A record and an original worked study

1969

Hoare: Assertions and Termination

Work backward through an original assignment, then prove a loop invariant and a separate stopping argument under explicitly unbounded integer arithmetic.

An invented assignment is solved backward, and an integer loop separates its invariant from a decreasing termination measure.
xโ‰ฅ3
Original assignment precondition
nโˆ’i
Original decreasing integer measure

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.

Fixtures are invented; none reconstructs historical measurements.
QuestionRecord or stipulated inputInterpretation
AssignmentSubstitute the new expressionUse the new x in the second assignment.
Invariant2s=i(i+1)A relation preserved by the stipulated body.
Stoppingnโˆ’i decreases to 0A separate argument over nonnegative integers.

Chronology

A timeline of the turning points

  1. 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

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.

  1. C. A. R. Hoare, CACM 12(10), 576โ€“580, 583, 1969An Axiomatic Basis for Computer Programming