Algorithm Search⌘K

Proofs: Bostan-Mori algorithm

These are the human proofs of Bostan-Mori algorithm, at full length.

BOSTAN-MORI returns the coefficient of x^N in P/Q with two products per halving of N full

This proof shows: correctness.

Let RR be a commutative ring, P,Q∈R[x]P, Q \in R[x] with Q(0)Q(0) a unit, and N≥0N \ge 0. A polynomial or power series FF with F(0)F(0) a unit is invertible in RxRx, and [xn]F[x^n] F denotes the coefficient of xnx^n. For a polynomial UU, Ueven(y)=∑iu2iyiU_{\mathrm{even}}(y) = \sum_i u_{2i} y^i and Uodd(y)=∑iu2i+1yiU_{\mathrm{odd}}(y) = \sum_i u_{2i+1} y^i, so U(x)=Ueven(x2)+x Uodd(x2)U(x) = U_{\mathrm{even}}(x^2) + x\, U_{\mathrm{odd}}(x^2).

Lemma 1 (the product is even). V=Q(x)Q(−x)V = Q(x) Q(-x) satisfies V(x)=Veven(x2)V(x) = V_{\mathrm{even}}(x^2), and Veven(0)=Q(0)2V_{\mathrm{even}}(0) = Q(0)^2 is a unit.

Proof. Replacing xx by −x-x is a ring endomorphism of R[x]R[x] that maps VV to Q(−x)Q(x)=VQ(-x) Q(x) = V. Comparing coefficients, vi(−1)i=viv_i (-1)^i = v_i, so 2vi=02 v_i = 0 for odd ii. This does not yet give vi=0v_i = 0 when 22 is a zero divisor, so we compute directly: vi=∑j+l=i(−1)lqjqlv_i = \sum_{j + l = i} (-1)^l q_j q_l. For odd ii, the pairs (j,l)(j, l) and (l,j)(l, j) are distinct, since j=lj = l would make ii even, and they contribute (−1)lqjql+(−1)jqlqj=((−1)l+(−1)j)qjql=0(-1)^l q_j q_l + (-1)^j q_l q_j = ((-1)^l + (-1)^j) q_j q_l = 0, because j+lj + l odd means jj and ll have different parity. So vi=0v_i = 0 for odd ii, and V(x)=Veven(x2)V(x) = V_{\mathrm{even}}(x^2). The constant term is v0=q0⋅q0v_0 = q_0 \cdot q_0, a product of units. □\square

Lemma 2 (one step). Let U=P(x)Q(−x)U = P(x) Q(-x), W=VevenW = V_{\mathrm{even}}, and M≥0M \ge 0. Then [x2M] P/Q=[yM] Ueven/W[x^{2M}]\, P/Q = [y^M]\, U_{\mathrm{even}}/W and [x2M+1] P/Q=[yM] Uodd/W[x^{2M+1}]\, P/Q = [y^M]\, U_{\mathrm{odd}}/W.

Proof. Q(−x)Q(-x) has constant term Q(0)Q(0), a unit, so it is invertible in RxRx and P/Q=P(x)Q(−x)/(Q(x)Q(−x))=U/W(x2)P/Q = P(x) Q(-x) / (Q(x) Q(-x)) = U / W(x^2) by Lemma 1. The map y↦x2y \mapsto x^2 is a ring homomorphism Ry→RxRy \to Rx, so 1/W(x2)=(1/W)(x2)1/W(x^2) = (1/W)(x^2), a series with only even powers of xx. Hence

PQ=(UevenW)(x2)+x(UoddW)(x2).\frac{P}{Q} = \Big(\frac{U_{\mathrm{even}}}{W}\Big)(x^2) + x \Big(\frac{U_{\mathrm{odd}}}{W}\Big)(x^2).

The first series has only even powers of xx and the second only odd powers. The coefficient of x2Mx^{2M} comes from the first, and equals [yM] Ueven/W[y^M]\, U_{\mathrm{even}}/W. The coefficient of x2M+1x^{2M+1} comes from the second, and equals [yM] Uodd/W[y^M]\, U_{\mathrm{odd}}/W. □\square

Theorem (correctness). BOSTAN-MORI(P,Q,N)(P, Q, N) returns [xN] P/Q[x^N]\, P/Q.

Proof. Let c=[xN] P/Qc = [x^N]\, P/Q for the input. We claim that at each test of line L1, Q(0)Q(0) is a unit and [xN] P/Q=c[x^{N}]\, P/Q = c for the current values. This holds at the start. If N≥1N \ge 1, lines L2 to L7 replace (P,Q,N)(P, Q, N) by (Ueven,W,N/2)(U_{\mathrm{even}}, W, N/2) for even NN, or by (Uodd,W,(N−1)/2)(U_{\mathrm{odd}}, W, (N-1)/2) for odd NN. In both cases the coefficient is kept by Lemma 2, and W(0)W(0) is a unit by Lemma 1. Each step replaces N≥1N \ge 1 by ⌊N/2⌋<N\lfloor N/2 \rfloor < N, so the loop ends with N=0N = 0. Then [x0] P/Q=P(0) Q(0)−1[x^0]\, 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=0P = 0 returns 00, which is correct, since then P/Q=0P/Q = 0. □\square

Theorem (cost). Let d=deg⁡Qd = \deg Q and deg⁡P<d\deg P < d, and assume MM is nondecreasing. For N≥1N \ge 1, the algorithm runs ⌊log⁡2N⌋+1\lfloor \log_2 N \rfloor + 1 steps, each with two products of polynomials with at most d+1d + 1 coefficients and O(d)O(d) other operations, and one inversion at the end. So it uses at most 2M(d+1)(log⁡2N+1)+O(dlog⁡N)2M(d + 1)(\log_2 N + 1) + O(d \log N) ring operations.

Proof. Steps. N↦⌊N/2⌋N \mapsto \lfloor N/2 \rfloor reaches 00 from N≥1N \ge 1 after exactly ⌊log⁡2N⌋+1\lfloor \log_2 N \rfloor + 1 steps.

Degrees stay bounded. Suppose deg⁡Q≤d\deg Q \le d and deg⁡P≤d−1\deg P \le d - 1 at the start of a step. Then deg⁡Q(−x)≤d\deg Q(-x) \le d, deg⁡U≤2d−1\deg U \le 2d - 1 and deg⁡V≤2d\deg V \le 2d. The new PP is UevenU_{\mathrm{even}} or UoddU_{\mathrm{odd}}, whose degree is at most ⌊(2d−1)/2⌋=d−1\lfloor (2d - 1)/2 \rfloor = d - 1. The new QQ is VevenV_{\mathrm{even}}, of degree at most dd. By induction these bounds hold at every step.

One step. Line L2 negates at most dd coefficients. Lines L3 and L4 multiply polynomials with at most dd and d+1d + 1 coefficients, and d+1d + 1 and d+1d + 1 coefficients, so they cost at most 2M(d+1)2M(d + 1). Lines L5 to L7 only select coefficients. Adding the steps and line L8 gives the bound. ■\blacksquare

Back to Bostan-Mori algorithm