MONSTERTRIG 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.
Raymond Toy
2008-01-02
Logged In: YES
user_id=28849
Originator: NO
The comment refers to some other bug (reported by Stavros some time ago). I guess the test for trig(c*x+b) could be made stricter so that only that particular case is handled. Or we can just take out the special case all together and live with the slowness.
Robert Dodier
2008-01-03
Logged In: YES
user_id=501686
Originator: YES
> I guess the test for trig(c*x+b) could be made stricter
> so that only that particular case is handled.
Narrowing the test makes sense to me.
> Or we can just take out the special case all
> together and live with the slowness.
Oh, I think we don't need to be so drastic.
Raymond Toy
2008-01-07
Logged In: YES
user_id=28849
Originator: NO
Fixed in sin.lisp, 1.29.
Changed the test match only if the coefficient is a number >= 1. All tests pass, and x*sin(n*x) is still fast, and we don't get the infinite recursion.
BTW, the original bug report doesn't actually give an infinite recursion. It eventually stopped with a message about too many contexts. But if I tried to do the integral again, it failed instantly with too many contexts. See bug
1866077.
Raymond Toy
2008-01-07