Η παρουσίαση φορτώνεται. Παρακαλείστε να περιμένετε

Η παρουσίαση φορτώνεται. Παρακαλείστε να περιμένετε

Semantics.

Παρόμοιες παρουσιάσεις


Παρουσίαση με θέμα: "Semantics."— Μεταγράφημα παρουσίασης:

1 Semantics

2 interp IR0 2 compile / desugar = interp IR1 2

3 Assignment 1

4 Scheme IR 2 (λ (f) (λ (x) (f (f x)))) λ-calculus interp church-encode
church->nat interp (λ (f) (λ (x) (f (f x)))) λ-calculus

5 Formal semantics

6 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.

7 ((λ (f) (f (f (λ (x) x)))) (λ (x) x))
β ((λ (x) x) ((λ (x) x) (λ (x) x))) β ((λ (x) x) (λ (x) x)) β (λ (x) x)

8 { ((λ (x) E0) E1) →β E0[x ← E1] redex

9 Capture-avoiding substitution
E0[x ← E1]

10 FV((λ (x) E0)) = FV(E0) \ {x}
FV(x) = {x} FV((λ (x) E0)) = FV(E0) \ {x} FV((E0 E1)) = FV(E0) ∪ FV(E1)

11 (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)

12 α - renaming (λ (x) (λ (y) x)) (λ (a) (λ (b) a))

13 α - renaming (λ (x) E0) →α (λ (y) E0[x ← y])

14 η - reduction (λ (x) (E0 x)) →η E0 where x ∉ FV(E0)

15 reflexive/transitive closure
Reduction (→) = (→β) ∪ (→α) ∪ (→η) (→*) reflexive/transitive closure

16 Evaluation E0 * E1 * ?

17 Evaluation to normal form
* (λ (x) …)

18 Evaluation to normal form
* (λ (x) … (λ (z) ((a …) …))) function position must be a variable

19 Evaluation Strategy E0 * * E1 E2

20 ((λ (x) ((λ (y) y) x)) (λ (z) z))
Evaluation Strategy ((λ (x) ((λ (y) y) x)) (λ (z) z)) →η ((λ (y) y) (λ (z) z)) →β (λ (z) z)

21 ((λ (x) ((λ (y) y) x)) (λ (z) z))
Evaluation Strategy ((λ (x) ((λ (y) y) x)) (λ (z) z)) →β ((λ (y) y) (λ (z) z)) →β (λ (z) z)

22 ((λ (x) ((λ (y) y) x)) (λ (z) z))
Evaluation Strategy ((λ (x) ((λ (y) y) x)) (λ (z) z)) →β ((λ (x) x) (λ (z) z)) →β (λ (z) z)

23 Church-Rosser Theorem
Confluence E0 * * E1 E2 * * E3 Church-Rosser Theorem

24 Applicative evaluation order
Always evaluates the innermost leftmost redex first. Normal evaluation order Always evaluates the outermost leftmost redex first.

25 Applicative evaluation order
((λ (x) ((λ (y) y) x)) (λ (z) z)) Normal evaluation order (((λ (x) ((λ (y) y) x)) (λ (z) z)) (λ (w) w))

26 Call-by-value semantics
Applicative evaluation order, but not under lambdas. Call-by-name semantics Normal evaluation order, but not under lambdas.

27 Evaluation contexts ℰ ::= (ℰ e) | (v ℰ) | □ v ::= (λ (x) e)
e ::= (λ (x) e) | (e e) | x ℰ ::= (ℰ e) | (v ℰ) | □

28 (((λ (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))

29 (((λ (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))

30 (((λ (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))

31 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))))


Κατέβασμα ppt "Semantics."

Παρόμοιες παρουσιάσεις


Διαφημίσεις Google