An unofficial, read-only Hacker News reader.

The need for a formally verifiable mainstream programming language (opens external site)

343 points by todsacerdoti 3 days ago | blainehansen.me | 321 comments on HN

View full thread · View on Hacker News

Comment thread (19)

  1. This is exactly what I do in $dayjob. I call it Property Driven Development.

    I start with prose requirements, then use Elenxis (https://github.com/kbr-/elenxis) to translate into formal Lean model.

    Then I state signatures and conjectures that the spec must have. Properties that the future implementation must hold. No implementation yet.

    Only once all conjectures are there, we are ready to roll.

    If I write in Lean, I can now fill in the signatures' implementations. Then prove theorems. Proof doesn't go through => bug. Fix, retry, repeat.

    If I write in an inferior language, there is extra Intermediate step: translating the conjectures into property test in the language. Only once these are ready, I can write implementation.

    You must not write implementation before having all conjectures stated -- otherwise the implementation will bias your thinking, and you will try to prove properties of your implementation instead of what you needed.

    All of the above applies equally to AI agents.

    Replies (4)
    1. Thank you for an interesting comment! Do you have any recommendations on web articles or other examples similar to what you do?
    2. Interesting. I work in bog standard LOB SaaS type businesses my whole career, so zero practical experience with formal methods, but a growing interest in them due to how I see the industry trending towards them. Can I ask... in your case, what is $dayjob related to that you find yourself operating this way already? Finance? Aerospace? Just curious...

      > You must not write implementation before having all conjectures stated -- otherwise the implementation will bias your thinking, and you will try to prove properties of your implementation instead of what you needed.

      Most software engineers don't really have a background in it, and tbh I kinda don't know where to start, and have heard that right now if you're already experienced with formal methods then you can get great results out of approaches like this with LLMs, but if you just vibecode up the Lean or TLA+ etc then you're not going to get out of it what you were expecting. I suspect your statement here is exactly the kind of thing that makes all the difference, but I don't know how to know what the other things that make the difference are. Any other pointers?

      Replies (3)
      1. You might find some of my previous comments useful.

        On Formal Methods Thinking/Levels and (In)Formal Methods - https://news.ycombinator.com/item?id=50478624

        On Design By Contract (DbC) - https://news.ycombinator.com/item?id=50108540

        On Combining Tests and Proofs with Contracts - https://news.ycombinator.com/item?id=50108206

        On Correctness-by-Construction - https://news.ycombinator.com/item?id=49613696

        Note that the above is based on using classical logic predicates to "steer" the program through its "state space". This is the more fundamental and "simpler" approach since it uses only First-Order Logic.

        Another way is to use the Type System (constructive logic, dependent types in Lean4 etc.) to embed the above directly into the program types. This is harder since you need Typed Lambda Calculus, Higher-Order Logic and need to think quite differently. For this you can read Types and Programming Languages by Benjamin Pierce and/or any number of lambda calculus books. The Curry-Howard Correspondence helps you understand this if you have some idea of the above state space approach.

        Finally, if you want to know/study the whole of above you need to read Understanding Formal Methods by Jean-Francois Monin - https://news.ycombinator.com/item?id=50506655

        It is all overwhelming at first if you are completely new to it so use it as a roadmap. Survey all of the above to get a grip on the jargon, notation and application and then choose your approach/logic/tool based on your interests/needs.

        Replies (2)
        1. Thanks, appreciate this!
        2. I studied from this during my University days: https://www.cs.cmu.edu/~rwh/courses/clogic/www/handouts/curr...
          Replies (1)
          1. Nice. I have heard of this though i have not yet read it.

            My current favourite are Helmut Brandl's writings - https://hbr.github.io/Lambda-Calculus/index.html particularly his 100-page Typed Lambda Calculus/Calculus of Constructions.

      2. You can use 'lightweight' formal methods too like Alloy or Forge https://forge-fm.github.io/book/2026/index.html
      3. > Can I ask... in your case, what is $dayjob related to that you find yourself operating this way already? Finance? Aerospace? Just curious...

        Nothing so critical.

        My first serious full-time job was at ScyllaDB, where I worked on distributed database system core. My main area of interest (carried over from University) were distributed algorithms. There, formal methods are basically necessary; if you design a distributed algorithm and don't use formal methods, you *will* fuck up. In ScyllaDB I used TLA+.

        Today I have a different job but my passion for formal methods didn't go away.

        I updated my HN profile with link to my website, you can look me up.

        Replies (1)
        1. Oooh that makes sense. Databases are one area I have definitely heard such methods being used. I remember seeing a talk on TLA+ by the CosmosDB people and thinking it was really cool.
          Replies (1)
          1. Yes. But formal methods, especially right now with agentic AI, are, I believe, a fucking superpower, no matter what you're doing. Even if I wrote a simple CRUD web app, I would start with a formal Lean contract. (And producing such a contract with my Elenxis tool + frontier model is trivial.)

            Imagine all software you build is bug-free from the start. No technical debt, ever.

            Replies (2)
            1. I even made https://github.com/kbr-/kotlean so I could make Android apps in Lean.

              Continue this thread (1 replies) →

            2. I'm onboard with this vision, and fully in agreement.
    3. Can you not do this with normal tests?
      Replies (1)
      1. Define "normal test".

        Property test can state general properties about the signature being tested. E.g. let's say you're proving correctness of addition in an abelian group. You can state Associativity, Commutativity, Identity Element (0), Additive Inverse, Closure, Cancellation Property, as properties of the signature, in the Property Testing framework you're using (Haskell: QuickCheck, Python: Hypothesis, and so on). The framework will generate test cases using a specially-crafted random distribution (one crafted to maximize the chance of catching a bug), then if it finds a failing case, it will shrink it, so your counterexample is minimal.

        It is a "normal test" except that you use a powerful framework to give you these mechanisms.

        It still depends on randomness, so it's still inferior to a theorem, which gives you 100% correctness.

    4. But then, is the application itself written in Lean?

      One could maybe combine this with Rust code verified by Aenas (which runs Lean proofs)