In short
Leonardo de Moura (creator of the Lean proof assistant) explains how Lean works with LLMs to verify proofs and programs, potentially replacing “absence of bugs” testing with machine-checked guarantees. He contrasts Lean with Z3 SMT solving and discusses Lean’s role in formalizing major math results and software/hardware verification.
Guest backgrounds
Leonardo de Moura is the creator of Lean and a key figure in its development; he also previously worked on Z3 (SMT solver) at Microsoft Research.
Key claims
- Lean is a programming language where you write both code and machine-checkable proofs; the kernel type-checks proofs for absolute assurance.
- Formal verification complements testing: tests can show bugs exist, but proofs cover all cases.
- AI + Lean can translate code to Lean, synthesize proofs, and maintain proofs as code changes.
- Lean’s interactive, stepwise proof control avoids “proof instability” seen in automated solvers.
Notable examples
- Aeneas tool: maps Rust to Lean for verification.
- Zlib compression: AI translated C to Lean, ensured tests pass, and proved compress/decompress returns original data.
- LeanVal challenges: formalized OpenAI’s unit distance conjecture proof in about a month (with a one-million-line Lean proof).
- IMO: Lean used to achieve gold-medal-level solutions; “IMO problems” now benchmarked as easier.
- Verified microkernel “seL4” (Cell 4 mentioned) as a milestone before AI.
Written by AI. May contain mistakes. Listen to the episode to check what was said.
Chapters
Tap a time to open that second in VOExploring Lean's Capabilities
0:32 to 1:48
Discover how Lean helps in writing and verifying proofs for code.
“There's this famous Dykstra quote I want to start the conversation with.”
Lean in Software Verification
1:48 to 2:52
Understand the differences between Lean programs and verification approaches.
“But for software verification, right, there are two very different use cases.”
Concrete Examples of Lean in Action
2:52 to 4:00
Examine practical scenarios of using Lean for program verification.
“To make it really concrete, to give someone a sense of, you know, here's this thing I want to prove about a simple C program.”
The Role of AI in Proof Generation
4:00 to 5:06
Explore how AI assists in generating proofs and optimizing code.
“So I have my C source files and then somehow there's an equivalent Lean proof that's almost like metadata on top of the C program.”
AI's Impact on Formal Verification
5:06 to 6:03
Learn about a project where AI successfully translated C code to Lean.
“And what you're saying sounds similar to in software, where you have to write it cleanly, it needs to be easy to edit and reason about.”
Differences Between Specifications and Test Suites
6:03 to 7:56
Understand the significance of specifications compared to traditional testing.
“I thought it was six months ago I would say it's not possible at all.”
Efficient vs. Inefficient Programming
7:56 to 10:10
Explore how inefficient programs can serve as specifications.
“but you may have a really corner case that's not covered by your test suites but with a proof you're covering all possible cases.”
Maintaining Proofs with AI Assistance
10:10 to 12:10
Discover how AI can ease the burden of maintaining formal proofs.
“And the technology, formal verification complements testing, right?”
Lean as a Dual-Function Tool
12:10 to 14:00
Learn how Lean functions both as a programming language and proof assistant.
“But imagine if your program is changing, that's something that's really common.”
Lean as a Programming Language
14:00 to 15:00
Explore how Lean functions both as a programming language and a proof assistant.
“For people that are familiar with programming languages like Haskell, Lean is close to Haskell.”
Show all 27 chapters
The Tooling of Lean
15:00 to 16:10
Learn about the various tools and systems implemented in Lean and their functionalities.
“That you can get the proofs and find problems in the design.”
Proofs and Theorems in Lean
16:10 to 18:20
Understand how proofs are structured in Lean and the concept of tactic modes.
“and then there's some additional layer on top that keeps track of that stuff.”
Understanding Lean's Kernel
18:20 to 20:00
Delve into the kernel of Lean and its role in proof checking and type checking.
“It's really hard to have a full specification of Lean, but the kernel is possible to have a specification.”
The Impact of Lean on Mathematical Proofs
20:00 to 22:30
Discover how Lean has influenced formal verification and notable mathematical proofs.
“I mean, it will print the statements that has been proven, all the dependencies.”
Lean's Popularity in the Math Community
22:30 to 26:10
Examine the rise of Lean within the mathematical community and its user base.
“He submits a one million line proof for whole proofing lean for this conjecture.”
AI and Lean in Competitive Mathematics
26:10 to 28:00
Learn about the intersection of AI and Lean in competitive mathematics and recent achievements.
“When you say addicted, you mean because that game, that completion engine.”
AI in Mathematical Problem Solving
28:00 to 30:54
Explore how AI applies to mathematical games and proofs.
“I told you that many people see Linhaza game.”
The Future of Handwritten Math and AI
31:29 to 38:51
Discuss the evolving interplay between AI and traditional mathematics.
“And I appreciate them for supporting my work and sponsoring this podcast.”
Understanding SMT Solvers and Z3
38:51 to 42:01
Delve into the mechanics and applications of SMT solvers like Z3.
“Outside of Lean, I know you worked on the Z3 SMT solver.”
Exploring Lean and Z3 for Software Verification
42:01 to 46:08
Learn about the challenges and advantages of using Lean compared to Z3 in software verification.
“sure that we would have a system that's really good for software verification.”
The Technical Challenges of Lean Development
46:09 to 51:08
Discover the complexities involved in transitioning Lean from C++ to its self-implementation.
“Fuzzy Tree, you have a defined language.”
Pros and Cons of Proof Assistants
51:09 to 55:28
Understand the advantages and drawbacks of different proof assistants, particularly Lean.
“We talked a lot about Lean, and I know there's competitors to Lean.”
Differences Between Dependent Types and Higher Order Logic
55:29 to 56:00
Explore the distinctions between dependent type proof assistants and higher order logic in mathematics.
“I mean, the math, I mean, if you talk, for example, Jeremy Avicad was the first user.”
Understanding Dependent Type Theory
56:00 to 1:00:41
Learn about the significance of dependent type theory in math and programming languages.
“you're making improvements making sure the system does what they want uh they come back for more i I mean, this also has a huge impact in growing the community.”
The Future of Lean and Formal Verification
1:00:41 to 1:03:23
Explore the anticipated evolution of Lean and the importance of formal verification in software.
“I'm curious to hear your thoughts on where you think Lean is going, things you're excited about in the future.”
Learning Lean with AI Assistance
1:03:23 to 1:06:07
Discover how AI can enhance the learning experience for Lean programming.
“scalability is super important right because there's a big difference between math and software verification.”
Advice for Aspiring Developers
1:06:07 to 1:07:08
Gain insights on the importance of people skills and community interaction in development.
Transcript
Automatic transcript. May contain errors.0:00LLMs paired with the Lean Proof Assistant have led to breakthroughs in competition math and more recently the verification of frontier math results. Lean is a critical part of this process because it helps validate the candidate proofs the LLM spits out. In this conversation, I asked the creator of Lean about how it works and how it will affect the future of math and software verification. Could that be the end of handwritten math? Here's the full episode.
0:32There's this famous Dykstra quote I want to start the conversation with. It's that program testing can be used to show the presence of bugs, but never to show their absence. And my understanding is that lean and formalizing proofs can be used to show the absence of bugs. And so in your words, what is lean and how do people use it to show bugs can't occur in programs? Lean is a programming language. You can write code, but you can also write proofs. You can reason about your code. You can write state properties about your code and prove them. Lean gives you machine-checkable proofs. You can check your proofs and get absolute assurance they are correct.
1:16You have many independent checkers. But you should view Lean as a platform. You can write code, you can write properties about your codes, and you can prove them. So could you give a concrete example? Because when I think of a proof, I think of what I learned in math. But then how do you couple that with the software that we write? Yeah, it's a great question. It's not that different from math proof. Lean is actually very popular for math. But for software verification, right, there are two very different use cases. You can reason about Lean programs. Lean is a programming language. You can write programs in Lean itself.
2:04Then a Lean program is not that different from a definition you have in math. The techniques are very similar. But if you want to verify programs written in a different programming language that basically two different approaches. One of them, they translate, it's called shallow embedding. They translate for Rust. This happens today. We have a tool called Aeneas that maps Rust into Lean. And you can verify the Lean translation. And there's another technique called deep embedding where you have the semantics. You write a semantics of the programming language of C in Lean. And now you have a data structure that represents a C program.
2:49And you can state properties about it. It's almost like your programs become Lean objects that you can reason about. To make it really concrete, to give someone a sense of, you know, here's this thing I want to prove about a simple C program. Maybe like no buffer overrun or something like that. What's the step-by-step where we could use Lean to prove that? Yeah, yeah. Let's get array, you're trying to access an array in C, you want to make sure the index is in bounds, you're not accessing elements that your array, for example, has 10 elements, you're not trying to access elements 11, right? Basically, you can write that.
3:33You can write in Lean that the value of i at this point in your program is going to be greater than or equal to zero and less than 10. You can write that as a mathematical statement. Another way to view is that if you can express in math what you care about your program, you can verify using Lean. that's another way to view it. So I have my C source files and then somehow there's an equivalent Lean proof that's almost like metadata on top of the C program. Yes. And that's a line-by-line proof and Lean will go and check. Exactly. People will build automation for automating the process. They're going to use techniques like hard triples that says like we have a precondition, some mathematical facts that should be true before executing that statement, the statement, and what is true after.
4:37And we will have a lot of automation to process. Makes your proof modular. Complexity is a challenge in software verification. Handling the complexity is a big deal. And all these frameworks for verifying programs, they are trying to manage the complexity, to make your proofs modular. Even with AI now, AI can prove things automatically for us, but they have to be modular to the proofs if you want them to scale. And what you're saying sounds similar to in software, where you have to write it cleanly, it needs to be easy to edit and reason about. So it's almost like a second software layer on top of the software.
5:20Yes, yes, you can feel this way. You can also flip and imagine a future where you're writing what you want mathematically, precisely, and AI synthesizing the codes and a proof that's the code that was synthesized meets your specification. Oh, interesting. So you could start by writing what you want to be true. Yes. And then... Ask the AI, please. And AI is going to just go and hammer at it until the lean proof says you're good. Yes. It feels like science fiction. Six months ago, I would say this is science fiction. But, for example, now a colleague of mine, Kim Morrison, a few months ago she started a project.
6:09I thought it was six months ago I would say it's not possible at all. She said, we have Zlib, this compression library written in C. And she said, she creates a very complicated prompt for AI saying, I want you to translate to Lean, ensure the Lean version passes the test suite for Zlib. Then I want you to prove that if you compress data and you decompress, you get the original data back. It's a really strong property, right? and believe it or not after one week succeeded doing the whole thing and now it's just asking to optimize the code but you cannot break the proofs I mean you have to keep still proof all the properties you care about I mean compressing and decompressing getting the data back is a really important property for a compression engine yeah this is enrich I mean, it's real.
7:16I mean, it's crazy. And I hear in the industry, a lot of people, they use a really comprehensive test suite coupled with AI to do some really amazing rewrites. Because they have some more confidence that the rewrite is accurate and the AI can check itself. and it sounds like a specification is even better than a comprehensive test suite. Yes, yes, because, well, your quote from Dijkstra captures perfectly, right? With a test suite, you can show the presence of bugs, but not the absence. It's almost like with a good test suite, you may say, well, probably there are no bugs here, but you may have a really corner case that's not covered by your test suites but with a proof you're covering all possible cases.
8:14And it connects. So property-based testing is really popular now. People are writing properties they want to ensure they are true but they are checking with testing, right? But now we can prove them and you say, look, There's no point testing anymore. I prove it. It seems like having a well-written specification is a superset of a test suite. But in terms of the human labor required to create a reasonable test suite versus a reasonable specification, how much more work is it to come up with a great specification? There is a lot. I mean, the programs, in many cases, it's not uncommon for someone to start developing a piece of software and they don't know exactly what the spec is, right?
9:13But you know properties. Usually, their properties are very clear in your mind. Another thing that I tell people to keep in mind is that an inefficient program can be viewed as a specification. Usually, writing an inefficient program is way easier than writing the super efficient one that has many clever tricks. You can write a very, this is what I want, in a very naive way. And you ask the AI, look, generate the efficient version and optimize and prove that's equivalent to my inefficient one. There are many scenarios. I mean, I will not say this. Specifications are always easy to come up with.
9:57But properties, usually the developers have good ideas about properties they care about. As inefficient programming is a spec, right? You can do a specification. And the technology, formal verification complements testing, right? I think your code from Dextra captures perfectly. And I think I saw this on Twitter because Jane Street was more heavily investing in formal verification. And I read their post and they talked about this. I think it was a cell for some software that was entirely formally verified. Yes. And the main drawback to why it wasn't, you know, how much more time would it take writing a program versus verifying it?
10:47Your example, Cell 4, is a great example. This was a major milestone. It's a microkernel they verified. Done manually was before AI. This project was done before AI. It was a big deal. And it's a lot. The cost is super expensive, right? At AWS, we have been using formal verification for a decade, but only for the super safety critical components because it's expensive until now, right? with AI, it changes the game. You have to come up with a spec, but this is not the most painful part. The most painful part is to develop the proofs manually, if you have to, before AI, and maintain the proofs as you change the codes.
11:35Imagine, you know, I've seen people complaining that, oh, I changed the program right now. I have a bunch of failures in my test suite, and I have to patch, go one by one. Imagine if proofs, it's the same process. You have to fix the proofs. Sometimes you don't remember anymore why the proof, what's the story behind this proof. It's a lot, but AI is extremely good at proving, writing formal proofs, maintaining formal proofs. for example yesterday i was changing something in linia i want to modify some proofs for technical reasons i didn't even know what the proofs were about someone else wrote then i said look i want you to i asked the i he write these proofs without using this feature because i'm going to change it i don't want to break the libraries it's instantaneous it came up with the new proofs for me, I mean, it's really good.
12:39And this is crucial for making formal verification mainstream, because otherwise maintaining the proofs was almost like if your program took X amount of time to do the formal verification in the past, it would take 10X, that would be normal. But imagine if your program is changing, that's something that's really common. Now you have to keep maintaining the proofs too. It's a lot of work. But AI eliminates this pain for us. You mentioned that Lean is, because I hear it as a proof assistant, and then you also said it's a programming language. Is that typical for proof assistants to be both a programming language and a proof assistant?
13:30Some of them, especially the ones that are based on dependence type theory, they are like rock and lean are programming languages in proof assistance right you can write definitions like when you're defining concepts in math but some of these definitions can be programs I mean and you have types you have structures it is a programming language but is in that the family of called functional programming language I mean is a specific kind of programming language. For people that are familiar with programming languages like Haskell, Lean is close to Haskell. But with the support for proofs, that's a way to view Lean.
14:15Are there major use cases where people use it as programming language but not as a proof assistant? Well, the first big use case is Lean. It's implemented in Lean. We have many of our tooling is implemented in Lean, like the documentation authoring system called Verso is implemented in Lean. The build system that's called Lake, it's like Lean Make. Lake is implemented in Lean. At AWS, we have a compiler for AI accelerators. It's half a million lines of Lean. And it's using Lean as a programming language. They're proving some properties about the program using Lean. But the main goal is to use Lean as a programming language in this project.
14:59The proofs are like a bonus, right? That you can get the proofs and find problems in the design. I think most people are familiar with programming languages and the tool chains they have. But what are all the major components that you would need for a proof assistant? It's not that different. I mean, if I use modern programming language like Rust, the tooling, for example, Lake is our cargo, right? I mean, you're going to open Visual Studio Code, same way. And I'm going to get all the IntelliSense. One big difference is that we have something called the info view in Lean. Your screen is usually going to be split in two.
15:44You have your file on the right-hand side. You have the info view that tells you information about your proofs, about your codes. is giving you constant feedback about your development. That's basically the main difference. But the tooling, VS code, everything works the same way. It seems like a programming language is the fundamental layer, and then there's some additional layer on top that keeps track of that stuff. Good question. In Lean, you have definitions that show your program, but you have theorems, statements. You're going to say, for example, factorial is always greater than or equal to zero or something like that.
16:29Or if you add two even numbers, you get an even number. You can write statements like that. And immediately you can write actually a program that's the proof. But most people don't do that. They go into something called tactic modes. You can view it as a domain-specific language for writing proofs. In Lean, when you write by, it switches to this domain-specific language. And you have steps like simplify my goal, the state of my proof. You can say, oh, apply this rewriting step. Apply, for example, we know that x plus 0 equals x. You can ask Lean, apply this rewriting. And you're going to see in the info view the state of the proof changing.
17:17You get immediate feedback and you get this feeling that you said you keep telling, applying transformations to your proof. Step by step, you can see what's happening until you get no goals left. You are done. The proof is complete. And some people view this process as a game. I have users that told me, you built my favorite computer game. That's funny. Is Lean itself verified in Lean? Lean is a massive program. You only have to trust the kernel. The kernel is where the proofs are checked. Lean itself is the kind of program that, because there are so many new things we are adding, it's not even clear what is the specification.
18:04For example, what is the specification of a simplifier. You can write general ideas, but users, they want to be able to customize the behavior. They keep asking, they keep changing the specification all the time. I want this, I want that. No, add this knob here. It's really hard to have a full specification of Lean, but the kernel is possible to have a specification. We have a kernel. The kernel that comes with Lean is not verified, but there are other kernels that you can use One of them is implemented by Mario Carneiro. It's called Lean for Lean. And it's implemented in Lean, and he's verifying.
18:46It's proving that this kernel has been verified with respect to the semantics of Lean. This is a cool project. But for us, having multiple kernels is the best way to ensure that your results are correct. I mean, some users implement their own kernels. We have kernels implemented in Rust, in different programming languages. And when you say kernel, what's the responsibility or what's the inputs and outputs of that portion? Yes. And lean proof checking is type checking. These kernels, they are type checking your programs. Basically, you can export your lean developments. you got a big blob and you read this blob and they're going to check if when you say we have a proof in Lean basically we have a term that has a type and you're checking if the type of this term matches the type that you claim it has for example the example of the even numbers this is a type in Lean saying that the sum of two even numbers is an even number you can write you can do that it is exactly a type and the proof what the kernel is checking is whether the type of the proof matches the type you claim this term has and the kernel will check you'll do this type checking the kernels vary between a high performance kernel it's like 5000 lines of code I mean the goal of the kernel should be something you can write yourself of course sometimes people put bells and whistles like one concern people have is like okay but how do I know suppose I wrote Fermat's last theorem in Lean, how do you know that when you export it's really Fermat's last theorem it's not 2 plus 2 equals 4 I mean and people, some external kernels they write print printers.
20:55I mean, it will print the statements that has been proven, all the dependencies. You can have all these fancy tools to make sure you're not being misled. Lean, obviously, it's so powerful. And I see on social media all these amazing results from formal verification. I want to know what are the top ones that you think of or top examples more recently that have impressed you that Lean was able to accomplish? Well, there are so many, I mean, that I thought it was impossible. For example, getting a gold medal in the International Mathematical Olympiad. A few years ago, everybody thought it was impossible.
21:38Now everybody, they use it as a benchmark of an easy problem. They say, oh, this is like an IMO problem. I mean, this is easy. But it's not. I mean, these are really challenging problems. the others conjectures that people close using lean ai with lean also impressed me there's this unit distance conjecture for others first open ai proved using formal right was not formal and we have a system now in lean it's a website where we call lean eval where we collect challenges. The same Kim Morrison saw this proof of OpenAI and she puts on LeanVal as a challenge. Say, okay, I want to see someone formalizing.
22:31We knew it was huge to formalize. It's serious math. It depends on. And Boris Alexei from OpenAI, he did. He submits a one million line proof for whole proofing lean for this conjecture. We estimate, I mean, the ground math that is needed for the proof, we knew it would take months, I mean, for experts to do by hand. How long did it take in that case? Like the time from when the proof came out to when the challenge was solved on the lean? I think it was one month. yeah and after kim was a few i think less than two weeks after kim puts as a challenge on lean i took i think two weeks to get the or less i mean that's that's insane yes yeah we talked about verifying programs but also there's using it just directly for mathematics like in this case how popular is lean in terms of when you look at the users of lean what percent are using it for software engineering what percent are using it more for just direct math well historically lean got popular first with math right i mean no with the beginning of the lean mathematical library in 2017.
23:56We had like a big project called Liquid Stencil Experiments. It started beginning of 2020. It was a big deal because it was to verify a result from a field medalist. Peter shows it. It's a result he was unsure about. He has not published it. He felt like this was one of the most important results in his career. here, he wants to be sure it was correct. It was done manually, the verification. It was a big deal because the team that formalized it led by Johan Komelin, they not only formalized the results without fully understanding it, they do not fully understand the proof, but having this info view helped them, guide them step by step.
24:47they formalized and simplified the proof without fully understanding the proof. It's mind-boggling, right? I mean, how can you simplify a proof from one of the greatest living mathematicians without fully understanding it? I mean, but they managed to simplify. It's almost like when people do refactoring codes and you start changing the codes. It's faster now, but the programmer doesn't really know why. I mean, it felt like that. It's like you have a gut feeling, I mean, that you're going in the right direction. And this, for us at the time, lots of people got excited about the math community because of this project.
25:28It's like it's shown that's not about verifying, but enabling people to work together in large numbers. Because you can trust, you don't need to trust someone else's proof, right? They can fill holes for you. this was I mean what attracts a lot of attention from the math community then came Terence Tao he starts using after this project he has really cool projects with and without AI and he got addicted actually I think the first time he used it he said I don't think I'm going to do it again the formal proof one week later he had another project using Ling and he did a new result he had. When you say addicted, you mean because that game, that completion engine.
26:17Yeah, some people, we feel like when I talk to professors that use Lean for teaching, they tell me that the class is going to split. Some people love it. Some people don't like. But people that like problem solving, people that get medals in the IMO, they love lean because you get this excitement of solving is like solving millions of really hard sudoku problems right and you can keep solving one and it's easy to get i mean i'm a lean developer not a lean user but when you're developing lean i'm coding in lean and sometimes i have proved things it's really easy to get addicted and get lost proving things you get this bus every time you prove something.
27:07You mentioned the IOI gold medals. How is Lean used in that kind of I think maybe you're referring to Alpha Proof by DeepMind or maybe something else? Yes. DeepMind was, they got in 2024, was a big surprise in 2024, they got a silver medal. And now we have gold medals from startups like Harmonic. By Dance got a medal. I never I never imagined by dancing, they're behind TikTok, right? I didn't even know they care about formal math, but they have a formal math team. They got medals also. The approver is really good. So how's it work? Let's say, I mean, there's a series of math problems. Lean is just used for verification, right?
27:55So I imagine there's other components there. Yeah, there's the AI. You can view it like we have Go that was very popular with AI. The AI is playing the game. I told you that many people see Linhaza game. It's the same. I mean, the AI is viewing Linhaza game. They have the statements of what you want to prove. You have the buy keywords. Now you have a blank field. Make sure that you have no goals left, right? It keeps applying steps in this game. And seeing the state of the boards, right? That's the info view changing. and the AI, they use reinforcement learning for trying to get to no goals left.
28:40It's a single player game. Some people play together these days, but the AI is learning to play the game. So before we were talking about that game, it kind of starts with the specification. So in that case, then the problem is kind of the specification and then it hammers away. You have basically for each problem in the International Mathematical Olympiad, someone translates to Lean the statements. It's super important to have the mathematical library because you want to be able to talk about the problems, right? For example, support the problems uses the real numbers. You need a definition in Lean.
29:18And we have it inside of Mathlib, the Lean Mathematical Library. The first thing you have to be able to write the problems in Lean. and this now because of mathlib it's easy part and after that you have to provide the proofs sometimes some problems you have to come up with a definition to some objects you have to create that has some property but that's how it is I remember you said one of the first use cases of Lean was this fields medalist had this novel mathematics and then we use Lean to verify it. But can Lean be used with LMs to generate novel mathematics or just verify existing? It's a good question.
30:09I mean, we don't see lots of evidence. We see now evidence it can find novel proofs, right? But coming up with new mathematical concepts is still at the limits, right? I mean, right now, in this lean of all, we have challenges where the AI has to come up with the objects themselves, right? I mean, but these people will keep investing in this area. I would not bet against AI here. I mean, but right now we don't have evidence they can come up with new math. OpenAI, Anthropic, Cursor, and Vercel all use this product to make their lives better. And the problem it solves is when you're building SaaS or an AI product and you want to sell to other companies, there's all these requirements you need to meet.
31:02There's SSO, there's SCIM, there's RBAC, there's audit logs. These are all things that take time to integrate but aren't the main focus of your app. WorkOS is an API layer that lets you meet all of these requirements in just a few lines of code. So let's say you have a new SaaS product and you want to sell to other companies. WorkOS will solve all of these critical feature gaps for you. You can check them out at workos.com to learn more and get started. And I appreciate them for supporting my work and sponsoring this podcast. When I see on Twitter this major conjecture, they made headway on it.
31:38It's that they made headway on confirming something. Or just proving. They also have these one million lines. They've shown the conjecture was false. They have a proof showing that it's false. But it's a formal proof. They did not come up with a new theory or anything like that. They are coming up with a proof. At what points would you say someone should evaluate formalizing something in Lean? I think if it's safety critical or if you don't understand really well, I mean, this is important part. I don't really understand. Anybody that went through the process of formalizing something understands the subject way better after that.
32:30I almost feel like I remember when I was in college, people would say, well, after I implemented this algorithm, now I understand it's much better. the next level is that you implement the algorithm, you prove the properties you expect. Your level of understanding grows, right? I mean, another cool thing is that it enables you to be much more bold on your optimizations. Because sometimes, I've seen that all the time, people fear implementing optimization because they don't really understand why the piece of software works. They feel like if I do that, it still works and is faster, but they are not confident.
33:17With proofs, you eliminate discomfort. You can prove it again, or the AI can prove for you or find a counter example. They are good at both things. But if you were to speculate or draw into the future, maybe three to five years from now, if the cost of formalizing things goes down? How does that change software? How does that change, you know, handwritten math? Oh, I think it will change dramatically, right? We have to keep in mind the big labs, they only start training for formal verification very recently, right? Seriously. Before that was like, oh, it's in the data sets. I mean, you don't really have the reinforcement learning.
Read the full transcript
34:06pipelines to optimize. The behavior we see today that is already amazing will get way better in the future. The costs will reduce. Programming languages like Lean and Rock will become more mainstream because of that. Many people are not so... In the past, people would say, oh, functional programming, I don't like it. but if I'm not the one that's writing most of the codes anyway it doesn't really matter what matters are the specification level, right? It doesn't really matter how the code has been written. Yeah, I think it will change a lot because of that at least that's the direction we are pushing Lean to What about, let's say, 10 years from now Lean is everything's going really well with Lean.
35:00Is that the could that be the end of handwritten math or handwritten proofs i think there will be always aspects that is handwritten the some people like to make a proof look they want to use the proof as an artifact you communicate ideas to others i can't imagine there will always be people polishing making them super easy to understand for for another human to communicate ideas to other people there will always be people like that the same way today we have people that we have machines that build furniture but people they like to to create them by hands and polish them make them perfect this will always exist but it will be a mixture i will be surprised as if there is someone that's completely AI is not in their workflow somehow, right?
36:05I mean, you'll be hybrids, many hybrids. Some people don't like feel uncomfortable about this future, but for me, it's super exciting because I view developing software as a super painful process and with AI it's crazy how it brings you awareness of how many steps are just repetitive and there's no creativity or just patching things and AI automates removes lots of this pain I cannot go back to I'm looking forward to this future you describe yeah i guess the thing that gives people i mean i'm guessing the discomfort is the worry that if it kept going then you know then we need less mathematicians or less computer scientists or something like that people don't see that ai can bring more people uh there's also the specification i mean some i've seen people saying oh we are going to leave ai we'll come up with new math.
37:19But if there's no connection to our world, this is some alien thing that's going by itself. You need an interface. For example, we want to build programs because you want to accomplish something. This something, whatever it is, has a specification. There will be always humans in the loop saying, this is what we need, this is what we want. Writing this interface, It's interacting with the AI. The AI will have math libraries and everything to prove things about these programs we are writing, these artifacts, whatever we are trying to build. But we have to be able to interact with these libraries.
38:07We have to understand the abstractions that are there. I don't see humans being eliminated. We are always going to be there. We are in the interface. we are telling them what we want specifications will be there I can see people always writing codes even another thing a lot of people like to write they say I love coding my interpretation is they love to write prototypes this is fun, this is the fun part to try a new idea but to transform it into a product is never fun I can tell you, it's never fun. And I can't take over these parts. Nobody really likes doing it. Outside of Lean, I know you worked on the Z3 SMT solver.
38:59And that sounds like a really difficult thing to build. So first, what is that solver, in your words? And how does it differ from a SAT solver? Yeah, a SAT solver is really long. is going to be yes 20 years ago i started history i mean when i joined microsoft research yeah this is a smt solver is like a set solver but you have backgrounds theories like you have support for arithmetic for arrays these are not random choices right this is because we use for doing test case generation software for doing software verification Z3 is fully automated it's a push button although Lean Z3 are called term provers, they are completely different beasts, Z3 is fully automatic, Lean is interactive, it has automation but it's interactive Z3 is not a programming language, it's like you can do, it's more like a constraint solver, it turns out you can prove simple things about it not, you cannot do advanced math with abstract math.
40:12You can solve constraints with Z3. What's an example of the inputs to this SMT solver and what you get out from it? Oh, I can give you one. I mean, that's even in the Z3 manual. You can encode a Sudoku problem as a set of constraints, and you can ask Z3 to solve, and it will give you back the answer instantaneously. For real applications Z3 was used very successfully for finding bugs in software. People would convert, for example, suppose that you have a path in your code you know that has a security vulnerability, but you don't know which inputs to the program allow you to execute this path. You can convert that into a set of constraints that you send to Z3 and it will say unsatisfiable it means it's impossible to execute this path and you are happy or it gives you back an example saying look with these inputs you're going to be able to do it i mean and people use z3 for doing software verification uh but because the problem becomes undecidable uh at that level you have many universal quantifiers for stating properties about your program your pre and post conditions the server has heuristics and it's just all before ai the heuristics were hand coded they will always fail and for simple things people would be very happy with the push the fact that z3's push button but when the property is not trivial they would come back saying come on i know the proof i mean why z3 can't find it that's why lean started i started lean to make sure that we would have a system that's really good for software verification.
42:07Z3 was successful for finding bugs, but not so much for software, for proving the absence of bugs. It was never super successful there. But Linf was born to fill this gap. You said undecidable, but in practice, in the real world, if you run it, does it typically terminate? Yeah, great question. Z3 goes the whole complexity ladder. You have sets, you have NP complete, PSP complete, XP complete. You have the whole, two undecidable. Surprisingly, even for sets, You can write really tiny set problems that are really hard to solve. No set solver will solve them. But in practice, the problems we get from hardware verification, especially if you bound everything, say, oh, I'm trying to look for a bug in the first 10 steps.
43:13Everything's bounded. You're not trying to prove, but you're trying to capture a class, like a space of scenarios, right? They are very effective there. I mean, I think the lesson there is that programs and hardware, they're not correct by esoteric reasons, right? They are correct for very simple reasons. I mean, that's why these tools are super effective there. Yeah, but when you get too undecidable and you're trying to prove even if the property is not trivial there i mean it runs out of steam i mean and they time out frequently and sometimes there is a here a colleague of mine here at amazon in minator like chooses the name proof instability because sometimes if you change the problem you just flip.
44:15I mean, you have A and B, you write B and A, where B and A are complicated formulas. You may fail to prove. And when she was just trying to maintain things, proofs would break if using this kind of technology. But with Lean, she switches to Lean and it's super smooth, right? Because you're controlling the proof. In the Lean case, why is it so much more efficient? your proof is basically you can view is the sequence of steps for solving the problem in Z3 you can view that you have only one proof step solve you have options to solve flags but you have very you cannot influence what Z3 is going to do it's much harder to influence this kind of system In Lean, if you want to give a super detailed step-by-step proof, you can.
45:17You can use proof automation like it's available in Z3, but you can also break it down step by step. And the fact you can do that, humans can do it, but the happy surprise is that AI can do it. because now you can say step by step why something is true. The AI can convince Lean that it can provide a proof. When you were working on Z3 and Lean, what was the most technically challenging part that you had to build for either project? I underestimated how much harder Lean is in comparison to Z3. It's hours of magnitude harder. I talked to many colleagues about that. Why I felt like this language was so much harder.
46:12I think it's the surface. The interface with humans is way... Fuzzy Tree, you have a defined language. It's called SMT Lib. It's a very simple language. It's not meant for humans. It's meant for tools. I mean, Z3 is used as the back end of many different tools. Some program is generating input for Z3. And people expect a counter example or saying it's impossible, it's unsatisfiable to come up with a counter example. The interface is really, really simple, right? You can view Z3 as a command line tool that you pass this file on this very low level language that's super easy to parse. and you come back with yes or no.
47:02And Lean is a programming language, you have libraries, you have mechanisms, you have interactivity, you have user interface, you have LSP, you have build system, you have this, you have that. It's so vast. I mean, that's another challenging part for me. As I mentioned, Z3 was a backend. the Z3 users are very sophisticated software developers people that speak the same language I speak it's way easier to talk to people that speak the same language with Lean it's completely different right, the first users are all math people they have a completely different background, different expectations different everything and it's a different community.
47:55And then you have people that want to use Lean as a programming language. I'm not a programming language person. My background is automated reasoning. And yeah, it's different language, different expectations. Was there like a singular component that was just really technically challenging? I told you that Lean is implemented using Lean. Of course, it was not always like that, right? It had to be implemented in something else at the beginning. The switch from, originally it was C++. The switch from C++ to Lean was extremely painful. Really, really. I remember I literally want to cry when I managed to compile Lean with Lean.
48:48I was just, Sebastian Ulrich and I at the time, we were building Lean4 together. But this was before we had a nonprofit for Lean. I remember calling him and I said, wow, man, it's insane. I mean, I said, are you not excited? He said, yes, I am, I am. I mean, I'm super excited. What made that switch hard? The first thing is, imagine you're going to implement the language in itself. The first thing you want is to minimize the number of features as much as possible. You want to implement Lean using bare bones features, because you're going to be able to compile it with itself. Then, now you have like 100 ,000 lines, more or less.
49:43I don't know the exact number but it was between 100 around 100 ,000 lines and you start trying compile you fail the first you cannot even compile the first file in the pipeline that more than 1 ,000 the first one fails then you fix the bug you can compile the first one then you can compile the second and you keep moving and you are always finding discrepancies between the new and the old one I mean, and you're trying to reconcile, make things easier for the new one, I mean, because you want to replace the old one. And this process is... And Lean is a complicated language because of these dependent types and so on, the proofs.
50:30For example, when you're implementing Lean, you still need some proofs there. There are some basic proofs you need, but you have to construct these proofs without no interactivity, nothing, bare bones, you have to provide the proof. It's almost like programming in assembly the proof. This was also super painful. Oh, my God. Yeah. But it took, yeah, many people thought we were going to fail. Sebastian and I would not be able to do it. 100 ,000 lines is a lot. like all human written. Yes, all human written, yeah. We talked a lot about Lean, and I know there's competitors to Lean. What are the pros and cons of the different proof assistants?
51:18In what scenarios is one preferred over the others, for instance? The first disclaimer, I have a completely biased person here, right? But I can tell you what users tell me about. For example, one thing the users love is the fact that Lean is super extensible. Because Lean is implemented in Lean. You can add extensions to... Imagine you're doing your math proof. In the middle of this math proof, you say, oh, I want this fancy automation here. You can write in the same file. Or the AI can write for you the extension for automating our proof. And it will do it. I mean, even the AIs, they know about the fact Lean is extensible.
52:04if I ask the AI to isolate an issue in Lean, I give the AI a Lean file, it will start writing a Lean meta program, a program about Lean internals to validate the conjecture it has about why it doesn't work. It's crazy. The AI keeps writing Lean meta extension there. The fact that Lean is an extension is really popular with so many people. For example, there is Patrick Massot. He's a French mathematician. He wrote something called Lean Verbals. Lean Verbals, he uses for teaching. We have this language for writing the proofs, but he made the language look like English. And he has the info view. Now it's a point and click.
52:57You can click there. It gives you suggestions about the next move that's written in structured English like you find in a textbook. The student has a really good idea on how to write informal math proof. And he did that without asking me any questions. All this stuff, the point and click, the new language, the new interactivity, he did it all by himself. He's not a computer scientist. He has a math degree. and he did all this stuff. And it's for English and French. I mean, you can choose. You can write the proofs in French. It looks textbook proof. I mean, there are people that write visualizations, right?
53:46You want to visualize, you're trying to prove something about a math object. You can write an extension that visualize these objects in your info view, right? that people that write new domain-specific languages embedded in LIM for different purposes. For example, for protocol verification, there is a language called Vail. It's a LIM file. You open Vail. You feel like it's a different system for protocol verification, but it's just a LIM file with these extensions for protocol verification. The language for writing protocols in a very convenient way. these folks wrote the whole thing without ever talking to us they only talked to us after they had done it they said look I want this path of link to be faster that was the only interaction we had interactivity is a big deal another big deal now is the mathematical library it's vast I mean for stating problems, open conjectures, you need a library with the concept, to even state the problem, right?
54:56So Lean has a massive library and a massive community. The community also plays a big role. People, before AI, I think now most people ask questions about Lean to AI, but in the past, people would go to the Lean Zulip channel, ask a question about Lean, they would get an answer in five minutes. I mean, people would say human-based AI. I mean, people would be writing answers instantaneously to your problems. The community played a big role. Another one was we listen to our users. I mean, the math, I mean, if you talk, for example, Jeremy Avicad was the first user. I mean, he has math backgrounds.
55:47he he you ask him look he said look i could ask anything any new feature i would get back the same day i mean this the fix the new feature same day and this attracts people right i mean because you're making improvements making sure the system does what they want uh they come back for more i I mean, this also has a huge impact in growing the community. When I was doing some research, there was this idea, I think you mentioned this conversation too, there's this dependent type proof assistance, and then there's higher order logic. What is that difference there? At the beginning, when I started Lean, I won't choose higher order logic because it's much easier to implement.
56:37I mean, dependent types is way harder. this but the math community I mean Jeremy is the one that convinced me that I would never be able to attract serious mathematicians like Fields Medal level math people with higher other logic right his point is like higher other logic is good for concrete math but if you want to talk about abstract objects dependent type theory is way more powerful and it's beautiful It's easy to explain why it's called dependence. For example, you can have a structure in Lean when you have several fields like X and Y are natural numbers or integers. Let's say they're integers.
57:22You can have another field. The type of the field is a proof that X greater than Y. The type of these fields is X, let's call greater. Colon, you say X greater than Y. The type depends on the value of the previous fields. That's why it's called dependence type theory. You can have types that depend on the values of other parameters, other fields, and so on. But the beautiful thing about that, you have this very small language that is so expressive. For example, this field now that's a proof, you have to provide the proof. You can view it as invariants. I can only build elements of this type if I give the X and Y, like in other programming languages, but I have to give a proof that the X is greater than Y.
58:19It's impossible to construct elements without providing this evidence, right? You can view this invariants. You don't have to invent invariants, right? It's just the fact you have these dependencies you can express. In the functions, you can have a function, for example, that says, takes a X, a Y, and a proof that Y is different from zero. Right? It's impossible to call the function if you do not provide evidence that Y is different from zero. This was always cool. But in the past, people would say, wow, providing these proofs is really annoying. But with AI now, the AI can't synthesize the proofs for you.
59:04and it's really cool. In higher order logic though, could you express the same? No, no. You lose the dependencies. For example, one thing that you cannot do in higher order logic in Lean in serious math people you have a bunch of structures they manipulate you have like something a field, a ring a group you can write a functioning lean that takes a group and returns a new group a new structure you're not money you don't really care about the elements of the structure you are viewing the structure as a first-class citizen that's something that the penitentiary can do easily and in higher logic is you have to play encoding tricks it is a mess i mean some people say oh it works for math none of the mathematicians agree with this statement none i mean you talk to to terence tall to alex konturvish jam heavy gods kevin buzzard patrick masso they would say no no you have to do depends type theory i mean that's another example for me that's listening to your users is important if you want to appeal to this community.
1:00:27It's totally okay to say, I don't care about this community. But if you care, listening to what they really want is important. So when we think about the future of Lean, I'm curious to hear your thoughts on where you think Lean is going, things you're excited about in the future. What might it look like in a few years? Yeah, I think we have these nonprofits behind Lean since 2023. I mean, Lean's 13 years old. The first 10 years was a research project, right? I mean, only when we got the non-profits behind Lean that it became, you can view as a product. You have a team of engineers. And we managed to do it because the impact on math, right?
1:01:21But Sebastian Wurik and I, I mean, we co-founded these non-profits. What we are really excited about is Lean as a programming language, a programming language where you can prove things about your programs, right? That's a direction we are pushing really hard, right, Lean too. We are super grateful for AWS, Amazon. They are making the largest donation so far to this nonprofit where the goal is to accelerate this path. I mean, Lean is doing super well in the math path, but let's make Lean as a programming language. Lean is a system for software verification, hardware verification. Let's push to the extreme.
1:02:04Let's give some love to these people, to this path that's right now, we do not really have funding to push seriously this path. That's the non-profit, right? For me, to be in a world where you can reason about your codes, is part of my life. I'm not writing unit tests anymore. I'm writing properties and proving them. The AI is proving most of them for me. This is a direction we are pushing hard. And one thing that people don't realize is that when you have proofs, it enables optimizations for free. You can ask the, for example, if you ask the AI to optimize, you have to inspect the code to make sure no bugs were introduced in the process but if the AI is telling you look I optimize it it still computes the same thing here's the proof this is a game changer in my point of view yeah I've heard multiple people say this decade will be the decade of formal verification of software and yeah maybe lean will be a huge part of that yeah we for sure we're super excited to make it happen and we're scalability is super important right because there's a big difference between math and software verification.
1:03:40In math, the statements are usually really tiny or small. I mean, Fermat's last term is an example. I mean, super small, but the proof is insanely cheap. For software verification, it's the opposite, right? The statements are big, but the proofs are shallow. The reason why this is true is shallow, But you have to manipulate these big objects, right? So for someone who wants to learn more about formal verification or learn more about Lean, do you have a top technical book recommendation? In the Lean website, I mean, we have several books there that introduce Lean, Functional Programming Lean, Term Proving Lean, Mathematics in Lean.
1:04:32The Mechanics of Proof is great for educational purposes. We have a collection of books. If people go to lean-lang.org, you'll find all these books there. But one thing I tell people these days is that learning lean using AI is super efficient. I mean, you keep talking to AI in natural language, asking what you want, asking it to write examples. Many people split the screen in three now, right? We have the link codes, the info view, and on the bottom now, many people now use an AI agent there that's writing the codes and explaining in natural language what's going on there. It's a super effective way.
1:05:24I mean, Terrence Stahl, he told me when he learned Lean, he uses an old version of it. It was before agents. He would have the chat to pitch on one window and the Visual Studio code in the other window and he would copy and paste between them. And that's how he learned. But now it's even more effective with the AI agents. It's easy to pick up. I mean, just talk to the agent. Sometimes people say, how do I start? Start talking to the agent. He will help you. He will customize. You can explain what you know already. What's your background? For example, if you tell, oh, I know Haskell. It's so much easier.
1:06:11You can customize the process. And then last question for you is, if you could go back to the beginning of building C3, building lean and give yourself some advice knowing what you know now what would you say you know i'll keep it a secret i mean i think ignorance is a bliss i mean you don't know how hard things are and when you start the adventure maybe i'll keep secrets what i would tell i think one thing especially before starting lean i'm super introverted and i would tell look you should work on your people's skills because it helps a lot when you have to interact with a community with people for me it was hard to learn that and I would tell myself it's really important to have people's skills too well thank you for your time today thank you thank you
1:07:20bring on please drop a comment guests like barbara liskov mike stonebreaker mark brooker these were all people that i brought on because someone left a comment on another note aside from the podcast i'm working on building the ergonomic keyboard that i wish existed here's a glance at the prototype it's a split keyboard so there's two sides this is in the case but yeah we launched on kickstarter and we hit our goal within eight hours of launching i really appreciate it if you were one of the people who grabbed one of the early units. We're now working on the long journey of building the tooling now.
1:07:54And so if you still want to pick one up, I've left the late pledges open on Kickstarter. So you can grab one there. I'll put a link in the description. Thank you again for watching the podcast and I'll see you in the next episode.
From the publisher
Leonardo de Moura is the creator of Lean and the Z3 theorem prover. I talked with him about how Lean works and why LLMs plus Lean will fundamentally change how we write software and do math.
• My ergonomic keyboard project I mentioned, you can follow along here: https://read.compose.llc/
• The Kickstarter page for it: https://www.kickstarter.com/projects/ryanlpeterman/compose-simple-ergonomics-beautifully-done
Podcast links:
• YouTube: https://youtu.be/KzdYKeAqWhY
• Apple: https://podcasts.apple.com/us/podcast/the-peterman-pod/id1777363835
• Transcript: https://www.developing.dev/p/creator-of-lean-the-end-of-handwritten
Thank you to this episode's sponsor for supporting my work:
• WorkOS: makes your app Enterprise Ready with easy to use APIs to add SSO, SCIM, RBAC, and more in just a few lines of code, check them out at https://workos.com/
Timestamps:
(00:00) Intro
(00:28) How formal verification works
(05:21) A new way of writing software
(13:15) Proof assistants vs programming languages
(21:06) How Lean has assisted in mathematical breakthroughs
(32:03) When is it worth formalizing software
(33:29) How Lean will impact handwritten math
(38:55) The Z3 theorem prover project he started
(45:44) The most technically challenging work of his career
(51:10) Lean vs its competitors
(01:00:37) The future of Lean
(01:04:10) Technical book recommendations
(01:06:15) Advice for his younger self
(01:07:10) Outro
Where to find Leonardo:
• Wikipedia: https://en.wikipedia.org/wiki/Leonardo_de_Moura
• Website: https://leodemoura.github.io/
• GitHub: https://github.com/leodemoura
• LinkedIn: https://www.linkedin.com/in/leonardo-de-moura-26a27b5/
• X/Twitter: https://x.com/Leonard41111588
Where to find Ryan:
• Newsletter: https://www.developing.dev/
• X/Twitter: https://x.com/ryanlpeterman
• LinkedIn: https://www.linkedin.com/in/ryanlpeterman/
• Threads: https://www.threads.com/@ryanlpeterman
• Instagram: https://www.instagram.com/ryanlpeterman
• TikTok: https://www.tiktok.com/@ryanlpeterman
Referenced in this episode:
• Lean 4: https://github.com/leanprover/lean4
• Mathlib: Lean Mathematical Library: https://github.com/leanprover-community/mathlib4
• Lean4Lean: https://github.com/digama0/lean4lean
• Liquid Tensor Experiment: https://xenaproject.wordpress.com/2020/12/05/liquid-tensor-experiment/
• Veil protocol verification language: https://veil.dev/
• Z3 theorem prover: https://github.com/Z3Prover/z3
• seL4 formally verified microkernel: https://github.com/seL4/seL4




