|q⟩ Bad Qubits

beginner · Programming · Single-Qubit Gates II: H, S, T & Phase

S, T and Their Inverses

Two single-qubit gates you will meet often are the S gate and the T gate. Both act only on the 1|1\rangle component of a state, leaving 0|0\rangle unchanged — they are called phase gates because they shift the relative phase between the two basis amplitudes.

The S gate and its inverse

The SS gate (also written P(π/2)P(\pi/2)) applies a phase of i=eiπ/2i = e^{i\pi/2} to 1|1\rangle:

S=(100i).S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}.

Its action on basis states is straightforward:

S0=0,S1=i1.S|0\rangle = |0\rangle, \qquad S|1\rangle = i\,|1\rangle.

On a superposition α0+β1\alpha|0\rangle + \beta|1\rangle, the effect is to rotate β\beta by 90°90° in the complex plane: S(α0+β1)=α0+iβ1S(\alpha|0\rangle + \beta|1\rangle) = \alpha|0\rangle + i\beta|1\rangle.

The inverse SS^\dagger (or S1S^{-1}) undoes that rotation by applying i=eiπ/2-i = e^{-i\pi/2}:

S=(100i).S^\dagger = \begin{pmatrix} 1 & 0 \\ 0 & -i \end{pmatrix}.

You can verify that SS=IS^\dagger S = I by multiplying the two matrices:

(100i)(100i)=(1001)=I.\begin{pmatrix} 1 & 0 \\ 0 & -i \end{pmatrix}\begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I.

The T gate and its inverse

The TT gate applies half the phase of SS — a 45°45° rotation, eiπ/4e^{i\pi/4}:

T=(100eiπ/4).T = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}.

This means S=T2S = T^2: two TT gates compose to one SS gate. Similarly, TT^\dagger applies the conjugate phase eiπ/4e^{-i\pi/4}:

T=(100eiπ/4),TT=I.T^\dagger = \begin{pmatrix} 1 & 0 \\ 0 & e^{-i\pi/4} \end{pmatrix}, \qquad T^\dagger T = I.

Why inverses matter

Every quantum gate is unitary — its inverse is just its conjugate transpose (Hermitian adjoint), often written UU^\dagger. Because of this, quantum operations are always reversible: you can run any circuit backward by applying each gate's adjoint in reverse order. For phase gates the inverse is simply the gate with the negated phase angle. Applying SS followed immediately by SS^\dagger is therefore the identity transformation, and the qubit is left exactly as it started.

Try it

Apply SS to qubit 0, then undo it with SS^\dagger. The grader checks the whole unitary matrix of your circuit, so doing nothing will not pass — you must actually apply both gates, and they must cancel to the identity.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.