Newton Lifting: Inverting a Million-Term Formal Power Series
Formal power series do not need to converge. In competitive programming, working modulo means keeping precisely the first coefficients. Everything beyond that boundary is irrelevant. This finite viewpoint makes a seemingly infinite inverse computable.
The inverse exists exactly when the constant allows it
Over a field, has a multiplicative inverse if and only if . The constant equation is . Every later coefficient is then determined by earlier ones:
This gives an verifier. It is also the right fallback for tiny inputs. But evaluating the recurrence for a million terms is infeasible.
Take . Its inverse begins
Check the coefficient of : . We will recover the same sequence with logarithmically many lifting stages.
Correct the error rather than solve every coefficient
Assume . Define , so every nonzero term of has degree at least . Replace with
Multiplying by gives . The new error starts at degree . This algebraic identity is the whole precision-doubling proof. There is no analytic limit and no approximate convergence.
Starting at , repeatedly double the truncation boundary until it reaches .
For our polynomial, the first lift yields modulo . At the next lift, modulo . Thus gives after truncation.
A safe implementation boundary
The following is pseudocode. multiply returns an ordinary polynomial product; truncate both discards excess terms and pads missing coefficients with zero.
B = [inverse_mod(A[0])]while length(B) < n: target = min(2 * length(B), n) E = truncate(multiply(A[0:target], B), target) E = -E E[0] += 2 B = truncate(multiply(B, E), target)return BThe companion header implements this as wsh::inverse(A, n). It rejects a zero constant. All coefficient arithmetic is modulo .
Do not use a cyclic convolution of length target without a separate derivation. Although we discard high-degree coefficients, they must not wrap into low-degree positions during multiplication. The straightforward implementation uses sufficiently padded ordinary products.
Complexity and storage
If multiplication costs , the stages cost . This geometric sum matters: charging every stage as a full size- transform would produce an unnecessary extra logarithm.
The simple implementation allocates a few linear-size arrays. It is suitable as a clear baseline; specialized NTT libraries reduce transforms and allocations. Always check the largest temporary product length, not just the requested final precision, against the transform prime’s limit.
Inversion unlocks division
For polynomial division with , reverse the coefficient order. The leading coefficient of becomes the constant term of its reversal. If , then
Here each reversal uses the polynomial’s own degree. Recover , then subtract to obtain . This is why fast inversion also appears in multipoint evaluation trees.
Exercise. Derive the inverse of through degree four over the field modulo 17. Verify it by multiplication, then explain why attempting the same inversion over integers fails. The distinction between a field and an arbitrary coefficient ring is substantive.
Read logarithms and exponentials next.
Support & Share
If this article helped you, please share or support!





























































Conversation
Comments powered by Waline