Loop correctness with ordinary local values #
The invariant and decrease relation below concern ordinary local coordinates and the actual shared heap. They are transported through the lossless view to the existing source well-founded loop rule. No loop interpreter, source product type, machine representation or proposed instruction budget is introduced.
The guard specification starts before the guard and retains its actual locals and heap. A false guard establishes the final postcondition there. A true guard runs the body from that state; only normal completion must restore the invariant and decrease relative to the state before the guard. Early body returns instead establish their result postcondition, while faults and missing guard returns cannot prove these strict specifications.
observe_while_contract separates the guard and body into ordinary relational
BlockSpec contracts. Its ready predicate retains the complete iteration's
starting state, so the body can establish well-founded progress without a
nested native triple or manual control-outcome transport in the author's proof.
Prove the actual source loop using an invariant and well-founded decrease over ordinary locals and shared heaps. The guard and body are the same block observations used in the loop equation, not supplied executable callbacks.
A natural-valued mathematical variant is a specialization of the same well-founded rule. It measures a complete guard/body iteration, not runtime instructions, fuel or a budget required for functional correctness.
Compose independent mathematical contracts for a loop guard and body.
The guard exposes its actual result and final state. A true result establishes
ready, which relates that state to the complete iteration's starting state;
a false result establishes the normal postcondition at the guard's actual exit.
The body contract starts at this real intermediate state. Only normal body completion restores the invariant and decreases the well-founded relation; early returns establish their own postcondition. The contracts and conclusion refer to the existing observations, without outcome-tuple or nested-WP work in the mathematical premises.
Use a natural mathematical variant with the same separate guard and body contracts. Its strict decrease is measured across a complete guard/body round, so an effectful guard cannot silently change the comparison's starting state.