clifford_t_gate_matrix
def
The matrix of a Clifford+T gate in the computational basis indexed by bit strings x : Fin N -> Bool: H on qubit i has entry (-1)^{x_i y_i}/sqrt 2 when x and y agree off i and 0 otherwise; S and T are diagonal with phase i, resp. e^{i pi/4}, when qubit i is 1; CNOT(c, t) is the permutation matrix of y -> y with bit t flipped by bit c.
Statement
noncomputable def clifford_t_gate_matrix {N : ℕ} : CliffordTGate N → Matrix (Fin N → Bool) (Fin N → Bool) ℂ
- Defined in
- Exact T-counts of Toffoli Layers from an Isotropy Bound, arXiv:2610.01024, Sec. A.3 (gate matrices of Clifford+T circuits)
- Verified
- 06 Oct 2026
- Axioms
- none listed
- Built on 1
- CliffordTGateA gate of a Clifford+T circuit on N qubits: a Hadamard H on qubit i, a phase gate S on qubit i, a CNOT with control c and target t (c…
- Used by 2
- clifford_t_gate_matrix_t_sqSanity check: T^2 = S on every qubit.
- clifford_t_circuit_matrixThe unitary of a Clifford+T circuit given as a list of gates, the first gate of the list acting first: g_k ... g_2 g_1.
Lean source view module on GitHub
/-- The matrix of a Clifford+T gate in the computational basis Fin N -> Bool. -/ noncomputable def clifford_t_gate_matrix {N : ℕ} : CliffordTGate N → Matrix (Fin N → Bool) (Fin N → Bool) ℂ := fun | .h i => fun x y => if ∀ j, j ≠ i → x j = y j then (if x i && y i then -1 else 1) / (Real.sqrt 2 : ℂ) else 0 | .s i => Matrix.diagonal fun x => if x i then Complex.I else 1 | .cnot c t _ => fun x y => if x = Function.update y t (xor (y t) (y c)) then 1 else 0 | .t i => Matrix.diagonal fun x => if x i then Complex.exp (Real.pi / 4 * Complex.I) else 1