Quantum Mechanics for Programmers

(c) 2009 Kim Øyhus

Quantum Mechanics will be explained by using simple program examples instead of the mathematical notations physicists tend to use. These examples will be in C, but could just as well be in LISP. C is chosen because it is the mother of many similar languages, and because it has compact syntax suited here, and because it is my favourite language.

Q.M. & Science

Quantum Mechanics is terribly confusing, even for a physicist like me. The reasons for this is its deep mind blowing concepts, as well as physicist culture of ignoring science, specifically Ockhams Razor and the connection to reality. More about that later.

Since you are a programmer, you do not know what science is, even though you may believe you do. A hint: Computer science does not contain science, just mathematics. I better tell you what science is:

Science

  • Science is finding better explanations.
  • An explanation is better if it describes reality better. (Falsification)
  • An explanation is better if it is shorter. (Ockhams razor)

    Other words for explanation is theory, hypothesis, model, description, map, program, etc. All these words have in common that use the concept of using something similar to something else instead of that something else, such as drawing lines on a map instead drawing really big lines in nature.

    As a programmer you know the Model-View-Control pattern, in which the "model" is not a model, because it is not an explanation, or theory. It might be, but typically isn't. This habit of using words totally differently from what they mean, is very typical for programmers, so just have in mind that you may have to re-interpret what you read in physics because the words mean something different from what you are used to. (Just like programmers call maps of pixels for BitMaps, and maps of bits for "bit fields".)

    The point of using models is to represent reality somehow. A good example of this is temperature, which is a deep concept with connections far into information theory. It is a function of the entropy in a place, and is a single positive number.

    Temperature is a good model, because it describes reality well. It is also a good model because it is very short, just a single number. Most models in physics are more complicated than this, but still simple from an absolute point of view, though not from a human point of view, since simple stuff can be incomprehensible, of which there are a lot of examples in math, such as the Goldbach Conjecture.

    Temperature diffusion

    A realistic model for temperature at more than one place at more than one time, is this:

     float 
    U[ 1000 ][ 1000 ];
    ...
    for(   t=0;  t<1000;  t++)
      for( x=0;  x<1000;  x++)
            U[ t+1 ][ x   ]  =
         (  U[ t   ][ x-1 ]
         +  U[ t   ][ x   ]
         +  U[ t   ][ x+1 ] ) / 3. ;
    
    As you can see, this program is quite simple. This model has 1000 positions, each with 1000 instants of time, as compared with just 1 number at one position in one instant for a single temperature measurement.

    It can quite accurately describe the temperature changes in a metal rod, where "x" is the distance along the rod in some unspecified unit, and "t" is the time in some unspecified unit.

    Waves

    Here is a model of waves, as in light or sound, but not as in water waves or electron waves:
     float 
    U[ 1000 ][ 1000 ];
    ...
    for(   t=0;  t<1000;  t++)
      for( x=0;  x<1000;  x++)
    
            U[ t+1 ][ x   ]  =
         -  U[ t-1 ][ x   ]
         +  U[ t   ][ x+1 ]
         +  U[ t   ][ x-1 ] ;
    
    As you can see, it is very similar. The behaviour is quite different, as waves propagate, while heat diffuse.

    These models would have been better if they were 3 dimensional, as the Universe is, or as we physicists say: 4 dimensional, as time is a dimension, which will be clear in this program for 3D wave propagation:

     double 
    U[ 1000 ][ 1000 ][ 1000 ][ 1000 ];    /* Note: 4 dimensions */
    ...
    for(       t=0;  t<1000;  t++)
      for(     x=0;  x<1000;  x++)
        for(   y=0;  y<1000;  y++)
          for( z=0;  z<1000;  z++)
    
            U[ t+1 ][ x   ][ y   ][ z   ]  =
         -  U[ t-1 ][ x   ][ y   ][ z   ]  * c
         +  U[ t   ][ x+1 ][ y   ][ z   ]  * c
         +  U[ t   ][ x-1 ][ y   ][ z   ]  * c
         +  U[ t   ][ x   ][ y+1 ][ z   ]  * c
         +  U[ t   ][ x   ][ y-1 ][ z   ]  * c
         +  U[ t   ][ x   ][ y   ][ z+1 ]  * c
         +  U[ t   ][ x   ][ y   ][ z-1 ]  * c
         -  U[ t   ][ x   ][ y   ][ z   ]  *(c*7-1) ;
    
    "c" is the adjustable speed of the waves. It must be small for the math to be stable.

    Note that each value is calculated from earlier and neighbouring values while the time coordinate "t" is increasing. It would work equally well if time went backwards, and this is a property of all such models, and reality as well apparently. This model could also be calcualted sideways. The electron models cannot be calculated sideways.

    The equivalent program for the quantum mechanical wave for an electron is:

     double complex
    U[ 1000 ][ 1000 ][ 1000 ][ 1000 ];    /* Note: 4 dimensions */
    ...
    for(       t=0;  t<1000;  t++)
      for(     x=0;  x<1000;  x++)
        for(   y=0;  y<1000;  y++)
          for( z=0;  z<1000;  z++)
    
            U[ t+1 ][ x   ][ y   ][ z   ]  +=  1.i * (
         -  U[ t   ][ x+1 ][ y   ][ z   ]
         -  U[ t   ][ x-1 ][ y   ][ z   ]
         -  U[ t   ][ x   ][ y+1 ][ z   ]
         -  U[ t   ][ x   ][ y-1 ][ z   ]
         -  U[ t   ][ x   ][ y   ][ z+1 ]
         -  U[ t   ][ x   ][ y   ][ z-1 ]
         +  U[ t   ][ x   ][ y   ][ z   ]  * 6       
         +  V( t,     x,     y,     z   )            );
    
    This is the Schrödinger wave equation for a single electron and a potential, V.

    Note that the fundamental structure is now complex numbers. Quantum Physics books often claim that Quantum Mechanics works on general vector fields. For us having studied cryptography or group theory, this can be terribly confusing, because it is not true. Quantum Mechanics only use complex numbers as base for all its structures. On top of this base however, there can be many different groups.

    The electron is not in a single place, but instead spread out over all the positions, more or less. This is called "superposition". When the electron is observed, it suddenly appears at a single random place. The probability P of observing the electron each place is calculated this way:

    for(       t=0;  t<1000;  t++)
      for(     x=0;  x<1000;  x++)
        for(   y=0;  y<1000;  y++)
          for( z=0;  z<1000;  z++)
    
            P[ t ][ x ][ y ][ z ]  =
            U[ t ][ x ][ y ][ z ]  *
      conj( U[ t ][ x ][ y ][ z ]  );
    
    Note: I have not specified what an observation actually is, and neither does almost all physics textbooks. Quite frustrating.

    Simplifications

    These examples have used cubes with a width of 1000 voxels, and of 1000 time instants. The Universe use a width of something like 10^70 voxels. The same goes for time.

    The size of these program voxels is also quite arbitrary. It is necessary to scale them to be physically correct. For the actual values, study Quantum Mechanics, or find it in Wikipedia. I dropped it to simplify the code. The basis structure in all these examples were ordinary arrays, which are square in their lattice structure, but other structures work as well, such as hexagonal packings and different sphere packings.

    I dropped polarization of light, and spin of electrons. The array with the electron wave would become:

     double complex
    U[ 1000 ][ 1000 ][ 1000 ][ 1000 ][ 2 ];    /* Note: 5th small dimension of 2 spins */
    
    The calclations are more complicated as well.

    Then there are the simplifications in the physics models these programs are based on. The Schrödinger wave equation is not relativistic, and it only models a single electron. Apart from that, it is reasonably accurate.

    To get a relativistic electron wave model, we have the "Dirac Equation". Its array structure would be:

     double complex
    U[ 1000 ][ 1000 ][ 1000 ][ 1000 ][ 4 ];    /* Note: 5th small dimension of 2 spins and positrons */
    
    The meaning of the "4" at the end is that each space-time point can contain electrons with 2 different spins, and positrons with 2 different spins too. The calcualtions becomes more complex, with a lot of 4x4 matrixes. The values also has a tendency to blow up due to negative energy of positrons, which is odd, because positrons have positive energy in reality. Apart from that, it give quite, but not entirely, accurate results.

    Another oddity is that it does not have a constant number of particles in it.

    Many Particles

    It is nice to be able to accurately model single particles, but reality is more complex than that. Phenomena like computers and observations must use many-particle models.

    The smart programmer would guess at a model containing more complex math that will get the array to model several particles, but no such thing exists.

    A smarter and a little insane programmer might guess at a model where there is a separate 4D space for each particle, with these spaces interacting. It would be something like this:

     double complex
    U[ 1000 ][ 1000 ][ 1000 ][ 1000 ][ 4 ][ 12 ];    /* Note: 12 particles to be modeled */
    
    However, that is neither smart nor insane enough to make accurate models. Something far beyond that is necessary:

    Ouch!!!!

    This model models a 5x5x5 voxel cube of 5 consequtive time instants:
     double complex
    U[16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
    
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
    
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
    
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
    
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  
     [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16]  [16][16][16][16][16];
    
    /* Note: 5*5*5*5 dimensions!!!! */
    
    #define u(x)  U[ x[0][0][0][0] ][ x[0][0][0][1] ][ x[0][0][0][2] ][ x[0][0][0][3] ][ x[0][0][0][4] ]  \
                   [ x[0][0][1][0] ][ x[0][0][1][1] ][ x[0][0][1][2] ][ x[0][0][1][3] ][ x[0][0][1][4] ]  \
                   [ x[0][0][2][0] ][ x[0][0][2][1] ][ x[0][0][2][2] ][ x[0][0][2][3] ][ x[0][0][2][4] ]  \
                   [ x[0][0][3][0] ][ x[0][0][3][1] ][ x[0][0][3][2] ][ x[0][0][3][3] ][ x[0][0][3][4] ]  \
                   [ x[0][0][4][0] ][ x[0][0][4][1] ][ x[0][0][4][2] ][ x[0][0][4][3] ][ x[0][0][4][4] ]  \
                                                                                                          \
                   [ x[0][1][0][0] ][ x[0][1][0][1] ][ x[0][1][0][2] ][ x[0][1][0][3] ][ x[0][1][0][4] ]  \
                   [ x[0][1][1][0] ][ x[0][1][1][1] ][ x[0][1][1][2] ][ x[0][1][1][3] ][ x[0][1][1][4] ]  \
                   [ x[0][1][2][0] ][ x[0][1][2][1] ][ x[0][1][2][2] ][ x[0][1][2][3] ][ x[0][1][2][4] ]  \
                   ...
                   [ x[4][4][3][3] ][ x[4][4][3][1] ][ x[4][4][3][2] ][ x[4][4][3][3] ][ x[4][4][3][4] ]  \
                   [ x[4][4][4][0] ][ x[4][4][4][1] ][ x[4][4][4][2] ][ x[4][4][4][3] ][ x[4][4][4][4] ]
    
    int  x[5][5][5][5];    /* 5x5x5x5 loop variables and loops!!!! */
    
    ...
    
    for( x[0][0][0][0] = 0;  x[0][0][0][0] < 16;  x[0][0][0][0]++ )
    for( x[0][0][0][1] = 0;  x[0][0][0][1] < 16;  x[0][0][0][1]++ )
    for( x[0][0][0][2] = 0;  x[0][0][0][2] < 16;  x[0][0][0][2]++ )
    for( x[0][0][0][3] = 0;  x[0][0][0][3] < 16;  x[0][0][0][3]++ )
    for( x[0][0][0][4] = 0;  x[0][0][0][4] < 16;  x[0][0][0][4]++ )
    
    for( x[0][0][1][0] = 0;  x[0][0][1][0] < 16;  x[0][0][1][0]++ )
    for( x[0][0][1][1] = 0;  x[0][0][1][1] < 16;  x[0][0][1][1]++ )
    for( x[0][0][1][2] = 0;  x[0][0][1][2] < 16;  x[0][0][1][2]++ )
    for( x[0][0][1][3] = 0;  x[0][0][1][3] < 16;  x[0][0][1][3]++ )
    for( x[0][0][1][4] = 0;  x[0][0][1][4] < 16;  x[0][0][1][4]++ )
    
    for( x[0][0][2][0] = 0;  x[0][0][2][0] < 16;  x[0][0][2][0]++ )
    ...
    for( x[4][4][4][4] = 0;  x[4][4][4][4] < 16;  x[4][4][4][4]++ )
      {
        int n0, n1, n2, n3;
    
        /* This is the part that does interactions between different numbers of particles. */
    
        for( n0=0; n0<16; n0++)
        for( n1=0; n1<16; n1++)
        for( n2=0; n2<16; n2++)
        for( n3=0; n3<16; n3++)
          {
            int  a[5][5][5][5];
    
            /*      a = x            */
            memcpy( a,  x, sizeof(x) );
    
            double complex s = 0.;
            int n;
            for( n=0; n<16; n++)
              {
                a[n0][n1][n2][n3] = n;
                s += O[ x[n0][n1][n2][n3] ][n] * u(a);
              }
    
        /* This is the part that does interactions in the 4 spatial directions t, x, y, z. */
            
            memcpy( a, x, sizeof(x) );
            a[n0  ][n1][n2][n3] = x[n0+1][n1][n2][n3];
            a[n0+1][n1][n2][n3] = x[n0  ][n1][n2][n3];
            s += O1 * u(a) + O2 * u(x);
    
            memcpy( a, x, sizeof(x) );
            a[n0][n1  ][n2][n3] = x[n0][n1+1][n2][n3];
            a[n0][n1+1][n2][n3] = x[n0][n1  ][n2][n3];
            s += O1 * u(a) + O2 * u(x);
    
            memcpy( a, x, sizeof(x) );
            a[n0][n1][n2  ][n3] = x[n0][n1][n2+1][n3];
            a[n0][n1][n2+1][n3] = x[n0][n1][n2  ][n3];
            s += O1 * u(a) + O2 * u(x);
    
            memcpy( a, x, sizeof(x) );
            a[n0][n1][n2][n3] = x[n0][n1][n2][n3+1];
            a[n0][n1][n2][n3] = x[n0][n1][n2][n3  ];
            s += O1 * u(a) + O2 * u(x);
    
            u(x) = s;   /* If solution is correct, then there is no change of value here */
          }
      }
      ...
    
    As you can see, it uses an insane amount of memory, of about 16^(5^4) which is similar to 10¹°°° . The array of loop variables is an entire universe in itself, or state as it is usually called. In short, this U array contains all possible 5x5x5x5 4D voxel universes. Each dimension corresponds to a single voxel, and its 4 states of spin and electron/positron possibility. There are 16 combinations of spins and electron and positron at each voxel.

    Remember, this is not an accurate representation of the model, but just a code example ment for you to get the structure of it.

    I have not yet gotten around to writing down the actual details of mathematical interaction part of this insane but realistic and accurate model. Neighboring universes/states interact. That is, the calculations are dependent on neighbors not just in position and time, but in number of particles as well. So a situation is dependent not just on the particles that actually are there, but on extra particles in neighboring universes as well. There is almost always leakage of probability and waves into neighboring universes. So this is the meaning of "The Many Worlds Interpretation."

    Quantum Electro Dynamics

    Another problem with this model is this: In which order should it be calculated? For the other models an answer was easy: Calculate it forwards in the time direction! For this model there are 5 time directions, of which none is special. If the model is correct, then the values in U will not change when the program is run. This is very typical of physical formulas, but not very helpful when one wants to find these values.

    Richard Feynman got the nobel prize for figuring out a way of doing this. His Quantum Electro Dynamics is a sort of dynamic programming method, where he started by putting up the known parts of a model, such as an electron in a magnetic field, and then proceeded by going back and forth through the numerous dimensions, adding calculated values where they give highest values first. In practice this starts by going forwards and backwards in space and time, and then adding particles that appear, do stuff, and disappear. The result is the lone electron interacting with virtual particles, giving it a little more magnetism than it would otherwise have.

    Light can also be considered as an effect of these virtual particles, as a differential probability wave. In practice, light is usually treated as a thing in itself to ease calculations.

    Single Electrons again

    So, where would a single electron model be inside this big model?

    One example is this:

    U[0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][1][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0] = 1;
    
    Can you see it? Hint: It is in the same voxel in all 5 instants. Look for the 1's in the indexes. But of course, a real electron would hardly stand still like that. Real electrons smear out over several states. One example of that would be a superposition of this and another state, like this:
    U[0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][1][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0] = .7;
    
    U[0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][1][0]  [0][0][0][0][1] <--here!
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
    
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  
     [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0] = .7i;
    
    In other words, an electron that gets a little smeared out at the last instant.

    Electron symmetries

    You might have heard that electrons are fundamentally the same, and that they have this weird Pauli exclusion principle, where it is impossible for 2 electrons of the same spin to be in the same place, or state. Well, as you can see from this model, this is indeed true. Here is a single line of code representing 2 similar electrons in different places:
     [0][1][0][0][1]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]
    /*   .        .                                                                    */
    
    As you can see, the electrons are indexes, and it is impossible to have 2 numbers in the same index, since an index is just one number. This is the Pauli exclusion principle in this model. If broken, it would become something like this:
     [0][1,1][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]  [0][0][0][0][0]
    /*   . .                                                                    */
    
    ... which is completely meaningless. It is not C code, and the corresponding math is equally meaningless.

    If one wants to simulate just 2 electrons, ignoring the neighboring states with more, one can separate out all the states containing just 2 used indexes, like the first example here. One would then get an 8 dimensional array, since there are 4 dimensions per particle, and it would be symmetrical in the placement of the electrons, i.e. there would be no way of changing them. The same goes for 3 electrons, except there would be 12 dimensions of space-time, cut up into 1/6 of a full 12 dimensional space due to the 6 ways that electrons can change place. Or to say it another way: When 3 indexes of 5*5*5 can be 1, there are about (5*5*5)^3 / 3! ways of doing it.

    We get something very like the many-particle Schrödinger wave equation, with all its symmetries.

    Matrix confusions

    As you have seen, all these programs/models use simple algebra, so everything could have been written as vectors and matrixes instead of programs. The U array could be the vector, and its updating could be the matrix. Of course U is a rather large vector, and the updatings would be large sparse matrixes, except for the Q.E.D. model, where the vector U is perversely absurdly large, and the matrixes even more so, and extremely sparse.

    When matrixes on vectors get this large, they behave like operators on functions, such as derivation, integration, convolution, etc. The vectors go from being arrays of numbers to being more like continuous functions. It is like increasing the resolution of a picture.

    And then there is the trick of multiplying everything by a matrix you like, just to make the model nicer and easier to solve. Both U and its rules of change or constantness can be transformed this way into something else, without actually changing the models behaviour. One example of such a matrix is the fourier transform. It changes positions into momentum, and pulses of light into colours. Another example is the orbitals of atoms, giving the chemical structures of matter.

    Ockhams Razor

    Many physicists like to believe that this makes the underlying model irrelevant; that the matrix behaviour, its eigenvalues, is the only thing that matter. You will encounter lots of this in books about Quantum Mechanics. This however is not science, because it ignores Ockhams Razor; the models shall be the simplest ones. A sparse matrix is simpler than when it is Fourier transformed, or put into atom orbitals. (I thank Eliezer Yudkowski who gave a reminder that Ockhams razor belongs here too.)

    Matrix Mechanics is however very useful for actually calculating stuff in Quantum Mechanics.

    Falsification

    Another problem with textbooks in Quantum Mechanics is that they tend to ignore reality. They do stuff like pretending to deduce the Dirac wave function from the Schrodinger wave function combined with spin and relativity, or to get many-particle models from a creator-annihilator matrix representation of nearly harmonic oscillators.

    What these books seem to misunderstand, is that physics is science, not math. In science one guesses at explanations. One does not deduce them like one do in math. The physicists who actually did this stuff apparently knew this, and considered the math more akin to toying with the models to see what happens, to see if they could get better models, and they thus got better models that modeled more accurately, while being simple. The text book authors are at fault for presenting this wrongly as mathematical deductions.

    These books also tend to ignore actual experiments and the reality that these models are supposed to represent. Lots of sloppy mathematics, and barely mentioning that electron spins can be measured by throwing them through a magnetic field.

    Observation

    Another omission they all do is avoiding to define what observations are. Feynman was better, since he at least admitted this.

    All we get served, is that to get the probabilites when observing, one must take the wave function multiplied by its complex conjugate. I was very frustrated by this when I studied, and when I finally understood Quantum Mechanics for many particles, I modeled an observer in the form of a universal computer observing a particle being in a superposition of reflected and not reflected, and saw in the answer that Hugh Everett was right: The wave function splits into two different universes/states, including the observer. There are now a superposition of 2 observers; one having observed the reflected particle, and one observing the lack of a reflected particle. See here for details of that.

    Recommendation

    Read Feynman and the originals.

    Richard Feynman is widely known for his good books, which avoid these mistakes. Other renowned scientists writing about their own stuff typically do so very well too. Even Charles Darwins "Origin of the Species" is easy to read and understand. Another example is the C language book by Kernighan and Ritchie. Later writers tend to misinterpret and bungle and distort and ignore parts, making stuff more confusing.

    Changelog

    2009.12.30 First partial version.
    2009.12.31 Added book critiques.
    2010.01.03 Added big interactions in the big code.
    Any comment?