Simple Bell test

Small simulator to reproduce both side of Bell's inequalities

by Boing3000

HTML

Locality type<select id="Locality" ><option value="NonLocal">Non-Local</option><option value="Local">Local</option></select><br/>
Detectors angle (degree, -1 means random)<br/>
Alice angle<input id="AliceAngle" type="text" value="-1"/> Bob angle<input id="BobAngle" type="text" value="-1" /><br/>
Number of photon <input id="PhotonCounts" value="1000" /> <input id="RunTest" type="button" value="Test" /><br/>
Correlation %<input id="Result" />

JavaScript

'use strict';

			function PolarizationProbability(photonPolarizationAngle, detectorAngle) {
				return Math.pow(Math.cos(photonPolarizationAngle - detectorAngle), 2);
			}

			function IsPhotonPolarized(photon, detectorAngle) {
				// this is where our virtual God play dice
				return Math.random() <= PolarizationProbability(photon.polarization.angle, detectorAngle);
			}

			function PrepareEntangledPair(useLocality) {
				var polarizationA = { angle: Math.random() * (Math.PI * 2) }; 
				var polarizationB = (useLocality)
					? { angle: polarizationA.angle } // locality means we create a different object *copy* (but still identical in value)
					: polarizationA; // we use the very same unique object/hidden variable whitch then span across two photon          
				return {
					APhoton: { polarization: polarizationA },
					BPhoton: { polarization: polarizationB },
				}
			}

			function PolarizationTest(photon, detectorDegree) {
				var detectorAngle = (detectorDegree < 0)
					? Math.random() * (Math.PI * 2)  // random radian angle
					: detectorDegree / 180 * Math.PI; // fixed angle

				var isPolarized = IsPhotonPolarized(photon, detectorAngle);
				// this is kind of the crux of the matter, 
				// even for a single photon, to keep 100% probability to still have the same polarization at the same angle later on, we have to change its polarization
				if (isPolarized) {
					photon.polarization.angle = detectorAngle; // not so incidentally, if polarization is **shared** by some other photon, it will then be 100% correlated too
				}
				else {
					photon.polarization.angle = detectorAngle + (Math.PI/2); // 90 degree will force 100% non-polarized
				}
        // FLT signaling impossible => (simulated by nature inability to preserve entanglement after interaction)
        photon.polarization = { angle : photon.polarization.angle }; // aka un-entanglement
        
				return { // the observation result
					detectorAngle: detectorAngle,
					isPolarized:...