Scaling Lean for AI

Leonardo de Moura

Vice President and Distinguished Scientist, AWS

Chief Architect, Lean FRO

SViL · Stanford · November 7, 2026

What is Lean?

A proof assistant and programming language that is transforming how we approach maths, software verification, and AI.

Lean provides machine-checkable proofs.

Lean is implemented in Lean, and is very extensible and scalable.

Small trusted kernel. Proofs can be exported and independently checked.

352K+ unique installations: ~203K VS Code; ~149K Open VSX.

Lean in the editor: proof state alongside the code

Programming and Theorem Proving in Lean

"You have written my favorite computer game" — Kevin Buzzard, Imperial College

def odd (n : Nat) : Prop := ∃ k, n = 2 * k + 1 theorem square_of_odd_is_odd : odd n → odd (n * n) := by intro ⟨k₁, e₁⟩ simp [e₁, odd] exists 2 * k₁ * k₁ + 2 * k₁ lia

Mathlib: The Lean Mathematical Library

Created in July 2017, in Lean 3 during Big Proof. September 2026:

Mathlib dependency graph

Mathematics Is Adopting Lean

Six Fields Medalists engaged: Tao, Scholze, Viazovska, Gowers, Hairer, Freedman.

Tao on Lex Fridman

Software Verification

  • Cedar (AWS): Verified Authorization

  • SymCrypt (Microsoft): Verified Cryptography

  • Kraken (Google): x64 and aarch64 Assembly

  • ArkLib (Ethereum Foundation): Formally Verified Arguments of Knowledge

  • Signal Shot (Beneficial AI): Verify the Signal protocol and app

  • SampCert (AWS): Differential Privacy

  • CSLib: Computer Science Library

Papers with Lean

Papers with Lean per month, January 2025 to October 2026: 27 in October 2025, 409 in October 2026 100 200 300 400 15 Jan 23 Feb 11 Mar 9 Apr 25 May 13 Jun 15 Jul 13 Aug 19 Sep 27 Oct 25 Nov 23 Dec 30 Jan 39 Feb 64 Mar 84 Apr 87 May 111 Jun 134 Jul 164 Aug 301 Sep 409 Oct 2025 2026

Lean on GitHub

Developers pushing Lean code on GitHub per quarter, 2024 to Q2 2026 2,000 4,000 6,000 2024 2025 2026 2,696 6,637 United States Other economies

AI Is Writing Lean

Fermat's Last Theorem: 13M+ Lines of Lean

Anthropic: Formalizing Fermat's Last Theorem

"We are sharing the first complete computer-checked proof of Fermat's Last Theorem. Claude worked largely autonomously over 11 days to write the proof in the Lean programming language."

Navier–Stokes and Euler in Lean

Buckmaster and Alpöge announce three blow-up results

OpenAI: On the Navier–Stokes Millennium Prize Problem

Lines of Lean, September 22: Buckmaster–Alpöge 1.81M; OpenAI 641K.

OpenAI: Subexponential k-SAT in Lean

Deterministic subexponential-time algorithm for k-SAT, every fixed k ≥ 2. Also counts satisfying assignments exactly, in polynomial space. AI output October 16; Lean formalization October 17.

From OpenAI's Comparator challenge file:

abbrev Clause (V : Type u) := Finset (Literal V) abbrev CNF (V : Type u) := Finset (Clause V) def WidthAtMost (k : ℕ) (F : CNF V) : Prop := ∀ C ∈ F, C.card ≤ k def count (F : CNF V) : ℕ := (satisfyingAssignments F).card

The theorem: one fixed machine computes count F for every F with WidthAtMost k F, within the stated time and space bounds.

Under examination by a group led by Russell Impagliazzo, Ramamohan Paturi, and Ryan Williams.

Classification of Finite Simple Groups

Axiom logo

CFSG: published mathematics and Lean formalizationAxiom reports a 43.1-million-line formalization over 24 days, building on published mathematics and earlier formalization work. Published proofLean formalization~15,000 pages in 500+ articlesWork by about 100 mathematicians43.1 million lines · 24 daysAI agents directed bymathematicians and engineers

34 deviations from the published arguments, resolved during formalization.

The Stacks Project in Lean

Axiom logo

  • The ~7,500-page open reference for algebraic geometry, started by Johan de Jong (Columbia) in 2005.

  • Dozens of statements needed refinement: missing hypotheses, edge cases in positive characteristic.

Stacks Project in Lean: 15.8M lines of Lean, 663,090 declarations, 62,975 Lean files; 15,279 of 16,249 formalizable tags 15.8M lines of Lean 663,090 declarations 62,975 Lean files Stacks tags formalized 15,279 of 16,249 formalizable tags (94%) Axiom, November 4, 2026 · the Stacks Project: ~7,500 pages, started by Johan de Jong in 2005

Tau Ceti

Tau Ceti: human targets, AI authorship, review gates, and recorded growth Review requirements feed the merge gate; human review is additionally required for pull requests touching human-owned files. Three recorded line totals are shown on a common linear scale; no daily trajectory is inferred. Tau Ceti review process Kim Morrison (Lean FRO) Mathematicians choose targets Human roadmap AI agents Code + proofs Pull requests AI reviewers Open review rubrics Lean proof checks Merge Touches human-owned files Human review required Lines of Lean, from zero on June 3, 2026 Jun 3 0 Sep 25 1,657,293 Nov 5 5,574,734

At the current rate, Kim expects 100M lines by 2027. Anthropic donated $3M of inference to Tau Ceti (AI for Science program).

All 100 Theorems in Lean

Freek Wiedijk's list of 100 significant theorems: Lean is the first system with proofs of all 100.

The 100th, October 30: Green's theorem, in Tau Ceti.

theorem green_ac_index_one {γ : ℝ → ℂ} {a b : ℝ} {U : Set ℂ} {P Q : ℂ → ℝ} (hab : a < b) (hγ : AbsolutelyContinuousOnInterval γ a b) (hclosed : γ a = γ b) (hU : IsOpen U) (hregion : filledHull (γ '' uIcc a b) ⊆ U) (hP : ContDiffOn ℝ 1 P U) (hQ : ContDiffOn ℝ 1 Q U) (hindex : ∀ z ∈ filledHull (γ '' uIcc a b) \ (γ '' uIcc a b), Contour.windingNumber γ a b z = 1) : IntervalIntegrable (circulationFun P Q γ) volume a b ∧ IntegrableOn (curl P Q) (filledHull (γ '' uIcc a b) \ (γ '' uIcc a b)) ∧ (∫ t in a..b, circulationFun P Q γ t) = ∫ z in filledHull (γ '' uIcc a b) \ (γ '' uIcc a b), curl P Q z := TauCeti.green_ac_index_one

Scale of Lean Formalizations

Scale of Lean formalizations: total Lean lines, log scale, June 2025 to October 24, 2026

Cedar (AWS): Verified Authorization

Cedar — open-source authorization policy language. Used by AWS Verified Permissions and AWS Verified Access.

Cedar spec: the model is written in Lean.

Three examples of verified components: evaluator, authorizer, validator.

  • forbid_trumps_permit — if any forbid policy is satisfied, the request is denied.

  • allowed_only_if_explicitly_permitted — a request is allowed only if at least one permit policy is satisfied.

  • typecheck_is_sound — if the validator accepts a policy, evaluation produces a boolean.

Cedar website

Cedar: The Engineering Story

Executable Lean model alongside Rust production code. Lean model ~10× smaller than Rust.

Cedar differential testing

  • ~100M differential random tests nightly. Lean: 5 μs/test. Rust: 7 μs/test.

  • Release gate: no Cedar version ships unless model, proofs, and differential tests are current.

"We've found Lean to be a great tool for verified software development." — Emina Torlak, Senior Principal Scientist, AWS

SampCert (AWS): Verified Differential Privacy

An open-source Lean library of formally verified differential privacy primitives.

The implementation is not only verified, but it is also twice as fast as the previous one.

SampCert is software, but its verification relies heavily on Mathlib.

The verification of code addressing practical problems in data privacy depends on the formalization of mathematical concepts, from Fourier analysis to number theory and topology.

Deployed in AWS Clean Rooms Differential Privacy.

PLDI 2025: "Verified Foundations for Differential Privacy."

“For SampCert, I started using Lean because of Mathlib, but I realized that Lean isn't just an excellent proof assistant, it's also a very pleasant and efficient programming language with a great ecosystem.” — Jean-Baptiste Tristan, Senior Principal Scientist, AWS

Kraken (Google): Verified Assembly

Jonathan Protzenko (Google, project lead), Andres Erbsen, Luke Zarko, and the Kraken team

FFmpeg's AAC SBR decoder: memory safety under its API protocol

10,000+ assembly instructions; ~240K lines of Lean.

Verifies x64 and aarch64 assembly, hand-written or compiler-generated. Semantics written by hand; proofs written by agents.

Built with vcgen (Sebastian Graf, Lean FRO).

SymM and grind hom are joint work between Google and the Lean FRO.

SymCrypt (Microsoft): Verified Cryptography

Son Ho (Microsoft Research) and the SymCrypt team

SymCrypt verification with Aeneas

SymCrypt: Microsoft's core cryptographic library, rewritten in Rust.

Aeneas: translates safe Rust to pure functional Lean code.

The first release includes complete proofs for ML-KEM and SHA-3 code running in Windows Insider builds today.

"We are verifying code faster than we can write it." — Son Ho, SymCrypt, Microsoft

Neuron Compiler (AWS)

Sean McLaughlin and the Neuron team

Work on the compiler stack for AWS Trainium, Amazon’s custom AI accelerator.

700,000 lines of Lean and growing. Assembler, disassembler, and several kinds of ISA simulators.

  • The ISA specification changes several times per week.

  • Lean provides an up-to-date simulator that hardware and verification engineers share.

  • Work is expanding to higher-level compilation and lower-level simulation.

Long-term goal: end-to-end compiler verification — source program compiles to Trainium machine code, with a proof that compilation preserves semantics.

Neuron: A Simple Model and a Fast Implementation

Sean McLaughlin and the Neuron team

A simple model and an optimized implementation

An AI-generated C version had many bugs.

The team instead used AI to write a fast Lean version and prove it equivalent to the simple model.

xv6: From Rocq to Lean

Frans Kaashoek and Nickolai Zeldovich (MIT)

xv6 kernel (6,657 lines of C and assembly): verified in Rocq with AI agents, then ported to Lean by an agent.

xv6 proofs ported from Rocq to Lean by an agent: about half the lines of proof, about 5 times faster to check Lines of proof Rocq Lean about half the size Build and check time Rocq Lean about 5× faster Normalized, Rocq = 1.

lean-zip: zlib in Lean

Kim Morrison (Lean FRO)

Coding agents (Claude and Codex) converted zlib to Lean, proved it correct, then optimized it under the proof.

theorem zlib_decompressSingle_compress (data : ByteArray) (level : UInt8) (maxOutputSize : Nat) (hsize : data.size ≤ maxOutputSize) : ZlibDecode.decompressSingle (ZlibEncode.compress data level) maxOutputSize = .ok data := LeanZip.zlib_decompressSingle_compress
  • Silesia corpus (212 MB), level 6: lean-zip 4.57 s, miniz_oxide (Rust) 5.77 s; 2× at level 9. 1,100+ theorems, ~32K lines of proof.

"This allows us to let AIs loose optimizing the code, requiring that they update the proof whenever the implementation materially changes." — Kim Morrison

lean-zip: Optimized Under the Proof

lean-zip vs miniz_oxide over the optimization history

Hex: Verified Algorithms

Kim Morrison (Lean FRO)

Specifications by people; code and proofs by AI agents.

Integer polynomial factorization

Berlekamp–Zassenhaus with van Hoeij's reconstruction, verified for the first time. Faster than Isabelle's verified implementation; about 5× slower than FLINT (unverified).

LLL lattice reduction

Faster than Isabelle's verified implementation. Or call fplll and check a certificate in Lean.

Graph isomorphism

A subset of nauty, proved correct: canonical forms with kernel-checkable certificates.

Linear programming

SoPlex as an untrusted oracle; exact rational certificates checked in Lean. 2–3× faster than linarith on dense problems.

Aristotle for C and Verilog

Harmonic logo

October 27, 2026

Tensordyne: Verilog

  • 12.2M gate equivalents, 312 pages of specifications.

  • 241 whole-block properties: 185 proved, 56 refuted.

  • 8 bugs found, including earlier sub-block runs, 25,000–110,000 cycles after reset.

LibTomMath: C

  • 3 bugs found and repaired.

  • Two arithmetic routines optimized and proved against the same specification.

  • Modular exponentiation: 1.31–1.38× faster (1,024- to 4,096-bit).

More Software Verification in Lean

Kiro logo

Kiro (AWS), November 2. 26 functions: 70 properties proved in Lean models; 18 counterexamples reproduced on the code.

Certora logo

Certora, September 10. zlib's inflate_table (266 lines of C): memory safety and termination; ~20,000 lines of Lean proof, written mostly by LLMs.

&Truth logo

&Truth, launched October 29. Startup for software verification on Lean, founded by Clark Barrett, Ilya Sergey, and Chris Hsu.

The Lean FRO

The Lean FRO: people, mission, focus, and funders Lean Focused Research Organization, a nonprofit launched in July 2023 by Leo de Moura and Sebastian Ullrich. Twenty people, open source. Its three focus areas are Trust, Scalability and Understanding. The seven funder names reproduce the slide, without amounts or rankings. Focused Research Organization Launched July 2023 Leo de Moura · Sebastian Ullrich 20 people Nonprofit · Open source Formal verification for mathematics, software, hardware, and AI. Long-term self-sustainability. Trust Check proofs with independent and verified checkers. Scalability Build, import, store, and check large Lean developments. Understanding Review statements and specifications; inspect proof structure and dependencies FUNDERS Alex Gerko Alfred P. Sloan Foundation Amazon Beneficial AI Foundation Harmonic Richard Merkin Foundation Simons Foundation

The Statement / Specification Is Our Responsibility

Human intent is autoformalized into a formal statement (human responsibility); Lean checks the proof against that statement (Lean's guarantee)

Formal Conjectures (Google DeepMind): curated, human-verified formal statements of open problems.

Formal Conjectures website

Validation Architecture

Kernel trust: declarations, official kernel, export, independent re-checks

Recent Progress

Mathlib Build Cost

Instructions to build Mathlib×10¹² Mathlib on Lean nightly Mathlib sizelines 90 T 140 T 190 T 1.4M 1.9M 2.4M v4.23-15% v4.36-12% v4.21-10% v4.28-9% 1.39M lines 2.46M+76% 187 T 110 Tmaster 92 T-51% from peak Last 4 weeks (shaded) 90 T 100 T 110 T 120 T 110 T92 T Oct 7Nov 4 2024 2025 2026 Every commit to Mathlib master, Feb 2024 – Nov 2026 · green: Lean releases with >2% impact

lake check and Comparator Live

Lean v4.35 · October 12

  • lake check: export the development and recheck it outside the build.

  • lake comparator: check a solution against a challenge statement.

  • --paranoid: accept only if Lean's kernel and all 5 bundled checkers accept: lean4lean, nanoda, con-leche, con-ron, leanchecker-paranoid.

  • Comparator Live: public since June 11. Paste a challenge and a solution; it runs the checkers in a sandbox.

Comparator Challenges

Challenge.lean: the statement only, with minimal dependencies, for review.

theorem FLT_for_comparator (n : Nat) (hn : 3 ≤ n) (a b c : Nat) (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a ^ n + b ^ n ≠ c ^ n := sorry

Comparator challenge flow

con-leche: A Verified Proof Checker

Joachim Breitner (Lean FRO). Code and proofs written by Claude. Released September 10, 2026.

A proof checker written in Lean. The main theorem: every set of declarations it accepts has a model in set theory. Checks all of Mathlib, FLT, Navier–Stokes, and openai/math. Full Mathlib, one worker:

Full Mathlib, one worker: official kernel 28.9 min, 11.44 GiB, 10.26 T instructions; con-leche 10.7 min, 4.27 GiB, 7.05 T 28.9 min official kernel 10.7 min con-leche Time 11.44 GiB official kernel 4.27 GiB con-leche Peak memory 10.26 T official kernel 7.05 T con-leche Instructions

Mathlib with 8 workers: ~100 s. FLT (1,044,222 declarations).

con-ron and con-agua

con-agua theorem: if checker.s accepts, con-leche and con-ron accept (up to resource limits).

con-leche, con-ron, and con-agua: verified proof checkers written by Claude con-leche Lean a proof checker written in Lean, with a consistency proof Sep 10, 2026 con-ron Rust the same checker in Rust, proved to follow con-leche (Aeneas) Sep 13, 2026 · written in 2 days con-agua x86 assembly verified at the x86 level via Kraken 20k lines of L, 350k lines of proof Oct 25, 2026 · written in 5 days as fast as con-ron on one thread

Checking OpenAI's k-SAT Formalization

Five checkers accept all 95,173 declarations. Time to check, one job each:

OpenAI k-SAT formalization, checking time: con-ron 2.4 min, nanoda 3.6, con-agua 8.7, official 20, con-leche 20.7 con-ron (Rust, verified) 2.4 min nanoda (Rust) 3.6 min con-agua (x86, verified) 8.7 min official kernel (C++) 20 min con-leche (Lean, verified) 20.7 min 95,173 declarations. con-leche and con-agua: one job.

grind: Homomorphisms

[grind hom] rules translate Fin, BitVec, UInt8–UInt64, and Int8–Int64 into Nat/Int arithmetic, where lia decides the goal. Range facts come from [grind hom_pred]. On by default.

example (x y : UInt8) (h : x < y) : x + 1 ≤ y := by grind example (x y : BitVec 8) (h : x < y) : x + 1 ≤ y := by grind example (a b : Int64) (h₁ : 0 ≤ a) (h₂ : a < b) : a + 1 ≤ b := by grind

Prototyped by Andres Erbsen (Google) in Kraken. Replaces the ToInt type classes.

lia: Linear Integer Arithmetic

  • Disjunction hulls: bounds that hold in every disjunct are asserted without case splitting.

  • Dynamic variable ordering: before a Cooper split with many cases (e.g. 2³² for a three-limb counter), move the variable first and restart.

  • Exact equality elimination, as in the Omega test: no derived bounds with coefficients in the thousands.

  • Compact certificates: proofs shared across grind case splits; one benchmark's kernel check 32 s → 145 ms.

example (x y : Int) (b : Bool) (h : (b = true ∧ y = x + 1) ∨ (b = false ∧ y = x + 2)) : x + 1 ≤ y ∧ y ≤ x + 2 := by lia

grind ring: Cheap Certificates

Gröbner basis benchmark: 55.8 G → 8.0 G instructions

  • Steps checked by definitional equality: each step states its result and the kernel checks it by Eq.refl, with hints for where each monomial goes.

  • Packed monomials: a monomial is one natural number; multiplying monomials adds numbers.

    • With base 10: x²y³ is 32, xy is 11, and x³y⁴ is 32 + 11 = 43.

  • Kronecker certificates: check a polynomial identity by evaluating both sides at one well-chosen big number. The kernel compares two numbers instead of normalizing polynomials. One normalization benchmark: kernel 6.0 G → 0.25 G instructions.

    • (x + 1)² = x² + 2x + 1 at x = 10: both sides are 121.

    • Its digits are the coefficients 1, 2, 1.

vcgen: Join Points

def f (n : Nat) : Id Nat := do let mut x := 0 if n > 0 then x := 1 else x := 2 return x + 1

The do elaborator shares the code after the if as a join point:

def f' (n : Nat) : Id Nat := have __do_jp := fun (r : Unit) (x : Nat) => pure (x + 1) if n > 0 then __do_jp () 1 else __do_jp () 2

Unfolding the join point at every jump: k consecutive splits give 2ᵏ copies.

vcgen (verification-condition generator, Sebastian Graf): +jp proves the join point once.

vcgen: Join Points

vcgen join points: duplicated continuations versus shared proofs Three consecutive if/else splits unfold to eight copies of the rest of the program without +jp. With +jp, each split has one shared continuation, proved once under the disjunction of the incoming branch facts. Without +jp With +jp if 1 if 2 if 2 if 3 if 3 if 3 if 3 rest of program rest of program rest of program rest of program rest of program rest of program rest of program rest of program k = 3 then else if 1 __do_jp proved once Hypothesis then-branch facts or else-branch facts then else if 2 __do_jp proved once Hypothesis then-branch facts or else-branch facts then else if 3 __do_jp proved once Hypothesis then-branch facts or else-branch facts rest of program k consecutive splits: 2ᵏ copies join point proved once 2³ = 8 copies

vcgen: Sequential Conditionals

Reported by Paul Govereau (AWS).

12 conditionals: timeout → 56 ms. 32 conditionals: 128 ms.

Before

Conditionals

goals

vcgen + omega

+jp, then omega

4

32

109 ms

34 ms

6

128

426 ms

125 ms

8

512

1.9 s

690 ms

10

2,048

8.3 s

4.2 s

12

—

—

timeout

After

Conditionals

vcgen +jp

lia

vcgen +jp with lia

4

21 ms

16 ms

29 ms

8

25 ms

25 ms

41 ms

12

32 ms

35 ms

56 ms

16

38 ms

46 ms

68 ms

24

51 ms

67 ms

97 ms

32

65 ms

93 ms

128 ms

vcgen: Measurements

Workload

Before

After

VC generation, 2,200 statements

mvcgen: 66 s

vcgen: 0.32 s (206×)

Kernel checking, same proof

246 s

0.53 s (464×)

con-ron proofs (Joachim Breitner)

5,677 G instructions, 592 s

1,647 G instructions (3.4×), 228 s

vcgen (Sebastian Graf) replaces mvcgen; built on SymM.

bv_decide

Henrik Böving: bv_decide ported to SymM, up to 6× faster.

SMT-COMP 2026, QF_BitVec, sequential track, 2,540 benchmarks:

SMT-COMP 2026 QF_BitVec sequential, correct answers of 2,540 Bitwuzla 2,475 bv_decide, kernel-checked 2,401 cvc5 2,375 2,540 benchmarks, sequential track. bv_decide: every proof checked by the Lean kernel.

SMT-LIB QF_BV: 45,159 of 46,191 benchmarks with kernel-checked proofs.

Lake

CFSG module graph, ~19.9K modules: 2,270 s → 1,387 s

Lake's own CPU time: −93%.

Mac Malone, after a proposal by Nickolai Zeldovich: the transitive import closure is computed from one build-store snapshot.

Mac Malone and Marcelo Lynch: cache overhaul with on-demand downloads, parallel transfers, deduplication by hash, content-stable archives.

lean-beam

in Lean v4.36 · release planned November 16

Emilio J. Gallego Arias (Lean FRO)

Agent interface to the Lean server: checkpoints without re-elaboration; branching for tree search.

lean-beam: AI agents talk to a Lean server that keeps module context and runs speculative branches AI agents Claude, Codex, ... many requests lean-beam CLI and MCP server one broker per workspace Lean server + Beam plugin module context kept across requests proof state try tactic A try tactic B try tactic C speculative: the file is not changed

Verso: Type-Checked Documents

  • Future math papers will embed type-checked Lean code.

  • Lecture notes, papers, and slides in one tool.

  • These slides are written in Verso.

  • Every example is checked by Lean.

  • lean-lang.org is written in Verso.

  • My homepage is written in Verso.

  • Verso is a domain-specific language embedded in Lean.

  • Built by David Thrane Christiansen at the Lean FRO.

Verso: source and rendered output

Verso Blueprint

Emilio J. Gallego Arias (Lean FRO), following Patrick Massot's Lean Blueprints

FLT blueprint, warm edit: 46.0 s → 8.18 s (with Wojciech Nawrocki)

  • Informal text, Lean declarations, and the dependency graph in one Lean document.

  • A node is complete when it and its dependencies are formalized.

  • Shown: the Noperthedron blueprint.

Verso Blueprint dependency graph

Palomar and AI Review

Palomar: Kim Morrison, with Terence Tao, Ravi Vakil, Akshay Venkatesh, Jeremy Avigad, and others

Palomar: 999 registered results

Palomar: each entry has the exact statement, the libraries it depends on, review comments.

Stacks in Lean (Axiom): each Lean declaration carries its Stacks tag.

Tau Ceti (Kim Morrison): AI reviewers check pull requests against public rubrics; AI changes to human-owned files need human review.

Code Formatter

Marc Huisinga (Lean FRO)

  • Extensible: formatting rules for all syntax in Lean core (Init, Std, Lean); new syntax can provide its own formatter.

  • Integrated with the language server.

  • Evaluated on all of core and Mathlib; reviewed with Lean FRO, Mathlib, CSLib, and PhysLib maintainers.

  • Infix operators start the line, so the structure of a term is visible at its left edge.

Also in the editor: fold away the proofs of theorems, on request or automatically.

Nerodia: Lean Libraries for Python

Mac Malone (Lean FRO)

  • A bridge between Lean and Python, inspired by Rust's PyO3.

  • Write Python extensions in Lean.

  • Example: ship the verified lean-zip as a Python library.

Nerodia logo

Nerodia: Wrapping lean-zip

LeanZip.lean defines the Python module in Lean. Docstrings become Python docstrings; Python type stubs are generated from the Lean types.

/-- Lean-verified zlib implementation. -/ py_module "leanzip" /-- Verified compression. -/ @[py_module_fn] def compress (data : ByteArray) : ByteArray := ZlibEncode.compress data 6 /-- Verified decompression. -/ @[py_module_fn] def decompress (data : ByteArray) : PyIO PyBytes := do match ZlibDecode.decompressSingle data with | .ok buf => mkPyBytes buf | .error e => raisePyRuntimeError e

Build: nerodia in lakefile.toml; setuptools-lean in pyproject.toml.

Nerodia: Running from Python

>>> import leanzip
>>> print(leanzip.__doc__)
Lean-verified zlib implementation.
>>> test = b"Nerodia: snakes that reside in lakes"
>>> import zlib  # Python's standard implementation
>>> print(zlib.decompress(leanzip.compress(test)))
b'Nerodia: snakes that reside in lakes'
>>> print(leanzip.decompress(zlib.compress(test)))
b'Nerodia: snakes that reside in lakes'

Verified Lean compression, interoperating with Python's zlib. No extra setup beyond pyproject.toml.

Next

con-leche as the Official Kernel

Today and next: modular checking

Kernel Improvements

Kernel next steps: verified bignums, verified kernel, #boost, certificate language Today · official proof checking Lean proof terms C++ kernel type checking + reduction GMP big Nat / Int Trusted: C++ kernel, GMP, compiler and runtime Verified bignums In progress Sebastian Ullrich GMP Big-number arithmetic in Lean proved correct against Nat / Int Verified kernel In progress Joachim Breitner C++ kernel con-leche as the official kernel written in Lean, with a consistency proof #boost Prototype · con-leche Joachim Breitner Selected functions run natively native evaluation ↔ kernel reduction 28 G → 0.24 G official kernel → con-leche + #boost one grind proof Certificate language Design Inside the kernel Small imperative language executed by the kernel, for certificates such as bv_decide's

lean-raw: Two paths to the kernel

Agents "have to use syntax that we designed for human interaction – extensible, flexible, but also slow."

Fully explicit terms parsed directly into Expr, with no elaboration.

Surface syntax: text, extensible parser, elaboration, Expr, kernel. lean-raw: raw text, efficient parser, Expr directly, kernel. Surface syntax text extensible parser Elaboration macro expansion unification, type classes coercions, tactics Expr Kernel type checking lean-raw raw⟦…⟧ efficient parser Expr Kernel type checking no elaboration Holes: ?h, ?(tac), ?[]

lean-raw: Initial benchmarks

Tau Ceti addition law: 74 s of elaboration → 20 ms

Statements and definitions only. G instructions:

File

Surface syntax

lean-raw

Tau Ceti addition law

620.51

1.26

CFSG worst file

1,996.1

638.7

CFSG worst file, no code generation

1,440.9

84.6

Lazy Import

in progress · Sebastian Ullrich

Eager import versus lazy access to memory-mapped module data Eager import merges every module’s constants, simp sets and instances into in-memory tables at startup. Lazy import keeps per-module data in memory-mapped .olean files and builds tables on first access. Only touched entries are highlighted. Prefix trees have shipped; lazy import is in progress. For import Lean, simp set instructions fall from 191M to 11M and instance instructions from 90M to 6M. Eager (today) Lazy Lazy import: in progress import Mathlib .olean module data .olean module data .olean module data Build extension tables at startup Constants Simp sets Instances import Mathlib .olean memory-mapped .olean memory-mapped .olean memory-mapped Load extension data on first use Constants Simp sets Instances import Lean simp sets 191M → 11M instructions instances 90M → 6M instructions

Builds and Elaboration at Scale

  • Mac Malone, Lake: module setup that scales with the size of the import closure; scanning for updated files.

  • Planned: lake build without kernel checks, then lake check with any checker.

  • Sebastian Ullrich: finer-grained caching in elaboration, including type class resolution.

  • Sebastian Graf: the new do notation, with support for intrinsic verification.

Veil 2.0

Ilya Sergey, Qiyuan Zhao, George Pîrlea, Arbenit Kamberi, Ziyu Mao, Vasilii Nesterov, Yueyang Feng (VERSE lab, NUS)

A Lean library for verifying distributed protocols: model checking, interactive proofs, and automated proofs in one framework. Released November 6.

  • Lace: verified explicit-state model checker for safety. 1.4–21.6× faster than TLA+/TLC across 20 benchmarks.

  • Lasso: verified model checker for LTL liveness; also faster than TLC.

  • Interactive proof mode for LTL specifications.

  • An LLM skill translates TLA+ specifications to Veil; ~40 models ported, including Paxos, EPaxos, NOPaxos, Raft.

Veil 2.0: Lace vs TLC

Minimum and maximum TLC-to-Lace wall-clock time ratios across 1–14 worker threads, sorted by maximum speedup. Horizontal positions use a logarithmic scale. MultiPaxos, Paxos, and NOPaxos are highlighted in blue. TLC MultiPaxos 11.4×–21.6× PAStatic 7.6×–18.9× Paxos 7.9×–14.7× LeaseGuard 5.7×–14.0× TicketSem 2.9×–13.5× LeaderlessLog 3.9×–11.8× NOPaxos 5.6×–10.7× 2PC 3.1×–10.2× bcastByz 2.4×–9.0× Percolator 1.9×–8.7× Oswald 3.2×–8.1× TaskClaiming 2.3×–7.5× Mutex 1.8×–6.1× ParCommits 1.8×–6.1× German 1.6×–5.9× SimpAllocator 3.7×–5.6× EWD840 2.4×–4.8× FileLease 1.5×–4.3× Bakery 1.4×–3.7× KeyValueStore 2.2×–3.7× 1× 2× 5× 10× 20× Speedup over TLC (log scale)

EPR for Veil

Most of Veil goals are in EPR (effectively propositional logic). Henrik Böving

EPR pipeline and the card example

A New Code Generator

New code generator: Lean to HIR, MIR, LIR to C or LLVM IR. Every IR has a formal semantics; each pass is proved correct; AI writes IR to IR optimizations checked against the semantics. Lean HIR formal semantics MIR formal semantics LIR formal semantics C or LLVM IR future: assembly AI AI AI IR → IR optimizations by AI, checked against the semantics Each pass proved correct: it preserves the semantics Design priorities Stack-allocated objects Recursive join points Uniqueness annotations Array programs Layout polymorphism

Conclusion

Lean is trusted, scalable, and extensible.

Lean is transforming mathematics and software verification. Software verification is now a major use case.

Lean has verified checkers: con-leche, con-ron, con-agua. Next: con-leche as the official kernel.

Focus: Trust, Scalability, Understanding. Scalability is the new challenge.

Lean FRO is looking for a Technical Communication & Content Lead.

Thank You

Leo de Moura

lean-lang.org | leanprover.zulipchat.com