Measuring a qubit as 0 or 1 is only one question you can ask it. A one-qubit state is a pair [a, b], meaning a|0\rangle + b|1\rangle, with |a|^2 + |b|^2 = 1. Another question uses the two states
that is [1/sqrt(2), 1/sqrt(2)] and [1/sqrt(2), -1/sqrt(2)]. Measured this way (in the X basis), a state |\psi\rangle gives "+" with probability |\langle +|\psi\rangle|^2 and "−" with probability |\langle -|\psi\rangle|^2: the Born rule for any pair of perpendicular unit vectors. The inner product of two vectors is \langle u|v\rangle = \sum_k \overline{u_k}\, v_k, where \overline{u_k} is the complex conjugate u[k].conjugate().
The states [0.6, 0.8] and [0.6, -0.8] give the same odds of 0 and 1, but very different odds of + and −.
Write plus_minus_odds(state) that returns the pair (p_plus, p_minus).
Examples
Input: state = [0.6, 0.8]
Output: (0.98, 0.02)
Explanation: <+|psi> = (0.6 + 0.8) / sqrt(2), and 1.4 ** 2 / 2 = 0.98.
Input: state = [0.6, -0.8]
Output: (0.02, 0.98)
Input: state = [1, 0]
Output: (0.5, 0.5)
Explanation: |0> is certain to give 0, but a coin toss between + and -.
Constraints
- answers are compared with a tolerance of
1e-6
Goals
- Measure a qubit in the plus/minus basis with the Born rule for a general basis
- Compute an inner product with the conjugate of the first vector
- See relative phases show up as different odds in another basis