length(): gives the number of elements in the array, and stores it in a single value K.
So ‘x’ will contain M random cos() numbers, ‘y’ will contain M numbers with values from the formula above (sqrt() is square root)
rbind(x,y) simply puts the two lists with numbers in x and y in one 2xM array called ‘e’
This is a loop structure: The program iterates over the code between the brackets, having i=1, 2, 3 …, until i =K-1 (K was the number of angles, so 361). Notice that within this loop another loop is used, having ‘j’ going from 1 to K-1.
The i-th angle in the array of angles is stored in ‘alpha’. The angles are expressed in radians, so when i=0 the alpha=0, when i = 1 then alpha=1 *pi /360 etc.
c(): an assignment: So Joy stores the 2 numbers cos(alpha) and sin(alpha) in a 2d array.
the second loop within the firs loop starts
‘beta’ will also contain each time a different angle, and b the two numbers cos(beta) and sin(beta)
so ‘e’ contains:
The number of elements in ca is put in N (which will always be M)
sign() returns 1 for positive numbers, -1 for negative numbers.
- Joy's model iterates over Alice’s and Bobs angles. This is an efficient mechanism to get results for all the settings. The same results should be obtained using random (integer) angles between 0 and 360 degrees, but one might need a slightly larger 'M' to get nice results for all the angles.
- The conditions for the Bell type simulation seems to be met: All the particles are used in the result set (which excludes the detection loophole) and the measurement for Alice does not use Bob's measurement and vice versa.