Lean
Write proofs the computer checks: logic, numbers and induction in Lean 4, one goal at a time.
Each lesson has statements to prove and a checker that accepts a proof or says exactly what is missing. Lean is real (Lean 4.35), running in a small Linux machine inside this tab: no install, no server checking your proofs. The first visit downloads about 140 MB before the first check, so start on a laptop with a good connection; later visits start from your browser's copy.
Linux + Lean 4 in your browser
21 lessons · 174 programs
Chapter 1 · Foundations
What Lean checks, what it trusts, and how to read what it says
- 1 Hello, Lean
Check a file, state facts, and prove them with rfl and decide.
- 2 Inside the checker
Parser, elaborator, kernel; statements are types and proofs are terms.
- 3 Terms, types and functions
Values and their types, functions with def and fun, and proofs that unfold them.
- 4 When Lean says no
Read Lean's messages: where they point, what they mean, and which one to fix first.
Chapter 2 · Logic
Proofs of if, and, or, not, for all and there exists
- 5 If, then
intro, exact and apply; a proof of → is a function.
- 6 And, or
∧ and ∨: constructor, bullets, obtain, left, right and cases.
- 7 Not, false and if-and-only-if
False and ¬, exfalso and contradiction, ↔, and by_cases with its axiom.
- 8 For all, there exists
∀ and ∃: intro n, h 3 and specialize, exists, and obtain.
Chapter 3 · Numbers and induction
Rewriting, calculations, checked automation and induction
- 9 Rewriting
Rewrite with equations and library facts: rw, ←, at, and exact? to find a fact.
- 10 Chains of steps
Prove a statement as a chain with calc; ≤ and <, have and show.
- 11 Automation you can check
decide, omega and simp do the arithmetic, and the kernel still checks every proof.
- 12 Recursion on numbers
How Nat is built, definitions by cases and by recursion, and how + computes.
- 13 Induction
Prove a fact about every number: induction, ih, unfold then omega.
Chapter 4 · Your own data
Types, lists and structures, and proofs about them
- 14 Your own types
inductive types, functions by cases, cases and <;>, constructors with fields.
- 15 Lists and recursion
List Nat, [] and ::, functions on lists by pattern matching, facts about given lists.
- 16 Induction on lists
induction xs with nil and cons; ih for the tail; a theorem reused by simp.
- 17 Structures
structure, fields, ⟨...⟩ and with; functions and facts about points; a proof as a field.
- 18 One symbol, many types
Int, classes and instances, {α : Type} and [Add α], Bool and Prop, Decidable.
Chapter 5 · Verified programs
Functions with specifications, proved
- 19 Specifications
if and split; a specification as theorems, and a counterexample for a wrong function.
- 20 Practice: choose the tactic
Read the goal, then choose the tactic: no new constructs, no tactic named.
- 21 A verified function
One file: rev, three promises about it, a helper lemma, and four proofs.