Pocklington's algorithm

From HandWiki

Pocklington's algorithm is a technique for solving a congruence of the form

x2≡a(modp),

where x and a are integers and a is a quadratic residue.

The algorithm is one of the first efficient methods to solve such a congruence. It was described by H.C. Pocklington in 1917.[1]

The algorithm

(Note: all ≡ are taken to mean (modp), unless indicated otherwise.)

Inputs:

  • p, an odd prime
  • a, an integer which is a quadratic residue (modp).

Outputs:

  • x, an integer satisfying x2≡a. Note that if x is a solution, −x is a solution as well and since p is odd, x≠−x. So there is always a second solution when one is found.

Solution method

Pocklington separates 3 different cases for p:

The first case, if p=4m+3, with m∈ℕ, the solution is x≡±am+1.

The second case, if p=8m+5, with m∈ℕ and

  1. a2m+1≡1, the solution is x≡±am+1.
  2. a2m+1≡−1, 2 is a (quadratic) non-residue so 42m+1≡−1. This means that (4a)2m+1≡1 so y≡±(4a)m+1 is a solution of y2≡4a. Hence x≡±y/2 or, if y is odd, x≡±(p+y)/2.

The third case, if p=8m+1, put D≡−a, so the equation to solve becomes x2+D≡0. Now find by trial and error t1 and u1 so that N=t12−Du12 is a quadratic non-residue. Furthermore, let

tn=(t1+u1D)n+(t1−u1D)n2,un=(t1+u1D)n−(t1−u1D)n2D.

The following equalities now hold:

tm+n=tmtn+Dumun,um+n=tmun+tnumandtn2−Dun2=Nn.

Supposing that p is of the form 4m+1 (which is true if p is of the form 8m+1), D is a quadratic residue and tp≡t1p≡t1,up≡u1pD(p−1)/2≡u1. Now the equations

t1≡tp−1t1+Dup−1u1andu1≡tp−1u1+t1up−1

give a solution tp−1≡1,up−1≡0.

Let p−1=2r. Then 0≡up−1≡2trur. This means that either tr or ur is divisible by p. If it is ur, put r=2s and proceed similarly with 0≡2tsus. Not every ui is divisible by p, for u1 is not. The case um≡0 with m odd is impossible, because tm2−Dum2≡Nm holds and this would mean that tm2 is congruent to a quadratic non-residue, which is a contradiction. So this loop stops when tl≡0 for a particular l. This gives −Dul2≡Nl, and because −D is a quadratic residue, l must be even. Put l=2k. Then 0≡tl≡tk2+Duk2. So the solution of x2+D≡0 is got by solving the linear congruence ukx≡±tk.

Examples

The following are 4 examples, corresponding to the 3 different cases in which Pocklington divided forms of p. All ≡ are taken with the modulus in the example.

Example 0

x2≡43(mod47).

This is the first case, according to the algorithm, x≡43(47+1)/2=4312≡2, but then x2=22=4 not 43, so we should not apply the algorithm at all. The reason why the algorithm is not applicable is that a=43 is a quadratic non residue for p=47.

Example 1

Solve the congruence

x2≡18(mod23).

The modulus is 23. This is 23=4⋅5+3, so m=5. The solution should be x≡±186≡±8(mod23), which is indeed true: (±8)2≡64≡18(mod23).

Example 2

Solve the congruence

x2≡10(mod13).

The modulus is 13. This is 13=8⋅1+5, so m=1. Now verifying 102m+1≡103≡−1(mod13). So the solution is x≡±y/2≡±(4a)2/2≡±800≡±7(mod13). This is indeed true: (±7)2≡49≡10(mod13).

Example 3

Solve the congruence x2≡13(mod17). For this, write x2−13=0. First find a t1 and u1 such that t12+13u12 is a quadratic nonresidue. Take for example t1=3,u1=1. Now find t8, u8 by computing

t2=t1t1+13u1u1=9−13=−4≡13(mod17),
u2=t1u1+t1u1=3+3≡6(mod17).

And similarly t4=−299≡7(mod17),u4=156≡3(mod17) such that t8=−68≡0(mod17),u8=42≡8(mod17).

Since t8=0, the equation 0≡t42+13u42≡72−13⋅32(mod17) which leads to solving the equation 3x≡±7(mod17). This has solution x≡±8(mod17). Indeed, (±8)2=64≡13(mod17).

References

  • Leonard Eugene Dickson, "History Of The Theory Of Numbers" vol 1 p 222, Chelsea Publishing 1952
  1. ↑ H.C. Pocklington, Proceedings of the Cambridge Philosophical Society, Volume 19, pages 57–58