lecture 1 combinatory logic and lambda calculus
play

Lecture 1: Combinatory Logic and Lambda Calculus H. Geuvers - PowerPoint PPT Presentation

Combinatory Logic Radboud University Lambda Calculus Lecture 1: Combinatory Logic and Lambda Calculus H. Geuvers Radboud University Nijmegen, NL 21st Estonian Winter School in Computer Science Winter 2016 H. Geuvers - Radboud Univ. EWSCS


  1. Combinatory Logic Radboud University Lambda Calculus Lecture 1: Combinatory Logic and Lambda Calculus H. Geuvers Radboud University Nijmegen, NL 21st Estonian Winter School in Computer Science Winter 2016 H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 1 / 39

  2. Combinatory Logic Radboud University Lambda Calculus Outline Combinatory Logic Lambda Calculus H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 2 / 39

  3. Combinatory Logic Radboud University Lambda Calculus Combinators Σ CL = { I , K , S , x , ′ , ) , ( , = } We introduce several simple grammars over Σ CL . • constant := I | K | S variable := x | variable ′ • term := constant | variable | ( term term ) • • formula := term = term Intuition: in ( F A ) the term F stands for a function and A for an argument H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 4 / 39

  4. Combinatory Logic Radboud University Lambda Calculus Combinatory Logic Axioms = ( I ) I P P K P Q = P ( K ) = P R ( Q R ) ( S ) S P Q R Deduction rules P = P P = Q ⇒ Q = P P = Q , Q = R ⇒ P = R P = Q ⇒ P R = Q R P = Q ⇒ R P = R Q Here P , Q , R denote arbitrary terms I P stands for ( I P ), K P Q for (( K P ) Q ) and S P Q R for ((( S P ) Q ) R ) In general P Q 1 . . . Q n ≡ ( .. (( P Q 1 ) Q 2 ) . . . Q n ) (association to the left) H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 5 / 39

  5. Combinatory Logic Radboud University Lambda Calculus Some conventions of Combinatory Logic Consider the term M P Q . • M P Q denotes ( M P ) Q and not! M ( P Q ) !! • First apply M to P and then the result is applied to Q . • You may view M P Q as the function M given two arguments, first P and then Q . • So an alternative writing for M P Q would be M ( P , Q ), but we will not write that! • M P Q can receive more arguments, e.g. P M , which is easy with the CL notation: M P Q ( P M ). • We write M = CL P or just M = P to denote that this equation is derivable from the axioms of Combinatory Logic using the derivation rules. • We write M ≡ P to denote that M and P are exactly the same terms. H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 6 / 39

  6. Combinatory Logic Radboud University Lambda Calculus Some magic with combinators Proposition. • Let D ≡ S I I . Then (doubling) D x = CL x x . • Let B ≡ S ( K S ) K . Then (composition) B f g x = CL f ( g x ) . • Let L ≡ D ( B D D ). Then (self-doubling, life!) L = CL L L . H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 7 / 39

  7. Combinatory Logic Radboud University Lambda Calculus Proof I Remember the Axioms I P = P ( I ) = ( K ) K P Q P S P Q R = P R ( Q R ) ( S ) Let D ≡ S I I . Then (doubling) D x = CL x x . Proof. D x ≡ S I I x = I x ( I x ) = x x . H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 8 / 39

  8. Combinatory Logic Radboud University Lambda Calculus Proof II Remember the Axioms = ( I ) I P P K P Q = P ( K ) = P R ( Q R ) ( S ) S P Q R Let B ≡ S ( K S ) K . Then (composition) B f g x = CL f ( g x ) . Proof. B f g x ≡ S ( K S ) K f g x = K S f ( K f ) g x = S ( K f ) g x = K f x ( g x ) = f ( g x ) . H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 9 / 39

  9. Combinatory Logic Radboud University Lambda Calculus Proof III Remember the Axioms = ( I ) I P P K P Q = P ( K ) S P Q R = P R ( Q R ) ( S ) Let L ≡ D ( B D D ). Then (self-doubling) L = CL L L . Proof. L ≡ D ( B D D ) = B D D ( B D D ) = D ( D ( B D D )) ≡ D L = L L . H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 10 / 39

  10. Combinatory Logic Radboud University Lambda Calculus Substitution Let M , L be terms and let x be a variable. The result of substitution of L for x in M , notation M [ x := L ] is defined by recursion on M . case for M definition of M [ x := L ] x L y y , provided x �≡ y C C (for C ∈ { I , K , S } ) P Q ( P [ x := L ]) ( Q [ x := L ]) Proposition If M = CL N, then M [ x := Q ] = CL N [ x := Q ] . Examples x I [ x := S ] ≡ S I . K I y x [ x := S ] ≡ K I y S . H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 11 / 39

  11. Combinatory Logic Radboud University Lambda Calculus First insight Combinatory Completeness Proposition. For every term P and variable x , there is a term F (where x does not occur in F ) such that F R = CL P [ x := R ] for every R . We denote this term F constructed in the proof as [ x ] P . Proof. Induction on the structure of P . Case 1. P ≡ x . Take [ x ] x ≡ I . Then ([ x ] x ) R ≡ I R = CL R = CL x [ x := R ] . Case 2. x / ∈ P . Take [ x ] P ≡ K P . Then indeed ([ x ] P ) R = CL K P R = CL P = CL P [ x := R ] . Case 3. P ≡ U V . Take [ x ]( U V ) ≡ S ([ x ] U ) ([ x ] V ). Then indeed ([ x ]( U V )) R ≡ S ([ x ] U ) ([ x ] V ) R = CL (([ x ] U ) R ) (([ x ] V ) R ) = CL ( U [ x := R ]) ( V [ x := R ]) = CL ( U V )[ x := R ] . � H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 12 / 39

  12. Combinatory Logic Radboud University Lambda Calculus Algorithms The previous proof gives the following algorithm P [ x ] P x I P with x / ∈ P K P U V S ([ x ] U ) ([ x ] V ) There are different possible algoritms. This is quite an efficient one. H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 13 / 39

  13. Combinatory Logic Radboud University Lambda Calculus Second insight Fixed Points Proposition. Every combinator has a fixed point: For every term P there exists a term X such that P X = CL X . Proof. Given P , define W := [ x ] P ( x x ) := W W . X Then X is a so called fixed point of P . X ≡ ([ x ] P ( x x )) W = CL P ( W W ) ≡ P X . Hence P X = CL X . L is a fixed point of D if one has L = D L = L L H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 14 / 39

  14. Combinatory Logic Radboud University Lambda Calculus Intended meaning of a λ -term The meaning of λ x . x 2 is the function → x 2 x �− that assigns to x the value x 2 ( x times x ) So according to this intended meaning we have ( λ x . x 2 )(6) = 6 2 = 36 . The parentheses around the 6 are usually not written: ( λ x . x 2 )6 = 36 Principal axiom is the β -eqality: ( λ x . M ) N = β M [ x := N ] H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 16 / 39

  15. Combinatory Logic Radboud University Lambda Calculus Language Alphabet: Σ = { x , ′ , ( , ) , ., λ, = } Language: the set of lambda terms, Λ: := x | variable ′ variable := variable | ( term term ) | ( λ variable . term ) term formula := term = term Theory (we often write just = for = β ) Axioms ( λ x . M ) N = β M [ x := N ] M = β M Rules M = β N ⇒ N = β M M = β N , N = β L ⇒ M = β L M = β N ⇒ ML = β NL M = β N ⇒ LM = β LN M = β N ⇒ λ x . M = β λ x . N H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 17 / 39

  16. Combinatory Logic Radboud University Lambda Calculus Substitution M M [ x := N ] x N y y ( P [ x := N ])( Q [ x := N ]) PQ λ x . P λ x . P λ y . P λ y . ( P [ x := N ]) where y �≡ x Application associates to the left P Q 1 . . . Q n ≡ ( . . . (( P Q 1 ) Q 2 ) . . . Q n ) . Abstraction associates to the right λ x 1 . . . x n . M ≡ ( λ x 1 . ( λ x 2 . ( . . . ( λ x n . M ) . . . )))) . Outer parentheses are often omitted. For example ( λ x . x ) y ≡ (( λ x . x ) y ) H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 18 / 39

  17. Combinatory Logic Radboud University Lambda Calculus Bound and free variables λ x . x and λ y . y acting on M both give M Renaming bound variables • In the term λ x . M , the ‘ λ x ’ binds the x in M . • Variables can occur free or bound. • We don’t want to distinguish between terms that only differ in their bound variables • We write M ≡ α N (or just M ≡ N ) if N arises from M by renaming bound variables Examples • λ x . x ≡ α λ y . y • λ x y . x ≡ α λ y x . y • λ x . ( λ x . x ) x ≡ α λ y . ( λ x . x ) y • ( λ x . ( λ y . x y )) x ≡ α ( λ z . ( λ y . z y )) x H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 19 / 39

  18. Combinatory Logic Radboud University Lambda Calculus Substution revisited • P [ x := N ] is only allowed if no free variable in N becomes bound after substitution. • Otherwise: rename bound variables first. ( λ x .λ y . x y ) ( y y ) = β ( λ y . x y )[ x := y y ] ( ≡ ?? λ y . y y y NO!! ) ≡ ( λ z . x z )[ x := y y ] ≡ λ z . y y z K y z ≡ ( λ x . ( λ y . x )) y z better: K y z ≡ ( λ x . ( λ y ′ . x )) y z = β ?? ( λ y . y ) z = β ( λ y ′ . y ) z = β z ?? = β y as it should. H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 20 / 39

  19. Combinatory Logic Radboud University Lambda Calculus Lambda Calculus subsumes Combinatory Logic I ≡ λ x . x ⇒ I M = β M K ≡ λ x y . x ⇒ K M P = β M S ≡ λ x y z . x z ( y z ) ⇒ S M P Q = β M Q ( P Q ) So we can define ( − ) λ : CL → Λ by ( M ) λ M λ x . x I K λ x y . x S λ x y z . x z ( y z ) P Q ( P ) λ ( Q ) λ Satisfying M = CL N ⇒ ( M ) λ = β ( N ) λ But not the other way around: S K I � = CL I , but in Λ we have ( S K I ) λ = β ( I ) λ . H. Geuvers - Radboud Univ. EWSCS 2016 CL and λ -calculus 21 / 39

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