Opened 5 years ago
Closed 2 months ago
#17468 closed defect (fixed)
Strange integration error/hang with log(abs(sin(x)))
Reported by: | kcrisman | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-9.0 |
Component: | calculus | Keywords: | abs_integrate |
Cc: | nbruin, pbruin, rws, tscrim | Merged in: | |
Authors: | Frédéric Chapoton | Reviewers: | Peter Bruin |
Report Upstream: | Completely fixed; Fix reported upstream | Work issues: | |
Branch: | d1b9085 (Commits) | Commit: | d1b90855e29f67423f404c18db74f2573c59446c |
Dependencies: | Stopgaps: |
Description
Here is something that hangs.
sage: var('u') u sage: integral(log(abs(2*sin(u))), u, 0, pi/3)
Interestingly, we get
sage: maxima_calculus('integrate(log(abs(2*sin(u))), u, 0, %pi/3)') #0: extra_integrate(q=(g93030^2+1)*(4*g93030/((g93030^2+1)*abs(g93030))-8*g93030*abs(g93030)/(g93030^2+1)^2)/abs(g93030),x=g93030) --------------------------------------------------------------------------- TypeError
but in the shell, we get
(%i1) integrate(log(abs(2*sin(u))),u,0,%pi/3); sqrt(3) %i + 1 sqrt(3) %i + 1 (%o1) (18 %i li (--------------) + 18 %i li (- --------------) - 3 %pi log(3) 2 2 2 2 2 2 %pi log(3) %i %pi + 2 %i %pi )/18 + ---------- - ------- 6 12
The problem in Sage directly is
(%i1) load(abs_integrate); (%o1) /Users/karl.crisman/Downloads/sage/local/share/maxima/5.34.1/share/contr\ ib/integration/abs_integrate.mac (%i2) integrate(log(abs(2*sin(u))),u,0,%pi/3); log: encountered log(0).
after which it hangs, and I'll report that upstream. But I don't know what the error in maxima_calculus
is!
Change History (15)
comment:1 Changed 5 years ago by
comment:2 Changed 5 years ago by
- Report Upstream changed from N/A to Reported upstream. No feedback yet.
See https://sourceforge.net/p/maxima/bugs/2853/ and note that the closely related integral integral(log(abs(sin(x))),x,0,%pi/2)
is just -pi log(2)
, according to Wolfram Alpha, though I haven't done the improper integral myself.
comment:3 Changed 5 years ago by
See also #12731.
comment:4 Changed 5 years ago by
- Component changed from PLEASE CHANGE to calculus
- Report Upstream changed from Reported upstream. No feedback yet. to Fixed upstream, but not in a stable release.
Apparently upstream Commit:eb935150c3d2c7717601da5bce470cb7f95f15df fixes this.
comment:5 follow-up: ↓ 6 Changed 5 years ago by
For the first example, with Maxima 5.35.1 (see #17514), I get the following error after a very long time (maybe 20 minutes):
sage: integral(log(abs(2*sin(u))), u, 0, pi/3) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-5-1e3da5ec6161> in <module>() ----> 1 integral(log(abs(Integer(2)*sin(u))), u, Integer(0), pi/Integer(3)) /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/misc/functional.pyc in integral(x, *args, **kwds) 800 """ 801 if hasattr(x, 'integral'): --> 802 return x.integral(*args, **kwds) 803 else: 804 from sage.symbolic.ring import SR /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expre ssion.cpp:50966)() /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.pyc in integrate(expression, v, a, b, algorithm, hold) 710 return indefinite_integral(expression, v, hold=hold) 711 else: --> 712 return definite_integral(expression, v, a, b, hold=hold) 713 714 integral = integrate /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/symbolic/function.so in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/func tion.cpp:10093)() /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/symbolic/function.so in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cp p:6284)() /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/symbolic/function.so in sage.symbolic.function.BuiltinFunction._evalf_or_eval_ (build/cythonized/sage/symbol ic/function.cpp:10751)() /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.pyc in _eval_(self, f, x, a, b) 173 for integrator in self.integrators: 174 try: --> 175 return integrator(*args) 176 except NotImplementedError: 177 pass /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/symbolic/integration/external.pyc in maxima_integrator(expression, v, a, b) 19 result = maxima.sr_integral(expression,v) 20 else: ---> 21 result = maxima.sr_integral(expression, v, a, b) 22 return result._sage_() 23 /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in sr_integral(self, *args) 774 """ 775 try: --> 776 return max_to_sr(maxima_eval(([max_integrate],[sr_to_max(SR(a)) for a in args]))) 777 except RuntimeError as error: 778 s = str(error) /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/libs/ecl.so in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:6877)() /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/libs/ecl.so in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:4734)() RuntimeError: ECL says: CALL-ARGUMENTS-LIMIT exceeded
For the second example:
sage: maxima_calculus('integrate(log(abs(2*sin(u))), u, 0, %pi/3)') --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-48dbe48094c9> in <module>() ----> 1 maxima_calculus('integrate(log(abs(2*sin(u))), u, 0, %pi/3)') /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/misc/lazy_import.so in sage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:3230)() /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in __call__(self, x, name) 197 198 if isinstance(x, basestring): --> 199 return cls(self, x, name=name) 200 try: 201 return self._coerce_from_special_method(x) /home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in __init__(self, parent, value, is_name, name) 624 self._name = parent._create(value, name=name) 625 except (TypeError, RuntimeError, ValueError) as x: --> 626 raise TypeError(x) 627 628 def _latex_(self): TypeError: ECL says: CALL-ARGUMENTS-LIMIT exceeded
comment:6 in reply to: ↑ 5 ; follow-up: ↓ 8 Changed 5 years ago by
For the first example, with Maxima 5.35.1 (see #17514), I get the following error after a very long time (maybe 20 minutes):
This might be https://sourceforge.net/p/maxima/bugs/2860/, see also https://sourceforge.net/p/maxima/bugs/2859/
comment:7 Changed 5 years ago by
Also directly in Maxima (with a very long time between "encountered log(0)" and "encountered a Lisp error"):
Maxima 5.35.1 http://maxima.sourceforge.net using Lisp ECL 13.5.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) integrate(log(abs(2*sin(u))),u,0,%pi/3); sqrt(3) %i + 1 sqrt(3) %i + 1 (%o1) (18 %i li (--------------) + 18 %i li (- --------------) - 3 %pi log(3) 2 2 2 2 2 2 %pi log(3) %i %pi + 2 %i %pi )/18 + ---------- - ------- 6 12 (%i2) load(abs_integrate); (%o2) /home/bruinpj/src/sage/local/share/maxima/5.35.1/share/contrib/integration/abs_integrate.mac (%i3) integrate(log(abs(2*sin(u))),u,0,%pi/3); log: encountered log(0). Maxima encountered a Lisp error: In form (PROGN (REQUIRE :DEFSYSTEM) (RUN)) CALL-ARGUMENTS-LIMIT exceeded Automatically continuing. To enable the Lisp debugger set *debugger-hook* to nil.
comment:8 in reply to: ↑ 6 Changed 5 years ago by
Replying to kcrisman:
For the first example, with Maxima 5.35.1 (see #17514), I get the following error after a very long time (maybe 20 minutes):
This might be https://sourceforge.net/p/maxima/bugs/2860/, see also https://sourceforge.net/p/maxima/bugs/2859/
At first sight it seems to be a different error; the ones in the Maxima bug tracker occur sooner (the second one after a few seconds, the others almost immediately) and look different.
Maxima branch_5_35_base_16_gfc3f8b9_dirty http://maxima.sourceforge.net using Lisp GNU Common Lisp (GCL) GCL 2.6.12 (a.k.a. GCL) 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) load(abs_integrate); (%o1) /home/bruinpj/src/maxima/share/contrib/integration/abs_integrate.mac (%i2) taylor(x^3*(cos(x)*abs(sin(x))/sin(x)-2*cos(x)*sin(x)/abs(sin(x)))/6,x,0,1); Maxima encountered a Lisp error: Condition in MACSYMA-TOP-LEVEL [or a callee]: INTERNAL-SIMPLE-ERROR: Bind stack overflow. Automatically continuing. To enable the Lisp debugger set *debugger-hook* to nil. (%i3) integrate(abs(cos(x)),x,0,%pi); log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). log: encountered log(0). (%o3) - 1 (%i4) integrate(abs(sin(x)),x,0,%pi); Unrecoverable error: bind stack overflow. Aborted
comment:9 Changed 5 years ago by
Also, with the latest Git version of Maxima (and using GCL) the error has disappeared and there is just an "encountered log(0)" message:
Maxima branch_5_35_base_16_gfc3f8b9_dirty http://maxima.sourceforge.net using Lisp GNU Common Lisp (GCL) GCL 2.6.12 (a.k.a. GCL) 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) integrate(log(abs(2*sin(u))),u,0,%pi/3); sqrt(3) %i + 1 sqrt(3) %i + 1 (%o1) (18 %i li (--------------) + 18 %i li (- --------------) - 3 %pi log(3) 2 2 2 2 2 2 %pi log(3) %i %pi + 2 %i %pi )/18 + ---------- - ------- 6 12 (%i2) load(abs_integrate); (%o2) /home/bruinpj/src/maxima/share/contrib/integration/abs_integrate.mac (%i3) integrate(log(abs(2*sin(u))),u,0,%pi/3); log: encountered log(0). sqrt(3) %i + 1 sqrt(3) %i + 1 (%o3) (18 %i li (--------------) + 18 %i li (- --------------) - 3 %pi log(3) 2 2 2 2 2 2 %pi log(3) %i %pi + 2 %i %pi )/18 + ---------- - ------- 6 12
I guess the reason for the errors in comment:5 and comment:7 was that http://sourceforge.net/p/maxima/bugs/2853/ was only fixed after Maxima 5.35.1 was released.
comment:10 Changed 7 months ago by
- Keywords abs_integrate added
comment:11 Changed 2 months ago by
- Branch set to u/chapoton/17468
- Commit set to d1b90855e29f67423f404c18db74f2573c59446c
- Status changed from new to needs_review
New commits:
d1b9085 | trac 17468 two more integral tests
|
comment:12 Changed 2 months ago by
- Milestone changed from sage-6.5 to sage-9.0
comment:14 Changed 2 months ago by
- Report Upstream changed from Fixed upstream, but not in a stable release. to Completely fixed; Fix reported upstream
- Reviewers set to Peter Bruin
- Status changed from needs_review to positive_review
Looks good. I also did an independent numerical correctness check for these answers (using PARI/GP).
comment:15 Changed 2 months ago by
- Branch changed from u/chapoton/17468 to d1b90855e29f67423f404c18db74f2573c59446c
- Resolution set to fixed
- Status changed from positive_review to closed
I'm getting pretty frustrated with
abs_integrate
, despite the many integral it allows us to do. It may have to become an option, though that would be annoying to implement all by itself. But it may be the only way to prevent these errors - see also #13733, #11590, #14591, and #16643.