dynamic semantics cos 441 princeton university fall 2004
Post on 21-Dec-2015
218 views
TRANSCRIPT
![Page 1: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/1.jpg)
Dynamic Semantics
COS 441
Princeton University
Fall 2004
![Page 2: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/2.jpg)
Outline for Today
• Evaluation/Big-Step/Natural Semantics– Semantics for -calculus– SML interpreter for -calculus
• Transition/Small-Step/SOS Semantics– Semantics for -calculus– SML interpreter for -calculus
• Harper covers these two topics in the other order
• Relationship between the two approaches
![Page 3: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/3.jpg)
Evaluation Semantics
• Evaluation semantics requires the definition of two sets– evaluatable expressions (E)– values (V)
• Useful but not required that V ½ E
• Defines a binary relation ½ E £ V
![Page 4: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/4.jpg)
Static Semantics for -calculus
Names x 2 …Expressions e ::= lam(x.e) | apply(e1,e2)| x
` X okX 2
ok-V
` apply(E1,E2)ok
` E1 ok ` E2 okok-A
` lam(X.E)ok
[ {X} ` E okok-L
![Page 5: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/5.jpg)
Evaluation Semantics for -calculus
Lambda Expr’s E = { E | {} ` E ok }
Lambda Values V = { lam(X.E) | lam(X.E) 2 E }
apply(E1,E2) V
E1 lam(X’.E’) E2 V’ [X’ Ã V’] E’ V eval-A
lam(X.E)lam(X.E)
lam(X.E) 2 V eval-L
![Page 6: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/6.jpg)
Evaluation Semantics for -calculus
Substitution of a closed term V’ into E’ is closed
Lambda Expr’s E = { E | {} ` E ok }
Lambda Values V = { lam(X.E) | lam(X.E) 2 E }
apply(E1,E2) V
E1 lam(X’.E’) E2 V’ [X’ Ã V’] E’ V eval-A
lam(X.E)lam(X.E)
lam(X.E) 2 V eval-L
![Page 7: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/7.jpg)
Example: Evaluations
apply(lam(X.X),lam(Y.Y)) ??
apply(lam(X.Z),lam(Y.Y)) ??
lam(X.X) ??
apply(X,lam(Y.Y)) ??
![Page 8: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/8.jpg)
Example: Evaluations
apply(lam(X.X),lam(Y.Y)) ??
apply(lam(X.Z),lam(Y.Y)) ??
lam(X.X) lam(X.X)
apply(X,lam(Y.Y)) ??
![Page 9: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/9.jpg)
Example: Evaluations
apply(lam(X.X),lam(Y.Y)) lam(Y.Y)
apply(lam(X.Z),lam(Y.Y)) ??
lam(X.X) lam(X.X)
apply(X,lam(Y.Y)) ??
![Page 10: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/10.jpg)
Example: Evaluations
apply(lam(X.X),lam(Y.Y)) lam(Y.Y)
apply(lam(X.Z),lam(Y.Y)) ??
lam(X.X) lam(X.X)
apply(X,lam(Y.Y)) ??
![Page 11: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/11.jpg)
Example: Evaluations
apply(lam(X.X),lam(Y.Y)) lam(Y.Y)
apply(lam(X.Z),lam(Y.Y)) ??
lam(X.X) lam(X.X)
apply(X,lam(Y.Y)) ??
![Page 12: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/12.jpg)
Example: Evaluations
apply(lam(X.apply(X,X)), lam(X.apply(X,X)) ??
![Page 13: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/13.jpg)
Example: Evaluations
apply(lam(X.apply(X,X)), lam(X.apply(X,X)) ??
[XÃlam(X.apply(X,X))] lam(X.apply(X,X)) apply(lam(X.apply(X,X)),
lam(X.apply(X,X))
![Page 14: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/14.jpg)
Example: Evaluations
There is no derivation because the expression “infinite loops”
apply(lam(X.apply(X,X)), lam(X.apply(X,X)) ??
[XÃlam(X.apply(X,X))] lam(X.apply(X,X)) apply(lam(X.apply(X,X)),
lam(X.apply(X,X))
![Page 15: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/15.jpg)
Evaluation “Order”
• Which subterm do we evaluate first?
• Rules don’t specify, you can build your proof tree up in any order!
• Order of evaluation doesn’t really matter in this case
apply(E1,E2)
![Page 16: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/16.jpg)
Evaluation Semantics in SML
apply(E1,E2) V
E1 lam(X’.E’) E2 V’ [X’ Ã V’] E’ V eval-A
lam(X.E)lam(X.E)
lam(X.E) 2 V eval-L
![Page 17: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/17.jpg)
Evaluation Semantics in SML eval(lam(X.E)) lam(X.E)
if lam(X.E) 2 V
apply(E1,E2) V
E1 lam(X’.E’) E2 V’ [X’ Ã V’] E’ V eval-A
![Page 18: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/18.jpg)
Evaluation Semantics in SML eval(lam(X.E)) lam(X.E)
if lam(X.E) 2 V
eval(apply(E1,E2)) eval([X’ÃV’]E’))
if lam(X’.E’)eval(E1))
and V’ eval(E2)
![Page 19: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/19.jpg)
Evaluation Semantics in SMLtype name = Names.namedatatype exp = Lam of (name * exp) | Apply of (exp * exp) | Var of (name)
val subst : (name * exp * exp) -> exp val ok : (Names.set * exp) -> bool
![Page 20: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/20.jpg)
Evaluation Semantics in SML
fun eval(Lam(x,e)) = if ok(Set.empty,Lam(x,e)) then Lam(x,e) else raise Wrong | eval(Apply(e1,e2)) = let val Lam(x’,e’) = eval(e1) val v’ = eval(e2) in eval(subst(x,v’,e’)) end
![Page 21: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/21.jpg)
Evaluation Semantics in SML
fun eval(Lam(x,e)) = if ok(Set.empty,Lam(x,e)) then Lam(x,e) else raise Wrong | eval(Apply(e1,e2)) = (case(eval(e1),eval(e2)) of (Lam(x’,e’),v’) =>
eval(subst(x,v’,e’)) | _ => raise Impossible) | eval _ = raise Wrong
![Page 22: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/22.jpg)
Evaluation Semantics in SML
fun eval(e as Lam _) = if ok(Set.empty,e)then e else raise Wrong | eval(Apply(e1,e2)) = (case(eval(e1),eval(e2)) of (Lam(x’,e’),v’) =>
eval(subst(x’,v’,e’)) | _ => raise Impossible) | eval _ = raise Wrong
![Page 23: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/23.jpg)
Another Approach
Introduce an type that represents valuestype name = Names.name
datatype exp = Lam of (name * exp) | Apply of (exp * exp) | Var of (name) type value = (name * exp)
![Page 24: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/24.jpg)
Another Approach
fun eval(Lam(x,e)) = if ok(Set.empty,Lam(x,e)) then (x,e) else raise Wrong | eval(Apply(e1,e2)) = let val (x’,e’) = eval(e1) val v’ = eval(e2) in eval(subst(x,Lam v’,e’)) end | eval _ = raise Wrong
![Page 25: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/25.jpg)
Evaluation Semantics
• Non-termination expressions do not evaluate to a value
• Evaluation “order” unspecified
• Concise and “intuitive”
• Easy to translate into efficient interpreter– The main reason we study it!
![Page 26: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/26.jpg)
Transition Semantics
• Transition semantics requires the definition of universe of states S– initial states (I)– final states (F)
• Required that I ½ S and F ½ S
• A binary step relation ½ S £ S
• Iterated multi-step versions *,!, and n
![Page 27: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/27.jpg)
Multistep Relations
S * SZ*
S * S’’
S S’ S’ * S’’S*
S ! S
S 2 FZ!
S ! S’’
S S’ S’ ! S’’S!
S 0 SZn
S n+1 S’’
S S’ S’ n S’’Sn
![Page 28: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/28.jpg)
Transition Semantics for -calculus
((x.e1) e2) ((x.e1) e’2)
e2 e’2A2
((x.e1) (y.e2)) [xÃ(y.e2)] e1 A1
(e1 e2) (e’1 e2)
e1 e’1 A3
I = { E | {} ` E ok }
S = { E | 9. ` E ok }
F = { x.e | {} ` x.e ok }
![Page 29: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/29.jpg)
Example:
((x.x) (y.y)) ??
x.x) ??
((x.(x x)) (x.(x x))) ??
(((x.x) (x.x)) ((x.x) (x.x))) ??
![Page 30: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/30.jpg)
Example:
((x.x) (y.y)) ??
x.x) ??
((x.(x x)) (x.(x x))) ??
(((x.x) (x.x)) ((x.x) (x.x))) ??
![Page 31: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/31.jpg)
Example:
((x.x) (y.y)) (x.x)
x.x) ??
((x.(x x)) (x.(x x))) ??
(((x.x) (x.x)) ((x.x) (x.x))) ??
![Page 32: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/32.jpg)
Example:
((x.x) (y.y)) (x.x)
x.x) ??
((x.(x x)) (x.(x x))) ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) ??
![Page 33: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/33.jpg)
Example:
((x.x) (y.y)) (x.x)
x.x) ??
((x.(x x)) (x.(x x))) ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) ((x.x) ((x.x) (x.x)))
![Page 34: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/34.jpg)
Example:
((x.x) (y.y)) (x.x)
x.x) ??
((x.(x x)) (x.(x x))) ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) ((x.x) ((x.x) (x.x)))
((x.x) ((x.x) (x.x))) ??
![Page 35: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/35.jpg)
Example:
((x.x) (y.y)) (x.x)
x.x) ??
((x.(x x)) (x.(x x))) ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) ((x.x) ((x.x) (x.x)))
((x.x) ((x.x) (x.x))) ((x.x) (x.x))
![Page 36: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/36.jpg)
Example:
((x.x) (y.y)) (x.x)
x.x) ??
((x.(x x)) (x.(x x))) ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) ((x.x) ((x.x) (x.x)))
((x.x) ((x.x) (x.x))) ((x.x) (x.x))
((x.x) (x.x)) ??
![Page 37: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/37.jpg)
Example:
((x.x) (y.y)) (x.x)
x.x) ??
((x.(x x)) (x.(x x))) ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) ((x.x) ((x.x) (x.x)))
((x.x) ((x.x) (x.x))) ((x.x) (x.x))
((x.x) (x.x)) (x.x)
![Page 38: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/38.jpg)
Example: *
((x.x) (y.y)) * ??
x.x) * ??
((x.(x x)) (x.(x x))) * ??
(((x.x) (x.x)) ((x.x) (x.x))) * ??
![Page 39: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/39.jpg)
Example: *
((x.x) (y.y)) * ((x.x) (y.y))
x.x) * x.x)
((x.(x x)) (x.(x x))) * ??
(((x.x) (x.x)) ((x.x) (x.x))) * ??
![Page 40: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/40.jpg)
Example: *
((x.x) (y.y)) * (y.y)
x.x) * x.x)
((x.(x x)) (x.(x x))) * ??
(((x.x) (x.x)) ((x.x) (x.x))) * ??
![Page 41: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/41.jpg)
Example: *
((x.x) (y.y)) * (y.y)
x.x) * x.x)
((x.(x x)) (x.(x x))) * ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) * ??
![Page 42: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/42.jpg)
Example: *
((x.x) (y.y)) * (y.y)
x.x) * x.x)
((x.(x x)) (x.(x x))) * ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) * (((x.x) (x.x)) ((x.x) (x.x)))
![Page 43: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/43.jpg)
Example: *
((x.x) (y.y)) * (y.y)
x.x) * x.x)
((x.(x x)) (x.(x x))) * ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) * ((x.x) ((x.x) (x.x)))
![Page 44: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/44.jpg)
Example: *
((x.x) (y.y)) * (y.y)
x.x) * x.x)
((x.(x x)) (x.(x x))) * ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) * ((x.x) (x.x))
![Page 45: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/45.jpg)
Example: *
((x.x) (y.y)) * (y.y)
x.x) * x.x)
((x.(x x)) (x.(x x))) * ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) * (x.x)
![Page 46: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/46.jpg)
Example: !
((x.x) (y.y)) ! ??
x.x) ! ??
((x.(x x)) (x.(x x))) ! ??
(((x.x) (x.x)) ((x.x) (x.x))) ! ??
![Page 47: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/47.jpg)
Example: !
((x.x) (y.y)) ! ??
x.x) ! x.x)
((x.(x x)) (x.(x x))) ! ??
(((x.x) (x.x)) ((x.x) (x.x))) ! ??
![Page 48: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/48.jpg)
Example: !
((x.x) (y.y)) ! (y.y)
x.x) ! x.x)
((x.(x x)) (x.(x x))) ! ??
(((x.x) (x.x)) ((x.x) (x.x))) ! ??
![Page 49: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/49.jpg)
Example: !
((x.x) (y.y)) ! (y.y)
x.x) ! x.x)
((x.(x x)) (x.(x x))) ! ??
(((x.x) (x.x)) ((x.x) (x.x))) ! ??
![Page 50: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/50.jpg)
Example: !
((x.x) (y.y)) ! (y.y)
x.x) ! x.x)
((x.(x x)) (x.(x x))) ! ??
(((x.x) (x.x)) ((x.x) (x.x))) ! (x.x)
![Page 51: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/51.jpg)
Example: 0
((x.x) (y.y)) 0 ??
x.x) 0 ??
((x.(x x)) (x.(x x))) 0 ??
(((x.x) (x.x)) ((x.x) (x.x))) 0 ??
![Page 52: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/52.jpg)
Example: 0
((x.x) (y.y)) 0 ((x.x) (y.y))
x.x) 0 x.x)
((x.(x x)) (x.(x x))) 0 ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) 0 (((x.x) (x.x)) ((x.x) (x.x)))
![Page 53: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/53.jpg)
Example: 1
((x.x) (y.y)) 1 (y.y)
x.x) 1 ??
((x.(x x)) (x.(x x))) 1 ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) 1 ((x.x) ((x.x) (x.x)))
![Page 54: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/54.jpg)
Example: 2
((x.x) (y.y)) 2 ??
x.x) 2 ??
((x.(x x)) (x.(x x))) 2 ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) 2 ((x.x) (x.x))
![Page 55: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/55.jpg)
Example: 3
((x.x) (y.y)) 3 ??
x.x) 3 ??
((x.(x x)) (x.(x x))) 3 ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) 3 (x.x)
![Page 56: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/56.jpg)
Example: 4
((x.x) (y.y)) 4 ??
x.x) 4 ??
((x.(x x)) (x.(x x))) 4 ((x.(x x)) (x.(x x)))
(((x.x) (x.x)) ((x.x) (x.x))) 4 (x.x)
![Page 57: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/57.jpg)
!
((x.x) (y.y)) ! (y.y)
x.x) ! x.x)
((x.(x x)) (x.(x x))) ! ??
(((x.x) (x.x)) ((x.x) (x.x))) ! (x.x)
![Page 58: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/58.jpg)
((x.x) (y.y)) (y.y)
x.x) x.x)
((x.(x x)) (x.(x x))) ??
(((x.x) (x.x)) ((x.x) (x.x))) (x.x)
![Page 59: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/59.jpg)
Relation Between ! and
Theorem: e ! (x.e’) iff e (x.e’)Proof: By lemma 1 and lemma 2
Lemma 1: If e (x.e’) then e ! (x.e’)
Lemma 2: If e ! (x.e’) then e (x.e’)Proofs: See Harper 7.3 for sketch
![Page 60: Dynamic Semantics COS 441 Princeton University Fall 2004](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d5e5503460f94a3e554/html5/thumbnails/60.jpg)
Transition Semantics
• Has direct correspondence with evaluation semantics
• Let us reason about– Evaluation order– Computational complexity of program– Partial computations
• Easier to relate with static semantics to prove type safety– Next lecture!