This repository contains code that formalizes the lambda calculus using de Bruijn indices. The main goal is to prove the Church–Rosser theorem, one of the most important and challenging results in lambda calculus.
Some lemmas required for key theorems were adapted from other lambda calculus formalizations, which are listed below:
- LeanScratch — Created by Chris Henson. This repository was my main reference for obtaining several lemmas.
- A Formalization of Typed and Untyped λ-Calculi in Coq and Agda2 — Created by Kazuhiko Sakaguchi, written in Rocq and Agda. I find this work particularly impressive.
De Bruijn indices provide a way to represent lambda calculus terms without naming bound variables.
Instead of using variable names, each variable is represented by a natural number that indicates how many binders (
Formally, the syntax of lambda terms using de Bruijn indices is defined as:
Here, variables are natural numbers, and each number refers to its binder according to its distance.
For example:
| Standard | de Bruijn |
|---|---|
The shifting operation is defined as an adjustment that increases the indices of free variables whose values are greater than or equal to the context
Here,
The substitution operation replaces all occurrences of a variable in a term with another term. Its formal definition is as follows:
In the case of an abstraction, we move one level deeper into the binding structure, so the context increases by one. That’s why we use
Additionally, we apply shifting to the term
The following function expresses a beta reduction step of the term
The beta reduction replaces the bound variable inside the abstraction
After substitution, the abstraction disappears — we have exited one binding level. Therefore, we apply unshifting to the resulting term to restore the correct indices.
Note: This function is used to inductively define the beta reduction relation.
- Write all definitions.
- Define the beta reduction and beta reduction relations.
- Show that parallel beta reduction satisfies the diamond property.
- Prove the Church-Rosser theorem.
- Writing a Blueprint.