lecture 2 self interpretation in the lambda calculus
play

Lecture 2: Self-interpretation in the Lambda-calculus H. Geuvers - PowerPoint PPT Presentation

Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Lecture 2: Self-interpretation in the Lambda-calculus H. Geuvers Radboud University Nijmegen, NL 21st Estonian Winter School in Computer


  1. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Lecture 2: Self-interpretation in the Lambda-calculus H. Geuvers Radboud University Nijmegen, NL 21st Estonian Winter School in Computer Science Winter 2016 H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 1 / 31

  2. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Outline Self-interpretation in the Lambda Calculus The limitations of Self-interpretation H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 2 / 31

  3. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation More on data types A data type D is a set with some operations (functions) on it. An k -ary operation is a function f : D k → D . Thereby a 0-ary operation c : D 0 → D is identified with a c ∈ D . A datatype is determined by its operations on D : D 0 → D = D c 1 , . . . , c k 0 : D 1 → D f 1 1 , . . . , f 1 : k 1 D 2 → D f 2 1 , . . . , f 2 : k 2 . . . Nat has z : Nat , s : Nat → Nat . Tree has l : Tree , j : Tree 2 → Tree H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 4 / 31

  4. � � � � � � � � Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Defining functions on data types in the lambda-calculus F λ -defines the function f : N → N if f ( n ) = F n for all n : f N N − − F Λ Λ Can we enode the λ -calculus in itself? F λ -defines the function f : Λ → Λ if f ( M ) = F M for all M ∈ Λ. f Λ Λ − − Is just the identity? F Λ Λ Why is this useful? H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 5 / 31

  5. � � � � Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Defining functions on codes of lambda-terms Some functions f : Λ → Λ can only be defined on codes of terms, not on terms. So we will need to talk about codes. f Λ Λ − − F Λ Λ Example. There is no λ -term F such that F ( M N ) = M for all M , N • There is a λ -term F such that F M N = M for all M , N . (With a suitable encoding − .) • We also have an evaluator E : E M = M H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 6 / 31

  6. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Packing and unpacking λ -terms Given M 1 , . . . , M k , define � M 1 , . . . , M k � := λ z . z M 1 . . . M k Define U k i , with 1 ≤ i ≤ k by U k := λ x 1 . . . x k . x i i Then U k i M 1 . . . M k = M i � M 1 , . . . , M k � U k U k = i M 1 . . . M k = M i i Note that K = U 2 1 H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 7 / 31

  7. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Second encoding of data types (B¨ ohm-Piperno-Guerini) Consider the data type D with c : D , f : D → D , g : D 2 → D The B¨ ohm-Piperno-Guerini coding (also denoted by t ) is λ e . e U 3 c = 1 e λ e . e U 3 f ( t ) = 2 t e λ e . e U 3 g ( t 1 , t 2 ) = 3 t 1 t 2 e Proposition. The constructors ( c , f , g ) can be λ -defined: There are lambda terms F , G such that = f ( t ) F t G t 1 t 2 = g ( t 1 , t 2 ) Proof. Take λ x e . e U 3 F := 2 x e λ x y e . e U 3 := 3 x y e . G � H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 8 / 31

  8. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Recursion Theorem. Given A 1 , A 2 , A 3 ∈ Λ there is an H ∈ Λ such that = H c A 1 H H ( f ( t ) ) = A 2 t H H ( g ( t 1 , t 2 ) ) = A 3 t 1 t 2 H Proof. Try H = �� B 1 , B 2 , B 3 �� . = �� B 1 , B 2 , B 3 �� c H c = c � B 1 , B 2 , B 3 � � B 1 , B 2 , B 3 � U 3 = 1 � B 1 , B 2 , B 3 � = B 1 � B 1 , B 2 , B 3 � = A 1 �� B 1 , B 2 , B 3 �� if B 1 := λ z . A 1 � z � = A 1 H � B 1 , B 2 , B 3 � U 3 H f ( t ) = 2 t � B 1 , B 2 , B 3 � = B 2 t � B 1 , B 2 , B 3 � = A 2 t H if B 2 := λ x z . A 2 x � z � H g ( t 1 , t 2 ) = A 3 t 1 t 2 H if B 3 := λ x y z . A 3 xy � z � . � H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 9 / 31

  9. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Data type for coding lambda terms To encode λ -terms we consider the data type D with var : D → D app : D → D → D abs : D → D • This data types is a bit strange: there is no base case. • It is a priori unclear how to encode the λ -terms in this data type. How to encode the variable binding? (Later slide.) Like before, we can define the constructors Var, App, Abs : λ x e . e U 3 := 1 x e Var λ x y e . e U 3 := 2 x y e App λ x e . e U 3 := 3 x e Abs H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 10 / 31

  10. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Recursion for the lambda terms data type Like before, we have a recursion theorem: Theorem I. Given A 1 , A 2 , A 3 ∈ Λ there is an H ∈ Λ such that H ( Var x ) = A 1 x H H ( App x y ) = A 2 x y H H ( Abs x ) = A 3 x H Proof. Take H = �� B 1 , B 2 , B 3 �� with B 1 := λ x z . A 1 x � z � := λ x y z . A 2 xy � z � B 2 B 3 := λ x z . A 3 x � z � . Then the equations hold indeed. � . (Exercise: Check this.) H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 11 / 31

  11. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Coding of lambda terms Coding lambda terms M � M Definition (Mogensen) The coding of λ -terms inside the λ -calculus is defined as follows. := x Var x MN := App M N λ x . M := Abs ( λ x . M ) A variable x is encoded using x itself and abstraction “ λ x . ” is encoded using the same abstraction “ λ x . ”. Note : coding is not λ -definable: there is no term C such that C M = M for all M . The reverse operation, evaluation, is λ -definable. H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 12 / 31

  12. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Self-interpretation Theorem. There exists a λ -term E (evaluator) such that for all M ∈ Λ E M = M Proof. By recursion we can find an E such that E ( Var x ) = x E ( App x y ) = E x ( E y ) E ( Abs x ) = λ z . E ( x z ) Then E ( x ) = E ( Var x ) = x E ( MN ) = E ( App M N ) = E M ( E N ) = MN E ( λ x . M ) = E ( Abs ( λ x . M )) = λ x . E M = λ x . M . Filling in the details of E one has (writing C := λ x y z . x z y ) E = �� K , S , C �� . � H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 13 / 31

  13. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Why is this encoding so cool? There are many encoding of Λ in itself. Why is this one so nice? • Older ones all go through a coding of λ -terms as numbers: − : Λ → N → Λ. This one is direct, uses λ for λ -abstraction. • E M ։ M , also for terms with free variables. • E = �� K , S , C �� , the initials of S.C. Kleene, one of the founders of the subject! • M 1 ≡ α M 2 ⇒ M 1 ≡ α M 2 . • M 1 ¬ ≡ α M 2 ⇒ M 1 � = β M 2 . • One can define a term R with R M ։ N , if M has N as normal form. • There is a Second Fixed Point Theorem (later) H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 14 / 31

  14. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Recursion for lambda terms using the encoding We can state the recursion theorem for the encoded lambda terms slightly differently, as follows. Theorem II. Given A 1 , A 2 , A 3 ∈ Λ there is an H ∈ Λ such that H x = A 1 x H H M N = A 2 M N H H λ x . M = A 3 ( λ x . M ) H Proof. According to Theorem I, there is an H satisfying H ( Var x ) = A 1 x H H ( App x y ) = A 2 x y H H ( Abs x ) = A 3 x H These equations immediately imply the ones of the statement of Theorem II (check this!), so the same H suffices. � . H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 15 / 31

  15. Self-interpretation in the Lambda Calculus Radboud University The limitations of Self-interpretation Application 1 If you see someone coming out of ‘arrivals’ in an airport, you cannot determine where he/she comes from. Similarly, there is no F such that for all X , Y ∈ Λ F ( X Y ) = X (Given the outcome of applying a function on an argument, there is no way we can determine the function that produced this outcome.) Proposition. There exists an F i ∈ Λ, i ∈ { 1 , 2 } such that F i X 1 X 2 = X i . Proof. We do this for i = 1. By the Recursion Theorem II, there exists F 1 s.t. X 2 F 1 = X 1 , taking A 2 = U 3 F 1 ( X 1 X 2 ) = A 2 X 1 1 . This suffices. � H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ -calculus 16 / 31

Recommend


More recommend