# Gates, observables, and the Bloch sphere {#gates}

**Learning goals.** Multiply gate matrices, distinguish active transformations from coordinates, derive Bloch coordinates, and understand rotations and noncommuting operations.

## Matrices act on vectors

A matrix is determined by what it does to basis vectors. Its first column is the output for $|0\rangle$; its second is the output for $|1\rangle$. Linearity then fixes the output for every superposition:

$$U(\alpha|0\rangle+\beta|1\rangle)=\alpha U|0\rangle+\beta U|1\rangle.$$

For $U=\begin{pmatrix}a&b\\c&d\end{pmatrix}$ the result is
$(a\alpha+b\beta)|0\rangle+(c\alpha+d\beta)|1\rangle$.
Every row forms one output amplitude. A valid closed-system gate preserves all inner products, so it satisfies $U^\dagger U=I$. Such a matrix is **unitary**, with inverse $U^\dagger$.

The Pauli gates and Hadamard are

$$X=\begin{pmatrix}0&1\\1&0\end{pmatrix},\quad
Y=\begin{pmatrix}0&-i\\i&0\end{pmatrix},\quad
Z=\begin{pmatrix}1&0\\0&-1\end{pmatrix},$$
$$H=\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}.$$

X swaps the amplitudes, Z changes their relative sign, and Y combines a swap with phases. H maps $|0\rangle$ to $|+\rangle$ and $|1\rangle$ to $|-\rangle$. These matrices are Hermitian as well as unitary; not every gate is Hermitian.

The phase gates are

$$S=\begin{pmatrix}1&0\\0&i\end{pmatrix},\qquad
T=\begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix},\qquad S=T^2.$$

S has inverse $S^\dagger=\operatorname{diag}(1,-i)$, not S itself.

## Gate order is matrix order in reverse time

If U acts first and V second, the output is $VU|\psi\rangle$. The rightmost matrix acts first. A circuit is conventionally read left to right, which is why translating circuits into matrix products requires care.

**Worked example.** Apply H to $\alpha|0\rangle+\beta|1\rangle$:

$$H|\psi\rangle=\frac{(\alpha+\beta)|0\rangle+(\alpha-\beta)|1\rangle}{\sqrt2}.$$

Applying H again gives

$$H^2|\psi\rangle
=\frac{(\alpha+\beta+\alpha-\beta)|0\rangle
+(\alpha+\beta-\alpha+\beta)|1\rangle}{2}
=\alpha|0\rangle+\beta|1\rangle.$$

The cancellations show $H^2=I$. They also explain interference: the first H creates alternatives, and the second recombines them.

By contrast, $XZ=-ZX$. For instance, $XZ|0\rangle=|1\rangle$ but $ZX|0\rangle=-|1\rangle$. The minus sign is a global phase when these are complete single-qubit operations. In controlled versions, a phase confined to one control branch becomes relative and can matter. Never discard a phase before checking its role in a larger circuit.

## Implementing a measurement basis

To measure X with a Z detector, apply H first, because
$\langle0|H=\langle+|$ and $\langle1|H=\langle-|$.
To measure Y, apply $S^\dagger$ and then H, so the total matrix is $HS^\dagger$:

$$\langle0|HS^\dagger
=\frac{\langle0|-i\langle1|}{\sqrt2}=\langle+i|.$$

Using SH instead produces a different operation. Writing the bra of the actual measurement is an effective way to verify a basis-rotation circuit.

## Bloch coordinates from amplitudes

Remove a global phase so the first nonzero coefficient is real. Every pure qubit can then be written

$$|\psi\rangle=\cos\frac\theta2|0\rangle+
e^{i\phi}\sin\frac\theta2|1\rangle,\quad 0\le\theta\le\pi.$$

Define $x=\langle X\rangle$, $y=\langle Y\rangle$, and $z=\langle Z\rangle$. Matrix multiplication gives

$$x=\alpha^*\beta+\beta^*\alpha=2\operatorname{Re}(\alpha^*\beta),$$
$$y=-i\alpha^*\beta+i\beta^*\alpha=2\operatorname{Im}(\alpha^*\beta),$$
$$z=|\alpha|^2-|\beta|^2.$$

Substituting the angular form yields

$$(x,y,z)=(\sin\theta\cos\phi,\sin\theta\sin\phi,\cos\theta).$$

Its length is one. The north and south poles are $|0\rangle,|1\rangle$; the positive x and y directions are $|+\rangle,|+i\rangle$. The sphere represents pure qubit states modulo global phase, not the physical path or shape of a particle.

For $(2|0\rangle+3i|1\rangle)/\sqrt{13}$,

$$(x,y,z)=(0,12/13,-5/13),\quad
x^2+y^2+z^2=(144+25)/169=1.$$

Thus equal X probabilities do not place the state at the sphere's center. They only imply its x coordinate is zero.

![Bloch coordinates and the three measurement axes.](figures/bloch.svg)

## Rotations and generators

For a unit vector $\boldsymbol n$, let
$A=n_xX+n_yY+n_zZ$. Since $A^2=I$, the exponential series separates into even and odd powers:

$$e^{-i\theta A/2}
=I\cos(\theta/2)-iA\sin(\theta/2).$$

This is $R_{\boldsymbol n}(\theta)$, rotating the Bloch vector by angle $\theta$ about $\boldsymbol n$. For example,

$$R_y(\theta)=
\begin{pmatrix}\cos(\theta/2)&-\sin(\theta/2)\\
\sin(\theta/2)&\cos(\theta/2)\end{pmatrix},$$
$$R_z(\theta)=\operatorname{diag}(e^{-i\theta/2},e^{i\theta/2}).$$

The half-angle is necessary: a $2\pi$ rotation gives $-I$, physically the same pure state but a different vector representative. H corresponds to a half-turn about $(x+z)/\sqrt2$, up to global phase; it is not simply a quarter-turn about y.

## Observables and uncertainty

An observable is Hermitian: $A^\dagger=A$. Its eigenvalues are real, and its orthonormal eigenvectors specify a projective measurement. A gate is unitary. Some matrices, including the Paulis, serve both roles, but “apply Z” and “measure Z” are different physical instructions.

The commutator is $[A,B]=AB-BA$. Since $[X,Y]=2iZ$, the uncertainty relation gives
$\Delta X\Delta Y\ge|\langle Z\rangle|$.
In $|0\rangle$, both X and Y outcomes are random, so $\Delta X=\Delta Y=1$, saturating the bound. This is a statement about measurement distributions across identically prepared copies.

::: {.lab #lab-bloch}
**Laboratory L05 — Bloch sphere and gates.** Adjust $\theta,\phi$, rotate the view, and apply H, X, Y, Z, S, or a rotation. Read all three expectations and basis probabilities. Check the recurring example's coordinates.
:::

## Exercises

:::: {.exercise #ex04-1}
**4.1.** Verify $HZH=X$ using the matrix columns or its action on both basis states.

::: {.solution}

$H|0\rangle=|+\rangle$, $Z|+\rangle=|-\rangle$, $H|-\rangle=|1\rangle$. The other input maps to $|0\rangle$. These outputs are exactly X's columns.
:::

::::

:::: {.exercise #ex04-2}
**4.2.** Calculate Z probabilities after $HSH|0\rangle$.

::: {.solution}

The intermediate state is $(|0\rangle+i|1\rangle)/\sqrt2$. The final amplitudes are $(1+i)/2,(1-i)/2$. Each has squared modulus $2/4=1/2$.
:::

::::

:::: {.exercise #ex04-3}
**4.3.** Find the Bloch coordinates of $(|0\rangle+e^{i\pi/3}|1\rangle)/\sqrt2$.

::: {.solution}

$\theta=\pi/2,\phi=\pi/3$, so $(x,y,z)=(1/2,\sqrt3/2,0)$.
:::

::::

:::: {.exercise #ex04-4}
**4.4.** Derive Z probabilities after $R_y(\theta)|0\rangle$ and verify normalization.

::: {.solution}

The state is $\cos(\theta/2)|0\rangle+\sin(\theta/2)|1\rangle$. The probabilities are $\cos^2(\theta/2),\sin^2(\theta/2)$ and sum to one.
:::

::::

:::: {.exercise #ex04-5}
**4.5.** Why can a unitary not reset both $|0\rangle$ and $|1\rangle$ to $|0\rangle$?

::: {.solution}

The input overlap is zero; the proposed output overlap is one. Reset is possible as an open-system process that exports information, not as a unitary on the qubit alone.
:::

::::

