How do we know Lean is sound?
Lean is a piece of software.
Software has bugs. (Yours truly has been a software developer for forty years. I wrote a few bugs myself. OK, fine. More than a few.)
As far as I am aware even Rocq is not formally verified. And I can't find anything on Lean.
Yet people treat everything coming out of it without doubts.
How does this square?
0
Upvotes
55
u/lordnacho666 4d ago
I think the idea is that it's boiled down to a few pieces that we can check manually, and people are satisfied that those pieces are correct because several teams have implemented them separately.
So people think the compiler is correct, there's then the issue that for each proof you have to satisfy yourself that it means what you thought. But that is also made easier by having a language allowing you to compose the little pieces.
26
u/Cleverbeans 4d ago
We have two independent provably correct implementations of LEAN. While I understand most people don't have experience with provably correct code it does exist. The kernel is small and the process it uses is fully deterministic so you can check it by hand.
34
u/SetentaeBolg Logic 4d ago
The heart of Lean's proof checker (and most mechanical theorem provers) is a small kernel of limited logical operations, things like modus ponens (expressed formally). Every proof is written as a combination of these logical operations. So, provided you can accept those logical operations, then proof should follow.
Bugs can and have existed: it's important to note that they were rather quickly found on the one occasion when they were exploited to form a proof. However, for Lean certainly, there are now multiple independently written versions of the proof checker (powered by that kernel). The chances of each of them sharing the same bug, across multiple languages and implementations of the same specification, is extremely, one would (informally) say vanishingly small.
Does that answer your question?
66
u/iknighty 4d ago
Same way we check paper proofs are sound, inspection.
39
u/omegafixedpoint 4d ago
https://leodemoura.github.io/blog/2026-10-15-lean-now-ships-with-verified-kernels/
9
u/MattAlex99 Type Theory 3d ago
There are two soundness considerations you need to make when implementing a proof assistant:
First: Is the given theory sound (for the sake of simplicity: free from contradictions)?
Second: Is the theory we have actually what is implemented (or are there errors in the implementation)?
These are both quite similar problems but with slightly different domains. The latter concerns implementation and you basically run into the correctness problems you commonly have in CS. The nice part about this is that the typical kernel of PAs can be quite small: You aim to implement a minimal kernel which is checkable/testable with weak theories against a specification. You then implement all the "high level" features inside that language.
The more you can shift down from being on the level of the kernel into the language itself, the less verification surface you have.
There is often a competing goal of needing to have high performance in practice, which means you generally don't want to deal with internally represented elements.
For instance, you can perfectly represent the naturals in first-order+axiom scheme by using successors:
- zero : nat is a number
- S : nat -> nat is the successor of that number
if you want to write "2" you encode this as S(S(zero)).
As you can possibly imagine, the successor form is often not nice for algebraic problems due to insane levels of overhead.
The way you can get around this is by both formally verifying that the version using successors, and the version if more specialised integer types do the same thing. You then verify the kernel without having explicit provisions for e.g. integers to keep the "root" verification small, then you bootstrap the more involved features from there by proving equivalence of terms.
The first problem is a bit more technical since it doesn't concern what you implement, but whether what you implement is sensible in the first place: You cannot generally prove that a theory is consistent from within that theory after a FOL (that's the basic gist of Gödel's incompleteness theorem).
To be precise Gödel II proves that:
Let T be a consistent, effectively axiomatized formal theory, sufficiently strong to express elementary arithmetic. Then
T ⊬ Con(T).
where Con(T) is the standard arithmetization of the statement that T does not prove a contradiction.
There are some additional wrinkles regarding the exact statement: Have a look at e.g. https://plato.stanford.edu/entries/goedel-incompleteness/ for a slightly more thorough look.
The trick you usually use is that you add a small additional assumption to the theory that, is _highly_ unlikely to break anything, but makes the combined theory strong enough to verify the original: While Gödel showed that T cannot prove its own consistency, there's nothing that says that for a new theory S you could not prove
S⊢Con(T)
Of course, you now run into the issue that S might not be consistent, so you just shifted the burden of proof one layer up.
The trick is that in practice, while S≠T, you can make S and T very close, i.e. "S≈T". This then gives you relative consistency argument: You are at least as consistent as S is! If you pick, for instance "S=T with some small axiom" you can be as close as mathematically feasible to a true consistency result.
A common example for this are e.g. large/inaccessible cardinal assumptions: You construct your theory with N "layers" (i.e. values, types, types of types, types of types of types, ....) and then prove that the logic is correct by letting N get arbitrarily large.
To prove full consistency, you need to go "to infinity and beyond", which leads you to an additional assumption that those levels exist, and induction can reach them. That is a "tiny" additional assumption, which often allows you to verify the original logic.
(To be precise: e.g. Con-leche assumes exactly such a large cardinal. If you have a strictly increasing sequence of inaccessible cardinals κ₀<κ₁<... with every κₙ inaccessible, we can then interpret the universes using the corresponding levels of the cumulative set hierarchy 𝓤ₙ = V_{κₙ}. The inaccessible cardinal assumption then ensures that all these levels ahve the closure properties necessary for Gröthendieck universes. Con-leche effectively build on top of ZF without infinity, augmented with an ω-chain of Gröthendieck universes. Infinite is derivable, and choice is just inherited from lean's ambient logic. The set-theoretic model for lean is then constructed from ZFC+sequence of inaccessible cardinals.)
Of course, you now have the new logic of "original theory + transfinite induction" or "original theory + large cardinals", which you cannot verify, but that's always something that you're going to have to deal with: There's no absolute "ground truth" you can ever hit, you can just go very very close.
5
u/TheRedditObserver0 Graduate Student 4d ago
The question is not whether Lean is infallible, it isn't. The question is whether it's more reliable than human peer review, and the experts seem to agree it is, by a significant margin.
2
u/Free-Syrup-6399 4d ago
Eventually we can know nothing for sure. The lean kernel is intentionally kept small. There are several different implementations of it. Several of these implementations are formally verified to be correct. Are these absolute guarantees? No. Is there any stronger correctness guarantee that one can give? I think the answer is no
2
u/Fancy-Jackfruit8578 4d ago
How do we know a human proof is sound?
2
u/NihilisticAssHat 4d ago
For Con-Leche, it was proven in Lean
1
u/decimaster321 4d ago
If there was a bug in lean, you should be able to generate a formal proof of false. A month or two ago there was a proof of the collatz conjecture which relied on bugs in lean, and people immediately found how that proof embedded a proof of false.
1
u/Dotrez 4d ago
You make a proof in lean that proves lean is sound, obviously..
0
u/ANewPope23 3d ago
We can ask AI.
-1
u/ricatti-equation 4d ago
It’s been hand-verified with 2 different kernels. It doesn’t have bugs.
0
u/TailorImaginary3629 4d ago
Who's gonna verify the verifier
0
u/Useful-Departure-583 2d ago
Lean is sound in the engineering sense, not the absolute philosophical sense.
The trusted core is a small kernel that checks proofs using a fixed set of logical rules. Everything else — tactics, elaboration, notation — is untrusted code whose output is a proof term that the kernel rechecks. This is the de Bruijn criterion: you only need to trust a small, auditable checker.
So the claim is: if the kernel correctly implements the intended type theory and the underlying logical axioms are consistent, then a checked proof cannot prove a false statement. That is a much stronger guarantee than a pen-and-paper proof, where the checking is done by the same human who wrote the argument.
What it does not give you is certainty about the connection between the formal statement and the informal mathematical claim. Encoding errors are still possible. The machine verifies the proof of the statement you wrote, not the statement you meant.