Semantics
interp IR0 2 compile / desugar = interp IR1 2
Assignment 1
Scheme IR 2 (λ (f) (λ (x) (f (f x)))) λ-calculus interp church-encode church->nat interp (λ (f) (λ (x) (f (f x)))) λ-calculus
Formal semantics
Denotational 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)
{ ((λ (x) E0) E1) →β E0[x ← E1] redex
Capture-avoiding substitution E0[x ← E1]
FV((λ (x) E0)) = FV(E0) \ {x} FV(x) = {x} FV((λ (x) E0)) = FV(E0) \ {x} FV((E0 E1)) = FV(E0) ∪ FV(E1)
(E0 E1)[x ← E] = (E0[x ← E] E1[x ← E]) x[x ← E] = E y[x ← E] = y where y ≠ x (E0 E1)[x ← E] = (E0[x ← E] E1[x ← E]) (λ (x) E0)[x ← E] = (λ (x) E0) (λ (y) E0)[x ← E] = (λ (y) E0[x ← E]) where y ≠ x and y ∉ FV(E) β-reduction cannot occur when y ∈ FV(E)
α - renaming (λ (x) (λ (y) x)) (λ (a) (λ (b) a))
α - renaming (λ (x) E0) →α (λ (y) E0[x ← y]) =α
η - reduction (λ (x) (E0 x)) →η E0 where x ∉ FV(E0)
reflexive/transitive closure Reduction (→) = (→β) ∪ (→α) ∪ (→η) (→*) reflexive/transitive closure
Evaluation E0 * E1 * ?
Evaluation to normal form * (λ (x) …)
Evaluation to normal form * (λ (x) … (λ (z) ((a …) …))) function position must be a variable
Evaluation Strategy E0 * * E1 E2
((λ (x) ((λ (y) y) x)) (λ (z) z)) Evaluation Strategy ((λ (x) ((λ (y) y) x)) (λ (z) z)) →η ((λ (y) y) (λ (z) z)) →β (λ (z) z)
((λ (x) ((λ (y) y) x)) (λ (z) z)) Evaluation Strategy ((λ (x) ((λ (y) y) x)) (λ (z) z)) →β ((λ (y) y) (λ (z) z)) →β (λ (z) z)
((λ (x) ((λ (y) y) x)) (λ (z) z)) Evaluation Strategy ((λ (x) ((λ (y) y) x)) (λ (z) z)) →β ((λ (x) x) (λ (z) z)) →β (λ (z) z)
Church-Rosser Theorem Confluence E0 * * E1 E2 * * E3 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 ℰ ::= (ℰ e) | (v ℰ) | □ v ::= (λ (x) e) e ::= (λ (x) e) | (e e) | x ℰ ::= (ℰ e) | (v ℰ) | □
(((λ (x) ((λ (y) y) x)) (λ (z) z)) (λ (w) w)) Context and redex { { r ℰ[(v v)] = (((λ (x) ((λ (y) y) x)) (λ (z) z)) (λ (w) w)) ℰ = (□ (λ (w) w)) r = ((λ (x) ((λ (y) y) x)) (λ (z) z))
(((λ (x) ((λ (y) y) x)) (λ (z) z)) (λ (w) w)) 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))
(((λ (y) y) (λ (z) z)) (λ (w) w)) 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))))