This section describes Shor's algorithm from a functional point of view which means that it doesn't deal with the implementation for a specific hardware architecture. A detailed implementation for the Cirac-Zoller device can be found in [8]. For a more rigid mathematical description, please refer to [9].
Let with the greatest common divisor
be the number to be factorised,
a
randomly selected number relatively prime to
(i.e.
and
the following function with the
period
:
The function performs a modular exponentiation,
its period
is the order of
.
If
is even, we can define a
, which satisfies
the condition
and therefore is the
solution of one of the following systems of equations:
The first two systems have the trivial solutions and
which don't differ from those of the quadratic equation
in
or a Galois field
(i.e.
with prime
).
The last two systems have the non-trivial solutions
,
,
as postulated by the Chinese remainder theorem stating that
a system of
simultaneous congruences (i.e. a system of equations of
the form
) with coprime moduli
(i.e.
for all
)
has a unique solution
with
.
If is even and
with
and
,
then
or
must have a common divisor with
because
which means that
with
and therefore
.
A factor of
can then be found by using Euclid's algorithm
for determing
and
which is
defined as
It can be shown that a random matches the above mentioned
conditions with a probability
if
is not
of the form
or
.
Since there are efficient classical algorithms to factorise pure
prime powers (and of course to recognise a factor of 2), an
efficient probabilistic algorithm for factorisation can be found
if the period
of the modular exponentiation can be determined
in polynomial time.
Let be an operator of the form
and
a function with the
unknown period
.
To determine , we need two registers, with the sizes of
and
qubits, which should be reset to
.
As a first step we produce a homogenous superposition of all
basevectors in the first register by applying an operator
with
This can e.g. be achieved by transforming each qubit with the
operator (see section 2.1.2).
Another possibility is the discrete fast Fourier
transform (
) which is defined for
qubits as
Applying to the resulting state gives
A measurement of the second register with the result
with
reduces the state to
The post-measurement state
of the first register
consists only of basevectors of the form
since
for all
.
It therefore has a discrete, homogenous spectrum.
It is not possible to directly extract the period or a
multiple of it by measurement of the first register because
of the random offset
.
The result of a Fourier transform, however, is invariant
(except for phase factors which don't effect the probability
spectrum) to offsets of a periodic distribution.
If is a multiple of
then
if
is a
multiple of
and
otherwise.
But even if
is not a power of
, the spectrum of
shows distinct peaks with a
period of
because
This is also the reason why we use a first register of
qubits when
because it guarantees at least
elements in the above sum and thus a peak width of
order
.
If we now measure the first register we will get a value
close to
with
.
This can be written as
.
We can think of this as finding a rational approximation
with
for the fixed point binary number
.
An an efficient classical algorithm for solving this problem
using continued fractions is described in [10] and
also implemented in the program shor (see section 4.3).
Since the form of a rational number is not unique, and
are only determined by
if
.
The probability that
and
are coprime is greater
then
, so only
tries are necessary for
a constant probability of success as close at 1 as desired.