Canonical binary count-up loops — definitions #
This module defines an output-safe loop driver for a body indexed by a
canonical little-endian binary counter. A second, distinct work tape stores a
preserved limit. Before each iteration, the driver compares the two tapes in
lockstep, remembers whether every scanned symbol agreed, and rewinds both
heads to cell one. Equality halts the loop; inequality runs the body and then
increments the counter with TM.binarySuccTM.
The comparison deliberately scans through the full limit width even after a
mismatch. Under the intended invariant counter ≤ limit, this gives the
value-independent exact comparison time 2 * limit.size + 2. The controller
never moves the output head left and does not alter its contents; output
behavior during an iteration is entirely delegated to the body.
The wrapper-free certificate structures at the end of the file separate the executable controller from later correctness and all-prefix space proofs.
Controller phases for a canonical binary count-up loop.
The Boolean carried by scan and rewind records whether the counter and
limit symbols seen so far were equal.
- scan (equalSoFar : Bool) : BinaryForPhase
- rewind (equalSoFar : Bool) : BinaryForPhase
- done : BinaryForPhase
Instances For
Equations
- Complexity.TM.instDecidableEqBinaryForPhase.decEq (Complexity.TM.BinaryForPhase.scan a) (Complexity.TM.BinaryForPhase.scan b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- Complexity.TM.instDecidableEqBinaryForPhase.decEq (Complexity.TM.BinaryForPhase.scan equalSoFar) (Complexity.TM.BinaryForPhase.rewind equalSoFar_1) = isFalse ⋯
- Complexity.TM.instDecidableEqBinaryForPhase.decEq (Complexity.TM.BinaryForPhase.scan equalSoFar) Complexity.TM.BinaryForPhase.done = isFalse ⋯
- Complexity.TM.instDecidableEqBinaryForPhase.decEq (Complexity.TM.BinaryForPhase.rewind equalSoFar) (Complexity.TM.BinaryForPhase.scan equalSoFar_1) = isFalse ⋯
- Complexity.TM.instDecidableEqBinaryForPhase.decEq (Complexity.TM.BinaryForPhase.rewind a) (Complexity.TM.BinaryForPhase.rewind b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- Complexity.TM.instDecidableEqBinaryForPhase.decEq (Complexity.TM.BinaryForPhase.rewind equalSoFar) Complexity.TM.BinaryForPhase.done = isFalse ⋯
- Complexity.TM.instDecidableEqBinaryForPhase.decEq Complexity.TM.BinaryForPhase.done (Complexity.TM.BinaryForPhase.scan equalSoFar) = isFalse ⋯
- Complexity.TM.instDecidableEqBinaryForPhase.decEq Complexity.TM.BinaryForPhase.done (Complexity.TM.BinaryForPhase.rewind equalSoFar) = isFalse ⋯
- Complexity.TM.instDecidableEqBinaryForPhase.decEq Complexity.TM.BinaryForPhase.done Complexity.TM.BinaryForPhase.done = isTrue ⋯
Instances For
BinaryForPhase is finite, as required by the concrete machine model.
Equations
- One or more equations did not get rendered due to their size.
One count-up iteration: run body, take the seqTM seam, and increment
the designated canonical binary counter.
Equations
- body.binaryForIterationTM counterIdx = body.seqTM (Complexity.TM.binarySuccTM counterIdx)
Instances For
Count upward from a canonical binary counter to a preserved canonical binary limit.
The intended correctness interface assumes counterIdx ≠ limitIdx. In the
driver phases both work heads move in lockstep. A complete scan records tape
equality without writing a verdict, and a complete rewind either halts or
enters binaryForIterationTM body counterIdx. When that composite iteration
halts, one content-preserving seam returns to a fresh equality scan.
Input, unrelated work tapes, and output use read-back/idle actions throughout
the controller. In particular, the driver itself is compatible with
append-only output; any output writes come only from body.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Exact time for one full-width equality scan and synchronized rewind when
the counter is bounded by limit.
Equations
- Complexity.TM.binaryForCompareTime limit = 2 * limit.size + 2
Instances For
Exact time of the composite iteration before the outer loopback seam:
the body run, one seqTM transition, and canonical binary successor.
Equations
- Complexity.TM.binaryForIterationTime bodyTime value = bodyTime value + 1 + Complexity.TM.binarySuccTime value
Instances For
Exact remaining count-up-loop time.
value is the current counter and count is the number of nonterminal
iterations remaining. The zero case performs the final successful comparison.
Each successor case performs one unsuccessful comparison, one composite
iteration, one outer loopback seam, and the remaining loop. Intended uses
supply value + count = limit.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.TM.binaryForLoopTime bodyTime limit value 0 = Complexity.TM.binaryForCompareTime limit
Instances For
Wrapper-free certificate for exact control flow of a canonical binary count-up loop.
All configurations use the public state type of
binaryForTM body counterIdx limitIdx. The client supplies the intended
canonical configuration family and proves that a nonterminal test reaches the
composite iteration, which runs the body and successor before one loopback
step advances to the next scanner configuration. At limitValue, the client
supplies the final comparison run.
The counter and preserved-limit tapes are distinct.
- scanCfg : ℕ → Cfg n (body.binaryForTM counterIdx limitIdx).Q
Client-supplied canonical combined-machine configuration before testing
value. - iterationStartCfg : ℕ → Cfg n (body.binaryForTM counterIdx limitIdx).Q
Client-supplied canonical configuration at the composite iteration start.
- iterationDoneCfg : ℕ → Cfg n (body.binaryForTM counterIdx limitIdx).Q
Client-supplied canonical configuration after the exact composite iteration.
- doneCfg : Cfg n (body.binaryForTM counterIdx limitIdx).Q
Client-supplied canonical final driver configuration.
- testRun (value : ℕ) : value < limitValue → (body.binaryForTM counterIdx limitIdx).reachesIn (binaryForCompareTime limitValue) (self.scanCfg value) (self.iterationStartCfg value)
A nonterminal comparison and rewind enter the composite iteration.
- iterationRun (value : ℕ) : value < limitValue → (body.binaryForTM counterIdx limitIdx).reachesIn (binaryForIterationTime bodyTime value) (self.iterationStartCfg value) (self.iterationDoneCfg value)
The body,
seqTMseam, and successor have the advertised exact runtime. - loopbackStep (value : ℕ) : value < limitValue → (body.binaryForTM counterIdx limitIdx).step (self.iterationDoneCfg value) = some (self.scanCfg (value + 1))
The preserving outer seam returns to the next comparison.
- doneRun : (body.binaryForTM counterIdx limitIdx).reachesIn (binaryForCompareTime limitValue) (self.scanCfg limitValue) self.doneCfg
Equality at the limit completes one final comparison and rewind.
Instances For
All-prefix auxiliary-space obligations for a certified binary count-up loop. The comparison and composite-iteration obligations concern prefixes of their advertised exact runs; later execution may already have crossed the corresponding seam.
- testPrefixWithin (value time : ℕ) (cfg : Cfg n (body.binaryForTM counterIdx limitIdx).Q) : value ≤ limitValue → time ≤ binaryForCompareTime limitValue → (body.binaryForTM counterIdx limitIdx).reachesIn time (spec.scanCfg value) cfg → cfg.WithinAuxSpace inputLength spaceBound
Every prefix of each full-width comparison and rewind respects the budget.
- iterationPrefixWithin (value time : ℕ) (cfg : Cfg n (body.binaryForTM counterIdx limitIdx).Q) : value < limitValue → time ≤ binaryForIterationTime bodyTime value → (body.binaryForTM counterIdx limitIdx).reachesIn time (spec.iterationStartCfg value) cfg → cfg.WithinAuxSpace inputLength spaceBound
Every prefix of each body-plus-successor iteration respects the budget.