A Point Inside the Ball

density matrix · Bloch vector · expectation value · Pauli matrices · trace

A pure qubit is a point on the surface of the Bloch sphere. A mixed qubit is a point inside it, and the density matrix tells you where.

For a one-qubit density matrix \rho (a 2 \times 2 list of rows), measuring in the computational basis gives outcome 0 with probability \rho_{00} and outcome 1 with probability \rho_{11}. More generally, the average value of a measurement described by a matrix P is

\langle P\rangle = \mathrm{Tr}(P\rho) = \sum_i \sum_j P_{ij}\,\rho_{ji},

where \mathrm{Tr} (the trace) is the sum of the diagonal. For example \langle Z\rangle = \rho_{00} - \rho_{11} with Z = \mathrm{diag}(1, -1). The Bloch vector of \rho is

(x, y, z) = \big(\mathrm{Tr}(X\rho),\ \mathrm{Tr}(Y\rho),\ \mathrm{Tr}(Z\rho)\big), \qquad X=\begin{pmatrix}0&1\\1&0\end{pmatrix},\ Y=\begin{pmatrix}0&-i\\i&0\end{pmatrix},\ Z=\begin{pmatrix}1&0\\0&-1\end{pmatrix}.

Its length \sqrt{x^2+y^2+z^2} is 1 for a pure state and less than 1 for a mixed one; the maximally mixed state I/2 sits at the centre.

Write bloch_vector(rho) that returns [x, y, z] as three real numbers.

Examples

Input:  rho = [[0.5, 0], [0, 0.5]]
Output: [0, 0, 0]

Input:  rho = [[0.52, 0.36], [0.36, 0.48]]
Output: [0.72, 0, 0.04]
Explanation: length sqrt(0.72**2 + 0.04**2) = 0.7211...: inside the ball.

Input:  rho = [[0.36, -0.48j], [0.48j, 0.64]]
Output: [0, 0.96, -0.28]
Explanation: the pure state [0.6, 0.8j]: length exactly 1.

Each number is compared with a tolerance of 1e-6.

Goals

  • Compute expectation values $\mathrm{Tr}(P\rho)$ of the Pauli matrices
  • Find the Bloch vector of a mixed qubit, which lies inside the unit ball
Starting Python…