170 likes | 194 Views
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. Soundness for SOS. Last time: soundness of typing rules for structural operational semantics
E N D
CS 611: Lecture 29 Soundness of Denotational Semantics and Strong Normalization in theSimply-Typed Lambda Calculus November 5, 1999 Cornell University Computer Science Department Andrew Myers
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
Outline • Soundness of denotational semantics • Agreement between operational and denotational semantics (briefly) • Proof of strong normalization CS 611—Semantics of Programming Languages—Andrew Myers
Denotational semantics for TLC • Semantic function C is applied to type judgements CG 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 G: r G xdom(G) .r(x) T G(x) • Denotational semantics are sound with respect to typing if they map expressions to meta-language values of the right type: r G CG e : tr T t CS 611—Semantics of Programming Languages—Andrew Myers
Denotational Semantics CG n : intr = n CGx : G(x)r = r(x) CGe0 e1: tr = CGe0: t1tr (CGe1: t1r) CG (l x :t . e) : tt’r = l v T t . CG[xt]e: t’r [xv] Example: CG (lx: int . x) : int intr = l v T int . CG[xint] x : intr [xv] = l v Z . v = identity function on integers CS 611—Semantics of Programming Languages—Andrew Myers
Type soundness • To show: Ge: tr G CGe : tr Tt • Use induction on height of type derivation for type judgement • Axioms: CG n : intr = n n Z CGx : G(x)r = r(x) r G r(x) T G(x) CGe0 e1 :tr = CGe0:t2tr (CGe1 :t2r) T t2t = T t2Tt T t2 CS 611—Semantics of Programming Languages—Andrew Myers
Type soundness, cont. CGl x : t . e : tt’r = l v T t . CG[xt]e : t’r [xv] G[xt]e : t’ Gl x : t . e : tt’ r [xv] G[xt] since v T t T t’ T tT t’ = T tt’ CS 611—Semantics of Programming Languages—Andrew Myers
Agreement • Would like to know that denotational semantics and operational semantics agree Operational e e’ e’’ … v : t C v : tr0 T t Denotational CS 611—Semantics of Programming Languages—Andrew Myers
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 : tr0 = C v : tr0 • They agree on observable results: divergence v . e* v e : t C e : t r0 • and also on ground types (e.g. int) e* v e : intC e : intr0 = v • Proof: last year’s CS 611 lecture notes CS 611—Semantics of Programming Languages—Andrew Myers
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 : intint . (+ (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
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 } Ttt’ = { e | e : tt’ e v (e’ Tt .(e e’ ) Tt’)} • Goal: e : t e Tt CS 611—Semantics of Programming Languages—Andrew Myers
Strategy Tint = { e | e : int e n } Ttt’ = { e | e : tt’ 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 G. Need to extend form of goal to allow it to be proved inductively: use substitution operators. • Introduce function g mapping variables to expressions. g : Var Exp • g only substitutes stable expressions of the right type: g G xdom(g) .g(x) TG(x) CS 611—Semantics of Programming Languages—Andrew Myers
Substitution function • Given any function g, we can define a related function g mapping ExpExp and performing all the substitutions specified by g: gx = g(x) if xdom(g) gx = x if xdom(g) gn = n ge0 e1= ge0ge1 glx : t . e= lx : t . g’e g’ is identical to g except that it does not map x CS 611—Semantics of Programming Languages—Andrew Myers
Refined goal • Original goal: show all expressions are stable e : t e Tt • Suppose we can prove the following goal: Ge : t . e Tt • Now consider G = . The only g 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
Part I • To show: Ge : t . e Tt • Integers: Gn : int . n Tint • Variables: Gx : G(x) . (x) TG(x) • if then (x) TG(x)by definition. • Application: G (e0 e1) : t • Consider a such that • e0 e1 = e0e1 • From type judgement: Ge0: t1 t, Ge1: t1 • inductive hypothesis gives use0ande1 are stable; therefore their application is too. CS 611—Semantics of Programming Languages—Andrew Myers
Part II • To show: G (lx : t . e) : tt’ . (lx : t . e) Ttt’ • Assume LHS, consider arbitrary g • Recall Ttt’ = { e | e : tt’ e v (e’ Tt .(e e’ ) Tt’)} • (lx : t . e) is already a value so e v • Need (e’ Tt .((lx : t . e) e’ ) Tt’)} • (lx : t . e)e’ = ’ e [e’/x] = ’’e where ’’ = [x e’ ] • From proof rule: G[xt]e :t’ • Applying induction hypothesis:’’[xt] ’’(e) Tt’ ’’ [xt] (e’ Tt ) QED CS 611—Semantics of Programming Languages—Andrew Myers
Coming soon: richer types • Recursive types • Polymorphic types • Subtyping • Objects CS 611—Semantics of Programming Languages—Andrew Myers