Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> To use formal verification you need to have formal requirements of the behavior of your software.

Not true!

Well, it is true of TLA+, but that is why TLA+ is not the future. The future is dependent types.

It is true we'll always be programming and specifying as we go to some extent. That's why formal methods have to be part of the software itself, not some extra burden off to the side.

Dependent types is basically unique in doing that. You can right some code, then reason about that code. Or you can write a program where the propositions/proofs and executable program proper are so intertwined the separation stops making sense in theory too.

This, and this alone, supports the dialectic of "doing" and "planning" that is hardly unique to software development, but rather is emblematic of most sufficiently complex human activities.

----

A really nice example to make this concrete is Lean's standard libraries's `SatisfyingM` and `MonadSatisfying`

(See https://leanprover-community.github.io/mathlib4_docs/Batteri...)

`SatisfiesM` is an attempt to support "external" reasoning: one already wrote a non-trivial monadic action, and now one wants to do Hoare-like reasoning about preconditions, posts conditions, the returned value, etc.

But a different monadic action that uses the first one might need to then internalize this reasoning. For example, it need to turn a pair of (program, proof about program's return value) into a new program that returns the thing and the proof.

This is `MonadSatisfying` is for. It is a constraint on the monad saying we now how to internalize such a proof.

The "external" proofs are the only ones TLA+ and similar tools support, and the honest truth is that you might want to make them, you might be forced for compliance/legal/insurance reasons to make them, but you are never intrinsically forced by the software itself to make them.

The "internal proofs", in contrast, are so required. The represent different abstractions which state their interface such that it is impossible to use them incorrectly --- providing a proof is a non-negotiable obligation on user of the abstraction just as providing a "regular" argument is a non-negotiable obligation to making a regular function call.

In addition to supporting to modular reasoning --- write a very fancy thing and then make sure your coworkers don't use it incorrectly --- this fixes the economic problem --- gotta do the proofs or the code won't compile!

----

If you have no idea how to start programming more formally, here are some ways to start:

external proofs:

you probably have tests. Think, how did you know those test cases are correct? Can you rewrite individual unit tests as property tests, to "formalize" that reasoning (yes, it is still formal, even though property testing is old and simple. "formal" means "explicit" not "fancy"!). If you can write a property test to by checked by probabilistic methods, then you implicitly have a property you could proove instead. Problem solved!

internal proofs:

Does you program have any `panic("this should never happen")` or similar? Well, why shouldn't it? Types, even non-dependent ones, allow for https://en.wikipedia.org/wiki/Principle_of_explosion, which is nothing more than showing some case-alternative has been given an impossible value, and so must be dead code. Every bit of code you think is unreachable, and your intuition is not correct, has a proof saying it is in fact so, and that proof is needed internally do "discharge" the branch.

Every assert? remember "assert c = branch c -> ok; not c -> panic("this should never happen")" so all your assertions are not things you might prove!

Even people that never have written down specs in their life probably have some assertions or panics lying about. So they too have something to formalize.



This sounds fabulous on paper. Are there any examples of moving unit tests to property tests? Are there examples for proving unreachability? Has anybody successfully managed to explain how this is applicable if you don't have a deep background in formal methods?

If we can't provide a pathway from where we are to a more formal world that is understandable to garden variety developers, it will remain an ivory tower occupation.

(And, in fact, things will get worse. Because in a world of LLM churnage, provable correctness becomes even more important)


> Are there any examples of moving unit tests to property tests?

A quick google didn't turn anything up, but gosh there must be. Property tests have been around for ages.

> Are there examples for proving unreachability?

Yeah I do this all the time even in Haskell with just GADTs. You can do it in Rust with ! Too.

> Has anybody successfully managed to explain how this is applicable if you don't have a deep background in formal methods?

Amateurs played around with Haskell and now Lean all the time. But I guess that is a "certain type of person". We'll see how this stuff goes mainstream over time. E.g. maybe someday Rust will get dependent types.

> If we can't provide a pathway from where we are to a more formal world that is understandable to garden variety developers, it will remain an ivory tower occupation. > > (And, in fact, things will get worse. Because in a world of LLM churnage, provable correctness becomes even more important)

Part B helps with A a lot. If people writing fancier types are better able to leverage LLMs, and get more productivity boost accordingly, the basic economics will push it mainstream.

After all, there's more demand for "equally bad software quicker", than "better software at the same speed". :)


I fear that the economics as they are will settle for "worse software, significantly quicker". Not sure formal methods will save us either way.

But making it more accessible might just trigger enough people's "I don't want to push out absolute garbage if I can avoid it" buttons.

That's why I was wondering if there are already mainstream-accessible examples/explanations. It seems your search yielded the same results mine did :)


Eh, I think it is hard to get around the need for maintaining software, no matter how "worse is better" you are.

> But making it more accessible might just trigger enough people's "I don't want to push out absolute garbage if I can avoid it" buttons.

Yes, there is that too. Simple love of the craft.

> That's why I was wondering if there are already mainstream-accessible examples/explanations. It seems your search yielded the same results mine did :)

Just keep watching Lean. Now it is dominated by pure math, but people will be writing more programs over time also.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: