Machine A flips a fair coin and sends out |0\rangle or |1\rangle. Machine B flips a fair coin and sends out |+\rangle = (|0\rangle + |1\rangle)/\sqrt2 or |-\rangle = (|0\rangle - |1\rangle)/\sqrt2. You receive a qubit but are not told the coin. Can any experiment tell which machine made it?
A source that sends state |\psi_k\rangle with probability p_k is described by the density matrix of the mixture
where \psi_{k,i} is amplitude i of state k and the bar is the complex conjugate. Every measurement probability of the received qubit depends only on \rho, so two sources with the same \rho cannot be told apart by any experiment. (Machines A and B both give \rho = I/2, as the first two examples show.)
Write mixture(probs, states) that returns \rho as a list of rows (rho[i][j]). states[k] is a normalised state (all of the same length, 2 or 4 amplitudes) sent with probability probs[k]; the probabilities add up to 1. A state may appear more than once, and a probability may be 0.
Examples
Input: probs = [0.5, 0.5], states = [[1, 0], [0, 1]]
Output: [[0.5, 0], [0, 0.5]]
Input: probs = [0.5, 0.5], states = [[0.7071067811865476, 0.7071067811865476], [0.7071067811865476, -0.7071067811865476]]
Output: [[0.5, 0], [0, 0.5]]
Explanation: the off-diagonal 0.5 of |+><+| and the -0.5 of |-><-| cancel.
Input: probs = [0.25, 0.75], states = [[1, 0], [0.6, 0.8]]
Output: [[0.52, 0.36], [0.36, 0.48]]
Explanation: 0.25 * [[1, 0], [0, 0]] + 0.75 * [[0.36, 0.48], [0.48, 0.64]].
Entries may be ints, floats or complex numbers; each is compared with a tolerance of 1e-6.
Goals
- Build the density matrix of a mixture $\sum_k p_k |\psi_k\rangle\langle\psi_k|$
- See that two different mixtures can give the same density matrix