Gödelization in the lambda calculus

Gödelization in the lambda calculus

Information Processing Letters 75 (2000) 13–16 Gödelization in the lambda calculus ✩ Mayer Goldberg 1 Department of Computer Science, Ben Gurion Univ...

62KB Sizes 6 Downloads 197 Views

Information Processing Letters 75 (2000) 13–16

Gödelization in the lambda calculus ✩ Mayer Goldberg 1 Department of Computer Science, Ben Gurion University, Be’er Sheva 84105, Israel Received 13 July 1995; received in revised form 14 April 2000 Communicated by P.M.B. Vitányi

Abstract Gödelization is a meta-linguistic encoding of terms in a language. While it is impossible to define an operator in the lambda calculus which encodes all closed lambda expressions, it is possible to construct restricted versions of such an encoding operator modulo normalization. In this paper, we propose such an encoding operator for proper combinators.  2000 Elsevier Science B.V. All rights reserved. Keywords: Programming calculi; Lambda calculus; Gödelization

1. Prerequisites and notation We assume some familiarity with the untyped and simply typed λ-calculi [1,3]. The set of all terms generated by {M1 , . . . , Mn } is {M1 , . . . , Mn }+ [1, Item 8.1.1(i), p. 165]. The set of all λ-terms is denoted by Λ, the set of all closed λ-terms (combinators) is denoted by Λ0 . When n ranges over the integers, pnq denotes the nth Church numeral, and when M ranges over all λ-expressions, pMq denotes an encoding of M (see Section 2). The Church successor function is denoted by SuccChurch . The identity combinator is denoted by I . The ordered n-tuple is denoted by [x1 , . . . , xn ], and the kth projection function on an n-tuple is denoted by πkn . Since the definition of an ordered n-tuple and the respective projection functions play a role in the proof of Theorem 4.2, we give their definitions below: ✩ This work was carried out while visiting BRICS (Basic Research in Computer Science, Centre of the Danish National Research Foundation, URL: http://www.brics.dk/). 1 Email: [email protected].

[x1, . . . , xn ] = λx.(x x1 · · · xn )  πkn = λt. t (λx1 · · · xn .xk )

the ordered n-tuple. the kth projection.

2. Gödelization of lambda terms In this work, we make use of Gödelization of λterms. Gödelization is an effective injection that is used to encode terms in a language [1, Item 6.5.6, p. 143]. Gödelization takes its name from a particular encoding used by Kurt Gödel in his paper “On formally undecidable propositions of Principia Mathematica and related systems” [6]. In his paper, Gödel used prime numbers and the property of the uniqueness of prime factorization to encode and decode terms in the language he was considering (System P). Since Gödel’s paper, many alternative encodings have been devised, for various languages and contexts. For example, in the context of computer programs, a variety of data structures (lists, arrays, records) are used to represent the parse tree of a program, and thus provide an encoding that can be manipulated

0020-0190/00/$ – see front matter  2000 Elsevier Science B.V. All rights reserved. PII: S 0 0 2 0 - 0 1 9 0 ( 0 0 ) 0 0 0 7 1 - 5

14

M. Goldberg / Information Processing Letters 75 (2000) 13–16

conveniently by other programs (e.g., interpreters and compilers). A different encoding would be used for the language of the λ-calculus. For example, in his paper Efficient Self-Interpretation in Lambda Calculus [10], Torben Mogensen presents a novel encoding of λterms as λ-terms. It should be clear that in any specific setting we would try to select an encoding that is natural and easy to use in that setting. Throughout this work we denote the encoding of a λ-term M by pMq. We try to avoid any bias towards a particular encoding scheme because even though this work is cast in the λ-calculus, the techniques developed herein are also used for encoding actual computer programs [8].

3. Introduction As mentioned in Section 2, Gödelization is an effective injection that is used to encode terms in a language. It is possible to write a combinator Gödel in the λ-calculus, such that (Gödel pMq) = ppMqq.

(1)

Gödel is the same as Barendregt’s Num combinator [1, Item 6.5.9, p. 143]. Gödel does not map λ-expressions to their encodings, but rather encodings of λ-expressions to the encodings of their encodings. Indeed, it is impossible to define a combinator that maps λ-expressions to their encodings: Proposition 3.1. Gödelization is necessarily a metalinguistic notion in the λ-calculus, i.e., there exists no combinator G such that for any closed λ-term M we have (G M) = pMq.

(2)

Proof. Suppose G exists. Then  pI q = (G I ) = G (I I ) = p(I I )q, which is impossible by the Church–Rosser theorem. 2 In light of Proposition 3.1, we are only interested in encoding λ-terms that have a normal form (nf) and we consider this encoding to be modulo the normal form. But even modulo normalization, defining a Gödelization combinator is still a difficult problem, quite

different in nature from the combinator we considered in (1). As a milestone on the road to deciding the existence of an encoding combinator such as (2) for all terms modulo normalization, we consider a weaker notion, that of a partial Gödelizer: Definition 3.2 (A partial Gödelizer). Given a set S of combinators, we associate with each M ∈ S a λexpression IM (which is taken to be “information about M”). A λ-expression GS is said to be a partial Gödelizer for S if for each M ∈ S we have: (GS M IM ) = pMq.

(3)

A trivial partial Gödelizer might have S Λ0 , and  pMnf q if M has nf Mnf , (4) IM = p⊥q if M has no nf. The best possible Gödelizer we could hope for has S = Λ0 , and IM = p⊥q (i.e., IM provides the partial Gödelizer with no information), and  pMnf q if M has nf Mnf , (5) (GS M IM ) = p⊥q if M has no nf. The challenge is to find partial Gödelizers for large and interesting classes of combinators, while keeping the information that needs to be passed on to the partial Gödelizers as simple as possible, so as not to trivialize the task of encoding. To the best of our knowledge, the only partial Gödelizer in the λ-calculus is due to Berger and Schwichtenberg [2], and encodes simply-typed λexpressions, given an encoding of their type. Given a simply typed λ-expression M of type pτ q, we have: (Gst M pτ q) = pMq.

(6)

In the next section we construct a partial Gödelizer for the set of all proper combinators. This result is a part of our Ph.D. thesis [8]. 4. Gödelization of proper combinators Definition 4.1 (Proper combinators [1, p. 184, Problem 8.5.15], PC(n)). A proper combinator of arity n is a λ-expression λx1 · · · xn .B where B ∈ {x1 , . . . , xn }+ . The set of all proper combinators of arity n is PC(n). Note that some proper combinators are not simply typed. For example, (λx.xx) has no simple type.

M. Goldberg / Information Processing Letters 75 (2000) 13–16

Theorem 4.2. There exists GPC such that for any n > 1 and proper combinator P ∈ PC(n) we have: (GPC P pnq) = pP q.

(Var pnq) = pxn q, (Abs pxn q pMq) = p(λxn .M)q,

By defining Var, Abs, and App appropriately, we can obtain encodings of λ-expressions in terms of integers (e.g., Gödel’s original encoding), lists, strings, or any other data structure we might want to work with: For a programming language such as Scheme we use S-expressions to encode variables, abstractions and applications, while for the λ-calculus, Mogensen’s encoding [10] would be a natural choice. The structure of a proper combinator P ∈ PC(n) is λx1 · · · xn .Q, where Q ∈ {x1 , . . . , xn }+ . By applying P to n λ-terms M(Var px1 q) , . . . , M(Var pxn q) (i.e., terms indexed by an encoding of variables x1 , . . . , xn ) we substitute these terms for x1 , . . . , xn in the application Q. Let T = {M(Var pkq) }k6n . To obtain the encoding of M, we embed a computable applicative structure [9] in the term model of T ∪ {MN: M, N ∈ T}, such that (8)

Given this substitution, the application Q reduces to MpQq . In order to find terms that satisfy (8), we make use of the following property of the application of two ordered pairs (compare with Barendregt’s hint in his text on the λ-calculus, Problem 6.8.15(ii) [1, p. 149]):   [a1 , b1 ] [a2, b2 ] → (λx.(x a1 b1 )) (λx.(x a2 b2 ))  → (λx.(x a2 b2 )) a1 b1 → (a1 a2 b2 b1 ).

(9)

(12)

which is how we encode the applicative structure. We can always extract the encoding of the application by taking the second projection:   (13) π22 RpMq = π22 [R, pMq]

(7)

(App pMq pNq) = p(M N)q.

MpRq MpSq = Mp(App R S)q .

If we parameterize the ordered pairs in the above equation by their second tuple, the equation transforms into (RpMq RpNq ) = RpMN q

Proof. We assume the existence of combinators Var, Abs, and App for encoding variables, abstractions and applications. Specifically:

15

= pMq.

(14)

Now pick a proper combinator in PC(n), P = λx1 · · · xn .B, where B ∈ {x1 , . . . , xn }+ . We obtain pBq as follows:  π22 (P R(Var p1q) · · · R(Var pnq) )  = π22 (P [R, (Var p1q)] · · · [R, (Var pnq)]) (15)  (16) = π22 [R, pBq] = pBq.

(17)

This solves the main problem in defining GPC , i.e., the construction of the body of a proper combinator of arity n. What remains is to wrap encodings of abstractions of the n variables around the encoding of the body. The technique we use is similar to that by Church to derive a definition for the predecessor function [3, Chapter III, §9, p. 31]: Let Ak = λx. Abs (Var p1q) .. .

  Abs (Var pkq) x · · · ,

Pk = P [R, (Var p1q)] .. .  [R, (Var pkq)] .

(18)

(19)

The function f maps [pk + 1q, Pk , Ak ] to [pk + 2q, Pk+1 , Ak+1 ]. We define f as follows:  f = λt. (SuccChurch (π13 t)), (π23 t [R, (Var (π13 t))]),

In particular, we have:  [R, a] [R, b] = (R R b a).

(10)

By choosing R = λrba.[r, (App a b)], we have    [R, pMq] [R, pNq] = R, p(M N)q .

(11)

 (λx.(π33 t (Abs (Var (π13 t))))) .

(20)

The nth composition of f applied to the triple [p1q, P0 = P , A0 = I ] reduces to the triple [pn + 1q, Pn , An ]. We get pP q by applying An to the second

16

M. Goldberg / Information Processing Letters 75 (2000) 13–16

projection of Pn . A definition for GPC is obtained by abstracting over the proper combinator P and the Church numeral n: GPC = λpn. (λt.(π33 t (π22 (π23 t))))  (n f [p1q, p, I ]) .

to thank Professor Hendrik P. Barendregt for suggesting an improvement to the argument in Proposition 3.1. Thanks are also due to Olivier Danvy, Daniel P. Friedman, Julia L. Lawall, and Larry Moss for their comments and encouragement.

(21)

We now have for all n > 1 and for any proper combinator P = λx1 · · · xn .B ∈ PC(n). This completes our derivation. 2 5. Conclusion Proposition 3.1 shows that no Gödelizer for Λ0 exists, that takes no additional information about the expression it is encoding. Consequently, we consider partial Gödelizers, operating on specific subsets of Λ0 and taking some information about the expressions they are encoding. Berger and Schwichtenberg [2] have constructed a partial Gödelizer which encodes simply-typed λ-expressions, given an encoding of their type. In this paper, we have shown that a partial Gödelizer GPC exists for proper combinators, given their arity. The fact that Gödelization is taken modulo the normal form results in a normalization effect which has been exploited in proof theory [2, Section 7], and in partial evaluation [5]. We have coded the definition for GPC into the programming language Scheme [4], and have used it to visualize the source code (modulo normalization and α-equivalence) of compiled code. See BRICS technical report RS-96-5 [7].

Acknowledgements I am grateful to BRICS 2 for hosting me and for providing a stimulating environment. I would like

2 Basic Research in Computer Science, Centre of the Danish National Research Foundation.

References [1] H.P. Barendregt, The Lambda Calculus, Its Syntax and Semantics, North-Holland, Amsterdam, 1984. [2] U. Berger, H. Schwichtenberg, An inverse of the evaluation functional for typed λ-calculus, in: Proc. 6th Annual IEEE Symposium on Logic in Computer Science, Amsterdam, July 1991, pp. 203–211. [3] A. Church, The Calculi of Lambda-Conversion, Princeton University Press, Princeton, NJ, 1941. [4] W. Clinger, J. Rees (Eds.), Revised report on the algorithmic language Scheme, LISP Pointers IV (3), 1991, pp. 1–55. [5] O. Danvy, Type-directed partial evaluation, in: J. Hatcliff, T.Æ Mogensen, P. Thiemann (Eds.), Partial Evaluation— Practice and Theory; Proceedings of the 1998 DIKU Summer School, Copenhagen, Denmark, Lecture Notes in Comput. Sci., Vol. 1706, Springer, Berlin, 1998, pp. 367–411. Extended version available as the lecture notes BRICS LN-98-3. [6] K. Gödel, Über formal unentscheidbare Sätze der Principia Mathematica und verwandter Systeme, Monatshefte für Mathematik und Physik 38 (1931) 173–198. [7] M. Goldberg, Gödelization in the λ-calculus (extended version), BRICS Research Series RS-96-5, Department of Computer Science, University of Aarhus, Denmark, March 1996. A revision of BRICS report RS-95-38. [8] M. Goldberg, Recursive application survival in the λ-calculus, Ph.D. Thesis, Department of Computer Science, Indiana University, Bloomington, IN, 1996. [9] J.C. Mitchell, Foundations of Programming Languages, MIT Press, Cambridge, MA, 1996. [10] T.Æ. Mogensen, Efficient self-interpretation in lambda calculus, Funct. Programming 2 (3) (1992) 345–364.