Period-finding
Suppose f is a periodic function producing a single bit as output and such that f(x+r) = f(x), for some unknown 0<r<2^{L}, where x,r \in \{0,1,2,...\}. Given a quantum black box U which performs the unitary transform U|x\rangle|y\rangle \mapsto |x\rangle|y\oplus f(x)\rangle (where \oplus denotes addition modulo 2) how many black box queries and other operations are required to determin r?
In practice U operates on a finite domain, whose size is deteremined by the desired accuracy r.
Algorithm overview (one query)
Inputs:
- A black box which performs the operation U|x\rangle|y\rangle = |x\rangle|y\oplus f(x)\rangle.
- A state to store the function evaluation, initialized to |0\rangle
- t=O(L+\text{log}(1/\epsilon)) qubits initialized to |0\rangle.
Outputs: The least integer r>0 such that f(x+r) = f(x)
Runtime: one use of u, and O(L^{3}) operations. Succeeds with probablility O(1)
Procedure:
The key to understanding this algorithm, which is based on phase estimation, and its basically a order-finding problem. In step 3, we introduce the state
the Fourier transform of |f(x)\rangle. The identity used in step 3 is based on
which is a easy to verfify noting that \sum_{k=0}^{r-1}e^{2\pi ilx/r} = r for integer x an integer multiple of r, and zero otherwise. The approximate equality in step 3 is required since 2^t may not be an integer multiple of r in general. After applying the inverse Fourier transform at the step 4 we can get l/r, where l is chosed randomly. r can be calcualted by using a continued fraction expansion.
From Factorization to Period Finding
The number thoery that underlines Shor's algorithm relates to periodic modulo sequences. Let's have a look at an example of such a sequence. let's consider the sequence of the power of two:
Now let's compute modulo 15 on each entry,
and we can easily see that sequence repeats every four numbers, and this is the periodic modulo sequence with a period of four.
The reduction of factorization of N to the problem of finding the period of an integer x less than N and greater than 1 depends on the following result from number theory:
The function \mathcal{F}(a) = x^{a} (\text{mod}\ N) is periodic function, where x is an integer coprime to N and a \geq 0.
Note that two numers are coprime, if the only positive integer that divides both of them is 1, \text{gcd}(2,9) = 1 and \text{gcd}(8,15) = 1, for an examples. On the other hand, \text{gcd}(2,8) = 2, so 2 and 8 are not coprime.
Since \mathcal{F}(a) is a periodic function, it has some period r. Knowing that x^{0} \text{mod} \ N =1, this means that x^{r} \text{mod} \ N =1 since the function is periodic, and thus r is just the first non-zero power where x^{r} = 1 \text{mod} (the result that we are looking for in the order finding problem).
Based on some basic algebras:
The product (x^{r/2} + 1)(x^{r/2} - 1) \equiv 0 \text{mod} is an integer multiple of N, the number to be factored. Thus, as long as (x^{r/2} + 1) of (x^{r/2} - 1) is not a multiple of N, then at least one of (x^{r/2} + 1) or (x^{r/2} - 1) must have a nontrivial factor in common with N.
Therefore, we can also know that calculate \text{gcd}(x^{r/2} + 1,N) and \text{gcd}(x^{r/2} - 1,N) will obtain a factor of N, which can be accomlished by using Euclidean algorithm.
References
[1]. M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th Anniversary Ed., Cambridge: Cambridge University Press, 2010.
[2]. Quantum Fourier transform (wiki) https://en.wikipedia.org/wiki/Quantum_Fourier_transform
[3]. Continued fraction (wiki) https://en.wikipedia.org/wiki/Continued_fraction
[4]. Modular exponentiation (wiki) https://en.wikipedia.org/wiki/Modular_exponentiation
[5]. Coprime integers (wiki) https://en.wikipedia.org/wiki/Coprime_integers
[6]. Greatest common divisor (wiki) https://en.wikipedia.org/wiki/Greatest_common_divisor
[7]. qiskit-community-tutorials/algorithms /shor_algorithm.ipynb https://github.com/qiskit-community/qiskit-community-tutorials/blob/master/algorithms/shor_algorithm.ipynb
[8]. Realization of a scalable Shor algorithm by Thomas Monz, Daniel Nigg, Esteban A. Martinez, Matthias F. Brandl, Philipp Schindler, Richard Rines, Shannon X. Wang, Isaac L. Chuang, Rainer Blatt https://arxiv.org/abs/1507.08852