The order-finding problem is a fundamental problem that plays a central role in several quantum algorithms; in particular, it underlies Shor’s celebrated factoring algorithm. Classically, order-finding is hard—no efficient classical algorithm is known—but quantum computers can solve it efficiently. Efficiently determining the order of an integer modulo allows integers to be factored in polynomial time, which would compromise RSA encryption, as we will discuss in the subsequent sections.
The order-finding problem is defined rigorously as follows:
Definition (Order-Finding Problem) Let be a positive integer, and let
be an integer coprime to
(that is, the greatest common divisor
of
and
equals one,
). The notation
denotes the set of invertible elements in
under multiplication—those integers that are coprime to
. The order of
modulo
, denoted
or simply
, is the smallest positive integer
such that
The order-finding problem is: given and
, compute
.
At first glance, this definition may appear somewhat abstract.
Do not worry—shortly, we will unpack each of the mathematical ingredients and illustrate their meaning with concrete examples.
The quantum algorithm for order-finding exploits the periodic structure of the function
which is periodic with period exactly . By preparing a quantum superposition over all possible exponents and applying the quantum phase estimation algorithm to the unitary operator
we obtain an efficient quantum procedure that succeeds with high probability.
Preliminaries of Modular Arithmetic
Before presenting the complete quantum algorithm, let us first review a few essential results from number theory. This section may appear somewhat technical compared to others; if you prefer not to delve into the details, simply remember that for coprime integers and
, there exists a positive order
, and the function in Eq.(1) is periodic and turn to the next section.
An integer is called a prime number if it has no nontrivial divisors; for example,
are prime numbers. Otherwise,
is called a composite number. We use
to denote that
is divisible by
, for instance
,
. Similarly,
means that
does not divide
, for example
.
Every integer can be uniquely expressed as a product of prime powers:
where are distinct prime numbers and
are positive integers. This result is known as the Fundamental Theorem of Arithmetic.
To obtain the prime factorization of a given number , one typically follows these steps:
- Divide
by
repeatedly until the quotient is no longer divisible by
.
Letbe the number of times we divide by
, and denote the resulting quotient by
, for which
.
- For the quotient
, proceed with the next prime,
, and divide repeatedly until the quotient is no longer divisible by
.
Letbe the number of divisions, and denote the resulting quotient by
.
- Continue in this manner with successive primes
until the quotient becomes
.
Exercise. Decompose into its prime factors:
.
The key operation we will use is modular arithmetic.
In everyday life we count linearly: 1, 2, 3, …, but in modular arithmetic we count on a circle.
Take a clock that shows only 12 hours. When the hand reaches 12, it jumps back to 0.
Mathematically, we say time is measured modulo 12.
This simple idea—wrapping around after a fixed modulus —is crucial in number theory and its applications in modern public-key cryptography.
Definition (Congruence) Fix an integer , called the modulus.
Two integers and
are congruent modulo
if their difference is a multiple of
:
We read as “
is congruent to
modulo
”.
The congruence class of is usually represented by its smallest non-negative residue:
It is also convenient to use to denote the congruence class whenever there is no ambiguity about the modulus.
Example. Let . We have
. Then
and
. The congruence class
consists of
, the congruence class
consists of
, and
consists of
, etc.
The order-finding problem considers the modular exponentiation for given integers and
:
The remainder can take values in
:
However, not all values of are necessarily attainable.
For example, let and
. We find that
We observe a repeating pattern. In this case, the residues ,
, and
never appear.
Note also that for any integers
and
. Hence, the order of
modulo
is defined as the smallest positive integer
such that
. However, we must still ensure that such an order actually exists. In fact, if
, then no positive integer
satisfies
. This can be seen in the previous example with
and
, where the sequence never returns to
modulo
.
Exercise. Let and
. Then the only integer
satisfying
is .
Proof. Suppose there exists an integer such that
.
Then divides
, so in particular
.
Since , we also have
, and therefore
,
which contradicts . Hence no such
exists.
For , the convention
gives
trivially. Thus is the only solution ∎.
In Shor’s algorithm, we either assume , or first compute the greatest common divisor classically, which already yields a nontrivial factor of
if
.
Another useful concept we will use is Euler’s Totient function: counts the number of integers
coprime to
.
For example, ,
,
,
, etc.
For fixed , consider
.
We call invertible if there exists an integer
such that
.
Proposition (Bézout’s Identity). Let and
be integers with greatest common divisor
. Then there exist integers
and
such that
.
Moreover, the integers of the form are exactly the multiples of
.
The set is not a group under multiplication modulo
in general. We denote by
the set of invertible elements, which indeed forms a group. By Bézout’s identity,
consists of all integers coprime to
, and this group has order
, where
denotes Euler’s totient function.
From a group-theoretic perspective, for any , there exists a positive integer
such that
.
Since must be invertible, it follows that
. In the multiplicative group
, the order of any element divides the order of the group, that is,
.
Theorem (Euler’s Theorem). If , then
and hence the order of modulo
divides
.
By Euler’s theorem, for integers and
with
, there always exists a positive integer
such that
The order always satisfies
.
Since in the cyclic subgroup generated by we have
the sequence is periodic with period equal to the order
:
Thus, the sequence repeats with period .
Example. Set and
. We have
as:
We see that the order is .
Quantum Order-Finding Algorithm
The quantum order-finding algorithm can be divided into two main steps:
- Encode the order into the phase of an eigenvalue of a suitable unitary operator, thereby reducing the order-finding problem to a quantum phase estimation problem.
- Recover the order
from the estimated phase
using the method of continued fractions.
Let us first examine how to encode the order into the phase of a unitary operator.
Fix integers and
such that
.
Define the unitary operator acting on computational basis states
by
We will see that the order can be mapped to the phase of an eigenvalue of .
Proposition. Let and let
be an integer coprime to
.
The operator on
defined by
is unitary.
Proof. Since , multiplication by
modulo
defines a bijection on the set
.
Thus merely permutes the computational basis
. Any permutation of an orthonormal basis extends to a unitary operator, so
is unitary.
Alternatively, suppose . Then
.
Because , we may cancel
(more precisely, multiply both sides by the modular inverse of
modulo
) to obtain
.
Since , the only possibility is
, so
.
Thus is injective on a basis of
.
Being an isometry that maps a basis to a basis, it is unitary ∎.
Proposition. Let be the order of
modulo
, i.e., the smallest positive integer such that
.
For each , define the state
Then, for each ,
is an eigenstate of
with eigenvalue
.
Proof. Apply to
:
Reindex the sum by letting :
The sum now runs from to
, but the
term is
while the term in the original definition of
is
Thus the missing term is exactly replaced by the
term, and we obtain
This holds for every ∎.
Now the procedure becomes “straightforward”. We apply quantum phase estimation (see this post) to the operators with the eigenstate
, which yields the phases
The output of the phase estimation algorithm is thus
represented as binary numbers. A classical algorithm called continued fractions can be applied to obtain the order .
