programming language concepts lecture 16
play

Programming Language Concepts: Lecture 16 Madhavan Mukund Chennai - PowerPoint PPT Presentation

Programming Language Concepts: Lecture 16 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 16, 23 March 2009 -calculus: syntax Assume a set Var of variables


  1. Programming Language Concepts: Lecture 16 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 16, 23 March 2009

  2. λ -calculus: syntax ◮ Assume a set Var of variables ◮ Set Λ of lambda expressions is given by Λ = x | λ x . M | MM ′ where x ∈ Var , M , M ′ ∈ Λ.

  3. λ -calculus: syntax ◮ Assume a set Var of variables ◮ Set Λ of lambda expressions is given by Λ = x | λ x . M | MM ′ where x ∈ Var , M , M ′ ∈ Λ. ◮ Basic rule for computing (rewriting) is called β ( λ x . M ) M ′ → β M { x ← M ′ } ◮ M { x ← M ′ } : substitute free occurrences of x in M by M ′

  4. λ -calculus: syntax ◮ Assume a set Var of variables ◮ Set Λ of lambda expressions is given by Λ = x | λ x . M | MM ′ where x ∈ Var , M , M ′ ∈ Λ. ◮ Basic rule for computing (rewriting) is called β ( λ x . M ) M ′ → β M { x ← M ′ } ◮ M { x ← M ′ } : substitute free occurrences of x in M by M ′ ◮ When we apply β to MM ′ , assume that we always rename the bound variables in M to avoid “capturing” free variables from M ′ .

  5. Encoding arithmetic Church numerals � 0 � = λ fx . x � n + 1 � = λ fx . f ( � n � fx )

  6. Encoding arithmetic Church numerals � 0 � = λ fx . x � n + 1 � = λ fx . f ( � n � fx ) ◮ Let g k y denote g ( g ( . . . ( gy ))) with k applications of g to y ◮ Show by induction that � n � = λ fx . f ( � n − 1 � fx ) → β . . . → β λ fx . ( f n x )

  7. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx )

  8. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n �

  9. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx )

  10. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x )

  11. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x

  12. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 �

  13. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 � plus: λ pqfx . pf ( qfx ).

  14. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 � plus: λ pqfx . pf ( qfx ). ( λ pqfx . pf ( qfx )) � m �� n �

  15. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 � plus: λ pqfx . pf ( qfx ). ( λ pqfx . pf ( qfx )) � m �� n � → β ( λ qfx . � m � f ( qfx )) � n �

  16. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 � plus: λ pqfx . pf ( qfx ). ( λ pqfx . pf ( qfx )) � m �� n � → β ( λ qfx . � m � f ( qfx )) � n � → β ( λ fx . � m � f ( � n � fx ))

  17. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 � plus: λ pqfx . pf ( qfx ). ( λ pqfx . pf ( qfx )) � m �� n � → β ( λ qfx . � m � f ( qfx )) � n � → β ( λ fx . � m � f ( � n � fx )) ( λ fx . � m � f ( f n x )) → β

  18. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 � plus: λ pqfx . pf ( qfx ). ( λ pqfx . pf ( qfx )) � m �� n � → β ( λ qfx . � m � f ( qfx )) � n � → β ( λ fx . � m � f ( � n � fx )) ( λ fx . � m � f ( f n x )) → β ( λ fx . f m ( f n x )) → β

  19. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 � plus: λ pqfx . pf ( qfx ). ( λ pqfx . pf ( qfx )) � m �� n � → β ( λ qfx . � m � f ( qfx )) � n � → β ( λ fx . � m � f ( � n � fx )) ( λ fx . � m � f ( f n x )) → β ( λ fx . f m ( f n x )) → β ( λ fx . f m + n x ) =

  20. Encoding arithmetic functions . . . Successor ◮ succ ( n ) = n + 1 ◮ Define as λ pfx . f ( pfx ) ( λ pfx . f ( pfx )) � n � → β λ fx . f ( � n � fx ) → β λ fx . f ( f n x ) = λ fx . f n +1 x = � n +1 � plus: λ pqfx . pf ( qfx ). ( λ pqfx . pf ( qfx )) � m �� n � → β ( λ qfx . � m � f ( qfx )) � n � → β ( λ fx . � m � f ( � n � fx )) ( λ fx . � m � f ( f n x )) → β ( λ fx . f m ( f n x )) → β ( λ fx . f m + n x ) = � m + n � =

  21. Encoding arithmetic functions . . . ◮ If functions are applied to meaningful terms we get meaningful answers!

  22. Encoding arithmetic functions . . . ◮ If functions are applied to meaningful terms we get meaningful answers! Other functions: multiplication : λ pqfx . q ( pf ) x exponentiation : λ pq . ( pq )

  23. One step reduction ◮ Can have other reduction rules like β

  24. One step reduction ◮ Can have other reduction rules like β ◮ Observe that λ x . ( Mx ) and M are equivalent with respect to β -reduction

  25. One step reduction ◮ Can have other reduction rules like β ◮ Observe that λ x . ( Mx ) and M are equivalent with respect to β -reduction ◮ New reduction rule η λ x . ( Mx ) → η M

  26. One step reduction ◮ Can have other reduction rules like β ◮ Observe that λ x . ( Mx ) and M are equivalent with respect to β -reduction ◮ New reduction rule η λ x . ( Mx ) → η M ◮ Given basic rules β , η , . . . , we are allowed to use them “in any context”

  27. One step reduction ◮ Can have other reduction rules like β ◮ Observe that λ x . ( Mx ) and M are equivalent with respect to β -reduction ◮ New reduction rule η λ x . ( Mx ) → η M ◮ Given basic rules β , η , . . . , we are allowed to use them “in any context” ◮ Define a one step reduction relation → inductively ′ M → x M ′ M → M x ∈ { β, η, . . . }

  28. One step reduction ◮ Can have other reduction rules like β ◮ Observe that λ x . ( Mx ) and M are equivalent with respect to β -reduction ◮ New reduction rule η λ x . ( Mx ) → η M ◮ Given basic rules β , η , . . . , we are allowed to use them “in any context” ◮ Define a one step reduction relation → inductively ′ M → x M ′ M → M ′ M → M λ x . M → λ x . M ′ x ∈ { β, η, . . . }

  29. One step reduction ◮ Can have other reduction rules like β ◮ Observe that λ x . ( Mx ) and M are equivalent with respect to β -reduction ◮ New reduction rule η λ x . ( Mx ) → η M ◮ Given basic rules β , η , . . . , we are allowed to use them “in any context” ◮ Define a one step reduction relation → inductively ′ M → x M ′ M → M ′ M → M ′ M → M λ x . M → λ x . M ′ MN → M ′ N x ∈ { β, η, . . . }

  30. One step reduction ◮ Can have other reduction rules like β ◮ Observe that λ x . ( Mx ) and M are equivalent with respect to β -reduction ◮ New reduction rule η λ x . ( Mx ) → η M ◮ Given basic rules β , η , . . . , we are allowed to use them “in any context” ◮ Define a one step reduction relation → inductively ′ M → x M ′ M → M ′ M → M ′ N → N ′ M → M λ x . M → λ x . M ′ MN → M ′ N MN → MN ′ x ∈ { β, η, . . . }

  31. Computability ◮ Church numerals encode n ∈ N

  32. Computability ◮ Church numerals encode n ∈ N ◮ Can we encode computable functions f : N k → N ? ◮ Let � f � be the encoding of computable function f

  33. Computability ◮ Church numerals encode n ∈ N ◮ Can we encode computable functions f : N k → N ? ◮ Let � f � be the encoding of computable function f ◮ Want � f �� n 1 �� n 2 � . . . � n k � → ∗ � f ( n 1 , n 2 , . . . , n k ) �

  34. Computability ◮ Church numerals encode n ∈ N ◮ Can we encode computable functions f : N k → N ? ◮ Let � f � be the encoding of computable function f ◮ Want � f �� n 1 �� n 2 � . . . � n k � → ∗ � f ( n 1 , n 2 , . . . , n k ) � ◮ Note! currying . . .

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