Advertisement
chemoelectric

eprb_signal_correlations.adb

Sep 4th, 2023 (edited)
3,703
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 33.00 KB | Source Code | 0 0
  1. --********************************************************************
  2. -- This is free and unencumbered software released into the public domain.
  3. --
  4. -- Anyone is free to copy, modify, publish, use, compile, sell, or
  5. -- distribute this software, either in source code form or as a compiled
  6. -- binary, for any purpose, commercial or non-commercial, and by any
  7. -- means.
  8. --
  9. -- In jurisdictions that recognize copyright laws, the author or authors
  10. -- of this software dedicate any and all copyright interest in the
  11. -- software to the public domain. We make this dedication for the benefit
  12. -- of the public at large and to the detriment of our heirs and
  13. -- successors. We intend this dedication to be an overt act of
  14. -- relinquishment in perpetuity of all present and future rights to this
  15. -- software under copyright law.
  16. --
  17. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. -- IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. -- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. -- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. -- OTHER DEALINGS IN THE SOFTWARE.
  24. --
  25. -- For more information, please refer to <https://unlicense.org>
  26. ----------------------------------------------------------------------
  27. -- A novel solution to a two-channel Bell test, by treating it as a
  28. -- problem in random signal analysis, and a simulation based on the
  29. -- solution.
  30. --
  31. -- Author: Barry Schwartz
  32. -- Mastodon address: @ chemoelectric at masto.ai
  33. -- Date completed: 4 Sept 2023
  34. ----------------------------------------------------------------------
  35. --
  36. -- The simulation is written in Ada. A free software Ada compiler is
  37. -- widely available: GCC. Many readers can compile this program,
  38. -- optimized and with runtime checks, by saving it in a file called
  39. -- ‘eprb_signal_correlations.adb’ and then running the command
  40. --
  41. --   gnatmake -O2 -gnata eprb_signal_correlations
  42. --
  43. -- which will create an executable program called
  44. -- ‘eprb_signal_correlations’.  Alternatively, translate the program
  45. -- into the language of your choice.
  46. --
  47. ----------------------------------------------------------------------
  48.  
  49. pragma ada_2022;
  50. pragma wide_character_encoding (utf8);
  51.  
  52. with ada.assertions;
  53. with ada.wide_wide_text_io;
  54. with ada.containers;
  55. with ada.containers.doubly_linked_lists;
  56. with ada.numerics;
  57. with ada.numerics.generic_elementary_functions;
  58. with ada.numerics.generic_complex_types;
  59.  
  60. ----------------------------------------------------------------------
  61.  
  62. procedure eprb_signal_correlations is
  63.  
  64. -- A ‘scalar’ is a double precision floating point number.
  65.   type scalar is digits 15;
  66.  
  67.   subtype scalar_in_0_1 is scalar range 0.0 .. 1.0;
  68.   subtype correlation_coefficient is scalar range -1.0 .. 1.0;
  69.  
  70.   use ada.assertions;
  71.   use ada.wide_wide_text_io;
  72.   use ada.numerics;
  73.   use ada.containers;
  74.  
  75.   package scalar_elementary_functions is
  76.     new ada.numerics.generic_elementary_functions (scalar);
  77.   use scalar_elementary_functions;
  78.  
  79.   package scalar_io is new float_io (scalar);
  80.   use scalar_io;
  81.  
  82.   π     : constant scalar := pi;
  83.   π_2   : constant scalar := π / 2.0;
  84.   π_3   : constant scalar := π / 3.0;
  85.   π_4   : constant scalar := π / 4.0;
  86.   π_6   : constant scalar := π / 6.0;
  87.   π_8   : constant scalar := π / 8.0;
  88.   π_180 : constant scalar := π / 180.0;
  89.   two_π : constant scalar := 2.0 * π;
  90.  
  91.   subtype pair_range is integer range 1 .. 2;
  92.  
  93. ----------------------------------------------------------------------
  94.  
  95. -- For the sake of reproducibility, let us write our own random number
  96. -- generator. It will be a simple linear congruential generator. The
  97. -- author has used one like it, in quicksorts and quickselects to
  98. -- select the pivot. It is good enough for our purpose.
  99.  
  100.   type uint64 is mod 2 ** 64;
  101.  
  102. -- The multiplier lcg_a comes from Steele, Guy; Vigna, Sebastiano (28
  103. -- September 2021). ‘Computationally easy, spectrally good multipliers
  104. -- for congruential pseudorandom number generators’.
  105. -- arXiv:2001.05304v3 [cs.DS]
  106.  
  107.   lcg_a : constant uint64 := 16#F1357AEA2E62A9C5#;
  108.  
  109. -- The value of lcg_c is not critical, but should be odd.
  110.  
  111.   lcg_c : constant uint64 := 1;
  112.  
  113.   seed  : uint64 := 0;
  114.  
  115. --
  116. -- random_scalar: returns a non-negative scalar less than 1.
  117. --
  118.   function random_scalar
  119.   return scalar_in_0_1
  120.   with post => random_scalar'result < 1.0 is
  121.     randval : scalar;
  122.   begin
  123.     -- Take the high 48 bits of the seed and divide it by 2**48.
  124.     randval := scalar (seed / (2**16)) / scalar (2**48);
  125.  
  126.     -- Update the seed.
  127.     seed := (lcg_a * seed) + lcg_c;
  128.  
  129.     return randval;
  130.   end random_scalar;
  131.  
  132. ----------------------------------------------------------------------
  133.  
  134. --
  135. -- Assume there are two communications channels, which can carry one
  136. -- of two orthogonal SIGNAL values, thus:
  137. --
  138.  
  139.   type SIGNAL is ('↶', '↷');
  140.  
  141. --
  142. -- Each channel assigns a TAG to its SIGNAL before delivering it to
  143. -- the receiver. The TAG values are thus:
  144. --
  145.  
  146.   type TAG is ('⊕', '⊖');
  147.  
  148.   type TAGGED_SIGNAL is
  149.     record
  150.       τ : TAG;
  151.       σ : SIGNAL;
  152.     end record;
  153.  
  154. --
  155. -- The algorithm for assigning a tag depends upon a parameter ζ.
  156. --
  157.  
  158.   function assign_TAG (ζ : scalar; σ : SIGNAL)
  159.   return TAGGED_SIGNAL is
  160.     r : constant scalar := random_scalar;
  161.     τ : TAG;
  162.   begin
  163.     case σ is
  164.       when '↶' => τ := (if r < cos (ζ) ** 2 then '⊕' else '⊖');
  165.       when '↷' => τ := (if r < sin (ζ) ** 2 then '⊕' else '⊖');
  166.     end case;
  167.     return (τ => τ, σ => σ);
  168.   end assign_TAG;
  169.  
  170. --
  171. -- We would like to collect data on TAGGED_SIGNAL values received at
  172. -- the terminuses of the two channels, when the same random signal is
  173. -- sent over both channels.
  174. --
  175.  
  176.   type TAGGED_SIGNAL_PAIR is array (pair_range) of TAGGED_SIGNAL;
  177.  
  178.   package TAGGED_SIGNAL_PAIR_LISTS is
  179.     new ada.containers.doubly_linked_lists
  180.       (element_type => TAGGED_SIGNAL_PAIR);
  181.  
  182.   function collect_data (ζ1, ζ2     : scalar;
  183.                          run_length : count_type)
  184.   return TAGGED_SIGNAL_PAIR_LISTS.list is
  185.     use TAGGED_SIGNAL_PAIR_LISTS;
  186.     data   : list := empty_list;
  187.     σ      : SIGNAL;
  188.     σ1, σ2 : TAGGED_SIGNAL;  
  189.   begin
  190.     for i in 1 .. run_length loop
  191.       σ := (if random_scalar < 0.5 then '↶' else '↷');
  192.       σ1 := assign_TAG (ζ => ζ1, σ => σ);
  193.       σ2 := assign_TAG (ζ => ζ2, σ => σ);
  194.       append (data, (σ1, σ2));
  195.     end loop;
  196.     return data;
  197.   end collect_data;
  198.  
  199. ----------------------------------------------------------------------
  200. --
  201. -- Before running a simulation, we MUST do a mathematical analysis of
  202. -- this experiment. Otherwise we will not know what to do with the raw
  203. -- data. So let us do the mathematics.
  204. --
  205. -- We will use subscripts to refer to channel numbers. Thus, for
  206. -- instance, ‘ζ₂’ refers to the ζ parameter for channel 2, and ‘τ₁’ to
  207. -- the TAG value for channel 1. Plain ‘τ’ without a subscript can
  208. -- refer to either τ₁ or τ₂. And so on like that.
  209. --
  210. -- We will use more or less conventional probability notation. Thus,
  211. -- for instance, ‘P(σ=↶ τ₁=⊖ | τ₂=⊖)’ refers to a joint probability of
  212. -- certain values for σ and τ₁ conditional on a given value of τ₂.
  213. --
  214. -- To start with, we have
  215. --
  216. --    P(σ=↶) = ½
  217. --    P(σ=↷) = ½
  218. --
  219. -- and some conditional probabilities are easily determined, as well
  220. --
  221. --    P(τ=⊕ | σ=↶ ζ=φ) = cos²(φ)
  222. --    P(τ=⊖ | σ=↶ ζ=φ) = sin²(φ)
  223. --    P(τ=⊕ | σ=↷ ζ=φ) = sin²(φ)
  224. --    P(τ=⊖ | σ=↷ ζ=φ) = cos²(φ)
  225. --
  226. -- It is easy to get the probabilities of τ=⊕ and τ=⊖ individually,
  227. -- and see that they are the constant ½.
  228. --
  229. --    P(τ=⊕ | ζ=φ) = P(σ=↶) P(τ=⊕ | σ=↶ ζ=φ) +
  230. --                        P(σ=↷) P(τ=⊕ | σ=↷ ζ=φ)
  231. --                 = ½ cos²(φ) + ½ sin²(φ) = ½
  232. --
  233. --    P(τ=⊖ | ζ=φ) = P(σ=↶) P(τ=⊖ | σ=↶ ζ=φ) +
  234. --                        P(σ=↷) P(τ=⊖ | σ=↷ ζ=φ)
  235. --                 = ½ sin²(φ) + ½ cos²(φ) = ½
  236. --
  237. -- Probability theory further tells us that
  238. --
  239. --    P(σ=↶ τ₁=⊕ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂)
  240. --         = P(σ=↶) P(τ₁=⊕ τ₂=⊕ | σ=↶ ζ₁=φ₁ ζ₂=φ₂)
  241. --         = P(σ=↶) P(τ₁=⊕ | σ=↶ ζ₁=φ₁) P(τ₂=⊕ | σ=↶ ζ₁=φ₁ ζ₂=φ₂)
  242. --         = P(σ=↶) P(τ₁=⊕ | σ=↶ ζ₁=φ₁) P(τ₂=⊕ | σ=↶ ζ₂=φ₂)
  243. --
  244. -- where in the last expression the ζ₁ parameter is removed from the
  245. -- factor for the channel 2, because it plays no role in channel 2.
  246. -- By the previous calculation and similar ones, the following table
  247. -- can be constructed.
  248. --
  249. --    P(σ=↶ τ₁=⊕ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) cos²(φ₂)
  250. --    P(σ=↶ τ₁=⊕ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) sin²(φ₂)
  251. --    P(σ=↶ τ₁=⊖ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) cos²(φ₂)
  252. --    P(σ=↶ τ₁=⊖ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) sin²(φ₂)
  253. --    P(σ=↷ τ₁=⊕ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) sin²(φ₂)
  254. --    P(σ=↷ τ₁=⊕ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) cos²(φ₂)
  255. --    P(σ=↷ τ₁=⊖ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) sin²(φ₂)
  256. --    P(σ=↷ τ₁=⊖ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) cos²(φ₂)
  257. --
  258. -- From that table, we easily get the following table of probabilities
  259. -- of coincidence pairs.
  260. --
  261. --    P(τ₁=⊕ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) cos²(φ₂) +
  262. --                                       ½ sin²(φ₁) sin²(φ₂)
  263. --    P(τ₁=⊕ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) sin²(φ₂) +
  264. --                                       ½ sin²(φ₁) cos²(φ₂)
  265. --    P(τ₁=⊖ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) cos²(φ₂) +
  266. --                                       ½ cos²(φ₁) sin²(φ₂)
  267. --    P(τ₁=⊖ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) sin²(φ₂) +
  268. --                                       ½ cos²(φ₁) cos²(φ₂)
  269. --
  270. -- Suppose we want to evaluate the correlation between τ₁ and τ₂ for
  271. -- given ζ₁ and ζ₂. Mapping (τ=⊕)↦(τ′=+1) and (τ=⊖)↦(τ′=-1), we can
  272. -- compute a correlation coefficient ρ. We will use the notation E(x)
  273. -- to represent the expectation (average weighted by probabilities) of
  274. -- x. Intuitively E(τ′)=0, and I will not belabor this page with the
  275. -- calculation. Therefore the formula for ρ simplifies to
  276. --
  277. --    ρ = E(τ′₁τ′₂)/(√E((τ′₁)²) √E((τ′₂)²))
  278. --
  279. -- where the numerator is the covariance and the denominator is the
  280. -- product of the standard deviations. The standard deviations are
  281. -- trivial. Using P(τ=⊕ | ζ=φ) = P(τ=⊖ | ζ=φ) = ½, one gets
  282. --
  283. --    √E(τ′²) = √((+1)²(½) + (-1)²(½)) = 1
  284. --
  285. -- Thus ρ = E(τ′₁τ′₂). Expanding that gives
  286. --
  287. --    ρ = (+1)(+1) P(τ₁=⊕ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) +
  288. --           (+1)(-1) P(τ₁=⊕ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) +
  289. --              (-1)(+1) P(τ₁=⊖ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) +
  290. --                 (-1)(-1) P(τ₁=⊖ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂)
  291. --      = cos²(φ₁) cos²(φ₂) - cos²(φ₁) sin²(φ₂)
  292. --              - sin²(φ₁) cos²(φ₂) + sin²(φ₁) sin²(φ₂)
  293. --      = (cos²(φ₂) - sin²(φ₂)) (cos²(φ₁) - sin²(φ₁))
  294. --      = cos(2φ₂) cos(2φ₁)
  295. --
  296. -- And what we are going to do, right now, is plug in the Bell test
  297. -- angles.
  298. --
  299. --    φ₁=0    φ₂=π/8       ρ=√½
  300. --    φ₁=0    φ₂=3π/8      ρ=-√½
  301. --    φ₁=π/4  φ₂=π/8       ρ=0
  302. --    φ₁=π/4  φ₂=3π/8      ρ=0
  303. --
  304. -- This is a disappointing result—but we have computed the
  305. -- expectations incorrectly. It is easy to overlook that one has
  306. -- assumed a particular coordinate system, and that is what we have
  307. -- done for the ζ settings. However, look at the answer we got: it
  308. -- SHOULD be, but is not, in terms of φ₂-φ₁. It is not
  309. -- coordinate-free. We should always have had an angular origin
  310. -- written into our probabilities as another condition.
  311. --
  312. -- Therefore let us assume that condition implicitly written in, and
  313. -- begin again exactly where we left off, but with the variables
  314. -- renamed.
  315. --
  316. --    ρ′ = cos(2φ′₂) cos(2φ′₁)
  317. --
  318. -- Let φ′₁ be the angular origin and take on any value in [-π/4,π/4].
  319. -- Compute the expectation
  320. --
  321. --        π/4                π/4
  322. --    ρ = ∫ ρ′ φ′₁ = cos(2φ′₂) ∫ cos(2φ′₁) dφ′₁
  323. --       -π/4               -π/4
  324. --
  325. --                                 = cos(2φ′₂) = cos²(φ′₂) - sin²(φ′₂)
  326. --
  327. -- Let φ′₂=(φ₂-φ₁)+δ, where δ is an arbitrary number. Thus a solution is
  328. --
  329. --    ρ = cos²(φ₂-φ₁) - sin²(φ₂-φ₁),  φ₁+δ ∈ [-π/4,π/4]
  330. --
  331. -- Because δ is arbitrary, we may drop the quadrant restriction and
  332. -- write
  333. --
  334. --    ρ = cos²(φ₂-φ₁) - sin²(φ₂-φ₁) = cos(2(φ₂-φ₁))
  335. --
  336. -- which, finally, is a solution in the desired, coordinate-free form.
  337. --
  338. -- Plugging in the Bell test angles gives
  339. --
  340. --    φ₁=0    φ₂=π/8       ρ=√½
  341. --    φ₁=0    φ₂=3π/8      ρ=-√½
  342. --    φ₁=π/4  φ₂=π/8       ρ=√½
  343. --    φ₁=π/4  φ₂=3π/8      ρ=√½
  344. --
  345. -- which is more satisfactory.
  346. --
  347. ----------------------------------------------------------------------
  348. --
  349. -- It is certain that most quantum theorists seeking solutions to
  350. -- similar problems via probability theory have neglected the last
  351. -- step, where we integrated over a probability distribution function
  352. -- of angular origins. The reason I say this with certainty is that
  353. -- the solution above is proof that it is possible to violate Bell
  354. -- inequalities with a ‘locally realistic’ model, and that Einstein,
  355. -- Podolsky, and Rosen were correct.
  356. --
  357. -- Two questions immediately arise. One is why do experimenters get
  358. -- Bell inequality violations, despite that they may have incorrect
  359. -- formulas for their correlation calculations? This is a question for
  360. -- which I have no answer. I am not in the least a scholar of the
  361. -- experimental techniques employed.
  362. --
  363. -- The other question is how do Bell and others arrive at their
  364. -- ‘inequalities’ in the first place? That question was answered at
  365. -- least as early as [2] in the References section below. As Bell
  366. -- explains at great length in his famous address [1], his argument
  367. -- rests entirely on what we might call an ‘axiom of causality’. This
  368. -- axiom states that if two random variables have no ‘causal
  369. -- influence’ on each other then they are statistically
  370. -- independent. It is easily demonstrated that this axiom makes
  371. -- mathematics inconsistent, so that any proofs that follow (such as
  372. -- Bell inequalities) are meaningless.
  373. --
  374. -- Suppose I mail a quartz to Fred Flintstone and a topaz to Barney
  375. -- Rubble, or a quartz to Barney Rubble and a topaz to Fred
  376. -- Flintstone. No matter how one writes expressions for them in
  377. -- ordinary probability theory, the joint probabilities are
  378. --
  379. --    P(Fred-quartz Barney-quartz) = 0
  380. --    P(Fred-quartz Barney-topaz)  = ½
  381. --    P(Fred-topaz  Barney-quartz) = ½
  382. --    P(Fred-topaz  Barney-topaz)  = 0
  383. --
  384. -- But suppose we add the ‘axiom of causality’ to the mix and use
  385. -- that. Then we get
  386. --
  387. --    P(Fred-quartz Barney-quartz) = ¼
  388. --    P(Fred-quartz Barney-topaz)  = ¼
  389. --    P(Fred-topaz  Barney-quartz) = ¼
  390. --    P(Fred-topaz  Barney-topaz)  = ¼
  391. --
  392. -- which yields the contradiction 0=¼=½. Thus Bell’s mathematics is
  393. -- inconsistent, and all ‘Bell inequalities’ are meaningless.
  394. --
  395. -- Bell, of course, concludes he has contradicted the assumption that
  396. -- the ‘causation’ in his axiom took place ‘locally’. But the fact
  397. -- remains that, with his axiom in place, mathematics is inconsistent
  398. -- and thus useless to prove ANYTHING.
  399. --
  400. ----------------------------------------------------------------------
  401.  
  402. --
  403. -- Back to the simulation. The data analysis follows the mathematics
  404. -- derived above, and not anything you will find in the usual
  405. -- Bell-test literature. That literature, we have found, is riddled
  406. -- with faulty mathematics. It can be relied on for nothing.
  407. --
  408. -- Our methods will be very similar to those of reference [3],
  409. -- although not identical. We substitute frequencies in the data for
  410. -- probabilities in the closed-form analysis.
  411. --
  412.  
  413.   function count (raw_data : TAGGED_SIGNAL_PAIR_LISTS.list;
  414.                   σ        : SIGNAL;
  415.                   τ1, τ2   : TAG)
  416.   return count_type is
  417.     use TAGGED_SIGNAL_PAIR_LISTS;
  418.     n    : count_type := 0;
  419.     curs : cursor := first (raw_data);
  420.     pair : TAGGED_SIGNAL_PAIR;
  421.   begin
  422.     while has_element (curs) loop
  423.       pair := element (curs);
  424.       assert (pair(1).σ = pair(2));
  425.       if pair(1).σ = σ and pair(1).τ = τ1 and pair(2).τ = τ2 then
  426.         n := n + 1;
  427.       end if;
  428.       curs := next (curs);
  429.     end loop;
  430.     return n;
  431.   end count;
  432.  
  433.   function frequency (raw_data : TAGGED_SIGNAL_PAIR_LISTS.list;
  434.                       σ        : SIGNAL;
  435.                       τ1, τ2   : TAG)
  436.   return scalar
  437.   with post => 0.0 <= frequency'result and frequency'result <= 1.0 is
  438.     use TAGGED_SIGNAL_PAIR_LISTS;
  439.     n_total : count_type := length (raw_data);
  440.   begin
  441.     return (scalar (count (raw_data, σ, τ1, τ2)) / scalar (n_total));
  442.   end frequency;
  443.  
  444.   function cosine_sign (φ : scalar)
  445.   return scalar
  446.   with post => cosine_sign'result = -1.0
  447.                  or cosine_sign'result = 1.0 is
  448.   begin
  449.     return (if cos (φ) < 0.0 then -1.0 else 1.0);
  450.   end cosine_sign;
  451.  
  452.   function sine_sign (φ : scalar)
  453.   return scalar
  454.   with post => sine_sign'result = -1.0 or sine_sign'result = 1.0 is
  455.   begin
  456.     return (if sin (φ) < 0.0 then -1.0 else 1.0);
  457.   end sine_sign;
  458.  
  459.   function cc_sign (φ1, φ2 : scalar)
  460.   return scalar
  461.   with post => cc_sign'result = -1.0 or cc_sign'result = 1.0 is
  462.   begin
  463.     return cosine_sign (φ1) * cosine_sign (φ2);
  464.   end cc_sign;
  465.  
  466.   function cs_sign (φ1, φ2 : scalar)
  467.   return scalar
  468.   with post => cs_sign'result = -1.0 or cs_sign'result = 1.0 is
  469.   begin
  470.     return cosine_sign (φ1) * sine_sign (φ2);
  471.   end cs_sign;
  472.  
  473.   function sc_sign (φ1, φ2 : scalar)
  474.   return scalar
  475.   with post => sc_sign'result = -1.0 or sc_sign'result = 1.0 is
  476.   begin
  477.     return sine_sign (φ1) * cosine_sign (φ2);
  478.   end sc_sign;
  479.  
  480.   function ss_sign (φ1, φ2 : scalar)
  481.   return scalar
  482.   with post => ss_sign'result = -1.0 or ss_sign'result = 1.0 is
  483.   begin
  484.     return sine_sign (φ1) * sine_sign (φ2);
  485.   end ss_sign;
  486.  
  487.   function estimate_ρ (raw_data : TAGGED_SIGNAL_PAIR_LISTS.list;
  488.                        φ1, φ2   : scalar)
  489.   return correlation_coefficient is
  490.     ac2c2, ac2s2 : scalar;
  491.     as2c2, as2s2 : scalar;
  492.     cc2c2, cc2s2 : scalar;
  493.     cs2c2, cs2s2 : scalar;
  494.     c2c2, c2s2   : scalar;
  495.     s2c2, s2s2   : scalar;
  496.     cc, cs       : scalar;
  497.     sc, ss       : scalar;
  498.     c12, s12     : scalar;
  499.     ρ_estimate   : scalar;
  500.   begin
  501.     -- P(σ=↶ τ₁=⊕ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) cos²(φ₂)
  502.     ac2c2 := frequency (raw_data, '↶', '⊕', '⊕');
  503.     -- P(σ=↶ τ₁=⊕ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) sin²(φ₂)
  504.     ac2s2 := frequency (raw_data, '↶', '⊕', '⊖');
  505.     -- P(σ=↶ τ₁=⊖ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) cos²(φ₂)
  506.     as2c2 := frequency (raw_data, '↶', '⊖', '⊕');
  507.     -- P(σ=↶ τ₁=⊖ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) sin²(φ₂)
  508.     as2s2 := frequency (raw_data, '↶', '⊖', '⊖');
  509.     -- P(σ=↷ τ₁=⊕ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) sin²(φ₂)
  510.     cs2s2 := frequency (raw_data, '↷', '⊕', '⊕');
  511.     -- P(σ=↷ τ₁=⊕ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ sin²(φ₁) cos²(φ₂)
  512.     cs2c2 := frequency (raw_data, '↷', '⊕', '⊖');
  513.     -- P(σ=↷ τ₁=⊖ τ₂=⊕ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) sin²(φ₂)
  514.     cc2s2 := frequency (raw_data, '↷', '⊖', '⊕');
  515.     -- P(σ=↷ τ₁=⊖ τ₂=⊖ | ζ₁=φ₁ ζ₂=φ₂) = ½ cos²(φ₁) cos²(φ₂)
  516.     cc2c2 := frequency (raw_data, '↷', '⊖', '⊖');
  517.  
  518.     -- cos²(φ₁) cos²(φ₂)
  519.     c2c2 := ac2c2 + cc2c2;
  520.     -- cos²(φ₁) sin²(φ₂)
  521.     c2s2 := ac2s2 + cc2s2;
  522.     -- sin²(φ₁) cos²(φ₂)
  523.     s2c2 := as2c2 + cs2c2;
  524.     -- sin²(φ₁) sin²(φ₂)
  525.     s2s2 := as2s2 + cs2s2;
  526.  
  527.     -- cos(φ₁) cos(φ₂)
  528.     cc := cc_sign (φ1, φ2) * sqrt (c2c2);
  529.     -- cos(φ₁) sin(φ₂)
  530.     cs := cs_sign (φ1, φ2) * sqrt (c2s2);
  531.     -- sin(φ₁) cos(φ₂)
  532.     sc := sc_sign (φ1, φ2) * sqrt (s2c2);
  533.     -- sin(φ₁) sin(φ₂)
  534.     ss := ss_sign (φ1, φ2) * sqrt (s2s2);
  535.  
  536.     -- cos(φ1 - φ2) = cos(φ₁) cos(φ₂) + sin(φ₁) sin(φ₂)
  537.     c12 := cc + ss;
  538.     -- sin(φ1 - φ2) = sin(φ₁) cos(φ₂) - cos(φ₁) sin(φ₂)
  539.     s12 := sc - cs;
  540.  
  541.     ρ_estimate := (c12 * c12) - (s12 * s12);
  542.  
  543.     return scalar'min (1.0, scalar'max (-1.0, ρ_estimate));
  544.   end estimate_ρ;
  545.  
  546. ----------------------------------------------------------------------
  547.  
  548. begin
  549.   declare
  550.     φ1, φ2 : scalar;
  551.     ρ_est  : correlation_coefficient;
  552.   begin
  553.     for i in 0 .. 31 loop
  554.       φ1 := scalar (i) * π / 16.0;
  555.       φ2 := φ1 - π_8;
  556.       ρ_est := estimate_ρ (collect_data (φ1, φ2, 1e6), φ1, φ2);
  557.       put ("   φ1 = ");
  558.       put (φ1 / π_180, 3, 2, 0);
  559.       put ("   φ2 = ");
  560.       put (φ2 / π_180, 3, 2, 0);
  561.       put ("   ρ est. = ");
  562.       put (ρ_est, 2, 5, 0);
  563.       new_line;
  564.     end loop;
  565.     new_line;
  566.     for i in 0 .. 31 loop
  567.       φ1 := scalar (i) * π / 16.0;
  568.       φ2 := φ1 + π_8;
  569.       ρ_est := estimate_ρ (collect_data (φ1, φ2, 1e6), φ1, φ2);
  570.       put ("   φ1 = ");
  571.       put (φ1 / π_180, 3, 2, 0);
  572.       put ("   φ2 = ");
  573.       put (φ2 / π_180, 3, 2, 0);
  574.       put ("   ρ est. = ");
  575.       put (ρ_est, 2, 5, 0);
  576.       new_line;
  577.     end loop;
  578.     new_line;
  579.     for i in 0 .. 31 loop
  580.       φ1 := scalar (i) * π / 16.0;
  581.       φ2 := φ1 - (3.0 * π_8);
  582.       ρ_est := estimate_ρ (collect_data (φ1, φ2, 1e6), φ1, φ2);
  583.       put ("   φ1 = ");
  584.       put (φ1 / π_180, 3, 2, 0);
  585.       put ("   φ2 = ");
  586.       put (φ2 / π_180, 3, 2, 0);
  587.       put ("   ρ est. = ");
  588.       put (ρ_est, 2, 5, 0);
  589.       new_line;
  590.     end loop;
  591.     new_line;
  592.     for i in 0 .. 31 loop
  593.       φ1 := scalar (i) * π / 16.0;
  594.       φ2 := φ1 + (3.0 * π_8);
  595.       ρ_est := estimate_ρ (collect_data (φ1, φ2, 1e6), φ1, φ2);
  596.       put ("   φ1 = ");
  597.       put (φ1 / π_180, 3, 2, 0);
  598.       put ("   φ2 = ");
  599.       put (φ2 / π_180, 3, 2, 0);
  600.       put ("   ρ est. = ");
  601.       put (ρ_est, 2, 5, 0);
  602.       new_line;
  603.     end loop;
  604.   end;
  605. end eprb_signal_correlations;
  606.  
  607. ----------------------------------------------------------------------
  608. --
  609. -- Afterword.
  610. --
  611. -- Of course, John S. Bell and others have at last been awarded a
  612. -- Nobel Prize, precisely for inventing and using their inconsistent
  613. -- mathematics, and for calculating their correlation coefficients
  614. -- incorrectly. What actually will happen now is that quantum
  615. -- physicists will continue to use inconsistent mathematics, and also
  616. -- will continue to leave probability distribution functions out of
  617. -- their expectation calculations. We will get no return to the
  618. -- classical approach, such as I demonstrated here using the
  619. -- engineering techniques of signal processing analysis. We will
  620. -- continue to get very little progress towards a deeper understanding
  621. -- of our universe—if we do not, in fact, slip considerably backwards.
  622. -- ‘Quantum’ madness seems to be infecting electrical engineering
  623. -- itself more and more deeply. Must I fear signal processing
  624. -- engineers going the same route as physicists? We may be witnessing
  625. -- one of the worst and most quickly accelerating infectious rots ever
  626. -- encountered by our intellectual institutions.
  627. --
  628. -- It is possible, by the way, to arrive at our solution by wave
  629. -- coherence theory instead of probability theory. Probability theory
  630. -- is more mathematically fundamental and so, perhaps, more
  631. -- convincing, but wave coherence is more familiar to some engineers
  632. -- and scientists. Reference [3] uses the wave coherence approach,
  633. -- treating the signals specifically as pulses of plane-polarized
  634. -- light. The wave coherence approach could be used as well with
  635. -- abstract signals, looking for coherence not in electromagnetic
  636. -- waves, but directly within statistical data. The mathematics would
  637. -- be similar.
  638. --
  639. -- Finally, I would like to point out that Bell’s ‘axiom of causality’
  640. -- is actually a corollary of the famous ‘Wishing Theorem’. The
  641. -- Wishing Theorem states: Proposition P is true because I wish it.
  642. --
  643. ----------------------------------------------------------------------
  644. --
  645. -- References.
  646. --
  647. -- [1] J. S. Bell, ‘Bertlmann’s socks and the nature of reality’,
  648. --     preprint, CERN-TH-2926 (1980).
  649. --     http://cds.cern.ch/record/142461/ (Open access, CC BY 4.0)
  650. --
  651. -- [2] E. T. Jaynes, ‘Clearing up Mysteries—The Original Goal’, in
  652. --     J. Skilling, ed., Maximum-Entropy and Bayesian Methods, Kluwer,
  653. --     Dordrecht (1989).
  654. --     https://bayes.wustl.edu/etj/articles/cmystery.pdf
  655. --
  656. -- [3] A. F. Kracklauer, ‘EPR-B correlations: non-locality or
  657. --     geometry?’, J. Nonlinear Math. Phys. 11 (Supp.) 104–109 (2004).
  658. --     https://doi.org/10.2991/jnmp.2004.11.s1.13 (Open access, CC
  659. --     BY-NC)
  660. --
  661. ----------------------------------------------------------------------
  662. --
  663. -- A copy of the program output.
  664. --
  665. --    φ1 =   0.00   φ2 = -22.50   ρ est. =  0.70795
  666. --    φ1 =  11.25   φ2 = -11.25   ρ est. =  0.70562
  667. --    φ1 =  22.50   φ2 =   0.00   ρ est. =  0.70626
  668. --    φ1 =  33.75   φ2 =  11.25   ρ est. =  0.70621
  669. --    φ1 =  45.00   φ2 =  22.50   ρ est. =  0.70683
  670. --    φ1 =  56.25   φ2 =  33.75   ρ est. =  0.70750
  671. --    φ1 =  67.50   φ2 =  45.00   ρ est. =  0.70796
  672. --    φ1 =  78.75   φ2 =  56.25   ρ est. =  0.70672
  673. --    φ1 =  90.00   φ2 =  67.50   ρ est. =  0.70792
  674. --    φ1 = 101.25   φ2 =  78.75   ρ est. =  0.70641
  675. --    φ1 = 112.50   φ2 =  90.00   ρ est. =  0.70639
  676. --    φ1 = 123.75   φ2 = 101.25   ρ est. =  0.70615
  677. --    φ1 = 135.00   φ2 = 112.50   ρ est. =  0.70959
  678. --    φ1 = 146.25   φ2 = 123.75   ρ est. =  0.70596
  679. --    φ1 = 157.50   φ2 = 135.00   ρ est. =  0.70671
  680. --    φ1 = 168.75   φ2 = 146.25   ρ est. =  0.70553
  681. --    φ1 = 180.00   φ2 = 157.50   ρ est. =  0.70702
  682. --    φ1 = 191.25   φ2 = 168.75   ρ est. =  0.70953
  683. --    φ1 = 202.50   φ2 = 180.00   ρ est. =  0.70713
  684. --    φ1 = 213.75   φ2 = 191.25   ρ est. =  0.70714
  685. --    φ1 = 225.00   φ2 = 202.50   ρ est. =  0.70612
  686. --    φ1 = 236.25   φ2 = 213.75   ρ est. =  0.70811
  687. --    φ1 = 247.50   φ2 = 225.00   ρ est. =  0.70919
  688. --    φ1 = 258.75   φ2 = 236.25   ρ est. =  0.70771
  689. --    φ1 = 270.00   φ2 = 247.50   ρ est. =  0.70738
  690. --    φ1 = 281.25   φ2 = 258.75   ρ est. =  0.70727
  691. --    φ1 = 292.50   φ2 = 270.00   ρ est. =  0.70712
  692. --    φ1 = 303.75   φ2 = 281.25   ρ est. =  0.70765
  693. --    φ1 = 315.00   φ2 = 292.50   ρ est. =  0.70597
  694. --    φ1 = 326.25   φ2 = 303.75   ρ est. =  0.70727
  695. --    φ1 = 337.50   φ2 = 315.00   ρ est. =  0.70733
  696. --    φ1 = 348.75   φ2 = 326.25   ρ est. =  0.70615
  697. --
  698. --    φ1 =   0.00   φ2 =  22.50   ρ est. =  0.70704
  699. --    φ1 =  11.25   φ2 =  33.75   ρ est. =  0.70688
  700. --    φ1 =  22.50   φ2 =  45.00   ρ est. =  0.70675
  701. --    φ1 =  33.75   φ2 =  56.25   ρ est. =  0.70772
  702. --    φ1 =  45.00   φ2 =  67.50   ρ est. =  0.70944
  703. --    φ1 =  56.25   φ2 =  78.75   ρ est. =  0.70698
  704. --    φ1 =  67.50   φ2 =  90.00   ρ est. =  0.70745
  705. --    φ1 =  78.75   φ2 = 101.25   ρ est. =  0.70660
  706. --    φ1 =  90.00   φ2 = 112.50   ρ est. =  0.70651
  707. --    φ1 = 101.25   φ2 = 123.75   ρ est. =  0.70768
  708. --    φ1 = 112.50   φ2 = 135.00   ρ est. =  0.70784
  709. --    φ1 = 123.75   φ2 = 146.25   ρ est. =  0.70716
  710. --    φ1 = 135.00   φ2 = 157.50   ρ est. =  0.70511
  711. --    φ1 = 146.25   φ2 = 168.75   ρ est. =  0.70778
  712. --    φ1 = 157.50   φ2 = 180.00   ρ est. =  0.70601
  713. --    φ1 = 168.75   φ2 = 191.25   ρ est. =  0.70930
  714. --    φ1 = 180.00   φ2 = 202.50   ρ est. =  0.70768
  715. --    φ1 = 191.25   φ2 = 213.75   ρ est. =  0.70538
  716. --    φ1 = 202.50   φ2 = 225.00   ρ est. =  0.70691
  717. --    φ1 = 213.75   φ2 = 236.25   ρ est. =  0.70773
  718. --    φ1 = 225.00   φ2 = 247.50   ρ est. =  0.70589
  719. --    φ1 = 236.25   φ2 = 258.75   ρ est. =  0.70642
  720. --    φ1 = 247.50   φ2 = 270.00   ρ est. =  0.70693
  721. --    φ1 = 258.75   φ2 = 281.25   ρ est. =  0.70703
  722. --    φ1 = 270.00   φ2 = 292.50   ρ est. =  0.70632
  723. --    φ1 = 281.25   φ2 = 303.75   ρ est. =  0.70764
  724. --    φ1 = 292.50   φ2 = 315.00   ρ est. =  0.70808
  725. --    φ1 = 303.75   φ2 = 326.25   ρ est. =  0.70540
  726. --    φ1 = 315.00   φ2 = 337.50   ρ est. =  0.70710
  727. --    φ1 = 326.25   φ2 = 348.75   ρ est. =  0.70595
  728. --    φ1 = 337.50   φ2 = 360.00   ρ est. =  0.70710
  729. --    φ1 = 348.75   φ2 = 371.25   ρ est. =  0.70676
  730. --
  731. --    φ1 =   0.00   φ2 = -67.50   ρ est. = -0.70675
  732. --    φ1 =  11.25   φ2 = -56.25   ρ est. = -0.70704
  733. --    φ1 =  22.50   φ2 = -45.00   ρ est. = -0.70640
  734. --    φ1 =  33.75   φ2 = -33.75   ρ est. = -0.70595
  735. --    φ1 =  45.00   φ2 = -22.50   ρ est. = -0.70673
  736. --    φ1 =  56.25   φ2 = -11.25   ρ est. = -0.70814
  737. --    φ1 =  67.50   φ2 =   0.00   ρ est. = -0.70717
  738. --    φ1 =  78.75   φ2 =  11.25   ρ est. = -0.70630
  739. --    φ1 =  90.00   φ2 =  22.50   ρ est. = -0.70750
  740. --    φ1 = 101.25   φ2 =  33.75   ρ est. = -0.70602
  741. --    φ1 = 112.50   φ2 =  45.00   ρ est. = -0.70693
  742. --    φ1 = 123.75   φ2 =  56.25   ρ est. = -0.70796
  743. --    φ1 = 135.00   φ2 =  67.50   ρ est. = -0.70756
  744. --    φ1 = 146.25   φ2 =  78.75   ρ est. = -0.70707
  745. --    φ1 = 157.50   φ2 =  90.00   ρ est. = -0.70766
  746. --    φ1 = 168.75   φ2 = 101.25   ρ est. = -0.70598
  747. --    φ1 = 180.00   φ2 = 112.50   ρ est. = -0.70700
  748. --    φ1 = 191.25   φ2 = 123.75   ρ est. = -0.70810
  749. --    φ1 = 202.50   φ2 = 135.00   ρ est. = -0.70828
  750. --    φ1 = 213.75   φ2 = 146.25   ρ est. = -0.70878
  751. --    φ1 = 225.00   φ2 = 157.50   ρ est. = -0.70693
  752. --    φ1 = 236.25   φ2 = 168.75   ρ est. = -0.70774
  753. --    φ1 = 247.50   φ2 = 180.00   ρ est. = -0.70804
  754. --    φ1 = 258.75   φ2 = 191.25   ρ est. = -0.70772
  755. --    φ1 = 270.00   φ2 = 202.50   ρ est. = -0.70717
  756. --    φ1 = 281.25   φ2 = 213.75   ρ est. = -0.70636
  757. --    φ1 = 292.50   φ2 = 225.00   ρ est. = -0.70899
  758. --    φ1 = 303.75   φ2 = 236.25   ρ est. = -0.70777
  759. --    φ1 = 315.00   φ2 = 247.50   ρ est. = -0.70699
  760. --    φ1 = 326.25   φ2 = 258.75   ρ est. = -0.70818
  761. --    φ1 = 337.50   φ2 = 270.00   ρ est. = -0.70656
  762. --    φ1 = 348.75   φ2 = 281.25   ρ est. = -0.70741
  763. --
  764. --    φ1 =   0.00   φ2 =  67.50   ρ est. = -0.70720
  765. --    φ1 =  11.25   φ2 =  78.75   ρ est. = -0.70685
  766. --    φ1 =  22.50   φ2 =  90.00   ρ est. = -0.70667
  767. --    φ1 =  33.75   φ2 = 101.25   ρ est. = -0.70794
  768. --    φ1 =  45.00   φ2 = 112.50   ρ est. = -0.70561
  769. --    φ1 =  56.25   φ2 = 123.75   ρ est. = -0.70839
  770. --    φ1 =  67.50   φ2 = 135.00   ρ est. = -0.70680
  771. --    φ1 =  78.75   φ2 = 146.25   ρ est. = -0.70912
  772. --    φ1 =  90.00   φ2 = 157.50   ρ est. = -0.70708
  773. --    φ1 = 101.25   φ2 = 168.75   ρ est. = -0.70705
  774. --    φ1 = 112.50   φ2 = 180.00   ρ est. = -0.70685
  775. --    φ1 = 123.75   φ2 = 191.25   ρ est. = -0.70501
  776. --    φ1 = 135.00   φ2 = 202.50   ρ est. = -0.70737
  777. --    φ1 = 146.25   φ2 = 213.75   ρ est. = -0.70629
  778. --    φ1 = 157.50   φ2 = 225.00   ρ est. = -0.70789
  779. --    φ1 = 168.75   φ2 = 236.25   ρ est. = -0.70808
  780. --    φ1 = 180.00   φ2 = 247.50   ρ est. = -0.70736
  781. --    φ1 = 191.25   φ2 = 258.75   ρ est. = -0.70660
  782. --    φ1 = 202.50   φ2 = 270.00   ρ est. = -0.70670
  783. --    φ1 = 213.75   φ2 = 281.25   ρ est. = -0.70555
  784. --    φ1 = 225.00   φ2 = 292.50   ρ est. = -0.70606
  785. --    φ1 = 236.25   φ2 = 303.75   ρ est. = -0.70866
  786. --    φ1 = 247.50   φ2 = 315.00   ρ est. = -0.70820
  787. --    φ1 = 258.75   φ2 = 326.25   ρ est. = -0.70672
  788. --    φ1 = 270.00   φ2 = 337.50   ρ est. = -0.70769
  789. --    φ1 = 281.25   φ2 = 348.75   ρ est. = -0.70806
  790. --    φ1 = 292.50   φ2 = 360.00   ρ est. = -0.70728
  791. --    φ1 = 303.75   φ2 = 371.25   ρ est. = -0.70809
  792. --    φ1 = 315.00   φ2 = 382.50   ρ est. = -0.70531
  793. --    φ1 = 326.25   φ2 = 393.75   ρ est. = -0.70815
  794. --    φ1 = 337.50   φ2 = 405.00   ρ est. = -0.70800
  795. --    φ1 = 348.75   φ2 = 416.25   ρ est. = -0.70445
  796. --
  797. --********************************************************************
  798. -- Some instructions for the Emacs text editor.
  799. -- local variables:
  800. -- mode: indented-text
  801. -- tab-width: 2
  802. -- end:
  803.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement