Cipolla's algorithm

1

In computational number theory, Cipolla's algorithm is a technique for solving a congruence of the form where, so n is the square of x, and where p is an odd prime. Here denotes the finite field with p elements;. The algorithm is named after Michele Cipolla, an Italian mathematician who discovered it in 1907. Apart from prime moduli, Cipolla's algorithm is also able to take square roots modulo prime powers.

Algorithm

Inputs: Outputs: Step 1 is to find an such that a^2 - n is not a square. There is no known deterministic algorithm for finding such an a, but the following trial and error method can be used. Simply pick an a and by computing the Legendre symbol one can see whether a satisfies the condition. The chance that a random a will satisfy is (p-1)/2p. With p large enough this is about 1/2. Therefore, the expected number of trials before finding a suitable a is about 2. Step 2 is to compute x by computing within the field extension. This x will be the one satisfying x^2 =n. If x^2 = n, then (-x)^2 = n also holds. And since p is odd, x \neq -x. 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 x^2 = 10. Before applying the algorithm, it must be checked that 10 is indeed a square in. Therefore, the Legendre symbol (10 | 13) has to be equal to 1. This can be computed using Euler's criterion: This confirms 10 being a square and hence the algorithm can be applied. So x = 6 is a solution, as well as x = -6. Indeed,

Proof

The first part of the proof is to verify that is indeed a field. For the sake of notation simplicity, \omega is defined as. Of course, a^2-n is a quadratic non-residue, so there is no square root in. This \omega can roughly be seen as analogous to the complex number i. The field arithmetic is quite obvious. Addition is defined as Multiplication 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, commutativity and distributivity are easily seen. This is because in this case the field is somewhat resembles the field of complex numbers (with \omega being the analogon of i). The additive identity is 0, or more formally 0 + 0\omega: Let, then The multiplicative identity is 1, or more formally 1 + 0\omega: 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 x+y\omega is -x-y\omega, 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 \alpha has a multiplicative inverse, write down and. In other words, So the two equalities and must hold. Working out the details gives expressions for x_2 and y_2, namely The inverse elements which are shown in the expressions of x_2 and y_2 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 (which says that x^p = x for all ) and the knowledge that in fields of characteristic p the equation holds, a relationship sometimes called the Freshman's dream, 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 of degree n has at most n roots in any field K, and the knowledge that x^2-n has 2 roots in, these roots must be all of the roots in. It was just shown that x_0 and -x_0 are roots of x^2-n in, so it must be that.

Speed

After finding a suitable a, the number of operations required for the algorithm is 4m + 2k - 4 multiplications, 4m-2 sums, where m is the number of digits in the binary representation 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 d=(x+ya) and b=ny. This operation needs 6 multiplications and 4 sums. Assuming that (in the case, the direct computation is much faster) the binary expression of (p+1)/2 has m-1 digits, of which k are ones. So for computing a (p+1)/2 power of, the first formula has to be used n-k-1 times and the second k-1 times. For this, Cipolla's algorithm is better than the Tonelli–Shanks algorithm if and only if, with 2^{S} being the maximum power of 2 which divides p-1.

Prime power moduli

According to Dickson's "History Of Numbers", the following formula of Cipolla will find square roots modulo powers of prime: Taking the example in the wiki article we can see that this formula above does indeed take square roots modulo prime powers. As Now solve for 2^{-1}q^{t} via: Now create the and (See here for mathematica code showing this above computation, remembering that something close to complex modular arithmetic is going on here) As such: and the final equation is:

Sources

This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.

Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.
Bliptext is not affiliated with or endorsed by Wikipedia or the Wikimedia Foundation.

Edit article