Algorithm Search⌘K

Proofs: Newton power series inversion

These are the human proofs of Newton power series inversion, at full length.

NEWTON-INVERSE returns the inverse modulo x^n in at most 3M(n) + o(M(n)) operations full

This proof shows: correctness.

Let RR be a commutative ring with 11, f=∑k≥0fkxkf = \sum_{k \ge 0} f_k x^k with f0f_0 a unit of RR, and n≥1n \ge 1. Congruences are in RxRx, or equivalently between polynomials, modulo powers of xx.

Lemma 1 (existence and uniqueness). For each m≥1m \ge 1 there is exactly one polynomial gg of degree less than mm with fg≡1(modxm)fg \equiv 1 \pmod{x^m}.

Proof. Write g=∑k<mgkxkg = \sum_{k<m} g_k x^k. The coefficient of xkx^k in fgfg, for k<mk < m, is ∑j=0kfjgk−j\sum_{j=0}^{k} f_j g_{k-j}. The conditions are f0g0=1f_0 g_0 = 1 and f0gk+∑j=1kfjgk−j=0f_0 g_k + \sum_{j=1}^{k} f_j g_{k-j} = 0 for 1≤k<m1 \le k < m. Since f0f_0 is a unit, these determine g0=f0−1g_0 = f_0^{-1} and then each gkg_k from g0,…,gk−1g_0, \ldots, g_{k-1}, uniquely. □\square

Lemma 2 (precisions). Let k0=nk_0 = n, ki+1=⌈ki/2⌉k_{i+1} = \lceil k_i/2 \rceil, and let ss be the first index with ks=1k_s = 1. Then k0>k1>⋯>ks=1k_0 > k_1 > \cdots > k_s = 1, ki+1<ki≤2ki+1k_{i+1} < k_i \le 2 k_{i+1} for i<si < s, ki≤n/2i+1k_i \le n/2^i + 1, and s=⌈log⁡2n⌉s = \lceil \log_2 n \rceil.

Proof. For k≥2k \ge 2, ⌈k/2⌉<k\lceil k/2 \rceil < k, so the sequence strictly decreases until it reaches 11, and it stops there. Also k≤2⌈k/2⌉k \le 2 \lceil k/2 \rceil. For the bound, k0=nk_0 = n, and if ki≤n/2i+1k_i \le n/2^i + 1 then ki+1≤(ki+1)/2≤n/2i+1+1k_{i+1} \le (k_i + 1)/2 \le n/2^{i+1} + 1. For ss: ⌈⌈k/2⌉/2⌉=⌈k/4⌉\lceil \lceil k/2 \rceil / 2 \rceil = \lceil k/4 \rceil, so ki=⌈n/2i⌉k_i = \lceil n/2^i \rceil, which is 11 exactly when 2i≥n2^i \ge n. □\square

Lemma 3 (one step). Let 1≤m<m′≤2m1 \le m < m' \le 2m, and let gg be a polynomial of degree less than mm with fg≡1(modxm)fg \equiv 1 \pmod{x^m}. Let d=(f mod xm′)g mod xm′d = (f \bmod x^{m'}) g \bmod x^{m'}, t=−∑j=0m′−m−1dm+jxjt = -\sum_{j=0}^{m'-m-1} d_{m+j} x^j, c=gt mod xm′−mc = g t \bmod x^{m'-m}, and g′=g+xmcg' = g + x^m c. Then deg⁡g′<m′\deg g' < m' and fg′≡1(modxm′)f g' \equiv 1 \pmod{x^{m'}}.

Proof. Since f≡(f mod xm′)(modxm′)f \equiv (f \bmod x^{m'}) \pmod{x^{m'}}, d≡fg(modxm′)d \equiv fg \pmod{x^{m'}}. By hypothesis d0=1d_0 = 1 and d1=⋯=dm−1=0d_1 = \cdots = d_{m-1} = 0. So e:=1−fg≡1−d=xmt(modxm′)e := 1 - fg \equiv 1 - d = x^m t \pmod{x^{m'}}. Next, xmc≡xmgt(modxm′)x^m c \equiv x^m g t \pmod{x^{m'}}, because c≡gt(modxm′−m)c \equiv gt \pmod{x^{m'-m}} and multiplying by xmx^m moves the modulus to xm′x^{m'}. So g′≡g+g xmt≡g+ge(modxm′)g' \equiv g + g\, x^m t \equiv g + g e \pmod{x^{m'}}. Then

1−fg′≡1−fg−fg e=e−(1−e) e=e2(modxm′).1 - f g' \equiv 1 - fg - fg\, e = e - (1 - e)\, e = e^2 \pmod{x^{m'}}.

Since e≡xmt(modxm′)e \equiv x^m t \pmod{x^{m'}}, e2≡x2mt2≡0(modxm′)e^2 \equiv x^{2m} t^2 \equiv 0 \pmod{x^{m'}} as 2m≥m′2m \ge m'. For the degree, deg⁡g<m\deg g < m and deg⁡(xmc)<m+(m′−m)=m′\deg(x^m c) < m + (m' - m) = m'. □\square

Theorem (correctness). NEWTON-INVERSE(f,n)(f, n) returns the unique gg of degree less than nn with fg≡1(modxn)fg \equiv 1 \pmod{x^n}, as a list of nn coefficients.

Proof. We show that at the start of each iteration of line L3, and after the loop, gg is a list of mm coefficients with fg≡1(modxm)fg \equiv 1 \pmod{x^m}, where mm is the precision reached so far. After lines L1 and L2, g=[f0−1]g = [f_0^{-1}] and m=1m = 1, and fg≡f0f0−1=1(modx)f g \equiv f_0 f_0^{-1} = 1 \pmod x. The loop visits m′=ks−1,ks−2,…,k0m' = k_{s-1}, k_{s-2}, \ldots, k_0 in this order, starting from m=ksm = k_s, so in each iteration m=ki+1m = k_{i+1} and m′=kim' = k_i for some ii, and m<m′≤2mm < m' \le 2m by Lemma 2. Lines L4 to L7 compute dd, tt, cc and g′g' of Lemma 3, so after line L7 the claim holds for m′m'. The list gg then has m+(m′−m)=m′m + (m' - m) = m' entries, because cc is padded to m′−mm' - m entries. After the last iteration m=k0=nm = k_0 = n (if n=1n = 1, there is no iteration and m=1=nm = 1 = n). By Lemma 1, gg is the unique inverse modulo xnx^n. □\square

Theorem (cost). Assume that multiplying a polynomial with aa coefficients by one with b≤ab \le a coefficients costs at most M(a)M(a) ring operations, and that M(k)/kM(k)/k is nondecreasing. Then NEWTON-INVERSE(f,n)(f, n) uses at most 3M(n)+2⌈log⁡2n⌉ M(n)/n+O(n)3M(n) + 2 \lceil \log_2 n \rceil\, M(n)/n + O(n) ring operations, plus one inversion in RR. Since log⁡n/n→0\log n / n \to 0, this is 3M(n)+o(M(n))3M(n) + o(M(n)).

Proof. Consider the iteration with m=ki+1m = k_{i+1} and m′=kim' = k_i, for 0≤i<s0 \le i < s. Line L4 multiplies kik_i by ki+1k_{i+1} coefficients, at most M(ki)M(k_i). Line L6 multiplies ki+1k_{i+1} by ki−ki+1≤ki+1k_i - k_{i+1} \le k_{i+1} coefficients, at most M(ki+1)M(k_{i+1}). Lines L5 and L7 and the padding cost O(ki)O(k_i). Since M(k)/kM(k)/k is nondecreasing and ki≤nk_i \le n, M(ki)≤(ki/n)M(n)≤(2−i+1/n)M(n)M(k_i) \le (k_i / n) M(n) \le (2^{-i} + 1/n) M(n) by Lemma 2. So

∑i=0s−1M(ki)≤(∑i≥02−i+sn)M(n)≤2M(n)+s M(n)n,∑i=0s−1M(ki+1)=∑i=1sM(ki)≤M(n)+s M(n)n.\sum_{i=0}^{s-1} M(k_i) \le \Bigl(\sum_{i \ge 0} 2^{-i} + \frac{s}{n}\Bigr) M(n) \le 2M(n) + s\, \frac{M(n)}{n}, \qquad \sum_{i=0}^{s-1} M(k_{i+1}) = \sum_{i=1}^{s} M(k_i) \le M(n) + s\, \frac{M(n)}{n}.

The linear terms sum to O(∑iki)=O(n)O(\sum_i k_i) = O(n), because ∑iki≤∑i(n/2i+1)≤2n+s\sum_i k_i \le \sum_i (n/2^i + 1) \le 2n + s. Adding up, with s=⌈log⁡2n⌉s = \lceil \log_2 n \rceil from Lemma 2, gives the bound. ■\blacksquare

Back to Newton power series inversion