BOSTAN-MORI returns the coefficient of x^N in P/Q with two products per halving of N full
This proof shows: correctness.
Let R be a commutative ring, P,Q∈R[x] with Q(0) a unit, and N≥0. A polynomial or power series F with F(0) a unit is invertible in Rx, and [xn]F denotes the coefficient of xn. For a polynomial U, Ueven(y)=∑iu2iyi and Uodd(y)=∑iu2i+1yi, so U(x)=Ueven(x2)+xUodd(x2).
Lemma 1 (the product is even). V=Q(x)Q(−x) satisfies V(x)=Veven(x2), and Veven(0)=Q(0)2 is a unit.
Proof. Replacing x by −x is a ring endomorphism of R[x] that maps V to Q(−x)Q(x)=V. Comparing coefficients, vi(−1)i=vi, so 2vi=0 for odd i. This does not yet give vi=0 when 2 is a zero divisor, so we compute directly: vi=∑j+l=i(−1)lqjql. For odd i, the pairs (j,l) and (l,j) are distinct, since j=l would make i even, and they contribute (−1)lqjql+(−1)jqlqj=((−1)l+(−1)j)qjql=0, because j+l odd means j and l have different parity. So vi=0 for odd i, and V(x)=Veven(x2). The constant term is v0=q0⋅q0, a product of units. □
Lemma 2 (one step). Let U=P(x)Q(−x), W=Veven, and M≥0. Then [x2M]P/Q=[yM]Ueven/W and [x2M+1]P/Q=[yM]Uodd/W.
Proof. Q(−x) has constant term Q(0), a unit, so it is invertible in Rx and P/Q=P(x)Q(−x)/(Q(x)Q(−x))=U/W(x2) by Lemma 1. The map y↦x2 is a ring homomorphism Ry→Rx, so 1/W(x2)=(1/W)(x2), a series with only even powers of x. Hence
QP=(WUeven)(x2)+x(WUodd)(x2). The first series has only even powers of x and the second only odd powers. The coefficient of x2M comes from the first, and equals [yM]Ueven/W. The coefficient of x2M+1 comes from the second, and equals [yM]Uodd/W. □
Theorem (correctness). BOSTAN-MORI(P,Q,N) returns [xN]P/Q.
Proof. Let c=[xN]P/Q for the input. We claim that at each test of line L1, Q(0) is a unit and [xN]P/Q=c for the current values. This holds at the start. If N≥1, lines L2 to L7 replace (P,Q,N) by (Ueven,W,N/2) for even N, or by (Uodd,W,(N−1)/2) for odd N. In both cases the coefficient is kept by Lemma 2, and W(0) is a unit by Lemma 1. Each step replaces N≥1 by ⌊N/2⌋<N, so the loop ends with N=0. Then [x0]P/Q=P(0)Q(0)−1, because the constant term of a product of series is the product of the constant terms. Line L8 returns it. The early exit of the implementation when P=0 returns 0, which is correct, since then P/Q=0. □
Theorem (cost). Let d=degQ and degP<d, and assume M is nondecreasing. For N≥1, the algorithm runs ⌊log2N⌋+1 steps, each with two products of polynomials with at most d+1 coefficients and O(d) other operations, and one inversion at the end. So it uses at most 2M(d+1)(log2N+1)+O(dlogN) ring operations.
Proof. Steps. N↦⌊N/2⌋ reaches 0 from N≥1 after exactly ⌊log2N⌋+1 steps.
Degrees stay bounded. Suppose degQ≤d and degP≤d−1 at the start of a step. Then degQ(−x)≤d, degU≤2d−1 and degV≤2d. The new P is Ueven or Uodd, whose degree is at most ⌊(2d−1)/2⌋=d−1. The new Q is Veven, of degree at most d. By induction these bounds hold at every step.
One step. Line L2 negates at most d coefficients. Lines L3 and L4 multiply polynomials with at most d and d+1 coefficients, and d+1 and d+1 coefficients, so they cost at most 2M(d+1). Lines L5 to L7 only select coefficients. Adding the steps and line L8 gives the bound. ■