← Latest papers
💻 computer science

From Lecture Notes to Lean: Formalizing a Textbook on Probability Theory

This paper reports on an ongoing project to formally verify the textbook "Measure-Theoretic Probability" in the Lean theorem prover, aiming to create a machine-checked companion that bridges textbook statements with the Mathlib library to enhance mathematical verification, clarify assumptions, and support reliable AI-assisted mathematics.

Original authors: Shuo Deng, Kenneth W. Shum

Published 2026-07-31
📖 7 min read🧠 Deep dive

Original authors: Shuo Deng, Kenneth W. Shum

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are walking through a vast, magical library where every book contains the secrets of the universe. For centuries, humans have been the only ones reading these books, writing proofs, and checking each other's work. But recently, a new kind of librarian has arrived: a super-smart robot that can read, write, and argue about math faster than any human. This robot can generate thousands of mathematical arguments in the time it takes you to brew a cup of tea. The problem? The robot is a bit of a show-off. It can write arguments that sound perfect and look very convincing, but sometimes, they are built on invisible cracks or made-up facts. It's like a magician who pulls a rabbit out of a hat, but the rabbit is actually a very realistic drawing.

This is where the concept of "formalization" comes in. Think of it as a magical spell-checker for math. Instead of just reading the words, this spell-checker forces the author to write down every single rule, assumption, and step in a language so precise that a computer can check it line by line. If the logic has a single gap, the computer refuses to accept it. The paper you are about to read explores what happens when we try to use this spell-checker on a very important math textbook about probability—the study of chance, risk, and how likely things are to happen. It asks: Can we take a book written for human students, translate it into this super-precise computer language, and use it to teach the next generation how to spot the difference between a real proof and a robot's hallucination?


The Project: Turning a Textbook into a Computer-Checked Treasure Map

The authors, Shuo Deng and Kenneth Shum, are on a mission to take a specific university textbook called Measure-Theoretic Probability: With Applications to Statistics, Finance, and Engineering and turn it into a "Lean" project. Lean is a computer program that acts like a strict, unblinking referee for mathematics. The book they chose is a tough one, covering 14 chapters of advanced math, from calculating areas under curves to predicting how random events behave over time. It contains 81 definitions, 127 theorems, 107 examples, and 134 problems.

Their goal isn't just to type the book into a computer. That would be like taking a recipe for a cake and just typing the words into a word processor. Instead, they are rebuilding the cake from scratch using a new set of ingredients (the computer's logic) to make sure the cake actually rises. They want to create a "machine-checked companion" for the book. Imagine if, while you were reading a chapter on probability, you could click a button and see the computer verify, step-by-step, that the author's logic is 100% solid. If the author skipped a step or made a hidden assumption, the computer would scream, "Wait a minute! You didn't prove that!"

The Big Challenge: Speaking Two Different Languages

The authors found that the textbook and the computer's library (called Mathlib) speak two very different languages. The textbook is written for humans; it uses shortcuts, familiar names, and steps that feel natural to a student. The computer's library, however, is built for maximum power and reuse. It uses very abstract, general terms that can apply to almost anything in math.

To bridge this gap, the authors had to act like translators. Sometimes, the textbook's definition of a concept was slightly different from the computer's. Instead of forcing the textbook to change its style, the authors wrote "bridge lemmas." Think of these as little adapters or connectors. They take the textbook's familiar idea, plug it into the computer's powerful engine, and prove that the two are actually saying the same thing. This is crucial because if the computer version is too abstract, students won't understand it. If it's too simple, the computer won't accept it. The authors had to find the perfect middle ground.

The Robot's Role and the Human's Safety Net

Here is where the story gets interesting. The authors didn't do all the typing themselves. They used an "agentic workflow," which is like having a team of AI robots do the heavy lifting. These robots read the textbook pages and tried to write the Lean code. But the authors learned a vital lesson: you cannot just trust the robots.

The robots are great at generating code, but they can be tricky. They might prove a slightly easier version of a theorem, or they might sneak in an extra rule that makes the proof too easy. To catch this, the authors set up a two-step check. First, the computer checks if the code compiles (does it run without errors?). Second, a human reviewer looks at the code to see if it actually says what the textbook said. It's like having a robot write a story, but a human editor has to read it to make sure the plot makes sense and the characters aren't doing impossible things.

Surprises and Mistakes Found

This process of translation actually helped the authors find a mistake in the original textbook! In one chapter, the book claimed that if a function works on two smaller pieces of a timeline, it must work on the whole timeline. The robot, trying to translate this into Lean, flagged it as a problem. When the human authors looked closer, they realized the textbook was missing a hidden assumption. The theorem was only true if you added a specific condition that the book forgot to mention in that specific sentence. This is a superpower of formalization: it forces you to be honest about every single rule. It's like finding a crack in a dam that you didn't know was there until you tried to build a perfect model of the water flow.

Another example involved "variance," a way to measure how spread out numbers are. The textbook gave a simple formula. The robot tried to use it, but the computer pointed out that the formula only works if the numbers are "integrable" (a fancy way of saying they behave nicely). The textbook assumed this was obvious, but the computer demanded it be written down explicitly. The authors had to fix the code to make sure the computer knew exactly when the formula was safe to use.

Why This Matters for the Future

The authors aren't just building a cool project; they are building a foundation for the future of math in an AI world. As robots get better at writing math, we will need better tools to check if that math is real. This project shows that we can take a standard textbook, translate it into a computer language, and use it to teach students how to think clearly. It turns the textbook from a static book into an interactive playground where students can see exactly why a proof works.

The paper concludes that while AI can generate proofs, it cannot yet replace the human judgment needed to decide if a proof is right for the context. The computer can check the steps, but a human (or a very careful process) must decide if the steps are the ones we actually wanted. This project is a step toward a future where AI helps us learn, but we still hold the reins to make sure the math is true. It's not about replacing the teacher; it's about giving the teacher and the students a super-powered magnifying glass to see the truth behind the numbers.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →