Quantum-factorization
Quantum-factorization
Christophe Pittet
CHRISTOPHE PITTET
1. Introduction
There exist (determistic) algorithms, based on the Agrawal-Kayal-
Saxena primality test, which decide wether a large n-bits integer N is
prime or not in O(n6 ) classical steps (see [5] and [3]). But the best
known algorithms (including probabilistic ones) which deliver a factor
of N , all require a superpolynomial number of classical steps in n. For
example, the Schnorr-Seysen-Lenstra probabilistic algorithm factorizes
N < 2n in
1
exp(O((n log n) 2 ))
classical steps [4]. In constrast, Shor’s algorithm [7] delivers (with
positive probability) a factor of N < 2n in O(n2 log n log log n) quantum
steps.
Implementing efficiently a quantum algorithm on a quantum com-
puter is a major goal in today’s science and technology. It involves sta-
bility issues in quantum technology. But the mathematical aspects of
Shor’s algorithm are elementary: the algorithm relies on the structure
of cyclic groups, on Fourier transform on cyclic groups, on orthogonal
projections in finite dimensional Hilbert spaces, on continued fraction,
on properties of the Euler function, and on the Euclidean algorithm.
The goal of this note is to explain how those tools beautifully com-
bine in Shor’s algorithm. We mainly follow [2] where the interested
reader will find more details. It is obvious from our exposition that
O(n4 ) bounds the complexity of the algorithm. Shor’s tight bound
O(n2 log n log log n)) is more technical and we do not attempt to ex-
plain it.
2.2. The first steps in Shor’s algorithm are classical and they
involve the structure of the unit group (Z/N Z)∗ . We are given a
large integer N < 2n and the goal is to find a factor of N . We choose
an integer
1<y<N
at random. We compute GCD(y, N ) (on a classical computer) with
the Euclidean algorithm. As explained above it requires at most O(n)
divisions. If it turns out that GCD(y, N ) 6= 1 then we have found a
factor of N and the algorithm stops. In the case GCD(y, N ) = 1, that
is if y has an inverse modulo N , then we consider y as an element of
the multiplicative group of units (Z/N Z)∗ of the ring Z/N Z. Let r be
the order of y in (Z/N Z)∗ .
Assume we are lucky in the sense that r is even. We have:
(y r/2 − 1)(y r/2 + 1) = y r − 1 = 0[N ].
MATHEMATICAL ASPECTS OF SHOR’S ALGORITHM 3
That is N divides (y r/2 − 1)(y r/2 + 1). So at least one of the prime
factors of N must divide y r/2 + 1 (otherwise N would divide y r/2 − 1
and this would contradict the definition of r). This implies
1 < GCD(y r/2 + 1, N ).
Assume we are super lucky in the sense that r is even and
y r/2 + 1 6= 0[N ]
(see the proposition below for a lower bound on the probabiliy of being
super lucky in the above sense). In this case,
1 < GCD(y r/2 + 1, N ) < N
is a non trivial factor of N and we can efficiently compute it with the
Euclidian algorithm, provided we know r.
If E is a finite set, let |E| denotes its cardinal.
Proposition 2.1. (A lower bound on the probability of picking y with
good properties.) Assume N is odd. Let m be the number of distinct
prime factors of N . The set
{y ∈ (Z/N Z)∗ : the order r of y is even and y r/2 + 1 6= 0[N ]}
contains at least
1
ϕ(N ) 1 −
2m−1
∗
elements, where ϕ(N ) = | (Z/N Z) | is the Euler function.
(The proof is based on the fact that if p is an odd prime and m ∈ N
then (Z/pm Z)∗ is cyclic.)
As it is obvious to find a factor in the case N is even and as it is
easy to find a factor if N is a power of a single prime (compute the
d-root of N for d ≤ log N/ log 3 and check if it is a factor of N ), we
may apply the above proposition, with m ≥ 2. In this case, we see that
we are super lucky in the above sense more than half of the time. So if
we have a device which efficiently compute the order r of y, then the
strategy is straightforward: first we efficiently compute a candidate for
a factor of N as explained above. Then we check if the candidate is
indeed a factor. If not, we pick another y and try again. The chance
we don’t get a factor after 10 tries for example, is less than 2110 = 1024
1
.
A quantum bit, (a q-bit), is the group algebra over the field of complex
numbers of the group with two elements:
C[Z/2Z] ∼ = C2 ∼ = {α0 + β1 : α, β ∈ C}.
It has two fundamental states 0 and 1. A state of a q-bit is a unit
vector in C2 for the standard hermitian product on C2 which makes 0
and 1 an orthonormal basis. Hence any state v of the q-bit C[Z/2Z] is
a complex superposition
v = α0 + β1
of the fundamental states with the condition
|α|2 + |β|2 = 1.
We will view C[Z/2Z] as a Hilbert space with two distinguished ele-
ments 0 and 1.
3.2. Classical memory versus quantum memory. An n-bit regis-
ter (or memory) is the Z/2Z-vector space (Z/2Z)n . It has dimension
n over Z/2Z. A state of it is any of its 2n elements.
An n-q-bit register (or memory) Vn is the Hilbert tensor product of
n copies of the q-bit C[Z/2Z]:
Vn = C[Z/2Z]⊗n ∼
⊗n
= C2 .
The Hilbert product of two pure tensors is
n
Y
(v1 ⊗ · · · ⊗ vn , w1 ⊗ · · · ⊗ wn ) = (vi , wi ).
i=1
Hence if we denote
e0 = 0, e1 = 1,
n
then the 2 fundamental states
{ei1 ⊗ · · · ⊗ ein }(i1 ,...,in )∈(Z/2Z)n ,
form an orthonormal basis of Vn . A state of Vn is any of its unit vector.
Hence any state v is a complex superposition
X
v= αI eI
I∈(Z/2Z)n
contains also any of their complex superposition (of unit norm). This
makes possible to consider the homogeneous state
1 X
eI
2n n
I∈(Z/2Z)
The two maps are isomorphisms of Hilbert spaces: each of the above
three families of elements, on which we have specified the maps, forms
an orthonormal basis with respect to the chosen Hermitian product on
the complex vector space it belongs to. In any of the three models of Vn ,
we will refer to the above orthonormal basis as the set of fundamental
states.
fˆ(c)δc ,
X X
F f (x)δx =
x∈Z/nZ c∈Z/nZ
where
χc
fˆ(c) = (f, √ ).
n
Although the following proposition is not needed in building Shor’s
algorithm (a more elaborated version of it is needed; see Proposition
8.1 below), it is helpful to have it in mind.
Proposition 4.1. Assume r is a factor of n. Let
f : Z/nZ → C
be a function of period r. Then
fˆ(c) = 0
excepted if
n n
c ∈ {0; ; · · · ; (r − 1) }
r r
Proof. The subspace of periodic functions of period r has dimension r.
It is generated by
χn/r , . . . , χ(r−1)n/r , χn = 1Z/nZ .
MATHEMATICAL ASPECTS OF SHOR’S ALGORITHM 9
1 X
= Uf (x ⊗ (0 ⊗ · · · ⊗ 0))
2n/2
x∈Z/2n Z
1 X
= x ⊗ f (x).
2n/2
x∈Z/2n Z
with N ≤ 2n , needs less than O(n3 log n log log n) classical gates: ex-
ponentiation by squaring needs O(n2 ) multiplications between n-bits
numbers, and multiplication of two n-bits number needs less than
O(n log n log log n) classical gates. On the other hand Wn needs O(n)
elementary quantum gates.
At this point, it may seem that the goal is reached: it is possible to
entangle all the values of the function f (x) = y x mod[N ] in a single state
of a quantum register which is the tensor product of O(log N ) quantum
bits, using O(n2 log n log log n) elementary quantum gates, where N <
N 2 ≤ 2n . In fact there are two obstacles left. First, as mentioned above,
the function f is not really periodic. A well-known rigidity feature from
number theory handles this issue (see Proposition 9.1 below). The
second obstacle is the measurement problem: extracting information
from a quantum register perturbs its state. So it is not obvious to
extract a period from it. This problem is solved by first measuring the
second register VL , then applying a Fourier transform, then measuring
the first register Vn . We explain these points in what follows.
VL = C[Z/2L Z].
Pb : V L → V L
be the orthogonal projection onto the complex line Cb. The family of
projectors
{idVn ⊗ Pb }b∈Z/2L Z
1 X
x ⊗ f (x),
2n/2
x∈Z/2n Z
MATHEMATICAL ASPECTS OF SHOR’S ALGORITHM 11
1 X
=k x ⊗ bk2
2n/2
x∈f −1 (b)
|f −1 (b)|
= .
2n
Notice that if b is observed, then after measurement the double register
is in the state
p 1
X
x ⊗ b.
|f −1 (b)| x∈f −1 (b)
Notice also that if b is observed then the above formula for the proba-
bility of observing b implies that f −1 (b) is nonempty. Let us denote
ψb : Z/2n Z → C,
the normalized characteristic function of the set f −1 (b):
1f −1 (b)
ψb = p .
|f −1 (b)|
With this notation, the state of the double register can be written as
X
ψb (x)x ⊗ b.
x∈Z/2n Z
where Ka is the largest integer such that a + (Ka − 1)r < 2n . Hence
by definition |f −1 (b)| = Ka and the probability of observing c is
χc
|ψ̂b (c)|2 = |(ψb , n/2 )|2
2
K a −1 2
1 X 2iπc(a + kr)
= exp − .
Ka 2n k=0 2n
The above formula enables one to prove the proposition.
(see [6]).
11. Acknowledgments
We are indebted to Andrew Duncan for giving us a preprint version
of [2] when quantum algorithms were still considered as science fiction.
Most of the note is based on it and most of the proofs can be found in
it. We have been supported by the CNRS and the Poncelet Laboratory
in Moscow when giving a course on Shor’s algorithm at the Indepen-
dent University of Moscow. We are very grateful to Tatiana Smirnova
Nagnibeda and Stanislav Smirnov who invited us to give a talk at the
Chebyshev Laboratory in St-Petersburg (May 18, 2011). The video
of the talk is available on the net under the name: Shor’s algorithm.
A link is: http://www.lektorium.tv/lecture/?id=13296. The present
note is an isomorphic written version of the video and of talks we gave
at the CIMPA-UNESCO School on Fourier Analysis on groups and
combinatorics, November 18-30, 2013, Shillong (India). We are very
grateful to the organizers Gautami Bhowmik and Himadri Mukherjee
for inviting us to their School.
References
[1] Tom M. Apostol, Introduction to analytic number theory, Springer-Verlag, New
York, 1976. Undergraduate Texts in Mathematics. MR0434929 (55 #7892)
[2] Michael Batty, Samuel L. Braunstein, Andrew J. Duncan, and Sarah Rees,
Quantum algorithms in group theory, Computational and experimental group
theory, Contemp. Math., vol. 349, Amer. Math. Soc., Providence, RI, 2004,
pp. 1–62, DOI 10.1090/conm/349/06356.
[3] H. W. Lenstra Jr. and Carl Pomerance, Primality Testing with Gaussian Pe-
riods, In proceeding of: FST TCS 2002: Foundations of Software Technology
and Theoretical Computer Science, 22nd Conference Kanpur, India, December
12-14, posted on 2002, DOI 10.1007/3-540-36206-1-1.
[4] , A rigorous time bound for factoring integers, J. Amer. Math. Soc. 5
(1992), no. 3, 483–516, DOI 10.2307/2152702. MR1137100 (92m:11145)
[5] Carl Pomerance, Primality testing: variations on a theme of Lucas, Congr. Nu-
mer. 201 (2010), 301–312. MR2598366 (2010k:11191)
[6] J. Barkley Rosser and Lowell Schoenfeld, Approximate formulas for some func-
tions of prime numbers, Illinois J. Math. 6 (1962), 64–94. MR0137689 (25
#1139)
MATHEMATICAL ASPECTS OF SHOR’S ALGORITHM 15
[7] Peter Shor, Polynomial-Time Algorithms for Prime Factorization and Discrete
Logarithms on a Quantum Computer, SIAM J.Sci.Statist.Comput. 26 (1997).