Canonical binary count-up loops #
This module exposes an output-safe bounded loop whose counter and preserved
limit use canonical little-endian binary work tapes. Under the certified
invariant counter ≤ limit, every test scans the full limit width, so a
comparison has the value-independent exact time 2 * limit.size + 2. A
nonterminal test runs the supplied body, increments the counter, and returns
to a fresh test; equality halts with both binary tapes rewound.
The generic certificates keep body-specific facts explicit. In particular,
the loop driver does not assume that an arbitrary body preserves its counter,
limit, or tape frames. Clients record those endpoint facts in
BinaryForLoopSpec and the corresponding prefix-space facts in
BinaryForLoopSpaceSpec.
Main results #
binaryForTM_compare_reachesIn_framegives the exact framed comparison.BinaryForLoopSpec.reachesIncomposes a certified loop exactly.BinaryForLoopSpaceSpec.prefix_withinAuxSpacecovers every run prefix.IsTransducer.binaryForTMpreserves one-way output safety.binaryForTM_hoareTimeruns the loop from a per-index contract for its body, for clients whose bodies come as Hoare triples rather than closed forms.guessProtocol_binaryForTMcarries a body's guess-tape discipline through the loop, so a nondeterministic body may be driven by one.
At equality, one full-width comparison preserves every tape and reaches the final driver configuration in exact time.
Strictly below the limit, one full-width comparison preserves every tape and reaches the composite iteration start in exact time.
A bounded canonical comparison has one exact, fully framed endpoint. It enters the composite iteration exactly below the limit and halts exactly at equality.
A certified count-up loop has its advertised exact remaining run.
Every canonical scanner configuration in a certified range satisfies the declared auxiliary-space budget.
The final configuration of a space-certified loop satisfies its declared auxiliary-space budget.
Every prefix of a certified binary count-up loop respects its declared auxiliary-space budget.
A count-up loop from a contract for its body.
BinaryForLoopSpec asks for a canonical configuration at every loop index,
which presumes a body whose tape effect is known in closed form. A body
assembled from Hoare triples has no such form — its contract only asserts that
some halting run exists — so this rule takes the per-index triple directly:
if the body carries BinaryForFrame at value to BinaryForBodyPost at
value, the driver runs the whole loop from counter zero to limitValue.
A binary count-up loop preserves the body's one-way-output discipline.
The guess protocol survives a count-up loop. The driver rewrites every tape it does not own and holds their heads still, so a body that consumes its guesses only in its advancing states keeps doing so inside the loop. The counter and the limit must not be the guess tape itself.