by Mikhail_Edoshin · 2w ago · 0 comments
Written code should by itself look like a logical reasoning sufficient for humans to verify the steps.
Once you have proven an implementation matches the specification, you could have that implementation become the spec, potentially tossing the spec you started with.
That's not unlike binary translation: say you have program A that is proven to produce correct output for all possible inputs, and you convert/translate/port it to a program B which produces exact same output for all possible inputs, then you could say that program B is proven to work correctly.
The proof for B then consists of [A proven to behave correct] paired with [comparing output of B with output of A for all possible inputs].
Note this does NOT require the converter/translator/ porting process to be proven correct.
Generally the spec you started with is a more convenient format. Or conveys intent in a more concise way. But perhaps, sometimes, a known-good binary might serve as a more practical 'specification'.
Of course as the article notes: it's important to understand underlying assumptions, declare those explicitly, and have that be integral part of a proof, showing its limitations. Flaky hardware, CPU errata, flipped bits in RAM, and un-sound specifications are a thing.
Even if it does work, a specification will never catch every detail. Any undergrad can come up with a formal specification for a sorting algorithm and prove that some simple ones follow it. But while both a worst-case O(n log n) Timsort and a best-case O(n^2) Selection Sort might technically be guaranteed to sort your data, the two are definitely not interchangeable!
And there is no way to verify the main spec because how do you describe the GCD part? Maybe the idea of a generic verifier of finiteness looks appealling as a common task, a subroutine: here is the specific GCD part and we check finiteness with a standart checker. But it goes against the very fabric of programming, because in programming we sort of reuse logical checks, use interdependencies between variables a generic routine won't know about.