In a Bell test two labs each hold one qubit of a pair. Each lab has a dial: lab A measures its qubit (qubit 0) along an angle a, lab B its qubit (qubit 1) along an angle b, and each reports +1 or -1. The correlation E(a, b) is the average of the product of the two reports: +1 if they always agree, -1 if they always disagree.
As maths: measuring along angle \theta (radians) is described by the matrix
(A(0) = Z, the ordinary 0/1 measurement with 0 reported as +1; A(\pi/2) = X), and
where M is the 4x4 matrix kron(A(a), A(b)) with qubit 0's matrix on the left, and \overline{\psi_i} is the complex conjugate (.conjugate()). The state is [\psi_{00}, \psi_{01}, \psi_{10}, \psi_{11}]: qubit 0 is the leftmost bit, so |10\rangle is index 2. The result is always real (up to rounding).
With two settings per lab the CHSH value is
Any pair of qubits in a product state gives |S| \le 2; entangled pairs can reach 2\sqrt2 \approx 2.83, which no pre-agreed classical strategy can.
Write chsh(state, a0, a1, b0, b1) that returns a pair (E, S): E is the list [E(a_0,b_0), E(a_0,b_1), E(a_1,b_0), E(a_1,b_1)] (real numbers) and S the CHSH value.
Examples
Input: state = [0.7071067811865476, 0, 0, 0.7071067811865476],
a0 = 0, a1 = 1.5707963267948966, b0 = 0.7853981633974483, b1 = -0.7853981633974483
Output: ([0.7071067811865475, 0.7071067811865475, 0.7071067811865474, -0.7071067811865474], 2.82842712474619)
Input: state = [0.7071067811865476, 0.7071067811865476, 0, 0], same angles
Output: ([0.7071067811865475, -0.7071067811865474, 0.0, 0.0], 0.0)
Explanation: qubit 0 is |0> and qubit 1 is (|0> + |1>) / sqrt(2): E(a, b) = cos(a) * sin(b).
Input: state = [0.7071067811865476, 0, 0, 0.7071067811865476j], same angles
Output: ([0.7071067811865475, 0.7071067811865475, 0.0, 0.0], 1.414213562373095)
Values like 4e-17 for 0.0 count as correct.
Constraints
- angles are any real numbers in
[-10, 10] - answers are compared with a tolerance of
1e-6
Goals
- Compute the correlation of two measurements along chosen angles as an expectation value
- Combine four correlations into the CHSH value S
- See that a Bell state reaches 2.83 while a product state stays at or below 2