 is a field in which
 is a field in which  , and
, and 
 , with
, with  , 
then
the solutions to the quadratic equation
, 
then
the solutions to the quadratic equation 
 are
 are
 
Now assume
 , with
, with  an odd prime.  Using
Theorem 4.1.7, we can decide whether or not
 an odd prime.  Using
Theorem 4.1.7, we can decide whether or not  is a
perfect square in
 is a
perfect square in 
 , and hence whether or not
, and hence whether or not 
 has a solution in
has a solution in 
 .  However
Theorem 4.1.7 says nothing about how to actually find 
a solution when there is one. 
Also, note that for this problem we do not need the
full quadratic reciprocity law; in practice to 
decide whether an element of
.  However
Theorem 4.1.7 says nothing about how to actually find 
a solution when there is one. 
Also, note that for this problem we do not need the
full quadratic reciprocity law; in practice to 
decide whether an element of 
 is
a perfect square Proposition 4.2.1 is quite fast, 
in view of Section 2.3.
 is
a perfect square Proposition 4.2.1 is quite fast, 
in view of Section 2.3.
Suppose 
 is a nonzero quadratic residue.
If
 is a nonzero quadratic residue.
If 
 then
 then 
 is a square root of
is a square root of  because
 because
 
We can compute
 in time polynomial in the number of digits of
 in time polynomial in the number of digits of  using the powering algorithm of Section 2.3.
using the powering algorithm of Section 2.3.
Suppose next that 
 .  
Unfortunately, we do not know a deterministic algorithm
that takes as input
.  
Unfortunately, we do not know a deterministic algorithm
that takes as input  and
 and  , outputs
a square root of
, outputs
a square root of  modulo
 modulo  when one exists,
and is polynomial-time in
 when one exists,
and is polynomial-time in  .
.
 in time
 in time 
 .  This beautiful algorithm (which makes use of elliptic
  curves) is not polynomial time in the sense described above since
  for large
.  This beautiful algorithm (which makes use of elliptic
  curves) is not polynomial time in the sense described above since
  for large  it takes exponentially longer than for small
 it takes exponentially longer than for small  .
.
We next describe a probabilistic algorithm to
compute a square root of  modulo
 modulo  , which is very quick
in practice.  
Recall the definition of ring from Definition 2.1.3.
We will also need the notion of ring homomorphism and isomorphism.
, which is very quick
in practice.  
Recall the definition of ring from Definition 2.1.3.
We will also need the notion of ring homomorphism and isomorphism.
 and
 and  be rings.
A homomorphism of rings
 be rings.
A homomorphism of rings 
 is a map such that for all
is a map such that for all  we have
 we have
 ,
,
 , and
, and
 .
.
 of rings is a
ring homomorphism that is bijective.
 of rings is a
ring homomorphism that is bijective.Consider the (quotient) ring
![$\displaystyle R = (\mathbb{Z}/p\mathbb{Z}{})[x]/(x^2 - a)$](img1460.png) 
defined as follows. We have
 
with multiplication defined by
 
Here
 corresponds to the class of
 corresponds to the class of  in the quotient ring.
 in the quotient ring.
 above
in SAGE as follows (for
 above
in SAGE as follows (for  ):
):
sage: S.<x> = PolynomialRing(GF(13)) sage: R.<alpha> = S.quotient(x^2 - 3) sage: (2+3*alpha)*(1+2*alpha) 7*alpha + 7
Let  and
 and  be the square roots of
 be the square roots of  in
 in 
 (though we cannot easily
compute
(though we cannot easily
compute  and
 and  yet, we can consider them in order
to deduce an algorithm to find them).
We have ring homomorphisms
 yet, we can consider them in order
to deduce an algorithm to find them).
We have ring homomorphisms
 and
 and 
 given by
given by 
 and
 and 
 .
Together these define a ring isomorphism
.
Together these define a ring isomorphism
 
given by
 .
Choose in some way a random element
.
Choose in some way a random element  of
 of 
 , and
define
, and
define 
 by
 by
 
where we compute
 quickly
using an analogue of the 
binary powering algorithm of Section 2.3.2.
If
 quickly
using an analogue of the 
binary powering algorithm of Section 2.3.2.
If  we try again with another random
 we try again with another random  .  If
.  If  we can
quickly find the desired square roots
 we can
quickly find the desired square roots  and
 and  as follows.  The
quantity
 as follows.  The
quantity  is a
 is a  power in
 power in 
 , so it equals
either 0
,
, so it equals
either 0
,  , or
, or  , so
, so  ,
,  , or
, or  ,
respectively.  Since we know
,
respectively.  Since we know  and
 and  we can try each of
 we can try each of  ,
,
 , and
, and  and see which is a square root of
 and see which is a square root of  .
.
 modulo
 modulo  .
We apply the algorithm described above in the case
.
We apply the algorithm described above in the case 
 .
We first choose the random
.
We first choose the random  and find that
 and find that
 The coefficient of
The coefficient of  in the power is 0
, and we try again with
 in the power is 0
, and we try again with
 .
This time we have
.
This time we have 
 .
The inverse of
.
The inverse of  in
 in 
 is
 is  , so we consider the
following three possibilities for a square root of
, so we consider the
following three possibilities for a square root of  :
:
 
Thus
 and
 and  are the square roots of
 are the square roots of  in
 in 
 .
.
sage: def find_sqrt(a, p): ... assert (p-1)%4 == 0 ... assert legendre_symbol(a,p) == 1 ... S.<x> = PolynomialRing(GF(p)) ... R.<alpha> = S.quotient(x^2 - a) ... while True: ... z = GF(p).random_element() ... w = (1 + z*alpha)^((p-1)//2) ... (u, v) = (w[0], w[1]) ... if v != 0: break ... if (-u/v)^2 == a: return -u/v ... if ((1-u)/v)^2 == a: return (1-u)/v ... if ((-1-u)/v)^2 == a: return (-1-u)/v ... sage: b = find_sqrt(3,13) sage: b # random: either 9 or 3 9 sage: b^2 3 sage: b = find_sqrt(3,13) sage: b # see, it's random 4 sage: find_sqrt(5,389) # random: either 303 or 86 303 sage: find_sqrt(5,389) # see, it's random 86
William 2007-06-01