For clarity, we give several examples to demonstrate the algorithm.
Square roots of complex polynomials modulo a polynomial
Suppose h is a complex polynomial not divisible by x (that is, it has a nonzero constant term). Find its square root modulo xn.
We have the equation:
G(f(x))=f2(x)−h(x)≡0(modxn)
Taylor expansion of G gives the following. Note that this expansion is with respect to f, so all derivatives are partial derivatives with respect to f; x is treated as a constant here.
Use doubling. Suppose the intermediate results in the doubling process are f0(x),f1(x),…,fj(x); more precisely, fj(x) is a complex polynomial satisfying G(fj(x))≡0(modx2j), and for uniqueness it also satisfies:
The degree of fj(x) is no greater than x2j;
fj+k(x)−fj(x)≡0(modx2j) for every k.
Substituting fj+1(x) and fj(x) into the equation above gives:
If fj(x) exists, then 2fj(x) is not divisible by x (it has a nonzero constant term), so it has an inverse modulo x2j+1. Thus the sequence f0,f1…,fj exists if and only if f0 exists. A complex polynomial not divisible by x, namely h(x), always has a square root modulo x, because reducing h(x) modulo x gives an ordinary nonzero complex number, which always has two square roots. Therefore this algorithm works for every h(x) with a nonzero constant term.
f0(x)=−1,f1(x)=2×(−1)(−1)2+x+1modx2=−21x−1,… (the negative of the preceding one)
It can be verified that both are valid sequences of polynomial square roots modulo the modulus.
Square roots of integers modulo prime powers
Newton iteration also extends to the case of integers modulo powers of a prime.
Suppose h is a “convenient” integer not divisible by 3 (“convenient” means that a solution is guaranteed to exist; the precise condition is given below). Suppose the square root of h modulo 3n to be computed is f. We have:
Use doubling. Suppose the intermediate results obtained during doubling are f0,f1,…,fj; more rigorously, fj is an integer satisfying G(fj)≡0(mod32j), and for uniqueness it also satisfies:
0<fj<32j;
fj+k−fj≡0(mod32j) for every k.
Substituting fj+1 and fj into the equation above gives:
Clearly, fj+1−fj must be a multiple of 32j. Therefore,
fj+1≡fj−2fjfj2−h≡2fjfj2+h(mod32j+1)
If fj exists, then 2fj is not divisible by 3, so it has an inverse modulo 32j+1. Thus the sequence f0,f1…,fj exists if and only if f0 exists. An integer h not divisible by 3 either has no square root or has two modulo 3. Therefore, h having a square root modulo 3 is the only condition needed for the algorithm to run.
f0=2,f1=2×222+46mod9=8,f2=2×882+46mod81=17,f3=2×17172+46mod6561=5606,… (the negative of the preceding one)
It can be verified that both are valid sequences of square roots modulo prime powers.
Algebraic proof
This section develops the preceding discussion further. Using the language of abstract algebra, we prove that as long as f satisfies the initial-solution condition, Newton's method produces a solution for every n and can produce all solutions.
Proof of existence
Lemma 1
Let the integral domainR contain a polynomial or formal power seriesf(X)=∑i≥0aiXi, and let r,p∈R satisfy f(r)∈Rp (that is, r is a root of f(X) modulo p) while f′(r)∈R is invertible modulo p. Here f′(X):=∑i≥0(i+1)ai+1Xi is the formal derivative of f(X). Then f(r−f′(r)f(r))≡0(modp2).
Since f(r)∈Rp and f′(r) is invertible, it suffices to take sp=−f′(r)f(r); here f′(r)1 is the inverse modulo p2. Because f′(r) is invertible modulo p, it must also have an inverse modulo p2: let a,b,c∈R satisfy af′(r)=bp+1 and f(r)=cp. Then (a2f′(r)−2)f′(r)=b2p2+1, so we may take s=c(2−a2f′(r)).
For a field k, consider its polynomial ring k[X]. Suppose G(X,Y)∈k[X,Y] and fn∈k[X] satisfy G(X,fn(X))∈k[X]Xn. Applying Lemma 1 gives
G(X,fn(X)−∂Y∂G(X,fn(X))G(X,fn(X)))≡0(modX2n)
For doubling, the initial conditions only require an f1∈k such that G(X,f1)≡0(modX) and ∂Y∂G(X,f1)≡0(modX). The latter condition ensures that ∂Y∂G has a nonzero constant term. Since X∂Y∂G(X,fn(X))G(X,fn(X)), for every n, ∂Y∂G(X,fn) is always invertible modulo Xn, so the condition for the next iteration is satisfied.
Proof that all solutions are obtained
Lemma 2
If R is a UFD, with f,r,p defined as in Lemma 1, then the value r−f′(r)f(r) given by Lemma 1 is, modulo p2, the unique value of x satisfying:
f(x)∈Rp2
x−r∈Rp
In other words,
∀x∈R,p2∣f(x)∧p∣(x−r)⟹x≡r−f′(r)f(r)(modp2)Proof
Let s=−f′(r)pf(r) and u=r+sp. Lemma 1 guarantees that u satisfies both conditions, and that f(r)+f′(r)sp∈Rp2.
If v is a value satisfying the conditions above, then v=r+tp and f(r)+f′(r)tp∈Rp2.
Hence f′(r)(t−s)p∈Rp2 and v−u∈Rp2.
Newton's method can obtain all solutions modulo X2n. Suppose G(X,h)≡0(modX2n). Set h2i:=h(modX2i), take f1=h1, and apply Newton's method. Lemma 2 gives f2i≡h2i(modX2i), so necessarily f2n=h.
The argument above also shows that when ∂y∂G(0,y) is always invertible, the number of solutions to G(X,f)≡0(modXn) equals the number of solutions to G(0,f)≡0(modX). This conclusion is not trivial; consider the following example.
An example where the number of solutions increases with the degree when Newton's method is invalid
Modulo X, the only square root of X2 is 0, but modulo X4, the square roots of X2 include X,−X,X3+X,….