ArticleslgStudy

mathematics

De Bruijn index

De Bruijn index is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand De Bruijn index rather than just read about it. In short: In mathematical logic, the de Bruijn index is a tool invented by the Dutch mathematician Nicolaas Govert de Bruijn for representing terms of lambda calculus without naming the bound variables. Terms written using these indices are invariant with respect to α-conversion, so the check for α-equivalence is the same as that for syntactic equality.

De Bruijn index — main illustration
De Bruijn index — illustration

Key takeaways

  • De Bruijn index belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect De Bruijn index to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of De Bruijn index from memory before moving on to harder problems.

Reference excerpt

In mathematical logic, the de Bruijn index is a tool invented by the Dutch mathematician Nicolaas Govert de Bruijn for representing terms of lambda calculus without naming the bound variables. Terms written using these indices 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 number 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 λx. λy. x, sometimes called the K combinator, is written as λ λ 2 with de Bruijn indices. The binder for the occurrence x is the second λ in scope. The term λx. λy. λz. x z (y z) (the S combinator), with de Bruijn indices, is λ λ λ 3 1 (2 1). The term λz. (λy. y (λx. x)) (λx. z x) is λ (λ 1 (λ 1)) (λ 2 1). See the following illustration, where the binders are colored and the references are shown with arrows.

De Bruijn indices are commonly used in higher-order reasoning systems such as automated theorem provers and logic programming systems.

Formal definition Formally, λ-terms (M, N, ...) written using de Bruijn indices have the following syntax (parentheses allowed freely):

M, N, ... ::= n | M N | λ M where n—natural 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 (λ M) N, for example, we must

find the instances of the variables n1, n2, ..., nk in M that are bound by the λ in λ M, decrement the free variables of M to match the removal of the outer λ-binder, and replace n1, n2, ..., nk with N, suitably incrementing the free variables occurring in N each time, to match the number of λ-binders, under which the corresponding variable occurs when N substitutes for one of the ni. To illustrate, consider the application

(λ λ 4 2 (λ 1 3)) (λ 5 1) which might correspond to the following term written in the usual notation

(λx. λy. z x (λu. u x)) (λx. w x). After step 1, we obtain the term λ 4 □ (λ 1 □), where the occurrences of the variable that is being substituted are replaced with boxes. Step 2 decrements the free variables, giving λ 3 □ (λ 1 □). Finally, in step 3, we replace the boxes with the argument, namely λ 5 1; the first box is under one binder, so we replace it with λ 6 1 (which is λ 5 1 with the free variables increased by 1); the second is under two binders, so we replace it with λ 7 1. The final result is λ 3 (λ 6 1) (λ 1 (λ 7 1)). Formally, a substitution is an unbounded list of terms, written M1.M2..., where Mi is the replacement for the ith free variable. The increasing operation in step 3 is sometimes called shift and written ↑k where k is a natural number indicating the amount to increase the variables, and is defined by

↑k=(k+1).(k+2).... For example, ↑0 is the identity substitution, leaving a term unchanged. A finite list of terms M1.M2...Mn abbreviates the substitution M1.M2...Mn.(n+1).(n+2)... leaving all variables greater than n unchanged. The application of a substitution s to a term M is written M[s]. The composition of two substitutions s1 and s2 is written s1 s2 and is defined by

(M1.M2...) s = M1[s].M2[s]... satisfying the property

M [s1 s2] = (M [s1]) [s2], and substitution is defined on terms as follows:

n[N1…Nn…]=Nn(M1M2)[s]=(M1[s])(M2[s])(λM)[s]=λ(M[1.s′])where s′=s↑1 The steps outlined for the β-reduction above are thus more concisely expressed as:

(λ M) N →β M [N.1.2.3...].

Alternatives to de Bruijn indices When using the standard "named" representation of λ-terms, where variables are treated as labels or strings, one must explicitly handle α-conversion when defining any operation on the terms. 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 indices internally, it will usually present a user interface with names. An alternative way to view de Bruijn indices is as de Bruijn levels, which indexes variables from the bottom of the stack rather than from the top. This eliminates the need to reindex free variables, for example when weakening the context, whereas de Bruijn indices eliminate the need to reindex bound variables, for example when substituting a closed expression in another context. De Bruijn indices are not the only representation of λ-terms that obviates the problem of α-conversion. Among named representations, the nominal techniques of Pitts and Gabbay is one approach, where the representation of a λ-term is treated as an equivalence class of all terms rewritable to it using variable permutations. This approach is taken by the Nominal Datatype Package of Isabelle/HOL. 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. When reasoning about the meta-theoretic properties of a deductive system in a proof assistant, it is sometimes desirable to limit oneself to first-order representations and to have the ability to name or rename assumptions. The locally nameless approach uses a mixed representation of variables—de Bruijn indices for bound variables and names for free variables—that is able to benefit from the α-canonical form of de Bruijn indexed terms when appropriate.

Barendregt's variable convention Barendregt's variable convention is a convention commonly used in proofs and definitions where it is assumed that:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with De Bruijn index

Start with the simplest possible case. Write down what De Bruijn index claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to De Bruijn index before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about De Bruijn index ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of De Bruijn index

In research
De Bruijn index appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses De Bruijn index in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
De Bruijn index is common in secondary-school and first-year university syllabi. It links to neighbouring topics Lambda calculus, so understanding it makes those chapters shorter.
In everyday life
Look for De Bruijn index outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “De Bruijn index” →

How to study De Bruijn index in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what De Bruijn index means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain De Bruijn index out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is De Bruijn index in simple terms?

In mathematical logic, the de Bruijn index is a tool invented by the Dutch mathematician Nicolaas Govert de Bruijn for representing terms of lambda calculus without naming the bound variables. Terms written using these indices are invariant with respect to α-conversion, so the check for α-equivalen…

Why does De Bruijn index matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study De Bruijn index?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on De Bruijn index.

Tags

  • Lambda calculus

Keep exploring