A test bench measures the eigenphase of a gate U with the Hadamard test. The target register holds an eigenvector |u\rangle of U, with U|u\rangle = e^{2\pi i\varphi}|u\rangle and \varphi in [0, 1). One extra qubit, the control, starts in |0\rangle. The bench applies H to the control, then controlled-U (the control decides whether U acts on the target), then H to the control again, and measures the control. Working through the circuit gives the probability of reading 0:
After many runs the bench knows p_0, and you must say which eigenphases are possible.
Write hadamard_phases(p0) that returns every \varphi in [0, 1) with (1 + \cos 2\pi\varphi)/2 = p_0, as a list in increasing order. When there is only one such \varphi, the list has one entry.
Examples
Input: p0 = 0.5
Output: [0.25, 0.75]
Explanation: cos(2 pi * 0.25) = cos(2 pi * 0.75) = 0.
Input: p0 = 0.75
Output: [0.16666666666666666, 0.8333333333333334]
Input: p0 = 1
Output: [0.0]
Explanation: only phi = 0 gives cos = 1; phi = 1 is outside [0, 1).
Answers are compared with a tolerance of 1e-6.
Goals
- Invert the Hadamard test's probability $(1 + \cos 2\pi\varphi)/2$ to candidate eigenphases
- See why one probability cannot tell $\varphi$ from $1 - \varphi$