CS 611 Lecture 29 Soundness of Denotational Semantics

  • Slides: 17
Download presentation
CS 611: Lecture 29 Soundness of Denotational Semantics and Strong Normalization in the Simply-Typed

CS 611: Lecture 29 Soundness of Denotational Semantics and Strong Normalization in the Simply-Typed Lambda Calculus November 5, 1999 Cornell University Computer Science Department Andrew Myers CS 611—Semantics of Programming Languages—Andrew Myers

Soundness for SOS • Last time: soundness of typing rules for structural operational semantics

Soundness for SOS • Last time: soundness of typing rules for structural operational semantics • “e is typable” e: t • “e does not get stuck”: e’. e * e’ value(e’) e’’. e’ e’’ • Soundness: “e is typable” “e does not get stuck” • Three parts to proof: – Preservation/Subject reduction e : t e * e’ e’ : t – Progress e : t value(e’) e’’. e’ e’’ – Induction on number of steps (generic) • New tool: induction on height of type derivation • Real languages much harder. . . CS 611—Semantics of Programming Languages—Andrew Myers 2

Outline • Soundness of denotational semantics • Agreement between operational and denotational semantics (briefly)

Outline • Soundness of denotational semantics • Agreement between operational and denotational semantics (briefly) • Proof of strong normalization CS 611—Semantics of Programming Languages—Andrew Myers 3

Denotational semantics for TLC • Semantic function C is applied to type judgements C

Denotational semantics for TLC • Semantic function C is applied to type judgements C e : t rather than just to expressions • Function C is defined only for legal type judgements : only typable expressions have a denotation • Environment r must satisfy the type context : r x dom( ). r(x) T (x) • Denotational semantics are sound with respect to typing if they map expressions to meta-language values of the right type: r C e : t r T t CS 611—Semantics of Programming Languages—Andrew Myers 4

Denotational Semantics C n : int r = n C x : (x) r

Denotational Semantics C n : int r = n C x : (x) r = r(x) C e 0 e 1: t r = C e 0: t 1 t r (C e 1: t 1 r) C (l x : t. e) : t t’ r = l v T t . C [x t] e: t’ r [x v] Example: C (l x : int. x) : int r = l v T int . C [x int] x : int r [x v] = lv Z. v = identity function on integers CS 611—Semantics of Programming Languages—Andrew Myers 5

Type soundness • To show: e: t r C e : t r T

Type soundness • To show: e: t r C e : t r T t • Use induction on height of type derivation for type judgement • Axioms: C n : int r = n n Z C x : (x) r = r(x) r r(x) T (x) C e 0 e 1 : t r = C e 0 : t 2 t r (C e 1 : t 2 T t 2 t = T r) t 2 T t 2 CS 611—Semantics of Programming Languages—Andrew Myers 6

Type soundness, cont. C l x : t. e : t t’ r =

Type soundness, cont. C l x : t. e : t t’ r = l v T t . C [x t] e : t’ r [x v] T t’ = T t t’ [x t] e : t’ l x : t. e : t t’ r [x v] [x t] since v T t CS 611—Semantics of Programming Languages—Andrew Myers 7

Agreement • Would like to know that denotational semantics and operational semantics agree Operational

Agreement • Would like to know that denotational semantics and operational semantics agree Operational e e’’ … v C v : t r 0 : t T t Denotational CS 611—Semantics of Programming Languages—Andrew Myers 8

Adequacy • Denotational semantics are adequate with respect to operational semantics: • Operational evaluation

Adequacy • Denotational semantics are adequate with respect to operational semantics: • Operational evaluation produces one of the values allowed by denotational semantics e * v e : t C e : t r 0 = C v : t r 0 • They agree on observable results: divergence v. e * v e : t C e : t r 0 • and also on ground types (e. g. int) e * v e : int C e : int r 0 = v • Proof: last year’s CS 611 lecture notes CS 611—Semantics of Programming Languages—Andrew Myers 9

Strong normalization • Every program in l terminates. Is this obvious? – Reduction can

Strong normalization • Every program in l terminates. Is this obvious? – Reduction can increase size of an expression – Reduction can increase number of contained lambda expressions ((l f : int. (+ (f 0) (f 1))) (l y : int. (* y 2))) – Untyped lambda calculus is not strongly normalizing • Idea: size of types decreases • Proof strategy: define set of strongly normalizing expressions SNt for every type t, show by induction on type derivation that expression of type t is a member of SNt. • Problem: induction hypothesis is not strong enough to handle application expressions. CS 611—Semantics of Programming Languages—Andrew Myers 10

Stable expressions • Strengthen induction hypothesis: define subset of strongly normalizing expressions (the stable

Stable expressions • Strengthen induction hypothesis: define subset of strongly normalizing expressions (the stable expressions); show all expressions in l are stable. • Stable expressions are strongly normalizing and result in strongly normalizing expressions when applied to other strongly normalizing expressions. • Tt is the set of stable expressions of type t. • Define inductively (note e v e * v ) Tint = { e | e : int e n } Tt t’ = { e | e : t t’ e v ( e’ Tt. (e e’ ) Tt’)} • Goal: e : t e Tt CS 611—Semantics of Programming Languages—Andrew Myers 11

Strategy Tint = { e | e : int e n } Tt t’

Strategy Tint = { e | e : int e n } Tt t’ = { e | e : t t’ e v ( e’ Tt. (e e’ ) Tt’) } Goal: e : t e Tt • Will use induction on type derivation for e • Problem: rule for typing l exprs adds to type context . Need to extend form of goal to allow it to be proved inductively: use substitution operators. • Introduce function mapping variables to expressions. : Var Exp • only substitutes stable expressions of the right type: x dom( ). (x) T (x) CS 611—Semantics of Programming Languages—Andrew Myers 12

Substitution function • Given any function , we can define a related function mapping

Substitution function • Given any function , we can define a related function mapping Exp and performing all the substitutions specified by : x = (x) if x dom( ) x = x if x dom( ) n = n e 0 e 1 = e 0 e 1 l x : t. e = l x : t. ’ e ’ is identical to except that it does not map x CS 611—Semantics of Programming Languages—Andrew Myers 13

Refined goal • Original goal: show all expressions are stable e : t e

Refined goal • Original goal: show all expressions are stable e : t e Tt • Suppose we can prove the following goal: e : t . e Tt • Now consider = . The only satisfying this type context is the identity mapping. Therefore, our refined goal becomes our original goal. • Now we turn the inductive crank. CS 611—Semantics of Programming Languages—Andrew Myers 14

Part I • To show: e : t . e Tt • Integers: n

Part I • To show: e : t . e Tt • Integers: n : int . n Tint • Variables: x : (x) T (x) – if then (x) T (x) by definition. • Application: (e 0 e 1) : t – Consider a such that – e 0 e 1 = e 0 e 1 – From type judgement: e 0 : t 1 t, e 1 : t 1 – inductive hypothesis gives us e 0 and e 1 are stable; therefore their application is too. CS 611—Semantics of Programming Languages—Andrew Myers 15

Part II • To show: (l x : t. e) : t t’ .

Part II • To show: (l x : t. e) : t t’ . (l x : t. e) Tt t’ • Assume LHS, consider arbitrary • Recall Tt t’ = { e | e : t t’ e v ( e’ Tt. (e e’ ) Tt’)} • (l x : t. e) is already a value so e v • Need ( e’ Tt. ( (l x : t. e) e’ ) Tt’)} • (l x : t. e) e’ = ’ e [e’/x] = ’’ e where ’’ = [x e’ ] • From proof rule: [x t] e : t’ • Applying induction hypothesis: ’’ [x t] ’’(e) Tt’ ’’ [x t] (e’ Tt ) QED CS 611—Semantics of Programming Languages—Andrew Myers 16

Coming soon: richer types • • Recursive types Polymorphic types Subtyping Objects CS 611—Semantics

Coming soon: richer types • • Recursive types Polymorphic types Subtyping Objects CS 611—Semantics of Programming Languages—Andrew Myers 17