De Bruijn index

From Wikipedia, the free encyclopedia

The correct title of this article is de Bruijn index. It appears incorrectly here because of technical restrictions.

In mathematical logic, the de Bruijn index is a notation invented by the Dutch mathematician Nicolaas Govert de Bruijn (IPA: [dɪ bʁœyn]) for representing terms in the λ calculus.[1] Terms written using these indexes are invariant with respect to α conversion, so the check for α-equivalence is the same as that for syntactic equality. Each de Bruijn index is a natural numbers that represents an occurrence of a variable in a λ-term, and denotes the number of binders that are in scope between that occurrence and its corresponding binder. The following are some examples:

  • The term \lambda x.\ \lambda y.\ x, sometimes called the K combinator, is written as \lambda\;\lambda\;2 with de Bruijn indexes. The binder for the occurrence x is the second λ in scope.
  • The term \lambda x.\ \lambda y.\ \lambda z.\ x\;z\;(y\;z) (the S combinator), with de Bruijn indexes, is \lambda\;\lambda\;\lambda\;3\;1\;(2\;1).
  • The term \lambda z.\ (\lambda y.\ y\;(\lambda x.\ x))\;(\lambda x.\ z\;x) is \lambda\;(\lambda\;1\;(\lambda\;1))\;(\lambda\;2\;1).

De Bruijn indexes are commonly used in higher-order reasoning systems such as automated theorem provers and logic programming systems.[citation needed]

Contents

[edit] Formal definition

Formally, λ-terms (M, N, \ldots) written using de Bruijn indexes have the following syntax (parentheses allowed freely):

M, N, \ldots\ ::=\ n\ |\ M\;N\ |\ \lambda\;M

where nnatural numbers greater than 0 — are the variables. A variable n is bound if it is in the scope of at least n binders (λ); otherwise it is free. The binding site for a variable n is the nth binder it is in the scope of, starting from the innermost binder.

The most primitive operation on λ-terms is substitution: replacing free variables in a term with other terms. In the β-reduction (\lambda M)\;N, for example, we must:

  1. find the variables n_1, n_2, \ldots, n_k in M that are bound by the λ in λM,
  2. decrease the free variables of M to match the removal of the outer λ-binder, and
  3. replace n_1, \ldots, n_k with B, suitably increasing its free variables each time to match the number of λ-binders the correponding variable occurs under.

To illustrate, consider the application

(\lambda\;\lambda\;4\;2\;(\lambda\;1\;3))\;(\lambda\;5\;1)

which might correspond to the following term written in the usual notation

(\lambda x.\ \lambda y.\ z\;x\;(\lambda u.\ u\;x))\;(\lambda x.\ w\;x).

After step 1, we obtain the term \lambda 4\;\square\;(\lambda 1\;\square), where the variables that are substituted for are replaced with boxes. Step 2 lowers the free variables, giving \lambda 3\;\square\;(\lambda 1\;\square). Finally, in step 3 we replace the boxes with the argument; the first box is under one binder, so we replace it with \lambda 6\; 1 (which is \lambda 5\; 1 with the free variables increased by 1); the second is under two binders, so we replace it with \lambda 7\;1. The final result is \lambda 3\;(\lambda 6\;1)\;(\lambda 1\;(\lambda 7\;1)).

Formally, a substitution is an unbounded list of term replacements for the free variables, written M_1.M_2.\ldots, where Mi is the replacement for the ith free variable. The increasing operation in step 3 is sometimes called shift and written \uparrow^k where k is a natural number indicating the amount to increase the variables; \uparrow^k is thus a shorthand for the substitution k+1.k+2\ldots. Ths identity substitution that leaves a term unchanged is \uparrow^0, i.e., 1.2.\ldots.

The application of a substitution s to a term M is written M[s]. The sequencing of two substitions s1 and s2 is written simply s_1\ s_2, with

M [s_1\ s_2] = (M [s_1]) [s_2].

The rules for application are as follows:

\begin{align}   n [N_1\ldots N_n\ldots] =& N_n \\   (M_1\;M_2) [s] =&\ (M_1[s])\;(M_2[s]) \\   (\lambda M) [s] =&\ \lambda (M [1.1[s'].2[s'].3[s']\ldots]) \\                    &\ \hbox{where}\ s' = s \uparrow^1 \end{align}

The steps outlined for the β-reduction above are thus more concisely expressed as:

(\lambda\;M)\;N\ \ \longrightarrow_\beta\ \ M [N.1.2.3.\ldots].

[edit] Alternatives to de Bruijn indexes

When using the standard "named" representation of λ-terms, where variables are treated as labels or strings, one has to explicitly handle ά-conversion when defining any operation on the terms. The standard Variable Convention[2] of Barendregt is one such approach where ά-conversion is applied as needed to ensure that:

  1. bound variables are distinct from free variables, and
  2. all binders bind variables not already in scope.

In practice this is cumbersome, inefficient, and often error-prone. It has therefore led to the search for different representations of such terms. On the other hand, the named representation of λ-terms is more pervasive and can be more immediately understandable by others because the variables can be given descriptive names. Thus, even if a system uses de Bruijn indexes internally, it will present a user interface with names.

De Bruijn indexes are not the only representation of λ-terms that obviates the problem of ά-conversion. Among named representations, the nominal logic of Pitts is one approach, where the representation of a λ-term is treated as an equivalence class of all terms rewritable to it using variable permutations.[3] This approach is taken by the Nominal Datatype Package of Isabelle/HOL.[4]

Another common alternative is an appeal to higher-order representations where the λ-binder is treated as a true function. In such representations, the issues of ά-equivalence, substitution, etc. are identified with the same operations in a meta-logic.

[edit] See also

  • The de Bruijn notation for λ-terms. This notation has little to do with de Bruijn indexes, but the name "de Bruijn notation" is often (erroneously) used to stand for it.

[edit] References

  1. ^ De Bruijn, Nicolaas Govert (1972). "Lambda Calculus Notation with Nameless Dummies: A Tool for Automatic Formula Manipulation, with Application to the Church-Rosser Theorem". Indagationes Mathematicae 34: 381–392. ISSN 0019-3577. 
  2. ^ Barendregt, Henk P. (1984). The Lambda Calculus: Its Syntax and Semantics. North Holland. ISBN 0-444-87508-5. 
  3. ^ Pitts, Andy M. (2003). "Nominal Logic: A First Order Theory of Names and Binding". Information and Computation 186: 165–193. ISSN 0890-5401. 
  4. ^ Nominal Isabelle web-site. Retrieved on 2007-03-28.