Reversible quantum×quantum multiplication — controlled shift-and-add (ECDLP Phase 2, Stage S2.3) #
Category: 1-Mathlib (CSD-free; staged as a Mathlib-upstream candidate).
The Tranche-3 multiplier (ModMul.lean) is quantum×classical (a·Y, a a classical constant fixing
which shifts appear). A genuine quantum×quantum multiply X·Y (both factors registers — what
squaring and elliptic-curve field multiplication need) controls each partial-product add on a register
bit X_i. This module folds the controlled ripple adder (CtrlAdd.lean, cRippleCirc_correct) over
the bits of X, with the per-bit control wire bound to X_i and a shared ancilla re-cleaned between
steps (cRippleCirc_anc_restored).
What is proved here #
cAccStep— the controlled accumulation step: one controlled full-window ripple add of the multiplicandY(valueYv) into the accumulator windowAcc[i, W), controlled onctrl, increases the accumulator byif ctrl then 2^i · Yv else 0. The controlled analogue ofModMul.accStep, routed throughcRippleCirc_correct(so thectrl-clear case adds nothing) — the heart of the quantum×quantum multiply.
Controlled accumulation step. One controlled full-remaining-width ripple add of the multiplicand
(value Yv, read by L.A) into the accumulator window Acc[i, W), controlled on L.ctrl: it
increases the full accumulator value by 2^i · Yv when the control is set and leaves it unchanged when
clear — + (if ctrl then 2^i · Yv else 0). The carry propagates through the whole upper accumulator
(width w = W - i); the low i bits are preserved (they are external to the slice); the add must not
overflow the window. The controlled analogue of ModMul.accStep.
The quantum×quantum multiplier and its correctness #
A CMulLayout lays out, on Fin M: the accumulator Acc (W wires), the control register X (the
first factor, whose bit sh controls partial product sh), the multiplicand Y (W wires, high bits
held zero), a per-shift carry chain Carry, and the shared ancilla anc. The multiplier is the
concatenation, over the shift list, of one controlled full-window ripple add of Y into Acc[sh, W)
controlled on X sh. Folding cAccStep gives Acc ← Acc + (∑ sh, [X_sh] · 2^sh) · Y = Acc + X·Y.
A quantum×quantum multiplier layout on Fin M: accumulator Acc, control register X,
multiplicand Y (high bits zero), per-shift carry chain Carry, shared ancilla anc. The fields are
pure wire geometry (disjointness + injectivity).
Accumulator wires (indices
[0, W)).Control-register wires (the first factor
X; bitshcontrols partial productsh).Multiplicand wires (
W-wire register; values in[0, n), high bits held zero).Carry chain for the partial-product add at shift
sh.- anc : Fin M
The shared clean ancilla.
Instances For
The quantum×quantum multiplier circuit: one controlled partial-product ripple add per shift.
Equations
- Reversible.cMulCircuit L shifts = Reversible.multiplier (List.map (fun (sh : ℕ) => Reversible.cRippleCirc (Reversible.cStepLayout L sh)) shifts)
Instances For
A partial-product step at shift sh preserves the carry chain of any other shift sh' ≠ sh.
A partial-product step preserves every control bit X j (the control register is read-only).
Quantum×quantum multiplier correctness (the S2.3 headline). The controlled shift-and-add
multiplier over shifts leaves the accumulator holding Acc + (∑ sh ∈ shifts, [X_sh] · 2^sh) · Y,
where [X_sh] is 0/1 for the control bit — provided the carries and ancilla start false, Y's high
bits are zero, and no step overflows. With shifts = [0, …, n-1] and Acc initialised 0 this is
Acc = X · Y (both factors quantum).
Quantum×quantum multiply, X · Y form. Over the full shift list [0, n), the controlled
shift-and-add multiplier leaves the accumulator holding Acc + (regValRange X) · Y. With Acc
initialised 0 this is Acc = X · Y (both factors quantum); with X preset to a copy of Y it is
Acc = Y² (squaring). The ctrlSum_eq rewrite collapses the per-bit controlled sum to the product.
The overflow hypothesis hbound is the worst-case-over-X condition
Acc + (∑ 2^sh)·Yv < 2^W = Acc + (2ⁿ−1)·Yv < 2^W, with no if: because X is a quantum register,
a sound circuit must not overflow on any branch of a superposition, so the design-time bound must hold
for the maximal X. (For squaring, the copy gadget X := Y is a precondition supplied by the caller as
regValRange X s n = regValRange Y s n; the copy CNOT fan-out is not built here.)
Non-vacuity witness #
A concrete 1-bit quantum×quantum multiplier layout on Fin 8: accumulator 0, control register X
on 1, multiplicand Y on 2, carry banks {3,4} (shift 0) / {5,6} (shift 1), shared ancilla
7 — exhibiting that CMulLayout is inhabited and cMulCircuit_eq_mul applies.
A concrete 1-bit (n = W = 1) quantum×quantum multiplier layout on Fin 8.
Equations
- One or more equations did not get rendered due to their size.