Prove initiation and preservation with a strong enough invariant
Separate the desired safety property from an inductive strengthening, and interpret a failed preservation check before calling it a reachable bug.
On this page
The question for today
What you’ll understand
- State initiation, consecution, and safety-implication obligations.
- Explain why a true reachable-state property may not be inductive by itself.
- Use conservation and type constraints to rule out spurious preservation witnesses.
Checking many executions can increase confidence, but an inductive invariant supports reasoning over every finite number of allowed transitions. The argument has two essential parts: initial states satisfy the invariant, and every allowed step preserves it. A desired safety statement is often too weak to support the second part alone. Strengthen it with relationships that explain why the mechanism works, then verify that the strengthening actually implies the desired contract.
The proof is about all states satisfying the induction hypothesis
Let Init identify permitted starting states and Next relate current and successor states. An inductive predicate J must hold initially and remain true after every Next step from a J-state. If J implies the desired safety predicate P, the induction establishes P for all reachable states. Preservation examines every state satisfying J, including states that might not be reachable from Init. This wider domain is why a preservation counterexample can reveal an insufficient hypothesis rather than a genuine executable failure from the initial state.
Include type and domain facts in J rather than relying on a variable's informal name. A free-capacity field intended to be an integer needs that constraint in the reasoning. Check all action cases, including duplicate requests, cancellation, recovery, and stuttering. Initialization must cover every allowed initial state, not just one convenient example. An invariant that holds only after a startup transition needs either a different initial model or an additional argument establishing the transition and the invariant before the contract begins.
Strengthening records the reason over-allocation is impossible
For the reservation service, the desired bound is that held plus committed units never exceed capacity. That predicate alone allows an artificial state with capacity two, two occupied units, and one free unit. The Reserve guard sees the free unit and permits a third occupied unit. This state cannot arise under the correct conservation rule, but the weak induction hypothesis has not excluded it. Add conservation, nonnegative free capacity, status partitioning, and stable request domains to the strengthening, then revisit initiation and every action case.
For Reserve, occupied count increases by one while free capacity decreases by one; the positive-free guard keeps the new free count nonnegative. Commit preserves total occupied count while changing its status class. Cancel transfers a held unit back to free capacity. A duplicated cancellation must have no refund transition from a terminal status. These local calculations preserve the strengthened relationship, from which the desired bound follows. This is a mechanism-level explanation; merely declaring the bound as an invariant to check does not supply the induction argument.
Classify a counterexample before changing the algorithm
A checker started from Init can expose a reachable invariant violation within its configured search. A checker started from J to test preservation can instead expose a state admitted by J but unreachable from Init. Inspect the starting predicate and trace before deciding whether to repair the protocol or strengthen the candidate invariant. An overstrong invariant can fail initiation by excluding legitimate starts; an understrong one can fail preservation or fail to imply P. Every changed strengthening needs all three obligations checked again under the same domains and assumptions.
The function instrument offers a small domain reminder. Reset, set coefficient a=1 and position x=1, predict y=1, then Play or Step. Separately Reset, set a=1 and x=−1, predict the same y=1 but tangent slope −2 rather than +2, then Play or Step. One output value does not capture all state facts relevant to the next claim. This fixed quadratic is not an invariant prover and has no reservation actions. It only illustrates why a summary can omit distinctions required by a preservation argument.
Work it through
A failed induction attempt need not be a reachable failure
Take capacity C=2 and the candidate predicate P saying occupied count R is at most two. A preservation checker starts from the arbitrary P-state R=2,F=1 and applies Reserve, which requires F>0 and updates R'=R+1,F'=F−1. Analyze the witness and the conservation strengthening.
The starting state satisfies P because R=2≤2. It violates conservation because F+R=1+2=3, rather than C=2, so it is excluded by the stronger J.
Reserve is enabled in this artificial state and produces R'=3,F'=0, violating P. This refutes P's inductiveness for the stated transition relation; it does not demonstrate reachability from the correct initial state.
For a J-state, F+R=2 and F>0 imply R≤1. Reserve therefore yields R'≤2, while F'+R'=(F−1)+(R+1)=2. The strengthening supplies the missing argument for this action case.
Distinguish a preservation witness from an Init-reachable counterexample. A complete proof still needs initialization, all action cases, type facts, and J⇒P.
The living notebook
Explore the model
Interactive lab · function
A summary can lose information needed by another property
Reset, set a=1 and x=1, predict y=1 and tangent slope 2, then Play or Step. Separately Reset, set a=1 and x=−1, predict y=1 and slope −2, then Play or Step. The instrument evaluates y=ax², its tangent, and signed area; it does not prove invariants or explore service transitions.
- y at chosen x
- 0.608
- Tangent slope · 2ax
- 1.35
- Signed area · ax³/3
- 0.182
This lab uses only y = ax². Playback traces the curve within the fixed integration interval from 0 to x; it does not estimate numerical error or change the chosen point. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA useful induction hypothesis retains the relationships needed for preservation.
Pause & reason
Check your understanding
Your turn
Try it yourself
Capacity is three, with two held units, no committed units, and one free unit. Cancel one held request, then suppose a buggy duplicate cancellation increments free again without changing any status. Compute the conservation total after each action and identify the missing guard.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The legitimate cancellation removes exactly one held unit; the duplicate has no remaining held unit to return.
Compare with the solution
The legitimate cancellation gives held one and free two, totaling three. The buggy duplicate gives held one and free three, totaling four. Cancellation's refund must require that the same stable request is currently held and atomically change it to cancelled. A terminal duplicate must preserve capacity rather than issue another refund.
Keep the idea
Take it with you
- Initiation, consecution, and implication to the desired property are distinct obligations.
- Strengthen a safety predicate with the relationships that make preservation true.
- A preservation counterexample can expose unreachable states admitted by the hypothesis.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.