Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange integration error/hang with log(abs(sin(x))) #17468

Closed
kcrisman opened this issue Dec 8, 2014 · 21 comments
Closed

Strange integration error/hang with log(abs(sin(x))) #17468

kcrisman opened this issue Dec 8, 2014 · 21 comments

Comments

@kcrisman
Copy link
Member

kcrisman commented Dec 8, 2014

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!

Upstream: Completely fixed; Fix reported upstream

CC: @nbruin @pjbruin @rwst @tscrim

Component: calculus

Keywords: abs_integrate

Author: Frédéric Chapoton

Branch/Commit: d1b9085

Reviewer: Peter Bruin

Issue created by migration from https://trac.sagemath.org/ticket/17468

@kcrisman kcrisman added this to the sage-6.5 milestone Dec 8, 2014
@kcrisman
Copy link
Member Author

kcrisman commented Dec 8, 2014

comment:1

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.

@kcrisman
Copy link
Member Author

kcrisman commented Dec 8, 2014

comment:2

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.

@kcrisman
Copy link
Member Author

kcrisman commented Dec 8, 2014

Upstream: Reported upstream. No feedback yet.

@kcrisman
Copy link
Member Author

kcrisman commented Dec 8, 2014

comment:3

See also #12731.

@kcrisman
Copy link
Member Author

comment:4

Apparently upstream Commit:eb935150c3d2c7717601da5bce470cb7f95f15df fixes this.

@kcrisman
Copy link
Member Author

Changed upstream from Reported upstream. No feedback yet. to Fixed upstream, but not in a stable release.

@pjbruin
Copy link
Contributor

pjbruin commented Dec 16, 2014

comment:5

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

@kcrisman
Copy link
Member Author

comment:6

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/

@pjbruin
Copy link
Contributor

pjbruin commented Dec 16, 2014

comment:7

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.

@pjbruin
Copy link
Contributor

pjbruin commented Dec 17, 2014

comment:8

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

@pjbruin
Copy link
Contributor

pjbruin commented Dec 17, 2014

comment:9

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.

@fchapoton
Copy link
Contributor

Changed keywords from none to abs_integrate

@fchapoton
Copy link
Contributor

New commits:

d1b9085trac 17468 two more integral tests

@fchapoton
Copy link
Contributor

Commit: d1b9085

@fchapoton
Copy link
Contributor

Branch: u/chapoton/17468

@fchapoton
Copy link
Contributor

Author: Frédéric Chapoton

@fchapoton
Copy link
Contributor

comment:13

bot is morally green, please review

@pjbruin
Copy link
Contributor

pjbruin commented Oct 8, 2019

comment:14

Looks good. I also did an independent numerical correctness check for these answers (using PARI/GP).

@pjbruin
Copy link
Contributor

pjbruin commented Oct 8, 2019

Changed upstream from Fixed upstream, but not in a stable release. to Completely fixed; Fix reported upstream

@pjbruin
Copy link
Contributor

pjbruin commented Oct 8, 2019

Reviewer: Peter Bruin

@vbraun
Copy link
Member

vbraun commented Oct 12, 2019

Changed branch from u/chapoton/17468 to d1b9085

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants