/* Original version of this file copyright 1999 by Michael Wester,
 * and retrieved from http://www.math.unm.edu/~wester/demos/IndefiniteIntegrals/problems.macsyma
 * circa 2006-10-23.
 *
 * Released under the terms of the GNU General Public License, version 2,
 * per message dated 2007-06-03 from Michael Wester to Robert Dodier
 * (contained in the file wester-gpl-permission-message.txt).
 *
 * See: "A Critique of the Mathematical Abilities of CA Systems"
 * by Michael Wester, pp 25--60 in
 * "Computer Algebra Systems: A Practical Guide", edited by Michael J. Wester
 * and published by John Wiley and Sons, Chichester, United Kingdom, 1999.
 */
/* ----------[ M a c s y m a ]---------- */
/* ---------- Initialization ---------- */
showtime: all$
prederror: false$
/* ---------- Indefinite Integrals ---------- */
/* This integral only makes sense for x real => x |x|/2 */
integrate(abs(x), x);
declare(z, complex)$
integrate(abs(z), z);
remove(z, complex)$
/* Calculus on a piecewise defined function */
a(x):= if x < 0 then -x else x$
/* => if x < 0 then -x^2/2 else x^2/2 */
integrate(a(x), x);
a(x):= -x*unit_step(-x) + x*unit_step(x)$
integrate(a(x), x);
ratsimp(%);
remfunction(a)$
/* This would be very difficult to do by hand
   => 2^(1/3)/6 [1/2 log([x + 2^(1/3)]^2/[x^2 - 2^(1/3) x + 2^(2/3)])
                 + sqrt(3) arctan({[sqrt(3) x]/[2^(4/3) - x]   or
                                   [2 x - 2^(1/3)]/[2^(1/3) sqrt(3)]})
      [Gradshteyn and Ryzhik 2.126(1)] */
1/(x^3 + 2);
integrate(%, x);
diff(%, x);
/* What a mess!  Simplify it. */
ratsimp(%);
/* This integral is easy if one realizes that 4^x = (2^x)^2
   => arcsinh(2^x)/log(2)   [Robert Israel in sci.math.symbolic] */
integrate(2^x/sqrt(1 + 4^x), x);
integrate(radcan(2^x/sqrt(1 + 4^x)), x);
/* => (-9 x^2 + 16 x - 41/5)/(2 x - 1)^(5/2)
      [Gradshteyn and Ryzhik 2.244(8)] */
integrate((3*x - 5)^2/(2*x - 1)^(7/2), x);
factor(%);
/* => 1/[2 m sqrt(10)] log([-5 + e^(m x) sqrt(10)]/[-5 - e^(m x) sqrt(10)])
      [Gradshteyn and Ryzhik 2.314] */
integrate(1/(2*exp(m*x) - 5*exp(-m*x)), x);
logcontract(%);
/* => -3/2 x + 1/4 sinh(2 x) + tanh x   [Gradshteyn and Ryzhik 2.423(24)] */
integrate(sinh(x)^4/cosh(x)^2, x);
partfrac(%, %e^x);
/* This example involves several symbolic parameters
   => 1/sqrt(b^2 - a^2) log([sqrt(b^2 - a^2) tan(x/2) + a + b]/
                            [sqrt(b^2 - a^2) tan(x/2) - a - b])   (a^2 < b^2)
      [Gradshteyn and Ryzhik 2.553(3)] */
assume(b^2 > a^2)$
integrate(1/(a + b*cos(x)), x);
trigsimp(ratsimp(diff(%, x)));
forget(b^2 > a^2)$
/* The integral of 1/(a + 3 cos x + 4 sin x) can have 4 different forms
   depending on the value of a !   [Gradshteyn and Ryzhik 2.558(4)]
   => (a = 3) 1/4 log[3 + 4 tan(x/2)] */
integrate(1/(3 + 3*cos(x) + 4*sin(x)), x);
/* => (a = 4) 1/3 log([tan(x/2) + 1]/[tan(x/2) + 7]) */
integrate(1/(4 + 3*cos(x) + 4*sin(x)), x);
logcontract(factor(%));
/* => (a = 5) -1/[2 + tan(x/2)] */
integrate(1/(5 + 3*cos(x) + 4*sin(x)), x);
/* => (a = 6) 2/sqrt(11) arctan([3 tan(x/2) + 4]/sqrt(11)) */
integrate(1/(6 + 3*cos(x) + 4*sin(x)), x);
/* => x log|x^2 - a^2| - 2 x + a log|(x + a)/(x - a)|
      [Gradshteyn and Ryzhik 2.736(1)] */
integrate(log(abs(x^2 - a^2)), x);
/* => (a x)/2 + (pi x^2)/4 - 1/2 (x^2 + a^2) arctan(x/a)
         [Gradshteyn and Ryzhik 2.822(4)]   or
      (a x)/2 + 1/2 (x^2 + a^2) arccot(x/a)   [Gradshteyn and Ryzhik 2.853(2)]
*/
integrate(x*acot(x/a), x);
factor(%);
/* => [sin(5 x) Ci(2 x)]/5 - [Si(7 x) + Si(3 x)]/10
      [Gradshteyn and Ryzhik 5.31(1)] */
integrate(cos(5*x)*cos_int(2*x), x);
/* => 1/2 [f(x) - g(x)]/[f(x) + g(x)]   [Gradshteyn and Ryzhik 2.02(25)] */
integrate(('diff(f(x), x)*g(x) - f(x)*'diff(g(x), x))/(f(x)^2 - g(x)^2), x);
logcontract(antidiff(part(%, 1), x, f(x)));
/* ---------- Quit ---------- */
quit();
