The Rothstein-Trager algorithm returns the logarithmic part of the integral full
This proof shows: correctness.
Setting. K is a field of characteristic 0 with algebraic closure K. A,D∈K[x], D squarefree, n=degD≥1, degA<n. α1,…,αn∈K are the roots of D, which are distinct, so D′(αj)=0. The residue at αj is rj=A(αj)/D′(αj). R(z)=resx(D,A−zD′), with the Sylvester matrix of formal degrees n and n−1. All gcds are monic. log is a formal symbol with (logv)′=v′/v, and equalities of integrals are equalities of derivatives.
Lemma 1 (the resultant). R(z)=LC(D)n−1∏j=1n(A(αj)−zD′(αj)). So R has degree exactly n, and its roots are r1,…,rn, with multiplicity.
Proof. For f of degree n with leading coefficient a and roots αj, and any g of formal degree k, the Sylvester determinant of formal degrees n and k is ak∏jg(αj); this is the product formula on the resultant page, and it holds for every g of degree at most k, because both sides are polynomials in the coefficients of g. Apply it in K[z] with f=D and g=A−zD′, of formal degree n−1. The factor j is D′(αj)(rj−z), with D′(αj)=0. So R(z)=LC(D)n−1∏jD′(αj)⋅∏j(rj−z), with a nonzero constant in front. □
Lemma 2 (the gcds). For c∈K, gcd(D,A−cD′)=∏j:rj=c(x−αj) in K[x]. If c∈K, this gcd lies in K[x].
Proof. D is squarefree, so its monic divisors in K[x] are the products of distinct x−αj, and gcd(D,G) is the product over the roots αj of D with G(αj)=0. For G=A−cD′, G(αj)=0 exactly when A(αj)=cD′(αj), that is rj=c, because D′(αj)=0. If c∈K, the Euclidean algorithm for D and A−cD′ runs in K[x], and the monic gcd does not depend on the field. □
Theorem. ∫DAdx=c∑cloggcd(D,A−cD′), where c runs over the distinct nonzero roots of R.
Proof. Since degA<n and the αj are distinct, partial fractions over K give A/D=∑jλj/(x−αj). Multiply by x−αj and let x→αj: since D/(x−αj) at αj is D′(αj), λj=A(αj)/D′(αj)=rj. So A/D=∑jrj/(x−αj). For each distinct value c of the residues, with Gc=∏rj=c(x−αj), (logGc)′=∑rj=c1/(x−αj). Hence
(c∑clogGc)′=c∑rj=c∑x−αjc=j∑x−αjrj=DA. Terms with c=0 contribute 0 and can be dropped. By Lemma 1 the distinct values c are the distinct roots of R, and by Lemma 2 Gc=gcd(D,A−cD′). □
Lemma 3 (gcd in a product of fields). Let q∈K[z] be monic and squarefree of positive degree, L=K[z]/(q), and F,G∈L[x]. Suppose the Euclidean algorithm on F,G in L[x], as on line L6, finds an inverse for every leading coefficient it needs, and returns the monic S. Then for every root c∈K of q, S(c,x)=gcd(F(c,x),G(c,x)).
Proof. The map ϕc:L→K, z↦c, is a well defined ring homomorphism because q(c)=0; extend it to L[x]→K[x] coefficientwise. If u∈L has an inverse, then ϕc(u)ϕc(u−1)=1, so ϕc(u)=0. The algorithm removes leading coefficients that are 0 in L, so every polynomial it keeps has an exact degree in L[x], and every one that is used as a divisor, or returned, has an invertible leading coefficient. Consider one division step a=Qb+r in L[x], with LC(b) invertible and degr<degb. Then ϕc(a)=ϕc(Q)ϕc(b)+ϕc(r), degϕc(b)=degb, and degϕc(r)≤degr<degϕc(b), so ϕc(r) is the remainder of ϕc(a) by ϕc(b) in K[x], and gcd(ϕc(a),ϕc(b))=gcd(ϕc(b),ϕc(r)). By induction over the steps, gcd(ϕc(F),ϕc(G))=gcd(ϕc(alast),0), where alast is the last nonzero remainder. Its leading coefficient is invertible, so ϕc(alast) has the same degree and ϕc(S)=ϕc(alast)/ϕc(LC(alast)) is its monic form. So S(c,x)=gcd(F(c,x),G(c,x)). □
Lemma 4 (splitting). If u∈L is nonzero (as a polynomial of degree less than degq) and has no inverse, then g=gcd(u,q) in K[z] has 0<degg<degq, and g and q/g are monic, squarefree and coprime, and the roots of q are the disjoint union of the roots of g and of q/g.
Proof. u has an inverse modulo q exactly when gcd(u,q)=1, by the extended Euclidean algorithm. So degg>0. Since u=0 and degu<degq, q∤u, so g=q. A factorization of a squarefree polynomial has squarefree, coprime factors, and their roots partition the roots of q. □
The algorithm. We show that the output pairs (qi,Si) satisfy ∑i∑qi(c)=0clogSi(c,x)=∫A/Ddx.
Lines L1 to L3. Line L1 computes R. The implementation evaluates the Sylvester determinant at z=0,…,n and interpolates; this is exact because degR≤n by Lemma 1. For each rational root c=0, line L3 outputs cloggcd(D,A−cD′), the term of the theorem for c.
Line L4. Let CQ be the set of rational roots of R. q is the squarefree part of R/∏c∈CQ(z−c)μc, where μc is the multiplicity, made monic. So the roots of q are the distinct roots of R not in CQ, each simple, and 0 is not among them. If degq=0, all terms of the theorem are already output.
Lines L5 to L8. Invariant: the roots of the polynomials on the stack and of the qi already output are, together, the roots of the q of line L4, each exactly once; each polynomial on the stack is monic and squarefree of positive degree. It holds at the start. A pass pops q and runs the Euclidean algorithm for F=D and G=A−zD′ in (K[z]/(q))[x]. If an inverse fails at line L7, Lemma 4 shows that the two pushed factors keep the invariant. Otherwise, by Lemma 3, S(c,x)=gcd(D,A−cD′) for every root c of q, so the pair (q,S) of line L8 stands for exactly the terms of the theorem for the roots of q, and the invariant holds.
Termination. Each split replaces q by two factors of smaller positive degree, so the total number of splits is less than the degree of the q of line L4, and each pass either splits or outputs. So the loop ends, with an empty stack.
Result. When the loop ends, by the invariant every distinct nonzero root of R is a root of exactly one output qi (degree 1 for the rational ones from line L3). By Lemma 2 and Lemma 3 the term for each root c is cloggcd(D,A−cD′). So the output sum is the sum of the theorem, which is ∫A/Ddx. ■