Formal specification Created 2026-10-14 Updated 2026-10-18
A mathematically precise description of permitted behaviour. A formal specification for the microkernel file-read example's service could relate an authorized request to the exact returned bytes; a formal specification of its microkernel's IPC need only describe the protected transport operation. They state different obligations.
For the summation loop verification, require a nonnegative integer input and a returned value satisfying . The formal specification describes what answer is acceptable without requiring this particular loop: another implementation may satisfy the same contract. State separately whether partial correctness or total correctness is required. A Hoare triple packages the precondition, the program and the postcondition; Hoare logic supplies rules for establishing such claims.
Precision alone does not ensure a useful requirement. The postcondition permits returning zero for every nonnegative integer input; it does not specify the intended triangular number. Conversely, an impossible precondition permits no starts, making a universal correctness claim vacuous. Check both that intended inputs are admitted and that admitted outputs express the intended task.
Hoare logic Created 2026-10-18 Updated 2026-11-05
Hoare logic proves properties of programs through Hoare triples . A precondition constrains initial states and a postcondition constrains returned states. The basic rules establish partial correctness; termination requires a further argument.[ref]
For a program expression whose evaluation is defined and has no side effects, the assignment rule is
The substitution replaces the free occurrences of in the desired postcondition. For example, obtaining after x := x+1 requires beforehand, so suffices. Integer overflow must be excluded or handled by the stated arithmetic model.
Sequential composition joins a first postcondition to the next precondition. For a while loop, proving establishes
Here is the loop invariant. For while x > 0 do x := x-1, starting with an exact nonnegative integer, is preserved and the false exit guard yields . The decreasing nonnegative integer is also a loop variant, establishing total correctness for this example.[ref]
For a proposed loop invariant , initial condition , guard , body , and postcondition , establish these Hoare logic obligations:
The first establishes before the loop; the second preserves it after each iteration; the third derives the desired result when the guard is false. Together they prove partial correctness. For total correctness, also prove algorithm termination, for example by a nonnegative integer loop variant that strictly decreases whenever the body executes. The loop invariant need not be the postcondition: it generally describes completed and unfinished work together.
Tony Hoare Created 2026-10-18 Updated 2026-11-05
Tony Hoare is a computer scientist whose contributions include quicksort, Hoare logic and communicating sequential processes. His industrial work included an early ALGOL 60 compiler; his institutional biography also describes an unsuccessful operating system project, giving concrete context for the difficulty of reliable systems engineering.[ref]
In his 1969 paper An Axiomatic Basis for Computer Programming by Tony Hoare, he set out assignment, composition and iteration rules for reasoning directly about program text. The assignment rule reasons backward from the required result, while a loop invariant compresses arbitrarily many iterations into a preservation obligation. The paper explicitly distinguishes these partial correctness results from successful termination and discusses how arithmetic and side effects affect the model.[ref]
Figure 1.
Portrait of Tony Hoare
. Dennis Hamilton (orcmid), Flickr; File caption identifies FLoC 2006, 18 August 2006. Creative Commons Attribution 2.0 Generic., via Wikimedia Commons. Source.