Algorithm Search⌘K

Proofs: Brent-Kung composition algorithm

These are the human proofs of Brent-Kung composition algorithm, at full length.

BRENT-KUNG returns f(g) mod h with at most 2 ceil(sqrt(N)) - 2 products modulo h and one matrix product full

This proof shows: correctness.

Let RR be a commutative ring, h∈R[x]h \in R[x] of degree n≥1n \ge 1 with a unit leading coefficient, g∈R[x]g \in R[x], and f=∑t=0N−1ftytf = \sum_{t=0}^{N-1} f_t y^t with N≥1N \ge 1. Let Q=R[x]/(h)Q = R[x]/(h) and let π:R[x]→Q\pi : R[x] \to Q be the quotient map. Division with remainder by hh is defined over RR because the leading coefficient is a unit, and it gives each class of QQ a unique representative of degree less than nn. We write rep⁡(aˉ)\operatorname{rep}(\bar a) for it, so a mod h=rep⁡(π(a))a \bmod h = \operatorname{rep}(\pi(a)). Let gˉ=π(g)\bar g = \pi(g), k=⌈N ⌉k = \lceil \sqrt{N}\, \rceil, m=⌈N/k⌉m = \lceil N/k \rceil, and ft=0f_t = 0 for t≥Nt \ge N.

Lemma 1 (reduction is a homomorphism). π\pi is a ring homomorphism, rep⁡\operatorname{rep} is RR-linear, and f(g) mod h=rep⁡(f(gˉ))f(g) \bmod h = \operatorname{rep}(f(\bar g)).

Proof. π\pi is the quotient map by an ideal, so it is a ring homomorphism, and π(f(g))=f(gˉ)\pi(f(g)) = f(\bar g). If aa and bb have degree less than nn and c∈Rc \in R, then a+cba + cb has degree less than nn and lies in the class π(a)+cπ(b)\pi(a) + c\pi(b), so by uniqueness rep⁡\operatorname{rep} is RR-linear. □\square

Lemma 2 (baby steps). For 1≤i≤min⁡(k,N−1)1 \le i \le \min(k, N - 1), line L3 gives Gi=rep⁡(gˉ i)G_i = \operatorname{rep}(\bar g^{\,i}), and G0=1=rep⁡(1)G_0 = 1 = \operatorname{rep}(1).

Proof. G1=g mod h=rep⁡(gˉ)G_1 = g \bmod h = \operatorname{rep}(\bar g) by line L2. If Gi−1=rep⁡(gˉ i−1)G_{i-1} = \operatorname{rep}(\bar g^{\,i-1}), then Gi−1G1 mod h=rep⁡(π(Gi−1G1))=rep⁡(gˉ i−1gˉ)G_{i-1} G_1 \bmod h = \operatorname{rep}(\pi(G_{i-1} G_1)) = \operatorname{rep}(\bar g^{\,i-1} \bar g). Also rep⁡(1)=1\operatorname{rep}(1) = 1 since n≥1n \ge 1. □\square

Lemma 3 (the matrix product). Row jj of C=A⋅BC = A \cdot B is the coefficient vector of rep⁡(Fj(gˉ))\operatorname{rep}(F_j(\bar g)), where Fj=∑i=0k−1fjk+iyiF_j = \sum_{i=0}^{k-1} f_{jk+i} y^i.

Proof. The entry of CC in row jj and column cc is ∑iA[j][i]B[i][c]=∑ifjk+i[xc]Gi\sum_i A[j][i] B[i][c] = \sum_i f_{jk+i} [x^c] G_i, so row jj is the coefficient vector of ∑ifjk+iGi\sum_i f_{jk+i} G_i. A row ii of BB with i>N−1i > N - 1 is zero, and it meets only fjk+if_{jk+i} with jk+i≥i≥Njk + i \ge i \ge N, which is 00, so those terms vanish. For the other ii, Gi=rep⁡(gˉ i)G_i = \operatorname{rep}(\bar g^{\,i}) by Lemma 2. By the linearity in Lemma 1, ∑ifjk+irep⁡(gˉ i)=rep⁡(Fj(gˉ))\sum_i f_{jk+i} \operatorname{rep}(\bar g^{\,i}) = \operatorname{rep}(F_j(\bar g)). □\square

Theorem (correctness). BRENT-KUNG returns f(g) mod hf(g) \bmod h.

Proof. Each t<mkt < mk has a unique form t=jk+it = jk + i with 0≤i<k0 \le i < k and 0≤j<m0 \le j < m, and N≤mkN \le mk. Since QQ is commutative, f(gˉ)=∑tftgˉ t=∑jFj(gˉ) (gˉ k)jf(\bar g) = \sum_t f_t \bar g^{\,t} = \sum_j F_j(\bar g)\, (\bar g^{\,k})^j. If m≥2m \ge 2, then N>kN > k, so k≤N−1k \le N - 1 and Gk=rep⁡(gˉ k)G_k = \operatorname{rep}(\bar g^{\,k}) by Lemma 2. Let Cj=rep⁡(Fj(gˉ))C_j = \operatorname{rep}(F_j(\bar g)) be row jj of CC (Lemma 3). We claim that after line L9 for index jj, and after line L7 for j=m−1j = m - 1, S=rep⁡(∑t=jm−1Ft(gˉ) (gˉ k)t−j)S = \operatorname{rep}\big(\sum_{t=j}^{m-1} F_t(\bar g)\, (\bar g^{\,k})^{t-j}\big). Line L7 gives it for j=m−1j = m - 1. If it holds for j+1j + 1, then S⋅Gk mod h=rep⁡(∑t=j+1m−1Ft(gˉ)(gˉ k)t−j)S \cdot G_k \bmod h = \operatorname{rep}\big(\sum_{t=j+1}^{m-1} F_t(\bar g) (\bar g^{\,k})^{t-j}\big) by Lemma 1, and adding CjC_j adds rep⁡(Fj(gˉ))\operatorname{rep}(F_j(\bar g)), by linearity of rep⁡\operatorname{rep}. At j=0j = 0 this is rep⁡(f(gˉ))=f(g) mod h\operatorname{rep}(f(\bar g)) = f(g) \bmod h by Lemma 1. If m=1m = 1, the loop does not run and S=C0=rep⁡(f(gˉ))S = C_0 = \operatorname{rep}(f(\bar g)). □\square

Theorem (cost). Assume M(a)/aM(a)/a is nondecreasing and N≤nN \le n, deg⁡g<n\deg g < n. The algorithm does at most 2k−22k - 2 products modulo hh, each costing at most 3M(n)+O(n)3M(n) + O(n) ring operations after a one-time cost of O(M(n))O(M(n)) for the inverse of the reversal of hh. Line L6 costs at most mkn≤k2nm k n \le k^2 n ring multiplications and as many additions by the schoolbook method, and O(n(ω+1)/2)O(n^{(\omega + 1)/2}) with an O(rω)O(r^\omega) matrix multiplication. So the total is O(n M(n)+n(ω+1)/2)O(\sqrt{n}\, M(n) + n^{(\omega+1)/2}).

Proof. Count. Line L3 runs min⁡(k,N−1)−1\min(k, N - 1) - 1 times and line L9 runs m−1m - 1 times. From (k−1)2<N≤k2(k - 1)^2 < N \le k^2 we get m=⌈N/k⌉≤km = \lceil N/k \rceil \le k, so the total is at most (k−1)+(k−1)=2k−2(k - 1) + (k - 1) = 2k - 2.

One product modulo hh. Both factors have degree less than nn, so their product costs at most M(n)M(n) and has degree at most 2n−22n - 2. Fast division of it by hh has a quotient with at most n−1n - 1 coefficients. With the inverse of the reversal of hh to precision nn stored, by the cost theorem for fast polynomial division it costs at most M(n−1)+M(n)+O(n)≤2M(n)+O(n)M(n - 1) + M(n) + O(n) \le 2M(n) + O(n). The stored inverse costs O(M(n))O(M(n)) once, by Newton iteration.

Matrix product. Pad AA to a k×kk \times k matrix with zero rows and BB to a k×k⌈n/k⌉k \times k\lceil n/k \rceil matrix with zero columns. Then A⋅BA \cdot B is ⌈n/k⌉\lceil n/k \rceil products of k×kk \times k matrices. With k≤n+1k \le \sqrt{n} + 1, this costs O((n/k+1)kω)=O(n(ω+1)/2)O((n/k + 1) k^\omega) = O(n^{(\omega+1)/2}). The schoolbook bound mknm k n counts one multiplication per triple (row, inner index, column).

Rest. Lines L4, L5 and L7 and the additions of line L9 cost O(mn)=O(n3/2)O(mn) = O(n^{3/2}), which is within O(n M(n))O(\sqrt{n}\, M(n)) since M(n)≥nM(n) \ge n. Adding up gives the bound. ■\blacksquare

Back to Brent-Kung composition algorithm