Use Cases: Mathematical Discovery, Verification, and AI
This chapter has no code. The earlier chapters used Lean as a programming language and touched proofs only at the edges: a decide here, a native_decide there, one theorem about double. Every reader who gets that far asks the same question: what is the proof half of Lean for?
This chapter answers that question with real projects. It covers four areas, in this order:
- Proofs about programs, which follow from what you already know.
- Verification of production software, with Cedar and Aeneas as the main case studies.
- Mathlib, the shared library of formal mathematics, and the large projects built on it.
- Lean and AI, where machine learning systems write proofs and the Lean kernel checks them.
The Lean project keeps a list of use cases at https://lean-lang.org/use-cases. That page changes often, so treat this chapter as a snapshot from late 2026 and check the page for newer work.
Why a Checked Proof Means Something
All four areas depend on one design choice, so it comes first.
When Lean accepts a theorem, a small program called the kernel has checked every step of the proof. Tactics such as simp, omega, and decide do not have to be correct. They search for a proof and emit a proof term, and the kernel checks that term against a few fixed rules. If a tactic has a bug, the worst case is that it fails to find a proof or emits a bad term that the kernel rejects. A tactic bug cannot make Lean accept a false theorem.
The Dutch logician N. G. de Bruijn argued for this design in the 1970s for his Automath system, and people now call it the de Bruijn criterion: a proof system should produce proofs that a small, simple checker can verify. Lean meets it. The kernel is small enough for a person to read, and other people have written independent checkers for Lean proof files, so you do not have to trust a single program. Lean4Lean, for example, implements the kernel in Lean itself, and Nanoda implements one in Rust.
This shapes everything that follows. You need not trust the person who wrote a proof, or the tactic that found it, or the AI model that guessed it. You trust the kernel, the axioms the proof uses, and the statement of the theorem. The last item matters most, and this chapter returns to it several times.
Two features weaken the guarantee, and you saw both in the tour. native_decide asks you to trust the compiler as well as the kernel, since it runs compiled code in place of a kernel check. sorry tells Lean to accept a claim with no proof at all; Lean warns you, but the file still compiles. The command #print axioms lists every axiom a theorem depends on, and it reports sorryAx if a sorry appears anywhere in the proof or the lemmas it uses. Projects that care about trust run that check on every main result.
Proving Things About Programs
The next-steps chapter listed properties you could prove about the programs in this book: the summarizer returns at most n sentences, the symbolic math normalize function is idempotent, and so on. This section describes what such work looks like in practice, without code.
Three levels of evidence
You can gain confidence in a function at three levels.
The first is testing. You run the function on some inputs and look at the output. Every chapter in this book does this. Tests are cheap and catch most bugs, but they cover only the inputs you thought of.
The second is a checked example. An example with decide or native_decide makes the build fail if one specific claim is false. The Hopfield and symbolic math chapters use this. A checked example is a test that runs at compile time; it still covers one input.
The third is a theorem. A theorem states a property for every input, and the kernel checks a proof of it. The double_eq theorem in the tour covers every natural number, not just the ones you tried. That jump from some inputs to all inputs is the whole point of the proof half of Lean.
Specifications
A theorem about a program needs a specification: a precise statement of what the program should do. Writing one is often harder than writing the proof, and it teaches you more about your program than the proof does.
Take the summarizer. A first attempt at a specification might say “the summary contains the most important sentences.” That claim is too vague to state in Lean. A better attempt splits it into parts you can state:
- The summary has at most
nsentences. - Every sentence in the summary appears in the input text.
- The summary keeps the sentences in the order they appear in the text.
- If the text has
nor fewer sentences, the summary is the whole text.
None of these says the summary is good. They say it is well formed. Most proofs about programs work this way: you prove the structural facts and leave judgments of quality to tests and people.
A slow version and a fast version
A common pattern is to write two versions of a function. The first is short, slow, and plainly correct; it serves as the specification. The second is the fast version you run. Then you prove that they return the same result for every input.
For example, a specification for sorting could say “return the list of all permutations of the input, filter for the sorted ones, and take the first.” No one would run that, but anyone can see that it is correct. A merge sort is fast but harder to read. A theorem that the two functions agree on every list moves the trust from the clever code to the plain code. Cedar, discussed below, applies this same idea to a whole language.
What makes proofs about programs hard
A few things make these proofs harder than the tour suggested.
Floating point is the first. Several programs in this book use Float, and Lean treats Float as an opaque type backed by the hardware. You cannot prove much about it inside Lean, because the kernel does not know IEEE 754 arithmetic. To prove that cosine similarity lies between -1 and 1, you would state and prove the claim for a model of the function over the rationals or the real numbers, and then argue in prose that the Float version stays close. Many verification projects make this split.
Partial functions are the second. Lean requires every function to terminate, or to be marked partial. A partial function compiles and runs, but Lean exposes no equations for it, so you cannot reason about its result. If you want to prove things about a loop, you must show Lean why it ends, often with a measure that shrinks on each step.
Input and output are the third. A function that reads a file or calls curl runs in IO, and Lean has no model of the outside world. The usual approach is to keep the IO code thin and put the logic in pure functions that take data and return data. The programs in this book already follow that style, which makes them good candidates for proofs.
Proof upkeep is the fourth. When you change a function, proofs about it may break. Small, general lemmas break less often than long proofs tied to the details of one version. Tactics such as simp and omega help here, since they redo a search after a change in place of replaying fixed steps.
Verification in Production
Proofs about programs stopped being only a research topic some years ago. This section describes two projects that use Lean on real software, then surveys a few smaller ones.
Cedar at AWS
Cedar is a language for access control policies. A policy says which principals may take which actions on which resources, under which conditions. For example: members of the finance group may read invoices, but no one may delete an invoice older than seven years. AWS released Cedar as open source in 2023 and uses it in services such as Amazon Verified Permissions.
Access control code is a natural target for proofs. A bug in an authorizer can let the wrong person read the wrong data, and the space of policies is far too large to test by hand. The Cedar team at AWS calls their method verification-guided development, and it has three parts.
First, they wrote a formal model of Cedar in Lean. The model defines the syntax of policies, how to evaluate them, how the authorizer combines them into an allow or deny decision, and how the validator type checks them. The model favors clarity over speed. It is the specification.
Second, they proved properties of the model in Lean. Examples of the kind of property they state:
- If no policy permits a request, the authorizer denies it. Cedar denies by default.
- If any
forbidpolicy applies to a request, the authorizer denies it, whatever thepermitpolicies say. A forbid always overrides a permit. - If the validator accepts a set of policies, evaluating them never hits a type error at run time. This is a soundness theorem for the validator.
These are exactly the claims a security reviewer would want. They hold for every policy and every request, not for a sample.
Third, they connect the model to the production code. Cedar’s production implementation is in Rust, for speed and for easy use from other services. The team does not prove the Rust code correct directly. They use differential random testing: a test harness generates millions of random policies and requests, runs both the Rust code and the Lean model on each, and flags any case where the two disagree. Since the Lean model is executable, it runs as an ordinary program in this harness. When the two disagree, either the Rust code has a bug or the model does, and the team finds out which.
This is the slow-version, fast-version pattern from the last section, at the scale of a language. The proofs make the Lean model trustworthy, and the random tests extend that trust, with high probability, to the Rust code.
The Cedar team first wrote their model in Dafny, another verification language, and later moved it to Lean. Their public reports cite faster proof checking and the fact that Lean is also a usable programming language, so the model can run in the test harness directly. That second reason is the theme of this book.
Cedar shows something else worth noting. The team found real bugs this way, in both the Rust code and the design of the language, before customers did. Some came from the proofs, when a property the team expected turned out to be false. Others came from the random tests, when the Rust code and the model disagreed on an odd input.
AWS has used Lean in other places too. SampCert, for example, is a Lean library of verified random samplers for differential privacy, and AWS uses code from it in production.
Aeneas: Rust into Lean
Cedar keeps two versions, Rust and Lean, and tests that they agree. Aeneas takes the opposite approach: it translates Rust code into Lean, so you can prove things about the Rust program itself.
Son Ho and Jonathan Protzenko started Aeneas. The tool works in two stages. A front end called Charon extracts a Rust crate from the Rust compiler’s internal form, called MIR. Aeneas then translates that into pure functional code in Lean, along with a set of definitions for the Rust features the code uses, such as machine integers that can overflow.
The key idea concerns Rust’s ownership rules. In most languages, proving things about code that mutates memory through pointers is hard, and verification tools need extra logic to track which pointers might alias. Rust’s borrow checker already forbids most aliasing. Aeneas takes advantage of this. It turns a function that takes a mutable borrow into a pure function that returns the new value, plus, where needed, a second function that says how to write a changed value back. The result is plain functional code with no pointers, which is the kind of code Lean handles well.
So a Rust programmer who wants to verify a function runs Aeneas, gets a Lean file, and writes theorems about the functions in it. If a Rust function might overflow an integer, the Lean version returns an error in that case, and the proof must show the error cannot happen for the inputs in question.
Microsoft has used Aeneas to verify parts of its SymCrypt cryptographic library as the team ports it from C to Rust. Cryptographic code suits this approach well. It is small, it runs everywhere, a bug can be costly, and its specification is usually clear math: this function computes that operation in a finite field.
For a reader of this book, Aeneas has a direct lesson. The functional style you used in every chapter, with data in and data out, is the style Aeneas produces from Rust. The proofs it calls for are the same kind of proofs you would write about your own Lean programs.
Smaller projects worth knowing
Two more projects show the range.
Veil is a framework for verifying distributed protocols in Lean. You describe a protocol, such as a leader election or consensus algorithm, as a transition system: a state, and rules for how the state may change. You then state invariants, such as “at most one node believes it is the leader.” Veil sends many of the proof obligations to automatic SMT solvers and lets you finish the rest by hand in Lean. That mix matters, because fully automatic tools give up on hard cases and fully manual proofs take a long time.
ArkLib is a Lean library for verifying SNARKs, the succinct proof systems used in blockchains and other places where one party must convince another that a computation ran correctly. These protocols mix probability, algebra over finite fields, and complex interaction between a prover and a verifier. Their security proofs on paper are long and have contained errors. ArkLib aims to state and check those security proofs in Lean, building on Mathlib for the algebra.
Both projects show a pattern. Lean does not replace the domain experts. It gives them a place to write down their claims so that a machine can check them.
Mathlib
Mathlib is the community library of formal mathematics for Lean. It began in 2017 as mathlib for Lean 3. When Lean 4 arrived, the community ported the whole library, file by file, with help from an automatic translation tool and a great deal of hand work. The port finished in 2023. The paper on Mathlib that people still cite came out in 2020, and the library has grown by more than ten times since. By recent counts it holds close to two million lines and more than 200,000 theorems, written by hundreds of contributors.
It helps to think of Mathlib as a second standard library, one for mathematics. The Lean standard library gives you lists, arrays, strings, and hash maps. Mathlib gives you groups, rings, fields, vector spaces, measure theory, topology, real and complex analysis, number theory, and much more, with the definitions and the theorems that relate them.
Mathlib for programmers
The best entry point for a programmer is the algebra hierarchy, because it uses a feature you already know: type classes.
The tour showed ToString, a type class with one operation. Mathlib uses the same mechanism to describe algebraic structures. A type class for a monoid says a type has an associative operation and an identity element. A class for a group adds inverses. A class for a ring has two operations, addition and multiplication, with the laws that connect them. A field is a ring where every nonzero element has a multiplicative inverse.
The difference from ToString is that these classes carry proofs as well as operations. An instance of the monoid class for a type must supply the operation, the identity, and proofs that the laws hold. Once you have an instance, every theorem Mathlib proves about monoids applies to your type at once. Lean finds the right instances the same way it found ToString instances in the tour.
This design lets Mathlib state a theorem once, at the most general level, and use it everywhere. A fact about groups works for integers under addition, for nonzero rationals under multiplication, for permutations, and for matrices with nonzero determinant. The ring tactic, mentioned in the next-steps chapter, works for any type with a commutative ring instance: integers, rationals, polynomials, and types you define yourself.
The symbolic math chapter of this book represents a polynomial as a list of exponent and coefficient pairs. Mathlib has its own polynomial type, with proved facts about degree, roots, derivatives, and division. A natural project would be to prove that the derivative function in that chapter agrees with Mathlib’s derivative after converting between the two forms. That project would use both halves of Lean at once.
Mathlib also has a cost. It is large, a first build takes a long time unless you download prebuilt files, and it changes fast, so code written against one version may need updates for the next. Most Lean users who work with Mathlib pin a version in their Lake file and update on purpose.
Large formalization projects
Mathlib exists to support projects that prove real mathematics. A few of those projects show what the community can now do.
Perfectoid spaces (2019). Kevin Buzzard, Johan Commelin, and Patrick Massot formalized the definition of a perfectoid space, a recent and complex object from Peter Scholze’s work. The point was not a new theorem. It was to show that Lean could express the definitions that working mathematicians use today, not only classical results from a century ago.
The cap set bound (2019). In 2016 Jordan Ellenberg and Dion Gijswijt proved a new upper bound on the size of sets of vectors with no three in a line, a problem in combinatorics that had resisted progress for decades. Their proof, based on work by Croot, Lev, and Pach, was short and surprising. Sander Dahmen, Johannes Hölzl, and Robert Lewis formalized it in Lean 3. This was an early sign that a recent result could reach formal form quickly.
The Liquid Tensor Experiment (2020 to 2022). In December 2020 Peter Scholze posed a challenge. He and Dustin Clausen had proved a hard theorem in their new theory of condensed mathematics, and Scholze was not fully sure of the proof. He asked the Lean community to check it. A team led by Johan Commelin formalized the key part by mid 2021 and the full result by 2022. Scholze said the process helped him understand his own proof better. The project changed how many mathematicians viewed formal proof: as a tool that could help with research, not just a check on old results.
The sphere eversion project. A team led by Patrick Massot formalized a theorem from differential topology: you can turn a sphere inside out through a smooth family of immersions. This required a large amount of geometry and analysis that Mathlib did not yet have, which the project then added.
The Polynomial Freiman-Ruzsa conjecture (2023). In November 2023, Timothy Gowers, Ben Green, Freddie Manners, and Terence Tao posted a proof of the Polynomial Freiman-Ruzsa conjecture, a central open problem in additive combinatorics. Tao then organized a public project to formalize the proof in Lean. Contributors split the proof into a graph of small lemmas, each with its own page, and people claimed lemmas and proved them in parallel. The project finished in about three weeks. A result went from preprint to fully checked proof in less than a month, faster than most papers pass peer review.
The Equational Theories Project (2024). Tao organized a second project of a different kind. It looked at thousands of simple laws for a single binary operation, such as “x times (y times z) equals (x times y) times z,” and asked, for each ordered pair of laws, whether the first implies the second. That makes about 22 million questions. Most were easy and fell to automatic tools. Some were hard and needed new ideas from human contributors. Lean checked every answer, whether a person or a program found it. This project points toward a style of mathematics in which humans, automatic provers, and AI tools all contribute, and a kernel keeps the whole result sound.
Fermat’s Last Theorem (from 2024). Kevin Buzzard leads a funded, multi-year project to formalize a proof of Fermat’s Last Theorem in Lean. The goal is not to formalize Andrew Wiles’s original proof line by line. It is to reduce the theorem to facts that mathematicians knew by the 1980s, then keep going as far as possible. The project will add a large amount of modern number theory to Mathlib along the way.
Why mathematicians care
Each of these projects answers a different question. Perfectoid spaces asked whether Lean could state modern definitions. The Liquid Tensor Experiment asked whether it could check a proof the author doubted. PFR asked whether it could keep up with new research. The Equational Theories Project asked whether it could combine work from many people and programs in one sound result.
For a working mathematician, the main gains are three. A checked proof removes doubt about details, which matters more as proofs grow longer and fewer people read them in full. A shared library means you can build on others’ work without checking it yourself. And a precise statement in Lean ends arguments about what a theorem actually says.
Lean and AI
This is the area where Lean has changed most in the last few years, and the area closest to the subject of my other books.
Why Lean suits AI
Large language models write plausible text. Plausible is not the same as correct, and in mathematics the gap between the two is the whole problem. A model can write a proof that reads well and contains a false step on line forty.
Lean removes that gap for every proof it accepts. If a model writes a Lean proof and the kernel accepts it, the proof is correct, no matter how the model produced it. The model can guess, search, or try ten thousand variants. Only the accepted proof matters.
This gives AI research in theorem proving three things it badly needs.
A perfect grader. The kernel returns yes or no. It does not give partial credit, it does not get tired, and no one can argue with it. This makes it a reward signal for reinforcement learning: the model tries to prove a theorem, gets a reward if the kernel accepts the proof, and learns from that.
Cheap, exact feedback. When a proof attempt fails, Lean reports where and why: this goal remains, this tactic failed, this term has the wrong type. A model can use those messages to fix the proof and try again, the same way you fixed errors in the errors chapter.
A large body of training data. Mathlib has more than 200,000 theorems with proofs, all checked, all in a uniform format. That is a rare kind of dataset: large, clean, and known to be correct.
Milestones
AlphaProof (2024). Google DeepMind built AlphaProof to solve competition math problems in Lean. To get training data, they used a language model to translate about a million informal problems into Lean statements. AlphaProof then trained on them by reinforcement learning, with the Lean kernel as the judge of each attempt, in the style of AlphaZero. At the 2024 International Mathematical Olympiad, AlphaProof and a companion system for geometry, AlphaGeometry 2, together solved four of the six problems, a score at the level of a silver medal. AlphaProof solved the hardest problem of the contest, which only five human contestants solved. Humans translated the problems into Lean first, and some solutions took the system days to find. Even so, every solution it produced came with a proof the kernel had checked.
Open prover models. Several groups have released open models that write Lean 4 proofs. DeepSeek’s DeepSeek-Prover series is the best known: it trains on Lean data, uses the kernel to filter and reward its own outputs, and in its second version breaks a hard problem into subgoals before proving each one. Other open efforts, such as Goedel-Prover and Kimina-Prover, use similar ideas. These models report their results on shared benchmarks of Lean problems, such as miniF2F for competition math and PutnamBench for problems from the Putnam exam, and scores on those benchmarks rose quickly through 2024 and 2025.
Formal solutions at the 2025 IMO. At the 2025 Olympiad several AI systems reached gold medal scores. Most wrote their solutions in natural language, which human graders had to read. Harmonic’s Aristotle system wrote its solutions in Lean, so the kernel checked them, and no grader had to trust the model’s reasoning. That difference will matter more as AI systems attack problems whose answers no human already knows.
Tau Ceti. The Lean use-cases page lists Tau Ceti first. It is a project in which AI systems contribute to a library of mathematics, and the Lean kernel checks every proof before it joins the library. This is the Equational Theories Project idea taken further: the contributors are mostly machines, and the kernel decides what counts.
How these systems work
Most current systems combine a few parts, and you could build a small version yourself with the tools from this book.
A language model proposes a next step or a whole proof. Lean runs the attempt and returns either success or an error with the goal state. A search procedure decides what to try next: retry with the error message, try a different tactic, or split the goal into smaller lemmas. Successful proofs feed back into training, so the model improves on the kind of problems it solved.
The Ollama and Gemini chapters of this book showed how to call a model from Lean. The standalone programs chapter showed how to run external commands. Put those together and you have the outline of a proof loop: send a theorem statement to a model, write the reply to a file, run lean on that file, and send any error back to the model. A loop like that, run against the properties in the next-steps chapter, would make a fine weekend project. Before you trust any result, check that the proof uses no sorry and no unexpected axioms.
What remains hard
The kernel checks proofs. It does not check that a theorem states what you meant. This is the most important limit of the whole approach, and AI makes it sharper.
Translating an informal claim into Lean is called autoformalization, and it is easy to get subtly wrong. Lean’s conventions can surprise you. In Lean, natural number subtraction stops at zero, so three minus five is zero. Division by zero returns zero for many number types. A statement that seems to say something deep may be trivially true because of one of these conventions, and a model trained to maximize accepted proofs will find that trivial route if it exists. A human must still read the statement and confirm it says the right thing.
Other limits matter too. Competition problems are short and self-contained; research mathematics depends on long chains of definitions that may not exist in Mathlib yet. A proof that the kernel accepts can still be thousands of lines that no human can read, which proves the result but may not explain it. And the systems that do best at present still need a great deal of computing power per hard problem.
These limits point at a division of labor that many researchers now expect. Humans choose the questions and check that the statements mean what they should. Machines search for proofs. The kernel checks every one.
What This Means for You
You now know Lean as a programming language, and you have seen what the proof half can do. Here is one path from this book into that work.
Start with proofs about your own programs. Pick one property from the table in the next-steps chapter and prove it for every input. You will learn more Lean from one such proof than from many small examples, and you will learn something about your program too.
Then read about Cedar. The AWS team has published papers and talks on verification-guided development, and the Cedar specification in Lean is open source. Reading how they structured a real model and its proofs teaches more than any toy example.
When you need algebra or analysis, add Mathlib. Learn the type class hierarchy first; it builds directly on what the tour taught.
If you work in AI, try the proof loop described above. Even a small model, run locally through Ollama, can prove simple lemmas when Lean tells it what went wrong. You will see both the strength of the approach, a checker that never accepts a bad proof, and its limit, a checker that cannot tell whether you asked the right question.
Lean began in 2013 as a research project of Leonardo de Moura at Microsoft Research. Today the Lean Focused Research Organization, founded in 2023, develops it, and companies, universities, and AI labs depend on it. The same language that ran the fourteen programs in this book now checks access control at AWS, cryptographic code at Microsoft, new results in number theory, and proofs that no human wrote. That range is the reason I think Lean is worth learning as a programming language first: once you can write Lean programs, every one of these uses is open to you.