A tale of four theorem provers, or: A (reasonably) opinionated comparison of Isabelle/HOL, Lean, HOL4, and Agda
57 points by blueberrywren
57 points by blueberrywren
I've only ever learnt Agda, and I feel like I should learn another popular proof assistant, but I can never understand the proofs that are made in other proof assistants. I suppose the point is not to understand but to trust that the compiler has checked it? The fact that Agda has barely any tactics means that at the end of the proof, you're left with a very readable program.
For example, the proof that 2 is prime from the post:
theorem prime_two : prime 2 := by
simp
intros k x
simp [divides] at x
have ⟨q,hq⟩ := x
(cases q <;> cases k <;> grind)
versus
two-prime : Prime 2
two-prime .gt1 = s≤s (s≤s z≤n)
two-prime .div zero (divides (suc q) eq) rewrite *-comm q 0 = ⊥-elim (1+n≢0 eq)
two-prime .div (suc zero) (divides (suc q) eq) = inj₁ refl
two-prime .div (2+ zero) (divides (suc q) eq) = inj₂ refl
I can understand the Agda proof by looking up what the requirements of the field gt1 and div are, then I can understand what the available arguments represent and what we're supposed to return as the return value of the function. But in the Lean proof, I have no clue what it's doing; what's the first simp for, what's grind actually doing? I can't translate the proof into mathematical terms, which I personally find annoying.
Yet another manifestation that the optimal shape to write the code, to read it, and to modify it are three different shapes.
When one is writing the proof, there is a side display with a list of goals, so one can see what simp actually did. The written list of just the tactics to apply does not have this affordance. Ideally, some kind of exporting the goal lists after each step would get to be the norm… but obviously we are not there.
Yeah, this is an example of what you might call “proof language paradigms” which I am sure has been written about somewhere although I don’t know of it. But basically with the proof languages we’ve developed so far there’s a tradeoff between how easy a proof is to write and how easy a proof is to read. The more declarative your proof is the more it looks like a real informal proof that you can read & follow, but also it seems much more difficult to understand why the prover is getting stuck while you are writing the proof.
TLA+ has a proof sub-language that is the most extreme example of declarative proofs I am aware of; you don’t get very much help when figuring out why discharging an obligation failed. However, the proofs are quite readable (as long as you collapse some of the longer nested child proofs). The TLA+ proof language has no support for tactics whatsoever.
Contrast this with Lean where proofs comprise a series of operations that directly manipulate the current assumption & goal states, often in an automated way using tactics. It is very easy to see why a proof obligation cannot be discharged while writing it, but it is impossible to read the proof without stepping through it in a Lean development environment.
I think at least part of the power of using tactics is being able to inspect proof state at any given point. Various tools even make this possible for HTML-rendered versions of these proofs (they names elude me, but I'm sure they're not hard to find). So maybe you don't REALLY need to be able to evaluate proof steps in your head; you need more so to follow the general shape of the proof. Which, I think the lean version shows pretty well.
I went to a talk by Kevin Hartnett, who had been interviewing mathematical Lean users for a book, and he had an intriguing set of anecdotes about that. Not sure whether these anecdotes made it into the book (I am only partly through it), but one of the recurring things he noticed mathematicians saying about Lean is that the tactics/proof-state combo turned theorem proving into a game, and a vaguely addictive one. You make a "move", and Lean keeps track of what the resulting effect is on the "board", listing the current state/score off to the side. Sometimes your proof obligations blow up and you realize you "lost" and have to restore from save point a few steps back. Other times it seems tantalizingly like you're almost there, enough to stay up another hour or two into the night to beat the level.
That's definitely how it was for me. When I first got started with Coq (now Rocq) in undergrad, I was hooked. I worked on software foundations proofs in class, I stayed up late to finish them. It was very much like a game, and the dopamine hits from Qed going through were powerful!
That said, I kind of feel that way about Agda proofs typechecking as well.
The undergrad course I did with coq was probably my favourite of my entire degree. I haven't touched it much since then though, this thread is inspiring me to go see what's changed in the intervening years!
Note that tactics don't immediately imply inspectiable-afterwards proofs; HOL4 is an exception here. You write with tactics, but piece together afterwards into one "block". Most of the time that's true though, and I agree with your later point completely.
Honestly in this day and age, proofs are written and read almost exclusively by llms for any kind of industrial usage. It's been a while since I spent any time stepping through a lean proof for any reason except fun or personal satisfaction. When I'm really trying to get shit done I just hand off to the agent and go make a coffee.
How unjoyful :(
Yeah idk I have mixed feelings. I definitely did enjoy the puzzle of it all, and I do miss the satisfaction of finally connecting all the dots and seeing the proof go through.
Equally it's hard for me not to feel at least a little joyful when the robot cranks through a mountain of tedious proof repair for me after I make some minor tweak to my definitions, and the feeling of suddenly having so much raw power at my fingertips is also quite intoxicating.
Glad you liked the article!
This is one of the chief advantages of Agda, yeah. I didn't explain this great (I'll probably go back and expand on it), but adding @[simp] to the definition of prime means that simp can unfold that definition itself. Stepping through the proof may be a bit enlightening, because this is the experience you'd get while writing:
The proof state before that simp is prime 2, and after is
⊢ ∀ (k : Nat), divides k 2 → k = 1 ∨ k = 2
(we can see it's taken out 1 < 2 automatically)
From there, the intros k x introduces k and x : divides k 2; simp [divides] at x unfolds divides (as we didn't tag it with @[simp], giving:
k : Nat
x : ∃ q, 2 = k * q
⊢ k = 1 ∨ k = 2
We break down that exists into the value itself and the property (q and hq), and then doing some case analysis gets us there.
Under the hood, all these tactics are doing is generating a proof term like the one we see in Agda; (simp and grind make it much more complex, but it's still just a term).
When the proof is complete it's less obvious what's going on without a good mental model of what's happening where, but it can be made nicer.
I do find myself wondering where Rocq (being also fairly constructive and automatable) sits here, though I presume it’d rank similarly to Lean based on my vague failed attempts to learn Lean from a Rocq user perspective over the years.
I’ve never quite got a good handle on what Lean does better than Rocq, and any cases of the opposite.
I think 99% of people that learn theorem provers learn to use perhaps one new one per decade, so comparisons are hard to come by. It’s a big investment!
I'm glad you enjoyed!
I did consider adding Rocq as well; unfortunately, the post was already getting unwieldly and I do have a life beyond writing blog posts 😅. I would guess the proof would look closer to Lean's, but a bit more verbose, as Rocq doesn't have automated tooling quite as good as grind.
I don't understand why Lean is so popular all of the sudden. Isabelle feels much more capable to me:
I guess all of those things don't matter if you never intend to actually write your own proofs, or even read them, and just let an LLM shit them out? That is at least the only context I see Lean mentioned in these days.
Regarding the specific points you bring up:
grind +premises you'd get a similar (although not as well calibrated) experience as sledgehammer with respect to automated lemma finding without you tagging them ahead of time. There is also proof automation that simply has no equivalent in Isabelle like e.g. bv_decide which currently sits ahead of both Z3 and cvc5 in competitions for the logic it targets.I'm glad you enjoyed!
I don't really have anything to add to your first point. My experience was that grind was finicky, but it's by no means a toy and is quite nice.
As for your second, the main thing I couldn't figure out how to do with loogle was context-sensitive searching. Perhaps I was just using it very wrong, but find_theorems also offers subcommands like intro (finds theorems that are directly applicable), elim, dest and solves, which are quite handy. I also found the syntax a bit confusing, and there's no good guide for it (e.g. chaining with , isn't actually explained anywhere I could find?). This is perhaps a bit of a skill issue, but I just didn't find it as nice an experience.
I concur with the CS point. There's no equivalent of projects like CakeML or seL4 in Lean, nor do I think any will pop up soon (organically, at least...), partially because the proofs involved are much less "single goaled", if that makes sense? An """advantage""" of formalizing math in Lean with LLMs is you can sort of just point it at one theorem and let it work, not caring what it does in the middle.
Personally I think verifying outside code is a better strategy than trying to make your proof language do two things at once. Whether that's the best approach, I can't say ¯_(ツ)_/¯
At the end of the day everything is just a tool, and I think we should be formalizing everything in HOL-light for maximum assuredness ;)
I don't think the answer is primarily LLM-related, because the adoption of Lean by prominent mathematicians dates to slightly earlier, 2017-2022 timeframe. So by the time LLMs came around it was already the default choice of theorem prover in the mathematics community.
I'm not an expert in the history, but am going through a recent book on it. In this book's telling, the two big inflection points were: 1) Kevin Buzzard became a big proponent around 2017, driving development of mathlib and pulling in a community around it, and then 2) the Liquid Tensor Experiment (2020-2022) convinced people it was usable for high-level research mathematics, not just for formalizing textbook results.
Now what the book doesn't answer is: why did all this happen in Lean and not another interactive theorem prover? How much does it have to do with technical features vs sociological?
Given it had to overtake Coq (now-Rocq), I would bet on some distinguishing features being relevant at least to the early adopters. If it is non-constructive by default, and uses a set theory closer to ZFC (which is what published math implicitly uses by default) that what other provers use, it might be enough of a closer-translation to help gain momentum.