Shors Algorithm
Shors Algorithm
. greatest common
( divisor: e.g. Euclidean algorithm
b if a mod b = 0
gcd(a, b) =
gcd(b, a mod b) else
with a > b, quadratic in number of digits of a, b.
reminder: gcd(a, b) = 1 → a, b coprime
. Test of primality: e.g. Agrawal-Kayal-Saxena 2002, polynomial
. Prime power test: determine if n = pα , e.g. Bernstein 1997 in O(log n)
. continued fraction expansion: required to approximate a rational number
by an integer fraction, e.g. Hardy and Wright 1979, polynomial
Reduction to period-finding problem, Miller 1976
. Find factor of odd n provided some method to calculate the order r of xa mod n,
a ∈ N:
. Define the QFT with respect to an ONB {|xi} = {|0i , ..., |q − 1i}
q−1 q−1
1 X 2πi 1 X x·y
QF T : |xi 7→ √ exp x · y |yi = √ ω |yi
q y=0 q q y=0
P
. Apply QFT to a general state |ψi = x αx |xi:
q−1
1 X
QF T (|ψi) = √ βy |yi ,
q y=0
where the βy ’s are the discrete Fourier transform of the amplitudes αx .
. The QFT is unitary, i.e.
QF T † QF T |xi = |xi
Quantum Fourier Transform (QFT)
. Given a periodic function f : {0, ..., q − 1} → {0, ..., q − 1}, where q = 2l , the periodicity conditions
are
f (a) = f (a + r) r 6= 0
f (a) 6= f (a + s) ∀s < r.
. Imagine one performs a measurement on f (a), then the post measurement state of
the first l qubits is
r X
r
|Φ1 iz = |ai .
q
a:f (a)=z
. Remember that f is periodic and choose a0 = min {a|f (a) = z}. Now one can
rewrite
r q/r−1
r X
|Φ1 iz = |a0 + t · ri
q t=0
c0 Φ̃ = r 1 = 1
X
2
r
c=kq/r
kq
. The algorithm output is a natural number that is of the form r, with
k ∈ N.
Example: Factoring n=21
1. Choose x
2. Determine q
3. Initialize first register (r1 )
4. Initialize second register (r2 )
5. QFT on first register
6. Measurement
7. Continued Fraction Expansion → determine r
8. Check r → determine factors
1. Choose a random integer x, 1 < x < n
!
. n = 244 ≤ q = 2l < 2n2 = 882
2
→ q = 512 = 29
. Initial state consisting of two registers of length l:
l
|Φii = |0ir1 |0ir2 = |0i⊗2
3. Initialize r1
. initialize second register with superposition of all states xa( mod n):
511
1 X
|Φ1i = √ |ai |11a( mod 21)i
512 a=0
1
= √ (|0i |1i + |1i |11i + |2i |16i + |3i |8i + ...)
512
a 0 1 2 3 4 5 6 7 8 9 10 ...
11a(mod21) 1 11 16 8 4 2 1 11 16 8 4 ...
. r = 6, but not yet observable
5. Quantum Fourier Transform
. probability for state |c, xk ( mod n)i, e.g. k = 2 → |c, 16i to occur:
511 2 2
1 X
2πiac/512
1 X
2πi(6b+2)c/512
p(c) = e = 512
e
512 a
a:11 mod 21=16 b
512
. peaks for c = 6 · d, d ∈ Z:
7. Determine the period r
427 d !
. Assume we get 427: qc − dr = 512 − r ≤ 1
1024
. check if r is even X
. check if xr/2 mod n 6= −1 X
. as both holds, we can determine the factors:
xr/2 mod n − 1 = 113 mod 21 − 1 = 7
xr/2 mod n + 1 = 113 mod 21 + 1 = 9