Semantik von Programmiersprachen
Bereich: III, Vorlesung: 4 Std.
Semantik kann alternativ auch als Vertiefung zu Übersetzung von
Programmiersprachen in die Diplomprüfung im Bereich
Praktische Informatik eingebracht werden.
Zeit & Ort: Mo 10:30-12:00 in N1070, Fr 9:30-11:00 in 0606
Beginn: 5.11.99
Übung: Di 13:15-14:45 in 1601
Übungsleitung: Gerwin Klein
Übungsschein: Einen Schein erhält, wer mindestens 40% der Punkte aus den Hausaufgaben und Programmieraufgaben erreicht und erfolgreich an der Semestralprüfung teilnimmt.
Prüfung:
Am 29.2.2000
findet statt der Übung die Semestralprüfung
statt. Teilnahmeberechtigt sind alle Studierenden, die mindestens 40%
der Punkte aus den Haus- und Programmieraufgaben erreicht haben. Wenn
Sie an dieser mündlichen Prüfung teilnehmen möchten, melden Sie sich
bitte bis spätestens 22.2.2000 per E-mail an Gerwin Klein <kleing@in.tum.de> an. Sie
erhalten dann Antwort, ob Sie die Zulassungsvoraussetzungen zur Prüfung
erfüllt haben.
Die Aufgabenblätter
für die Zentralübung werden regelmäßig in
der Vorlesung verteilt. Bei Bedarf werden in der Vorlesung auch
Merkblätter ausgeteilt.
Lernziele:
-
Das Verstehen der grundlegenden mathematischen Techniken, um die Semantik einer
Programmiersprache präzise zu definieren.
-
Das Anwenden dieser Techniken auf Probleme wie
Äquivalenz verschiedener Sprachbeschreibungen,
Korrektheit von Übersetzern, Programmkorrektheit,
Sicherheit von Typsystemen,
Korrektheit von Programmtransformationen etc.
Beispielhafte Anwendungen der Techniken der Vorlesung auf die
Programmierpsrache Java finden sie hier.
Inhalt: Eine einfache imperative Programmiersprache WHILE wird aus
verschiedenen Blickwinkeln beschrieben und analysiert:
-
Introduction
The syntax of WHILE. Concrete vs abstract syntax.
Evaluation of arithmetic and boolean expressions.
-
Operational Semantics
- Big-step semantics
The rules. Derivation trees.
Lemma while b do s is equivalent to
if b do s;while b do s else skip.
- Rule induction
Inductively defined sets and the principle of rule induction.
Examples: natural numbers and transitive reflexive closure, together with
proofs of various closure properties. Rule induction for big-step
semantics of WHILE. Theorem: WHILE is deterministic.
- Small-step semantics
The rules. Derivation sequences. Theorem: Agreement of big-step and
small-step semantics.
- Extensions of WHILE
- Nondeterminism. Big-step semantics hides nontermination. Small-step
semantics more appropriate.
- Parallelism. Big-step semantics not possible. Interleaving small-step
semantics.
- Local variables.
- Procedures. Static and dynamic scope for variables and
procedures. Big-step semantics for a) dynamic scope for variables and
procedures, b) dynamic scope for variables and static scope for
procedures, c) static scope of variable and procedures.
- Application: a compiler for WHILE
A 3-instruction machine. Its operational single-step semantics. The
compiler. Detailed proof of the equivalence of running the source program
and running the compiled program.
- Type Systems
Static vs dynamic typing.
- Types for WHILE.
Merging the syntax of arithmetic and boolean expression.
Types bool and int. Variable declarations.
- A monomorphic type system
- The type system
Typing rules for expressions and statements. The need for semantics to
talk about correctness of the type system.
- The semantics
The need to separate booleans and integers. Semantics
of expressions and statements. Theorem: Typed WHILE is type safe,
i.e. type correct statements transform type correct states into type
correct states.
- A polymorphic type system.
- Type checking
Type variables. Typing rules and semantics unchanged! A rephrased type
safety theorem based on substitutions for type variables: type correct
statements guarantee type safe execution starting from any state that is
type correct w.r.t. an instance of the polymorphic variable declarations.
- Type inference
How to reconstruct the missing type declarations using type checking and
unification, i.e. Prolog.
A classification of various programming language according to
static/dynamic and monomorphic/polymorphic.
- Denotational Semantics
- Inductive definitions and rule induction
A set theoretic treatment of rules. Definition: The set
IR defined by a set of rules R is the least
R-closed set.
- The derivation of rule induction.
- Theorem: IR is the least fixpoint of the
consequence operator induced by R. If R is finitary,
IR is the union of all finite iterations of R
starting from the empty set.
- A denotational semantics based on sets
The semantics of while-loops as a least fixpoint of a function which can
be expressed by inference rules. Equivalence proof of denotational and
operational semantics.
- Complete partial orders
Definition of complete partial orders (cpos) and continuity.
The Fixpoint Theorem. Discrete cpos, product cpos, function cpos,
lifting.
- A cpo-based denotational semantics for While.
- Extensions of WHILE
- Local variables and procedures. Static scoping only.
- Exceptions and continuations.
- The Knaster-Tarski fixpoint theorem.
Every monotone function on a complete lattice has a least fixpoint.
- Nondeterminism. Relational semantics already defined but too weak
because it does not distinguish possible and guaranteed termination.
Definition of the set of start states that guarantee
termination using the Knaster-Tarski fixpoint theorem to obtain the least
fixpoint of a monotone function (in the case of loops).
- Axiomatic Semantics (Hoare Logic)
- From Floyd to Hoare. Partial and total correctness. The rules of Hoare
logic.
- Syntax of assertions: first-order arithmetic.
- Semantics of assertions and Hoare triples: validity w.r.t. a state and
an interpretation of the logical variables.
- Soundness of Hoare logic: proof by rule induction.
- Completeness of Hoare logic: impossible for effective proof systems.
Relative completeness: use semantics (|=) rather than proof system
(|-) of the assertion language. Prove relative completeness via
weakest liberal precondition and expressiveness, i.e. the ability to
express the wlp in the assertion language.
- Verification conditions. Extraction of (weakest) preconditions and
verification conditions in the presence of loop invariants. Proof of
soundness and completeness of this approach.
- Total correctness. Completeness requires "expressive" language of
arithmetic (beyond polynomials).
- Extensions of WHILE
- Nondeterminism
- Arrays
- Procedures: The problem. An adaption rule. A complete system based
on a generalized consequence rule. (Soundness only sketched,
completeness not proved.)
- Time complexity
- Exact execution times.
- Timed Hoare triples and their validity.
- Proof rules for timed Hoare triples.
- Operational semantics of functional languages
- A first-order language of recursion equations. Call by value and call
by name semantics. Proof that termination of c-b-v implies termination of
c-b-n.
- A higher-order language with call by value semantics.
Hörerkreis: Studenten/-innen der Informatik und Mathematik
Note: The lectures are taught in English.
Voraussetzungen: Vordiplom
Empfehlenswert für: Für eine spätere theoretische
Beschäftigung mit Programmiersprachen ist diese Vorlesung unabdingbar.
Es bestehen ausserdem starke Querbezüge zu den Gebieten Logik,
Programmverifikation und Lambda-Kalkül.
Skript und Literatur:
Die Vorlesung orientiert sich stark an folgenden beiden Büchern
Tobias Nipkow, 24.1.2000