The qureg class, the quantum memory register, is defined in qureg.cpp.
When a quantum memory register is created it takes as input the number
of qubits it is composed of. A quantum memory register with
qubits requires
complex numbers to represent it. This is
because a register of
bits can exist in any one of
base
states, and a quantum register may exist in any superposition of those
base states. I use one complex number per base state to describe the
probability of that state being measured.
For example, if a quantum register has 3 bits it can be measured to exist in any one of the following states:
Taking these values as binary numbers with the most significant bit
the left most bit, then these states correspond to the numbers
0,1,2,3,4,5,6,7. There are
possible base states.
The probability of measuring the
'th state whose complex
amplitude is
is
. I ensure
throughout that algorithm that
is 1,
so the probability of measuring the
'th state is simply
. The base states of our
bit quantum
register can be thought of as being the integers 0 through
. In code the quantum register of size
will be represented by
an array of complex numbers of size
. The value stored at the
'th array position is the complex probability amplitude associated
with measuring the number
. For example, a quantum memory
register of size 2 that contains an equal superposition of the numbers
0-3 would be represented by:
Observe that the probability of measuring any given state is
.
If we attempt to measure this register, we will with equal probability
measure one of
. Let us assume we measure the state and
observe the value 2, this has the effect of collapsing all
probabilities not measured to 0, so the new state of our quantum
register is:
If we were to measure this register again we would attain 2 without fail.
Sometimes during the course of operation we cause a state to exist in the quantum memory register where the sum over the squares of the probability amplitudes is not 1, for example a quantum register could be in the state:
We would expect that when measured 0 and 1 would be equally likely
outcomes, however we would also like for simplicity to have
be the probability of measuring the
'th
state. To accommodate this desire the qureg class contains a
subroutine which will normalize the probability amplitudes, such that
sum of the
over all
's is one. The qureg
class also allows the state of the register to be set to any arbitrary
state.
The quantum memory register class has two member functions which do things that a real quantum memory register could not do. The first such function is the Dump() function which dumps the entire state information of the register without collapsing it, and is included for debugging. The second such function is the GetProb(state) which gets the probability amplitude of any given state.
The GetProb function is used in the main program to calculate the discrete Fourier transform in step 8. While a quantum computer could not use this information in step 8, a quantum computer would not need to. In a quantum computer the Fourier transformation would take place in one step, and the transform function would take as its argument a state which could in general be any superposition of base states. The GetProb function is used to simulate the application of a function which takes a superposition of states as its argument.