# Finding the rotation angle $\theta$ of a 2x2 unitary matrix

We can represent a 2x2 unitary matrix as follows: $$U = \cos(\theta)I - i \sin(\theta) \vec{n} \cdot \vec{\sigma},$$ where $$\vec{n} \in \mathbb{R}^3$$ and $$\vec{\sigma} = (\sigma_x, \sigma_y, \sigma_z)$$. This can be viewed as a rotation around the axis $$\vec{n}$$ on a Block sphere by angle $$\theta$$.

Given a numerical representation of $$U$$ $$U = \begin{pmatrix} a & b\\ c & d \end{pmatrix}$$ what is the easiest way to extract the angle $$\theta$$?

• theta=arccos(a) Jun 27, 2023 at 17:38

If you can actually guarantee $$U = \cos\theta I - i \sin \theta\vec{n}\cdot \vec{\sigma}$$, then we can see that $$\text{Re}[a] = \text{Re}[d] = \cos \theta$$ and so $$\theta = \arccos \left( \text{Re}[a] \right). \tag{1}$$

For completeness, we should consider when there might be an unknown global phase (e.g. Nielsen and Chuang exercise 4.8). In this case, we are instead interested in the unitary $$U = \exp(i\alpha) \left(\cos\theta I - i \sin \theta\vec{n}\cdot \vec{\sigma}\right). \tag{2}$$ We equate the two expressions for $$U$$ for the diagonal elements, \begin{align} a &= (\cos \alpha + i \sin \alpha)(\cos \theta - i \sin\theta n_z) \tag{3} \\ d &= (\cos \alpha + i \sin \alpha)(\cos \theta + i \sin \theta n_z) \tag{4} \end{align} Then, \begin{align} \text{Re}[a + d] &= 2 \cos \alpha \cos \theta \tag{5} \\ \text{Im}[a + d] &= 2 \sin \alpha \cos \theta \tag{6}\\ \end{align} So first solve for $$$$\alpha = \arctan \left(\frac{\text{Im}[a + d]}{\text{Re}[a + d]} \right), \tag{7}$$$$ and then plug this into Eq. (5) to find $$$$\theta = \arccos \left( \frac{\text{Re}[a + d]}{2 \cos \alpha}\right). \tag{8}$$$$ You might have to be careful because of the periodicity of $$\tan \alpha$$ that gets lost in Eq. (7).

Taking trace of a unitary $$U{=}\cos(\theta)\mathbb{I}-i\sin(\theta)\vec{n}.\vec{\sigma}$$ leads to $$Tr(U){=}2\cos(\theta)$$, from which you can calculate $$\theta{=}\cos ^{-1}\frac{Tr(U)}{2}$$. In general, your numerical matrix can lead to a global phase which you can eliminate by taking the absolute of the trace, i.e. your solution for $$\theta{=}\cos ^{-1}\frac{|Tr(U)|}{2}$$, in terms of your matrix element, this becomes $$\theta{=}\cos ^{-1}\frac{|a+d|}{2}$$.

I have code to compute the angle and axes here:

def u_to_bloch(u):
"""Compute angle and axis for a unitary."""

angle = np.real(np.arccos((u[0, 0] + u[1, 1]) / 2))
sin = np.sin(angle)
if sin < 1e-10:
axis = [0, 0, 1]
else:
nx = (u[0, 1] + u[1, 0]) / (2j * sin)
ny = (u[0, 1] - u[1, 0]) / (2 * sin)
nz = (u[0, 0] - u[1, 1]) / (2j * sin)
axis = [nx, ny, nz]
return axis, 2 * angle