Lab 12: The Lean Proof Assistant¶
Learning Objectives
Learn what a proof assistant is and how it checks proofs down to their logical foundation.
Use the Lean interactive theorem prover to build the natural numbers from foundational axioms.
This lab has no template notebook.
Automated Logic¶
Lean is a relatively new programming language that has exploded in importance in the AI era. It lets users define objects, state properties, and write formal proofs as code. Lean checks whether each proof follows from the definitions and assumptions in the environment. This verifies the formal theorem, provided that the theorem accurately represents the intended mathematical claim.
The Lean website gives this description.
A proof assistant is a piece of software that provides a language for defining objects, specifying properties of these objects, and proving that these specifications hold. The system checks that these proofs are correct down to their logical foundation.
These tools are often used to verify the correctness of programs. But they can also be used for abstract mathematics…In a formalization, all definitions are precisely specified and all proofs are virtually guaranteed to be correct.
The goal of this lab is to get a sense of how a theorem prover works by practicing with an interactive game for learning Lean. We will focus on the structure of the natural numbers and prove, among other things, that \(2 + 2 = 4\).
The Natural Numbers¶
The set of natural numbers \(\mathbb{N}\) is often defined as \(\mathbb{N} = \{1, 2, 3, 4, 5, \ldots\}\), beginning at \(1\). In Lean, the natural numbers start at \(0\):
We are all comfortable with the notion of adding two numbers together and readily accept statements like \(1 + 2 = 2 + 1\). To build logical statements for proof, the rules that define and govern the natural numbers and relations like addition must be precisely stated and assumed.
Let \(s:\mathbb{N}\to\mathbb{N}\), called the successor function. The following statements, called the Peano axioms, are the foundational assumptions on which all of mathematics relies.
Axiom 1: \(0\in\mathbb{N}\).
Axiom 2: If \(n\in\mathbb{N}\), then \(s(n)\in\mathbb{N}\).
Axiom 3: For every \(n\in\mathbb{N}\), \(s(n)\ne 0\).
Axiom 4: For every \(n,m\in\mathbb{N}\), if \(s(m)=s(n)\), then \(m=n\) (\(s\) is injective).
Axiom 5: For every set \(K\subseteq\mathbb{N}\), if \(0\in K\) and \(s(n)\in K\) whenever \(n\in K\), then \(K=\mathbb{N}\).
The natural number \(s(n)\) is called the successor of \(n\). Axiom 3 says there is no natural number whose successor is \(0\). Axiom 5, the axiom of induction, says that \(\mathbb{N}\) is the smallest set that contains \(0\) and is closed under the successor function. It implies that every natural number can be obtained by applying the successor function to \(0\) finitely many times. Hence, the natural numbers can be written as the set
In standard notation, the symbol \(1\) represents \(s(0)\), the symbol \(2\) represents \(s(s(0))\), and so on. The symbol \(7\) is (convenient) shorthand for \(s(s(s(s(s(s(s(0)))))))\), the successor of the successor of the successor of the successor of the successor of the successor of the successor of \(0\).
Defining Addition¶
The successor function returns the “next” natural number, so it is tempting to define \(s(n) = n + 1\). However, instead of using addition to define \(s\), we must use \(s\) to define addition.
Addition. Define \(+:\mathbb{N}\times\mathbb{N}\to\mathbb{N}\) recursively by the following rules.
\(n + 0 = n\).
\(n + s(m) = s(n + m)\).
Using only these two rules and the definition \(1 = s(0)\), we have
which shows that the successor function really is the operation “add \(1\).”
With these logical building blocks in place, statements like \(2 + 2 = 4\) and \(a + b = b + a\) can be rigorously proved. Formalizing these rules in Lean lets more complicated proofs build on checked results.
Problem 1
The Natural Number Game is an interactive tool for learning foundational concepts in Lean.
Read the instructions on the left-hand side of the page, under “Welcome to the Natural Number Game.” Then complete every level from the Tutorial World.
Problem 2
In the Natural Number Game, complete every level from the Addition World.
Defining Multiplication¶
Like addition, multiplication is a function that operates on two natural numbers and produces another natural number.
Multiplication. Define \(\cdot:\mathbb{N}\times\mathbb{N}\to\mathbb{N}\) recursively by the following rules.
\(n \cdot 0 = 0\).
\(n \cdot s(m) = n + n\cdot m\).
Using only these two rules, the rules of addition, and \(1 = s(0)\),
Proving \(1 \cdot n = n\) is a bit harder, requiring the induction axiom.
Problem 3
In the Natural Number Game, complete EITHER
every level from the Multiplication World. OR
every level from the Implication World.
Submitting This Lab
In the Natural Number Game click on the symbol at the top right corner of the Natural Number Game, then click Download. The resuling JSON file records your progress from the Natural Number Game (you can resume your progress by loading this file with Upload).
To submit this lab, upload this JSON file to GradeScope.
Lean and AI
AI tools can suggest proof strategies, then generate Lean code to check a proposed proof. Lean checks whether the code proves the formal statement from the available assumptions; if the proof is wrong, an AI agent can adjust the proof accordingly, generate new Lean code, and so on. This back and forth iterative process has led to recent important breakthroughs in pure mathematics. For example, on November 20, 2026, mathematician Levent Alpöge announced a proof of the Riemann hypothesis developed with Claude and formalized in Lean. The Lean FRO and Mathlib Initiative later reported that they verified the formal statement and proof.
The Translation Gap
Lean shows whether a statement or proof is logically sound, but it cannot determine whether that statement captures the intended mathematics. A Lean-based proof still needs to be checked by humans to verify that the proof actually proves what we think it proves, not just that the proof is valid.
Software is Still Software
The Lean proof checker is software and hence can contain bugs. In July 2026, an AI-assisted purported disproof of the Collatz conjecture passed Lean’s kernel because of a bug. Fixing the bug revealed that the purported proof was invalid.