Constant-cost counting loops #
An indexed semantic invariant describes the state after each completed iteration. The native counter increases by exactly one, and the limit register keeps the fixed endpoint. The rule derives the counter bounds, decreasing rank and final index from these facts; clients still prove execution of the actual body, including its word fits and memory semantics.
Main results #
ExecWithin.loop_count: count from the current index toNwith a body allowanceT, charging(N - index) * (T + 2) + 2, including both loop-control instructions per iteration and the final test/exit. No one-past-end word-fit premise is required.prefix_write_step: advance a written-prefix and outside-prefix memory invariant across a single store atd + j.
This is an original specialization of ExecWithin.loop_invariant.
Execute a native counting loop with an indexed semantic invariant. The invariant supplies the unchanged limit register. Each body execution advances the counter by exactly one and establishes the next semantic state. The bound excludes setup and the final program halt.
Advance a loop's written-prefix and outside-prefix memory invariants across a single store
at d + j.