next up previous contents
Next: The Simulation of Shor's Up: A Simulation of Shor's Previous: The Complex Number Class   Contents

The Quantum Memory Register Class

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 $n$ qubits requires $2^{n}$ complex numbers to represent it. This is because a register of $n$ bits can exist in any one of $2^{n}$ 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:


\begin{displaymath}\left\vert,0,0 \right\rangle \end{displaymath}


\begin{displaymath}\left\vert,0,1 \right\rangle \end{displaymath}


\begin{displaymath}\left\vert,1,0 \right\rangle \end{displaymath}


\begin{displaymath}\left\vert,1,1 \right\rangle \end{displaymath}


\begin{displaymath}\left\vert 1,0,0 \right\rangle \end{displaymath}


\begin{displaymath}\left\vert 1,0,1 \right\rangle \end{displaymath}


\begin{displaymath}\left\vert 1,1,0 \right\rangle \end{displaymath}


\begin{displaymath}\left\vert 1,1,1 \right\rangle \end{displaymath}

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 $2^{3} = 8 $ possible base states.

The probability of measuring the $j$'th state whose complex amplitude is $w_{j}$ is $\left\vert w_{j}\right\vert^{2}/\sum_{j}\left\vert w_{j}\right\vert^{2}$. I ensure throughout that algorithm that $\sum_{j}\left\vert w_{j}\right\vert^{2}$ is 1, so the probability of measuring the $j$'th state is simply $\left\vert w_{j}\right\vert^{2}$. The base states of our $n$ bit quantum register can be thought of as being the integers 0 through $2^{n - 1}$. In code the quantum register of size $n$ will be represented by an array of complex numbers of size $2^{n}$. The value stored at the $j$'th array position is the complex probability amplitude associated with measuring the number $j$. For example, a quantum memory register of size 2 that contains an equal superposition of the numbers 0-3 would be represented by:


\begin{displaymath}State[0] = 1/2 + i * 0 \end{displaymath}


\begin{displaymath}State[1] = 1/2 + i * 0 \end{displaymath}


\begin{displaymath}State[2] = 1/2 + i * 0\end{displaymath}


\begin{displaymath}State[3] = 1/2 + i * 0\end{displaymath}

Observe that the probability of measuring any given state is $\left\vert w_{j}\right\vert^{2} = \frac{1}{2}^{2} + 0^{2} = 1/4$.

If we attempt to measure this register, we will with equal probability measure one of $0,1,2,3$. 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:


\begin{displaymath}State[0] = 0 + i * 0\end{displaymath}


\begin{displaymath}State[1] = 0 + i * 0\end{displaymath}


\begin{displaymath}State[2] = 1 + i * 0\end{displaymath}


\begin{displaymath}State[3] = 0 + i * 0\end{displaymath}

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:


\begin{displaymath}State[0] = 1 + i * 0\end{displaymath}


\begin{displaymath}State[1] = 1 + i * 0\end{displaymath}

We would expect that when measured 0 and 1 would be equally likely outcomes, however we would also like for simplicity to have $\left\vert w_{j}\right\vert^{2}$ be the probability of measuring the $j$'th state. To accommodate this desire the qureg class contains a subroutine which will normalize the probability amplitudes, such that sum of the $\left\vert w_{j}\right\vert^{2}$ over all $j$'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.


next up previous contents
Next: The Simulation of Shor's Up: A Simulation of Shor's Previous: The Complex Number Class   Contents
Matthew Hayward 2008-04-26