1. Home
  2. Explore
  3. Computer Science
  4. Lean’s Dependent Type Theory

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Lean’s Dependent Type Theory

Lean’s Dependent Type Theory

Lean is an open-source interactive theorem prover and functional programming language. It is based on dependent type theory, which combines programming-language features with a logical system for expressing and checking mathematical proofs.

Lean supports:

  • Formalized mathematics, including the development of the mathlib library.

  • Functional programming and metaprogramming.

  • Theorem proving through type checking.

  • Classical reasoning, unlike intuitionistic type theories.

  • A type theory closely related to the Calculus of Inductive Constructions used by Coq.

Lean is not based on homotopy type theory. In particular, Lean includes proof irrelevance, which conflicts with important principles of homotopy type theory such as univalence.


Untyped Lambda Calculus

The untyped lambda calculus is a simple formal model of computation. It was developed by Alonzo Church and has the same computational power as Turing machines.

Syntax

An expression eee in the untyped lambda calculus has one of three forms:

  1. Variable

    • A variable such as xxx.

  2. Application

    • Two expressions placed next to each other: $$ e_1\ e_2 $$

    • This means that e1e_1e1​ is applied to e2e_2e2​.

  3. Lambda abstraction

    • A function: $$ \lambda x.\ e $$

    • The variable xxx is bound in eee.

The lambda abstraction represents a function whose parameter is xxx and whose body is eee.

Substitution and Bound Variables

Lambda calculus requires a primitive notion of:

  • Bound variables, which are variables introduced by a lambda.

  • Free variables, which occur without being bound.

  • Substitution, which replaces a variable with an expression.

Substitution must avoid accidentally capturing free variables. These details are shared with other formal systems involving binders.

Beta Reduction

The central computation rule is beta reduction:

(λx. e1) e2⟶e1[x:=e2](\lambda x.\ e_1)\ e_2 \longrightarrow e_1[x := e_2](λx. e1​) e2​⟶e1​[x:=e2​]

This rule replaces the parameter xxx in e1e_1e1​ with the argument e2e_2e2​.

Reduction can occur inside any application or subexpression. If a term contains several possible redexes, reduction is nondeterministic: different redexes may be reduced first.

A particular reduction strategy can impose restrictions such as:

  • Call-by-value: evaluate the argument before applying the function.

  • Call-by-name: substitute the argument without evaluating it first.

  • Full reduction: allow any available reduction.

The general reduction relation permits all possible reductions.

Confluence and the Church–Rosser Theorem

Lambda-calculus reduction is confluent. Informally, if a term reduces in different ways, the resulting terms can eventually be brought back together.

If

e⟶∗e1ande⟶∗e2,e \longrightarrow^{*} e_1 \qquad\text{and}\qquad e \longrightarrow^{*} e_2,e⟶∗e1​ande⟶∗e2​,

then there exists some term e′e'e′ such that

e1⟶∗e′ande2⟶∗e′.e_1 \longrightarrow^{*} e' \qquad\text{and}\qquad e_2 \longrightarrow^{*} e'.e1​⟶∗e′ande2​⟶∗e′.

Here, ⟶∗\longrightarrow^{*}⟶∗ means zero or more reduction steps.

Church–Rosser property: Different reduction paths from the same term can be joined at a common later term.

Confluence does not imply that reduction always terminates. A term may have an infinite reduction sequence.


Simply Typed Lambda Calculus

The simply typed lambda calculus adds a type system to the untyped lambda calculus.

Types

In the basic system, types include:

  • A base type of individuals, written ι\iotaι.

  • Function types:

    α→β\alpha \to \betaα→β

The base type is not mathematically essential, but without at least one primitive type, the system would contain no types at all.

Typing Contexts

A typing context Γ\GammaΓ records assumptions about variables. For example:

Γ=x:α, y:β\Gamma = x : \alpha,\ y : \betaΓ=x:α, y:β

A typing judgment has the form:

Γ⊢e:τ\Gamma \vdash e : \tauΓ⊢e:τ

This means that expression eee has type τ\tauτ under the assumptions in Γ\GammaΓ.

Variable Rule

If the context contains x:τx : \taux:τ, then xxx has type τ\tauτ:

x:τ∈ΓΓ⊢x:τ\frac{x : \tau \in \Gamma}{\Gamma \vdash x : \tau}Γ⊢x:τx:τ∈Γ​

This rule simply looks up the type of a variable in the context.

Application Rule

If e1e_1e1​ is a function from α\alphaα to β\betaβ, and e2e_2e2​ has type α\alphaα, then applying e1e_1e1​ to e2e_2e2​ produces a term of type β\betaβ:

Γ⊢e1:α→βΓ⊢e2:αΓ⊢e1 e2:β\frac{ \Gamma \vdash e_1 : \alpha \to \beta \qquad \Gamma \vdash e_2 : \alpha }{ \Gamma \vdash e_1\ e_2 : \beta }Γ⊢e1​ e2​:βΓ⊢e1​:α→βΓ⊢e2​:α​

The argument type must match the function’s domain.

Lambda Rule

A lambda abstraction has a function type. If, under the assumption that xxx has type α\alphaα, the body eee has type β\betaβ, then:

Γ,x:α⊢e:βΓ⊢λx:α. e:α→β\frac{ \Gamma, x : \alpha \vdash e : \beta }{ \Gamma \vdash \lambda x : \alpha.\ e : \alpha \to \beta }Γ⊢λx:α. e:α→βΓ,x:α⊢e:β​

The parameter annotation is what distinguishes this system from the untyped lambda calculus.

Strong Normalization

Simply typed lambda calculus has the property of strong normalization:

Every well-typed term eventually reduces to a normal form, regardless of the order in which reductions are performed.

This excludes nonterminating untyped terms such as the YYY combinator. Although the YYY combinator can be written in the untyped lambda calculus, it cannot receive a valid simple type.

Strong normalization prevents unrestricted self-application and infinite unfolding in the typed system.


Dependent Function Types

Dependent type theory extends ordinary function types so that the result type may depend on the argument.

Pi Types

An ordinary function type

α→β\alpha \to \betaα→β

can be viewed as a special case of a dependent function type:

∀x:α, β\forall x : \alpha,\ \beta∀x:α, β

This is also called a Pi type, commonly written:

Πx:α, β\Pi x : \alpha,\ \betaΠx:α, β

The crucial difference is that β\betaβ may contain the variable xxx.

For example, a function may return a vector whose length depends on the input natural number:

Πn:N, Vector n\Pi n : \mathbb{N},\ \mathrm{Vector}\ nΠn:N, Vector n

Dependent Application

If

e1:Πx:α, βe_1 : \Pi x : \alpha,\ \betae1​:Πx:α, β

and

e2:α,e_2 : \alpha,e2​:α,

then applying e1e_1e1​ to e2e_2e2​ gives:

e1 e2:β[x:=e2]e_1\ e_2 : \beta[x := e_2]e1​ e2​:β[x:=e2​]

The result type is obtained by substituting the argument e2e_2e2​ for xxx in β\betaβ.

Dependent Lambda Abstraction

The dependent lambda rule is:

Γ,x:α⊢e:βΓ⊢λx:α. e:Πx:α, β\frac{ \Gamma, x : \alpha \vdash e : \beta }{ \Gamma \vdash \lambda x : \alpha.\ e : \Pi x : \alpha,\ \beta }Γ⊢λx:α. e:Πx:α, βΓ,x:α⊢e:β​

Ordinary function types are recovered when xxx does not occur in β\betaβ.


Universes and Types as Expressions

Dependent type theory allows variables to range over types. To express polymorphic functions, the theory needs a type whose elements are themselves types.

A Universe of Types

Suppose there is a universe UUU such that:

U:UU : UU:U

Then a polymorphic identity function can be expressed as:

λα:U. λx:α. x\lambda \alpha : U.\ \lambda x : \alpha.\ xλα:U. λx:α. x

This function accepts a type α\alphaα and then returns the identity function on α\alphaα.

Combining Terms and Types

Initially, terms and types may be treated as separate syntactic categories. Dependent type theory combines them into one category of expressions.

An expression can therefore be:

  • A term.

  • A type.

  • A function that returns a type.

  • A type-level computation.

This permits computation at the type level. For example, a function can calculate a type based on an input value.

Dependent types: Types may depend on terms, allowing the type system to express precise relationships between data and proofs.

The primitive base type ι\iotaι becomes unnecessary once the theory has sufficiently many universes.


Why a Single Universe Is Inconsistent

The rule

U:UU : UU:U

is inconsistent. It leads to a version of Russell’s paradox.

If the universe of types is itself an element of that same universe, the system can construct a type corresponding to the collection of all types that do not contain themselves. This allows the derivation of contradictions.

Once contradiction is available, every proposition becomes provable. In logical terms, the system becomes trivial or inconsistent:

False⊢P\text{False} \vdash PFalse⊢P

for every proposition PPP.


A Hierarchy of Universes

Lean avoids this circularity by using a hierarchy of universes:

U0, U1, U2, …U_0,\ U_1,\ U_2,\ \ldotsU0​, U1​, U2​, …

Each universe is contained in the next level in the following sense:

Un:Un+1U_n : U_{n+1}Un​:Un+1​

Thus, no universe contains itself.

Universe Levels of Pi Types

If:

α:Umandβ:Un,\alpha : U_m \qquad\text{and}\qquad \beta : U_n,α:Um​andβ:Un​,

then a Pi type over α\alphaα with codomain β\betaβ belongs to a universe determined by the larger level:

Πx:α, β:Umax⁡(m,n)\Pi x : \alpha,\ \beta : U_{\max(m,n)}Πx:α, β:Umax(m,n)​

This prevents types from being assigned artificially low universe levels.


The Curry–Howard Correspondence

The Curry–Howard correspondence identifies propositions with types and proofs with terms.

Logic

Type theory

Proposition

Type

Proof of a proposition

Term inhabiting the type

Implication

Function type

Universal quantification

Pi type

False proposition

Empty type

True proposition

Inhabited type

A proposition is true when its corresponding type has an inhabitant.

Implication

The logical implication P→QP \to QP→Q corresponds to a function:

P→QP \to QP→Q

A proof of P→QP \to QP→Q is a function that transforms a proof of PPP into a proof of QQQ.

Universal Quantification

The logical statement

∀x:α, P(x)\forall x : \alpha,\ P(x)∀x:α, P(x)

corresponds to the dependent function type:

Πx:α, P(x)\Pi x : \alpha,\ P(x)Πx:α, P(x)

A proof supplies a proof of P(x)P(x)P(x) for every xxx.

Propositions as a Universe

Lean has a universe of propositions, usually called Prop, identified here with U0U_0U0​:

Prop=U0\mathrm{Prop} = U_0Prop=U0​

A proposition has type U0U_0U0​.


Impredicativity and the imax Universe Rule

If propositions were combined with ordinary universe formation using only max⁡\maxmax, a proposition such as

∀n:N, Even(n)∨Odd(n)\forall n : \mathbb{N},\ \mathrm{Even}(n) \lor \mathrm{Odd}(n)∀n:N, Even(n)∨Odd(n)

would be placed in a higher universe because N\mathbb{N}N belongs to a higher universe.

For example:

  • Even(n)∨Odd(n)\mathrm{Even}(n) \lor \mathrm{Odd}(n)Even(n)∨Odd(n) is a proposition in U0U_0U0​.

  • N\mathbb{N}N is a type in U1U_1U1​.

  • A naive maximum rule would place the entire universal proposition in U1U_1U1​.

This is undesirable because the result should still be a proposition.

Lean uses an imax operation instead of ordinary maximum. Informally:

imax⁡(m,0)=0\operatorname{imax}(m,0)=0imax(m,0)=0

and otherwise:

imax⁡(m,n)=max⁡(m,n)when n≠0.\operatorname{imax}(m,n)=\max(m,n) \qquad\text{when } n \neq 0.imax(m,n)=max(m,n)when n=0.

This allows a proposition to remain in the lowest universe even when it quantifies over objects from higher universes.

Impredicativity: A low-level universe of propositions can quantify over or depend on objects from higher universes while remaining itself in the lowest universe.

Impredicativity gives the logical system substantial expressive power.


Definitional Equality and Convertibility

Dependent type systems need more than syntactic equality. Two expressions may be different textually but become equal through computation.

The Conversion Problem

Consider a polymorphic identity function:

id:Πα:U, α→α\mathrm{id} : \Pi \alpha : U,\ \alpha \to \alphaid:Πα:U, α→α

Applying it to a type τ\tauτ produces:

id τ\mathrm{id}\ \tauid τ

The expression id τ\mathrm{id}\ \tauid τ is not syntactically identical to τ\tauτ, even though it computes to τ\tauτ.

Without a conversion rule, a function expecting an argument of type id τ\mathrm{id}\ \tauid τ would reject an argument having type τ\tauτ.

Conversion Rule

Lean therefore has a definitional equality or convertibility judgment. If:

α≡β\alpha \equiv \betaα≡β

then any term of type α\alphaα may also be treated as having type β\betaβ.

The conversion rule is:

Γ⊢e:αΓ⊢α≡βΓ⊢e:β\frac{ \Gamma \vdash e : \alpha \qquad \Gamma \vdash \alpha \equiv \beta }{ \Gamma \vdash e : \beta }Γ⊢e:βΓ⊢e:αΓ⊢α≡β​

Definitional equality is intended to capture equality by computation and structural principles.

Equivalence Properties

Definitional equality is reflexive, symmetric, and transitive:

  • Reflexivity: α≡α\alpha \equiv \alphaα≡α.

  • Symmetry: If α≡β\alpha \equiv \betaα≡β, then β≡α\beta \equiv \alphaβ≡α.

  • Transitivity: If α≡β\alpha \equiv \betaα≡β and β≡γ\beta \equiv \gammaβ≡γ, then α≡γ\alpha \equiv \gammaα≡γ.

Compatibility

Definitional equality is compatible with the structure of expressions. If corresponding parts are definitionally equal, then the larger expressions are also definitionally equal.

For example, if:

α≡α′andβ≡β′,\alpha \equiv \alpha' \qquad\text{and}\qquad \beta \equiv \beta',α≡α′andβ≡β′,

then:

Πx:α, β≡Πx:α′, β′.\Pi x : \alpha,\ \beta \equiv \Pi x : \alpha',\ \beta'.Πx:α, β≡Πx:α′, β′.

Beta Equality

Beta reduction becomes a definitional equality:

(λx. e1) e2≡e1[x:=e2](\lambda x.\ e_1)\ e_2 \equiv e_1[x := e_2](λx. e1​) e2​≡e1​[x:=e2​]

Eta Equality

The eta rule identifies a function with a lambda abstraction that immediately applies the function to its argument:

λx. e x≡e\lambda x.\ e\ x \equiv eλx. e x≡e

provided xxx does not occur free in eee.

Eta expresses the idea that a function is completely characterized by its behavior on an arbitrary argument.


Inductive Types

Inductive types provide a general mechanism for defining data types and propositions through constructors.

An inductive specification consists of a collection of labeled constructors. The inductive type is the smallest type freely generated by those constructors.

Natural Numbers

The natural numbers can be described by two constructors:

  • Zero:

    zero:N\mathrm{zero} : \mathbb{N}zero:N
  • Successor:

    succ:N→N\mathrm{succ} : \mathbb{N} \to \mathbb{N}succ:N→N

The natural numbers are the smallest type containing zero and closed under successor.

They can also be viewed as the least fixed point of the type expression:

T↦1+TT \mapsto 1 + TT↦1+T

where 111 represents the zero constructor.

Propositional Connectives as Inductive Types

Several logical connectives can be represented by inductive types.

Existential Quantification

An existential proposition can be formed using a dependent constructor:

intro:Πx:α, P(x)→∃x:α, P(x)\mathrm{intro} : \Pi x : \alpha,\ P(x) \to \exists x : \alpha,\ P(x)intro:Πx:α, P(x)→∃x:α, P(x)

An inhabitant consists of:

  1. A witness xxx.

  2. A proof that P(x)P(x)P(x) holds.

Because the existential type is inductively generated, elimination by cases is available.

Conjunction

Conjunction has one constructor requiring proofs of both components:

and_intro:P→Q→P∧Q\mathrm{and\_intro} : P \to Q \to P \land Qand_intro:P→Q→P∧Q

An inhabitant of P∧QP \land QP∧Q contains a proof of PPP and a proof of QQQ.

Disjunction

Disjunction has two constructors:

or_inl:P→P∨Q\mathrm{or\_inl} : P \to P \lor Qor_inl:P→P∨Q

and

or_inr:Q→P∨Q.\mathrm{or\_inr} : Q \to P \lor Q.or_inr:Q→P∨Q.

An inhabitant contains either a proof of PPP or a proof of QQQ.

False

False, or bottom, is an inductive proposition with no constructors:

⊥\bot⊥

Because it has no constructors, no term can inhabit it without additional inconsistent assumptions.

True

True is an inductive proposition with exactly one constructor. Its sole constructor serves as a proof of true.


Constructors and Recursors

Declaring an inductive type automatically provides:

  1. The type itself.

  2. Its constructors.

  3. A recursor or eliminator.

  4. Computation rules for the recursor.

Natural Number Recursor

For a dependent family C:N→UiC : \mathbb{N} \to U_iC:N→Ui​, suppose there are:

  • A base case:

    z:C(0)z : C(0)z:C(0)
  • A step case:

    s:Πn:N, C(n)→C(succ(n)).s : \Pi n : \mathbb{N},\ C(n) \to C(\mathrm{succ}(n)).s:Πn:N, C(n)→C(succ(n)).

Then the recursor produces:

natRec(C,z,s,n):C(n).\mathrm{natRec}(C,z,s,n) : C(n).natRec(C,z,s,n):C(n).

It computes according to the following rules:

natRec(C,z,s,0)≡z\mathrm{natRec}(C,z,s,0) \equiv znatRec(C,z,s,0)≡z

and

natRec(C,z,s,succ(n))≡s n (natRec(C,z,s,n)).\mathrm{natRec}(C,z,s,\mathrm{succ}(n)) \equiv s\ n\ \big(\mathrm{natRec}(C,z,s,n)\big).natRec(C,z,s,succ(n))≡s n (natRec(C,z,s,n)).

These are both reduction rules and definitional equalities.

The recursor supports:

  • Primitive recursive computation over natural numbers.

  • Proof by induction when the family CCC takes values in Prop.

Thus, the recursor embodies the Peano induction principle.


Strict Positivity

Inductive declarations must satisfy a strict positivity condition.

Meaning of Strict Positivity

The inductive type being defined may not occur negatively in an argument to a constructor. In particular, the type variable TTT may not occur on the left side of the left side of an arrow.

A problematic pattern would involve a constructor resembling:

(T→2)→T.(T \to 2) \to T.(T→2)→T.

This places TTT in a negative position.

Why Positivity Is Necessary

Allowing negative occurrences can produce contradictions. A bad inductive definition could give an injective function:

P(B)→B,\mathcal{P}(B) \to B,P(B)→B,

where P(B)\mathcal{P}(B)P(B) is the powerset of BBB.

Cantor’s theorem shows that no such injection can exist in the relevant setting. Therefore, permitting this inductive definition would allow the derivation of a contradiction.

Strict positivity ensures that inductive types have well-founded constructions and do not encode paradoxical self-reference.


Inductive Families and Equality

Lean also supports inductive families, whose types depend on indices.

Equality is defined as an inductive family. For a fixed xxx, equality with xxx is generated by a single constructor:

refl:x=x.\mathrm{refl} : x = x.refl:x=x.

There are no primitive constructors for arbitrary equalities x=yx = yx=y. All equality proofs arise from reflexivity and elimination.

Equality Elimination

The recursor for equality expresses substitution:

If:

x=yx = yx=y

and a property CCC holds of xxx, then CCC also holds of yyy.

Symbolically:

x=y→C(x)→C(y).x = y \to C(x) \to C(y).x=y→C(x)→C(y).

This is the basis of replacing equals by equals in dependent contexts.


Proof Irrelevance

Lean treats proofs in Prop as proof irrelevant.

If ppp and qqq are both proofs of the same proposition, then they are definitionally equal:

p≡q.p \equiv q.p≡q.

A type with at most one inhabitant is called a subsingleton.

Subsingleton: A type containing at most one element.

Proof irrelevance has important consequences:

  • Different proofs of the same proposition cannot be distinguished computationally.

  • All proofs of a proposition are treated as the same for definitional equality.

  • The theory cannot support homotopy type theory with univalence in its usual form.

Conflict with Univalence

Univalence implies that some equality types have multiple unequal inhabitants. Proof irrelevance instead identifies all proofs of a proposition.

Therefore, assuming univalence together with proof irrelevance leads to contradiction. In particular, univalence conflicts with:

  • Proof irrelevance.

  • Axiom K.

  • Definitional proof irrelevance.


Elimination Restrictions for Propositions

Because all proofs in Prop are identified, Lean restricts how certain propositions may be eliminated.

Small Eliminators

If an inductive proposition has multiple constructors or multiple possible proofs, its recursor may generally eliminate only into Prop.

Such a type is sometimes called a small eliminating type in this context.

For example, a proof of a disjunction contains information about which side was proven. Allowing unrestricted elimination from such a proof into arbitrary data types could expose computational distinctions that proof irrelevance says should not matter.

Subsingleton-Eliminating Types

Some propositions in Prop are permitted to eliminate into higher universes. This occurs when the proposition has a structure ensuring that its elimination does not reveal computationally distinguishable information.

Such types are called subsingleton-eliminating types.

The exact condition is technical. Roughly, nonrecursive arguments must themselves be propositions or must appear appropriately in the resulting target type.

Equality is an important example. Even though equality lies in Prop, its eliminator can be used into any universe because equality is generated by a single reflexivity constructor and behaves as a subsingleton.


Additional Axioms and Type Constructions

Lean’s core type theory can be extended with objects that inhabit specified types but do not have a computational interpretation.

Propositional Extensionality

Propositional extensionality states that logically equivalent propositions are equal.

If:

P→QP \to QP→Q

and

Q→P,Q \to P,Q→P,

then:

P=Q.P = Q.P=Q.

This permits propositions to be substituted for one another in all contexts.

It can be viewed as a weak, proposition-level analogue of univalence.

Quotient Types

A quotient identifies elements according to an equivalence relation rrr.

A quotient construction includes:

  • A constructor such as mk that maps an element to its equivalence class.

  • A lifting operation that allows functions to be defined on quotient classes.

  • A requirement that the function respect the relation rrr.

Unlike ordinary inductive types, quotients are not freely generated by their constructors. Elements are identified according to the specified relation.

Nonempty Propositions

For a type α\alphaα, Nonempty α is a proposition with a constructor of the form:

intro:α→Nonempty(α).\mathrm{intro} : \alpha \to \mathrm{Nonempty}(\alpha).intro:α→Nonempty(α).

Thus, Nonempty α asserts that α\alphaα has at least one element without providing computational access to a particular element.

Axiom of Choice

The axiom of choice supplies a function in the opposite direction:

Nonempty(α)→α.\mathrm{Nonempty}(\alpha) \to \alpha.Nonempty(α)→α.

This means that an inhabitance proof can be converted into an actual element.

This axiom has no computational interpretation in Lean. It is included to support classical mathematics.

Classical Logic

From the available classical axioms, Lean can derive the law of excluded middle:

P∨¬P.P \lor \neg P.P∨¬P.

Consequently, Lean’s logic is classical rather than intuitionistic.

The combination of:

  • Proof irrelevance.

  • Propositional extensionality.

  • Quotients.

  • Choice.

  • Excluded middle.

provides strong support for conventional classical mathematics but weakens the direct computational interpretation of proofs.


Undecidability of Definitional Equality

The ideal definitional equality relation in Lean is not decidable.

This is surprising because type checking is expected to be algorithmic. The source of the problem is the interaction between:

  • Dependent types.

  • Proof irrelevance.

  • Subsingleton elimination.

  • Recursive inductive propositions.

Accessibility

Consider an inductive proposition expressing accessibility with respect to a relation <<<.

Informally, an element xxx is accessible if every element smaller than xxx is accessible:

acc(x)if(Πy, y<x→acc(y)).\mathrm{acc}(x) \quad\text{if}\quad \left(\Pi y,\ y < x \to \mathrm{acc}(y)\right).acc(x)if(Πy, y<x→acc(y)).

This is a proposition with one constructor. It expresses well-foundedness: elements can be reached from smaller elements without an infinite descending chain.

Although acc lies in Prop, it can be subsingleton-eliminating because its recursive argument appears in the target appropriately.

The Inversion Function

From a proof of accessibility of xxx, one can derive accessibility of every smaller yyy:

invx:acc(x)→Πy, y<x→acc(y).\mathrm{inv}_x : \mathrm{acc}(x) \to \Pi y,\ y < x \to \mathrm{acc}(y).invx​:acc(x)→Πy, y<x→acc(y).

Because proofs of acc x are definitionally irrelevant, applying this inversion operation to the constructor can reduce definitionally back to the original proof.

This creates a form of reduction that can repeatedly unfold a recursive proof without consuming ordinary computational data.

Encoding an Undecidable Problem

Suppose P(n)P(n)P(n) is a decidable proposition for each natural number nnn, but the universal statement

∀n, P(n)\forall n,\ P(n)∀n, P(n)

is undecidable.

A typical example is whether a particular Turing machine halts within a given number of steps. Each finite-step question is decidable, but some corresponding universal statement is not.

A recursively defined function can inspect P(0),P(1),P(2),…P(0), P(1), P(2),\ldotsP(0),P(1),P(2),…:

  • If P(n)P(n)P(n) holds, it continues to the next number.

  • If P(n)P(n)P(n) fails, it reduces to zero.

Because accessibility proofs can be unfolded without ordinary fuel, this function can effectively search through all natural numbers.

Its definitional behavior can therefore depend on an undecidable proposition, such as:

∃n, ¬P(n)\exists n,\ \neg P(n)∃n, ¬P(n)

or equivalently the negation of ∀n, P(n)\forall n,\ P(n)∀n, P(n).

Thus, determining whether two terms are definitionally equal would solve an undecidable problem.

Conclusion: The full idealized definitional equality relation cannot be both complete and decidable in Lean’s system with these features.

Empty Contexts Do Not Avoid the Problem

The construction may initially assume an impossible accessibility proof. This does not make the issue irrelevant.

The assumed proof can be abstracted away:

λh0:acc(0), f 0 h0\lambda h_0 : \mathrm{acc}(0),\ f\ 0\ h_0λh0​:acc(0), f 0 h0​

and compared with:

λh0:acc(0), 0.\lambda h_0 : \mathrm{acc}(0),\ 0.λh0​:acc(0), 0.

These are functions from an empty type. They can be shown propositionally equal because their domain has no elements. However, they are definitionally equal exactly when the undecidable reduction condition holds.

Therefore, the phenomenon affects terms in ordinary contexts, not merely visibly inconsistent assumptions.


Lean’s Algorithmic Approximation

Since full definitional equality is undecidable, Lean uses an algorithmic typing and conversion procedure that underapproximates the ideal rules.

The algorithm may reject a term that is theoretically well typed because it does not perform arbitrarily complicated reductions.

Consequences include:

  • Lean may report that two terms are not definitionally equal even when the ideal relation would identify them.

  • The algorithmic approximation may fail to be transitive.

  • Completeness is sacrificed to preserve practical decidability.

This does not mean that the underlying mathematical theory has genuinely nontransitive definitional equality. Rather, the implemented approximation does not preserve every property of the ideal relation.

Identity-Function Workarounds

When Lean fails to see a large conversion path, identity functions can sometimes expose the intermediate steps:

idγ(idβ(e)).\mathrm{id}_\gamma(\mathrm{id}_\beta(e)).idγ​(idβ​(e)).

Adding identities at carefully chosen types can force Lean to check smaller conversions rather than one large conversion.

These identity functions can also act as reduction blockers. They may need to be unfolded carefully.

Proposition Equality as a Practical Alternative

When definitional equality becomes unstable or difficult to control, ordinary propositional equality can be used instead.

This is often more robust because ordinary equality does not depend on the exact unfolding behavior of definitions. However, in heavily dependent developments, replacing definitional equality with Leibniz equality can make dependent reasoning more cumbersome.

A practical design principle is therefore:

Avoid relying on definitional equality more than necessary, especially in complicated dependent constructions.

Possible Changes

If decidability were considered more important than unrestricted expressiveness, one possible change would be to restrict or eliminate subsingleton elimination.

A less damaging restriction might prohibit subsingleton elimination for recursive propositions such as accessibility while retaining it for nonrecursive propositions such as equality.

This could restore decidability but would affect some well-foundedness proofs and other developments that currently rely on recursive propositions eliminating into higher universes.

Alternatively, a stronger reduction procedure could be used as a semidecision procedure:

  • If two terms are definitionally equal, it eventually discovers the equality.

  • If they are not equal, it may run forever.

This would preserve more of the ideal theory but would not provide guaranteed termination.


Set-Theoretic Model of Lean

Lean admits a natural model in which:

  • Types are interpreted as sets.

  • Terms are interpreted as elements of those sets.

  • Dependent functions are interpreted as set-theoretic dependent functions.

Interpretation of Pi Types

A dependent function type

Πx:α, β(x)\Pi x : \alpha,\ \beta(x)Πx:α, β(x)

is interpreted as the set of functions fff such that:

  • The domain of fff is the interpretation of α\alphaα.

  • For every xxx in that domain, f(x)f(x)f(x) belongs to the interpretation of β(x)\beta(x)β(x).

ZFC set theory can express such functions as sets of ordered pairs.

Interpretation of Universes

Universes are interpreted using very large sets, specifically Grothendieck universes. These correspond to inaccessible cardinals and are closed under the constructions needed by the type theory, including:

  • Function types.

  • Dependent function types.

  • Inductive constructions.

  • Other universe-level operations.

If there are nnn inaccessible cardinals, one can model a finite hierarchy of nnn universes. If there are countably many inaccessible cardinals, one can model an infinite hierarchy.

Interpretation of Prop

Because Lean includes proof irrelevance, excluded middle, and choice, Prop is modeled in a highly collapsed way:

  • False is interpreted as the empty set.

  • True is interpreted as a singleton set containing one proof object.

All proofs of a given proposition are identified.

Different empty propositions may therefore be interpreted as the same empty set, and different singleton propositions may be interpreted as the same singleton set.

Models can be refined by adding tags to distinguish how types were constructed, provided that provably equal types are still identified.


Soundness

The soundness theorem connects Lean’s type theory to its set-theoretic model.

The main claims are:

  1. If: $$ \Gamma \vdash e : \alpha, $thentheinterpretationofthen the interpretation ofthentheinterpretationofeisanelementoftheinterpretationofis an element of the interpretation ofisanelementoftheinterpretationof\alpha$.

  2. If: $$ \Gamma \vdash \alpha \equiv \beta, $thenthenthen\alphaandandand\beta$ have the same interpretation as sets.

Soundness establishes that Lean does not prove false statements in the intended model. Therefore, Lean is consistent relative to the assumptions used to construct the model.


Unique Typing

Lean satisfies a unique typing theorem:

If an expression has two types, then those types are definitionally equal.

Formally, if:

Γ⊢e:αandΓ⊢e:β,\Gamma \vdash e : \alpha \qquad\text{and}\qquad \Gamma \vdash e : \beta,Γ⊢e:αandΓ⊢e:β,

then:

α≡β.\alpha \equiv \beta.α≡β.

Unique typing is important for interpreting terms in the set-theoretic model. A term must have one well-defined universe level rather than potentially living in unrelated universes.

Relation to Universe Levels

If:

α:Umandα:Un,\alpha : U_m \qquad\text{and}\qquad \alpha : U_n,α:Um​andα:Un​,

unique typing implies that:

Um≡Un.U_m \equiv U_n.Um​≡Un​.

The universe rules then imply that m=nm=nm=n.

Lean and Coq

This form of unique typing holds in Lean because Lean does not use universe cumulativity.

Coq has cumulativity, which permits a type in one universe to be treated as belonging to a larger universe through a subtyping-like relationship. As a result, the analogous unique-typing statement must be weakened or reformulated.


Additional Unprovability Results

Several distinctions that might seem natural cannot generally be proved within Lean’s theory.

Heterogeneous Equality

Heterogeneous equality compares terms that may have different types. A folklore result is that one cannot generally prove that function application preserves heterogeneous equality in the same straightforward way that it preserves ordinary homogeneous equality.

Equality of Types

It is usually impossible to prove that two types are unequal.

For example, it may not be possible to prove:

Z≠N\mathbb{Z} \neq \mathbb{N}Z=N

as type equality in the relevant internal sense.

Even if two inductive types are defined separately using identical constructors, such as N\mathbb{N}N and another independently defined copy N′\mathbb{N}'N′, the theory may not prove:

N≠N′.\mathbb{N} \neq \mathbb{N}'.N=N′.

It can often prove that the types are isomorphic, but isomorphism is weaker than equality.

Cardinality as a Distinguishing Method

The most direct way to prove that two types are unequal is to show that they have different cardinalities.

If:

A=B,A = B,A=B,

then AAA and BBB must have the same cardinality. Therefore, unequal cardinalities imply unequal types.

Beyond cardinality, distinguishing types internally is difficult because many syntactic differences disappear under the available equality principles and set-based models.


Lean’s Virtual Machine and Type Erasure

Lean’s virtual machine does not necessarily follow the formal reduction relation exactly.

Ignoring Casts

When the VM encounters casts between types, it may ignore them during evaluation rather than reducing the associated dependent recursor all the way to a reflexivity proof.

As a result, the VM may temporarily evaluate terms that are not well typed according to the strict formal reduction relation. Nevertheless, it is designed to produce the correct final computational result.

Type Erasure

A useful conceptual tool is a type-erasure map that removes type information from terms while preserving their computational behavior.

If type erasure preserves results, it could help explain why VM execution remains safe despite ignoring certain casts.

Such a theory would also support reasoning about VM overrides: replacing one definition with another implementation in the virtual machine while proving that the replacement preserves the original result.


Open Theoretical Questions

Several aspects of Lean’s theory require further formal analysis.

Strong Normalization

Strong normalization is well understood for various subsystems, especially in related systems such as Coq. A complete strong-normalization theorem for Lean’s full theory would be valuable.

The algorithmic reduction relation is expected to be strongly normalizing because it stops before reaching the problematic reductions associated with undecidable definitional equality.

Formalization

Because Lean is a formal theorem prover, important metatheoretic properties should themselves be formalized, including:

  • Soundness.

  • Strong normalization.

  • Type preservation.

  • Properties of algorithmic conversion.

  • The relationship between VM evaluation and formal reduction.

  • Correctness of VM overrides.


Key Relationships Among the Main Concepts

Dependent Types and Computation

Dependent types allow types to depend on terms. This enables precise specifications, but it also makes conversion and type checking more complicated because type checking may require computation.

Proof Irrelevance and Elimination

Proof irrelevance identifies all proofs of a proposition. To preserve this irrelevance, Lean restricts how many propositions can be eliminated into computational types.

Subsingleton Elimination and Undecidability

Subsingleton elimination is powerful because it allows certain propositions to eliminate into higher universes. When combined with recursive propositions such as accessibility, it can enable reductions that encode undecidable computations.

Definitional Equality and Type Checking

Definitional equality allows Lean to recognize terms as having compatible types when they compute to the same result. It is essential for dependent types, but the full relation is not decidable.

Classical Axioms and Computation

Choice and excluded middle support classical mathematics but do not have direct computational meanings. They weaken the interpretation of proofs as executable programs.

Set Models and Consistency

A set-theoretic interpretation provides a semantic model in which types are sets and terms are elements. Soundness with respect to this model establishes consistency relative to the model’s set-theoretic assumptions.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent