Hybrid circuits: reversible gates and measure-and-correct gadgets on the full register #
Category: 1-Mathlib (CSD-free; staged as a Mathlib-upstream candidate).
Lift.lean embeds one CCX into QReg m as a permutation matrix and notes that a mid-circuit
measurement gadget is not a permutation, so the basis-state induction that lifts a
permutation circuit "breaks at the replaced block". This module closes that gap without the
tensor factorisation the note anticipated: the gadget, per outcome, is a monomial operator —
it sends every computational basis state to a scalar multiple of a basis state — so the
induction goes through with a scalar carried along.
gateMat g— the general lift of a reversible gate: the permutation matrix of its Boolean actiondenoteGate g, recast throughstateOfReg/regOfState;gateMat_basisStateis the basis-state rule, andgateMat_CCXchecks it against the hand-built CCX unitaryccxAtMat.measureCorrectMat pairs g mo— the measure-and-correct gadget on the ancillag, per outcomemo: Hadamard ong, projection ofgontomo, then a CZ on each pair ofpairswhenmo = 1. On a basis state it is(phase · ⟨mo|H|w g⟩) • |update w g mo⟩(measureCorrectMat_basisState); when the ancilla holds the parity of ANDs the corrections cancel,w g = andParity pairs w, the scalar is(√2)⁻¹for both outcomes (measureCorrect_scalar) — the genuine phase cancellation((−1)^{p})² = 1; when it does not, themo = 1branch carries the sign−(√2)⁻¹(measureCorrect_scalar_of_ne) — the reason a gadget must be matched to what its ancilla holds.HybridGate,hybridLin,shadow,WellFormed,gadgetCount— a hybrid gate list, its register semantics (a linear map, first gate first), its Boolean shadow (a reversible gate acts bydenoteGate, a gadget writes its outcome into the ancilla), and the well-formedness of a run on a basis input (every gadget meets an ancilla holding the parity its corrections cancel, on wires its corrections avoid).- ★
hybridLin_basisState— the hybrid amplitude equality: on a well-formed basis input the hybrid circuit produces(√2)⁻¹^{#gadgets} • |shadow⟩;hybridLin_sumextends it by linearity to superpositions of well-formed inputs.
The consumer is the AND-adder with its Toffoli-free uncompute pass
(Empirical/QM/MeasurementAdderHybrid.lean), where the gadgets are matched to the majority
ancillas of the carry cells.
Honest scope #
The gadget is represented per outcome (a partial isometry), as in the measurement-gadget
modules it generalises; the two outcomes have probability 1/2 each, which the scalar
(√2)⁻¹ records. Nothing here is about noise or about gate decompositions: gateMat is the
permutation a reversible gate is on the computational basis, and a hybrid list is costed by
its consumers.
The recasts round-trip #
The general lift of a reversible gate #
The permutation matrix of a reversible gate on QReg m: the basis state w goes to the
basis state of the gate's Boolean action on w.
Equations
- Reversible.gateMat g = Matrix.of fun (z w : Fin m → Fin 2) => if z = Reversible.regOfState (Reversible.denoteGate g (Reversible.stateOfReg w)) then 1 else 0
Instances For
The lifted gate permutes basis states by the gate's Boolean action.
The measure-and-correct gadget at arbitrary wires #
The correction phase at outcome mo: (−1)^{mo · ⊕ ANDs} — a CZ on each pair when
mo = 1, nothing when mo = 0.
Equations
- Reversible.correctionPhase pairs mo w = (-1) ^ (↑mo * ↑(Reversible.andParity pairs w))
Instances For
The measure-and-correct gadget on the ancilla wire g of QReg m, per outcome mo:
Hadamard on g, projection of g onto mo, then a CZ on each pair of pairs if mo = 1.
Entry (z, w): nonzero only for z = update w g mo, where it is the correction phase at z
times the Hadamard entry ⟨mo|H|w g⟩.
Equations
- Reversible.measureCorrectMat pairs g mo = Matrix.of fun (z w : Fin m → Fin 2) => if z = Function.update w g mo then Reversible.correctionPhase pairs mo z * QuantumInfo.hadEntry mo (w g) else 0
Instances For
The gadget is monomial: a basis state goes to a scalar multiple of a basis state.
The gadget scalar on a well-formed input. If the ancilla holds the parity its
corrections cancel, the scalar is (√2)⁻¹ for both outcomes: the projection phase
(−1)^{mo · w g} and the correction phase (−1)^{mo · parity} cancel.
The sign flip on an ill-formed input. If the ancilla does not hold the parity the
corrections cancel, the mo = 1 branch carries −(√2)⁻¹: a data-dependent relative phase.
Hybrid gate lists #
A hybrid gate: a reversible gate, or a measure-and-correct gadget with its outcome.
- gate
{m : ℕ}
(g : Gate m)
: HybridGate m
A reversible gate, lifted as a permutation.
- measure
{m : ℕ}
(pairs : List (Fin m × Fin m))
(g : Fin m)
(mo : Fin 2)
: HybridGate m
The measure-and-correct gadget on ancilla
gwith correctionspairs, at outcomemo.
Instances For
The register operator of a hybrid gate.
Equations
- (Reversible.HybridGate.gate g).mat = Reversible.gateMat g
- (Reversible.HybridGate.measure pairs g mo).mat = Reversible.measureCorrectMat pairs g mo
Instances For
The Boolean shadow of a hybrid gate on register indices: a reversible gate acts by its
denoteGate, a gadget writes its outcome into the ancilla.
Equations
- (Reversible.HybridGate.gate g).shadow x✝ = Reversible.regOfState (Reversible.denoteGate g (Reversible.stateOfReg x✝))
- (Reversible.HybridGate.measure pairs g mo).shadow x✝ = Function.update x✝ g mo
Instances For
The register semantics of a hybrid gate list, first gate first.
Equations
Instances For
The Boolean reading of a reversible gate's shadow is its denoteGate.
A reversible gate's shadow preserves every wire it does not target.
The Boolean shadow of a hybrid gate list.
Equations
- Reversible.shadow l w = List.foldl (fun (w : Fin m → Fin 2) (h : Reversible.HybridGate m) => h.shadow w) w l
Instances For
The number of gadgets in a hybrid gate list.
Equations
- Reversible.gadgetCount [] = 0
- Reversible.gadgetCount (Reversible.HybridGate.gate g :: rest) = Reversible.gadgetCount rest
- Reversible.gadgetCount (Reversible.HybridGate.measure pairs g mo :: rest) = Reversible.gadgetCount rest + 1
Instances For
Well-formed run on a basis input: every gadget meets an ancilla holding the parity its corrections cancel, on wires its corrections avoid.
Equations
- One or more equations did not get rendered due to their size.
- Reversible.WellFormed [] x✝ = True
- Reversible.WellFormed (Reversible.HybridGate.gate g :: rest) x✝ = Reversible.WellFormed rest (Reversible.regOfState (Reversible.denoteGate g (Reversible.stateOfReg x✝)))
Instances For
★ The hybrid amplitude equality #
★ The hybrid amplitude equality on a well-formed basis input. The hybrid circuit sends
the basis state w to (√2)⁻¹^{#gadgets} • |shadow⟩: each reversible gate permutes the basis
state, each gadget resets its ancilla to the outcome and contributes the scalar (√2)⁻¹.
The hybrid amplitude equality on a superposition of well-formed basis inputs.
Reversible prefixes #
The shadow of a reversible gate list is its Boolean semantics, recast.
A reversible prefix only moves the basis input; well-formedness is decided after it.