Opened 5 months ago

Last modified 3 days ago

#16643 needs_review defect

integrate() problem

Reported by: rws Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: symbolics Keywords: integration, maxima
Cc: Merged in:
Authors: Reviewers: Peter Bruin
Report Upstream: Fixed upstream, but not in a stable release. Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by nbruin)

I interrupted Sage after 5min of churning without result:

sage: f=diff((tan(x)+x)*e^tan(x),x)
(tan(x)^2 + 1)*(x + tan(x))*e^tan(x) + (tan(x)^2 + 2)*e^tan(x)
sage: integrate(f,x)

On a faster computer:

sage: %time integrate(f,x)
CPU times: user 3min 58s, sys: 50 ms, total: 3min 58s
Wall time: 3min 58s
integrate((tan(x)^2 + 1)*(x + tan(x))*e^tan(x) + (tan(x)^2 + 2)*e^tan(x), x)

On the other hand, for the equivalent expression

sage: g=e^tan(x)*sec(x)^2*(tan(x)+x)+e^tan(x)*(sec(x)^2+1)
sage: %time integrate(g,x)
RuntimeError: ECL says: In function CAR, the value of the first argument is
  0
which is not of the expected type LIST

which happens in maxima/ECL with abs_integrate loaded, but not in maxima/SBCL. Upstream: https://sourceforge.net/p/maxima/bugs/2781/

Change History (11)

comment:1 Changed 5 months ago by nbruin

This may be a reportable issue upstream:

Maxima 5.33.0 http://maxima.sourceforge.net
using Lisp ECL 12.12.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) display2d: false;

(%o1) false
(%i2) load(abs_integrate);

(%o2) "/usr/local/sage/sage-git/local/share/maxima/5.33.0/share/contrib/integration/abs_integrate.mac"
(%i3) f: diff((tan(x)+x)*exp(tan(x)),x);

(%o3) %e^tan(x)*sec(x)^2*(tan(x)+x)+%e^tan(x)*(sec(x)^2+1)
(%i4) integrate(f,x);

Maxima encountered a Lisp error:

 In function CAR, the value of the first argument is
  0
which is not of the expected type LIST

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.

Without the load(abs_integrate) the code seems to execute fine (by returning the integral unevaluated). This does not fully explain why sage seems to get stuck on it, though. Perhaps a try/except that is a little too agressive in suppressing problems?

Also, the problem does not arise in Maxima 5.30.0 on SBCL 1.1.8-2, so it may be a problem with maxima-ecl interaction (so it depends a little on how well the maxima-devs want to support ECL)

Also executing domain: complex;load(to_poly_solve);load(simplify_sum); (as we do in sage) doesn't affect the outcome.

comment:2 Changed 5 months ago by nbruin

The following helps perhaps to locate the problematic code. The following fragment does complete (but after considerable time):

from sage.interfaces.maxima_lib import *
args=((tan(x)^2 + 1)*(x + tan(x))*e^tan(x) + (tan(x)^2 + 2)*e^tan(x), x)
expr=EclObject(([max_integrate],[sr_to_max(SR(a)) for a in args]))
result=maxima_eval(expr)
max_to_sr(result)

this is the code the integrator would execute, and it does return the integral unevaluated. So somehow we're avoiding the error above.

Indeed, the difference seems to be how you feed the expression. Sage actually DOES return this integral (unevaluated), it just takes longer. The difference is in how you give the integral. The expression for the derivative that maxima computes gives the result above. However, the form computed by sage still works. If you do in maxima

...
(%i6) f: (tan(x)^2 + 1)*(x + tan(x))*exp(tan(x)) + (tan(x)^2 + 2)*exp(tan(x));

(%o6) %e^tan(x)*(tan(x)^2+2)+%e^tan(x)*(tan(x)+x)*(tan(x)^2+1)
(%i7) integrate(f,x);

(%o7) 'integrate(%e^tan(x)*(tan(x)^2+2)+%e^tan(x)*(tan(x)+x)*(tan(x)^2+1),x)

everything is fine.

So the only report for Maxima is the above question why ECL runs into an error for the particular integral given there. This integral is not the one encountered with the original sage script and the sage code does finish correctly (albeit after a rather long time).

comment:3 Changed 5 months ago by nbruin

  • Description modified (diff)
  • Summary changed from integrate() infinite loop to integrate() problem

I changed the title and description, because I found evidence there is no infinite loop involved. Please change back if you're unhappy with the change.

Last edited 5 months ago by nbruin (previous) (diff)

comment:4 Changed 5 months ago by nbruin

  • Description modified (diff)

comment:5 Changed 5 months ago by nbruin

  • Description modified (diff)

comment:6 Changed 5 months ago by kcrisman

  • Report Upstream changed from N/A to Reported upstream. No feedback yet.

comment:7 Changed 4 months ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:8 Changed 11 days ago by kcrisman

See also #12731.

comment:9 Changed 5 days ago by kcrisman

  • Report Upstream changed from Reported upstream. No feedback yet. to Fixed upstream, but not in a stable release.

It's claimed that upstream has this 'fixed' in some sense now.

comment:10 Changed 3 days ago by pbruin

  • Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
  • Reviewers set to Peter Bruin
  • Status changed from new to needs_review

With Maxima 5.34.1 and also with 5.35.1 (see #17514), both integrals are returned unevaluated:

sage: f = diff((tan(x) + x) * e^tan(x), x)
sage: %time integrate(f, x)
CPU times: user 5min 32s, sys: 12 ms, total: 5min 32s
Wall time: 5min 33s
integrate((tan(x)^2 + 1)*(x + tan(x))*e^tan(x) + (tan(x)^2 + 2)*e^tan(x), x)
sage: g = e^tan(x) * sec(x)^2 * (tan(x) + x) + e^tan(x) * (sec(x)^2 + 1)
sage: %time integrate(g,x)
CPU times: user 4min 43s, sys: 128 ms, total: 4min 44s
Wall time: 4min 44s
integrate((x + tan(x))*e^tan(x)*sec(x)^2 + (sec(x)^2 + 1)*e^tan(x), x)

I propose to close this since the ECL error appears to have been fixed upstream and the example takes too long to be a sensible doctest.

comment:11 Changed 3 days ago by kcrisman

some terrifyingly huge trig expression

says upstream... though I am agnostic on whether to close this, one could repurpose it as "make this integral faster" and ask upstream for that (or see if Sympy can do it faster, or whatever).

Note: See TracTickets for help on using tickets.