r/3Blue1Brown • u/DifficultAvocado6185 • 7d ago
What does a compiled Lean proof actually certify?
What do you think about that?
63
Upvotes
r/3Blue1Brown • u/DifficultAvocado6185 • 7d ago
What do you think about that?
38
u/SufficientGreek 7d ago
This is a good article about the topic: https://xenaproject.wordpress.com/2026/11/12/and-the-proof-is-checked-in-lean/
24
u/zolk333 7d ago
I'll try not to muddy the waters too much, but a compiled lean proof doesn't really certify anything. The fact that it compiled (rather, type-checked) is the certificate.
For example: let's say you want to prove that there are infinitely many prime numbers, i.e. that for any natural number there is a prime number that's larger than it. This statement can be translated into a Lean type. Your proof then would be a program that can take in any number, and return a prime that's larger. Lean checks that the program actually satisfies the type: it really can work for any input number, the result really is larger than the input, it really is a prime, etc. If the checks fail, the program doesn't compile.
So in the end, your problem statement is turned into a type, your proof into a program, the compiler makes sure the program satisfies the type, and returns a compiled program. But this compiled program, by itself, is nothing more than a box that takes in a number and returns another one. The compilation process is what made sure the compiled program is correct.
(Actually, many proving techniques don't really compile into anything tangible, but that's another rabbit hole)
7
u/Tejasisamazing 5d ago edited 5d ago
If you are wondering why or how type checking to validate proofs actually works, here is a nice way to look at it
In other programming languages, like java, if you have a function which is supposed to return something of type int, then the program would not even compile if you tried to return some object of type bool, or string, or tried to return nothing. Before even running the program, the type checker can check if you are outputting a correct object of the type int or not.
Now, suppose we are able to create a situation, where the types themselves (like int, bool) represents statements like 2+2=4, and objects of that type are proofs of that statement, then
if you have a function of type (2+2=4), your program wouldn't be able to compile until you can return an object of the type 2+2=4, ie, a proof of 2+2=4. Which means you'll have to make the proof object somehow, ie prove the statement.
So you can atleast see that if we are able to create such a situation, then the type checker can actually validate your proof. If you have written an incorrect proof, then it wouldn't match the type, and fail at type checking.
Lets see more concretely how this works We start with certain axioms, ie statement which we say are true without proof. What this corresponds to in lean, is the axiom keyword, where you specify a type (like the statement 2+1=3), and it automatically gives you an object/proof of that type, without having to prove it. Thats what we mean by axioms.
Then, using these proven statements, we can then prove other statements, ie, give object of type of other statements, which can then further be used to give objects of other types, and so on
Here is an example suppose we start with axioms: 2=1+1, 3=2+1, 4=3+1 this means, we now have objects of each of these types. Ill label them st1, st2, st3 (standing for statement 1, 2 and 3). Assume that the = and + symbols have been defined seperately.
And I wish to prove 2+2=4, so my type is (2+2=4), and i wish to produce an object of this type
I denote it like theorem twoplustwoeq4: (2+2=4) := .....
the (2+2=4) denotes the type, and in the ....., ill write a proof/create an object of type 2+2=4, and return it.
You can think of theorem as a function, which takes in nothing, and returns that object of type 2+2=4.
so i start with the object of 4=3+1, and i apply st2 to simplify it, and i get an object of type 4=2+1+1. Then I notice the 1+1, and i tell lean to apply st1 on the section (1+1), and i get an object of type 4=2+2. (These assumed associativity, so the definition of + itself must have a theorem that associativity works)
almost proven, but the object of 4=2+2 is not object of 2+2=4, they are different things!
Luckily, the way = is defined is that it is a symmetric relation, ie, the type = gives us a function Sym, which, given a object of type a=b, returns an object of type b=a. (so notation: theorem Sym (h:a=b) : (b=a) := .....
the (h:a=b) indicates taking in input an object of type a=b, and storing it in the variable h to be used in the proof)
So we apply Sym on object of 4=2+2, and get an object of 2+2=4, and we can return it! This program will pass type checking, and hence its a valid proof.
Notice how at any point of time, you didn't have any other way of returning an object of type 2+2=4, aside from actually constructing it, or defining it as an axiom
Thats how lean can actually truly verify proofs.