Polynomial Newton iteration

Description

Given a polynomial G(x,y)G\left(x, y\right), suppose the polynomial f(x)f\left(x\right) satisfies:

G(x,f(x))≡0(modxn)G\left(x, f\left(x\right)\right)\equiv 0\pmod{x^{n}}

and there is a value f1f_1 such that G(x,y)G\left(x, y\right) satisfies the following conditions:

  • G(0,f1)=0G(0, f_1) = 0;
  • ∂G∂y(0,f1)≠0\dfrac{\partial G}{\partial y}(0, f_1) \neq 0.

Find, modulo xnx^{n}, f(x)f\left(x\right).

Newton's Method

Consider doubling the precision.

First, when n=1n=1, the solution to [x0]G(x,f(x))=0\left[x^{0}\right]G\left(x, f\left(x\right)\right)=0 must be found separately; the f1f_1 in the assumption is one such solution.

Suppose we have obtained, modulo x⌈n2⌉x^{\left\lceil\frac{n}{2}\right\rceil}, a solution f⌈n2⌉(x)f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right), and want, modulo xnx^{n}, a solution f(x)=fn(x)f\left(x\right) = f_n\left(x\right).

Expand G(x,f(x))G\left(x, f(x)\right) in a Taylor series in f(x)f(x) around f(x)=f⌈n2⌉(x)f(x)=f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right):

∑i=0+∞∂iG∂yi(x,f⌈n2⌉(x))i!(f(x)−f⌈n2⌉(x))i≡0(modxn)\sum_{i=0}^{+\infty}\frac{\frac{\partial^i G}{\partial y^i}\left(x, f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)}{i!}\left(f\left(x\right)-f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)^{i}\equiv 0\pmod{x^{n}}

Because the lowest possible degree of a nonzero term in f(x)−f⌈n2⌉(x)f\left(x\right)-f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right) is ⌈n2⌉\left\lceil\frac{n}{2}\right\rceil, we have:

∀2⩽i:(f(x)−f⌈n2⌉(x))i≡0(modxn)\forall 2\leqslant i:\left(f\left(x\right)-f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)^{i}\equiv 0\pmod{x^{n}}

Thus:

∑i=0+∞∂iG∂yi(x,f⌈n2⌉(x))i!(f(x)−f⌈n2⌉(x))i≡G(x,f⌈n2⌉(x))+∂G∂y(x,f⌈n2⌉(x))[f(x)−f⌈n2⌉(x)]≡0(modxn)\begin{aligned} \sum_{i=0}^{+\infty}\frac{\frac{\partial^i G}{\partial y^i}\left(x, f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)}{i!}\left(f\left(x\right)-f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)^{i}&\equiv G\left(x, f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)+\frac{\partial G}{\partial y}\left(x, f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)\left[f\left(x\right)-f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right]\\ &\equiv 0\pmod{x^{n}} \end{aligned} fn(x)≡f⌈n2⌉(x)−G(x,f⌈n2⌉(x))∂G∂y(x,f⌈n2⌉(x))(modxn)f_n\left(x\right)\equiv f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)-\frac{G\left(x, f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)}{\frac{\partial G}{\partial y}\left(x, f_{\left\lceil\frac{n}{2}\right\rceil}\left(x\right)\right)}\pmod{x^{n}}

Or, equivalently,

f2n(x)≡fn(x)−G(x,fn(x))∂G∂y(x,fn(x))(modx2n)f_{2n}\left(x\right)\equiv f_n\left(x\right)-\frac{G\left(x, f_n\left(x\right)\right)}{\frac{\partial G}{\partial y}\left(x, f_n\left(x\right)\right)}\pmod{x^{2n}}

Examples

Polynomial inversion

Let the given function be h(x)h\left(x\right), with:

G(x,y)=1y−h(x)G\left(x, y\right)=\frac{1}{y}-h\left(x\right)

Applying Newton's Method gives:

f2n(x)≡fn(x)−1/fn(x)−h(x)−1/fn2(x)(modx2n)≡2fn(x)−fn2(x)h(x)(modx2n)\begin{aligned} f_{2n}\left(x\right)&\equiv f_{n}\left(x\right)-\frac{1/f_{n}\left(x\right)-h\left(x\right)}{-1/f_{n}^{2}\left(x\right)}&\pmod{x^{2n}}\\ &\equiv 2f_{n}\left(x\right)-f_{n}^{2}\left(x\right)h\left(x\right)&\pmod{x^{2n}} \end{aligned}

The time complexity is

T(n)=T(n2)+O(nlog⁡n)=O(nlog⁡n)T\left(n\right)=T\left(\frac{n}{2}\right)+O\left(n\log{n}\right)=O\left(n\log{n}\right)

Polynomial square root

Let the given function be h(x)h\left(x\right), with:

G(x,y)=y2−h(x)≡0G\left(x, y\right)=y^{2}-h\left(x\right)\equiv 0

Applying Newton's Method gives:

f2n(x)≡fn(x)−fn2(x)−h(x)2fn(x)(modx2n)≡fn2(x)+h(x)2fn(x)(modx2n)\begin{aligned} f_{2n}\left(x\right)&\equiv f_{n}\left(x\right)-\frac{f_{n}^{2}\left(x\right)-h\left(x\right)}{2f_{n}\left(x\right)}&\pmod{x^{2n}}\\ &\equiv\frac{f_{n}^{2}\left(x\right)+h\left(x\right)}{2f_{n}\left(x\right)}&\pmod{x^{2n}} \end{aligned}

The time complexity is

T(n)=T(n2)+O(nlog⁡n)=O(nlog⁡n)T\left(n\right)=T\left(\frac{n}{2}\right)+O\left(n\log{n}\right)=O\left(n\log{n}\right)

Polynomial exponential function

Let the given function be h(x)h\left(x\right), with:

G(x,y)=ln⁡y−h(x)G\left(x, y\right)=\ln{y}-h\left(x\right)

Applying Newton's Method gives:

f2n(x)≡fn(x)−ln⁡fn(x)−h(x)1/fn(x)(modx2n)≡fn(x)(1−ln⁡fn(x)+h(x))(modx2n)\begin{aligned} f_{2n}\left(x\right)&\equiv f_{n}\left(x\right)-\frac{\ln{f_{n}\left(x\right)}-h\left(x\right)}{1/f_{n}\left(x\right)}&\pmod{x^{2n}}\\ &\equiv f_{n}\left(x\right)\left(1-\ln{f_{n}\left(x\right)+h\left(x\right)}\right)&\pmod{x^{2n}} \end{aligned}

The time complexity is

T(n)=T(n2)+O(nlog⁡n)=O(nlog⁡n)T\left(n\right)=T\left(\frac{n}{2}\right)+O\left(n\log{n}\right)=O\left(n\log{n}\right)

Worked examples

For clarity, we give several examples to demonstrate the algorithm.

Square roots of complex polynomials modulo a polynomial

Suppose hh is a complex polynomial not divisible by xx (that is, it has a nonzero constant term). Find its square root modulo xnx^n.

We have the equation:

G(f(x))=f2(x)−h(x)≡0(modxn)G\left(f(x)\right) = f^2(x)-h(x) \equiv 0\pmod{x^{n}}

Taylor expansion of GG gives the following. Note that this expansion is with respect to ff, so all derivatives are partial derivatives with respect to ff; xx is treated as a constant here.

G(f(x))=∑i=0+∞G(i)(f0(x))i!(f(x)−f0(x))i=G(f0(x))+2f0(x)(f(x)−f0(x))+(f(x)−f0(x))2G(f(x)) = \sum_{i=0}^{+\infty}\frac{G^{\left(i\right)}\left(f_{0}(x)\right)}{i!}\left(f(x)-f_{0}(x)\right)^{i} = G(f_0(x)) + 2f_0(x)(f(x)-f_0(x)) + (f(x)-f_0(x))^2

Use doubling. Suppose the intermediate results in the doubling process are f0(x),f1(x),…,fj(x)f_0(x), f_1(x), \ldots, f_j(x); more precisely, fj(x)f_j(x) is a complex polynomial satisfying G(fj(x))≡0(modx2j)G(f_j(x))\equiv 0\pmod{x^{2^j}}, and for uniqueness it also satisfies:

  • The degree of fj(x)f_{j}(x) is no greater than x2jx^{2^j};
  • fj+k(x)−fj(x)≡0(modx2j)f_{j+k}(x)-f_j(x)\equiv 0\pmod{x^{2^j}} for every kk.

Substituting fj+1(x)f_{j+1}(x) and fj(x)f_j(x) into the equation above gives:

G(fj+1(x))=G(fj(x))+2fj(fj+1(x)−fj(x))+(fj+1(x)−fj(x))2≡0(modx2j+1)G(f_{j+1}(x)) = G(f_j(x)) + 2f_j(f_{j+1}(x)-f_j(x)) + (f_{j+1}(x)-f_{j}(x))^2 \equiv 0 \pmod{x^{2^{j+1}}}

Clearly, fj+1(x)−fj(x)f_{j+1}(x)-f_j(x) must be a multiple of x2jx^{2^j}. Therefore,

fj+1(x)≡fj(x)−fj2(x)−h(x)2fj(x)≡fj(x)2+h(x)2fj(x)(modx2j+1)f_{j+1}(x) \equiv f_j(x) - \frac{f_j^2(x)-h(x)}{2f_j(x)} \equiv \frac{f_j(x)^2 + h(x)}{2f_j(x)} \pmod{x^{2^{j+1}}}

If fj(x)f_j(x) exists, then 2fj(x)2f_j(x) is not divisible by xx (it has a nonzero constant term), so it has an inverse modulo x2j+1x^{2^{j+1}}. Thus the sequence f0,f1…,fjf_0,f_1\ldots,f_j exists if and only if f0f_0 exists. A complex polynomial not divisible by xx, namely h(x)h(x), always has a square root modulo xx, because reducing h(x)h(x) modulo xx gives an ordinary nonzero complex number, which always has two square roots. Therefore this algorithm works for every h(x)h(x) with a nonzero constant term.

For example, take h(x)=x+1h(x)=x+1:

  • f0(x)=1f_0(x)=1,f1(x)=12+x+12×1mod  x2=12x+1f_1(x)=\dfrac{1^2+x+1}{2\times 1}\mod x^2 = \dfrac{1}{2}x+1,f2(x)=(12x+1)2+x+12×(12x+1)mod  x4=116x3−18x2+12x+1f_2(x)=\dfrac{\left(\dfrac{1}{2}x+1\right)^2+x+1}{2\times \left(\dfrac{1}{2}x+1\right)}\mod x^4 = \dfrac{1}{16}x^3-\dfrac{1}{8}x^2+\dfrac{1}{2}x+1,…\ldots
  • f0(x)=−1f_0(x)=-1,f1(x)=(−1)2+x+12×(−1)mod  x2=−12x−1f_1(x)=\dfrac{(-1)^2+x+1}{2\times (-1)}\mod x^2 = -\dfrac{1}{2}x-1,…\ldots (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 hh 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 hh modulo 3n3^n to be computed is ff. We have:

G(f)=f2−h≡0(mod3n)G\left(f\right) = f^2-h \equiv 0\pmod{3^{n}}

Taylor expansion of GG gives:

G(f)=∑i=0+∞G(i)(f0)i!(f−f0)i=G(f0)+2f0(f−f0)+(f−f0)2G(f) = \sum_{i=0}^{+\infty}\frac{G^{\left(i\right)}\left(f_{0}\right)}{i!}\left(f-f_{0}\right)^{i} = G(f_0) + 2f_0(f-f_0) + (f-f_0)^2

Use doubling. Suppose the intermediate results obtained during doubling are f0,f1,…,fjf_0, f_1, \ldots, f_j; more rigorously, fjf_j is an integer satisfying G(fj)≡0(mod32j)G(f_j)\equiv 0\pmod{3^{2^j}}, and for uniqueness it also satisfies:

  • 0<fj<32j0 < f_{j} < 3^{2^j};
  • fj+k−fj≡0(mod32j)f_{j+k}-f_j\equiv 0\pmod{3^{2^j}} for every kk.

Substituting fj+1f_{j+1} and fjf_j into the equation above gives:

G(fj+1)=G(fj)+2fj(fj+1−fj)+(fj+1−fj)2≡0(mod32j+1)G(f_{j+1}) = G(f_j) + 2f_j(f_{j+1}-f_j) + (f_{j+1}-f_{j})^2 \equiv 0 \pmod{3^{2^{j+1}}}

Clearly, fj+1−fjf_{j+1}-f_j must be a multiple of 32j3^{2^j}. Therefore,

fj+1≡fj−fj2−h2fj≡fj2+h2fj(mod32j+1)f_{j+1} \equiv f_j - \frac{f_j^2-h}{2f_j} \equiv \frac{f_j^2 + h}{2f_j} \pmod{3^{2^{j+1}}}

If fjf_j exists, then 2fj2f_j is not divisible by 33, so it has an inverse modulo 32j+13^{2^{j+1}}. Thus the sequence f0,f1…,fjf_0,f_1\ldots,f_j exists if and only if f0f_0 exists. An integer hh not divisible by 3 either has no square root or has two modulo 33. Therefore, hh having a square root modulo 33 is the only condition needed for the algorithm to run.

Here is a worked example with h=46h=46.

  • f0=1f_0=1,f1=12+462×1mod  9=1f_1=\dfrac{1^2+46}{2\times 1}\mod 9 = 1,f2=12+462×1mod  81=64f_2=\dfrac{1^2+46}{2\times 1}\mod 81 = 64,f3=642+462×64mod  6561=955f_3=\dfrac{64^2+46}{2\times 64}\mod 6561 = 955,…\ldots
  • f0=2f_0=2,f1=22+462×2mod  9=8f_1=\dfrac{2^2+46}{2\times 2}\mod 9 = 8,f2=82+462×8mod  81=17f_2=\dfrac{8^2+46}{2\times 8}\mod 81 = 17,f3=172+462×17mod  6561=5606f_3=\dfrac{17^2+46}{2\times 17}\mod 6561 = 5606,…\ldots (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 ff satisfies the initial-solution condition, Newton's method produces a solution for every nn and can produce all solutions.

Proof of existence

Lemma 1

Let the integral domain RR contain a polynomial or formal power series f(X)=∑i≥0aiXif(X) = \sum_{i\geq 0}a_iX^i, and let r,p∈Rr,p\in R satisfy f(r)∈Rpf(r)\in Rp (that is, rr is a root of f(X)f(X) modulo pp) while f′(r)∈Rf'(r)\in R is invertible modulo pp. Here f′(X):=∑i≥0(i+1)ai+1Xif'(X) := \sum_{i\geq 0}(i+1)a_{i+1}X^i is the formal derivative of f(X)f(X). Then f(r−f(r)f′(r))≡0(modp2)f\left(r-\dfrac{f(r)}{f'(r)}\right) \equiv 0\pmod {p^2}.

Proof

For every s∈Rs\in R,

f(r+sp)=∑i≥0ai(r+sp)i=∑i≥0airi+sp∑i≥1iairi−1+s2p2(…)=f(r)+spf′(r)+s2p2(f′′(r)2!+⋯ ),\begin{aligned} f(r+sp) &= \sum_{i\geq 0}a_i(r+sp)^i \\ &= \sum_{i\geq 0}a_ir^i + sp\sum_{i\geq 1}ia_ir^{i-1} + s^2p^2\left(\ldots\right) \\ &= f(r) + spf'(r) + s^2p^2\left(\frac{f''(r)}{2!} + \cdots\right), \end{aligned}

Therefore

f(r+sp)∈Rp2  ⟺  f(r)+f′(r)sp∈Rp2f(r+sp) \in Rp^2 \iff f(r)+f'(r)sp \in Rp^2

Since f(r)∈Rpf(r)\in Rp and f′(r)f'(r) is invertible, it suffices to take sp=−f(r)f′(r)sp = -\dfrac{f(r)}{f'(r)}; here 1f′(r)\dfrac{1}{f'(r)} is the inverse modulo p2p^2. Because f′(r)f'(r) is invertible modulo pp, it must also have an inverse modulo p2p^2: let a,b,c∈Ra,b,c\in R satisfy af′(r)=bp+1af'(r) = bp+1 and f(r)=cpf(r)=cp. Then (a2f′(r)−2)f′(r)=b2p2+1\left(a^2f'(r)-2\right)f'(r) = b^2p^2+1, so we may take s=c(2−a2f′(r))s=c(2-a^2f'(r)).

For a field kk, consider its polynomial ring k[X]k[X]. Suppose G(X,Y)∈k[X,Y]G(X, Y)\in k[X, Y] and fn∈k[X]f_n\in k[X] satisfy G(X,fn(X))∈k[X]XnG(X, f_n(X))\in k[X]X^n. Applying Lemma 1 gives

G(X,fn(X)−G(X,fn(X))∂G∂Y(X,fn(X)))≡0(modX2n)G\left(X, f_n(X) - \frac{G(X, f_n(X))}{\frac{\partial G}{\partial Y}(X, f_n(X))} \right)\equiv 0 \pmod {X^{2n}}

For doubling, the initial conditions only require an f1∈kf_1\in k such that G(X,f1)≡0(modX)G(X, f_1)\equiv 0\pmod X and ∂G∂Y(X,f1)≢0(modX)\dfrac{\partial G}{\partial Y}(X, f_1)\not\equiv 0\pmod X. The latter condition ensures that ∂G∂Y\dfrac{\partial G}{\partial Y} has a nonzero constant term. Since X∣G(X,fn(X))∂G∂Y(X,fn(X))X\left| \dfrac{G(X, f_n(X))}{\frac{\partial G}{\partial Y}(X, f_n(X))} \right., for every nn, ∂G∂Y(X,fn)\dfrac{\partial G}{\partial Y}(X, f_n) is always invertible modulo XnX^n, so the condition for the next iteration is satisfied.

Proof that all solutions are obtained

Lemma 2

If RR is a UFD, with f,r,pf,r,p defined as in Lemma 1, then the value r−f(r)f′(r)r-\dfrac{f(r)}{f'(r)} given by Lemma 1 is, modulo p2p^{2}, the unique value of xx satisfying:

  • f(x)∈Rp2f(x)\in Rp^{2}
  • x−r∈Rpx-r\in Rp

In other words,

∀x∈R,p2∣f(x)∧p∣(x−r)  ⟹  x≡r−f(r)f′(r)(modp2)\forall x\in R,\qquad p^2\mid f(x)\wedge p\mid (x-r) \implies x\equiv r-\dfrac{f(r)}{f'(r)} \pmod {p^2}
Proof

Let s=−f(r)f′(r)ps = -\dfrac{f(r)}{f'(r)p} and u=r+spu = r+sp. Lemma 1 guarantees that uu satisfies both conditions, and that f(r)+f′(r)sp∈Rp2f(r) + f'(r)sp \in Rp^{2}. If vv is a value satisfying the conditions above, then v=r+tpv = r+tp and f(r)+f′(r)tp∈Rp2f(r) + f'(r)tp \in Rp^{2}. Hence f′(r)(t−s)p∈Rp2f'(r)(t-s)p\in Rp^{2} and v−u∈Rp2v-u\in Rp^{2}.

Newton's method can obtain all solutions modulo X2nX^{2^n}. Suppose G(X,h)≡0(modX2n)G(X, h)\equiv 0\pmod {X^{2^n}}. Set h2i:=h(modX2i)h_{2^i} := h\pmod {X^{2^i}}, take f1=h1f_1 = h_1, and apply Newton's method. Lemma 2 gives f2i≡h2i(modX2i)f_{2^i} \equiv h_{2^i}\pmod {X^{2^i}}, so necessarily f2n=hf_{2^n} = h.

The argument above also shows that when ∂G∂y(0,y)\dfrac{\partial G}{\partial y}(0, y) is always invertible, the number of solutions to G(X,f)≡0(modXn)G(X, f)\equiv 0\pmod {X^n} equals the number of solutions to G(0,f)≡0(modX)G(0, f)\equiv 0\pmod X. 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 XX, the only square root of X2X^2 is 00, but modulo X4X^4, the square roots of X2X^2 include X,−X,X3+X,…X, -X, X^3+X, \ldots.

This content comes from OI Wiki: Polynomial Newton iteration. See the original for authors and revision history. AIOJ has adapted the formatting, in-site links, and resource paths.

Content is shared under CC BY-SA 4.0 and SATA license; additional terms are governed by the original notice. Thanks to the OI Wiki authors and contributors; per the SATA terms, please visit the OI Wiki repository and star it to show your support.