Lesson 1 of 15

S and T Phase Gates

S and T Phase Gates

The S gate (also called the phase gate or Z\sqrt{Z}) and T gate (S=Z4\sqrt{S} = \sqrt[4]{Z}) are fundamental single-qubit phase gates.

S Gate

The S gate applies a π2\frac{\pi}{2} phase to 1|1\rangle:

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

S0=0S1=i1S|0\rangle = |0\rangle \qquad S|1\rangle = i|1\rangle

T Gate

The T gate applies a π4\frac{\pi}{4} phase to 1|1\rangle:

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

T1=eiπ/41=1+i21T|1\rangle = e^{i\pi/4}|1\rangle = \frac{1+i}{\sqrt{2}}|1\rangle

Why These Gates Matter

Phase gates do not change measurement probabilities on their own — α2|\alpha|^2 and β2|\beta|^2 are unchanged. Their power lies in interference: applying S or T before a Hadamard creates a different superposition.

The T gate, combined with H and CNOT, forms a universal gate set for quantum computation.

The S² = Z Relationship

Applying S twice gives the Pauli-Z gate:

S2=(100i2)=(1001)=ZS^2 = \begin{pmatrix} 1 & 0 \\ 0 & i^2 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} = Z

Implementation

To apply S to a state [α,β][\alpha, \beta]:

S[α,β]=[α, iβ]S[\alpha, \beta] = [\alpha,\ i\beta]

To apply T to a state [α,β][\alpha, \beta]:

T[α,β]=[α, eiπ/4β]T[\alpha, \beta] = [\alpha,\ e^{i\pi/4}\beta]

import cmath, math

def s_gate(state):
    return [complex(state[0]), state[1] * 1j]

def t_gate(state):
    return [complex(state[0]), state[1] * cmath.exp(1j * math.pi / 4)]

Your Task

Implement s_gate(state) and t_gate(state) that apply the S and T gates to a 2-element complex state vector.

Python runtime loading...
Loading...
Click "Run" to execute your code.