Unofficial Hacker News companion — get notified on comment replies, and more.

So you want to build a mainstream formally verifiable language (opens external site)

122 points by mpweiher 4 days ago | danilafe.com | 82 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (14)

  1. I think there's a pretty big conceptual difference between programming and math, which is that in programming we think about building up something over time by applying successive steps. In math though we have to think about the whole thing simultaneously, forwards and backwards. So when we prove a program, we're actually proving it forwards and backwards, with all possible inputs and outputs, at the same time. And either it's all true, or it blows up in your face.

    Another difficulty is with programming, we succeed by making abstractions that don't leak, where with math we're constantly opening up mathematical objects and messing around with their internals, chaining together the internals with theorems to get to our desired outcome.

    Since we so often need access to the guts of the objects we're working with to prove facts, it makes it really hard to interoperate with other systems, because either we have to make assumptions about those systems which can compromise correctness or we have to be able to plug in all the way.

    Signed, an undergrad in math with decent coding experience.

    Replies (7)
    1. As a computer scientist with 20 years experience in software and last 3 shifting on math, I think I agree with how you describe the approach in SWE. I collected a ton of notes on the same process myself.

      I'd sum it up as starting to code before/without trying to get a proper* understanding of the end-to-end problem, and then incrementally adjusting along the way. This often solves a chicken and egg problem, of not being able to advance understanding before building. The problem is not rewriting or fully refactoring the code once your understanding persist. Often this is too late (aka "shipping the prototype"). Then everything expands into more complexity over more or less** time.

      I think this whole process can actually be described formally. I'm not sure how much it matters anymore, but I suspect agent generated code suffers from the same issue, just with different measures due to speed/memory advantages agents have.

      ----

      * I say "proper" assuming "full" is likely unachievable in most settings

      ** the difference between many software projects can be reduced to how fast they become dead ends based on how fast complexity explodes.

      Replies (1)
      1. > As a computer scientist with 20 years experience in software and last 3 shifting on math,

        That's good but it doesn't prove your point, or any point for that matter.

        > I'd sum it up as starting to code before/without trying to get a proper* understanding... [chicken, egg, omelet] ... > I think this whole process can actually be described formally.

        I'm not sure why anyone in his right mind would want to describe formally this entire process. Formal verification proves the correctness of the code produced by this process, not the process itself - and correctness is always provable, if in fact the code is correct.

    2. > Another difficulty is with programming, we succeed by making abstractions that don't leak

      So, we basically fail then.

    3. While I like your dichotomy, I find more similarity between maths and programming.

      you usually define the internals of your mathematical object based on the requirements of the 'rest of the system' and then you study the objects a lot to see it they even make sense or collapse.

      As soon as you have an object that does not collapse, you know you can use it.

      Take for example measure theory, you start with the basics axioms that are there to make the measure useful to others, then, based on the axioms you derive everything that you need to ensure that it's well defined, and then some more theorems that are like glue code to be able to use that measure for particular cases.

      In this view, the axioms are your basic API, and the 'glue' theorems for an application are your frameworks.

      Now a big difference between maths and programming is that maths is way bigger and more complex though

    4. I think you're not wrong about the situation today, but that doesn't mean we cannot change things. Verifiability is an exciting possibility that may be enabled by LLMs.

      I also somewhat disagree with you about abstraction. In programming as well we move "up and down the ladder of abstraction", which means opening up objects and revisiting how we've built their abstractions. If you're doing performance work or debugging, while you don't exactly IGNORE abstractions, you're definitely opening them up.

      Signed, professional software engineer with math degrees. :)

      Replies (1)
      1. I guess my point wasn't that it's not possible to formally verify programs as much as it exercises a different part of your brain. Doing math feels different for me, because I'm constructing the whole thing in its entirety in my mind at once, and I can poke at it and follow strands in a different way.

        Of course, when I have a good design for a program I also have a mental map of how it all connects, but the methods I use to morph a problem in programming is sequential and directed in a way, where proof by contradiction or contrapositive feels very different.

    5. I disagree. In writing a proof in math you also apply successive steps. This is clear in a proof written in English, and even clearer in a Lean proof where you literally list the steps (tactics) in order. The forward and backward thing you are talking about is probably about proving A if and only if B; that’s a small category of proofs. A small category of programming tasks (like parsing and pretty printing) also need the programmer to think forwards and backwards.

      The idea of making abstractions comes from mathematics. The entire field of algebra is just abstractions. Algebraists think about the group, the ring, the field rather than the underlying objects. These abstractions absolutely don’t leak. These are some of the most elegant abstractions available, and this style of abstractions is known as type classes (in Haskell) or traits (in Rust), and is far superior to programmer-derived object-oriented abstractions. Why do most programmers create abstractions that leak? Because they are only taught object-oriented programming and yet without even learning about the Liskov substitution principle.

      Replies (1)
      1. > The forward and backward thing you are talking about is probably about proving A if and only if B

        I'm aware about bidirectional implication, but that's not quite what I'm getting at. With programming I think in terms of starting with some input data, successively applying calculations, and then ending with a result. There's a step-by-stepness to it. With math I have to think of it existing in all ways, simultaneously. Equality works both directions, but variable assignment doesn't. Math functions go both ways (at least when they're bijective), but programming functions only go one way. Maybe I haven't done enough math yet, but it hurts my brain in ways that programming never has. I don't usually program contrapositively or by contradiction.

        And it's true that math arguments are presented linearly, but that's because there's not really another way. I have to reconstruct the mathematical framework from the linear presentation, but it hardly feels linear once it's all brought together in my head.

        > The entire field of algebra is just abstractions.

        I'm afraid I haven't taken abstract algebra yet, that'll be next semester! But I hadn't considered about how algebra works with objects that satisfy certain properties, so I'm glad you've brought that up. Thus far I've mainly been done proofs in linear algebra and my intro to proofs class, so that certainly colors my understanding.

        Replies (2)
        1. I still don’t get you. There’s definitely a step-by-stepness in math. Nobody can hope to put a complex proof like FLT in their head all at once.

          Equality works both directions in math just as it does in programming (the == operator in popular languages). Variable assignments don’t because they model definitions. The only difference is referential transparency, which is not required in most programming languages but a good thing to have (say in Haskell).

          I do use contrapositivity occasionally when programming, but I don’t use proof by contradiction. This is actually interesting because proof by contradiction is inherently non-constructive: it can be used to prove the existence of things without a way to compute them. I do think restricting math to what’s computable makes things much easier and makes students’ brain hurt less, but it is also a lot less interesting.

          Good luck!

        2. The key to connecting Mathematics to Programming is to study Set Theory/Predicate Calculus and think of your program statement as a "Predicate Transformer" (https://en.wikipedia.org/wiki/Predicate_transformer_semantic...).

          The state space of a program is given by the cartesian product of all the types (i.e. sets) of its variables (global+those in current frame/scope). If you know your Relational Algebra (from RDBMS theory) you can see that this program state space is a relational table of n-ary tuples. You then write out predicates (i.e. precondition) which select a subset of the above tuples based on relationships between the variables. Your program statement acts on this subset to produce another subset of tuples which is asserted by another predicate (i.e. postcondition). Your program statement between the pre and post simply maps between the two subsets (either pre to post or post to pre). So mathematically your program is just a sequence of predicates (pre and post) asserting subsets from the global state space which is progressively transformed to give you your final result.

          To understand how logical deduction is used to verify programs in a "correct-by-construction" approach (the above state space predicate transformer), see the seminal papers; Assigning Meanings to Programs by Floyd, An Axiomatic Basis for Computer Programming by Hoare and Guarded commands, Nondeterminacy and Formal derivation of Programs by Dijkstra.

          For understanding how abstract algebra maps to programming see From Mathematics to Generic Programming by Stepanov and Rose. Basically your program implements a "Model" of an algebraic "Theory" - https://www.fm2gp.com/

    6. Have you programmed in haskell? Because I disagree in general, and haskell takes it furthur: you program declaratively
      Replies (1)
      1. I haven't programmed much in Haskell, but I have played around with Elixir and Clojure before, so I have a rough sense of programming declaratively (I'm not terribly familiar with Haskell's type system outside of my exposure to traits in Rust, but I don't think that was the feature you were focusing on). Programming declaratively from what I've done is still thinking downwards, in that you map this, you filter this, etc, but it's a directed graph. With math you have equality/equivalence, which works both ways. If a + b = c + d, then c + d = a + b, so now you can go backwards. In my experience it feels completely different, because the way you solve problems takes advantage of things like this all the time.
    7. Interestingly, for the kinds of proofs on programs I'm familiar with (as someone who works in the separation logic world), the notion of proving a program backwards and forwards are two different things; we generally use a forward proof (hoare logic / separation logic) for correctness (this program doesn't deviate from the spec / has no bugs) and a backward proof (incorrectness logic) for incorrectness (this program can exhibit a certain bug)