semantics
play

Semantics interp IR 0 2 compile / desugar = interp IR 1 2 - PowerPoint PPT Presentation

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


  1. Semantics

  2. interp IR 0 2 compile / desugar = interp IR 1 2

  3. Assignment 1

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

  5. Formal semantics

  6. 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. → β E 0 [x ← E 1 ] (( λ (x) E 0 ) E 1 ) { redex

  9. Capture-avoiding substitution E 0 [x ← E 1 ]

  10. FV(x) = {x} FV( ( λ (x) E 0 ) ) = FV( E 0 ) \ {x} FV( (E 0 E 1 ) ) = FV( E 0 ) ∪ FV( E 1 )

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

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

  13. α - renaming → α ( λ (y) E 0 [x ← y]) ( λ (x) E 0 ) = α

  14. η - reduction → η ( λ (x) (E 0 x)) E 0 where x ∉ FV( E 0 )

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

  16. Evaluation E 0 * E 1 * ?

  17. Evaluation to normal form E 0 * ( λ (x) …)

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

  19. Evaluation Strategy E 0 * * E 1 E 2

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

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

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

  23. Confluence E 0 * * E 1 E 2 * * E 3 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 v ::= ( λ (x) e) 
 ℰ ::= ( ℰ e) 
 | (v ℰ ) 
 e ::= ( λ (x) e) 
 | □ | (e e) | x

  28. Context and redex r { { ℰ [(v v)] = ((( λ (x) (( λ (y) y) x)) ( λ (z) z)) ( λ (w) w)) ℰ = ( □ ( λ (w) w) ) r = (( λ (x) (( λ (y) y) x)) ( λ (z) z))

  29. 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. 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))))

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend