3. Projects
In addition to the exercise sheets, which run through the whole semester, every student works on an individual project: pick a topic, formalize it in Lean, and present the result. Every project should take about 90 hours. Seven suggestions follow, each with a description, a sketch of one implementation, comments and references.
You are equally welcome to propose a topic of your own, for example an exercise from your first year of studies or a corner of Mathlib that interests you, as long as you discuss the scope with us first.
3.1. Project 1: The natural numbers, Lean against Peano
What it is. In Lean, Nat is an inductive type with two
constructors, zero and succ (chapter 1.1). Peano's
axiomatization of 1889 has five axioms:
-
0is a natural number. -
Every natural number
nhas a successorsucc n. -
0is not the successor of any natural number. -
succis injective. -
Induction: a property that holds for
0, and forsucc nwhenever it holds forn, holds for every natural number.
The project shows how the two sides come together. In one direction,
the two constructors and the recursor Nat.rec give all five axioms.
In the other, any type satisfying the five axioms is equivalent to
Nat.
Implementation idea.
-
From
Natto Peano. Axioms 1 and 2 are the constructors. Prove 3 and 4 by hand, withoutNat.succ_ne_zeroandNat.succ_injective. This needs the fact that constructors are distinct and injective, which Lean derives from the recursor (Nat.noConfusion, or the tacticscasesandinjection). Axiom 5 isNat.recwith a motive inProp. -
From Peano to
Nat. Package the axioms as a structure:structure Peano where N : Type zero : N succ : N → N succ_ne_zero : ∀ n, succ n ≠ zero succ_inj : ∀ m n, succ m = succ n → m = n ind : ∀ P : N → Prop, P zero → (∀ n, P n → P (succ n)) → ∀ n, P nThe map
Nat → Nis defined by recursion onNat. The map back is the main work:indonly proves propositions, it does not define functions. You need Dedekind's recursion theorem (1888): for everya : Xandf : X → Xthere is exactly oneg : N → Xwithg zero = aandg (succ n) = f (g n). Prove it fromind, for example by buildinggas a relation and showing by induction that it is the graph of a function. Then constructN ≃ ℕ. -
Which axiom is used where? Drop axiom 3, 4 or 5 and give a model of the remaining axioms that is not equivalent to
Nat:Fin 1withsucc 0 = 0;Fin 2withsuccconstantly1;ℕ ⊕ ℤwithsuccon both summands.
Comments and extensions.
-
Lean's
Nat.rechas a motiveℕ → Sort u, so it defines functions as well as proving statements. Peano's axiom 5 is the weaker,Prop-valued half. The recursion theorem is exactly the gap between the two. -
Uniqueness: show that the equivalence commutes with
zeroandsuccand that there is only one such map. In the language of category theory:Natis an initial algebra. -
Transport addition and multiplication to
Nwith the recursion theorem and prove that the equivalence respects them. -
indquantifies over all predicates, so it is a second-order axiom; that is why any two models are equivalent. First-order Peano arithmetic has non-standard models. Explain the difference in the write-up.
References. Dedekind, Was sind und was sollen die Zahlen? (1888),
§ 126 for the recursion theorem; Peano, Arithmetices principia
(1889). Avigad et al. (2024)Jeremy Avigad, Leonardo de Moura, Soonho Kong, and Sebastian Ullrich, 2024. “Theorem Proving in Lean 4”. In Online textbook. describes how Lean generates
Nat.rec and Nat.noConfusion.
3.2. Project 2: The integers, defined in several ways (reserved)
What it is. There are several reasonable definitions of ℤ, and
each makes different things easy. The project builds at least three
of them, proves that they are isomorphic rings, and compares them.
-
Quotient.
ℕ × ℕmodulo(a, b) ∼ (c, d) ↔ a + d = b + c; the pair(a, b)stands fora - b. This is the standard construction from a first-year course, and it uses quotient types and the axiomQuot.sound. -
Inductive, as in Lean. Two constructors
ofNat n(forn) andnegSucc n(for-(n + 1)). Every integer has exactly one representation, so equality is decidable and#evalworks. -
Normal forms. The subtype of pairs
(a, b) : ℕ × ℕwitha = 0 ∨ b = 0, i.e. one chosen representative from each class of 1.
Optional fourth: an inductive type zero | pos (n : ℕ+) | neg (n : ℕ+)
(sign and absolute value).
Implementation idea. For the quotient: prove that the relation is
an equivalence, set MyInt := Quotient of the setoid, and lift 0,
1, addition, negation and multiplication with Quotient.map₂ and
Quotient.lift, each time proving that the operation respects the
relation (multiplication is the interesting case). Then build a
CommRing instance; the ring laws reduce to ring or omega on
representatives. For the inductive version, addition needs a case
split on the constructors, and the ring laws need more cases. Then
construct maps between the versions, prove that they are mutually
inverse and respect + and ·, and finish with a RingEquiv to
Mathlib's ℤ. Add the order ≤ and the embedding of ℕ.
Comments and extensions.
-
The write-up should say which version made which proof short: ring laws (easy for the quotient, case-heavy for the inductive type), decidable equality and computation (free for the inductive type, needs work for the quotient), and the normal form (where is the work hidden?).
-
#print axiomsfor each version: where doesQuot.soundappear? -
Stretch:
ℚas a quotient ofℤ × ℕ+, compared with Mathlib'sRat(a structure with a reduced numerator and denominator, see chapter 2.1).
References. Avigad et al. (2024)Jeremy Avigad, Leonardo de Moura, Soonho Kong, and Sebastian Ullrich, 2024. “Theorem Proving in Lean 4”. In Online textbook. explains the quotient
machinery; Community (2025)The mathlib Community, 2025. “Mathlib Documentation”. In Online API documentation. documents Quotient.lift,
Quotient.map₂ and Int.
3.3. Project 3: Limits of sequences, with and without filters
What it is. In the filters chapter we saw that
Mathlib phrases convergence via Filter.Tendsto. This project
builds the classical theory first — the epsilon-N definition from
Analysis 1 — and then proves that the two formulations agree. It is
the ideal project if you want to formalize material you know very
well and see the filter language pay off.
Implementation idea. Define
TendsTo (a : ℕ → ℝ) (t : ℝ) : Prop by the usual quantifier chain
(for every positive epsilon there is an N beyond which the distance
is below epsilon). Then build the toolbox: limits are unique; a
constant sequence converges; limits respect sums, scalar multiples,
and products; the squeeze theorem. Expect to practice intro,
obtain, specialize, and the art of choosing the right N (a
max of two thresholds) — plus linarith and abs lemmas.
Finally, prove the bridge:
TendsTo a t ↔ Filter.Tendsto a Filter.atTop (nhds t), using
Mathlib's Metric.tendsto_atTop as the stepping stone, and reprove
one of your toolbox lemmas in one line with
the filter API. Stretch goal: monotone
bounded sequences converge (this needs the completeness of ℝ via
suprema).
Comments and extensions. This is the project closest to a
first-year course, and a good choice if Lean is still new to you.
Further steps: Cauchy sequences and their convergence in ℝ;
Bolzano–Weierstrass; series and the comparison test. For each, prove
the classical version first and then compare with the Mathlib
statement.
References. Avigad and Massot (2025)Jeremy Avigad and Patrick Massot, 2025. “Mathematics in Lean”. In Online textbook. develops exactly this programme in its convergence chapter, and Buzzard and Mehta (2024)Kevin Buzzard and Bhavik Mehta, 2024. “Formalising Mathematics”. In Online lecture notes. cover limits of sequences as a running example; consult them when stuck, not before.
3.4. Project 4: Girard's paradox, or why Type : Type is fatal
What it is. Russell's paradox shows that a "set of all sets that
do not contain themselves" is contradictory. Girard's paradox is
its type-theoretic incarnation: in a type theory where the universe
contains itself — where Type : Type holds — one can construct a
closed term of type False, so the whole system collapses. This is
precisely why Lean arranges its universes in a hierarchy
(the universe hierarchy): Type u lives
in Type (u+1), never in itself. The project is to make this story
precise in Lean: build the paradoxical machinery, watch exactly
where the type-checker stops it, and prove that any universe evading
the hierarchy is contradictory.
Implementation idea. A possible route, in four steps of increasing depth:
-
Build Girard's universe and locate the failure. The only type former needed is the power set
Set X(definitionallyX → Prop). Girard's universe is engineered so that its own double power set embeds back into it:def U : Type 1 := (X : Type) → (Set (Set X) → X) → Set (Set X) -- encoding: a "set of sets of U" as an element of U def τ (t : Set (Set U)) : U := fun X f p => t (fun x => p (f (x X f))) -- decoding -- but `s U` instantiates `s : U` at `U` -- itself, and `U : Type 1`, not `Type`: rejected! def σ (s : U) : Set (Set U) := s U τ
Uandτtype-check;σdoes not, and#check_failurelets you document the failure inside a compiling file. Convince yourself (and your readers) that the level mismatch persists at every universe level — predicativity makes the self-instantiation untypeable, full stop. -
Smuggle the paradox in as a hypothesis. What
Type : Typewould buy you is an injection ofSet (Set U)intoU. Assume it and deriveFalse— with no extra axioms — by composing with the singleton mapSet U → Set (Set U)and applying Cantor's theorem, which Mathlib provides asFunction.cantor_injective. Check with#print axiomsthat your proof only uses Lean's standard axioms. -
Formalize Coquand's abstract version. Package a "paradoxical universe" as a structure: a type
Uwith mapsσ : U → Set Uandτ : Set U → Usatisfyingσ (τ X) = (fun x => τ (σ x)) '' X. Prove that every such universe is contradictory. The proof is a Burali-Forti-style argument via the accessibility predicateAccand can be carried out without any axioms at all —#print axiomsreports none, making the refutation fully constructive. -
Stretch goals: formalize Hurkens' famous simplification of the paradox, and explain — in prose and with
#check_failureexperiments — why Lean's impredicativePropdoes not fall to the same argument.
Comments. This is the most demanding of the projects. It suits someone who wants to see why the universe hierarchy and the rules of chapter 1.5 are what they are. The write-up should explain, in prose, the line from Russell's paradox to Girard's.
References. The paradox is from the thesis of
Girard (1972)Jean-Yves Girard, 1972. Interprétation fonctionnelle et élimination des coupures de l'arithmétique d'ordre supérieur. PhD thesis, Université Paris VII; Coquand (1986)Thierry Coquand, 1986. “An Analysis of Girard's Paradox”. In Proceedings of the First Annual IEEE Symposium on Logic in Computer Science (LICS 1986). gives the analysis on
which the abstract version above is based, and Hurkens (1995)Antonius J. C. Hurkens, 1995. “A Simplification of Girard's Paradox”. In Typed Lambda Calculi and Applications (TLCA 1995). (Lecture Notes in Computer Science 902)
the short self-contained term. A formalization of Hurkens' term is
in the file Logic/Hurkens.v of the Rocq (formerly Coq) standard
library, which can serve as a blueprint.
3.5. Project 5: Reading a theorem in Mathlib
What it is. Take an important result in Mathlib and understand its proof, or the construction behind it, through the formalization. The result is a written account of how Mathlib does it, together with a Lean file in which you redo the central step yourself.
Candidates (with their Mathlib names):
-
the fundamental theorem of algebra,
Complex.isAlgClosed; -
the completeness of
ℝ,Real.exists_isLUB; -
Banach's fixed-point theorem,
ContractingWith.fixedPoint_isFixedPt; -
Sylow's first theorem,
Sylow.exists_subgroup_card_pow_prime; -
quadratic reciprocity,
legendreSym.quadratic_reciprocity; -
Lagrange's four-square theorem,
Nat.sum_four_squares.
Other choices are welcome; agree on the result with us first.
Implementation idea.
-
Statement. Read the statement until every symbol is clear: which typeclasses appear, what each hypothesis says, and why it is phrased this way (for example with
Nat.cardorFact p.Prime). Compare with the textbook statement. -
Dependencies. Follow the proof with "go to definition" and
#check. Draw the tree of definitions and lemmas it rests on, down to the point where everything is familiar. -
Comparison. Put the Mathlib proof next to a textbook proof. Where do they agree? Where did Mathlib generalize (filters, typeclasses, a more abstract setting), and which other results use the general version?
-
Own proof. In your own file, prove the central step, or a special case of the theorem, without the Mathlib lemma that does it. Use
#print axiomsto compare your proof with Mathlib's.
Comments. This project trains the skill used most in practice: reading and using a large library. The difficulty depends on the theorem; agree on the depth of step 4 when choosing.
References. Community (2025)The mathlib Community, 2025. “Mathlib Documentation”. In Online API documentation.; each declaration there links to its source.
3.6. Project 6: Mutual inductive types
What it is. The course did not cover mutual inductive types:
several types, declared together in a mutual … end block, whose
constructors refer to each other. The first task is to find out what
they are, using the
Lean Language Reference
and experiments. The second is to come up with examples of your own.
Here are two to start from:
mutual
inductive IsEven : ℕ → Prop
| zero : IsEven 0
| succ {n : ℕ} : IsOdd n → IsEven (n + 1)
inductive IsOdd : ℕ → Prop
| succ {n : ℕ} : IsEven n → IsOdd (n + 1)
end
mutual
inductive MTree (α : Type) where
| node : α → MForest α → MTree α
inductive MForest (α : Type) where
| nil : MForest α
| cons : MTree α → MForest α → MForest α
end
A tree is a label and a forest of children; a forest is a list of trees.
Implementation idea.
-
Even and odd. Prove
IsEven n ∨ IsOdd n, that no number is both, and thatIsEvenandIsOddagree with Mathlib'sEvenandOdd. -
Trees and forests. Define
size,mirrorand the list of labels by mutual recursion (amutualblock ofdefs), and prove statements such ast.mirror.size = t.size. The tacticinductionrefuses mutual types. The proofs are therefore again mutual recursions, astheorems in amutualblock. -
The recursor.
#check @MTree.recshows two motives, one for each type. Explain how it is built, following the recipe of chapter 1.3. -
Your own examples. Two suggestions:
-
A small language with arithmetic and Boolean expressions:
AExphas anif b then a₁ else a₂withb : BExp, andBExphas a comparisona₁ ≤ a₂withaᵢ : AExp. Write the evaluatorsAExp.evalandBExp.eval, a simplifier (constant folding), and prove that the simplifier does not change the value. -
Games: given
move : P → P → Prop, define winning and losing positions mutually. A position is winning if some move leads to a losing position, and losing if every move leads to a winning one. For the game "take 1 or 2 from a pile ofn", prove thatnis losing if and only if3 ∣ n.
-
Comments and extensions.
-
Nested types.
inductive Rose (α : Type) | node : α → List (Rose α) → Rose αis not declared as mutual, but#check @Rose.recalso shows two motives, the second one forList (Rose α). Lean treats nested types as mutual ones. ConstructMTree α ≃ Rose α. -
One type instead of two. Encode
MTreeandMForestas a single familyTF : Bool → Typeindexed by "tree or forest", and prove that it is equivalent to the mutual version. -
Games. The inductive
Win/Loseonly see games in which every play ends. What happens for a game with a cycle? Discuss coinductive definitions in the write-up.
References. The Lean Language Reference (link above) for mutual;
Avigad et al. (2024)Jeremy Avigad, Leonardo de Moura, Soonho Kong, and Sebastian Ullrich, 2024. “Theorem Proving in Lean 4”. In Online textbook., chapter on inductive types, for
mutual and nested inductive types.
3.7. Project 7: What Lean makes of a recursive definition
What it is. The kernel knows no pattern matching and no recursion, only recursors (chapter 1.3). A definition such as
def fib : ℕ → ℕ | 0 => 0 | 1 => 1 | n + 2 => fib n + fib (n + 1)
is translated by the elaborator into terms built from Nat.rec.
Along the way it generates auxiliary definitions, all ordinary
defs that #print shows:
-
Nat.casesOn: the recursor without the values at the recursive arguments, a case split on the outermost constructor; -
fib.match_1: the patterns0,1,n + 2as nestedcasesOn; -
Nat.below: the type of a table of the values at all smaller arguments, withNat.below (n + 1) = motive n ×' Nat.below n; -
Nat.brecOnandNat.brecOn.go: one pass ofNat.recthat builds value and table together; -
fib._f:fibwith every recursive call replaced by a lookup in the table;#print fibshowsfun x => Nat.brecOn x fib._f.
The project is to rebuild this machinery by hand, for ℕ and for a
type of trees, and to check each step against Lean with rfl.
Course-of-values recursion in chapter 1.3 states
the problem that this machinery solves.
Implementation idea.
-
Reading. Run
#printonNat.casesOn,Nat.below,Nat.brecOn,Nat.brecOn.go,fib.match_1,fib._fandfib. Explain each term.×'isPProd, the pair type that also accepts proofs as components; explain whyProddoes not suffice. -
By hand for
ℕ. DefinemyCasesOn,myBelow,myBrecOnwithNat.reconly, and prove that they agree with Lean's versions, byrflwhere possible. Definefibonce more throughmyBrecOnand prove that it agrees withfib. -
Trees. Take
inductive BinTree | leaf | node (l : BinTree) (a : ℕ) (r : BinTree). Write downBinTree.belowandBinTree.brecOnby hand: the table now branches like the tree,BinTree.below (node l a r) = (motive l ×' below l) ×' (motive r ×' below r). Check against Lean withrfl. Defineheightthrough yourbrecOnand compare with the definition by pattern matching. -
The structural check. Explain with
fib._fwhy Lean accepts a recursive call exactly when its argument is found in the table, and whyloop n := loop nandlog2 (n / 2)are not structural. -
Proofs. With a
Prop-valued motive the table holds proofs: the induction hypotheses for all smaller arguments. Prove0 < fib (n + 1)once by pattern matching and once through yourmyBrecOn, and compare the proof terms with#print.
Comments and extensions.
-
Running time.
#eval fib 32takes over a second,fib 90 = … := rflis checked at once. Explain the difference:#evalruns compiled code made from the equations as written, the kernel reduces thebrecOnterm, which computes every value once. Measure, for example withset_option profiler true. -
Well-founded recursion. Definitions that are not structural are translated with
WellFounded.fix. Find out how, and whyrflthen usually fails while the equation lemmas (f.eq_1) work. -
Other types. Do the same for
List, or for the infinitely branchingMyTreeof chapter 1.3, whose table is a function. -
Project 6 (mutual types) asks for the recursor of a mutual type; the two projects combine well.
References. Avigad et al. (2024)Jeremy Avigad, Leonardo de Moura, Soonho Kong, and Sebastian Ullrich, 2024. “Theorem Proving in Lean 4”. In Online textbook., chapter on induction and recursion, for the translation of pattern matching and structural recursion; the Lean Language Reference on recursive definitions.