Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Lunatic program on Linux and Smaky ?

  1. Sep 2, 2016 #1
    I'm simulating Bell's theorem of quantum mechanics on a PC. I have guests Linux and Smaky systems and wrote codes in resp. C and Basic doing basically the same but obtain different results on both systems. On Linux the results of CHSH oscillate around 2, while on the Smaky it's always above 2 ?

    Code (C):


    #define PI 4.0*atan(1.0)

    double cof=.8;
    double eps=.00001;
    double omega=200.0;

    double MAX_INT=4294967296.0/2.0-1.0;

    //local function for the result in A depending on the angle of measurement and the parameter

    int A(double angle, double lambda)
       int resa=0;
       double pa=0.0, choice=0.0;

      //set probabilities

       if(pa<eps) pa=eps;
       if(pa>1.0-eps) pa=1.0-eps;

       //choose +/- for A



    //local deterministic result in A

    int A(double angle, double lambda)
       int resa=0;
       double v=cos(angle-lambda);


    int main(void)
       int a,b,ap,bp;

       int i=0;
       int na=0,nb=0;
       double choice;
       double anga,angb,angap,angbp,maxangb;
       double phi;
       double cov1=0.0,cov2=0.0,cov3=0.0,cov4=0.0;
       int vrmax=20000;
       int angdiv=100;
       int vrmin=10;
       int resa, resb;

       int avga1,avga2,avga3,avga4,avgb1,avgb2,avgb3,avgb4;


       double avgcov1=0.0, avgcov2=0.0, avgcov3=0.0, avgcov4=0.0;
       FILE *varout;



       bool stop=false;


       double maxavgs=-6.0;
       double maxcof=0.0;

       double avgs,pm4f,pm2f,pzf,p2f,p4f,sumpf;
       int S=0;

       //for(int j=0;j<angdiv;j++)
       //   angb=PI*(double)j/(double)angdiv;

       int pm4=0,pm2=0,pzero=0,p2=0,p4=0;

    //calculate probabilities of -4 -2 0 2 4 :

         int resa,resb;








           case -4 : pm4++; break;
           case -2 : pm2++; break;
           case 0 : pzero++; break;
           case 2 : p2++; break;
           case 4 : p4++; break;

         if(i>=vrmax-1) stop=true;

       //probabilities of measurement results floating



       //compute maximal average of S taking into account the variance


       //fprintf(varout,"%lf %lf %lf\n",cof,avgs,fabs((double)S/(double)vrmax));

       fprintf(varout,"%lf %lf %lf\n",angb,avgcov1/(double)i,avgs);

       }  //end loop angdiv

       printf("p-4=%lf p-2=%lf p0=%lf sumprob=%lf\n",pm4f,pm2f,pzf,sumpf);  
       printf("S=%lf Covariances : %lf %lf %lf %lf\n",(double)S/(double)vrmax, avgcov1/(double)vrmax, avgcov2/(double)vrmax, avgcov3/(double)vrmax, avgcov4/(double)vrmax);  

       printf("maxavgS=%lf angb=%lf\n",maxavgs, maxangb);
    Here S oscillate and can be smaller than 2.

    In Basic I wrote the same algorithm for Smaky emulating a 68040 processor.

    In the latter the result is always above 2, namely around 2.08.

    What could explain this difference ? Could it be that the skewness is positive so that by simulating it we obtain a numerical average higher ?

    Then why would the Linux program give other results ?
  2. jcsd
  3. Sep 2, 2016 #2


    Staff: Mentor

    Number precision may be the reason.


    and for C


    Check to see if you are using the same/equivalent datatypes.

    Also each language may be using a different implementation of numerical methods each with its own peculiarities.

    You could try implementing it in MATLAB or in Python (see the Anaconda distribution for prepackaged python numpy and scipy modules).

    I had a similar experience years ago when I implemented a simple "what day of the week" from a date algorithm in several languages including fortran and honeywell basic for a Boy Scouts Explorer open house.

    One mother put in her son's birthday in each program. One said Sunday and said Monday and she wanted to know why and I humorously said maybe he was born at midnight. She was not amused, told her husband who turned out to an upper level computer center manager for my site and I never heard the end of it.

    The moral: No good deed goes unpunished.

    Upon investigation, I found one language rounded up and the other had truncated the answer. The algorithm expected the rounding up to work correctly.
    Last edited: Sep 2, 2016
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: Lunatic program on Linux and Smaky ?
  1. Learn linux (Replies: 6)