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 (26)

  1. Quite ironically I see formal methods being extremely key to your central argument. That is, the design should be started by modelling with some formal language that then gets expanded into an implementation. I fully agree about massively restricting the possibility space of code as being why they work. I've found that to basically be the only thing that produces consistently good results in the face of all the non-determinism. The entire codebase doesn't fit into the context window though, but formal models of it can act as some form of lossy compression that helps it fit into the context window better. I think formal methods definitely have a role to play, as to do anything that restricts what the valid moves are like frameworks and fitness functions etc.
    Replies (2)
    1. > Quite ironically I see formal methods being extremely key to your central argument.

      Formal verification is a useful tool, but I don't think it meaningfully combats "slop," which I argue is primarily disorganised, voluminous, and lacking in aesthetics.

      > That is, the design should be started by modelling with some formal language

      I would make sure what I am developing demonstrably works before formally verifying the characteristics of the system.

      Replies (1)
      1. The question is, why do we care about slop in the first place? If we ignore the ideological and emotional reasons, I think it boils down to three things:

        1. The slop is incorrect

        2. The slop is bloated

        3. The slop is not human readable

        Formal verification together with human validation is the answer to point 1. The second point needs additional measures to keep the artificial author in check which is in my experience quite easy to accomplish.

        If these two are in place I found that human readability falls out mostly for free.

        So, to summarize, in my opinion formal verification together with measures to keep the code minimal and concise is our best way to tackle slop.

        Replies (2)
        1. Personally, I think the slop is very dangerous to a codebase both when humans produce (and they do!!!) and when AI produces it because the uncontrolled growth of entropy in a codebase has this funny way of just completely trashing your ability to get anything done in it. Like, now there's two ways to do the same thing, so.. which one do you pick? Pick at random, now there's 30% this way and 70% that way, so probably the 70% one will get picked, but there's this non-zero chance that now a third way is invented! When you think about next-token prediction, it's so heavily conditioned on the context, that crappy context equals crappy results, and uncontrolled growth of entropy results in crappy context.

          TL;DR it impacts the trajectory of the LLM negatively in a massive way IMHO.

        2. Assuming a narrow definition of "incorrect", I would add:

          4a. The slop has been generated with rules and processes, ones that needed actual decisions and approval which never happened.

          4b. Nobody reading the slop can distinguish between deliberate things that were chosen and approved, versus accidental things which were blindly generated and kept.

          Replies (2)
          1. 4b is a real bitch even on very short timescales, let along medium and long ones. It compounds so fast.
          2. This is all covered by 2. If you keep your source minimal you have no problem. Doing it is not trivial, but it is doable.
    2. 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.

              Continue this thread (2 replies) →

      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)