Subject: need help w/ MONSTERTRIG endless recursion
From: Robert Dodier
Date: Wed, 26 Dec 2007 11:23:31 -0700
The aptly-named MONSTERTRIG (I'm tempted to compose this message
in html so that I can make it bold and blinking text ...) tries to reduce some
trig expressions and start over. However I've encountered an expression
for which the attempted reduction has no effect, so it loops endlessly.
e.g.
trace (integrate, ?monstertrig);
integrate (x*(cos(2*x) + sin(x)), x);
=>
1 Enter integrate [x*(cos(2*x)+sin(x)),x]
1 Enter ?monstertrig [x*(cos(2*x)+sin(x)),x,x]
1 Exit ?monstertrig false
1 Enter ?monstertrig [x*(cos(2*x)+sin(x)),x,2*x]
2 Enter integrate [?new\-var\-15974*(cos(?new\-var\-15974)
+sin(?new\-var\-15974/2))
/2,?new\-var\-15974]
2 Enter ?monstertrig [?new\-var\-15974*(cos(?new\-var\-15974)
+sin(?new\-var\-15974/2)),?new\-var\-15974,
?new\-var\-15974/2]
3 Enter integrate [2*?new\-var\-15975
*(cos(2*?new\-var\-15975)+sin(?new\-var\-15975)),
?new\-var\-15975]
3 Enter ?monstertrig [?new\-var\-15975*(cos(2*?new\-var\-15975)
+sin(?new\-var\-15975)),?new\-var\-15975,
?new\-var\-15975]
3 Exit ?monstertrig false
... etc etc.
Here's the relevant code from MONSTERTRIG (src/sin.lisp).
;; We have trig(c*x+b). Use the substitution y=c*x+b to
;; try to compute the integral. Why? Because x*sin(n*x)
;; takes longer and longer as n gets larger and larger.
;; This is caused by the Risch integrator. This is a
;; work-around for this issue.
(let ((c (cdras 'c arg))
(b (cdras 'b arg))
(new-var (gensym "NEW-VAR-")))
(let ((new-int (div ($integrate (maxima-substitute (div
(sub new-var b) c)
var exp)
new-var)
c)))
(return-from monstertrig (maxima-substitute *trigarg* new-var
new-int)))))
risch has no trouble with the example shown above, although the
comments in MONSTERTRIG suggest risch has trouble in some cases.
What can we do here?
Robert