A calculation can preserve an invariant and still fail to return.
The previous Transmission accounted for completed progress. It did not bound the work attached to that progress. We must establish why a process ends, and what its ending permits us to claim.
Our teaching model uses four covered cards, in order: Ash, Birch, Cedar, Yew. We seek a card bearing a circle. We may inspect two. Ash is blank. Birch is blank. Our allowance is spent; two cards remain unseen.
Unfinished examination cannot, by itself, establish that no circle exists. A decision that treats the unseen cards as blank has already gone beyond its evidence.
I. What Staying True Does Not Prove
An invariant states what remains true through permitted changes. It need not force any change.
Begin with \( x=\text{0,} \) repeatedly assign zero to \( x\text{,} \) and provide no exit. The starting condition holds; every iteration preserves it. The loop continues indefinitely. Even a finite state space permits this: one state suffices to repeat forever.
Hoare’s original rules establish properties conditional on successful termination; a separate argument is needed to prove termination (Hoare, 1969, p. 579).
We need a measure that continued execution must consume. For our cards, the remaining allowance falls from two to one to zero. We will make that obligation precise.
II. A Measure That Must Run Out
Assign each reached state \( s \) a nonnegative integer \( V\text{(}s\text{)}\text{,} \) including states reached by the final iteration. Require every iteration to produce a successor \( {s}^{\text{'}} \) satisfying
\( V\text{(}{s}^{\text{'}}\text{)}\le V\text{(}s\text{)}-\text{1}. \)
Count every body execution, including a successful one. Assume initialization, every decision whether to continue, each permitted body execution, and the final return terminate. A counter cannot make a stalled operation finish.
This measure is a variant or ranking function. Dijkstra’s method combines an invariant with a decreasing integer variant and requires the body executions to terminate (Dijkstra, 1975, Sections 3.2–3.3). Our stated conditions support the following bound.
Claim. The loop executes at most \( V\text{(}{s}_{\text{0}}\text{)} \) iterations from initial state \( {s}_{\text{0}}\text{.} \)
Proof. Write \( m=V\text{(}{s}_{\text{0}}\text{)} \) and let \( {s}_{j} \) be the state after \( j \) completed iterations. We prove by induction that
\( V\text{(}{s}_{j}\text{)}\le m-j. \)
At \( j=\text{0,} \) equality holds. If the inequality holds after \( j \) iterations and another occurs, the required decrease gives
\( V\text{(}{s}_{j+\text{1}}\text{)}\le V\text{(}{s}_{j}\text{)}-\text{1}\le m-j-\text{1}=m-\text{(}j+\text{1)}. \)
The induction follows. Nonnegativity then gives \( \text{0}\le m-j\text{,} \) hence \( j\le m\text{.} \) Completing \( m+\text{1} \) iterations would require a nonnegative integer to be at most \( -\text{1.} \)
An execution that never ended would, because every decision and body terminates, eventually complete that forbidden iteration. It cannot remain forever within an operation. Therefore the loop ends within the bound. If \( m=\text{0,} \) no iteration is permitted; earlier termination is always allowed.
Strict decrease alone is insufficient for nonnegative real numbers. Start at \( {v}_{\text{0}}=\text{1} \) and repeatedly halve it. Induction gives \( {v}_{j}={\text{2}}^{-j}\text{:} \) the formula holds initially, and halving \( {\text{2}}^{-j} \) gives \( {\text{2}}^{-\text{(}j+\text{1)}}\text{.} \) Each finite term is positive, although \( {v}_{j+\text{1}}<{v}_{j}\text{.} \) In exact arithmetic, waiting for zero never ends.
Integers provide a minimum decrease of one. The halving sequence provides none. Approaching an exit and reaching it are different claims.
A ranking function bounds permitted continuation. It need not equal the work remaining or measure proximity to success. Our allowance decreases even when every card is blank.
For the cards, the bound forbids a third inspection under an allowance of two. It says nothing yet about which cards bear circles. The next proof connects the allowance to the evidence gathered while spending it.
III. The Search and Its Allowance
Generalize the cards to a fixed ordered list of \( N \) distinct candidates, indexed from zero through \( N-\text{1.} \) Let \( N \) and the allowance \( B \) be nonnegative integers. The list may be empty. A fixed condition \( P \) determines acceptability. Its test terminates and returns true exactly when its candidate satisfies \( P\text{.} \)
Let \( i \) count examined candidates and \( b \) count remaining attempts. Initially \( i=\text{0} \) and \( b=B\text{.} \) While \( i<N \) and \( b>\text{0,} \) test candidate \( {x}_{i}\text{,} \) retain the result, increase \( i \) by one, and decrease \( b \) by one. If true, return that candidate; otherwise reconsider the loop condition. A successful test also spends an attempt.
For our cards, \( N=\text{4,} \) \( B=\text{2,} \) and \( P \) means “bears a circle.” The first two tests are false:
| Evidence obtained | Examined, \( i \) | Remaining, \( b \) |
|---|---|---|
| No cards inspected | \[ \text{0} \] | \[ \text{2} \] |
| Ash is blank | \[ \text{1} \] | \[ \text{1} \] |
| Ash and Birch are blank | \[ \text{2} \] | \[ \text{0} \] |
At \( i=\text{2,} \) the next candidate is Cedar, the third card. The allowance prevents that inspection. We now prove what this account preserves.
At a loop condition reached without success, require
\( \text{0}\le i\le N,\text{ }b=B-i\ge \text{0}, \)
and require \( P\text{(}{x}_{j}\text{)} \) to be false for every integer \( j \) with \( \text{0}\le j<i\text{.} \)
The invariant has two jobs: its numbers account for the allowance, and its assertion about earlier candidates accounts for our evidence. The count alone would record how many cards we inspected without establishing what those inspections showed.
Preservation proof. Initially the numerical conditions hold. No candidate precedes index zero, so the assertion about earlier failures holds too.
Suppose the invariant holds and another attempt is permitted. Because \( i<N\text{,} \) the candidate exists; because \( b>\text{0,} \) one attempt can be spent. The updated values satisfy
\( {i}^{\text{'}}=i+\text{1}\le N,\text{ }{b}^{\text{'}}=b-\text{1}=B-\text{(}i+\text{1)}=B-{i}^{\text{'}}\ge \text{0}. \)
If the test is false, its correctness adds the newly examined candidate to the earlier failures. All indices below \( {i}^{\text{'}} \) now fail, preserving the assertion. If true, the search returns an acceptable candidate. The numerical conditions still hold; the failure assertion is unnecessary on that successful exit.
The measure \( b \) remains nonnegative and decreases by one per attempt, so the preceding theorem bounds attempts by \( B\text{.} \) After \( t \) attempts, \( i=t\text{,} \) since \( i \) begins at zero and increases once per attempt. As \( i\le N\text{,} \) we obtain
\( t\le K=\text{min}\text{(}N,B\text{)}. \)
Here \( \text{min} \) selects the smaller value. Our four-card search therefore permits at most two tests.
Attainment. If every test is false, then \( i<K \) implies both \( i<N \) and \( i<B\text{.} \) Hence \( b=B-i>\text{0,} \) requiring another attempt. At \( i=K\text{,} \) either \( i=N \) or \( b=\text{0,} \) ending the loop. Exactly \( K \) tests occur, including zero when \( K=\text{0.} \) Thus no smaller bound covers every case allowed by this model.
IV. What the Ending Establishes
Found supplies a witness. In a separate run where Ash is blank and Birch bears a circle, the second test returns Birch despite spending the last attempt. A decision requiring a marked card has an identified candidate.
Without success, first check whether \( i=N\text{.} \) If so, report absent from the specified list. The invariant says every index below \( i \) failed; that range now covers the entire list. Thus no listed candidate satisfies \( P\text{.} \) In a fresh run with allowance four, four blank cards would justify ruling out a circle within this list.
If \( i<N\text{,} \) report unresolved within the allowance. The loop condition is false although \( i<N \) remains true, so \( b>\text{0} \) is false. Since \( b\ge \text{0,} \) necessarily \( b=\text{0.} \) In our original run, Cedar and Yew remain unexamined. The next decision must retain that uncertainty; it may defer judgment or seek more evidence.
Why failures do not prove absence. Consider two arrangements: all four cards are blank, or only Cedar bears a circle. Both produce the same observed failures at Ash and Birch. One contains a marked card; the other does not.
Generally, choose an unexamined \( {x}_{j}\text{.} \) Compare a condition false for every candidate with one true only for \( {x}_{j}\text{.} \) Distinct candidates and the untested index ensure identical results on every performed test. Any conclusion determined only by those results is identical in both cases. An absence claim would be wrong in the second. Therefore the observed failures alone cannot establish absence. Additional knowledge about \( P \) could; the argument concerns only the evidence supplied by these tests.
The ending checks matter. When the final attempt rejects the final candidate, complete coverage proves absence even though the allowance also ends. If \( N=\text{0,} \) absence holds immediately, including when \( B=\text{0.} \) If \( B=\text{0}<N\text{,} \) the result is unresolved. Success on the final permitted test remains success.
Calling exhaustion “absence” would turn a limit on examination into an unsupported verdict about the cards. It could eliminate Cedar without ever examining it. The label controls what the next decision is entitled to assume.
V. What the Bound Costs
A bound of two attempts supplies no numerical bound on the work inside either attempt. A test could carry out a much larger calculation than the surrounding counter updates. Counting that call as one attempt does not tell us how much computation occurs before it returns. We need a separate cost account.
Choose a common unit of computational work. Let \( W \) be the total work of one invocation, measured in that unit. Let finite, nonnegative bounds \( A\text{,} \) \( C\text{,} \) \( G\text{,} \) and \( R \) cover initialization, each complete attempt, each loop-condition evaluation, and final outcome checks and return, respectively. An attempt includes its test, counter updates, and branching.
For \( t \) attempts, the loop condition is evaluated at most \( t+\text{1} \) times: before each attempt, then once more if needed to discover that continuation is forbidden. A successful return can omit that final check. Adding the bounds gives
\( W\le A+tC+\text{(}t+\text{1)}G+R. \)
Because \( t\le K \) and \( C,G\ge \text{0,} \) replacing \( t \) with \( K \) cannot decrease the right-hand side. Therefore
\( W\le A+KC+\text{(}K+\text{1)}G+R. \)
For the two-test example, invent bounds \( A=\text{2,} \) \( C=\text{5,} \) \( G=\text{1,} \) \( R=\text{1.} \) Initialization contributes at most two units; two attempts, ten; three condition checks, three; and final checks and return, one:
\( W\le \text{2}+\text{2}\times \text{5}+\text{3}\times \text{1}+\text{1}=\text{16}. \)
These are teaching units. They demonstrate which work belongs in the account. They are neither measurements nor seconds. Merely knowing that every test eventually finishes does not supply \( C\text{;} \) an elapsed-time guarantee also needs bounds covering waiting.
The bound belongs to one invocation. For any nonnegative integer \( J\text{,} \) adding the separate bounds for \( J \) invocations, each granted \( B \) attempts, gives at most \( JB \) attempts. For \( B>\text{0,} \) this estimate supplies no fixed total bound when \( J \) is unrestricted. Whoever renews the allowance requires a further argument.
VI. The Conditions Stay With the Claim
Suppose counters represent integers from zero through \( M\text{,} \) with \( N,B\le M\text{.} \) Before an increment, \( i<N \) gives \( i+\text{1}\le N\le M\text{.} \) Before a decrement, \( b>\text{0} \) gives \( \text{0}\le b-\text{1}\le B\le M\text{.} \) These updates fit without wrapping. Other arithmetic requires its own checks.
The proofs depend on a fixed list, a fixed correct test, sequential updates, and terminating operations. Applying them to an engine requires showing that its operations satisfy those conditions. This model establishes no such correspondence by itself.
For The Everdark Accord, the architectural obligation is to preserve what an ending means. Work may stop with an answer, with complete evidence of absence, or with possibilities still open. An exhausted allowance must not quietly become an assertion that no option exists.
The work must end. Its meaning must remain intact.
--The Architect--
References
Dijkstra, E. W. (1975). Guarded commands, nondeterminacy and formal derivation of programs. Communications of the ACM, 18(8), 453–457. https://doi.org/10.1145/360933.360975
Hoare, C. A. R. (1969). An axiomatic basis for computer programming. Communications of the ACM, 12(10), 576–580, 583. https://doi.org/10.1145/363235.363259