In
computational number theory
In mathematics and computer science, computational number theory, also known as algorithmic number theory, is the study of
computational methods for investigating and solving problems in number theory and arithmetic geometry, including algorithm ...
, Cipolla's algorithm is a technique for solving a
congruence of the form
:
where
, so ''n'' is the square of ''x'', and where
is an
odd
Odd means unpaired, occasional, strange or unusual, or a person who is viewed as eccentric.
Odd may also refer to:
Acronym
* ODD (Text Encoding Initiative) ("One Document Does it all"), an abstracted literate-programming format for describing X ...
prime
A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways ...
. Here
denotes the finite
field
Field may refer to:
Expanses of open ground
* Field (agriculture), an area of land used for agricultural purposes
* Airfield, an aerodrome that lacks the infrastructure of an airport
* Battlefield
* Lawn, an area of mowed grass
* Meadow, a grass ...
with
elements;
. The
algorithm
In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
is named after
Michele Cipolla
Michele Cipolla (28 October 1880, Palermo – 7 September 1947, Palermo) was an Italians, Italian mathematician, mainly specializing in Number Theory, number theory.
He was a professor of Algebraic Analysis at the University of Catania and, l ...
, an
Italian
Italian(s) may refer to:
* Anything of, from, or related to the people of Italy over the centuries
** Italians, an ethnic group or simply a citizen of the Italian Republic or Italian Kingdom
** Italian language, a Romance language
*** Regional Ita ...
mathematician
A mathematician is someone who uses an extensive knowledge of mathematics in their work, typically to solve mathematical problems.
Mathematicians are concerned with numbers, data, quantity, structure, space, models, and change.
History
On ...
who discovered it in 1907.
Apart from prime moduli, Cipolla's algorithm is also able to take square roots modulo prime powers.
[
"History of the Theory of Numbers" Volume 1 by Leonard Eugene Dickson, p218]
read online
Algorithm
Inputs:
*
, an odd prime,
*
, which is a square.
Outputs:
*
, satisfying
Step 1 is to find an
such that
is not a square. There is no known deterministic algorithm for finding such an
, but the following
trial and error
Trial and error is a fundamental method of problem-solving characterized by repeated, varied attempts which are continued until success, or until the practicer stops trying.
According to W.H. Thorpe, the term was devised by C. Lloyd Morgan (1 ...
method can be used. Simply pick an
and by computing the
Legendre symbol
In number theory, the Legendre symbol is a multiplicative function with values 1, −1, 0 that is a quadratic character modulo an odd prime number ''p'': its value at a (nonzero) quadratic residue mod ''p'' is 1 and at a non-quadratic residu ...
one can see whether
satisfies the condition. The chance that a random
will satisfy is
. With
large enough this is about
. Therefore, the expected number of trials before finding a suitable
is about 2.
Step 2 is to compute ''x'' by computing
within the
field extension
In mathematics, particularly in algebra, a field extension is a pair of fields E\subseteq F, such that the operations of ''E'' are those of ''F'' restricted to ''E''. In this case, ''F'' is an extension field of ''E'' and ''E'' is a subfield of ...
. This ''x'' will be the one satisfying
If
, then
also holds. And since ''p'' is odd,
. So whenever a solution ''x'' is found, there's always a second solution, ''-x''.
Example
(Note: All elements before step two are considered as an element of
and all elements in step two are considered as elements of
.)
Find all ''x'' such that
Before applying the algorithm, it must be checked that
is indeed a square in
. Therefore, the Legendre symbol
has to be equal to 1. This can be computed using
Euler's criterion In number theory, Euler's criterion is a formula for determining whether an integer is a quadratic residue modulo a prime. Precisely,
Let ''p'' be an odd prime and ''a'' be an integer coprime to ''p''. Then
:
a^ \equiv
\begin
\;\;\,1\pmod& \text ...
:
This confirms 10 being a square and hence the algorithm can be applied.
* Step 1: Find an ''a'' such that
is not a square. As stated, this has to be done by trial and error. Choose
. Then
becomes 7. The Legendre symbol
has to be −1. Again this can be computed using Euler's criterion:
So
is a suitable choice for ''a''.
* Step 2: Compute
in
:
:
:
:
:
So
is a solution, as well as
. Indeed,
Proof
The first part of the proof is to verify that
is indeed a field. For the sake of notation simplicity,
is defined as
. Of course,
is a quadratic non-residue, so there is no
square root
In mathematics, a square root of a number is a number such that ; in other words, a number whose ''square'' (the result of multiplying the number by itself, or ⋅ ) is . For example, 4 and −4 are square roots of 16, because .
E ...
in
. This
can roughly be seen as analogous to the complex number
i.
The field arithmetic is quite obvious.
Addition
Addition (usually signified by the Plus and minus signs#Plus sign, plus symbol ) is one of the four basic Operation (mathematics), operations of arithmetic, the other three being subtraction, multiplication and Division (mathematics), division. ...
is defined as
:
.
Multiplication
Multiplication (often denoted by the cross symbol , by the mid-line dot operator , by juxtaposition, or, on computers, by an asterisk ) is one of the four elementary mathematical operations of arithmetic, with the other ones being additi ...
is also defined as usual. With keeping in mind that
, it becomes
:
.
Now the field properties have to be checked.
The properties of closure under addition and multiplication,
associativity
In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement f ...
,
commutativity
In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. Most familiar as the name of ...
and
distributivity
In mathematics, the distributive property of binary operations generalizes the distributive law, which asserts that the equality
x \cdot (y + z) = x \cdot y + x \cdot z
is always true in elementary algebra.
For example, in elementary arithmetic, ...
are easily seen. This is because in this case the field
is somewhat resembles the field of
complex number
In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the form ...
s (with
being the analogon of ''i'').
The additive
identity
Identity may refer to:
* Identity document
* Identity (philosophy)
* Identity (social science)
* Identity (mathematics)
Arts and entertainment Film and television
* ''Identity'' (1987 film), an Iranian film
* ''Identity'' (2003 film), ...
is
, or more formally
: Let
, then
:
.
The multiplicative identity is
, or more formally
:
:
.
The only thing left for
being a field is the existence of additive and multiplicative
inverses. It is easily seen that the additive inverse of
is
, which is an element of
, because
. In fact, those are the additive inverse elements of ''x'' and ''y''. For showing that every non-zero element
has a multiplicative inverse, write down
and
. In other words,
:
.
So the two equalities
and
must hold. Working out the details gives expressions for
and
, namely
:
,
:
.
The inverse elements which are shown in the expressions of
and
do exist, because these are all elements of
. This completes the first part of the proof, showing that
is a field.
The second and middle part of the proof is showing that for every element
.
By definition,
is not a square in
. Euler's criterion then says that
:
.
Thus
. This, together with
Fermat's little theorem
Fermat's little theorem states that if ''p'' is a prime number, then for any integer ''a'', the number a^p - a is an integer multiple of ''p''. In the notation of modular arithmetic, this is expressed as
: a^p \equiv a \pmod p.
For example, if = ...
(which says that
for all
) and the knowledge that in fields of
characteristic ''p'' the equation
holds, a relationship sometimes called the
Freshman's dream
The freshman's dream is a name sometimes given to the erroneous equation (x+y)^n=x^n+y^n, where n is a real number (usually a positive integer greater than 1) and x,y are nonzero real numbers. Beginning students commonly make this error in computi ...
, shows the desired result
:
.
The third and last part of the proof is to show that if
, then
.
Compute
:
.
Note that this computation took place in
, so this
. But with
Lagrange's theorem, stating that a non-zero
polynomial
In mathematics, a polynomial is an expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An exa ...
of degree ''n'' has at most ''n'' roots in any field ''K'', and the knowledge that
has 2 roots in
, these roots must be all of the roots in
. It was just shown that
and
are roots of
in
, so it must be that
.
Speed
After finding a suitable ''a'', the number of operations required for the algorithm is
multiplications,
sums, where ''m'' is the number of
digits in the
binary representation
A binary number is a number expressed in the base-2 numeral system or binary numeral system, a method of mathematical expression which uses only two symbols: typically "0" (zero) and "1" (one).
The base-2 numeral system is a positional notation ...
of ''p'' and ''k'' is the number of ones in this representation. To find ''a'' by trial and error, the expected number of computations of the Legendre symbol is 2. But one can be lucky with the first try and one may need more than 2 tries. In the field
, the following two equalities hold
:
where
is known in advance. This computation needs 4 multiplications and 4 sums.
:
where
and
. This operation needs 6 multiplications and 4 sums.
Assuming that
(in the case
, the direct computation
is much faster) the binary expression of
has
digits, of which ''k'' are ones. So for computing a
power of
, the first formula has to be used
times and the second
times.
For this, Cipolla's algorithm is better than the
Tonelli–Shanks algorithm The Tonelli–Shanks algorithm (referred to by Shanks as the RESSOL algorithm) is used in modular arithmetic to solve for ''r'' in a congruence of the form ''r''2 ≡ ''n'' (mod ''p''), where ''p'' is a prime: that is, to find a square root of ''n'' ...
if and only if
, with
being the maximum power of 2 which divides
.
Prime power moduli
According to Dickson's "History Of Numbers", the following formula of Cipolla will find square roots modulo powers of prime:
[
"History of the Theory of Numbers" Volume 1 by Leonard Eugene Dickson, p218, Chelsea Publishing 1952
]