Wintersemester 2001/2002
Semantik von Programmiersprachen
Prof. Tobias Nipkow
Bereich: |
Info III, Wahlpflichtvorlesung: 4 Std. (+2Ü),
oder Info I, vertiefend zu Übersetzerbau (4 Std.)
|
Zeit und Ort: |
Mo, 10:30-12:00, 0360
Mi, 10:30-12:00, 0360
|
Beginn: |
Mi, 17.10.2001
|
Zentralübung: |
Mo, 14:00-16:00, S2229 |
Übungsleitung: |
Gerwin Klein |
Hörerkreis: Studenten/-innen der Informatik und Mathematik
Voraussetzungen: Vordiplom
Note: The lectures are taught in English.
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.
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.(Isabelle
[pdf]
[ps.gz])
-
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.(Isabelle
[pdf]
[ps.gz])
- 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 (Isabelle
[pdf]
[ps.gz])
- Small-step semantics
The rules [pdf]
[ps.gz]. Derivation sequences. Theorem: Agreement of big-step and
small-step semantics.(Isabelle
[pdf]
[ps.gz])
- 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.(Isabelle
[pdf]
[ps.gz])
- 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.
Übungsschein:
Einen Schein erhält, wer mindestens 40% der Punkte aus den Hausaufgaben und Programmieraufgaben erreicht und erfolgreich an der Semestralprüfung teilnimmt.
Literatur:
Die Vorlesung orientiert sich stark an folgenden beiden Büchern