javamathquantum-computingqubit

Apply n qubits to a Hadamard Gate


First of all sorry for the long text, I tried to explain my problem / misunderstanding as good as possible.

For my student project I have to implement a simulation of a simple Quantum Computer. What I am trying to understand right now is how different Gates are getting applied to n-qubits, bit by bit.

For example one qubit gets represented by two complex numbers (a1, a2) :

a1 |0> + a2 |1>

Where a1 and a2 are the amplitudes - the possibilities that a value is meassured. All amplitudes squared and summed must always be equal to 1.

So i added a Hadamard Gate, represented by its 2x2 Matrizes

public void Hadamard(){
  gate.entries[0][0] = new ComplexNumber(1,0);
  gate.entries[0][1] = new ComplexNumber(1,0);
  gate.entries[1][0] = new ComplexNumber(1,0);
  gate.entries[1][1] = new ComplexNumber(-1,0);
  gate = (Matrix.scalarMultiplication(gate,Math.pow(2,-0.5)));
}

Now I would make a Matrixmultiplication with the a1 and a2 with a Hadamard gate.

So I set up a register as a two dimensional array of complex numbers representing the states of the bit as :

Register register = new Register(1); 

Where the number represents the number of qubits. We only create one row holding all our states and the index of the columns equals the state. So e.g.

[0][0] = |0> and [0][1] = |1> 

If we say that a1=1+0i and a2=0+0i the multiplication would look like this :

 cmplx1 = cmplxMultiplicate(gate.entries[0][0],a1);
 cmplx2 = cmplxMultiplicate(gate.entries[0][1],a2);
 cmplx3 = cmplxMultiplicate(gate.entries[1][0],a1);
 cmplx4 = cmplxMultiplciate(gate.entires[1][1],a2);
 register.entries[0][0] = cmplxAddition(cmplx1,cmplx2); // 0.70710678118
 register.entries[0][1] = cmplxAddition(cmplx3,cmplx4); // 0.70710678118

Now comes the question - I have no idea how to do this if we have more than one Qubit. For example at two Qubits I would have

a1 |00> + a2 |01> + a3 |10> + a4 |11> 

Four different states (or 2^(numberOfQubits) states for any given number). But how could i now apply all 4 States to my Hadamard Gate ? Do i have to make all possible outcomes where i multiply a1 with every value, than a2 etc. etc. ? Like this :

 cmplx1 = cmplxMultiplicate(gate.entries[0][0],a1);
 cmplx2 = cmplxMultiplicate(gate.entries[0][1],a2);
 cmplx3 = cmplxMultiplicate(gate.entries[1][0],a1);
 cmplx4 = cmplxMultiplciate(gate.entries[1][1],a2);
 cmplx1 = cmplxMultiplicate(gate.entries[0][0],a1);
 cmplx2 = cmplxMultiplicate(gate.entries[0][1],a3);
 cmplx3 = cmplxMultiplicate(gate.entries[1][0],a1);
 cmplx4 = cmplxMultiplciate(gate.entries[1][1],a3);

I am really clueless about this and i think there is a fundamental misunderstanding on my site that makes things so complicated for me.

Any help leading me on the right way / track would be really appreciated.

Thank you very much.


Solution

  • Note that https://en.wikipedia.org/wiki/Hadamard_transform#Quantum_computing_applications writes:

    It is useful to note that computing the quantum Hadamard transform is simply the application of a Hadamard gate to each qubit individually because of the tensor product structure of the Hadamard transform.

    So it would make sense to just model a single gate, and instantiate that a number of times.

    But how could i now apply all 4 States to my Hadamard Gate ?

    The gate would get applied to all 4 states of your 2-qubit register. It would operate on pairs of coefficients, namely those which only differ in a single bit, corresponding on the bit position to which the gate gets applied.

    If you want to go for the larger picture, apply the Hadamard operation first to the left qubit

    ((|00〉 + |10〉) 〈00| + (|00〉 − |10〉) 〈10| + (|01〉 + |11〉) 〈01| + (|01〉 − |11〉) 〈11|) / sqrt(2)

    and then to the right qubit

    ((|00〉 + |01〉) 〈00| + (|00〉 − |01〉) 〈01| + (|10〉 + |11〉) 〈10| + (|10〉 − |11〉) 〈11|) / sqrt(2)

    Writing this as matrices with your order of coefficients (first step right matrix and second step left matrix) you get

      ⎛1  1  0  0⎞ ⎛1  0  1  0⎞     ⎛1  1  1  1⎞
      ⎜1 -1  0  0⎟ ⎜0  1  0  1⎟     ⎜1 -1  1 -1⎟
    ½ ⎜0  0  1  1⎟ ⎜1  0 -1  0⎟ = ½ ⎜1  1 -1 -1⎟
      ⎝0  0  1 -1⎠ ⎝0  1  0 -1⎠     ⎝1 -1 -1  1⎠
    

    If you wanted you could encode the product matrix in your notation. But I'd rather find a way to model applying a quantum gate operation to a subset of the qubits in your register while passing through the other bits unmodified. This could be by expaning the matrix, as I did above to go from the conventional 2×2 to the 4×4 I used. Or it could be in the way you evaluate the matrix times vector product, in order to make better use of the sparse nature of these matrices.

    Looking at your code, I'm somewhat worried by the two indices in your register.entries[0][0]. If the first index is supposed to be the index of the qubit and the second the value of that qubit, then the representation is unfit to model entangled situations.