I am taking a MOOC on quantum information from MIT (8.370.1x). The discussion on Bell's theorem involves a game, the CHSH game, with two players, Alice and Bob. I wrote a little bit of Python code to understand the results better.
The CHSH game consist of a referee (Rosa) that produces two randomly chosen classical bits \(a\) and \(b\) and hands Alice and Bob one each. Alice and Bob are separated. Alice produces another bit, \(x\), and Bob produces another bit \(y\). The game is won if the following condition is met:
The claim is that if Alice and Bob follow a deterministic strategy when they each produce their bit, the game can only be won at most 75% of the time.
Here is some code to check this. First, you do some imports and set the seed of the random number generator:
from itertools import product
import numpy as np
np.random.seed(0)
Then you introduce a couple of variables:
rosa_option = np.arange(2)
N = 64000
a = np.random.choice(rosa_option, size=N)
b = np.random.choice(rosa_option, size=N)
You define some functions for playing the game:
def deterministic(i, strategy, option):
return option[strategy[i]]
def fraction_of_wins(a, b, f, g, n):
booleans = np.array([False, True])
X = deterministic(a, f, booleans)
Y = deterministic(b, g, booleans)
A = booleans[a]
B = booleans[b]
wins = np.equal(np.bitwise_and(A, B), np.bitwise_xor(X, Y))
return np.sum(wins) / n
Here is some code for printing the probability of winning when using different combination of strategies:
strategy = np.array([p for p in product((0, 1), repeat=2)])
M = 4
p = np.zeros((M, M), dtype=float)
for i in range(M):
for j in range(M):
p[i, j] = fraction_of_wins(a, b, strategy[i], strategy[j], N)
print(p)
Each deterministic strategy corresponds to 2-tuple where the first value corresponds to what the player does for one kind of referee input and the other value is for the other kind of referee input.
The output is:
[[ 0.75101562 0.74796875 0.25203125 0.24898438]
[ 0.749375 0.24835937 0.75164062 0.250625 ]
[ 0.250625 0.75164062 0.24835937 0.749375 ]
[ 0.24898438 0.25203125 0.74796875 0.75101562]]
The largest fractions are close to 75%. In more detail, Alice and Bob have the largest chance of winning if they follow one of the following strategies:
- Both always return 0
- Both always return 1
- Alice (Bob) always returns 0 and Bob (Alice) returns the same as given
- Alice (Bob) always returns 1 and Bob (Alice) returns the negation of what was given
- Alice (Bob) returns the same as given and Bob (Alice) returns the negation of what was given
The other strategies result in the complement winning probability.