A two-level unitary on qubits is a Gray-code sandwich of multiply-controlled gates #
Category: 1-Mathlib (CSD-free; staged for upstream). BACKLOG #71, part (d) of R-005
(specs/magic-plan.md, "The split").
On the computational basis Fin m → Fin 2 of m qubits, a multiply-controlled gate
ctrlGate j pat a b c d acts by the 2 × 2 block !![a, b; c, d] on qubit j of those basis
labels that agree with pat away from j, and as the identity on every other label. The bridge to
the two-level matrices of TwoLevel.lean is exact: ★ ctrlGate_eq_twoLevelMat identifies it with
the two-level matrix on the adjacent pair pat[j ↦ 0], pat[j ↦ 1]. So a multiply-controlled X
(ctrlGate j pat 0 1 1 0) is the transposition of two labels differing in one bit.
Nielsen–Chuang §4.5.2: a two-level unitary on labels u ≠ v becomes a multiply-controlled gate
once u is walked to a neighbour of v along a Gray code, each step being a multiply-controlled
X. Here the Gray code is the recursion itself: flip one differing bit, conjugate, and the
differing set shrinks by one.
swapMat u v— the transposition of two labels;swapMat_apply(its entries are the permutation's),swapMat_mul_self,swapMat_mem_unitaryGroup;- ★
swapMat_conj_apply— conjugating by a transposition relabels:(S V S) k l = V (swap u v k) (swap u v l), hence ★idOutside_swapMat_conj; Adjacent u v,diffSet,adjacent_iff_diffSet_card_eq_one;ctrlGate, ★ctrlGate_eq_twoLevelMat,ctrlGate_mem_unitaryGroup, ★exists_ctrlGate_of_adjacent— a two-level matrix on an adjacent pair is a multiply-controlled gate;IsMultiCtrlX,IsMultiCtrlGate;- ★★
exists_multiCtrl_sandwich— every two-level unitary on qubits isL · W · L⁻¹withLa list of multiply-controlledXs andWa single multiply-controlled gate; ★exists_multiCtrl_list— the same as one flat product, the form #72 consumes.
Honest scope #
⚠️ Existence and structure, no gate counts: the Gray walk here flips the differing bits in the
order the recursion picks them, and L.length is the Hamming distance minus one, but no optimality
or circuit-size claim is made (the two-level count of #70 is #82, landed 2026-09-28 as
exists_twoLevel_prod_length, and says nothing about this file's Gray walk; efficiency overall is
#74, kept not claimed). Decomposing a multiply-controlled gate into CNOTs and single-qubit gates is #72.
References: M. A. Nielsen, I. L. Chuang, Quantum Computation and Quantum Information §4.5.2;
specs/magic-plan.md; specs/BACKLOG.md #71; specs/future-work.md.
Transpositions of basis labels #
The transposition of two basis labels, as a matrix.
Equations
- QuantumInfo.MultiControlled.swapMat u v = QuantumInfo.TwoLevel.twoLevelMat u v 0 1 1 0
Instances For
Adjacent labels #
Multiply-controlled gates #
The multiply-controlled gate: the 2 × 2 block !![a, b; c, d] applied to qubit j of
the basis labels agreeing with pat away from j, the identity on all other labels.
Equations
- One or more equations did not get rendered due to their size.
Instances For
★ A multiply-controlled gate is the two-level matrix on the adjacent pair it acts on.
A multiply-controlled X: the transposition of two labels differing in one qubit.
Equations
- QuantumInfo.MultiControlled.IsMultiCtrlX X = ∃ (j : Fin m) (pat : Fin m → Fin 2), X = QuantumInfo.MultiControlled.ctrlGate j pat 0 1 1 0
Instances For
For adjacent labels the pair is the multiply-controlled gate's pair, in one of two orders.
★ A two-level matrix on an adjacent pair is a multiply-controlled gate.
★ The transposition of two adjacent labels is a multiply-controlled X.
The Gray-code decomposition #
★★ Every two-level matrix on qubits is a Gray-code sandwich: a list of
multiply-controlled Xs, one multiply-controlled single-qubit gate, and the list again (each
factor being its own inverse). If the matrix is unitary so is the gate.
★ The flat form: a two-level matrix on qubits is a product of multiply-controlled gates — the shape BACKLOG #72 consumes.