An unofficial, read-only Hacker News reader.

Much shorter version of GRH Lean verification from Anthropic (opens external site)

569 points by nb-t 3 days ago | github.com | 371 comments on HN

View full thread · View on Hacker News

Comment thread (20)

  1. I don't know Lean..

    But looking at the code, I can't help but wonder:

    Who on Earth can understand that ?

    Random example: https://github.com/lsernau/grh-lean/blob/main/grh-compact/sr...

    Genuine question for people who know Lean: How realistic is it for a human to read this code, 'grok' it and verify that it is correct ?

    Replies (13)
    1. The grh-compact version is not very readable (it is deliberately minimized), I'd read the 300kloc version in the grh folder instead, which looks fairly clean to me.
    2. Lean syntax is alright. You can get used to it. The hardcore part is the jargon.

      > Scaled Hecke operators repair divisibility at inert primes pairing tops

      Literally every word here has a precise definition. Probability takes forever to get an intuition for all of that. But that's always the problem with math.

      Replies (2)
      1. I'd say the hardcore part is the complex concepts that are compactly described with the jargon.
        Replies (2)
        1. For me, the hardcore parts are the impenetrable `simp`s and `grind`s. Of course, source code is not the best way to view lean proofs.
        2. applies to any topic of any field, but yes
      2. Claude's writing style still comes through. In a nine word sentence where most of it is technical terms. I don't even know how to rewrite it but I can still notice it's the same ultra-condensed writing as all the docs on vibe coded GTA 6 projects.
    3. I don't understand the math or logic here, but the syntax is not half bad.
    4. Code in the sciences often looks like that. You have to have domain-specific knowledge to read it and there's no escaping that.

      >How realistic is it for a human to read this code, 'grok' it and verify that it is correct ?

      Data presented this way isn't simply read and understood, it often has to be studied.

    5. For me, this is more readable than many "human-language" paper proofs.
    6. Besides this being the compact version, a decent chunk of it (typically everything after the first `by` in each declaration) is proof tactics, which are not really needed to verify that it's correct because they're mechanically checked by the compiler.
    7. Most of the hard-to-grok code there is proof bodies rather than theorem statements. Assuming you can parse the statements, you can follow the proof pretty loosely and reconstruct it yourself. Such is the tradition in math generally

      Plus, these proofs are actually quite tame compared to human-written Lean proofs.

      > How realistic is it for a human to read this code, 'grok' it and verify that it is correct ?

      You don't need to verify any of this, but for the final theorem statements. That's the point of formal methods.

    8. This is nearly as ugly as ABAP, only misses the comments in German

      Something that I wonder where is the "eureka" part of this proof, or perhaps the top 10 "eureka" moments.

    9. Just for your reference. you linked to the compact version

      https://github.com/lsernau/grh-lean/blob/main/grh/src/New/Up...

      This is the non-compact 'Human Readable' version. Still pretty intense!

    10. This is just programming

      To properly understand a proof you need to run it interactively (or at least I do), which is kind of running in a debugger

      I mean the here's the gist of what takes to understand a proof

      To prove a theorem in Lean (or similar theorem provers; I'm actually more familiar with Rocq) you have goals, which are the things that are left to prove. The "main goal" is what you want to prove right now, and the other goals are other things you also need to prove

      When the list of goals becomes empty, you have proved the theorem. You start with a single goal: the theorem itself

      It proceeds like a game. Depending on what the main goal looks like, you can eliminate it calling some piece of code (there's more to it but let's say it's a tactic). But more often than not, eliminating a complex goal just pushes more, hopefully simpler goals into the goal list. So you need to be, well, strategic in what tactics you employ - you need to go into the direction of making things easier to prove, not harder

      So what looks like to run a proof interactively? You can go through the proof step by step, all the while you observe how the goal list changes. That's analogous to run a C program in a debugger, watching the local variables of each stack frame

      Ok so that's how you (or at least I would) understand a proof - run it interactively, which is like watching a professor write down each step of the proof in a white board, all the while she carefully keeps track of what's left to prove

      But anyway. The innovative thing about theorem provers in general is that to verify a proof you run a program (a kernel) which is just a trusted type checker. Unfortunately the official kernel is written in C++ and agents found bugs before (that made the kernel accept theorems that were false). However, there's multiple kernels, so if all of them type checks the proof (and the proof doesn't contain stuff like "sorry", which means it's not proved at all), there's a high confidence in the result

      Replies (2)
      1. Thanks, useful explanation!
      2. In the before times you could have made a big fuss if you made a tool to convert js to typescript in this way.

        Alas we’re about to stop caring about programming languages at all.

    11. > verify that it is correct

      To be clear, it is not a human who verifies it's correct.

      Lean does that.

      Humans just have to verify that the statement of the theorem is accurate, and that it is rooted in mathlib.

    12. I'm not a mathematician so I don't understand half of it, but it seems pretty close to "real" math. And the fact it compiles makes it at least self consistent, I remember having a hard time with math because many of my teachers weren't that rigorous with notation because they could "read" the flow of a proof like you and I can read a sentence with typos. Like I distinctly remember spending hours trying to understand a proof, until the teacher ended up like "oh btw I made a mistake did you find it?". No I didn't because I'm trying to learn.

      Sorry for ranting, point is, looks fine to me, and it probably reads easily for someone well versed in math, granted they take the time to learn Lean

    13. Eh i've seen Rust code that is as ugly as this, when dealing with multiple lifetime.