1.07k likes | 1.19k Views
Relating Static and Dynamic Semantics. COS 441 Princeton University Fall 2004. Motivations. We want to know that when evaluating certain well-formed programs certain errors never occur Example
E N D
Relating Static and Dynamic Semantics COS 441 Princeton University Fall 2004
Motivations • We want to know that when evaluating certain well-formed programs certain errors never occur • Example • Transition semantics for -calculus is “stuck” when applied to expressions with free variables in it • So if {} `Eok then E should never be “stuck”
Formal Statement isFinal(e) = e 2 F steps(e) = 9 e’. e e’ stuck(e) = :(steps(e) or isFinal(e)) Soundness Theorem: If {} `Eokand E*E’then:stuck(E’)
Formal Statement isFinal(e) = e 2 F steps(e) = 9 e’. e e’ stuck(e) = :(steps(e) or isFinal(e)) Soundness Theorem: If {} `Eokand E*E’then (steps(E’) or isFinal(E’))
Proof: Soundness Theorem By induction on derivations of * with Preservation and Progress Lemmas Preservation Lemma: If {} `Eokand EE’then {} `E’ok Progress Lemma: If {} `Eokthen (steps(E) or isFinal(E))
Warning!! • The remainder of the lecture consists of a series of tedious proofs • Take that swig of coffee now • Slides will be on web-site • Last set of tedious proofs in lecture • I’ll assign them as homework from now on! ;) • What we discuss today is a template for Assignment 3
S S’ S’ * S’’ Z* S* S * S S * S’’ Proof by Induction over * To show 8 e,e’ P(e,e’) we must show case Z*: IH(E,E) case S*: IfEE’andIH(E’,E’’) then IH(E,E’’) IH(e,e’) = If {} ` e okand e * e’ then (steps(e’) or isFinal(e’))
Proof: Soundness Theorem case Z*: IH(E,E)
Proof: Soundness Theorem case Z*: If {} `Eokand E*Ethen (steps(E) or isFinal(E))
Proof: Soundness Theorem case Z*: (steps(E) or isFinal(E)) • {} `Eokand E*E by assumption
Proof: Soundness Theorem case Z*: • {} `Eokand E*E by assumption 2. (steps(E) or isFinal(E)) by ??
Proof: Soundness Theorem case Z*: • {} `Eokand E*E by assumption 2. (steps(E) or isFinal(E)) by Progress Lemma with (1)
Proof: Soundness Theorem case S*: IfEE’andIH(E’,E’’) then IH(E,E’’)
Proof: Soundness Theorem case S*: IH(E,E’’) 1. EE’andIH(E’,E’’) by assumption
Proof: Soundness Theorem case S*: If {} `Eokand E*E’’then (steps(E’’) or isFinal(E’’)) • EE’andIH(E’,E’’) by assumption
Proof: Soundness Theorem case S*: (steps(E’’) or isFinal(E’’)) • EE’andIH(E’,E’’) by assumption • {} `Eokand E*E’’ by assumption • ` E’ ok by Preservation with (2,1) • E’ * E’’ by inversion of S* and (2) • (steps(E) or isFinal(E’’)) by IH with (3, 4)
Proof: Soundness Theorem case S*: (steps(E’’) or isFinal(E’’)) • EE’andIH(E’,E’’) by assumption • {} `Eokand E*E’’ by assumption • {} `E’ok by ?? E’ * E’’ by inversion of S* and (2) • (steps(E) or isFinal(E’’)) by IH with (3, 4)
Proof: Soundness Theorem case S*: (steps(E’’) or isFinal(E’’)) • EE’andIH(E’,E’’) by assumption • {} `Eokand E*E’’ by assumption • {} `E’ok by Preservation with (2,1) • E’ * E’’ by inversion of S* and (2) • (steps(E) or isFinal(E’’)) by IH with (3, 4)
Proof: Soundness Theorem case S*: (steps(E’’) or isFinal(E’’)) • EE’andIH(E’,E’’) by assumption • {} `Eokand E*E’’ by assumption • {} `E’ok by Preservation with (2,1) • E’*E’’ by ?? • (steps(E’’) or isFinal(E’’)) by IH with (3, 4)
Proof: Soundness Theorem case S*: (steps(E’’) or isFinal(E’’)) • EE’andIH(E’,E’’) by assumption • {} `Eokand E*E’’ by assumption • {} `E’ok by Preservation with (2,1) • E’*E’’ by inversion of S* and (2) • (steps(E’’) or isFinal(E’’)) by IH with (3, 4)
Proof: Soundness Theorem case S*: • EE’andIH(E’,E’’) by assumption • {} `Eokand E*E’’ by assumption • {} `E’ok by Preservation with (2,1) • E’*E’’ by inversion of S* and (2) • (steps(E’’) or isFinal(E’’)) by ??
Proof: Soundness Theorem case S*: • EE’andIH(E’,E’’) by assumption • {} `Eokand E*E’’ by assumption • {} `E’ok by Preservation with (2,1) • E’*E’’ by inversion of S* and (2) • (steps(E’’) or isFinal(E’’)) by IH(E’,E’’) with (3, 4)
Notes About our Proof • Note our Proof works for any single step relation () • Specific details of step function factored into Progress and Preservation lemmas • Need to refer to the static and dynamic semantics of the step relation to prove Progress and Preservation Lemmas
ok-V X2 ` X ok ` E1ok ` E2ok [{X}` Eok X ok-A ok-L ` apply(E1,E2)ok ` lam(X.E)ok Static Semantics for -calculus
e2 e’2 e1 e’1 A2 A1 A3 ((x.e1) e2) ((x.e1) e’2) ((x.e1) (y.e2)) [xÃ(y.e2)] e1 (e1 e2) (e’1 e2) Dynamic Semantics for -calculus
Proof: Preservation Lemma Proof by induction on the derivations of EE’ case A1: IH(((X.E1) (Y.E2)),[XÃ (Y.E2)] E1) case A2: IfIH(E2,E’2) then IH(((X.E1) E2)),((X.E1) E’2)) case A3: IfIH(E1,E’1) then IH((E1E2)),(E’1E2)) IH(e,e’) =If {} ` e okand e e’ then {} ` e’ ok
Proof: Preservation Lemma case A1: If {} ` ((X.E1) (Y.E1))okand ((X.E1) (Y.E1))[XÃ (Y.E2)] E1then {} `[XÃ (Y.E2)] E1ok
Proof: Preservation Lemma case A1: {} `[XÃ (Y.E2)] E1 ok • {} ` ((X.E1) (Y.E2))okand ((X.E1) (Y.E2))[XÃ (Y.E2)] E1 by assumption • {} `(X.E1)ok and {} `(Y.E2)ok by inversion of ok-A and (1) • {} [ {X} ` E1ok by inversion of ok-L and (2) • {} `[X Ã (Y.E2)] E1 ok by Substitution Lemma with (3) and (2)
Proof: Preservation Lemma case A1: {} `[XÃ (Y.E2)] E1 ok • {} ` ((X.E1) (Y.E2))okand ((X.E1) (Y.E2))[XÃ (Y.E2)] E1 by assumption • {} `(X.E1)ok and {} `(Y.E2)ok by ?? • {} [ {X} ` E1ok by inversion of ok-L and (2) • {} `[X Ã (Y.E2)] E1 ok by Substitution Lemma with (3) and (2)
Proof: Preservation Lemma case A1: {} `[XÃ (Y.E2)] E1 ok • {} ` ((X.E1) (Y.E2))okand ((X.E1) (Y.E2))[XÃ (Y.E2)] E1 by assumption • {} `(X.E1)ok and {} `(Y.E2)ok by inversion of ok-A and (1) • {} [ {X} ` E1ok by inversion of ok-L and (2) • {} `[X Ã (Y.E2)] E1 ok by Substitution Lemma with (3) and (2)
Proof: Preservation Lemma case A1: {} `[XÃ (Y.E2)] E1 ok • {} ` ((X.E1) (Y.E2))okand ((X.E1) (Y.E2))[XÃ (Y.E2)] E1 by assumption • {} `(X.E1)ok and {} `(Y.E2)ok by inversion of ok-A and (1) • {} [ {X} `E1ok by ?? • {} `[X Ã (Y.E2)] E1 ok by Substitution Lemma with (3) and (2)
Proof: Preservation Lemma case A1: {} `[XÃ (Y.E2)] E1 ok • {} ` ((X.E1) (Y.E2))okand ((X.E1) (Y.E2))[XÃ (Y.E2)] E1 by assumption • {} `(X.E1)ok and {} `(Y.E2)ok by inversion of ok-A and (1) • {} [ {X} `E1ok by inversion of ok-L and (2) • {} `[X Ã (Y.E2)] E1 ok by Substitution Lemma with (3) and (2)
Proof: Preservation Lemma case A1: {} `[X Ã (Y.E2)] E1 ok • {} ` ((X.E1) (Y.E2))okand ((X.E1) (Y.E2))[XÃ (Y.E2)] E1 by assumption • {} `(X.E1)ok and {} `(Y.E2)ok by inversion of ok-A and (1) • {} [ {X} `E1ok by inversion of ok-L and (2) • {} `[XÃ (Y.E2)] E1 ok by ??
Proof: Preservation Lemma case A1: {} `[X Ã (Y.E2)] E1 ok • {} ` ((X.E1) (Y.E2))okand ((X.E1) (Y.E2))[XÃ (Y.E2)] E1 by assumption • {} `(X.E1)ok and {} `(Y.E2)ok by inversion of ok-A and (1) • {} [ {X} `E1ok by inversion of ok-L and (2) • {} `[XÃ (Y.E2)] E1 ok by Substitution Lemma with (3) and (2)
Substitution Lemma Proof by induction on the derivations of `E ok If[ {X} `E ok and {} `E’ ok then ` [XÃE’]E ok case ok-V: … case ok-L: … case ok-A: … IH(env,e) =If env [ {X} ` eok and {} `E’ ok then env ` [XÃE’]eok
Substitution Proof by induction on the derivations of `E ok If[ {X} `E ok and {} `E’ ok then ` [XÃE’]E ok case ok-V: If X2 then IH(,X) case ok-L: If IH( [ {X}, E) and X then IH(,(X.E)) case ok-A: If IH(,E1) and IH(,E2) then IH(,(E1E2)) IH(env,e) =If env [ {X} ` eok and {} `E’ ok then env ` [XÃE’]eok
Proof: Substitution case ok-V: 1. X2 by assumption 2. [ {Y} `X ok and {} `E’ ok by assumption 3. ` [YÃE’]X ok by cases case X = Y: 3.1. [YÃE’]X = E’ by def of subst. 3.2. ` E’ok by (2) 3.3. ` [YÃE’]X ok by (3.1) and (3.2) case XY: 3.1. [YÃE’]X = X by def of subst. 3.2. `X ok by ok-V and (1) 3.3. ` [YÃE’]X ok by (3.1) and (3.2)
Proof: Substitution case ok-L: If IH( [ {X}, E) and X then IH(,(X.E)) …
Proof: Substitution case ok-A: If IH(,E1) and IH(,E2) then IH(,(E1E2)) …
Proof: Preservation Lemma case A2: IfIH(E2,E’2) then IH(((X.E1) E2)),((X.E1) E’2))
Proof: Preservation Lemma case A2: IH(((X.E1) E2)),((X.E1) E’2)) • IH(E2,E’2) by assumption
Proof: Preservation Lemma case A2: If {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)then {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption
Proof: Preservation Lemma case A2: {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption • {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)by assumption • {} `(X.E1) ok and {} ` E2ok by inversion of ok-A and (2) • E2 E’2 by inversion of A2 • {} ` E’2ok by IH(E2,E’2) with (3) and (4) • {} `((X.E1) E’2)ok by ok-A with (3) and (5)
Proof: Preservation Lemma case A2: {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption • {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)by assumption • {} `(X.E1) ok and {} `E2ok by ?? • E2 E’2 by inversion of A2 • {} ` E’2ok by IH(E2,E’2) with (3) and (4) • {} `((X.E1) E’2)ok by ok-A with (3) and (5)
Proof: Preservation Lemma case A2: {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption • {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)by assumption • {} `(X.E1) ok and {} `E2ok by inversion of ok-A and (2) • E2 E’2 by inversion of A2 • {} ` E’2ok by IH(E2,E’2) with (3) and (4) • {} `((X.E1) E’2)ok by ok-A with (3) and (5)
Proof: Preservation Lemma case A2: {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption • {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)by assumption • {} `(X.E1) ok and {} `E2ok by inversion of ok-A and (2) • E2E’2 by ?? • {} ` E’2ok by IH(E2,E’2) with (3) and (4) • {} `((X.E1) E’2)ok by ok-A with (3) and (5)
Proof: Preservation Lemma case A2: {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption • {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)by assumption • {} `(X.E1) ok and {} `E2ok by inversion of ok-A and (2) • E2E’2 by inversion of A2 and (2) • {} ` E’2ok by IH(E2,E’2) with (3) and (4) • {} `((X.E1) E’2)ok by ok-A with (3) and (5)
Proof: Preservation Lemma case A2: {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption • {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)by assumption • {} `(X.E1) ok and {} `E2ok by inversion of ok-A and (2) • E2E’2 by inversion of A2 and (2) • {} `E’2ok by ?? • {} `((X.E1) E’2)ok by ok-A with (3) and (5)
Proof: Preservation Lemma case A2: {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption • {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)by assumption • {} `(X.E1) ok and {} `E2ok by inversion of ok-A and (2) • E2E’2 by inversion of A2 and (2) • {} `E’2ok by IH(E2,E’2) with (3) and (4) • {} `((X.E1) E’2)ok by ok-A with (3) and (5)
Proof: Preservation Lemma case A2: {} `((X.E1) E’2)ok • IH(E2,E’2) by assumption • {} ` ((X.E1) E2))okand ((X.E1) E2))((X.E1) E’2)by assumption • {} `(X.E1) ok and {} `E2ok by inversion of ok-A and (2) • E2E’2 by inversion of A2 and (2) • {} `E’2ok by IH(E2,E’2) with (3) and (4) • {} `((X.E1) E’2)ok by ??