The counting loop's body #
⚠️ Unreviewed by Bolton
The body of the counting loop advances the count and one of the two tallies. Which tally it
advances is decided by the simulated path's verdict, and TM.ifTM is the combinator that reads a
verdict and branches — but it reads the output tape, so the verdict must already have been
published there, which is what TM.writeOutputBitTM is for.
This file builds the arithmetic end of the body: given the verdict in the output tape's slot, bump the chosen tally, bump the count, and blank the slot again for the next pass.
Main results #
TM.binarySuccTM_hoareTime_pinned,TM.binaryRippleSubTM_hoareTime_pinned— the successor and truncated subtraction, with fully named result banksTM.condBumpTM,TM.condBumpTM_hoareTime— bump one of two registers according to the published verdictTM.tallyBumpTM,TM.tallyBumpTM_hoareTime— that bump, the count's bump, and the blanking of the verdict slot, chained through named banks
The canonical successor, with the result bank named. Tape.HasBinaryNat determines a
tape outright, so the library's contract — which reports the new value rather than the new tape —
can be sharpened to a pinned one, which is what the chaining rules consume.
Bump one of two registers, according to the verdict already in the output slot. The test
stage is TM.skipTM: the verdict is published before the branch is reached, so the conditional
has nothing left to compute.
Equations
- Complexity.TM.condBumpTM aIdx rIdx = Complexity.TM.skipTM.ifTM (Complexity.TM.binarySuccTM aIdx) (Complexity.TM.binarySuccTM rIdx)
Instances For
The conditional bump's contract. The verdict b sitting in the output slot selects which
register grows; the slot itself is untouched, since the branch reads it and nothing writes it.
The arithmetic end of the loop body. Bump the selected tally, bump the count, and blank the verdict slot so the next pass starts from the state the loop's invariant describes.
Equations
- Complexity.TM.tallyBumpTM cIdx aIdx rIdx zIdx = Complexity.TM.bigSeqTM [Complexity.TM.condBumpTM aIdx rIdx, Complexity.TM.binarySuccTM cIdx, Complexity.TM.writeOutputBitTM zIdx]
Instances For
The arithmetic end of the loop body, contracted. Every intermediate bank is named, so the
three stages chain through TM.bigSeqTM_hoareTime_pinned with no existential in sight.
Truncated subtraction, with the result bank named. As with the successor, the library
reports the new values; since Tape.HasBinaryNat determines a tape, the operands come back
literally unchanged and only the result register moves.