bet2.R

richard — Apr 19, 2014, 3:25 PM

## Programme to resolve bet between Joy Christian and Richard Gill
## Version 2: four separate samples for each of the four correlations

## I use mathematician's notation: theta is the azimuthal angle, phi is the polar 
## (aka zenith) angle; both measured in radians. 
## Reference: https://en.wikipedia.org/wiki/Spherical_coordinates
## Since my measurement directions all lie in equatorial plane I just extract "theta"


AliceDirections <- read.table("AliceDirections.txt")   ## offline

# AliceDirections <-                                  # online
#    read.table("http://www.math.leidenuniv.nl/~gill/AliceDirections.txt")

names(AliceDirections) <- c("theta", "phi")

head(AliceDirections) ## N pairs theta, phi (N rows, 2 columns)
       theta    phi
1  0.4558512 1.0748
2  0.5828188 2.0602
3 -0.6764309 0.9770
4  0.0008851 2.4905
5  0.5155671 1.2942
6 -0.1007671 0.7155

NAlice <- nrow(AliceDirections)

NAlice
[1] 100

AliceTheta <- AliceDirections$theta # Alice's azimuthal angles

head(AliceTheta)
[1]  0.4558512  0.5828188 -0.6764309  0.0008851  0.5155671 -0.1007671

BobDirections <- read.table("BobDirections.txt")  # offline

# BobDirections <-                                # online
#     read.table("http://www.math.leidenuniv.nl/~gill/BobDirections.txt")

names(BobDirections) <- c("theta", "phi")

head(BobDirections)
    theta    phi
1  1.4594 2.3205
2  0.5882 2.4816
3 -1.0540 0.8944
4 -0.2971 1.0470
5  1.2251 1.8913
6 -1.1389 2.3236

NBob <- nrow(BobDirections)

NBob
[1] 100

if (NAlice != NBob) print("Error: particle numbers don't match") else
    print("Go ahead!")
[1] "Go ahead!"

N <- NAlice ## The common number of particle pairs

BobTheta <- BobDirections$theta  # Bob's azimuthal angles

head(BobTheta)
[1]  1.4594  0.5882 -1.0540 -0.2971  1.2251 -1.1389

## Now we create four random subsamples for each of the four correlations

Sample <- sample(c(1, 2, 3, 4), N, replace = TRUE)

## First pair of measurement directions

Alpha <- 0 * pi / 180
Beta <- 45 * pi / 180
A <- sign(cos(AliceTheta[Sample == 1] - Alpha))
B <- - sign(cos(BobTheta[Sample == 1] - Beta))
E11 <- mean(A * B)

## Second pair of measurement directions

Alpha <- 0 * pi / 180
Beta <- 135 * pi / 180
A <- sign(cos(AliceTheta[Sample == 2] - Alpha))
B <- - sign(cos(BobTheta[Sample == 2] - Beta))
E12 <- mean(A * B)

## Third pair of measurement directions

Alpha <- 90 * pi / 180
Beta <- 45 * pi / 180
A <- sign(cos(AliceTheta[Sample == 3] - Alpha))
B <- - sign(cos(BobTheta[Sample == 3] - Beta))
E21 <- mean(A * B)

## Fourth pair of measurement directions

Alpha <- 90 * pi / 180
Beta <- 135 * pi / 180
A <- sign(cos(AliceTheta[Sample == 4] - Alpha))
B <- - sign(cos(BobTheta[Sample == 4] - Beta))
E22 <- mean(A * B)

CHSH <- E12 - E11 - E21 - E22

CHSH 
[1] 1.38

if (CHSH > 2.4) print("Congratulations, Joy") else 
    print("Congratulations, Richard")
[1] "Congratulations, Richard"