Semantics
interp IR 0 2 compile / desugar = interp IR 1 2
Assignment 1
interp Scheme IR 2 church-encode church->nat interp ( λ (f) ( λ (x) λ -calculus (f (f x))))
Formal semantics
Axiomatic Semantics Gives axioms for constructing sound proofs about programs (typically using Hoare logic). Denotational Semantics Provides a function that maps language forms into their denotations in a known domain. Operational Semantics Provides a step-by-step reduction of the program to a value in terms of program terms or an abstract machine .
(( λ (f) (f (f ( λ (x) x)))) ( λ (x) x)) β (( λ (x) x) (( λ (x) x) ( λ (x) x))) β (( λ (x) x) ( λ (x) x)) β ( λ (x) x)
→ β E 0 [x ← E 1 ] (( λ (x) E 0 ) E 1 ) { redex
Capture-avoiding substitution E 0 [x ← E 1 ]
FV(x) = {x} FV( ( λ (x) E 0 ) ) = FV( E 0 ) \ {x} FV( (E 0 E 1 ) ) = FV( E 0 ) ∪ FV( E 1 )
x [ x ← E ] = E y [ x ← E ] = y where y ≠ x (E 0 E 1 ) [ x ← E ] = (E 0 [ x ← E] E 1 [ x ← E ] ) ( λ (x) E 0 ) [ x ← E ] = ( λ (x) E 0 ) ( λ (y) E 0 ) [ x ← E ] = ( λ (y) E 0 [ x ← E ] ) where y ≠ x and y ∉ FV( E ) β -reduction cannot occur when y ∈ FV( E )
α - renaming ( λ (x) ( λ (y) x)) ( λ (a) ( λ (b) a))
α - renaming → α ( λ (y) E 0 [x ← y]) ( λ (x) E 0 ) = α
η - reduction → η ( λ (x) (E 0 x)) E 0 where x ∉ FV( E 0 )
Reduction ( → ) = ( → β ) ∪ ( → α ) ∪ ( → η ) ( → * ) reflexive/transitive closure
Evaluation E 0 * E 1 * ?
Evaluation to normal form E 0 * ( λ (x) …)
Evaluation to normal form E 0 * ( λ (x) … ( λ (z) ((a …) …))) function position must be a variable
Evaluation Strategy E 0 * * E 1 E 2
Evaluation Strategy (( λ (x) (( λ (y) y) x)) ( λ (z) z)) → η (( λ (y) y) ( λ (z) z)) → β ( λ (z) z)
Evaluation Strategy (( λ (x) (( λ (y) y) x)) ( λ (z) z)) → β (( λ (y) y) ( λ (z) z)) → β ( λ (z) z)
Evaluation Strategy (( λ (x) (( λ (y) y) x)) ( λ (z) z)) → β (( λ (x) x) ( λ (z) z)) → β ( λ (z) z)
Confluence E 0 * * E 1 E 2 * * E 3 Church-Rosser Theorem
Applicative evaluation order Always evaluates the innermost leftmost redex first. Normal evaluation order Always evaluates the outermost leftmost redex first.
Applicative evaluation order (( λ (x) (( λ (y) y) x)) ( λ (z) z)) Normal evaluation order ((( λ (x) (( λ (y) y) x)) ( λ (z) z)) ( λ (w) w))
Call-by-value semantics Applicative evaluation order, but not under lambdas . Call-by-name semantics Normal evaluation order, but not under lambdas .
Evaluation contexts v ::= ( λ (x) e) ℰ ::= ( ℰ e) | (v ℰ ) e ::= ( λ (x) e) | □ | (e e) | x
Context and redex r { { ℰ [(v v)] = ((( λ (x) (( λ (y) y) x)) ( λ (z) z)) ( λ (w) w)) ℰ = ( □ ( λ (w) w) ) r = (( λ (x) (( λ (y) y) x)) ( λ (z) z))
Context and redex ℰ [r] = ((( λ (x) (( λ (y) y) x)) ( λ (z) z)) ( λ (w) w)) ℰ = ( □ ( λ (w) w) ) r = (( λ (x) (( λ (y) y) x)) ( λ (z) z)) → β (( λ (y) y) ( λ (z) z))
Put it back together: ℰ = ( □ ( λ (w) w) ) r = (( λ (x) (( λ (y) y) x)) ( λ (z) z)) → β (( λ (y) y) ( λ (z) z)) ℰ [r] ((( λ (y) y) ( λ (z) z)) ( λ (w) w) )
Some exercises 1) ((( λ (y) y) ( λ (z) z)) ( λ (w) w) ) 2) (( λ (u) (u u)) ( λ (x) ( λ (x) x))) 3) ((( λ (x) x) ( λ (y) y)) (( λ (u) (u u)) ( λ (z) (z z))))
Recommend
More recommend