skip to content
Navid Mesbah
فا
← Back

Why I'm Learning Lean

/ 10 min read

Certainty in a World of Probabilities

As an AI scientist, I spend most of my days with models that speak in probabilities: likely answers, plausible outputs, confidence scores, loss curves that go down but never reach zero. So it’s a little ironic that one of my favorite hours of the day lately is spent with a tool that accepts no probabilities at all: a proof assistant.

Most evenings, after the day’s work at Charsook is done, I open Lean and try to prove something. Sometimes it’s an exercise from a tutorial. Sometimes it’s a small property of code I actually ship. Often I lose. Lean tells me, with perfect calm, that my argument has a gap, and I stare at the goal on the screen until I understand why it’s right.

I’m learning Lean. Not for academic reasons, and not because I think every startup should formally verify its code. I’m learning it because of how software is now being made, and because I think the skills it teaches are about to become far more important than most people realize.

What Lean Actually Is

For readers who haven’t encountered it, a quick explanation.

Lean is both a programming language and a proof assistant. You can write ordinary programs in it, but you can also write mathematical statements about those programs, or about anything else, and then write proofs of those statements. The key is that the proofs are checked by the computer. Not checked in the sense of running some tests, but checked completely, step by step, against the rules of logic.

If Lean accepts your proof, the statement is true. Not probably true. Not true for the cases you tried. True, for every possible input, forever.

This has made Lean popular among mathematicians, who have used it to formalize large and difficult areas of mathematics. It has also made it increasingly interesting to people building AI systems, because AI models can now write Lean proofs, and Lean can check them. The model can be wrong as often as it likes; the checker never is.

That last idea is the heart of why I care.

Generation Is Cheap, Trust Is Not

AI agents can now produce more code in an afternoon than I used to write in a month. That’s real, and it’s wonderful. Features that would have taken weeks take days. Experiments that would never have been worth trying are now cheap enough to try.

But it creates a new problem: the volume of code grows faster than our ability to understand it.

When I wrote every line myself, I had a mental model of the whole system. I knew where the fragile parts were. I knew which functions I trusted and which I didn’t. That model was imperfect, but it existed. When agents write most of the code, my mental model becomes thinner. I review, I test, I read carefully, but I can no longer hold the whole thing in my head the way I used to.

The standard tools help. Tests help. But tests only check the cases we thought of, and the most dangerous bugs live in the cases we didn’t think of. If a function is supposed to handle any timeline the user can create, and there are effectively infinite possible timelines, a hundred test cases are a hundred drops in an ocean.

Types help more. A good type system can make whole categories of mistakes impossible. If a function can only receive a non-empty list, it doesn’t need to handle the empty case, and no test can forget to check it. I’ve always been a fan of strong types, which is part of why I enjoy languages like OCaml and Rust.

But types in most languages can only express simple properties. They can say “this is a list of clips.” They usually can’t say “this list of clips never overlaps, is sorted by start time, and its total duration equals the duration of the timeline.”

A proof can say that. A proof says: for every possible input, this property holds. No sampling, no luck, no hoping you thought of the right cases.

For most code, that’s overkill. For the small core that everything else depends on, it’s starting to look like the only honest option.

Moving the Trust Boundary

Here’s the idea that changed how I think about all of this.

In any system, there’s a boundary between what you trust and what you verify. Traditionally, we trusted the programmer. A senior engineer wrote the critical code, other engineers reviewed it, and we trusted that the combination of skill and review was good enough.

When AI writes the code, trusting the author becomes difficult. The author is a model that can be brilliant on one task and confidently wrong on the next. It doesn’t have a track record in the way a human colleague does. Its mistakes aren’t always the kind of mistakes a human would make, so human reviewers don’t always know where to look.

Formal verification lets you move the trust boundary. Instead of trusting the author, you trust two much smaller things: the statement of the property and the proof checker.

The proof checker is small, carefully built, and used by thousands of people. It’s about as trustworthy as software gets.

The statement is the part a human must get right. And here’s the beautiful thing: the statement is usually short. The code that implements a correct merge of two edit histories might be hundreds of lines. The statement that the merge preserves every edit and never duplicates one might be a few lines. I can read those few lines very carefully. I can think about whether they really capture what I mean. That’s a task a human can actually do well.

So the workflow becomes: I write the statement. The agent writes the code and the proof. Lean checks the proof. If it passes, I don’t need to trust the agent at all. I only need to trust my own statement, which I can read and understand completely.

That’s the real promise: shrink the part of the system a human must trust down to something a human can actually read.

Where It Fits at Charsook

We’re not proving our whole product correct. That would be absurd, and it would slow us down to a crawl. Most of what we build is user interface, creative tooling, and integration with external systems, where formal proofs would be expensive and the benefit small.

But there are pieces where being wrong is costly and where the logic is crisp enough to state precisely.

How edits merge. When a person and an AI agent both modify a project, or when two collaborators work on the same timeline, the system has to combine their changes. A bug here can silently lose someone’s work, and creative work is painful to lose.

How timelines stay consistent. Clips, keyframes, transitions, and audio all have to agree about time. A small inconsistency can make an export subtly wrong in a way nobody notices until it’s published.

How certain geometric and timing calculations behave at the edges. Interpolation, easing, coordinate transformations. These are mathematical, and mathematics is exactly where proofs shine.

These are exactly the places where an agent’s “looks right to me” is not enough. They’re also the places where a bug might hide for months, because the failing cases are rare and strange.

We’re early. I’m still learning, and our use of Lean is still experimental. But even the process of trying to state these properties precisely has been valuable. Several times, writing down what should be true revealed that we didn’t fully agree on what should be true. That alone justified the effort.

What Learning Lean Feels Like

I won’t pretend it’s easy.

Lean is strict in a way that can feel almost rude. It won’t accept “it’s obvious.” It won’t accept “and similarly for the other case.” It won’t accept a step that any human mathematician would wave through. It makes you say exactly what you mean, every time.

At first this is frustrating. I would spend an hour on something I could have convinced a human of in a minute. But slowly, the frustration turns into something else. I started noticing how often “it’s obvious” was hiding a real gap in my own understanding. Lean wasn’t being pedantic; it was showing me that I didn’t know something as well as I thought.

There’s also a pleasure that’s hard to describe. When a proof finally goes through, when the goal disappears and Lean says there’s nothing left to prove, there’s a feeling of certainty that almost nothing else in life provides. Not confidence. Certainty.

Coming Back to Math

There’s a personal side to this too.

For years I worked as a university teaching assistant and as a math and computer science coach, with more than a thousand students. A lot of that time was spent trying to show people that a proof isn’t a ritual. It’s not something teachers make you write to fill a page. It’s the moment you truly know something, the moment a statement stops being a claim and becomes a fact.

Many students never felt that moment. For them, proofs were a chore, a sequence of steps to memorize for an exam. I always found this sad, because the feeling of real understanding is one of the best things mathematics can give you.

Lean brings that feeling back for me, with a very strict teacher. As a coach I always wanted students to have that discipline: to know the difference between “I think so” and “I can show it.” Now I get to practice it myself, every evening, with a teacher that never gets tired and never lets anything slide.

I sometimes imagine what it would be like to teach mathematics with a tool like this. A student tries a proof, and instead of waiting a week for a teacher’s red pen, they get immediate, precise feedback about exactly where their reasoning breaks. That’s a different relationship with mathematics. It might be part of the explainer engine I’m building someday.

Why This Matters Beyond My Work

I think formal verification is about to have a moment, and AI is the reason.

For decades, formal methods were respected but rarely used outside of specialized areas like aerospace, chip design, and cryptography. The reason was cost. Writing proofs by hand was slow and required rare expertise. For most software, it wasn’t worth it.

AI changes the economics on both sides. It makes writing code much cheaper, which increases the volume of code that needs to be trusted. And it makes writing proofs cheaper too, because models are increasingly capable of producing proofs that a checker can verify. The expensive part, finding the proof, can be delegated. The cheap part, checking it, stays reliable.

When those two curves cross, verification stops being a luxury and becomes practical. I think we’re close to that crossing for important categories of software. And the people who understand how to state properties precisely will be in a very good position when it happens.

The Bet

My bet is simple. In a world where AI writes most code, the scarce skill is not writing. It’s specifying and verifying.

Types, tests, evals, and proofs are all points on the same line. They are all ways of saying precisely what should be true and checking that it is. Tests check examples. Evals check quality across many cases. Types check structure. Proofs check everything.

Lean sits at the far end of that line. Most of my work will always live closer to the other end, with tests and evals and good judgment. But I want to know how to reach the far end before I need it, because I’m increasingly sure that one day, for something important, I will.

And honestly, even if that day never comes, the evenings have been worth it. There are few better ways to learn humility than to have a computer politely explain, again and again, that you haven’t actually proven what you thought you had.