Lean4 Academy
All lessons
130 lessons in 13 courses, about 34 hours in total. 38 lessons are free; the Academy Pass opens the rest. Each lesson ends with an exercise the Lean compiler checks.
130 lessons
Start here
Lean foundations
14 lessons · 220 min
- Your first checked statementRead a theorem, write rfl, and check a proof of a calculation.11 min
- Evaluate and inspectRun a calculation with #eval and inspect its type with #check.12 min
- Ask Lean about typesUse #check to read a type, and tell data apart from statements.14 min
- Values and core typesNat, Int, Bool, and the truncated subtraction that catches everyone once.15 min
- Write your own functionParameters, a result type Lean holds you to, and checks that call your code.16 min
- Prove which branch runsUnfold a function and use a hypothesis to simplify its condition.15 min
- Lists and optional valuesProve the first-element law for every nonempty list.15 min
- Model data with a structureDefine named fields, construct records and update one field safely.17 min
- Define data by constructorsCreate a three-state type and write an exhaustive transition function.17 min
- Prove every constructor caseSplit an arbitrary value into cases and prove a property in every branch.17 min
- Read and repair an errorPreserve the valid part of a multi-step proof and repair its first error.14 min
- State your own theoremWrite binders, a hypothesis and a claim. The proofs are supplied; the statements are yours.19 min
- Put a small file togetherCombine a structure, record update, evaluation and multi-step theorem.18 min
- Review: build it without helpDefine a type and functions, prove properties by cases and predict output, with no step checklist.20 min
Your first Lean proofs
13 lessons · 200 min
- Equality with an unknown inputProve n + 0 = n and learn when computation can work with a variable.13 min
- Use what you already knowHypotheses are proofs you already hold. exact hands one to Lean.12 min
- Prove an implicationAssume the premise with intro, then prove the conclusion.14 min
- Build a two-part proofconstructor splits P ∧ Q, bullets keep the branches tidy.14 min
- Apply an implicationAn implication is a function on proofs. apply works backwards from the goal.15 min
- Name an intermediate stephave records a fact you have derived, so later steps can use it by name.15 min
- Take a hypothesis apartobtain ⟨hp, hq⟩ := h unpacks a conjunction so you can use both halves.15 min
- Plan a proof, then fill it inWrite the structure first with sorry in the holes, and let Lean show what each hole needs.17 min
- Replace equals by equalsrw [h] substitutes using an equation, even inside functions no tactic can compute.15 min
- Rewrite through a chainRecord each step of an equality argument in a readable calc proof.17 min
- Prove both Boolean casesSplit an arbitrary Boolean and verify both exhaustive branches.15 min
- Practice: transform both sidesUnpack, split and apply two implications in a branching proof.20 min
- Review: choose the next moveMixed exercises from the whole course, with no step checklist.18 min
Propositional logic
11 lessons · 165 min
- Prove an or-statementTo prove P ∨ Q, pick the side you can prove.12 min
- Reason from alternativescases h with | inl hp | inr hq handles both possibilities.16 min
- What ¬P really meansA negation is a function into False. Apply it like one.14 min
- From a contradiction, anythingexfalso and absurd let a contradiction prove any goal.14 min
- Prove an equivalenceP ↔ Q is two implications. constructor gives you both.13 min
- Use an equivalenceh.mp and h.mpr turn an iff into the direction you need.13 min
- Prove a contrapositiveFrom P → Q and ¬Q, build ¬P by introducing an assumed P.15 min
- A De Morgan lawShow ¬(P ∨ Q) gives ¬P ∧ ¬Q, combining everything so far.17 min
- Split on whether P holdsby_cases and the classical De Morgan law ¬(P ∧ Q) → ¬P ∨ ¬Q.17 min
- Proof by contradictionAssume the negation of the goal, derive False, and see why that step is classical.16 min
- Review: every connectiveMixed exercises on or, not, iff and classical reasoning, with no step checklist.18 min
Proof techniques
Quantifiers
7 lessons · 107 min
- Prove a statement about every numberintro n picks an arbitrary n. Whatever you prove holds for all of them.15 min
- Use a universal hypothesisA ∀-hypothesis is a function: apply it to the value you need.13 min
- Provide a witnessTo prove ∃ n, …, name the n and prove the property for it.14 min
- Use an existential hypothesisobtain ⟨n, hn⟩ := h gives you the witness and its property.16 min
- Specialize a hypothesisNarrow a general fact to the one instance your goal needs.14 min
- Combine both quantifiersBuild an existence proof whose witness comes from a hypothesis.17 min
- Review: four quantifier movesIntroduce, apply, witness and open quantifiers in mixed exercises, with no step checklist.18 min
Rewriting and automation
8 lessons · 77 min
- Rewrite with an equalityrw [h] replaces the left side of h by its right side everywhere.9 min
- Rewrite in the other directionrw [← h] uses an equation right-to-left. Chain rewrites in one call.10 min
- Rewrite inside a hypothesisrw [h] at h2 changes a hypothesis instead of the goal.9 min
- Simplify a goalsimp normalizes with hundreds of known lemmas.8 min
- Point simp and rw at the right lemmasLibrary lemmas about lists and arithmetic, used by name.12 min
- Decide a finite factdecide evaluates a decidable proposition and produces a proof.8 min
- Linear arithmetic with omegaInequalities and natural-number subtraction, solved automatically.9 min
- Chain equalities with calcA readable proof that shows each rewriting step and its justification.12 min
Proof terms and Curry–Howard
7 lessons · 70 min
- An implication is a functionfun hp => hp proves P → P.9 min
- A conjunction is a pair⟨hp, hq⟩ proves P ∧ Q.8 min
- Projectionsh.1 and h.2 read the halves of a conjunction.8 min
- Compose implicationsChaining P → Q and Q → R is function composition.10 min
- Eliminate a disjunctionh.elim takes one handler per case.11 min
- Existentials as dependent pairs⟨witness, proof⟩ proves ∃ n, p n.10 min
- Assemble a whole proof termName every component, then hand Lean one finished term.14 min
Programs and induction
Functional programming
12 lessons · 148 min
- Functions as valuesPass behaviour as an argument, then prove a law about every input.10 min
- Functions you build as you goCapture local context in a lambda, and return a function as a result.11 min
- Structures and record updatesNamed fields, precise copies, and why eta closes a round trip.11 min
- Define your own structureFields, the constructor Lean generates for you, and record updates.12 min
- Exhaustive pattern matchingWildcards, exhaustiveness, and covering every constructor in a proof.12 min
- Recursion on natural numbersBase and successor cases, and the equations they hand you for free.12 min
- Recursion on listsPeel constructors off a list while staying polymorphic in the elements.12 min
- Write and verify your own mapBuild a polymorphic higher-order list function, then prove that it preserves length.18 min
- Walk two lists at onceMatch two lists together and combine them element by element.13 min
- Why recursion must terminateWhat Lean rejects, why it must, and what totality buys your proofs.10 min
- Recursion that is not structuralRecursive calls on computed values, and the measure that proves they stop.14 min
- Classes and instancesDescribe shared behaviour and let Lean pick the implementation.13 min
Induction on numbers and lists
6 lessons · 78 min
- Your first inductionProve double n = n + n for a recursive double.14 min
- Why 0 + n = n needs inductionn + 0 is rfl, 0 + n is not. See what computation does and does not give you.13 min
- Induction over listsA hand-written length distributes over append.15 min
- map preserves lengthBase cases that compute, step cases that rewrite.12 min
- A growth bound by inductionThe sum 0 + 1 + … + n is at least n.12 min
- Exponential growthProve n < 2ⁿ with an induction hypothesis and omega.12 min
Programs with proofs
9 lessons · 127 min
- Specify a functionThree properties that pin down a maximum, and split for the proof.12 min
- Safe division with OptionSpecify a partial function that returns none instead of failing.11 min
- Case analysis on inputsProve a fact about a pattern-matching function with cases.12 min
- Structures and round tripsSwapping a point twice returns the original point.11 min
- Verify your own reverseReversing a concatenation reverses the order of the pieces, by induction.15 min
- Build on a proved lemmaReversing twice gives back the list, with the previous law doing the hard step.13 min
- A Boolean search over a listSearching two joined lists is searching each part and combining with ||.13 min
- An invariant over every runA capped counter stays within its cap after any sequence of operations.16 min
- Project: verified iterationWrite a polymorphic iterator, prove its composition law, and verify a numeric specialization.24 min
Inductive types and case analysis
7 lessons · 88 min
- An enumeration and a general cycle lawTraffic lights: define a transition and prove its cycle for every constructor.12 min
- Define your own typeDeclare constructors, match on all of them, and meet the missing-case error.11 min
- Prove two-sided inverse operationsShow next and previous cancel in both orders across every constructor.13 min
- Constructors that carry dataShapes with sizes, and a scaling law proven per constructor.12 min
- Binary treesEvery tree has positive size.11 min
- Induction over treesTwo induction hypotheses, one for each subtree.14 min
- Derive the fold for your own typeOne function parameter per constructor, read straight off the declaration.15 min
Natural Number Lab
The Natural Number Lab
18 lessons · 336 min
- Addition worldAddition from recursionStart from zero and successor, then prove the first identity by induction.15 min
- Move a successor across additionProve the equation the recursive definition does not compute for you.16 min
- Addition commutesCombine the first two lemmas in a structured induction.18 min
- Addition associatesControl three nested unfolds and expose the induction hypothesis.18 min
- Cancel a common tailRewrite inside a hypothesis and recover equality of the starting values.20 min
- Multiplication worldZero times everythingRebuild the left-zero law directly from multiplication recursion.14 min
- Move a successor through multiplicationExpose recursive products, then finish the visible arithmetic.18 min
- Multiplication distributesProve distributivity one successor at a time without a broad simplifier.20 min
- Multiplication commutesPair left and right recursion laws in the induction step.18 min
- Multiplication associatesUse distributivity as a local step inside a larger induction.22 min
- Power worldAdding exponentsProve that exponent addition becomes multiplication of powers.20 min
- Powers of a productInduct, then commute the middle factors with a controlled normalization.22 min
- Order worldOrder as a gapDefine an order relation with an existential witness and prove reflexivity.14 min
- Compose two gapsBuild a transitivity witness and document the route with calc.20 min
- Two directions force equalityExpose hidden gaps and derive antisymmetry from their equations.18 min
- Divisibility worldCompose divisibility witnessesMultiply two quotient witnesses and associate the resulting product.20 min
- A divisor of a sumAdd quotient witnesses and factor the common divisor.18 min
- Finale: chain, add and factorSynthesize three hypotheses in a long, readable divisibility proof.25 min
Advanced proofs and effects
Advanced functional proofs
7 lessons · 156 min
- Higher-order listsBuild map and prove its append lawImplement a polymorphic map, then prove the compositional law callers need.20 min
- Fuse two mapsRemove an intermediate traversal with a general function-composition proof.16 min
- Fuse filtering and mappingWrite a branching list combinator and prove its append law in both predicate cases.22 min
- Folds and invariantsA fold with a generalized accumulatorBuild a left fold and strengthen the induction hypothesis enough to prove chunking.22 min
- Carry a proof for every elementDefine an indexed All predicate and map evidence through a transformation.24 min
- Dependent dataMake lengths part of the typeImplement vector map so preserving length is enforced before any theorem runs.24 min
- Verified projectFinale: verify a polymorphic tree mapProve map fusion and size preservation with two induction hypotheses per node.28 min
Monads and effects
11 lessons · 250 min
- Failure and sequencingOption as a monadReplace nested matches with bind and short-circuit a two-step safe division.18 min
- Do notation, desugaredWrite the exact >>= chain behind two left-arrow bindings.18 min
- Errors that carry a reasonRefactor safeDiv from Option to Except while keeping the pipeline.20 min
- Abstraction ladderFunctor and ApplicativeMap one contextual value and combine two independent ones.20 min
- Execution and performanceIO and the proof boundaryRead a file, print a result, and understand why IO stays opaque.18 min
- Array, List and access patternsUse array literals, map and safe indexing, then prove size preservation.20 min
- Mutable syntax is a foldWrite let mut and for, then prove the loop equals its fold specification.22 min
- Lawful effectsWrite a Monad and prove its lawsImplement a Trace monad and prove left identity, right identity and associativity.32 min
- StateM and a verified counterThread state through two actions and prove the state-monad laws.26 min
- Combine state and errors with StateTBuild a failing balance computation and reason about transformer order.26 min
- Dependent programsMake invalid workflows impossibleIndex commands by protocol state and prove typed composition laws.30 min