Computational projects on quantum computing suitable for students in a junior-level quantum mechanics course are described. In these projects students write their own programs to simulate quantum computers. Knowledge is assumed of introductory quantum mechanics through the properties of spin 1/2. Initial, more easily programmed projects treat the basics of quantum computation, quantum gates, and Grover's quantum search algorithm. These are followed by more advanced projects to increase the number of qubits and implement Shor's quantum factoring algorithm. The projects can be run on a typical laptop or desktop computer, using most programming languages. Supplementing resources available elsewhere, the projects are presented here in a self-contained format especially suitable for a short computational module for physics students.

## References

Although tensor products are mentioned, it is not assumed that the reader is familiar with and able to compute tensor products. Therefore, an alternative method is given based on bitwise manipulation of matrix indices (Sec. VIII A). Similarly, a bitwise method is used to compute the modular-arithmetic gates needed for Shor's algorithm (Sec. IX D). A good understanding of binary numbers should suffice for both situations.

With four weekly meetings (one third of the semester) on quantum computing, students completed the three-qubit projects including Grover's algorithm and a variable amount of the more advanced material. Consistently reaching Shor's algorithm would require additional meetings.

Working code for these projects in Mathematica is available by email request to the author.

The particle could have a spatial wave function $\Psi (x)$ that stays fixed, for example.

Although electrons are identical fermions, it is not necessary to antisymmetrize $|\Psi \u27e9$ if the electrons are not allowed to exchange places with one another.

In most computer languages $|\Psi \u27e9$ will simply be an eight-element array of complex numbers. In matrix multiplications $|\Psi \u27e9$ must be treated as a column vector: when multiplied on the *left* by a square matrix, the result is another column vector.

If desired, the program can compute $|\Psi \u27e9$ once just before the measurement and then use this $|\Psi \u27e9$ as the input for multiple measurements. This would not be possible in a physical quantum computer since measuring $|\Psi \u27e9$ would collapse the quantum state.

The probability for any measurement result can be computed from Eq. (8) without making simulated measurements. However, there is pedagogical value in having the simulated quantum system act like a real quantum system. Seeing the results from repeating the quantum measurement a small number of times is closer to the operation of a physical quantum computer.

The left-arrow notation, e.g., $a\u21d0a+1$, is used to denote the assignment of a new value to the program variable *a*. In most computer languages this is written a=a+1.

Gates can be moved along their lines as long as the order of operations *on each line* is unchanged. So for Fig. 3(b) the three Hadamard gates could be applied in any order.

One can object that to write Eq. (27), we need to know the answer to the search problem. For a useful application of Grover's algorithm, the oracle would be a quantum calculation that can be constructed without knowing the correct answer. For example, the oracle could implement the logic circuit of Fig. 2 using quantum gates. See Ref. 10, pp. 88–89, for further discussion.

*C*. Shor's contribution was to prove that step 4 can be done much more quickly on a quantum computer than classically.

**NP**is actually a different class than P. Based on Shor's algorithm, factoring is thought to lie in the class

**BQP**(larger than

**P**but not equal to

**NP**) of problems that can be solved with high probability in polynomial time on a quantum computer. See “Computational complexity theory,” Wikipedia, <http://en.wikipedia.org/wiki/Computational_complexity_theory>, and Ref. 8, Sec. 3.2.

*American Journal of Physics*and

*The Physics Teacher*as a member benefit. To learn more about this member benefit and becoming an AAPT member, visit the Joining AAPT page.