IEEE Quantum Week 2026 · Tutorial

Lean into QEC

machine verification for quantum error correction
Stavan · Aws · Swamit · Nithin · Toronto · 13 September 2026

What You’ll Leave With

1A reason to use Lean
2Your first formalized quantum proofs

The Plan

Session 1
Session 2
this talk
demo 1
setup + exercises
lunch
quantum in Lean
demo 2
exercises

Lean in the News

The Decoder · May 2026
“Google Deepmind’s AlphaProof Nexus solves decades-old math problems for a few hundred dollars”
⊢IN LEAN
Forbes · August 2026
“Claude Just Broke A Math Record That Stood For 37 Years”
⊢IN LEAN
Quanta Magazine · September 2026
“AI Has Solved One of Math’s $1 Million Millennium Prize Problems”
⊢IN LEAN

Definitions and Theorems

def IsEven (n : ℕ) : Prop := ∃ k : ℕ, n = k + k
def fib : ℕ → ℕ | 0 => 0 | 1 => 1 | n + 2 => fib n + fib (n + 1)
= 0, 1, 1, 2, 3, 5, 8, 13, …
theorem fib_six_even : IsEven (fib 6)
theorem and_swap (P Q : Prop) : P ∧ Q → Q ∧ P := by intro h constructor · exact h.right · exact h.left
theorem irrational_sqrt_two : Irrational (√2)
lemma X_on_ket0 : X • |0⟩ = |1⟩
theorem fermat_last_theorem : ∀ n ≥ 3, ∀ a b c : ℕ, a ≠ 0 → b ≠ 0 → c ≠ 0 → a ^ n + b ^ n ≠ c ^ n

Proofs are Checked

theorem and_swap (p q : Prop) : p ∧ q → q ∧ p := by intro h constructor · exact h.right · exact h.left
theorem fermat : ∀ a b c n : ℕ, 3 ≤ n → a ≠ 0 → b ≠ 0 → a^n + b^n ≠ c^n := by trivial
kernel
✓
kernel
✗
tactic 'trivial' failed
⊢ ∀ a b c n : ℕ, 3 ≤ n → …

Proofs are Interactive

theorem and_swap (p q : Prop) : p ∧ q → q ∧ p := by intro h constructor · exact h.right · exact h.left
Tactic statep q : Prop ⊢ p ∧ q → q ∧ p
Tactic statep q : Prop h : p ∧ q ⊢ q ∧ p
Tactic statecase left h : p ∧ q ⊢ q case right h : p ∧ q ⊢ p
Tactic statecase left h : p ∧ q ⊢ q
Tactic statecase right h : p ∧ q ⊢ p
Tactic stateNo goals ✓

A Brief History of Lean

ORIGINS MATHEMATICS AI 2013 Lean Leonardo de Moura · Microsoft Research 2017 mathlib the mathematicians arrive 2019 – 2022 research-level mathematics perfectoid spaces · the Liquid Tensor Experiment 2024 SCIENTIFIC AMERICAN · JULY 2024 “AI Reaches Silver-Medal Level at This Year’s Math Olympiad” 2025 BUSINESS WIRE · JULY 2025 “Harmonic Announces IMO Gold Medal-Level Performance” 5 / 6 proofs — formally verified in Lean

Setup

Quantum in Lean

Session 1
Session 2
Introduction to Lean
Demo 1
Setup + Exercises
Lunch
Quantum in Lean
Demo 2
Exercises

Collaboration at Scale

stated formalized — kernel-checked
PFR ✓✓✓✓ ✓✓ ✓✓✓ ✓✓ ✓

Metaprogramming and Widgets

h : s ⊆ t ⊢ s ∩ u ⊆ t ∩ u
t s u
#toric_chain zLoop

Why Formalize QEC?

1Verified discovery of new codes
2Trust across the stack

QECLean

Stabilizer formalism
[[n, k, d]]
Formalized codes
Widgets

QEC Primitives in Lean

Pauli operator
P ∈ {I, X, Y, Z}
inductive PauliOperator : Type | I : PauliOperator | X : PauliOperator | Y : PauliOperator | Z : PauliOperator
n-qubit Pauli operator
P = P₁ ⊗ P₂ ⊗ ⋯ ⊗ Pₙ
Pᵢ ∈ {I, X, Y, Z}
e.g. X ⊗ Z
def NQubitPauliOperator (n : ℕ) : Type := Fin n → PauliOperator example : NQubitPauliOperator 2 := fun | 0 => X | 1 => Zexample : NQubitPauliOperator 2 := P[XZ]
Pauli group element
g = ik · P₁ ⊗ ⋯ ⊗ Pₙ
k ∈ {0, 1, 2, 3}
the Pauli group 𝒫ₙ
structure NQubitPauliGroupElement (n : ℕ) where phasePower : Fin 4 -- 0 → 1, 1 → i, 2 → -1, 3 → -i operators : NQubitPauliOperator n
stabilizer group
S ≤ 𝒫ₙ
gh = hg for all g, h ∈ S
−I ∉ S
structure StabilizerGroup (n : ℕ) where toSubgroup : Subgroup (NQubitPauliGroupElement n) is_abelian : ∀ g h, g ∈ toSubgroup → h ∈ toSubgroup → g * h = h * g no_neg_identity : negIdentity n ∉ toSubgroup
stabilizer code [[n, k]]
g₁, …, gₙ₋ₖ ∈ 𝒫ₙ
independent, pairwise commuting
S = ⟨g₁, …, gₙ₋ₖ⟩, −I ∉ S
structure StabilizerCode (n k : ℕ) where hk : k ≤ n generatorsList : List (NQubitPauliGroupElement n) generators_length : generatorsList.length = n - k generators_phaseZero : AllPhaseZero generatorsList generators_independent : GeneratorsIndependent n generatorsList generators_commute : ∀ g ∈ listToSet generatorsList, ∀ h ∈ listToSet generatorsList, g * h = h * g closure_no_neg_identity : negIdentity n ∉ Subgroup.closure (listToSet generatorsList)
logical operators
C(S) = { g ∈ 𝒫ₙ : gs = sg ∀ s ∈ S }
g logical ⇔ g ∈ C(S)
g nontrivial ⇔ ikg ∉ S for all k
noncomputable def centralizer (S : StabilizerGroup n) : Subgroup (NQubitPauliGroupElement n) := Subgroup.centralizer (S.toSubgroup : Set (NQubitPauliGroupElement n)) def IsNontrivialLogicalOperator (g : NQubitPauliGroupElement n) (S : StabilizerGroup n) : Prop := g ∈ centralizer S ∧ ∀ s ∈ S.toSubgroup, s.operators ≠ g.operators
distance
d = min { wt(g) : g nontrivial logical }
def HasCodeDistance (C : StabilizerCode n k) (d : ℕ) : Prop := d ≥ 1 ∧ (∀ g, IsNontrivialLogicalOperator g C.toStabilizerGroup → 0 < weight g → weight g ≥ d) ∧ (∃ g, IsNontrivialLogicalOperator g C.toStabilizerGroup ∧ weight g = d)
stabilizer code [[n, k, d]]
structure StabilizerCodeWithDistance (n k d : ℕ) extends StabilizerCode n k where hasDistance : HasCodeDistance toStabilizerCode d

The Steane Code

1110100
1101010
1011001
ZZZIZII
ZZIZIZI
ZIZZIIZ
XXXIXII
XXIXIXI
XIXXIIX
[[7, 1, 3]]

Does It Scale?

[[7, 1, 3]]
Steane
[[L², 1, L]]
rotated surface
[[2L², 2, L]]
toric
[[144, 12, 12]]
gross code

Exercises

The Certificate

StabilizerCodeWithDistance 7 1 3⊢IN LEAN

Resources

Natural Number Game
Mathematics in Lean
Lean Zulip
QECLean
sjain298@wisc.edu