The capstone is a formalization of your own choosing. You pick a statement, decide how to represent its objects, write the definitions, state the theorem so that it says what you mean, prove it, and audit the result before you call it verified. That is the recipe of Lecture 5, now run on a project large enough that you need a plan. This lecture gives you the plan: a project template, a blueprint, four guided options with their first statements already compiled, a route for contributing the result upstream, and the audit to finish with. Homework 6 asks for the proposal.

A capstone succeeds if it ends with a main theorem whose statement you can defend, a proof with no sorry, and an honest account of what was and was not done. Size is not the measure. A small theorem stated faithfully is worth more than a large one that proves something else.

Notebook and cheatsheet

This lecture has no notebook; its Lean blocks run in any file that imports Mathlib. Cheatsheet: The formalization recipe, Blueprints, Landmark formalizations, 2020–2026.

A project template

Create the project. Lake, Lean’s build tool, has a template for projects that depend on Mathlib:

lake new myproject math
cd myproject
lake exe cache get   # download compiled Mathlib instead of building it
lake build

lake new … math writes a lakefile.toml that requires Mathlib at the release matching your Lean version, a lean-toolchain file that pins Lean, a root file Myproject.lean that imports Myproject/Basic.lean, a README, a .gitignore, a git repository and GitHub workflows that build the project and keep Mathlib up to date. The lakefile also sets relaxedAutoImplicit to false, so a misspelt name longer than one letter is an error rather than a new variable. Commit lake-manifest.json once it appears: it records the exact Mathlib commit, which is what makes your build reproducible.

Lay it out by role. Split the code the way the recipe splits the work:

  • Myproject/Defs.lean: the definitions, with a docstring each, and nothing else.
  • Myproject/SanityChecks.lean: small facts that the definitions must satisfy (a distance from a point to itself is 0), and an example showing that the main theorem’s hypotheses can all hold at once.
  • Myproject/Lemmas.lean and Myproject/Main.lean: the proof, then the main theorem alone.
  • blueprint/src/content.tex: the blueprint (below).
  • README.md: the statement in English, the Lean statement next to it, and the audit results.

Keeping Main.lean short means a reader can check the statement without reading the proof.

Write a blueprint. The PFR and Carleson projects of Lecture 13 were both organised this way.

Definition 14.1 (Blueprint).

A blueprint is an informal proof written as a graph. Each node is a definition or a lemma, stated in ordinary mathematics and linked to the Lean declaration that will formalize it. An edge from one node to another means the second uses the first. Each node also records whether its statement and its proof exist in Lean yet.

The leanblueprint tool (pip install leanblueprint, then leanblueprint new in your project) turns LaTeX into a web page with the graph drawn and coloured by progress. A node looks like this:

\begin{theorem}[No-deleting]
  \label{thm:no-deleting}
  \lean{Capstone.no_deleting}
  \uses{lem:inner-tensor, lem:sq-eq-self, def:deleter}
  No unitary on two qubits maps $\psi \otimes \psi$ to $\psi \otimes b$
  for every unit vector $\psi$.
\end{theorem}

\lean{…} names the declaration, \uses{…} draws the edges, and \leanok (added when the work is done) marks the statement or, inside a proof, the proof as formalized. leanblueprint checkdecls confirms that every name in \lean{…} exists, which catches renamed lemmas. Tao’s tour of the PFR blueprint shows a real one.

Go sorry-first. State every node of the blueprint in Lean with sorry as its proof, and build. Lean then checks that the statements fit together (that each lemma’s conclusion has the type its users expect) before you have proved anything. Then fill in the sorrys in any order, rebuilding as you go. Lecture 5 calls this step 7 of the recipe. The figure is the blueprint (Definition 14.1) for the first option below, drawn as a graph.

definitions lemmas goal tensor definition IsDeleter definition ket0, ketA witness states L1: product inner product inner_tensor_tensor L2: unit vectors inner_self_of_norm_one L4: z * z = z sq_eq_self L5: the overlap is 3/5 inner_ket0_ketA no_deleting main theorem with an ancilla not stated yet done in your no-cloning work new here, proof is sorry not stated yet

Four guided options

Each option below comes with its first statement, compiled on this page. Every block that ends in sorry is an exercise: proving it is the start of the capstone, not something this page has done. The quantum options can build on the separate quantum-LEAN4 no-cloning development, which uses Mathlib’s EuclideanSpace for states and a LinearIsometryEquiv (written ≃ₗᵢ[ℂ], a linear bijection that preserves norms) for unitaries. Lecture 7 represents the same objects as matrices and vectors. Either choice works, and choosing is part of your proposal.

Option A: no-deleting

Pati and Braunstein proved that linearity forbids deleting one of two copies of an unknown quantum state (arXiv quant-ph/9911090, Nature 404, 164, 2000). Their machine acts as : a blank state replaces the second copy, and an ancilla may end in a state that depends on . The first statement leaves the ancilla out:

import Mathlib
 
open scoped InnerProductSpace
 
namespace Capstone
 
abbrev QState (n : Type) [Fintype n] := EuclideanSpace ℂ n
 
noncomputable def tensor {n m : Type} [Fintype n] [Fintype m]
    (ψ : QState n) (φ : QState m) : QState (n × m) :=
  WithLp.toLp 2 (fun p => ψ.ofLp p.1 * φ.ofLp p.2)
 
infixl:75 " ⊗ᵩ " => tensor
 
abbrev TwoQubits := QState (Fin 2 × Fin 2)
 
/-- `D` deletes: it turns two copies of any unit vector into one copy
and the blank state. -/
def IsDeleter (blank : QState (Fin 2))
    (D : TwoQubits ≃ₗᵢ[ℂ] TwoQubits) : Prop :=
  ∀ ψ : QState (Fin 2), ‖ψ‖ = 1 → D (ψ ⊗ᵩ ψ) = ψ ⊗ᵩ blank
 
theorem no_deleting :
    ¬ ∃ (blank : QState (Fin 2)) (D : TwoQubits ≃ₗᵢ[ℂ] TwoQubits),
      ‖blank‖ = 1 ∧ IsDeleter blank D := by
  sorry
 
end Capstone

The proof is the no-cloning argument run backwards. For unit vectors with overlap , the left side gives , the right side gives , and preserves inner products, so . The witnesses and have overlap , a contradiction. As the figure shows, every lemma this needs is one you proved for no-cloning.

Remark 14.1 (Narrow first, faithful second).

The statement above is narrower than Pati and Braunstein’s: with no ancilla, it rules out fewer machines. That is a sensible first milestone, but your README must say so. The second milestone is the ancilla version, the dashed node in the figure. Writing its statement faithfully, with allowed to depend on , is the harder half of the option.

Option B: Fuchs–van de Graaf, the easy direction

The trace distance and the fidelity are the two standard ways to measure how far apart two quantum states are. Fuchs and van de Graaf proved (arXiv quant-ph/9712042, their inequality (46)). Their proof of the left inequality has two steps. First, the classical inequality (their (43)), where is half the distance between two probability vectors and . Second, a measurement chosen so that its outcome distributions have equal to the quantum fidelity. The first step is a self-contained theorem:

namespace Capstone
 
def IsProb {n : ℕ} (p : Fin n → ℝ) : Prop :=
  (∀ i, 0 ≤ p i) ∧ ∑ i, p i = 1
 
noncomputable def bhatt {n : ℕ} (p q : Fin n → ℝ) : ℝ :=
  ∑ i, Real.sqrt (p i * q i)
 
noncomputable def kolm {n : ℕ} (p q : Fin n → ℝ) : ℝ :=
  (∑ i, |p i - q i|) / 2
 
theorem one_sub_bhatt_le_kolm {n : ℕ} {p q : Fin n → ℝ}
    (hp : IsProb p) (hq : IsProb q) : 1 - bhatt p q ≤ kolm p q := by
  sorry
 
end Capstone

Homework 6 works this statement out completely, as its model proposal. The capstone is the second step. Its risky node is the existence of the measurement: Fuchs and Caves showed that some measurement achieves the fidelity, and that is a real theorem about matrix square roots. Physlib already defines the objects (MState, TrDistance, fidelity). On its master branch of 2026-11-06 the file QuantumInfo/States/Mixed/TraceDistance.lean defines TrDistance and proves basic facts about it, but under the heading -- Fuchs–van de Graaf inequalities it has no proofs yet. A proof would be a genuine contribution.

Option C: a verified interpreter

Lecture 9 gives a small language of commands a meaning with the relation Exec c s t (“command c, started in state s, stops in state t”). An interpreter is a function that runs a command. Because a loop may never stop, it takes a fuel argument and gives up with none when the fuel runs out:

namespace Capstone
 
abbrev Env := String → Nat
 
def Env.set (s : Env) (x : String) (n : Nat) : Env :=
  fun y => if y = x then n else s y
 
inductive Com where
  | skip : Com
  | assign : String → (Env → Nat) → Com
  | seq : Com → Com → Com
  | whileDo : (Env → Bool) → Com → Com
 
inductive Exec : Com → Env → Env → Prop
  | skip (s : Env) : Exec .skip s s
  | assign (x : String) (f : Env → Nat) (s : Env) :
      Exec (.assign x f) s (s.set x (f s))
  | seq {c d : Com} {s t u : Env} :
      Exec c s t → Exec d t u → Exec (.seq c d) s u
  | whileTrue {b : Env → Bool} {c : Com} {s t u : Env} :
      b s = true → Exec c s t → Exec (.whileDo b c) t u →
      Exec (.whileDo b c) s u
  | whileFalse {b : Env → Bool} {c : Com} {s : Env} :
      b s = false → Exec (.whileDo b c) s s
 
def interp : Nat → Com → Env → Option Env
  | 0, _, _ => none
  | _ + 1, .skip, s => some s
  | _ + 1, .assign x f, s => some (s.set x (f s))
  | n + 1, .seq c d, s => (interp n c s).bind (interp n d)
  | n + 1, .whileDo b c, s =>
      if b s then (interp n c s).bind (interp n (.whileDo b c))
      else some s
 
/-- `y := 3 + 2 + 1`, by a loop that counts `x` down from 3. -/
def countdown : Com :=
  .seq (.assign "x" (fun _ => 3))
    (.whileDo (fun s => s "x" != 0)
      (.seq (.assign "y" (fun s => s "y" + s "x"))
        (.assign "x" (fun s => s "x" - 1))))
 
#eval (interp 20 countdown (fun _ => 0)).map (fun s => s "y")
 
theorem interp_sound (n : Nat) (c : Com) (s t : Env) :
    interp n c s = some t → Exec c s t := by
  sorry
 
end Capstone

The #eval prints some 6, a sanity check that the interpreter runs. The theorem says the interpreter never lies: whenever it answers, the answer is one the semantics allows. Prove it by induction on the fuel, for all commands at once (induction n generalizing c s t). The second milestone is the converse, Exec c s t → ∃ n, interp n c s = some t: if the command stops, some amount of fuel is enough.

Option D: a code distance by bv_decide

The distance of an error-correcting code is the smallest number of bit flips that turns one codeword into another. For a linear code it is the smallest weight (number of 1s) of a nonzero codeword, and a code of distance 3 corrects any single error. The Hamming code has 16 codewords of length 7. Over bit vectors the whole statement is a finite problem, and bv_decide (Lecture 10) settles it with a SAT solver:

namespace Capstone
 
def parity (y : BitVec 7) : Bool :=
  y[0] ^^ y[1] ^^ y[2] ^^ y[3] ^^ y[4] ^^ y[5] ^^ y[6]
 
/-- The three parity checks of the Hamming code. -/
def inHamming (x : BitVec 7) : Bool :=
  !parity (x &&& 0b1010101#7) && !parity (x &&& 0b1100110#7) &&
    !parity (x &&& 0b1111000#7)
 
/-- The number of 1 bits, as a 4-bit number. -/
def weight (x : BitVec 7) : BitVec 4 :=
  let b (i : Nat) : BitVec 4 := (x.extractLsb' i 1).zeroExtend 4
  b 0 + b 1 + b 2 + b 3 + b 4 + b 5 + b 6
 
theorem hamming_distance (x : BitVec 7) (h0 : x ≠ 0)
    (hx : inHamming x = true) : 3#4 ≤ weight x := by
  unfold inHamming parity weight at *
  bv_decide
 
example : inHamming 0b0000111#7 = true ∧ weight 0b0000111#7 = 3#4 := by
  decide
 
#print axioms hamming_distance

The example is the sanity check that matters: a codeword of weight exactly 3 exists, so the bound is not vacuous and cannot be improved. The axiom report is the audit:

'Capstone.hamming_distance' depends on axioms: [propext,
 Classical.choice,
 Quot.sound,
 hamming_distance._native.bv_decide.ax_1]

The last axiom is the one Lecture 13 describes: the theorem trusts the compiled checker of the SAT solver’s certificate. Your README must say so. The capstone goes from here to quantum codes. The Steane code is built from two copies of this code, and its distance statement has the same shape with one more hypothesis: is a Hamming codeword that is not in the code’s dual. The Lean-QEC project (SELF-REPORTED) does this at scale; read it for its definitions after you have written your own.

Contributing to Mathlib or Physlib

A finished lemma that others need belongs upstream. Both libraries welcome newcomers and both have rules.

Mathlib. Start with what to contribute: small pull requests (PRs), each with one purpose, and a question on the Lean Zulip (the #mathlib channel) before you start anything large. How to contribute walks through the mechanics: fork leanprover-community/mathlib4, make a branch, commit, push and open a PR; continuous integration builds it; reviewers label it (awaiting-author means it is your turn); a maintainer approves it, and a merge bot lands it. Before you open the PR, read the style guide, the naming conventions (a lemma’s name describes its statement, as in inner_self_of_norm_one) and the documentation rules. If an AI tool wrote any of the code, the contribution page says to disclose it.

Physlib. Physlib has its own AI policy. A human must vouch for every line, because “A clean Lean build proves what was written, but only the human can certify what was written is what they meant.” References must be checked by a person, not delegated to an AI, and discussion with reviewers must be by people. As of 2026-11-06, Physlib proves no-cloning (in QuantumInfo/Operators/Unitary.lean), and we found no no-deleting theorem and no proof of the Fuchs–van de Graaf inequalities. Options A and B are therefore open gaps; say on Zulip that you are working on one before you start.

The audit, before you say “verified”

Lecture 13 ended with five questions for reading other people’s claims (the checklist). The capstone applies them to your own.

Remark 14.2 (The capstone audit).
  1. Statement. Your README puts the English statement and the Lean statement side by side, lists every definition the Lean statement uses, and says what is narrower than the literature (Remark 14.1).
  2. Sanity and non-vacuity. SanityChecks.lean shows that each definition behaves as named and that the main theorem’s hypotheses can all hold together.
  3. Axioms. #print axioms on the main theorem shows only propext, Classical.choice and Quot.sound, or the README explains each extra one, as for bv_decide above.
  4. Reproducible. A fresh clone builds with lake exe cache get and lake build, with no sorry warnings, on the Lean and Mathlib versions pinned in the repository.
  5. Independent. Someone else has built it and read the statement. On Linux, lake check replays the proof through the kernel in a sandbox.

By the course’s own tags, a capstone that passes items 1 to 4 is SELF-REPORTED. It becomes VERIFIED when item 5 has been done by someone else, which is why the last step of the capstone is to swap projects with a classmate and audit each other’s (Remark 14.2). Lecture 13’s PTX paper is a model for item 2: for every kernel it proves that a complete execution exists, so its correctness theorems cannot hold vacuously.

Try this

  • Run lake new myproject math and move the no-deleting block into Myproject/Main.lean. Split the definitions into Defs.lean and check that lake build reports exactly one sorry.
  • Write the \uses{…} lines for all nine nodes of the figure, then run leanblueprint checkdecls once the names exist.
  • For Option C, state the converse milestone in Lean with sorry, and find a command and an amount of fuel for which interp returns none although Exec has a derivation.
  • For Option D, add the Steane hypothesis (not in the dual code) and see whether bv_decide still proves the bound.

Readings