NEWTON-INVERSE returns the inverse modulo x^n in at most 3M(n) + o(M(n)) operations full
This proof shows: correctness.
Let R be a commutative ring with 1, f=∑k≥0fkxk with f0 a unit of R, and n≥1. Congruences are in Rx, or equivalently between polynomials, modulo powers of x.
Lemma 1 (existence and uniqueness). For each m≥1 there is exactly one polynomial g of degree less than m with fg≡1(modxm).
Proof. Write g=∑k<mgkxk. The coefficient of xk in fg, for k<m, is ∑j=0kfjgk−j. The conditions are f0g0=1 and f0gk+∑j=1kfjgk−j=0 for 1≤k<m. Since f0 is a unit, these determine g0=f0−1 and then each gk from g0,…,gk−1, uniquely. □
Lemma 2 (precisions). Let k0=n, ki+1=⌈ki/2⌉, and let s be the first index with ks=1. Then k0>k1>⋯>ks=1, ki+1<ki≤2ki+1 for i<s, ki≤n/2i+1, and s=⌈log2n⌉.
Proof. For k≥2, ⌈k/2⌉<k, so the sequence strictly decreases until it reaches 1, and it stops there. Also k≤2⌈k/2⌉. For the bound, k0=n, and if ki≤n/2i+1 then ki+1≤(ki+1)/2≤n/2i+1+1. For s: ⌈⌈k/2⌉/2⌉=⌈k/4⌉, so ki=⌈n/2i⌉, which is 1 exactly when 2i≥n. □
Lemma 3 (one step). Let 1≤m<m′≤2m, and let g be a polynomial of degree less than m with fg≡1(modxm). Let d=(fmodxm′)gmodxm′, t=−∑j=0m′−m−1dm+jxj, c=gtmodxm′−m, and g′=g+xmc. Then degg′<m′ and fg′≡1(modxm′).
Proof. Since f≡(fmodxm′)(modxm′), d≡fg(modxm′). By hypothesis d0=1 and d1=⋯=dm−1=0. So e:=1−fg≡1−d=xmt(modxm′). Next, xmc≡xmgt(modxm′), because c≡gt(modxm′−m) and multiplying by xm moves the modulus to xm′. So g′≡g+gxmt≡g+ge(modxm′). Then
1−fg′≡1−fg−fge=e−(1−e)e=e2(modxm′). Since e≡xmt(modxm′), e2≡x2mt2≡0(modxm′) as 2m≥m′. For the degree, degg<m and deg(xmc)<m+(m′−m)=m′. □
Theorem (correctness). NEWTON-INVERSE(f,n) returns the unique g of degree less than n with fg≡1(modxn), as a list of n coefficients.
Proof. We show that at the start of each iteration of line L3, and after the loop, g is a list of m coefficients with fg≡1(modxm), where m is the precision reached so far. After lines L1 and L2, g=[f0−1] and m=1, and fg≡f0f0−1=1(modx). The loop visits m′=ks−1,ks−2,…,k0 in this order, starting from m=ks, so in each iteration m=ki+1 and m′=ki for some i, and m<m′≤2m by Lemma 2. Lines L4 to L7 compute d, t, c and g′ of Lemma 3, so after line L7 the claim holds for m′. The list g then has m+(m′−m)=m′ entries, because c is padded to m′−m entries. After the last iteration m=k0=n (if n=1, there is no iteration and m=1=n). By Lemma 1, g is the unique inverse modulo xn. □
Theorem (cost). Assume that multiplying a polynomial with a coefficients by one with b≤a coefficients costs at most M(a) ring operations, and that M(k)/k is nondecreasing. Then NEWTON-INVERSE(f,n) uses at most 3M(n)+2⌈log2n⌉M(n)/n+O(n) ring operations, plus one inversion in R. Since logn/n→0, this is 3M(n)+o(M(n)).
Proof. Consider the iteration with m=ki+1 and m′=ki, for 0≤i<s. Line L4 multiplies ki by ki+1 coefficients, at most M(ki). Line L6 multiplies ki+1 by ki−ki+1≤ki+1 coefficients, at most M(ki+1). Lines L5 and L7 and the padding cost O(ki). Since M(k)/k is nondecreasing and ki≤n, M(ki)≤(ki/n)M(n)≤(2−i+1/n)M(n) by Lemma 2. So
i=0∑s−1M(ki)≤(i≥0∑2−i+ns)M(n)≤2M(n)+snM(n),i=0∑s−1M(ki+1)=i=1∑sM(ki)≤M(n)+snM(n). The linear terms sum to O(∑iki)=O(n), because ∑iki≤∑i(n/2i+1)≤2n+s. Adding up, with s=⌈log2n⌉ from Lemma 2, gives the bound. ■