Section 16.1 Square Roots
ΒΆSubsection 16.1.1 Recalling existing answers
ΒΆTo use the quadratic formula in full generality, one needs to know whether one can take square roots (for example, if they are complex, you won't have a real solution). So too, our first task for modular arithmetic will be finding such square roots. Given our work in Chapter 7, e.g. Fact 7.2.2, it should be sufficient to solveFact 16.1.1.
The congruence x2β‘1 (mod p), for p prime, always has the solution(s) xβ‘Β±1. So if p=2 there is one solution, and otherwise 1 has two square roots modulo p.
Fact 16.1.2.
The congruence x2β‘β1 (mod p), for p prime, does not always have solutions. It does precisely when p=2 (where xβ‘1) and when pβ‘1 (mod 4), which has the two solutions
where again the exclamation point here indicates the factorial.
Subsection 16.1.2 Finding more answers
ΒΆWe know the full answer (any modulus) for square roots of +1 from Fact 7.3.1. What about finding out when β1 has a square root for non-prime moduli? We can ask Sage about this:xxxxxxxxxx
var('x')
def _(n=50):
for i in [2..n]:
sols = [sol[0] for sol in solve_mod([x^2==-1],i)]
l = len(sols)
if l!=0:
pretty_print(html("$x^2=-1\\text{ (mod }%s)$ has $%s$ solutions, $%s$"%(i,l,sols)))
Example 16.1.3. Prime power modulus.
For instance, let's go from p to p2 by trying a bit of Example 7.2.4 from earlier. Here, f(x)=x2+1 is what we want a solution for. If we are looking (mod 25), then we already know that (mod 5) we have xβ‘2 as a solution. Then a solution (mod 25) will look like 2+k(5) (again recall Example 7.2.4).
Remembering that fβ²(x)=2x, in fact it will satisfy
which is 1+4kβ‘0, which has solution kβ‘1; hence a solution (mod 25) should be 2+1(5)β‘7. And indeed 72+1=50 is divisible by 25 as expected!
(Notice that 5β€fβ²(2)=4, so the technical condition is granted; otherwise we'd have 1β‘0 to solve!)
Example 16.1.4. Composite moduli.
Suppose I want solutions to x2β‘β1 (mod 14). I should immediately note that although x2β‘β1 (mod 2) has a solution, x2β‘β1 (mod 7) does not (it's a prime of the form 4k+3) so there will be no solutions modulo 14 either.
But if I am looking (mod 65), since 65=5β 13 and x2β‘β1 has solutions both (mod 5) and (mod 13), I can use the Chinese Remainder Theorem to combine them:
xβ‘2 (mod 5)
xβ‘5 (mod 13)
We combine them thus:
And that also is consistent with the computations in the Sage interact above!
Algorithm 16.1.5.
To solve a polynomial modulo a given modulus n, the following information suffices, granted the technical condition for the first bullet that gcd(p,fβ²(x))=1 for a solution x modulo a prime factorβ1βWhy not prime power factor? Because in the construction of Theorem 7.2.3 solutions modulo \(p^e\) are also solutions modulo \(p\text{.}\) So if \(p\) divides \(f'(x_e)\) for a solution \(x_e\text{,}\) it will already divide \(f'(x)\) for a solution modulo \(p\text{.}\) pβ£n.
-
If we can solve, for a given prime p,
f(x)β‘0 (mod p),we can solve
f(x)β‘0 (mod pe). -
If we can solve, for coprime integers p and q, f(x)β‘0 (mod p) and (q), then we can solve
f(x)β‘0 (mod pq).