The short answer
A correct answer about a program must identify both the allowed inputs and the arithmetic model. A preserved assertion and a stopping argument answer different questions.
Selected record and original analysis
Separate the obligations
Read the stated model and observation separately.
| Question | Record or stipulated input | Interpretation |
|---|---|---|
| Assignment | Substitute the new expression | Use the new x in the second assignment. |
| Invariant | 2s=i(i+1) | A relation preserved by the stipulated body. |
| Stopping | nโi decreases to 0 | A separate argument over nonnegative integers. |
Chronology
A timeline of the turning points
Selected paper
Published the axiomatic-programming account.
A rule and its limit
Hoareโs assignment rule substitutes an expression into an assertion. His iteration rule preserves an invariant while the guard is true and yields the invariant with the negated guard when execution terminates. The paper does not supply a general termination proof.
The selected page also discusses restrictions such as expression side effects. The calculation below removes that complication by stipulation rather than treating every programming language as if it obeyed the same rules.
Sources for this section: [1]
Two original questions
Use unbounded mathematical integers and side-effect-free expressions. First execute x:=x+2, then y:=3*x. Find the weakest starting condition on x that ensures yโฅ15. Assignments occur in order; the second uses the new x.
Second, take an integer nโฅ0. Set i=0, s=0. While i<n, execute i:=i+1 followed by s:=s+i. Show that 2s=i(i+1) and 0โคiโคn are preserved. What holds when the loop stops? Supply a separate decreasing quantity proving that it does stop.
Sources for this section: [1]
Reference answer: work backward and forward
For the assignment, 3(x+2)โฅ15 is equivalent to xโฅ3. There is no rounding or overflow in the stipulated arithmetic. A fixed-width implementation would need its own bounds.
Initially 2s=i(i+1)=0. If the old value is i, the body adds i+1, so the new doubled sum is i(i+1)+2(i+1)=(i+1)(i+2). The guard and nโs integrality preserve the stated bounds. At exit i=n, so s=n(n+1)/2.
The nonnegative integer nโi decreases by one on every iteration. This separately proves termination in the fixture. Reversing the two body assignments instead sums 0 through nโ1; for n=3 it returns 3 rather than 6. Order is part of the program, not a stylistic choice.
Sources for this section: [1]
Return to the research question
The example distinguishes a logical relationship from an execution guarantee. The invariant alone supplies the requested relationship on exit; the decreasing quantity closes a different obligation. Neither step validates an unspecified compiler, finite-word arithmetic or an arbitrary program.
Sources for this section: [1]
Continue the chronology
Related history guides
Biography context
Explore United Kingdom through connected lives
Connected biographies
The working life behind the record
Quick answers
Common questions
- Does the fixture use machine overflow?
- No. It explicitly uses unbounded integers.
- Does reversing the body preserve the same sum?
- No. The reference counterexample demonstrates the changed result.
Primary and institutional sources
How this history was checked
These selected records support the historical account. Invented inputs and their original reference answers are identified explicitly. This article was reviewed on 31 October 2026.
