Interactive Theorem Proving using Lean, Winter 2026/27

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:

  1. 0 is a natural number.

  2. Every natural number n has a successor succ n.

  3. 0 is not the successor of any natural number.

  4. succ is injective.

  5. Induction: a property that holds for 0, and for succ n whenever it holds for n, 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 Nat to Peano. Axioms 1 and 2 are the constructors. Prove 3 and 4 by hand, without Nat.succ_ne_zero and Nat.succ_injective. This needs the fact that constructors are distinct and injective, which Lean derives from the recursor (Nat.noConfusion, or the tactics cases and injection). Axiom 5 is Nat.rec with a motive in Prop.

  • 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 n
    

    The map Nat → N is defined by recursion on Nat. The map back is the main work: ind only proves propositions, it does not define functions. You need Dedekind's recursion theorem (1888): for every a : X and f : X → X there is exactly one g : N → X with g zero = a and g (succ n) = f (g n). Prove it from ind, for example by building g as a relation and showing by induction that it is the graph of a function. Then construct N ≃ ℕ.

  • 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 1 with succ 0 = 0; Fin 2 with succ constantly 1; ℕ ⊕ ℤ with succ on both summands.

Comments and extensions.

  • Lean's Nat.rec has 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 zero and succ and that there is only one such map. In the language of category theory: Nat is an initial algebra.

  • Transport addition and multiplication to N with the recursion theorem and prove that the equivalence respects them.

  • ind quantifies 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.

  1. Quotient. ℕ × ℕ modulo (a, b) ∼ (c, d) ↔ a + d = b + c; the pair (a, b) stands for a - b. This is the standard construction from a first-year course, and it uses quotient types and the axiom Quot.sound.

  2. Inductive, as in Lean. Two constructors ofNat n (for n) and negSucc n (for -(n + 1)). Every integer has exactly one representation, so equality is decidable and #eval works.

  3. Normal forms. The subtype of pairs (a, b) : ℕ × ℕ with a = 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 axioms for each version: where does Quot.sound appear?

  • Stretch: ℚ as a quotient of ℤ × ℕ+, compared with Mathlib's Rat (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 (definitionally X → 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 τ
    

    U and τ type-check; σ does not, and #check_failure lets 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 : Type would buy you is an injection of Set (Set U) into U. Assume it and derive False — with no extra axioms — by composing with the singleton map Set U → Set (Set U) and applying Cantor's theorem, which Mathlib provides as Function.cantor_injective. Check with #print axioms that your proof only uses Lean's standard axioms.

  • Formalize Coquand's abstract version. Package a "paradoxical universe" as a structure: a type U with maps σ : U → Set U and τ : Set U → U satisfying σ (τ X) = (fun x => τ (σ x)) '' X. Prove that every such universe is contradictory. The proof is a Burali-Forti-style argument via the accessibility predicate Acc and can be carried out without any axioms at all — #print axioms reports none, making the refutation fully constructive.

  • Stretch goals: formalize Hurkens' famous simplification of the paradox, and explain — in prose and with #check_failure experiments — why Lean's impredicative Prop does 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.

  1. 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.card or Fact p.Prime). Compare with the textbook statement.

  2. 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.

  3. 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?

  4. 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 axioms to 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 that IsEven and IsOdd agree with Mathlib's Even and Odd.

  • Trees and forests. Define size, mirror and the list of labels by mutual recursion (a mutual block of defs), and prove statements such as t.mirror.size = t.size. The tactic induction refuses mutual types. The proofs are therefore again mutual recursions, as theorems in a mutual block.

  • The recursor. #check @MTree.rec shows 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: AExp has an if b then a₁ else a₂ with b : BExp, and BExp has a comparison a₁ ≤ a₂ with aᵢ : AExp. Write the evaluators AExp.eval and BExp.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 of n", prove that n is losing if and only if 3 ∣ n.

Comments and extensions.

  • Nested types. inductive Rose (α : Type) | node : α → List (Rose α) → Rose α is not declared as mutual, but #check @Rose.rec also shows two motives, the second one for List (Rose α). Lean treats nested types as mutual ones. Construct MTree α ≃ Rose α.

  • One type instead of two. Encode MTree and MForest as a single family TF : Bool → Type indexed by "tree or forest", and prove that it is equivalent to the mutual version.

  • Games. The inductive Win/Lose only 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 patterns 0, 1, n + 2 as nested casesOn;

  • Nat.below: the type of a table of the values at all smaller arguments, with Nat.below (n + 1) = motive n ×' Nat.below n;

  • Nat.brecOn and Nat.brecOn.go: one pass of Nat.rec that builds value and table together;

  • fib._f: fib with every recursive call replaced by a lookup in the table; #print fib shows fun 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 #print on Nat.casesOn, Nat.below, Nat.brecOn, Nat.brecOn.go, fib.match_1, fib._f and fib. Explain each term. ×' is PProd, the pair type that also accepts proofs as components; explain why Prod does not suffice.

  • By hand for ℕ. Define myCasesOn, myBelow, myBrecOn with Nat.rec only, and prove that they agree with Lean's versions, by rfl where possible. Define fib once more through myBrecOn and prove that it agrees with fib.

  • Trees. Take inductive BinTree | leaf | node (l : BinTree) (a : ℕ) (r : BinTree). Write down BinTree.below and BinTree.brecOn by 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 with rfl. Define height through your brecOn and compare with the definition by pattern matching.

  • The structural check. Explain with fib._f why Lean accepts a recursive call exactly when its argument is found in the table, and why loop n := loop n and log2 (n / 2) are not structural.

  • Proofs. With a Prop-valued motive the table holds proofs: the induction hypotheses for all smaller arguments. Prove 0 < fib (n + 1) once by pattern matching and once through your myBrecOn, and compare the proof terms with #print.

Comments and extensions.

  • Running time. #eval fib 32 takes over a second, fib 90 = … := rfl is checked at once. Explain the difference: #eval runs compiled code made from the equations as written, the kernel reduces the brecOn term, which computes every value once. Measure, for example with set_option profiler true.

  • Well-founded recursion. Definitions that are not structural are translated with WellFounded.fix. Find out how, and why rfl then usually fails while the equation lemmas (f.eq_1) work.

  • Other types. Do the same for List, or for the infinitely branching MyTree of 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.