Every programmer has stared at a bug that passed all the tests yet destroyed production. Testing shows the presence of bugs; it cannot prove their absence. In 1969, computer scientist Tony Hoare published a two-page paper that took a radically different approach: treat programs as mathematical objects and prove they are correct.
The core idea is a Hoare triple, written {P} C {Q}:
- P is the pre-condition — what must be true before command C runs.
- C is the command (an assignment, a loop, a sequence of statements).
- Q is the post-condition — what is guaranteed to be true after C finishes.
If you can prove the triple is valid, you don't need to test: the program is mathematically correct relative to that specification. The sum-to-n loop that adds 1 + 2 + … + n? You prove it with a loop invariant — a property that holds before every iteration and implies the result when the loop exits.
This isn't just academic elegance. The same formalism, extended to separation logic and machine-checked proofs, powered the complete formal verification of the seL4 microkernel (2009) — the first operating-system kernel proved correct for every possible input. Hoare logic sits at the foundation of program verification tools, proof assistants, and the correctness guarantees built into safety-critical software worldwide.
Comments
Loading comments...