FIGURE 1. Quantum circuit for Shor's algorithm.
From the following article:
Experimental realization of Shor's quantum factoring algorithm using nuclear magnetic resonance
Lieven M. K. Vandersypen, Matthias Steffen, Gregory Breyta, Costantino S. Yannoni, Mark H. Sherwood and Isaac L. Chuang
Nature 414, 883-887(20 December 2001)
doi:10.1038/414883a

a, Outline of the quantum circuit. Wires represent qubits, and boxes represent operations. Time goes from left to right. (0) Initialize a first register of n = 2
log2 N
qubits to |0
...
|0
(for short |0
) and a second register of m =
log2 N
qubits to |0
...
|0
|1
). (1) Apply a Hadamard transform H to the first n qubits, so the first register reaches
2n-1x = 0 |x
/
(2n). (2) Multiply the second register by f(x) = ax mod N (for some random a < N which has no common factors with N), to get |
2
=
2n-1x = 0 |x
|1
ax mod N
/
(2n). As the first register is in a superposition of 2n terms |x
, the modular exponentiation is computed for 2n values of x in parallel. (3) Perform the inverse QFT on the first register19, giving |
3
=
2n-1y = 0
2n-1x = 0 e2
ixy/2n|y
|ax mod N
/2n, where interference causes only terms |y
with y = c2n/r (for integer c) to have a substantial amplitude, with r the period of f(x). (4) Measure the qubits in the first register. On an ideal single quantum computer, the measurement outcome is c2n/r for some c with high probability, and r can be quickly deduced from c2n/r on a classical computer via continued fractions2. b, Detailed quantum circuit for the case N = 15 and a = 7. Control qubits are marked by filled circles;
represents a NOT operation and 90 and 45 represent
rotations over these angles. The gates shown in dotted lines can be removed by optimization, and the gates shown in dashed lines can be replaced by simpler gates (see Methods).
