Width-driven binary shift-and-add multiplication -- definitions #
This module defines a six-work-tape multiplication ABI and a concrete least-significant-bit-first shift-and-add machine. The multiplicands are preserved, the accumulator receives their product, and three scratch tapes are returned to canonical zero.
One pure shift-and-add iteration. The first component is the partial accumulator and the second is the current shifted multiplicand.
Equations
Instances For
Fold little-endian multiplier bits through generalized initial accumulator and shift values.
Equations
- Complexity.BinaryShiftMul.fold [] x✝¹ x✝ = (x✝¹, x✝)
- Complexity.BinaryShiftMul.fold (bit :: bits) x✝¹ x✝ = Complexity.BinaryShiftMul.fold bits (Complexity.BinaryShiftMul.step bit x✝¹ x✝).1 (Complexity.BinaryShiftMul.step bit x✝¹ x✝).2
Instances For
Accumulator value after the first i little-endian multiplier bits.
Equations
- Complexity.BinaryShiftMul.partialAcc lhs rhs i = lhs * Nat.fromBitsLE (List.take i rhs.bits)
Instances For
Shifted multiplicand after i iterations.
Equations
- Complexity.BinaryShiftMul.partialShift lhs i = lhs * 2 ^ i
Instances For
Preserved multiplicand tape.
Instances For
Preserved multiplier and loop-driver tape.
Instances For
Initially-zero output accumulator tape.
Instances For
Current shifted multiplicand tape.
Instances For
First alternating zero scratch tape.
Instances For
Second alternating zero scratch tape.
Instances For
Distinct ABI slots map to distinct work tapes.
Initialize the shifted multiplicand from lhs, using the zero accumulator
as the copy routine's preserved zero scratch.
Equations
- Complexity.TM.binaryShiftMulInitTM abi = Complexity.TM.binaryCopyIntoTM abi.lhs abi.shift abi.acc
Instances For
Execute the conditional add and then the unconditional doubling step.
Equations
Instances For
Branch on the current multiplier bit. A one performs update-and-double; every other dispatched Boolean symbol performs only the doubling step.
Equations
Instances For
Iterate once per canonical bit on the preserved multiplier tape.
Equations
Instances For
Restore the multiplier head and reset every non-output scratch tape.
Equations
- Complexity.TM.binaryShiftMulCleanupTM abi = (Complexity.TM.rewindWorkTM abi.rhs).seqTM (Complexity.TM.resetBinaryWorkManyTM [abi.shift, abi.tmp, abi.dbl])
Instances For
Initialize, scan the multiplier, and clean up the six-tape shift-and-add implementation.
Equations
Instances For
Combined input width used by the conservative multiplication budget.
Equations
- Complexity.TM.binaryShiftMulWidth lhs rhs = lhs.size + rhs.size
Instances For
Audited conservative quadratic budget for initialization, all multiplier iterations, cleanup, and composition seams.
Equations
- Complexity.TM.binaryShiftMulTime lhs rhs = 33 * Complexity.TM.binaryShiftMulWidth lhs rhs ^ 2 + 170 * Complexity.TM.binaryShiftMulWidth lhs rhs + 58