Macaulay2 » Documentation
Packages » Macaulay2Doc » elementary arithmetic » sqrt(ZZ,ZZ)
next | previous | forward | backward | up | index | toc

sqrt(ZZ,ZZ) -- modular square root

Description

This returns a solution of the equation $x^2\equiv n\pmod p$, provided that n is a quadratic residue modulo p. If it is not, then an error is raised.

i1 : powermod(5, (41 - 1) // 2, 41) -- Euler's criterion

o1 = 1
i2 : sqrt(5, 41)

o2 = 13
i3 : powermod(13, 2, 41)

o3 = 5

Every quadratic residue modulo an odd prime has two square roots. The second square root may be obtained by subtracting the first from p.

i4 : powermod(28, 2, 41)

o4 = 5

This method may also be used for finding square roots in finite prime fields.

i5 : sqrt(5_(ZZ/41))

o5 = 13

     ZZ
o5 : --
     41
i6 : sqrt(5_(GF 41))

o6 = 13

o6 : GF 41

References

Shanks, Daniel. "Five number-theoretic algorithms." Proceedings of the Second Manitoba Conference on Numerical Mathematics (Winnipeg), 1973.

See also

Ways to use this method:


The source of this document is in Macaulay2Doc/operators.m2:149:0.