{"id":34322473,"url":"https://github.com/dk14/bell","last_synced_at":"2026-05-27T08:34:08.943Z","repository":{"id":21432636,"uuid":"24750826","full_name":"dk14/bell","owner":"dk14","description":"experimental CHSH inequality violation using local hidden parameters","archived":false,"fork":false,"pushed_at":"2015-01-02T06:36:46.000Z","size":7672,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-21T00:43:36.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dk14.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-03T07:56:55.000Z","updated_at":"2024-09-04T12:50:25.000Z","dependencies_parsed_at":"2022-08-21T11:10:55.494Z","dependency_job_id":null,"html_url":"https://github.com/dk14/bell","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dk14/bell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk14%2Fbell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk14%2Fbell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk14%2Fbell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk14%2Fbell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dk14","download_url":"https://codeload.github.com/dk14/bell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk14%2Fbell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33558648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-17T14:25:57.069Z","updated_at":"2026-05-27T08:34:08.925Z","avatar_url":"https://github.com/dk14.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"#Bell's game\n\nThis is a simulation of [CHSH](http://en.wikipedia.org/wiki/CHSH_inequality) bell's inequality violation, assuming:\n\n- local realism, determinism - entangled particles are sharing some hidden parameter\n- particle knows about local measurement\n- no [loopholes](http://en.wikipedia.org/wiki/Loopholes_in_Bell_test_experiments) in detectors\n- using simple \"50%\" gaussian distribution instead of wave functions (they're just special case of gaussian).\n\nIt does not correlate with practical experiments (they've not been solved practical [loopholes](http://en.wikipedia.org/wiki/Loopholes_in_Bell_test_experiments) yet), but at least shows that it's logically possible to set up an ideal experiment that sometimes violates CHSH with local reality assumption and without any communication between participants or particles.\n\nSee [artcle](https://www.writelatex.com/read/sszqhnwsxydt) or [Q\u0026A](http://physics.stackexchange.com/questions/138691/is-it-enough-to-use-only-sigma-criterion-to-calculate-expected-value-for-ideal-b) for theoretical explanation.\n \n## Game rules\n\n\"I want to play a game...\"(c) Billy The Puppet \n\n1. Just pick up some statistically significant N (like 100 or 1000). \n2. Randomly choose detector setting (a/a', b/b') and some hidden parameter (H) for every sub-experiment (i.e. unique measurement). Encode detector setting as binary a-\u003e0, a'-\u003e1, b-\u003e0, b'-\u003e1. So you will have an array of detector settings, like A = 0010011101110... , B= 101101110110101... and array of hidden parameters, like H=01110110101100... \n3. Now you can built measurement statistic with simple rules: \n\n- at the detector A - you should always repeat hidden parameter, regardless which setting was used -  a or a' \n- at the detector B - hidden parameter is repeated only for B=0 setting. If B=1 (b') - you may choose strategy (use only one in same statistic):\n  - always return 0\n  - always return 1\n  - randomly return hidden parameter or inverted value of hidden parameter\n \nCalculate [S](http://en.wikipedia.org/wiki/CHSH_inequality) based on received statistic. You will get S \u003e 2  with 50% probability. So CHSH will be (pseudo-)violated without any non-local magic! \n\n\\* the only exception: N = infinity\n\n## MatLab simulation\n\n    function S = S(n)\n      AA_ = arrayfun(@(x) round(rand), 1:n); # randomly choose detector setting a or a’ (0 or 1 respectively)\n      BB_ = arrayfun(@(x) round(rand), 1:n); # randomly choose detector setting b or b’ (0 or 1 respectively)\n      notbb = arrayfun(@(x) mod(x + 1, 2), BB_); # invert BB_\n      H = arrayfun(@(x) round(rand), 1:n); #randomly choose hidden parameter (0 or 1)\n      A = H; #A always correlate with hidden parameter\n      H2 =  arrayfun(@(x) round(rand), 1:n).*notbb; # second hidden parameter\n      B = abs(H.-H2); # it's just XOR, alternative one-parameter based option - B = H.*BB_\n      PLAN = AA_.+(notbb.*2);\n      ABQC = (A(PLAN == 0) - B(PLAN == 0)); # choose only AB combos\n      AB = (size(find(ABQC == 0))(2) - size(find(ABQC != 0))(2)) / size(ABQC)(2); #calculate E(AB)\n      AB_QC = (A(PLAN == 2) - B(PLAN == 2));\n      AB_ = (size(find(AB_QC== 0))(2) - size(find(AB_QC != 0))(2)) / size(AB_QC)(2);\n      A_BQC = (A(PLAN == 1) - B(PLAN == 1));\n      A_B = (size(find(A_BQC== 0))(2) - size(find(A_BQC != 0)))(2)/ size(A_BQC)(2);\n      A_B_QC = (A(PLAN == 3) - B(PLAN == 3));\n      A_B_ = (size(find(A_B_QC== 0))(2) - size(find(A_B_QC != 0))(2)) / size(A_B_QC)(2);\n      S = AB - AB_ + A_B + A_B_; # calculate S\n    end\n    S(100)\n    \n    #graphics\n    X = @arrayfun(@S,meshgrid([1:15].*100))\n    surf(X)\n\\* checked with GNU Octave\n\n## Scala simulation\n\nThis section describes how to run simulator\n\nActions:\n\n1. Generating e.txt file with hidden parameters (you can make it read-only to ensure there is no tricks)\n2. Measuring A statistic using e.txt -\u003e and saving to A.log\n3. Measuring B statistic using e.txt -\u003e and saving to B.log (may be done on another machine)\n4. Analyzing results from A.log and B.log\n\nCommands:\n\n    # please, install Git and Java 8 before, \n    # MacOS, Linux or Git Cygwin Terminal is also preferred\n    git clone https://github.com/dk14/bell.git # or just download jar-file from WebUI\n    cd bell\n    # 1. Save 1000 particle entanglements (hidden parameters) to the e.txt file:\n    # (you may also copy it into another directory or computer to ensure non-communication)\n    java -jar bell.jar entangle 1000 \u003e e.txt \n    \n    # 2. Measure A particles 1000 times using random settings for detector\n    # * results will be saved into A.log\n    java -jar bell.jar measureA e.txt 1000 random \u003e A.log\n    \n    # 3. Do same for B -- you may run it on another computer\n    java -jar bell.jar measureB e.txt 1000 random \u003e B.log\n    \n    # 4. Use 'analize' command to analise correlations (or do it manually from A.log and B.log)\n    # * please move A.log and B.log to the same folder if these files were separated  \n    # SHCH says that S should be \u003c= 2, so inequality violated only if you received S \u003e 2\n    # if still not violated - just try to measure A and B again :-)\n    java -jar bell.jar analize A.log B.log\n    \n    # You can also choose your own polarization states instead of pseudorandom - i used http://qrng.anu.edu.au/\n    # 6 - is a number of tacts with continuous (same in current period of time) detector's setting\n    # 101010100 means aa'aa'aa'aa'a' or bb'bb'bb'bb'b' depending what you're measuring\n    # result will be saved to myA.log\n    java -jar bell.jar measureA e.txt 6 1010110110101011011010110 \u003e myA.log\n    \n    # you can also simulate man-in-the-middle by using different entanglement file for measureB (cause measuring leads to corruption)\n    # statistic will be much different and always \u003c= 2 \n\n\nLinks: \n\n- http://en.wikipedia.org/wiki/CHSH_inequality\n- http://en.wikipedia.org/wiki/Fr%C3%A9chet_inequalities\n- http://en.wikipedia.org/wiki/Loopholes_in_Bell_test_experiments\n- http://plato.stanford.edu/entries/bell-theorem/\n- http://qrng.anu.edu.au/ - randomizer\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdk14%2Fbell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdk14%2Fbell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdk14%2Fbell/lists"}