REDUCE

20.46 RATINT: Integrate Rational Functions using the Minimal Algebraic Extension to the Constant Field

Author: Neil Langmead

This package was written when the author was a placement student at ZIB Berlin.

20.46.1 Rational Integration

This package implements the Horowitz/ Rothstein/ Trager algorithms  [GCL92] for the integration of rational functions in REDUCE. We work within a field \(K\) of characteristic \(0\) and functions \(p,q \in K[x]\). \(K\) is normally the field \(Q\) of rational numbers, but not always. These procedures return \(\int \frac {p}{q} dx.\) The aim is to be able to integrate any function of the form \(p/q\) in \(x\), where \(p\) and \(q\) are polynomials in the field \(Q\). The algorithms used avoid algebraic number extensions wherever possible, and in general, express the integral using the minimal algebraic extension field.

20.46.1.1 Syntax of ratint

This function has the following syntax:

ratint(\(\langle \)p\(\rangle \),\(\langle \)q\(\rangle \),\(\langle \)var\(\rangle \))

where \(\langle \)p\(\rangle \) and \(\langle \)q\(\rangle \) are polynomials in \(\langle \)var\(\rangle \), so that \(p/q\) is a rational function in \(var\). The output of ratint is a list of two elements: the first is the polynomial part of the integral, the second is the logarithmic part. The integral is the sum of these parts.

20.46.1.2 Examples

Consider the following examples in REDUCE (the meaning of the log_sum operator will be explained in the next section).

ratint(1,x^2-2,x);

{0,

                  2    1
 log_sum(beta,beta  - ---,0,log(2*beta*x - 1)*beta)}
                       8

p:=441*x^7+780*x^6-2861*x^5+4085*x^4+7695*x^3+3713*x^2
          -43253*x+24500;

q:=9*x^6+6*x^5-65*x^4+20*x^3+135*x^2-154*x+49;

ratint(p,q,x);


   49    6    226   5    268   4    1608   3
{(----*(x  + -----*x  - -----*x  - ------*x
   2          147        49          49

            6011   2    536       256      4
         + ------*x  + -----*x - -----))/(x
            147         21         9

        2   3      2          7
     - ---*x  - 4*x  + 6*x - ---),
        3                     3

 0}

k:=36*x^6+126*x^5+183*x^4+(13807/6)*x^3-407*x^2
      -(3242/5)*x+(3044/15);
l:=(x^2+(7/6)*x+(1/3))^2*(x-(2/5))^3;

ratint(k,l,x);

   5271    3    39547   2    31018       7142
  ------*(x  + -------*x  - -------*x + -------)
                                                                     

                                                                     
    5           52710        26355       26355
{------------------------------------------------,
       4    11   3    11   2    2        4
      x  + ----*x  - ----*x  - ----*x + ----
            30        25        25       75

  37451            2      91125           2
 -------*(log(x - ---) + -------*log(x + ---)
   16              5      37451           3

              128000           1
           - --------*log(x + ---))}
              37451            2


ratint(1,x^2+1,x);

                    2    1
{0,log_sum(beta,beta  + ---,0,log(2*beta*x - 1)*beta)}
                         4

20.46.2 The Algorithm

The following main algorithm is used:

procedure ratint\((p,q,x);\)
% p and q are polynomials in \(x\), with coefficients in the
% constant field Q
solution_list \(\leftarrow HorowitzReduction(p,q,x)\)
\(c/d \leftarrow \) part(solution_list,1)
\(poly\_part \leftarrow \) part(solution_list,2)
\(rat\_part \leftarrow \) part(solution_list,3)
\(rat\_part \leftarrow LogarithmicPartIntegral(rat\_part,x)\)
return(\(rat\_part+c/d+poly\_part\))
end

The algorithm contains two subroutines, HorowitzReduction and rtHorowitzReduction is an implementation of Horowitz’ method to reduce a given rational function into a polynomial part and a logarithmic part. The integration of the polynomial part is a trivial task, and is done by the int operator in REDUCE. The integration of the logarithmic part is done by the routine rt, which is an implementation of the Rothstein and Trager method. These two answers are outputed in a list, the complete answer being the sum of these two parts.
These two algorithms are as follows:

procedure \(how(p,q,x)\)

for a given rational function \(p/q\) in \(x\), this algorithm calculates the
reduction of \(\int (p/q)\) into a polynomial part and logarithmic part.

\(poly\_part \leftarrow quo(p,q);\) \(p \leftarrow rem(p,q)\);

\(d \leftarrow GCD(q,q')\); \(b \leftarrow quo(q,d)\); \(m \leftarrow deg(b)\);
\(n \leftarrow deg(d)\);

\(a \leftarrow \sum _{i=1}^{m-1} a_{i}x^{i}\); \(c \leftarrow \sum _{i=1}^{n-1} c_{i}x^{i}\);
\(r \leftarrow b*c'-quo(b*d',d)+d*a;\)

for \(i\) from \(0\) to \(m+n-1\) do
                 {
                    \(eqns(i) \leftarrow coeff(p,i)=coeff(r,i)\);
                 };

\(solve(eqns,\{a(0),....,a(m-1),c(0),....,c(n-1)\});\)

return(\(c/d+\int poly\_part + a/b\));
end;

procedure RothsteinTrager(\(a,b,x\))

% Given a rational function \(a/b\) in \(x\) with \(deg(a)<deg(b)\),
with \(b\) monic and square free, we calculate \(\int (a/b)\)
\(R(z) \leftarrow resultant(a-zb',b)\)
\((r_{1}(z)...r_{k}(z)) \leftarrow factors(R(z))\)
integral \(\leftarrow 0\)

for \(i\) from \(1\) to \(k\) do
                    {
                     \( d \leftarrow degree(r_{i}(z))\)
                     if \(d=1\) then {
                                            c \(\leftarrow solve(r_{i}(z)=0,z)\)
                                            v \(\leftarrow GCD(a-cb',b)\)
                                            v \(\leftarrow v/lcoeff(v)\)
                                            \(integral \leftarrow integral+c*log(v)\)
                                            }
                     else {
                            % we need to do a GCD over algebraic number field
                            v \(\leftarrow GCD(a-\alpha *b',b)\)
                            v \(\leftarrow v/lcoff(v) \), where \(\alpha =roof\_of(r_{i}(z))\)
                     if \(d=2\) then {
                                            % give answer in terms of radicals
                                            c \(\leftarrow solve(r_{i}(z)=0,z)\)
                                            for j from 1 to 2 do {
                                            \(v[j] \leftarrow substitute(\alpha =c[j],v)\)
                                            \(integral \leftarrow integral+c[j]*log(v[j])\)
                                            }
                                            else {
                                            % Need answer in terms of root_of notation
                                            for j from 1 to d do {
                                            v[j] \(\leftarrow substitute(\alpha =c[j],v)\)
                                            integral \(\leftarrow integral+c[j]*log(v[j])\)
                                            % where \(c[j]=root\_of(r_{i}(z))\) }
                                            }
                       }
                    }
return(integral)
end

20.46.3 The log_sum operator

The algorithms above returns a sum of terms of the form \[ \sum _{\alpha \mid R(\alpha )=0} \log (S(\alpha ,x)), \]

where \(R \in K[z]\) is square free, and \(S \in K[z,x]\). In the cases where the degree of \(R(\alpha )\) is less than two, this is merely a sum of logarithms. For cases where the degree is two or more, I have chosen to adopt this notation as the answer to the original problem of integrating the rational function. For example, consider the integral \[ \int \frac {a}{b}=\int \frac {2x^5-19x^4+60x^3-159+x^2+50x+11}{x^6-13x^5+58x^4-85x^3-66x^2-17x+1}\, dx \] Calculating the resultant \(R(z)=res_x(a-zb',b)\) and factorising gives \[ R(z)=-190107645728000(z^3-z^2+z+1)^{2} \] Making the result monic, we have \[ R_2(z)=z^3-z^2+z+1 \] which does not split over the constant field \(Q\). Continuting with the Rothstein Trager algorithm, we now calculate \[ gcd(a-\alpha \,b',b)=z^2+(2*\alpha -5)*z+\alpha ^2, \] where \(\alpha \) is a root of \(R_2(z)\).
Thus we can write \[ \int \frac {a}{b}= \sum _{\alpha \mid \alpha ^3-\alpha ^2+\alpha +1=0} \alpha *\log (x^2+2\alpha x-5x+\alpha ^2), \]

and this is the answer now returned by REDUCE, via a function called log_sum. This has the following syntax:

\( \logsum (\alpha ,eqn(\alpha ),0,sum\_term,var)\)

where \(\alpha \) satisfies \(eqn=0\), and \(sum\_term\) is the term of the summation in the variable \(var\). Thus in the above example, we have \[ \int \frac {a}{b}\,dx= \logsum (\alpha ,\alpha ^3-\alpha ^2+\alpha +1,0,\alpha *\log (x^2+2\alpha x-5x+\alpha ^2),x) \]

Many rational functions that could not be integrated by REDUCE previously can now be integrated with this package. The above is one example; some more are given on the next page.

20.46.3.1 More examples

\( \displaystyle \int \frac {1}{x^5+1} \, dx = \frac {1}{5}\log (x + 1) \) \[ \mbox {} + 5 \logsum (\beta ,\beta ^4+\frac {1}{5}\beta ^3+\frac {1}{25}\beta ^2+\frac {1}{125}\beta +\frac {1}{625},0,\log (5*\beta +x)*\beta ) \]

which should be read as \[ \int \frac {1}{x^5+1}\,dx = \frac {1}{5}\log (x+1)+\sum _{\beta \mid \beta ^4+\frac {1}{5}\beta ^3+\frac {1}{25}\beta ^2+\frac {1}{125}\beta +\frac {1}{625}=0}\log (5*\beta +x)\beta \]

\( \displaystyle \int \frac {7x^{13}+10x^8+4x^7-7x^6-4x^3-4x^2+3x+3}{x^{14}-2x^8-2x^7-2x^4-4x^3-x^2+2x+1} \, dx = \) \[ \logsum (\alpha ,\alpha ^2 -\alpha -\frac {1}{4},0,\log ( - 2\alpha x^2 - 2\alpha x + x^7 + x^2 - 1)*\alpha ,x) , \] \[ \int \frac {1}{x^3+x+1} \, dx = \logsum (\beta ,\beta ^3-\frac {3}{31}\beta ^2-\frac {1}{31},0,\beta \log (-\frac {62}{9}\beta ^2+\frac {31}{9} \beta +x+\frac {4}{9})). \]

20.46.4 Options

There are several alternative forms that the answer to the integration problem can take. One output is the log_sum form shown in the examples above. There is an option with this package to convert this to a “normal” sum of logarithms in the case when the degree of \(eqn\) in \(\alpha \) is two, and \(\alpha \) can be expressed in surds. To do this, use the function convert, which has the following syntax:

convert(\(\langle \)exp\(\rangle \))

If \(\langle \)exp\(\rangle \) is free of log_sum terms, then \(\langle \)exp\(\rangle \) itself is returned. If \(\langle \)exp\(\rangle \) contains log_sum terms, then \(\alpha \) is represented as surds, and substituted into the log_sum expression. For example, using the last example, we have in REDUCE:

2: ratint(a,b,x);

{0,

                    2            1
 log_sum(alpha,alpha  - alpha - ---,0,log(
                                 4

                        2                7    2
             - 2*alpha*x  - 2*alpha*x + x  + x

             - 1)*alpha,x)}

3: convert(ws);


 1
---*(sqrt(2)
 2

                      2                7
     *log( - sqrt(2)*x  - sqrt(2)*x + x  - x - 1)

     - sqrt(2)

                   2                7
     *log(sqrt(2)*x  + sqrt(2)*x + x  - x - 1) +

                     2                7
     log( - sqrt(2)*x  - sqrt(2)*x + x  - x - 1)

                     2                7
      + log(sqrt(2)*x  + sqrt(2)*x + x  - x - 1))

20.46.4.1 LogtoAtan function

The user could then combine these to form a more elegant answer, using the switch combinelogs if one so wished. Another option is to convert complex logarithms to real arctangents  [Bro97], which is recommended if definite integration is the goal. This is implemented in REDUCE via a function convert_log, which has the following syntax:

convert_log(\(\langle \)exp\(\rangle \))

where \(\langle \)exp\(\rangle \) is any expression containing log_sum terms.

The procedure to convert complex logarithms to real arctangents is based on an algorithm by Rioboo. Here is what it does:

Given a field \(K\) of characteristic 0 such that \(\sqrt {-1} \not \in K\) and \(A, B \in K[x]\) with \(B \not = 0\), return a sum \(f\) of arctangents of polynomials in \(K[x]\) such that \[ \frac {df}{dx}=\frac {d}{dx} i \log (\frac {A+ i B}{A- i B}) \]

Example: \[ \int \frac {x^4-3*x^2+6}{x^6-5*x^4+5*x^2+4} \, dx = \sum _{ \alpha \mid 4\alpha +1=0} \alpha \log (x^3+2\alpha x^2-3 x-4 \alpha ) \]

Substituting \(\alpha =i/2\) and \(\alpha =-i/2\) gives the result

\[ \frac {i}{2} \log (\frac {(x^3-3 x)+i (x^2-2)}{(x^3-3 x)-i (x^2-2)}) \]

Applying logtoAtan now with \(A=x^3-3 x\), and \(B=x^2-2\) we obtain \begin {multline*} \int \frac {x^4-3*x^2+6}{x^6-5*x^4+5*x^2+4} \, dx \\ = \arctan (\frac {x^5-3 x^3+x}{2})+\arctan (x^3)+\arctan (x) , \end {multline*} and this is the formula which should be used for definite integration.

Another example in REDUCE is given below:

1: ratint(1,x^2+1,x);

                    2    1
{0,log_sum(beta,beta  + ---,0,log(2*beta*x - 1)*beta)}
                         4

13: part(ws,2);

                 2    1
log_sum(beta,beta  + ---,0,log(2*beta*x - 1)*beta)
                      4

14: on combinelogs;

15: convertlog(ws);

 1        - i*x + 1
---*log(------------)*i
 2         i*x + 1


logtoAtan(-x,1,x);

 - 2*atan(x)

20.46.5 Hermite’s method

The package also implements Hermite’s method to reduce the integral into its polynomial and logarithmic parts, but occasionally, REDUCE returns the incorrect answer when this algorithm is used. This is due to the REDUCE operator pf, which performs a complete partial fraction expansion when given a rational function as input. Work is presently being done to give the pf operator a facility which tells it that the input is already factored. This would then enable REDUCE to perform a partial fraction decomposition with respect to a square free denominator, which may not necessarily be fully factored over Q.

For a complete explanation of this and the other algorithms used in this package, including the theoretical justification and proofs, please consult  [GCL92].

20.46.6 Tracing the ratint program

The package includes a facility to trace in some detail the inner workings of the ratint program. Messages are given at the key stages of the algorithm, together with the results obtained. These messages are displayed when the switch traceratint is on, which is done in REDUCE with the command

on traceratint;

This switch is off by default. Here is an example of the output obtained with this switch on:

1: on traceratint;


2: ratint(1+x,x^2-2*x+1,x);

                                     x + 1
performing Howoritz reduction on --------------
                                   2
                                  x  - 2*x + 1

                   - 2        1
Howoritz gives: {-------,0,-------}
                  x - 1     x - 1

                                 1
computing Rothstein Trager on -------
                               x - 1

integral in Rothstein T is log(x - 1)

   - 2
{-------,log(x - 1)}
  x - 1

20.46.7 Bugs, suggestions and comments

This package was written when the author was working as a placement student at ZIB Berlin.


Hosted by Download REDUCE Powered by MathJax