Lesson 19 · 70 min · core
Hadamard, S and T Gates
The Hadamard gate exchanges the computational basis with the eigenbasis, squares to the identity, and conjugates and ; geometrically it is a rotation by about the axis , and . The phase gates and are rotations about by and up to global phase. Applied to every qubit, turns into the uniform superposition and into .
Prerequisites: Pauli Gates & the Pauli Algebra
Objectives and key results
Write , prove and from , and use to change between the and eigenbases.
Derive , and by explicit algebra with the Pauli product formula .
Identify as a rotation by about and verify entry by entry.
Prove , , and , and describe and as rotations about the axis.
Prove and compute every amplitude for .
- identity · Hadamard from Paulis
- identity · Hadamard conjugation
- formula · Hadamard as a rotation
- identity · Phase gates
- theorem · Walsh–Hadamard transform
The Hadamard gate#
Definition
Hadamard gate
The Hadamard gate is the single-qubit operator , i.e. and . In outer-product form .
Unitary verified: (max deviation 2.2e-16)
and
- Step 1:Add the two Pauli matrices entry by entry.
- Step 2:Compare with the definition of : the matrices agree entry by entry.
- Step 3:Row-by-column products; for instance and .
- Step 4:Adding the two products gives zero: and anticommute. Also , consistent with for , where .
- Step 5:Expand the product; matrix multiplication is distributive but not commutative, so and are kept separate.
- Step 6:Every Pauli matrix squares to the identity, , and from the previous step.
- Step 7:and are Hermitian, so is Hermitian (it is real and symmetric); together with this shows that is unitary and is its own inverse.
Result
Action on the and eigenbases
- Step 1:is the first column of .
- Step 2:is the second column of .
- Step 3:Substitute and use . Directly: .
- Step 4:A linear map is fixed by its action on a basis; the first form maps to the -th eigenvector, and the second is its adjoint, which equals because .
- Step 5:, and likewise . Hence measuring in the basis is the same as applying and then measuring in the computational basis.
Result
Quick check
Which state is ?
Conjugation identities#
Conjugation describes how a gate transforms an observable or another gate. Because , conjugation by the Hadamard is simply . The derivations below use only and the Pauli product formula , which gives the six products together with . The prefactor is always .
Hadamard conjugation of the Pauli matrices
, and . Consequently, for every real vector , .
Proof (11 steps)
- Step 1:Right-multiply by , then use and .
- Step 2:Expand, substitute and , and use , .
- Step 3:Combine the two previous lines with the prefactor .
- Step 4:Right-multiply by , then use and .
- Step 5:Expand and substitute the same two products; now and .
- Step 6:Combine with the prefactor .
- Step 7:Right-multiply by , then use and .
- Step 8:Expand, substitute , , ; the identity terms cancel and , .
- Step 9:Combine with the prefactor .
- Step 10:Independent check: (multiply by ), and inserting between and splits the conjugation into the two identities already proven.
- Step 11:Conjugation is linear, so apply the three identities term by term.
∎
Circuit · 1 qubit
The sandwich implements exactly : the unitary panel shows , and starting from the output is . The phase flip in the basis is a bit flip in the basis.
Circuit · 1 qubit
The sandwich implements , which differs from by the global phase and therefore acts on the Bloch sphere exactly like .
Comparing two circuits. The identity playground below draws two single-qubit circuits side by side, multiplies out their unitaries and , and reports with . By the Cauchy–Schwarz inequality for the Hilbert–Schmidt inner product, exactly when , and the playground then prints the verdict "equal" () or "equal up to global phase " together with . The circuits here are fixed; the menu offers five identities, written as matrix products whose right-most factor acts first: , , , and . Predict each verdict with the derivation below before selecting it.
What the playground reports for and
- Step 1:Right multiplication by swaps the two columns of .
- Step 2:Row by column: , , , .
- Step 3:The two unitaries coincide, so the verdict is "equal".
- Step 4:Entries , , and .
- Step 5:Row by column: , , , .
- Step 6:and . The verdict is "equal up to global phase ": both circuits move every Bloch vector in the same way, although the matrices differ. Such a sign becomes observable once the gate is controlled (Module 2.3).
Result
Then select the other three. is an exact equality, since (proved in the next section), and is exact by . For the left circuit applies , then , then , so its unitary is the product ; it equals the empty circuit only up to the global phase . Applying the same three gates in the time order , , gives instead, a reminder that the order of factors is reversed with respect to the wire.
Quick check
Which operator equals ?
The Hadamard as a rotation#
is a rotation by about
- Step 1:The unit vector bisecting the and axes.
- Step 2:Use from the first section.
- Step 3:The term is antisymmetric in while is symmetric, so it sums to zero.
- Step 4:Even powers of equal and odd powers equal ; the even terms sum to and the odd terms to .
- Step 5:Set : and .
- Step 6:Multiply by and use . The factor is a global phase, so on the Bloch sphere acts exactly as the rotation .
- Step 7:Rodrigues' rotation formula at angle , with and .
- Step 8:, so . This is exactly the map of the conjugation proposition: and .
Result
by matrix multiplication
- Step 1:The platform conventions for and .
- Step 2:.
- Step 3:Euler's formula: .
- Step 4:Row-by-column products, every entry written out.
- Step 5:Factor out of every entry: and .
- Step 6:Multiply both sides by ; on a circuit wire this is first and second.
Result
Circuit · 1 qubit
followed by . The unitary panel shows : the same gate as up to the unobservable global phase .
The phase gates S and T#
Definition
Phase gates S and T
The phase gate and the gate (also called the gate) leave unchanged and multiply the amplitude by and respectively. Their inverses are and .
Unitary verified: (max deviation 0.0e+0)
Unitary verified: (max deviation 2.2e-16)
The matrix display below recognises the entry and prints it symbolically as . Its property list shows what distinguishes from the Pauli and Hadamard gates: is unitary and normal but not Hermitian, because , so is a gate but not an observable. Its trace is , with modulus , and its determinant is . As for every diagonal matrix, the eigenvalues are the diagonal entries and , both on the unit circle.
, and
- Step 1:Diagonal matrices multiply entry by entry, and : both gates are unitary.
- Step 2:Square the diagonal entries; . So is a square root of .
- Step 3:. Hence is a square root of , and , .
- Step 4:Put in .
- Step 5:Multiply each diagonal entry by and add exponents: and . The off-diagonal entries stay .
- Step 6:The same computation with and : in general .
Result
and the Bloch picture of and
- Step 1:Row-by-column product; left multiplication by a diagonal matrix scales the rows.
- Step 2:Right multiplication by the diagonal scales the columns.
- Step 3:The same two steps for ( multiplies the second row of by ); is diagonal and commutes with , so .
- Step 4:Scale row of by and column by ; then by Euler's formula. Likewise .
- Step 5:Apply the conjugation to term by term: a rotation by about the axis. is the case (, ) and the case .
Result
Circuit · 1 qubit
The sandwich is half of the lab answer. Its unitary is , a rotation by about up to global phase: one is a quarter turn about , and the Hadamards move that axis to .
Quick check
Which gate equals up to a global phase?
Quick check
What is the smallest positive integer with ?
Hadamard on many qubits#
Walsh–Hadamard transform
For every and every bit string , with . In particular is the uniform superposition of all basis states.
Proof (6 steps)
- Step 1:Base case : for every sign is , giving ; for the sign is , giving .
- Step 2:Induction step: for , and .
- Step 3:Insert the induction hypothesis for qubits and the base case for the last qubit.
- Step 4:The tensor product is bilinear, so it distributes over both sums; the scalars multiply, , and the signs add in the exponent.
- Step 5:Rename ; then , which completes the induction.
- Step 6:For every product vanishes. The state is normalised: amplitudes each of squared modulus .
∎
Worked example:
- Step 1:Apply to each qubit separately.
- Step 2:Expand the tensor product; with qubit 0 as the most significant bit the amplitudes are listed in the order , each with probability .
- Step 3:Here , so : the sign is exactly when the second bit of is .
- Step 4:Here , so the sign is for and and for , where .
- Step 5:Column of the matrix is ; the four columns are the four expansions for (the column for is by the same rule).
Result
Circuit · 2 qubits
on both qubits of produces the uniform superposition with amplitudes ; the unitary panel shows the Walsh–Hadamard matrix .
Circuit · 2 qubits
Preparing with on qubit 1 and then applying gives : the signs follow with .
- |00⟩0.25
- |01⟩0.25
- |10⟩0.25
- |11⟩0.25
Quick check
What is the amplitude of in ? Give a decimal.
Numerical verification and lab#
The script below rebuilds every identity of this lesson from the simulator's gate matrices and checks it entry by entry to . It also evaluates the overlap that appears as a diagnostic in the lab: one in the sandwich is not enough.
import { HADAMARD, PAULI_X, PAULI_Y, PAULI_Z, S_GATE, SDG_GATE, T_GATE, cexpi, matrix, ryMatrix, rzMatrix } from '@/lib/quantum-simulator';
const tol = 1e-12;
const H = HADAMARD;
// Hadamard conjugation identities
console.log('HXH = Z :', matrix.approxEqual(matrix.mulAll(H, PAULI_X, H), PAULI_Z, tol));
console.log('HZH = X :', matrix.approxEqual(matrix.mulAll(H, PAULI_Z, H), PAULI_X, tol));
console.log('HYH = -Y :', matrix.approxEqual(matrix.mulAll(H, PAULI_Y, H), matrix.scale(PAULI_Y, -1), tol));
// Phase gates
console.log('S^2 = Z :', matrix.approxEqual(matrix.mul(S_GATE, S_GATE), PAULI_Z, tol));
console.log('T^2 = S :', matrix.approxEqual(matrix.mul(T_GATE, T_GATE), S_GATE, tol));
console.log('T = e^{i pi/8} RZ(pi/4) :', matrix.approxEqual(matrix.scale(rzMatrix(Math.PI / 4), cexpi(Math.PI / 8)), T_GATE, tol));
console.log('S X S^dag = Y :', matrix.approxEqual(matrix.mulAll(S_GATE, PAULI_X, SDG_GATE), PAULI_Y, tol));
// Euler factorisation H = i RY(pi/2) RZ(pi)
const ryrz = matrix.mul(ryMatrix(Math.PI / 2), rzMatrix(Math.PI));
console.log('H = i RY(pi/2) RZ(pi) :', matrix.approxEqual(matrix.scale(ryrz, cexpi(Math.PI / 2)), H, tol));
// Lab diagnostic: one S is only half of the answer
const hsh = matrix.mulAll(H, S_GATE, H);
const tr = matrix.trace(matrix.mul(matrix.adjoint(PAULI_X), hsh));
console.log('Tr(X^dag HSH) =', tr.re.toFixed(4), tr.im.toFixed(4));
console.log('|Tr(X^dag HSH)|^2 / 4 =', ((tr.re * tr.re + tr.im * tr.im) / 4).toFixed(4));Expected output
HXH = Z : true
HZH = X : true
HYH = -Y : true
S^2 = Z : true
T^2 = S : true
T = e^{i pi/8} RZ(pi/4) : true
S X S^dag = Y : true
H = i RY(pi/2) RZ(pi) : true
Tr(X^dag HSH) = 1.0000 -1.0000
|Tr(X^dag HSH)|^2 / 4 = 0.5000References
- M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary ed., Cambridge University Press (2010), §4.2 (single qubit operations).doi:10.1017/CBO9780511976667
- P. O. Boykin, T. Mor, M. Pulver, V. Roychowdhury and F. Vatan, A new universal and fault-tolerant quantum basis, Information Processing Letters 75, 101–107 (2000); arXiv:quant-ph/9906054 (1999).doi:10.1016/S0020-0190(00)00084-3
Hands-on labs
Build X from H and S
1 step · auto-gradedOpen labImplement the bit flip on one qubit, up to a global phase, using only the Hadamard gate and the phase gate , with at most four gates.