A one-qubit state is a pair [a, b] of complex numbers, meaning a|0\rangle + b|1\rangle, with |a|^2 + |b|^2 = 1. Up to a global phase (one unit complex number multiplying both amplitudes, which changes nothing measurable) it can always be written as
with 0 \le \theta \le \pi: here \cos\frac\theta2 = |a|, \sin\frac\theta2 = |b|, and \varphi is the angle of b minus the angle of a (cmath.phase(b) - cmath.phase(a)). The Bloch point of the state is the point on the unit sphere
|0\rangle sits at the north pole (0, 0, 1), |1\rangle at the south pole (0, 0, -1), and every state with equal odds of 0 and 1 on the equator. A chip's dashboard draws each qubit this way.
Write bloch_point(state) that returns the tuple (x, y, z). Press Run with plot([p[0] for p in pts], [p[1] for p in pts], kind="scatter") for a list pts of points to see them from above.
Examples
Input: state = [1, 0]
Output: (0.0, 0.0, 1.0)
Input: state = [0.7071067811865476, 0.7071067811865476j]
Output: (0.0, 1.0, 0.0)
Explanation: theta = pi / 2 and phi = pi / 2: on the equator, a quarter turn round.
Input: state = [0.6, -0.8]
Output: (-0.96, 0.0, -0.28)
Explanation: cos(theta / 2) = 0.6 and sin(theta / 2) = 0.8, so cos(theta) = 0.36 - 0.64
and sin(theta) = 2 * 0.6 * 0.8 = 0.96; phi = pi.
Constraints
- answers are compared with a tolerance of
1e-6; values like6e-17for 0 count as correct
Goals
- Place a qubit state as a point (x, y, z) on the unit sphere
- See that a global phase does not move the point
- Read the north and south poles as |0> and |1>, and the equator as equal odds