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 Type Theory: From Lambda Calculus to a Classical Axiomatic System

Lean is an interactive theorem prover and functional programming language. Its central idea is that mathematical statements, proofs, programs, and types can all be represented within one formal system. Lean’s foundation is dependent type theory, a type theory in which types may depend on values.

Understanding Lean therefore requires understanding the layers from which its system is built:

  1. The untyped lambda calculus, which provides a model of computation.
  2. Simple type theory, which assigns types to expressions.
  3. Dependent type theory, in which types can depend on terms.
  4. Universes, which organize types and prevent paradoxes.
  5. The Curry–Howard correspondence, which connects propositions and types.
  6. Inductive types, which define data structures and logical constructions.
  7. Definitional equality, which determines when expressions count as interchangeable.
  8. Classical axioms, proof irrelevance, and quotient constructions.
  9. Metatheoretic properties such as normalization, consistency, soundness, and decidability.

Lean is based on a classical dependent type theory. It is closely related to the Calculus of Inductive Constructions, or CIC, associated with systems such as Coq, but it is not based on homotopy type theory. In particular, Lean includes proof irrelevance and classical principles that are incompatible with univalence in homotopy type theory.

The Untyped Lambda Calculus

The untyped lambda calculus is a very small formal system designed to describe computation. It was developed by Alonzo Church and has the same computational power as Turing machines.

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

  • A variable, such as xxx.
  • An application, written by placing two expressions next to each other, such as e1e2e_1 e_2e1​e2​.
  • A lambda abstraction, written λx. e\lambda x.\,eλx.e, which represents a function whose parameter is xxx and whose body is eee.

For example,

λx. x\lambda x.\,xλx.x

is the identity function: it takes an argument and returns that same argument.

An application such as

(λx. x) a(\lambda x.\,x)\,a(λx.x)a

means that the identity function is applied to aaa.

Beta Reduction

The central computation rule is beta reduction:

(λx. e) a  ⟶  e[a/x].(\lambda x.\,e)\,a \;\longrightarrow\; e[a/x].(λx.e)a⟶e[a/x].

The notation e[a/x]e[a/x]e[a/x] means that every appropriate free occurrence of xxx in eee is replaced by aaa. Thus,

(λx. x) a  ⟶  a.(\lambda x.\,x)\,a \;\longrightarrow\; a.(λx.x)a⟶a.

This operation is substitution. Substitution must respect bound variables so that a variable inside another lambda expression is not accidentally captured. For example, substitution requires care when the replacing expression contains variables that could become bound after replacement.

The reduction rules can be viewed as nondeterministic. If an expression contains several reducible applications, any one of them may be reduced first. Different reduction paths can therefore produce different intermediate expressions.

For example, an expression might reduce in one step at an outer application or in a separate step inside one of its arguments. Some reduction sequences may continue forever, while others may reach a normal form.

Confluence and the Church–Rosser Theorem

Although the lambda calculus can have multiple reduction paths, it has an important property called confluence.

If an expression eee can reduce to both e1e_1e1​ and e2e_2e2​, then there is some expression e′e'e′ such that both e1e_1e1​ and e2e_2e2​ can eventually reduce to e′e'e′:

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

imply

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.

This is the Church–Rosser theorem. It says that different choices of reduction order do not lead to permanently incompatible results. The system may fail to terminate, but if two reduction paths eventually reach normal forms, those normal forms agree.

Different evaluation strategies restrict which reduction is performed first. Examples include call-by-value and call-by-name. The unrestricted theory considers all possible reductions.

Key idea: Confluence guarantees agreement between successful reduction paths, but it does not guarantee that every reduction path terminates.

Think About It

Why can a computation still be useful if a formal system permits infinitely long reduction sequences? The important distinction is between the existence of some infinite paths and the behavior of the particular terms used in a program or proof.

Adding Simple Types

The untyped lambda calculus allows every expression to be applied to every other expression, including nonsensical applications such as applying a number to a function. Simple type theory restricts this by assigning types to expressions.

A basic simply typed system contains:

  • Function types, such as α→β\alpha \to \betaα→β.
  • At least one base type, represented here by ι\iotaι.

The base type is needed so that the theory contains some type at all. Without any primitive type, there would be no initial type from which to construct function types.

A lambda expression now carries a type annotation:

λx:α. e.\lambda x : \alpha.\,e.λx:α.e.

This means that xxx is assumed to have type α\alphaα.

Typing Contexts

Typing judgments have the general form

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

which means that, under the assumptions recorded in context Γ\GammaΓ, expression eee has type τ\tauτ.

A context is a collection of variable declarations, such as

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

The context records the types that are available for variables.

The Variable Rule

The variable rule says that a variable may be assigned the type recorded for it in the context:

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

In words, if the context contains the assumption that xxx has type τ\tauτ, then xxx has type τ\tauτ under that context.

The Application Rule

Suppose e1e_1e1​ is a function from α\alphaα to β\betaβ and e2e_2e2​ has type α\alphaα:

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

Then the application e1e2e_1 e_2e1​e2​ has type β\betaβ:

Γ⊢e1:α→βΓ⊢e2:αΓ⊢e1e2:β.\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. This is the basic mechanism by which the type checker rejects invalid applications.

The Lambda Rule

A lambda expression has a function type. If, after assuming that xxx has type α\alphaα, the body eee has type β\betaβ, then the lambda has type α→β\alpha \to \betaα→β:

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

For example, the identity function has type

λx:α. x:α→α.\lambda x : \alpha.\,x : \alpha \to \alpha.λx:α.x:α→α.

The body xxx has type α\alphaα because the context contains x:αx : \alphax:α.

Strong Normalization

Simple typing eliminates certain nonterminating expressions that exist in the untyped lambda calculus. In particular, expressions such as the YYY combinator do not receive valid simple types.

As a result, every well-typed term in the simply typed lambda calculus eventually reduces to a normal form. This property is called strong normalization.

Strong normalization is valuable because it ensures that well-typed computations cannot unfold forever. A type system can therefore act as a termination guarantee for the terms it accepts.

Key idea: Simple types do more than classify expressions. They restrict computation strongly enough to rule out certain infinite computations.

Dependent Function Types

Simple function types have the form

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

The result type β\betaβ is fixed and cannot refer to the particular input. Dependent type theory generalizes this by allowing the result type to depend on the argument.

A dependent function type is written

∀x:α,  β(x),\forall x : \alpha,\;\beta(x),∀x:α,β(x),

or, using the traditional notation,

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

The symbol Π\PiΠ is commonly called the dependent product or Pi type. The source uses “forall” and “Pi” interchangeably in this setting.

The essential difference is that β\betaβ may contain xxx. For example, the result type might describe a vector whose length is exactly the input number.

When the result does not depend on xxx, the dependent function type reduces to an ordinary function type:

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

behaves like

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

Dependent Application

For an ordinary function, applying a function of type α→β\alpha \to \betaα→β to an argument of type α\alphaα produces an expression of type β\betaβ.

For a dependent function, the result type must be specialized to the actual argument. If

e1:∀x:α,  β(x)e_1 : \forall x : \alpha,\;\beta(x)e1​:∀x:α,β(x)

and

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

then

e1e2:β(e2).e_1 e_2 : \beta(e_2).e1​e2​:β(e2​).

The type β(x)\beta(x)β(x) is obtained by substituting the argument e2e_2e2​ for xxx.

Dependent Lambda Abstraction

The lambda rule also becomes dependent. If assuming x:αx : \alphax:α allows the body eee to have type β(x)\beta(x)β(x), then

λx:α. e\lambda x : \alpha.\,eλx:α.e

has type

∀x:α,  β(x).\forall x : \alpha,\;\beta(x).∀x:α,β(x).

This makes it possible for a function to compute not only a value but also information about the type of its result.

Type-Level Computation

Dependent type theory allows expressions to occur in types. Consequently, computation can occur at the type level.

A function may take a type as an argument and return another type. For example, a polymorphic identity function should work for every type. To express this, the function must quantify over a variable whose value is itself a type.

That requires a type of types.

Universes and the Type Hierarchy

A naive system might introduce a single type called Type\mathsf{Type}Type and assert

Type:Type.\mathsf{Type} : \mathsf{Type}.Type:Type.

This is inconsistent. It enables a version of Russell’s paradox, leading to the conclusion that every proposition is inhabited, meaning that every proposition is provable. Such a system would no longer distinguish truth from falsehood.

Universe Levels

Lean avoids this circularity with a hierarchy of universes:

U0:U1,U1:U2,…\mathcal{U}_0 : \mathcal{U}_1, \qquad \mathcal{U}_1 : \mathcal{U}_2, \qquad \ldotsU0​:U1​,U1​:U2​,…

More generally,

Un:Un+1.\mathcal{U}_n : \mathcal{U}_{n+1}.Un​:Un+1​.

A universe at one level is itself an object in the next higher universe, but it is not an object of itself. This prevents the self-reference that causes the paradox.

Lean’s universe levels are not merely ordinary natural-number labels. They can contain universe expressions involving operations such as imax⁡\operatorname{imax}imax and universe variables. This supports definitions that are polymorphic over universe levels.

Universe Levels of Pi Types

If the domain lies in universe Um\mathcal{U}_mUm​ and the codomain lies in universe Un\mathcal{U}_nUn​, then the corresponding dependent function type normally lies in a universe determined by the larger level.

A simple version would use

max⁡(m,n).\max(m,n).max(m,n).

However, propositions receive special treatment, so Lean uses a modified operation called imax. It behaves like maximum except when the codomain universe is U0\mathcal{U}_0U0​:

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

while for positive codomain levels it behaves like the appropriate maximum.

This special behavior is connected to the impredicativity of the universe of propositions.

The Curry–Howard Correspondence

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

Under this correspondence:

  • A proposition is represented as a type.
  • A proof of that proposition is an element of the type.
  • A proposition is true when its type is inhabited.
  • A proposition is false when its type is empty.
  • A function from proofs of PPP to proofs of QQQ represents an implication P→QP \to QP→Q.
  • A dependent function represents universal quantification.

For example, a term of type

P→QP \to QP→Q

is a function that transforms a proof of PPP into a proof of QQQ. This is why the function arrow corresponds to material implication.

Similarly, a term of type

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

is a construction that gives a proof of P(x)P(x)P(x) for every x:αx : \alphax:α.

The Universe of Propositions

Lean treats propositions as belonging to a special lowest universe, commonly denoted

Prop=U0.\mathsf{Prop} = \mathcal{U}_0.Prop=U0​.

A proposition is therefore a type in U0\mathcal{U}_0U0​.

For example, natural numbers may belong to a higher universe such as U1\mathcal{U}_1U1​, while a proposition about natural numbers initially belongs to U0\mathcal{U}_0U0​. Without the special universe rule, combining a proposition with natural numbers could force the resulting proposition into U1\mathcal{U}_1U1​.

The imax⁡\operatorname{imax}imax rule prevents that elevation when the result is still a proposition. Thus a statement such as

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

remains a proposition in Prop\mathsf{Prop}Prop rather than becoming an ordinary higher-universe type.

This feature is called impredicativity. Informally, impredicativity allows a proposition to quantify over a collection that includes propositions, while still remaining in the universe of propositions.

Key idea: Universes prevent paradoxes, while impredicative Prop\mathsf{Prop}Prop allows logical statements to remain propositions even when they quantify over objects from higher universes.

Think About It

Why is an empty type a natural representation of a false proposition? If a proposition has no inhabitants, then there is no term that can serve as a proof of it.

Definitional Equality and Convertibility

Dependent types create a subtle problem. Two types may compute to the same result even when they are not written identically.

For example, suppose an identity function is applied to a type τ\tauτ:

(λx:U. x) τ.(\lambda x : \mathcal{U}.\,x)\,\tau.(λx:U.x)τ.

This expression is not textually identical to τ\tauτ, but beta reduction shows that it computes to τ\tauτ:

(λx:U. x) τ⟶τ.(\lambda x : \mathcal{U}.\,x)\,\tau \longrightarrow \tau.(λx:U.x)τ⟶τ.

Without a notion of convertibility, Lean might reject an application whose function expects an argument of type (λx. x) τ(\lambda x.\,x)\,\tau(λx.x)τ even though that type computes to τ\tauτ.

Lean therefore uses a definitional equality or convertibility judgment. If types α\alphaα and β\betaβ are definitionally equal, then an expression of type α\alphaα may be used where an expression of type β\betaβ is expected.

Definitional equality is not ordinary proved equality. It is built into type checking and is determined by the computational and structural rules of the theory.

Rules for Definitional Equality

Definitional equality has the usual properties of an equivalence relation:

  • Reflexivity: α\alphaα is definitionally equal to itself.
  • Symmetry: if α\alphaα is definitionally equal to β\betaβ, then β\betaβ is definitionally equal to α\alphaα.
  • Transitivity: if α\alphaα is definitionally equal to β\betaβ and β\betaβ is definitionally equal to γ\gammaγ, then α\alphaα is definitionally equal to γ\gammaγ.

It also has compatibility rules. If corresponding components of larger expressions are definitionally equal, then the larger expressions are definitionally equal as well.

For example, if α\alphaα is definitionally equal to α′\alpha'α′ and β\betaβ is definitionally equal to β′\beta'β′, then the corresponding function types are definitionally equal.

Beta and Eta Equality

The beta rule is the ordinary function-computation rule:

(λx. e) a≡e[a/x].(\lambda x.\,e)\,a \equiv e[a/x].(λx.e)a≡e[a/x].

The eta rule expresses extensionality for functions. If xxx does not occur freely in eee, then

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

The eta rule says that a function that merely takes an argument and passes it to eee is definitionally the same as eee itself.

Algorithmic Type Checking

The ideal definitional equality relation of the full theory is problematic: with all of Lean’s features combined, it is not decidable in general. That means there is no algorithm guaranteed to answer every definitional-equality question correctly and terminate.

Lean therefore uses an algorithmic typing judgment that underapproximates the ideal rules. The algorithm may reject an expression that is theoretically well typed because it declines to perform an extremely difficult or potentially nonterminating computation.

This practical approximation can produce a relation that is not fully transitive. In unusual cases, Lean may recognize one definitional-equality step and another separate step without recognizing the combined path.

Identity functions can sometimes expose the smaller steps:

id⁡γ(id⁡β(e)).\operatorname{id}_{\gamma} \bigl(\operatorname{id}_{\beta}(e)\bigr).idγ​(idβ​(e)).

The additional layers can guide the elaborator or type checker through conversions that it could not recognize as one large conversion.

However, these identity functions may act as computational blockers until they are unfolded carefully. In practical developments, ordinary propositional equality is often preferred when relying on definitional equality becomes fragile. Ordinary equality is proved and transported explicitly, while definitional equality is silently used by the type checker.

Subject Reduction

A typical type theory has subject reduction: if a well-typed term reduces, its reduct remains well typed. In the behavior discussed here, Lean’s virtual machine can evaluate terms in ways that do not directly preserve the formal typing discipline at every intermediate stage.

This makes the relationship between Lean’s kernel-level theory and its virtual-machine evaluation behavior particularly subtle.

Inductive Types

The next major feature is the ability to define inductive types. An inductive type is generated by constructors and is understood as the smallest type closed under those constructors.

The natural numbers are the fundamental example:

  • 000 is a natural number.
  • If nnn is a natural number, then succ⁡(n)\operatorname{succ}(n)succ(n) is a natural number.

Symbolically, the natural numbers can be viewed as the fixed point of a type expression resembling

T↦1+T,T \mapsto 1 + T,T↦1+T,

where the first alternative supplies zero and the second supplies a successor of an existing element.

The constructors are therefore

zero⁡:N\operatorname{zero} : \mathbb{N}zero:N

and

succ⁡:N→N.\operatorname{succ} : \mathbb{N}\to\mathbb{N}.succ:N→N.

The phrase “freely generated” means that natural numbers contain exactly the objects generated from zero and successor, without adding unrelated elements.

Logical Inductive Types

Inductive definitions can represent logical connectives.

Existential Quantification

An existential proposition can be represented by a constructor that takes:

  1. A witness xxx.
  2. A proof that P(x)P(x)P(x) holds.

The constructor then produces a proof of

∃x,  P(x).\exists x,\;P(x).∃x,P(x).

Because the type is generated by such witnesses, reasoning about an existential proof can proceed by examining its witness and its accompanying proof.

Conjunction

Conjunction has a constructor requiring both proofs:

P→Q→P∧Q.P \to Q \to P\land Q.P→Q→P∧Q.

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

Disjunction

Disjunction has two constructors:

P→P∨QP \to P\lor QP→P∨Q

and

Q→P∨Q.Q \to P\lor Q.Q→P∨Q.

An inhabitant records which side was supplied.

False and True

False is an inductive proposition with no constructors. Since there is no way to construct an element of it, it has no proofs.

True is an inductive proposition with exactly one constructor. That constructor supplies the unique proof of truth.

Recursors and Induction

Every inductive type generates not only its type and constructors but also a recursor. A recursor is a general mechanism for defining functions out of the inductive type.

For natural numbers, suppose there is a dependent family C(n)C(n)C(n) describing the desired output type for each natural number. If there is:

  • An element of C(0)C(0)C(0).
  • A way to produce an element of C(succ⁡(n))C(\operatorname{succ}(n))C(succ(n)) from an element of C(n)C(n)C(n).

Then there is an element of C(n)C(n)C(n) for every natural number nnn.

The recursor therefore captures both primitive recursion and mathematical induction.

Its computation rules state that:

  • The recursor applied to zero reduces to the base case.
  • The recursor applied to a successor reduces to the step function applied to the predecessor and the recursively computed result.

Schematically,

rec⁡(0)=c0\operatorname{rec}(0) = c_0rec(0)=c0​

and

rec⁡(succ⁡(n))=cs  n  (rec⁡(n)).\operatorname{rec}(\operatorname{succ}(n)) = c_s\;n\;(\operatorname{rec}(n)).rec(succ(n))=cs​n(rec(n)).

When the result family lies in Prop\mathsf{Prop}Prop, this recursor gives the ordinary induction principle for natural numbers, corresponding to the Peano induction axiom.

Key idea: An inductive type is defined by its constructors, and its recursor is what makes computation and induction possible.

Think About It

Why must an inductive type be the smallest type closed under its constructors? Without minimality, the type could contain arbitrary extra elements that do not arise from the intended data-generation process.

Strict Positivity

Inductive definitions cannot be completely unrestricted. Lean requires inductive specifications to be strictly positive.

Very roughly, the type being defined may not appear negatively inside a constructor argument. In particular, it cannot occur on the left side of the left side of an arrow in a way that allows the type to refer to itself contravariantly.

This restriction is needed for consistency. If arbitrary recursive occurrences were allowed, one could define a problematic type such as a type that contains functions from itself to a two-element type. Such a definition would yield an injection from the powerset of the type into the type itself, contradicting Cantor’s theorem.

Because Cantor’s theorem is provable, that contradiction would make the entire system inconsistent. Strict positivity prevents the problematic construction.

Inductive Families and Equality

An inductive family is an inductive type indexed by values. Equality is defined in this way.

For a fixed value xxx, equality at xxx has a constructor

refl⁡x:x=x.\operatorname{refl}_x : x = x.reflx​:x=x.

There is no primitive constructor directly producing an equality proof between arbitrary different values. Equality is generated from reflexivity.

The recursor for equality expresses the substitution principle:

If x=yx=yx=y and a property or type family CCC holds at xxx, then it holds at yyy.

This is the formal foundation for replacing equals by equals in dependent contexts.

Proof Irrelevance and Elimination Restrictions

Proof irrelevance says that proofs of propositions are treated as indistinguishable. If ppp and qqq are both elements of the proposition universe, then they are definitionally equal in the relevant sense:

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

This means that the identity of a proof object is ignored. Only the fact that the proposition is inhabited matters.

Proof irrelevance conflicts with the principles of homotopy type theory, especially univalence. Under univalence, certain equality types can have multiple unequal inhabitants. Proof irrelevance instead collapses proofs of propositions, so assuming both principles leads to inconsistency.

Subsingletons

A subsingleton is a type with at most one element. If an inductive proposition has at most one possible inhabitant, then treating its proofs as equal does not lose meaningful information.

However, not every proposition may be eliminated into arbitrary higher types. If an inductive proposition has multiple constructors or multiple ways to carry computational data, unrestricted elimination could allow proof information to be extracted in ways that conflict with proof irrelevance.

A small-eliminating proposition can be eliminated only into propositions.

A subsingleton-eliminating proposition may be eliminated into higher universes when its structure guarantees that it has at most one meaningful inhabitant. Equality is an important example: although equality lies in Prop\mathsf{Prop}Prop, its recursor can eliminate into arbitrary universes.

The accessibility predicate used to express well-foundedness is another important example discussed in this context. Its structure permits elimination into higher types because its nonrecursive arguments satisfy the relevant restrictions.

Additional Axioms and Classical Reasoning

Lean’s core type theory can be extended with axioms: terms introduced at specified types without computational interpretations.

Propositional Extensionality

Propositional extensionality states that propositions are equal when they imply each other.

If there are terms of types

P→QP\to QP→Q

and

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

then PPP and QQQ are identified as equal propositions:

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

This allows substitution of one proposition for the other in any context. It is weaker than full univalence but resembles a limited extensionality principle for the lowest universe.

Quotient Types

A quotient identifies elements according to an equivalence relation RRR. Instead of freely generating a type from constructors, a quotient generates it subject to the additional rule that related elements are identified.

A quotient typically provides:

  • A map placing elements into the quotient.
  • A lifting operation for defining functions out of the quotient.
  • A condition requiring the target function to respect the relation.

If aaa and bbb satisfy R(a,b)R(a,b)R(a,b), then a function defined on the quotient must assign them equal results.

Quotients are not simply propositions. The quotient of a type by the total relation produces a propositional-truncation-like object, but it need not have the same proof-irrelevance behavior as a proposition in Prop\mathsf{Prop}Prop.

Nonemptiness and Choice

For a type α\alphaα, the proposition Nonempty⁡(α)\operatorname{Nonempty}(\alpha)Nonempty(α) can be defined with a constructor of type

α→Nonempty⁡(α).\alpha \to \operatorname{Nonempty}(\alpha).α→Nonempty(α).

This proposition records only that some element of α\alphaα exists; it does not provide a computationally accessible element in the same way that an ordinary term of type α\alphaα does.

The axiom of choice supplies the reverse direction:

Nonempty⁡(α)→α.\operatorname{Nonempty}(\alpha)\to\alpha.Nonempty(α)→α.

This principle has no computational interpretation in the system under discussion. It is introduced to support classical mathematics. Together with the other classical principles, it yields the law of excluded middle, making Lean’s logic fully classical.

Undecidability of Definitional Equality

A surprising consequence of combining Lean’s features is that the ideal type system is not decidable in general.

The problematic combination involves:

  • Proof irrelevance.
  • Subsingleton elimination.
  • Recursive inductive propositions.
  • Definitional equality.

Accessibility

Consider an accessibility predicate Acc⁡<(x)\operatorname{Acc}_{<}(x)Acc<​(x), expressing that xxx is accessible with respect to a relation <<<. Its constructor says, informally:

If every y<xy<xy<x is accessible, then xxx is accessible.

This captures well-foundedness: elements are reachable from the bottom by repeatedly moving to smaller elements.

Because of the way its recursive argument appears, accessibility can be eliminated into arbitrary universes. Its recursor can therefore be used computationally even though accessibility is a proposition.

The crucial issue is that the proof of accessibility can be unfolded repeatedly without consuming a separate computational resource. A recursive proof object can effectively contain a route back to itself.

Encoding a Nondecidable Property

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

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

is not decidable. A typical example concerns whether a particular computation halts within nnn steps: each finite case can be checked, while the universal statement may not be decidable.

Under an inconsistent assumption such as a proof that a particular starting point is accessible with respect to a descending relation, one can define a function that:

  • Tests P(n)P(n)P(n).
  • Moves to the next natural number if P(n)P(n)P(n) holds.
  • Returns zero when P(n)P(n)P(n) fails.

Repeated reduction then searches through the values of PPP.

If every P(n)P(n)P(n) holds, the computation continues indefinitely. If some P(n)P(n)P(n) fails, the computation eventually reduces to zero. Thus a definitional-equality question can encode the nondecidable statement

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

or, equivalently, the failure of

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

The inconsistent assumption can be abstracted away with lambda abstraction, so the issue is not limited to an explicitly contradictory local context. The resulting definitional-equality problem remains equivalent to a nondecidable proposition.

Practical Consequences

Lean’s actual type-checking algorithm does not attempt to solve every ideal definitional-equality problem. It uses an underapproximation that may reject some theoretically valid conversions.

An alternative would be a semidecision procedure: it could keep reducing, eventually finding a proof of equality when one exists, but potentially run forever when equality does not hold.

To recover full decidability, one possible approach would be to restrict or remove subsingleton elimination, especially for recursive propositions such as accessibility. Equality might be treated more permissively because it lacks the same recursive structure. Such restrictions could preserve more practical behavior while preventing the nonterminating reduction mechanism.

A Set-Theoretic Model

Lean’s type theory admits a natural interpretation in set theory.

Under this interpretation:

  • A type is interpreted as a set.
  • A term of that type is interpreted as an element of the set.
  • A dependent function type is interpreted as a set of dependent functions.
  • A proposition is interpreted as either the empty set or a singleton set.

Because of proof irrelevance and classical principles, the model of Prop\mathsf{Prop}Prop has only two possibilities:

  • The empty set, representing false.
  • A singleton set, representing true.

Different proofs of the same true proposition are therefore interpreted as the same element.

Higher universes must be interpreted by very large sets closed under the relevant type-forming operations, including function types and inductive constructions. These are modeled using Grothendieck universes, associated with inaccessible cardinal assumptions.

Soundness

The soundness theorem states, in simplified form, that if

Γ⊢e:α,\Gamma \vdash e : \alpha,Γ⊢e:α,

then the interpretation of eee is an element of the interpretation of α\alphaα.

If two expressions are definitionally equal, then their interpretations are equal in the ordinary set-theoretic sense.

Soundness implies consistency: the system cannot prove a proposition whose interpretation is empty.

Unique Typing

Lean also has a unique typing property. If an expression has two types,

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

then the two types are definitionally equal:

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

This property ensures that an expression belongs to one well-defined universe level rather than several unrelated ones.

Lean’s lack of universe cumulativity helps preserve this result. In a cumulative system such as Coq’s universe treatment, a type may be viewed as belonging to higher universes through a subtyping-like relation without those universe levels being definitionally equal. The corresponding unique-typing statement is therefore more complicated.

What Cannot Generally Be Proved

The system has limits on what can be established internally.

Heterogeneous Equality

Heterogeneous equality compares terms that may have different types. A known limitation is that application does not generally preserve heterogeneous equality in the way it preserves ordinary homogeneous equality.

Equality of Types

It is generally difficult to prove that two types are unequal. For example, one cannot generally prove that Z\mathbb{Z}Z and N\mathbb{N}N are unequal merely from their definitions, nor can one prove that two separately declared but structurally identical copies of the natural numbers are unequal.

The two types may be shown to be isomorphic, but isomorphism is weaker than equality.

A reliable way to distinguish types is by cardinality. If two types have different cardinalities, they cannot be equal, because equality would preserve their cardinality. Apart from such structural differences, the theory may not provide enough information to prove that two types are distinct.

Virtual-Machine Evaluation and Type Erasure

Lean’s virtual machine does not always evaluate terms exactly according to the kernel’s formal reduction relation.

For example, when a term contains casts between types, the virtual machine may ignore those casts rather than fully reducing the corresponding equality recursors. During evaluation, it may therefore pass through intermediate representations that are not formally well typed in the strict kernel sense, while still producing the correct final result.

This behavior motivates a type-erasure map: a translation that removes type information and retains the computational content. A useful theory of erasure would explain why removing types preserves the result of execution.

Such a theory would also help justify virtual-machine overrides, in which one implementation is replaced by another implementation in the VM. The replacement should preserve observable computation.

Open Metatheoretic Questions

Several properties remain important goals for a complete understanding of Lean’s theory:

  • A full proof of strong normalization for the complete system.
  • A precise account of the VM’s evaluation behavior.
  • A formal theory of type erasure.
  • A formal correctness criterion for VM overrides.
  • A complete treatment of the relationship between algorithmic reduction and ideal definitional equality.

A restricted algorithmic reduction relation is expected to be strongly normalizing because it stops before reaching the problematic forms of unrestricted reduction. The challenge is to relate that practical relation rigorously to Lean’s full axiomatic system.

Comprehensive Review

Lean is built from the lambda calculus, but its type system transforms the computational foundation into a system for both programming and proving.

  • The untyped lambda calculus supplies variables, application, abstraction, substitution, and beta reduction.
  • Confluence, expressed by the Church–Rosser theorem, ensures that different successful reduction paths can be joined.
  • Simple types restrict invalid applications and provide strong normalization.
  • Dependent function types allow result types to depend on input values.
  • Universes organize types into levels and prevent the paradox caused by Type:Type\mathsf{Type}:\mathsf{Type}Type:Type.
  • Impredicative Prop\mathsf{Prop}Prop keeps logical statements in the proposition universe even when they quantify over higher-level objects.
  • The Curry–Howard correspondence identifies propositions with types and proofs with inhabitants.
  • Definitional equality lets Lean treat expressions as interchangeable when they compute or reduce to the same form.
  • Inductive types define data and logical constructions through constructors.
  • Recursors provide computation and induction principles for inductive types.
  • Strict positivity prevents inconsistent self-referential inductive definitions.
  • Proof irrelevance identifies proofs of propositions and explains restrictions on eliminating propositions into computational types.
  • Propositional extensionality, quotient types, and choice support classical mathematical reasoning.
  • The interaction of recursive propositions, proof irrelevance, and subsingleton elimination creates undecidability in ideal definitional equality.
  • Lean therefore uses an algorithmic approximation in practice.
  • A set-theoretic model supports soundness and consistency, while unique typing ensures that types have coherent universe levels.
  • Lean’s virtual machine adds a separate computational layer involving casts, erasure, and evaluation that is not identical to kernel reduction.

The central lesson is that Lean’s power comes from combining computation and logic in one typed language. That same combination creates delicate metatheoretic tradeoffs: richer dependent types provide expressive proofs and programs, while convertibility, proof irrelevance, classical axioms, and recursive elimination complicate normalization and decidability.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent