ratint.tex 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. \documentstyle[11pt,reduce,fancyheadings]{article}
  2. \title{
  3. \author{Neil Langmead \\
  4. Konrad-Zuse-Zentrum f\"ur Informationstechnik (ZIB) \\
  5. Takustrasse 7 \\
  6. D- 14195 Berlin Dahlem \\
  7. Berlin
  8. Germany}
  9. \date{January 1997}
  10. \def\foottitle{Rational Integration in \small{REDUCE}}
  11. \pagestyle{fancy}
  12. \lhead[]{{\footnotesize\leftmark}{}}
  13. \rhead[]{\thepage}
  14. \setlength{\headrulewidth}{0.6pt}
  15. \setlength{\footrulewidth}{0.6pt}
  16. \addtolength{\oddsidemargin}{-20 mm}
  17. \addtolength{\textwidth}{25 mm}
  18. \pagestyle{fancy}
  19. \setlength{\headrulewidth}{0.6pt}
  20. \setlength{\footrulewidth}{0.6pt}
  21. \setlength{\topmargin}{1 mm}
  22. \setlength{\footskip}{10 mm}
  23. \setlength{\textheight}{220 mm}
  24. \cfoot{}
  25. \rfoot{\small\foottitle}
  26. \def\exprlist {exp$_{1}$,exp$_{2}$, \ldots ,exp$_{{\tt n}}$}
  27. \def\lineqlist {lin\_eqn$_{1}$,lin\_eqn$_{2}$, \ldots ,lin\_eqn$_{n}$}
  28. \pagestyle{fancy}
  29. \begin{document}
  30. \maketitle{
  31. \begin{center} \Large Package to Integrate Rational Functions using the minimal algebraic extension to the constant field \end{center}}
  32. \pagebreak
  33. \tableofcontents
  34. \pagebreak
  35. \section{Rational Integration}
  36. \normalsize
  37. This package implements the Horowitz/ Rothstein/ Trager algorithms ~\cite{Ged92} for the integration of rational functions in \small{REDUCE}.\normalsize 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.$
  38. 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. \\
  39. \subsection{Syntax of $ratint$}
  40. This function has the following syntax:
  41. \begin{center} \bf{ratint(p,q,var)} \end{center}
  42. where $ 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.
  43. \subsection{Examples}
  44. consider the following examples in \small{REDUCE}:
  45. \begin{verbatim}
  46. ratint(1,x^2-2,x);
  47. sqrt(2)*x-2 sqrt(2)*x+2
  48. log(-------------) - log(-------------)
  49. sqrt(2) sqrt(2)
  50. { 0, --------------------------------------- }
  51. 2*sqrt(2)
  52. p:=441*x^7+780*x^6-2861*x^5+4085*x^4+7695*x^3+3713*x^2-43253*x
  53. +24500;
  54. q:=9*x^6+6*x^5-65*x^4+20*x^3+135*x^2-154*x+49;
  55. ratint(p,q,x);
  56. 49 6 226 5 268 4 1332 3 2809 2 752 256
  57. ---*(x + ---*x - ---*x + ----*x - ----*x - ---*x + ---)
  58. 2 147 49 49 147 21 9
  59. {----------------------------------------------------------- , 0 }
  60. 4 2 3 2 7
  61. x - ---*x - 4*x + 6*x - ---
  62. 3 3
  63. k:=36*x^6+126*x^5+183*x^4+(13807/6)*x^3-407*x^2-(3242/5)*x+(3044/15);
  64. l:=(x^2+(7/6)*x+(1/3))^2*(x-(2/5))^3;
  65. ratint(k,l,x);
  66. 5271 3 39547 2 31018 7142
  67. ------*(x + -------*x - -------*x + -------)
  68. 5 52710 26355 26355
  69. {------------------------------------------------,
  70. 4 11 3 11 2 2 4
  71. x + ----*x - ----*x - ----*x + ----
  72. 30 25 25 75
  73. 37451 2 91125 2 128000 1
  74. -------*(log(x - ---) + -------*log(x + ---) - --------*log(x + ---))}
  75. 16 5 37451 3 37451 2
  76. ratint(1,x^2+1,x);
  77. 2 1
  78. {0,log_sum(beta,beta + ---,0,log(2*beta*x - 1)*beta)}
  79. 4
  80. \end{verbatim}
  81. The meaning of the log\_sum function will be explained later.
  82. \pagebreak
  83. \section{The Algorithm}
  84. The following main algorithm is used:
  85. procedure $ratint(p,q,x);$
  86. % p and q are polynomials in $x$, with coefficients in the %constant field Q
  87. solution\_list $\leftarrow HorowitzReduction(p,q,x)$
  88. \\
  89. $c/d \leftarrow$ part(solution\_list,1)\\
  90. $poly\_part \leftarrow$ part(solution\_list,2)
  91. \\
  92. $rat\_part \leftarrow$ part(solution\_list,3)
  93. \\
  94. $rat\_part \leftarrow LogarithmicPartIntegral(rat\_part,x) $
  95. \\
  96. return($rat\_part+c/d +poly\_part$)
  97. \\
  98. end
  99. The algorithm contains two subroutines, $HorowitzReduction$ and $rt$. $HorowitzReduction$ 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 \small{REDUCE}. The integration of the logarithmic part is done by the routine $rt$, which is an impementation of the Rothstein and Trager method. These two answers are outputed in a list, the complete answer being the sum of these two parts.
  100. \\
  101. These two algorithms are as follows:
  102. procedure $how(p,q,x)$
  103. for a given rational function $p/q$ in $x$, this algorithm calculates the
  104. reduction of $ \int(p/q)$ into a polynomial part and logarithmic part. \\
  105. $ poly\_part \leftarrow quo(p,q); \hspace{3 mm} p \leftarrow rem(p,q)$;
  106. $d \leftarrow GCD(q,q') $; \hspace{3 mm} $b \leftarrow quo(q,d)$; \hspace{3 mm}
  107. $m \leftarrow deg(b)$; \\ $n \leftarrow deg(d)$;
  108. $a \leftarrow \sum_{i=1}^{m-1} a_{i}x^{i}$; \hspace{3 mm}
  109. $ c \leftarrow \sum_{i=1}^{n-1} c_{i}x^{i}$; \\
  110. $r \leftarrow b*c'-quo(b*d',d)+d*a; $\\
  111. \begin{tabbing}
  112. for $i$ from \= $0$ \= to $m+n-1$ do \\
  113. \> \{ \\
  114. \> \> $ eqns(i) \leftarrow coeff(p,i)=coeff(r,i)$; \\
  115. \> \};
  116. \end{tabbing}
  117. $solve(eqns,\{a(0),....,a(m-1),c(0),....,c(n-1)\});$
  118. return($c/d+\int poly\_part + \int a/b$);
  119. \\
  120. end;
  121. \newpage
  122. procedure RothsteinTrager($a,b,x$)
  123. \% Given a rational function $a/b$ in $x$ with $deg(a)<deg(b)$, with b monic and square free, we calculate $ \int(a/b)$ \\
  124. $R(z) \leftarrow residue(a-zb',b)$ \\
  125. $(r_{1}(z)...r_{k}(z)) \leftarrow factors(R(z))$ \\
  126. integral $\leftarrow 0 $\\
  127. \begin{tabbing}
  128. for $i$ from $1$ \= to \= $k$ do \\
  129. \> \{ \\
  130. \> \> $ d \leftarrow degree(r_{i}(z))$ \\
  131. \> \> if $d=1$ then \= \\
  132. \> \> \> \{ \\
  133. \> \> \> c $\leftarrow solve(r_{i}(z)=0,z)$ \\
  134. \> \> \> v $\leftarrow GCD(a-cb',b)$\\
  135. \> \> \> v $\leftarrow v/lcoeff(v) $\\
  136. \> \> \> $integral \leftarrow integral+c*log(v)$ \\
  137. \> \> \> \}\\
  138. \> \> else \= \{ \\
  139. \> \> \> \% we need to do a GCD over algebraic number field\\
  140. \> \> \> v $\leftarrow GCD(a-\alpha*b',b) $ \\
  141. \> \> \> v $\leftarrow v/lcoff(v) $, \hspace{3 mm}
  142. where $\alpha=roof\_of(r_{i}(z)) $\\
  143. \> \> if d=2 then \= \{ \\
  144. \> \> \> \% give answer in terms of radicals \\
  145. \> \> \> c $\leftarrow solve(r_{i}(z)=0,z) $ \\
  146. \> \> \> for j from 1 to 2 do \= \{ \\
  147. \> \> \> $v[j] \leftarrow substitute(\alpha=c[j],v) $ \\
  148. \> \> \> $integral \leftarrow integral+c[j]*log(v[j]) $ \\
  149. \> \> \> \> \> \} \\
  150. \> \> \> \} \\
  151. \> \> \> else \= \{ \\
  152. \> \> \> \% Need answer in terms of root\_of notation \\
  153. \> \> \> for j from 1 to d do \= \{ \\
  154. \> \> \> v[j] $\leftarrow substitute(\alpha=c[j],v) $ \\
  155. \> \> \> integral $ \leftarrow integral+c[j]*log(v[j]) $ \\
  156. \> \> \> \% where $c[j]=root\_of(r_{i}(z))$ \} \\
  157. \> \> \> \> \> \> \} \\
  158. \> \> \> \} \\
  159. \> \> \} \\
  160. \> \} \\
  161. return(integral) \\
  162. end
  163. \end{tabbing}
  164. \pagebreak
  165. \section{The log\_sum operator}
  166. The algorithms above returns a sum of terms of the form
  167. \[ \sum_{\alpha \mid R(\alpha)=0} \log(S(\alpha,x)), \]
  168. 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,
  169. consider the integral
  170. \[ \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 \]
  171. Calculating the resultant $R(z)=res_x(a-zb',b)$ and factorising gives
  172. \[ R(z)=-190107645728000(z^3-z^2+z+1)^{2} \]
  173. Making the result monic, we have
  174. \[ R_2(z)=z^3-z^2+z+1 \]
  175. which does not split over the constant field $Q$.
  176. Continuting with the Rothstein Trager algorithm, we now calculate
  177. \[ gcd(a-\alpha\,b',b)=z^2+(2*\alpha-5)*z+\alpha^2, \] where $\alpha$ is a root of $R_2(z)$. \\
  178. Thus we can write
  179. \[ \int \frac{a}{b}= \sum_{\alpha \mid \alpha^3-\alpha^2+\alpha+1=0} \alpha*\log(x^2+2\alpha x-5x+\alpha^2), \]
  180. and this is the answer now returned by \small{REDUCE}, via a function called $log\_sum$. This has the following syntax:
  181. \begin{center}$ log\_sum(\alpha,eqn(\alpha),0,sum\_term,var)$ \end{center}
  182. 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
  183. \[ \int \frac{a}{b}\,dx= log\_sum(\alpha,\alpha^3-\alpha^2+\alpha+1,0,\alpha*\log(x^2+2\alpha x-5x+\alpha^2),x) \]
  184. Many rational functions that could not be integrated by \small{REDUCE} previously can now be integrated with this package. The above is one example; some more are given on the next page.
  185. \pagebreak
  186. \subsection{More examples}
  187. \begin{eqnarray*}
  188. \int \frac{1}{x^5+1} \, dx & = &\frac{1}{5}\log(x + 1) \\
  189. & & \mbox{} + 5log\_sum(\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)
  190. \end{eqnarray*}
  191. which should be read as
  192. \[
  193. \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 \]
  194. \vspace{5 mm}
  195. \begin{eqnarray*}
  196. \lefteqn{\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 =} \\
  197. & & log\_sum(\alpha,\alpha^2 -\alpha -\frac{1}{4},0,log( - 2\alpha x^2 - 2\alpha x + x^7 + x^2 - 1)*\alpha,x) ,
  198. \end{eqnarray*}
  199. \[ \int \frac{1}{x^3+x+1} \, dx = log\_sum(\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})). \]
  200. \section{Options}
  201. 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:
  202. \begin{center} convert(exp) \end{center}
  203. If exp is free of $log\_sum$ terms, then $exp$ itself is returned. If $exp$ 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 \small{REDUCE}:
  204. \begin{verbatim}
  205. 2: ratint(a,b,x);
  206. {0,
  207. 2 1
  208. log_sum(alpha,alpha - alpha - ---,0,
  209. 4
  210. 2 7 2
  211. log( - 2*alpha*x - 2*alpha*x + x + x - 1)*alpha,x)}
  212. 3: convert(ws);
  213. 1 2 7
  214. ---*(sqrt(2)*log( - sqrt(2)*x - sqrt(2)*x + x - x - 1)
  215. 2
  216. 2 7
  217. - sqrt(2)*log(sqrt(2)*x + sqrt(2)*x + x - x - 1)
  218. 2 7
  219. + log( - sqrt(2)*x - sqrt(2)*x + x - x - 1)
  220. 2 7
  221. + log(sqrt(2)*x + sqrt(2)*x + x - x - 1))
  222. \end{verbatim}
  223. \subsection{LogtoAtan function}
  224. 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 ~\cite{Bron97}, which is recommended if definite integration is the goal. This is implemented in \small{REDUCE} via a function $convert\_log$, which has the following syntax:
  225. \begin{center} \bf{convert\_log(exp)}, \end{center}
  226. where $exp$ is any log\_sum expression.\\
  227. The procedure to convert complex logarithms to real arctangents is based on an algorithm by Rioboo. Here is what it does: \\
  228. Given a field $K$ of characteristic 0 such that $\sqrt(-1) \not\in K$ and
  229. $A, B \in K[x]$ with $B \not = 0$, return a sum $f$ of arctangents of polynomials in $K[x]$ such that
  230. \[ \frac{df}{dx}=\frac{d}{dx} i \log(\frac{A+ i B}{A- i B}) \]
  231. Example:
  232. \[ \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) \]
  233. Substituting $\alpha=i/2$ and $\alpha=-i/2$ gives the result
  234. \[ \frac{i}{2} \log(\frac{(x^3-3 x)+i (x^2-2)}{(x^3-3 x)-i (x^2-2)}) \]
  235. Applying logtoAtan now with $A=x^3-3 x$, and $B=x^2-2$ we obtain
  236. \[ \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) , \]
  237. and this is the formula which should be used for definite integration. \\
  238. Another example in \small{REDUCE} is given below:
  239. \begin{verbatim}
  240. 1: ratint(1,x^2+1,x);
  241. *** Domain mode rational changed to arnum
  242. 2 1
  243. {0,log_sum(beta,beta + ---,0,log(2*beta*x - 1)*beta)}
  244. 4
  245. 13: part(ws,2);
  246. 2 1
  247. log_sum(beta,beta + ---,0,log(2*beta*x - 1)*beta)
  248. 4
  249. 14: on combinelogs;
  250. 15: convertlog(ws);
  251. 1 - i*x + 1
  252. ---*log(------------)*i
  253. 2 i*x + 1
  254. logtoAtan(-x,1,x);
  255. 2*atan(x)
  256. \end{verbatim}
  257. \section{Hermite's method}
  258. The package also implements Hermite's method to reduce the integral into its polynomial and logarithmic parts, but occasionally, \small{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.
  259. \newline
  260. For a complete explanation of this and the other algorithms used in this package, including the theoretical justification and proofs, please consult ~\cite{Ged92}.
  261. \section{Tracing the $ratint$ program}
  262. 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 \small{REDUCE} \normalsize with the command
  263. \begin{verbatim}
  264. on traceratint;
  265. \end{verbatim}
  266. This switch is off by default. Here is an example of the output obtained with this switch on:
  267. \begin{verbatim}
  268. Loading image file: /silo/tony/red/lisp/psl/solaris/red/reduce.img
  269. REDUCE Development Version, 21-May-97 ...
  270. 1: load_package ratint;
  271. 2: on traceratint;
  272. 3: ratint(1+x,x^2-2*x+1,x);
  273. x + 1
  274. performing Howoritz reduction on --------------
  275. 2
  276. x - 2*x + 1
  277. - 2 1
  278. Howoritz gives: {-------,0,-------}
  279. x - 1 x - 1
  280. 1
  281. computing Rothstein Trager on -------
  282. x - 1
  283. integral in Rothstein T is log(x - 1)
  284. - 2
  285. {-------,log(x - 1)}
  286. x - 1
  287. \end{verbatim}
  288. \section{Bugs, suggestions and comments}
  289. This package was written when the author was working as a placement student at ZIB Berlin. All comments should therefore be reported to Winfried Neun, ZIB, Takustrasse 7, D 14195 Berlin Dahlem, Germany \\ (email: neun@zib.de).
  290. \pagebreak
  291. \begin{thebibliography}{999999}
  292. \normalsize
  293. \bibitem[Bron97]{Bron97} Bronstein, Manuel,
  294. {\it Symbolic Integration I: Transendental Functions},
  295. Springer-Verlag, Heidelberg, 1997.
  296. \bibitem[Dav88]{Dav88} Davenport, James H. et al,
  297. {\it Computer Algebra- Systems and Algorithms for Algebraic Computation},
  298. Academic Press, 1988.
  299. \bibitem[Ged92]{Ged92} Geddes, K.O. et al,
  300. {\it Algorithms for Computer Algebra}, Klewer Academic \mbox{Publishers}, 1992.
  301. \bibitem[Red36]{Red36} Hearn, Anthony C. and Fitch, John F.
  302. {\it REDUCE User's Manual 3.6}, RAND Corporation, 1995
  303. \end{thebibliography}
  304. \end{document}