clifford_t_gate_matrix_t_sq
Sanity check: T^2 = S on every qubit.
Statement
theorem clifford_t_gate_matrix_t_sq {N : ℕ} (i : Fin N) : clifford_t_gate_matrix (.t i) * clifford_t_gate_matrix (.t i) = clifford_t_gate_matrix (.s i)- Source
- Stated here; not taken from a source
- Verified
- 06 Oct 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 1
- clifford_t_gate_matrixThe 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…
The proof, explained
To show that T² = S on qubit i, the proof unrolls the definitions of both gates as diagonal matrices. The matrix product of two diagonal matrices is diagonal with pointwise multiplied entries. For any computational basis state x, the diagonal entry is (exp(iπ/4))² = exp(iπ/2) = i when the i-th qubit is true, and 1 * 1 = 1 when it is false; in both cases, this matches the diagonal entry of the S gate.
The equality of the gate matrices reduces to checking that for every basis state x, the product of the corresponding diagonal entries of T equals the diagonal entry of S.
Unfolding the definition of clifford_t_gate_matrix, both the T gate and the S gate on qubit i are diagonal matrices. By Matrix.diagonal_mul_diagonal, the product of two diagonal matrices is the diagonal matrix of their pointwise product. Applying congr 1 and function extensionality (ext x) reduces the matrix equation to checking that the diagonal entries agree on every computational basis state x : Fin N → Bool.
uses
Matrix.diagonal_mul_diagonaldsimp [clifford_t_gate_matrix] rw [Matrix.diagonal_mul_diagonal] congr 1 ext x
When the i-th qubit is true (x(i) = true), the diagonal entry (exp(iπ/4))² evaluates to i.
Splitting on the condition x(i) = true via split_ifs, in the positive case both factors on the diagonal are exp(iπ/4). Applying Complex.exp_add in reverse combines the product into exp(iπ/4 + iπ/4). Since iπ/4 + iπ/4 = iπ/2 by ring arithmetic, rewriting with Complex.exp_pi_div_two_mul_I evaluates exp(iπ/2) to i, which matches the diagonal entry of S.
uses
Complex.exp_add,Complex.exp_pi_div_two_mul_Isplit_ifs with h · rw [← Complex.exp_add] have h1 : (Real.pi / 4 * Complex.I : ℂ) + Real.pi / 4 * Complex.I = Real.pi / 2 * Complex.I := by ring rw [h1, Complex.exp_pi_div_two_mul_I]
When the i-th qubit is false (x(i) ≠ true), the diagonal entry 1 * 1 evaluates to 1.
In the negative branch where x(i) ≠ true, the diagonal entries of both factors are 1. Ring arithmetic closes the goal 1 * 1 = 1, matching the diagonal entry of S.
· ring
Matrix.diagonal_mul_diagonal- The product of two diagonal matrices is the diagonal matrix whose entries are the pointwise products of the diagonal entries.
Complex.exp_add- The exponential of a sum of complex numbers is the product of their exponentials: exp(x + y) = exp(x) * exp(y).
Complex.exp_pi_div_two_mul_I- The exponential of iπ/2 equals the imaginary unit i: exp(iπ/2) = i.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
theorem clifford_t_gate_matrix_t_sq {N : ℕ} (i : Fin N) : clifford_t_gate_matrix (.t i) * clifford_t_gate_matrix (.t i) = clifford_t_gate_matrix (.s i) := by dsimp [clifford_t_gate_matrix] rw [Matrix.diagonal_mul_diagonal] congr 1 ext x split_ifs with h · rw [← Complex.exp_add] have h1 : (Real.pi / 4 * Complex.I : ℂ) + Real.pi / 4 * Complex.I = Real.pi / 2 * Complex.I := by ring rw [h1, Complex.exp_pi_div_two_mul_I] · ring