# Adding expectation values to a CHSH animation

1. Jan 27, 2016

### edguy99

An animation of the CHSH experiment to generate correlated photons is at: http://www.animatedphysics.com/games/photon_longdistance_chsh.htm

@georgir has a program to show the calculations using the formula for photon detection
return Math.random() < (Math.cos(r(p-a)*2)+1)/2;
yields the following for the coincident (same as the animation):

classic:
{
"0-22.5": {
"coincident": 1675,
"total": 2501,
"rate": 0.6697321071571372
},
"45-67.5": {
"coincident": 1671,
"total": 2468,
"rate": 0.6770664505672609
},
"45-22.5": {
"coincident": 1709,
"total": 2579,
"rate": 0.6626599457153936
},
"0-67.5": {
"coincident": 820,
"total": 2452,
"rate": 0.33442088091353994
}
}

I am looking for help in calculating the expectation values for the above data. I am interested in adding the expectation values into my animation. A brief explanation on how to do it I found at http://www.gutenberg.us/articles/CHSH_Bell_test:

Any help or checking would be appreciated.

The usual form of the CHSH inequality is:
(1) − 2 ≤ S ≤ 2,
where
(2) S = E(a, b) − E(a, b′) + E(a′, b) + E(ab′).

a and a′ are detector settings on side A, b and b′ on side B, the four combinations being tested in separate subexperiments. The terms E(a, b) etc. are the quantum correlations of the particle pairs, where the quantum correlation is defined to be the expectation value of the product of the "outcomes" of the experiment, i.e. the statistical average of A(aB(b), where A and B are the separate outcomes, using the coding +1 for the '+' channel and −1 for the '−' channel.

2. Jan 28, 2016

### Strilanc

Math.random returns a chosen uniformly random value between 0 and 1. The expression Math.random() < p will evaluate to true with probability p. So the coincidence rate for that particular expression is exactly (Math.cos(r(p-a)*2)+1)/2.

You may be interested in viewing an interactive widget I made to simulate the CHSH test as part of a blog post, to get ideas. You can view it directly on jsfiddle, or in the blog post (with explanation of how to use it). Also you can edit it on jsfiddle. Here's a screenshot:

3. Jan 29, 2016

### edguy99

Nice animation, nice to be able to insert javascript. Never used fiddle, but was able to copy to what I am used to using and am able to work with it. Two quick questions:
1/ Your "photons" are shot with 2 independent random polarizations, rather then being split from a common photon and both photons having the same Jones vector?
2/ I could not find the turn(x,90) or the measure() functions, maybe I am looking in the wrong file?

Thanks, I hope to have fun and let you know.

4. Jan 29, 2016

### Strilanc

It would be more accurate to say that my simulation has two polarizations than to say it has whole photons. Polarization is a 2-level quantum system, a qubit, and the post is framed in terms of qubits. The qubits are entangled to have agreeing value and phase, which corresponds roughly to saying two polarizations will agree both horizontally and diagonally (whichever one you check first).

The measure function is defined at line 217 of src/Engine/ChSh.js; it's just a simple wrapper around code in src/Engine/Superposition.js.

They're written inside strings instead of directly in the code because the widget uses web workers to avoid blocking the browser while running simulations. There's also some string interpolation happening to make escaping the sandbox a bit harder. Also it's not using any math libraries or anything, just direct twiddling of numbers inside a buffer. And the code on jsfiddle has been transpiled by traceur into ES5. So I'm not too surprised you had trouble finding the measure function.

5. Jan 29, 2016

### edguy99

Thanks, I will have a look.

WRT to polarizations, perhaps I am miss-reading, but you assign var refChoice = Math.random() < 0.5; to Alice, then a second var refChoice = Math.random() < 0.5; to Bob, I dont see how these are entangled? Here's where I would assign the same Jones vector to both.

6. Jan 29, 2016

### Strilanc

The entanglement is in the fake sharedQubits variable, which is only worked with indirectly via measure and turn. In the code the entangled state is stored as a list of 8 floats representing 4 complex amplitudes, and Alice and Bob's operations fiddle with the list in the way described by the postulates of QM.

The 'refChoice' variable is the referee's choice, not the entangled qubit. Each player gets an independent random referee bit. The CHSH game is for two isolated players to pick bits satisfying $a \oplus b = x \land y$, where $a, b$ are the players' respective chosen bits and $x, y$ are random bits (chosen by referee to prevent cheating) fed respectively to each player once they're isolated (and ideally at the last possible moment, to close the signalling loophole).

7. Jan 30, 2016

### edguy99

I like the wiki quote at https://en.wikipedia.org/wiki/Qubit:

A qubit is a two-state quantum-mechanical system, such as the polarization of a single photon: here the two states are vertical polarization and horizontal polarization.

8. Jan 31, 2016

### georgir

A bit confusing, but this formula is only used for deciding if a single photon passes a certain polarizer. So it does not reflect coincidence rates between two polarizers in any way in general.
Certainly not in the 'classical' simulation. But it does match coincidence rates in the special case of the "qm" simulation where the photon gets changed by the first measurement.