The need for a formally verifiable mainstream programming language (opens external site)
View full thread · View on Hacker News
To get push notifications on iPhone or iPad, add Hack and Chat to your Home Screen: tap Share → Add to Home Screen, then open the installed app and enable push in Settings.
View full thread · View on Hacker News
Replies (10)
Replies (1)
I think today it's actually more possible than ever. Writing programs in this way is hard and tedious but LLM can excel at that. I also think that a hybrid of Z3+LLM is orders of magnitude stronger than pure Z3. LLMs generated a formal proof of GRH, surely than can prove banking app correct.
The most vulnerable part that will remain will be the formalization of requirements. That's impossible to solve fully because you never know what the human had in mind exactly when he ordered the program to be written.
Replies (2)
Replies (3)
I don't think it necessarily needs to be solved. You can combine formal verification with tests! Use tests to show that the program occasionally does what you want. Use verification to show that the program never does what you don't want (e.g. crash). The formal requirements can be quite weak this way, yet you still get a high level of assurance overall.
And you'll be surprised how many invariants you'll actually need for the simple "don't crash" requirement -- to prove anything at all in a complex program, underlying components need to be correct, or it becomes hard/impossible to prove anything at all about the code using those components.
So (admittedly without any personal experience other than studying this area an university more than decade ago) I expect even a simple "don't crash" requirement gets you the majority of the formal verification benefits. (as long as you have some tests to ensure the implementation isn't just returning a constant)
Replies (2)
If you want actual guarantees that e.g. money won't disappear from your account some day or your messages won't be read by a third-party, then formal verification alone doesn't grant that.
Consider that Wifi WPA2 encryption was formally verified and yet broken. In simple terms the bug was in the protocol specification [1]. The "code is the law" crypto folks have even more fun stories to share.
[1] https://www.galois.com/articles/formal-methods-krack-vulnera...
Formal verification of full behavior is impossible. But formal verification of important properties is within the reach of AI.
Replies (1)
Replies (1)
See https://www.anthropic.com/research/formal-verification for more.
Replies (5)
Haskell has interesting uses in industry, but in general in the last decade or so the functional paradigm has become retrofitted to basically each mainstream language. Like java's streams/lambdas, algebraic data types in basically every modern language (rust), immutable by default, etc.
Replies (2)
Replies (4)
Replies (3)
If the majority say "you don't need a degree" then you don't need a degree.
If the majority believes in "move fast and break things" then things stay broken.
JS devs are doing monadic development (async is just that), and plenty of lambda passings, with the predominant frontend framework model being one where the view is a pure function of state, driven by reactive changes of the state.
Functional won vast areas in mainstream programming. What you are saying may have been true 15 years ago, but not anymore.
Replies (1)
I think software development and the tools underlying it could be wildly more powerful and exploit the underlying computer algebra more directly if dev tools didn't have to cater to the lowest common denominator imperative language dev
LLMs are valuable to me not because they can replace the types of coding these devs do, but because they have a far more deeper 'understanding' of the foundational math and algebra than could ever be expected of the average dev
There's ways software engineering could engage much more directly with these concepts to produce more sound and expressive results if the "user" could be safely assumed to be an IMO level mathematician like a sufficiently powerful LLM is
Replies (1)
This is the correct way to look at using LLMs for coding using their "jagged intelligence". The key here is that the developer has to know enough of the formal methods mathematics to guide the LLM within proper guardrails such that it cuts down on the non-determinism. You don't have to be a master mathematician who knows every single detail but just have enough conceptual understanding of the domain that you can create modular components and link them together using pre/post/invariants/assertions and type-driven design. You keep overall control while leaving the drudgery to the LLM.
Here is one process methodology that i wrote up - https://news.ycombinator.com/item?id=50319347
Continue this thread (1 replies) →
Java was the laggard there, and yeah I hated Java for years. Python and JS supported functional programming from early on, yet nobody went all the way with it. Python is the leader for toy problems like coding interviews and pseudocode that should be totally doable with pure functions, but nobody does that.
Replies (1)
Or like, make any web backend.
Do you really think all the math proofs being done with Lean could work at all if it was imperative as opposed to a purely functional, dependentally typed language
Replies (1)
Replies (1)
Formal verification a la cocq/Agda/lean works by constructive logic. (Disregard the middle paragraphs, I'm sure I'm not telling you anything new)
The type system is strong enough to encode various statements, even about variables (dependent type system, this is a valid type: a + b == b + a)
The only way to create an instance for this type is by proving the statement. The == type can only be created by trivially equal expressions, so it will accept a == a. So in the definition of the above you will go step by step, each step itself being accepted by the compiler, and at the end you get a proof and a compiling program, a bit similarly to how you would do it on paper.
So I guess it boils down to. Could a mathematician figure out some elegant proof for the system that somehow makes "checking each state" reduced to an easier statement? If yes, then formal verification can also do so. If no, then LLMs may be able to scale up what is feasibly provable, but there is no real alternative. Real world testing is just scratching the surface of the state space.
All in all, that's why it's paramount that systems are designed with complexity in mind. We can compose simple function into a simple function and have it explode in complexity, but it's also possible to choose good primitives that are easy to "mock out" (often both in practice and theory) and not significantly increase the whole system's complexity.
There is a "Correctness-by-Construction" approach to programming which allows one to severely restrict the state space of a program from the beginning such that every statement/block/function only operates on a much smaller "valid" set of program sub-states. This is using classical logic via predicates as explained by Hoare Triples, Dijkstra's wp-calculus, Morgan's refinement calculus and later Meyer's Design-by-Contract.
To do deductive verification statically, the basic idea is to group all computation paths (i.e. sequence of state transitions) over the entire program state space into a much smaller set of logical constraints (aka verification conditions) which is then handed off to a SAT/SMT solver to be proved/disproved.
An alternative is constructive logic using types and lambda calculus as pointed out by a sibling commentator.
There have been lots of systems which have been formally proved/verified to various extents/levels as can be seen in Industrial-Strength Formal Methods in Practice by Hinchey/Bowen and many other similar books.
Replies (2)
Replies (3)
The original comment was about industrial automation and in that environment a lot of those issues are not that relevant. Unless we're talking really big systems, a lot of it is very well specified controllers which run without shell/VM/container/runtime. They just talk to some fancy general GUI on a different chip/board to load the data/config. But the state space of a lot of actual practical hardware doing the work is not that complex. Bare metal, careful io timing, state transitions and some control loops gets you very very far.
To be clear, there are bigger, complicated systems, but simpler devices with a clock, PID loop and I2C outnumber them by likely a few orders of magnitude - we can start there.
Replies (1)
Verification is not about "happy path logic" but all computation paths (happy, error, cross-layer etc.) over the entire state space of a "system".
The system can include everything from hardware circuits all the way to distributed applications if needed. Across layers/components it works by composition of contracts where a higher-layer guarantees based on its lower layer's contract guarantees. The book i listed gives examples.
See also my comment here - https://news.ycombinator.com/item?id=50664740
Replies (1)
Replies (1)
Basically, you have to keep your module internals "pure", distinguish between domain exceptions (i.e. checked) vs. environmental runtime exceptions (i.e. unchecked) and push all "impure" operations to the boundary of the module.
Also see the following paper which shows how to formally model hardware faults;
Faulty Logic: Reasoning about Fault Tolerant Programs - http://www.cs.princeton.edu/~dpw/papers/faultylogic_esop2010...
WTH is "happy path logic"? Formal verification's main feature and selling point is the guarantied safety of absolutely all paths, the happy path stuff is what testing does, you're confusing these quite hard.
> Programming is layers of abstraction on top several more - unless all of them are formally verified - program can be never be truly verified.
Yes, all of them are formally verified, the bots doing the verification get neither bored nor tired.
> Think of different hardware, software, time, timezone, os/drivers/shell/vm/container/language runtime versions etc.
I don't have to think about these, the bots handle them one by one, mainly by porting re-wrting in a manner that allows formal verification. There is a formally verified OS - even verified by hand long time ago - nowadays it's a lot easier.
- ignoring how programs are written, they are usually compiled and linked, which introduces states unknown to the original programmer,
- ignoring how they are compiled, they are executed in environments with variability, including temporal; I remember tracing a problem related to a longer trace on one of the paths of the PCB, and materially different outcomes depending on which trace the signal happen to travel on (it was a high-frequency P-I-D controller, but for whatever reason the microcontroller could transmit the same signal on one or the other path). The particular bug was traced with a oscilloscope, by a graybeard, not algebra.
The way I see it, in order to get verifiability to actual programs, one would need to cover the state space of the entire system - algo, compiled binaries, operating system, hardware, and the weather on the other side of the planet for a good measure.
I am not an expert in the area, in any way - just a regular software dude. Appreciate all the responses in this thread!
Replies (2)
It depends upon what all parts of a "system" you want to encompass under "formal verification". There is nothing preventing you from verifying everything from hardware all the way to user-facing software or only certain layers in the chain.
As an analogy, the FIPS/Common Criteria security standards have multiple levels of certification going from simple signed binary blob to a complete hardware and software lockdown system.
You can do the exact same thing with formal verification of your system if needed. LLMs have made this possible if driven properly.
Replies (1)
He meant wrong, nowadays you just ask an LLM to re-write with proofs and redeploy.
> I remember tracing a problem related to a longer trace on one of the paths of the PCB... but for whatever reason the microcontroller could transmit the same signal on one or the other path
It's not clear what the issue was there but there are two possibilities (1) a software bug - only the pin connected to the short path should've been used by the program - easily caught by formal verification. (2) Analog/board design problem - these are resolved by proper safety margins and their state space is quite small - AI can redo the hardware with proper guarantees too.
> The way I see it, in order to get verifiability to actual programs, one would need to cover the state space of the entire system - algo, compiled binaries, operating system, hardware
No need to be scared, all of these are easily handled separately.
> and the weather on the other side of the planet for a good measure.
Formal verification provides proofs for any weather, on any side of any planet in the galaxy. It can even design systems that are solar-weather and star-weather proofed... if you can afford to actually implement them. Let me stop here, I don't want to scare you even more with stories about what some stars, even distant ones, can do to our planet. Yeah, life's tough.
Replies (1)
I feel we're searching for an ordering of the universe that bumps up against thermodynamic limits as we know them, something like Shannon's Entropy, and there is no silver bullet, only choices of where to select the complexity landscape and take our stand.
Replies (1)
But to a large extent that's a "so what?" if you plan for it.
If each layer adds 30% overhead and you have 8 layers, that's a 6x slowdown compared to a beautiful/horrible knot of code. 6x slowdown is really bad for a company, but the vast majority of your program is using negligible resources and 6x is still too small to worry about. The important part is designing around the part that needs to be fast.
And this was 25 years ago! We now have advanced formal techniques for inductive reasoning like IC3 that run on top of SMT solvers, enabling verification of (some) bona-fide infinite state systems. Of course the problem itself is undecidable in the general case, but in practice these tools do get the job done. We have formally verified OS kernels, Lean kernels, SAT solvers out there :)