The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tangle - a quantum state machine

SYNOPSIS

     use Tangle;
     my $q1 = Tangle->new(1,0);
     print "q1 = $q1\n";
     $q1->x_gate;
     print "X(q1) = $q1\n";
     $q1->hadamard;
     print "H(X(q1)) = $q1\n";
    
     my $q2 = Tangle->new(1,0);
     print "q2 = $q2\n";
    
     # perform CNOT($q1 ⊗ $q2)
     $q1->cnot($q2);
    
     print "q1 = $q1\n";
     print "q2 = $q2\n";
    
     $q1->x_gate;
     print "X(q1) = $q1\n";
     print "entanglement causes q2 to automatically changed: $q2\n";

DESCRIPTION

     Create quantum probability states in classic memory.
     Preform quantum gate manipulations and measure the results.
     Ideal for testing, simulating and understanding quantum programming concepts.

USAGE

new()

     # create a new Tangle object in the |0> state ...
     my $q1 = Tangle->new(0,1);

cnot()

     # tensors this object onto the given one and flip the second half accordingly ...
     my $q2 = Tangle->new(0,1);
    
     # q1 ⊗ q2
     $q2->cnot($q1);
    
     # both $q and $q2 are now sharing memory so that changes to one will effect the other.

*_gate()

     * functioning gates are x, y, z, i and sometimes cnot.
     
     # unitary gate functions ...
     
     $q->x; # x-gate
     $q->y; # y-gate
     $q->z; # z-gate
     $q->i; # identity
    
     # partially operational gates ...
     
     $q->cnot;
     $q->swap;
    
     # other common gates ...
     # context: https://en.wikipedia.org/wiki/Quantum_logic_gate 
     
     $q->h;     # hadamard
     $q->xx;    # isling (xx) coupling gate
     $q->yy;    # isling (yy) coupling gate
     $q->zz;    # isling (zz) coupling gate
     $q->u;     # universal gate... quantum cheating
     $q->d;     # deutsch gate ... not in the real world yet.
     $q->cx;    # controlled x-not = cnot() gate
     $q->cy;    # controlled y-not
     $q->cz;    # controlled z-not
     $q->cs;    # controlled swap gate 
     $q->rswap; # root swap
     $q->rnot;  # root not
     $q->ccnot; # toffoli gate

state()

     # square of the coefficients of this number.
     # or ... the probability states as percentages for each outcome (seeing a 1 in that location if you looked).
     
     my $i = 0;
     print "chance of outcome:\n";
     foreach my $percent (@{$q->state}) {
        $i++;
        print "$i: $percent%%\n";
     }

raw_state()

     # state of raw amplitudes as an array reference ...
     printf "The coefficients of q: [%s]\n", join(', ', @{$q->state};

measure()

     # a singular measure based on the current probability state.
     printf "The answer is: %s\n", $q->measure

measures()

     # a set of singular measures returned as a hash
     # the keys match the actual measurements found
     # and the values of those keys is the number of times that measure was found in the set
     # first parameter is the number of measures you want to preform ...
     
     foreach my $measured ( keys %{$q->measures(1000)} ) {
        printf "Measured '%d': %d times\n", $measured, $q->{measures}->{ $measured };
     }

SUMMARY

     The goal of this project is to provide a minimal universal quantum emulator for coders.
    
     Conceptually, things are numbers or objects. Every objects contains two numbers or two objects. 
    
     If an object contains two numbers it must be complex. If an object contains four numbers it must contain two more objects where each sub-object contains 2 numbers, so that your original number has 4 numbers deeper within it. If an object contains more numbers it must contain more depth and pairs of objects contain pair of objects and so on and so on.
    
     Objects of any size can add, multiply, subtract and divide with one another.
    
     Objects can be tensored which is similar to storing the products of associative multiplication without completing the summation.
      ie: real number multiplication: (a+b) × (c+d) = ac + ad + bc + bd
                      tensor product: (a,b) ⊗ (c,d) = ac,  ad,  bc,  bd
    
     A gate is a rotational transformation. Rotation transformations are represented by invertible matrix which are there own inverse and can be represented by a Cayley Dickson number.
    
     Objects contain Cayley Dickson number representations, so gates are Tangle objects as well.
    
     Using a gate with 2 or more inputs will put your state into superposition, so that we can not gleen the individual qbit states from the given probability distribution.
    
    
     Output from binary gates will be objects with 4 numbers, which are attached to the output in a manner which represents lesser and greater binary control over its future changes.
    
     We cannot determine the individual states of the input qbits to set them after the gate transformation, we need to attach the input qbits to the gate output so that they each share the same output in different ways.
    
     Quantum gates are laid out in series, one after the other. Shared memory from the output of one gate needs to be maintained when an entangled qbit is subsequently put through another gate. This is done by taking the partial products of the gate and its inputs and then stitching that output back to the ends of the existing input ends.
    
     A qbit and its gate have no way of knowing whether another variable is sharing its memory, there is no way to update the one without destroying the connection to the other. Since the existing ends could be shared already with existing entangled qbits, the connection between an objects and number needs to be expanded. In this code we preform this by having 3 pointer references between each object and number. This allows two entangled variables to remain entanglment after one of them is put through a gate and its value is changed accordingly.
    
     An object is an array containing a pair triple references to either another object or to a number. This represents a Cayley Dickson number which is used to represent the probability state of a quantum computer. The square of the coefficient (number) in each dimension of this object is the probability of seeing a 1 there if you measured in that state. The probabilities of a quantum computer can be thought of as rotations in high dimensions. Cayley Disckson numbers rotate in high dimension by multiplying together.
    
     Quantum gates can be represented by static Cayley Dickson numbers and multiplied by existing states in order to produce outputs. In other words, the object used to store your quantum probability state is the same object used to represent quantum gates. ie: this object. Binary quantum gates produce unreduced outputs that are stitched back onto the ends of the inputs with links that share those numbers in different orders. There is seperation between objects and numbers so a number be split into two numbers and all other qbits previously sharing the original number will also automatically share the two new numbers as well.
     
    
     # Sample quantum program:
     #
     # This simple example will result in a measurement of |00> or |11> showing entanglement
     # where the measure of one qbit will always equal the second.
    
     my $q1 = Tangle->new(1,0);
     my $q2 = Tangle->new(1,0);
     $q1->hadamard;
     $q1->tensor($q2);
     printf "measured: %d\n", $q2->measure;

AUTHOR

 Jeff Anderson
 truejeffanderson@gmail.com