integrating trig functions with large constants, exponent out of range



>>>>> "Robert" == Robert Dodier <robert.dodier at gmail.com> writes:

    Robert> On 1/9/07, Raymond Toy <raymond.toy at ericsson.com> wrote:

    >> It might be possible to add another test to MONSTERTRIG (responsible
    >> for handling messy trig integrands) so that if the trig arg is of the
    >> form a*x to try the substitution y = a*x and integrate that.  If it
    >> succeeds, we're done; if not, call the Risch integrator.

    Robert> Maxima knows integrate(sin(n*x)*x, x) with symbolic n. Maybe we
    Robert> can throw in a heuristic: replace literal constants with symbols and
    Robert> try to integrate it; if that fails then fall back on whatever is done now.

I didn't implement this heuristic, but did implement the substitution
y = a*x.  This seems to work and the test suite passes.

I'm not sure this is the right place or way to fix this issue.  It
seems that the Risch integrator would be the right place to fix this,
but I don't know anything about the Risch integrator.

Ray

If you want to play with this, use the following snippet in place of
monstertrig.

(defun simple-trig-arg (exp)
  (m2 exp
      '((mtimes)
	((coefftt) (c freevar))
	((coefftt) (v varp)))
      nil))


(defun monstertrig (exp var *trigarg*)
  (declare (special *trigarg*))
  ;; New stuff begins here, replacing existing code
  (when (not (atom *trigarg*))
    (let ((arg (simple-trig-arg *trigarg*)))
      (cond (arg
	     ;; We have trig(c*x).  Use the substitution y=c*x 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))
		   (new-var (gensym "NEW-VAR-")))
	       (let ((new-int ($integrate (div (maxima-substitute (div new-var c) var exp) c)
					  new-var)))
		 (return-from monstertrig (maxima-substitute *trigarg* new-var new-int)))))
	    (t
	     (return-from monstertrig (rischint exp var))))))
  ;; End of new stuff.
  (prog (*notsame* w *a* *b* y *d*) 
     (declare (special *notsame*))