trigint.tex 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. \documentstyle[11pt,reduce,fancyheadings]{article}
  2. \title{The Weierstrass substitution in REDUCE}
  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{The Weierstrass substitution}
  11. \pagestyle{fancy}
  12. \lhead[]{{\footnotesize\leftmark}{}}
  13. \rhead[]{\thepage}
  14. \lfoot[]{Neil Langmead}
  15. \rfoot[]{}
  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. \begin{document}
  29. \maketitle
  30. %\begin{center} \Large The Weirstrass Substitution in REDUCE
  31. %\end{center} }
  32. \pagebreak
  33. \tableofcontents
  34. \pagebreak
  35. \section{Introduction}
  36. This package is an implementation of a new algorithm proposed by D.J. Jeffrey and A.D. Rich ~\cite{Jeff} to remove "spurious" discontinuities from integrals. Their paper focuses on the Weirstrass substitution,$u=\tan(x/2)$, currently used in conjunction with the Risch algorithm in most computer algebra systems to evaluate trigonometric integrals. Expressions obtained using this substitution sometimes contain discontinuities, which limit the domain over which the expression is correct. The algorithm presented finds a better expression, in the sense that it is continous on wider intervals whilst still being an anti derivative of the integrand.
  37. \subsection{Example}
  38. Consider the following problem: \\
  39. \begin{equation} \int \frac{3}{5-4\cos(x)}\,dx \end{equation}
  40. \small{REDUCE} \normalsize computes an anti derivative to the given function using the Weirstrass substitution $u=tan(\frac{x}{2})$, and then the Risch algorithm is used, returning:
  41. \begin{equation} \frac{2\arctan(3\tan(\frac{x}{2}))}{3}, \end{equation}
  42. which is discontinuous at all odd multiples of $\pi$. Yet our original function is continuous everywhere on the real line, and so by the Fundamental Theorem of Calculus, any anti-derivative should also be everywhere continuous. The problem arises from the substitution used to transform the given trigonometric function to a rational function: often, the substituted function is discontinuous, and spurious discontinuities are introduced as a result. \\
  43. Jeffery and Richs' algorithm returns the following to the given problem: \\
  44. \[ \int \frac{3}{5-4\cos(x)}\,dx = 2\arctan(3\tan(\frac{x}{2}))+2\pi\lfloor \frac{x-\pi}{2\pi} \rfloor \]
  45. which differs from (2) by the constant 2$\pi$, and this is the correct way of removing the discontinuity.
  46. \pagebreak
  47. \section{Statement of the Algorithm}
  48. We define a Weierstrass substitution to be one that uses a function $u=\Phi(x)$ appearing in the following table: \\
  49. \begin{tabular}{|c|p{1in}|p{0.5in}|p{0.5in}|p{0.5in}|c|c||} \hline
  50. \multicolumn{7}{|l|}{Functions $u=\Phi$ used in the Weirstrass Alg. and their corresponding substitutions} \\ \hline
  51. \multicolumn{1}{|c|}{Choice}
  52. &\multicolumn{1}{|c|}{ $\Phi(x)$ }
  53. &\multicolumn{1}{|c|}{ $\sin(x)$ }
  54. &\multicolumn{1}{|c|}{ $\cos(x)$ }
  55. &\multicolumn{1}{|c|}{ $dx$ }
  56. &\multicolumn{1}{|c|}{ $b$ }
  57. &\multicolumn{1}{|c|}{ $p$ } \\ \hline
  58. $(a)$ & $\tan(x/2)$ & $\frac{2u}{1+u^{2}}$ & $ \frac{1-u^{2}}{1+u^{2}}$ & $\frac{2du}{1+u^{2}}$ & $\pi$ & $2\pi$ \\ \hline
  59. $(b)$ & $\tan(\frac{x}{2}+\frac{\pi}{4})$ & $\frac{u^{2}-1}{u^{2}+1}$ & $\frac{2u}{u^{2}+1} $ & $\frac{2du}{1+u^{2}}$ & $\frac{\pi}{2}$ & $2\pi$ \\ \hline
  60. $(c)$ & $\cot(x/2)$ & $\frac{2u}{1+u^{2}}$ & $\frac{u^{2}-1}{1+u^{2}}$ & $\frac{-2du}{1+u^{2}}$ & $0$ & $2\pi$ \\ \hline
  61. $(d)$ & $\tan(x)$ & $\frac{u}{\sqrt{1+u^{2}}}$ & $\frac{1}{\sqrt{1+u^{2}}}$ & $\frac{du}{1+u^{2}}$ & $\frac{\pi}{2}$ & $\pi$ \\ \hline
  62. \end{tabular} \vspace{4mm}
  63. There are of course, other trigonometric substitutions, used by \small{REDUCE}, \normalsize such as $\sin$ and $\cos$, but since these are never singular, they cannot lead to problems with discontinuities. \\
  64. Given an integrable function $f(\sin x,\cos x)$ whose indefinite integral is required, select one of the substitutions listed in the table. The choice is based on the following heuristics: choice (a) is used for integrands not containing $\sin x$, choice (b) for integrands not containing $\cos x$; (c) is useful in cases when (a) gives an integral that cannot be evaluated by \small{REDUCE},\normalsize and (d) is good for conditions described in Gradshteyn and Ryzhik (1979, sect 2.50). The integral is then transformed using the entries in the table,; for example, with choice (c), we have:
  65. \[ \int f(\sin x,\cos x)\, dx = \int f(\frac{2u}{1+u^{2}},\frac{u^{2}-1}{1+u^{2}})\,\frac{-2 du}{1+u^{2}} . \]
  66. The integral in $u$ is now evaluated using the standard routines of the system, then $u$ is substituted for. Call the result $\hat{g}(x)$. Next we calculate
  67. \[ K=\lim_{x \rightarrow b^{-}} \hat{g}(x) - \lim_{x \rightarrow b^{+}} \hat{g}(x), \]
  68. where the point $b$ is given in the table. the corrected integral is then
  69. \[ g(x)=\int f(\sin x,\cos x)\,dx = \hat{g}(x)+K\lfloor \frac{x-b}{p} \rfloor, \]
  70. where the period $p$ is taken from the table, and $\lfloor x \rfloor$ is the floor function.
  71. \pagebreak
  72. \section{REDUCE implementation}
  73. The name of the function used in \small{REDUCE} \normalsize to implement these ideas is trigint, which has the following syntax:
  74. \begin{center} \bf{trigint(exp,var)}, \end{center}
  75. where exp is the expression to be integrated, and var is the variable of integration. \\
  76. If trigint is used to calculate the integrals of trigonometric functions for which no substitution is necessary, then non standard results may occur. For example, if we calculate
  77. \begin{center} \bf{trigint(cos(x),x)}, \end{center}
  78. we obtain \\
  79. \[ \frac{2\tan\frac{x}{2}}{\tan\frac{x}{2}^{2}+1} \]
  80. which, by using simple trigonometric identities, simplifies to: \\
  81. \[ \frac{2\tan\frac{x}{2}}{\tan\frac{x}{2}^{2}+1} \rightarrow \frac{2\tan\frac{x}{2}}{\sec^{2}\frac{x}{2}} \rightarrow 2\sin\frac{x}{2}\cos\frac{x}{2} \rightarrow \sin 2\frac{x}{2} \rightarrow \sin x, \]
  82. which is the answer we would normally expect. In the absence of a normal form for trigonometric functions though, both answers are equally valid, although most would prefer the simpler answer $\sin x.$ Thus, some interesting trigonometric identities could be derived from the program if one so wished.
  83. \subsection{Examples}
  84. Using our example in (1), we compute the corrected result, and show a few other examples as well:
  85. \begin{verbatim}
  86. REDUCE Development Version, 4-Nov-96 ...
  87. 1: trigint(3/(5-4*cos(x)),x);
  88. x - pi + x
  89. 2*(atan(3*tan(---)) + floor(-----------)*pi)
  90. 2 2*pi
  91. \end{verbatim}
  92. \pagebreak
  93. \begin{verbatim}
  94. 2: trigint(3/(5+4*sin(x)),x);
  95. 2
  96. pi + 2*x - pi + 2*pi*x
  97. 2*(atan(3*tan(----------)) + floor(-----------------)*pi
  98. 4 4
  99. - pi + 2*x
  100. + floor(-------------)*pi)
  101. 4*pi
  102. 3: trigint(15/(cos(x)*(5-4*cos(x))),x);
  103. x - pi + x x
  104. 8*atan(3*tan(---)) + 8*floor(-----------)*pi - 3*log(tan(---) - 1)
  105. 2 2*pi 2
  106. x
  107. + 3*log(tan(---) + 1)
  108. 2
  109. \end{verbatim}
  110. \section{Definite Integration}
  111. The corrected expressions can now be used to calculate some definite integrals, provided the region of integration lies between adjacent singularities. For example, using our earlier function, we can use the corrected primitive to calculate
  112. \begin{equation} \int_{0}^{4\pi} \frac{1}{2+\cos x}\,dx \end{equation}
  113. trigint returns the answer below to give an indefinite integral, $F(x)$:
  114. \begin{verbatim}
  115. x
  116. tan(---)
  117. 2 - pi + x
  118. 2*sqrt(3)*(atan(----------) + floor(-----------)*pi)
  119. sqrt(3) 2*pi
  120. ------------------------------------------------------ (*)
  121. 3
  122. \end{verbatim}
  123. And now, we can apply the Fundamental Theorem of Calculus to give
  124. \begin{equation} \int_{0}^{4\pi} \frac{1}{2+\cos x}\,dx = F(4\pi)-F(0) \end{equation}
  125. \begin{verbatim}
  126. sub(x=4*pi,F)-sub(x=0,F);
  127. 4*sqrt(3)*pi
  128. -----------------
  129. 3
  130. \end{verbatim}
  131. and this is the correct value of the definite integral.
  132. Note that although the expression in (*) is continuous, the functions value at the points $x=\pi,3\pi$ etc. must be intepreted as a limit, and these values cannot substituted directly into the formula given in (*). Hence care should be taken to ensure that the definite integral is well defined, and that singularities are dealt with appropriately. For more details of this in \small{REDUCE},\normalsize please see the documentation for the $cwi$ addition to the $defint$ package.
  133. \section{Tracing the $trigint$ function}
  134. The package includes a facility to trace in some detail the inner workings of the $ratint$ program. Messages are given at key points of the algorithm, together with the results obtained. These messages are displayed whenever the switch $tracetrig$ is on, which is done in \small{REDUCE} \normalsize with the following command:
  135. \begin{verbatim}
  136. on tracetrig;
  137. \end{verbatim}
  138. This switch is off by default. In particular, the messages inform the user which substitution is being tried, and the result of that substitution. The error message
  139. \begin{verbatim}
  140. cannot integrate after subs
  141. \end{verbatim}
  142. means that \small{REDUCE} \normalsize has tried all four of the Weierstra\ss \hspace{1 mm} substitutions, and the system's standard integrator is unable to integrate after the substitution has been completed.
  143. \section{Bugs, comments, suggestions}
  144. This program was written whilst the author was a placement student at ZIB Berlin. Please refer all suggestions, comments or bugs therefore to Winfried Neun, Symbolik, ZIB, Takustrasse 7, D- 14195 Berlin Dahlem, Germany (e-mail neun@zib.de).
  145. \begin{thebibliography}{99999}
  146. \bibitem[Jeff]{Jeff} Jeffery, D.J. and Rich, A.D.
  147. {\it The Evaluation of Trigonometric Integrals avoiding Spurious Discontinuities
  148. }, article appearing in ACM Trans. Math Software
  149. \end{thebibliography}
  150. \end{document}