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
mathliblibrary.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 e in the untyped lambda calculus has one of three forms:
Variable
A variable such as x.
Application
Two expressions placed next to each other: $$ e_1\ e_2 $$
This means that e1 is applied to e2.
Lambda abstraction
A function: $$ \lambda x.\ e $$
The variable x is bound in e.
The lambda abstraction represents a function whose parameter is x and whose body is e.
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:
This rule replaces the parameter x in e1 with the argument e2.
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
then there exists some term e′ such that
Here, ⟶∗ 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 ι.
Function types:
α→β
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 Γ records assumptions about variables. For example:
A typing judgment has the form:
This means that expression e has type τ under the assumptions in Γ.
Variable Rule
If the context contains x:τ, then x has type τ:
This rule simply looks up the type of a variable in the context.
Application Rule
If e1 is a function from α to β, and e2 has type α, then applying e1 to e2 produces a term of type β:
The argument type must match the function’s domain.
Lambda Rule
A lambda abstraction has a function type. If, under the assumption that x has type α, the body e has type β, then:
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 Y combinator. Although the Y 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
can be viewed as a special case of a dependent function type:
This is also called a Pi type, commonly written:
The crucial difference is that β may contain the variable x.
For example, a function may return a vector whose length depends on the input natural number:
Dependent Application
If
and
then applying e1 to e2 gives:
The result type is obtained by substituting the argument e2 for x in β.
Dependent Lambda Abstraction
The dependent lambda rule is:
Ordinary function types are recovered when x does not occur in β.
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 U such that:
Then a polymorphic identity function can be expressed as:
This function accepts a type α and then returns the identity function on α.
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 ι becomes unnecessary once the theory has sufficiently many universes.
Why a Single Universe Is Inconsistent
The rule
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:
for every proposition P.
A Hierarchy of Universes
Lean avoids this circularity by using a hierarchy of universes:
Each universe is contained in the next level in the following sense:
Thus, no universe contains itself.
Universe Levels of Pi Types
If:
then a Pi type over α with codomain β belongs to a universe determined by the larger level:
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→Q corresponds to a function:
A proof of P→Q is a function that transforms a proof of P into a proof of Q.
Universal Quantification
The logical statement
corresponds to the dependent function type:
A proof supplies a proof of P(x) for every x.
Propositions as a Universe
Lean has a universe of propositions, usually called Prop, identified here with U0:
A proposition has type U0.
Impredicativity and the imax Universe Rule
If propositions were combined with ordinary universe formation using only max, a proposition such as
would be placed in a higher universe because N belongs to a higher universe.
For example:
Even(n)∨Odd(n) is a proposition in U0.
N is a type in U1.
A naive maximum rule would place the entire universal proposition in U1.
This is undesirable because the result should still be a proposition.
Lean uses an imax operation instead of ordinary maximum. Informally:
and otherwise:
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:
Applying it to a type τ produces:
The expression id τ is not syntactically identical to τ, even though it computes to τ.
Without a conversion rule, a function expecting an argument of type id τ would reject an argument having type τ.
Conversion Rule
Lean therefore has a definitional equality or convertibility judgment. If:
then any term of type α may also be treated as having type β.
The conversion rule is:
Definitional equality is intended to capture equality by computation and structural principles.
Equivalence Properties
Definitional equality is reflexive, symmetric, and transitive:
Reflexivity: α≡α.
Symmetry: If α≡β, then β≡α.
Transitivity: If α≡β and β≡γ, then α≡γ.
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:
then:
Beta Equality
Beta reduction becomes a definitional equality:
Eta Equality
The eta rule identifies a function with a lambda abstraction that immediately applies the function to its argument:
provided x does not occur free in e.
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:NSuccessor:
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:
where 1 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:
An inhabitant consists of:
A witness x.
A proof that 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:
An inhabitant of P∧Q contains a proof of P and a proof of Q.
Disjunction
Disjunction has two constructors:
and
An inhabitant contains either a proof of P or a proof of Q.
False
False, or bottom, is an inductive proposition with no constructors:
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:
The type itself.
Its constructors.
A recursor or eliminator.
Computation rules for the recursor.
Natural Number Recursor
For a dependent family C:N→Ui, suppose there are:
A base case:
z:C(0)A step case:
s:Πn:N, C(n)→C(succ(n)).
Then the recursor produces:
It computes according to the following rules:
and
These are both reduction rules and definitional equalities.
The recursor supports:
Primitive recursive computation over natural numbers.
Proof by induction when the family C 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 T may not occur on the left side of the left side of an arrow.
A problematic pattern would involve a constructor resembling:
This places T in a negative position.
Why Positivity Is Necessary
Allowing negative occurrences can produce contradictions. A bad inductive definition could give an injective function:
where P(B) is the powerset of B.
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 x, equality with x is generated by a single constructor:
There are no primitive constructors for arbitrary equalities x=y. All equality proofs arise from reflexivity and elimination.
Equality Elimination
The recursor for equality expresses substitution:
If:
and a property C holds of x, then C also holds of y.
Symbolically:
This is the basis of replacing equals by equals in dependent contexts.
Proof Irrelevance
Lean treats proofs in Prop as proof irrelevant.
If p and q are both proofs of the same proposition, then they are definitionally equal:
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:
and
then:
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 r.
A quotient construction includes:
A constructor such as
mkthat 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 r.
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 α, Nonempty α is a proposition with a constructor of the form:
Thus, Nonempty α asserts that α 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:
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:
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 x is accessible if every element smaller than x is accessible:
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 x, one can derive accessibility of every smaller 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) is a decidable proposition for each natural number n, but the universal statement
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),…:
If P(n) holds, it continues to the next number.
If 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:
or equivalently the negation of ∀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:
and compared with:
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:
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
is interpreted as the set of functions f such that:
The domain of f is the interpretation of α.
For every x in that domain, f(x) belongs to the interpretation of β(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 n inaccessible cardinals, one can model a finite hierarchy of n 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:
If: $$ \Gamma \vdash e : \alpha, $thentheinterpretationofeisanelementoftheinterpretationof\alpha$.
If: $$ \Gamma \vdash \alpha \equiv \beta, $then\alphaand\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:
then:
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:
unique typing implies that:
The universe rules then imply that m=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:
as type equality in the relevant internal sense.
Even if two inductive types are defined separately using identical constructors, such as N and another independently defined copy N′, the theory may not prove:
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:
then A and B 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.