Acceptance sampling

From formulasearchengine
Revision as of 07:58, 12 December 2013 by 117.194.4.149 (talk)
Jump to navigation Jump to search

In computational number theory, Cipolla's algorithm is a technique for solving a congruence of the form

x2n(modp).

where x,nFp, so n is the square of x, and where p is an odd prime. Here Fp denotes the finite field with p elements; {0,1,,p1}. The algorithm is named after Michele Cipolla, an Italian mathematician who discovered it in the year 1907.

The algorithm

Inputs:

  • p, an odd prime,
  • nFp, which is a square.

Outputs:

Step 1 is to find an aFp such that a2n is not a square. There is no known algorithm for finding such an a, except the trial and error method. Simply pick an a and by computing the Legendre symbol (a2n|p) one can see whether a satisfies the condition. The chance that a random a will satisfy is (p1)/2p. With p large enough this is about 1/2.[1] Therefore, the expected number of trials before finding a suitable a is about 2.

Step 2 is to compute x by computing x=(a+a2n)(p+1)/2 within the field Fp2=Fp(a2n). This x will be the one satisfying x2=n.

If x2=n, then (x)2=n also holds. And since p is odd, xx. 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 F13 and all elements in step two are considered as elements of F132).

Find all x such that x2=10.

Before applying the algorithm, it must be checked that 10 is indeed a square in F13. Therefore, the Legendre symbol (10|13) has to be equal to 1. This can be computed using Euler's criterion; (10|13)1061mod13. This confirms 10 being a square and hence the algorithm can be applied.

(2+6)2=4+466=2+46.
(2+6)4=(2+46)2=136.
(2+6)6=(2+46)(136)=9+26.
(2+6)7=(9+26)(2+6)=6.

So x=6 is a solution, as well as x=6=7. Indeed, 62=36=10 and 72=49=10.

Proof

The first part of the proof is to verify that Fp2=Fp(a2n)={x+ya2n:x,yFp} is indeed a field. For the sake of notation simplicity, ω is defined as a2n. Of course, a2n is a quadratic non-residue, so there is no square root in Fp. This ω can roughly be seen as analogous to the complex number i. The field arithmetic is quite obvious. Addition is defined as

(x1+y1ω)+(x2+y2ω)=(x1+x2)+(y1+y2)ω.

Multiplication is also defined as usual. With keeping in mind that ω2=a2n, it becomes

(x1+y1ω)(x2+y2ω)=x1x2+x1y2ω+y1x2ω+y1y2ω2=(x1x2+y1y2(a2n))+(x1y2+y1x2)ω.

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 Fp2 is somewhat equivalent to the field of complex numbers (with ω being the analogon of i).
The additive identity is 0, more formal 0+0ω: Let αFp2, then

α+0=(x+yω)+(0+0ω)=(x+0)+(y+0)ω=x+yω=α.

The multiplicative identity is 1, or more formal 1+0ω:

α1=(x+yω)(1+0ω)=(x1+00(n2a))+(x0+1x)ω=x+yω=α.

The only thing left for Fp2 being a field is the existence of additive and multiplicative inverses. It is easily seen that the additive inverse of x+yω is xyω, which is an element of Fp2, because x,yFp. 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 α=x1+y1ω and α1=x2+y2ω. In other words,

(x1+y1ω)(x2+y2ω)=(x1x2+y1y2(n2a))+(x1y2+y1x2)ω=1.

So the two equalities x1x2+y1y2(n2a)=1 and x1y2+y1x2=0 must hold. Working out the details gives expressions for x2 and y2, namely

x2=y11x1(y1(n2a)x12y11)1,
y2=(y1(n2a)x12y11)1.

The inverse elements which are shown in the expressions of x2 and y2 do exist, because these are all elements of Fp. This completes the first part of the proof, showing that Fp2 is a field.

The second and middle part of the proof is showing that for every element x+yωFp2:(x+yω)p=xyω. By definition, ω2=a2n is not a square in Fp. Euler's criterion then says that

ωp1=(ω2)p12=1.

Thus ωp=ω. This, together with Fermat's little theorem (which says that xp=x for all xFp) and the knowledge that in fields of characteristic p the equation (a+b)p=ap+bp holds, shows the desired result

(x+yω)p=xp+ypωp=xyω.

The third and last part of the proof is to show that if x0=(a+ω)p+12Fp2, then x02=nFp.
Compute

x02=(a+ω)p+1=(a+ω)(a+ω)p=(a+ω)(aω)=a2ω2=a2(a2n)=n.

Note that this computation took place in Fp2, so this x0Fp2. 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 x2n has 2 roots in Fp, these roots must be all of the roots in Fp2. It was just shown that x0 and x0 are roots of x2n in Fp2, so it must be that x0,x0Fp.[2]

Speed of the algorithm

After finding a suitable a, the number of operations required for the algorithm is 4m+2k4 multiplications, 4m2 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 Fp2, the following two equalities hold

(x+yω)2=(x2+y2ω2)+((x+y)2x2y2)ω,

where ω2=a2n is known in advance. This computation needs 4 multiplications and 4 sums.

(x+yω)2(c+ω)=(cdb(x+d))+(d2by)ω,

where d=(x+yc) and b=ny. This operation needs 6 multiplications and 4 sums.

Assuming that p1(mod4), (in the case p3(mod4), the direct computation x±np+14 is much faster) the binary expression of (p+1)/2 has m1 digits, of which k are ones. So for computing a (p+1)/2 power of (a+ω), the first formula has to be used nk1 times and the second k1 times.

For this, Cipolla's algorithm is better than the Tonelli-Shanks algorithm if and only if S(S1)>8m+20, with 2S being the maximum power of 2 which divides p1.[3]

References

  1. R. Crandall, C. Pomerance Prime Numbers: A Computational Perspective Springer-Verlag, (2001) p. 157
  2. M. Baker Cipolla's Algorithm for finding square roots mod p
  3. Gonzalo Tornaria Square roots modulo p
  • E. Bach, J.O. Shallit Algorithmic Number Theory: Efficient algorithms MIT Press, (1996)

Template:Number theoretic algorithms