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

integral of ln(1+4/5*sin(x)) from -3.1415 to 3.1415 crashes Maxima and Sage #13097

Closed
kcrisman opened this issue Jun 8, 2012 · 26 comments
Closed

Comments

@kcrisman
Copy link
Member

kcrisman commented Jun 8, 2012

See extensive discussion at this sage-support thread.

Reported by Ben Jones:

sage: integrate(ln(1+4/5*sin(x)), x, -3.1415, 3.1415)


;;;
;;; Binding stack overflow.
;;; Jumping to the outermost toplevel prompt
;;;

...

;;;
;;; Binding stack overflow.
;;; Jumping to the outermost toplevel prompt
;;;


/Users/jonesbe/sage/sage-5.1.beta2/spkg/bin/sage: line 335: 86594 Illegal instruction     sage-ipython "$@" -i

There don't seem to be any problems with Maxima. Although it's been traced down (thanks to Dan Drake) to 5.0.beta3, the only obvious candidate for a change in our interface is when we added abs_integrate, which doesn't seem to impact things.

(%i2) load(abs_integrate);
(%o2) /Users/.../sage-5.0/local/share/maxima/5.26.0/s\
hare/contrib/integration/abs_integrate.mac
(%i4) keepfloat:true;
(%o4)                                true
(%i7) integrate(ln(1+4/5*sin(x)), x, -3.1415, 3.1415);
                          3.1415
                         /
                         [            4 sin(x)
(%o7)                    I         ln(-------- + 1) dx
                         ]               5
                         /
                          - 3.1415

And we have

sage: maxima_calculus(" integrate(ln(1+4/5*sin(x)), x, -3.1415, 3.1415);")
'integrate(ln(4*sin(x)/5+1),x,-3.1415,3.1415)

so something must indeed be wrong in how we're sending this to Maxima.

Upstream: Fixed upstream, in a later stable release.

CC: @benjaminfjones @sagetrac-dsm

Component: calculus

Keywords: integral

Author: Dave Morris

Branch/Commit: 3f41b09

Reviewer: Karl-Dieter Crisman

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

@kcrisman kcrisman added this to the sage-5.11 milestone Jun 8, 2012
@kcrisman

This comment has been minimized.

@dimpase
Copy link
Member

dimpase commented Jun 8, 2012

comment:2

Could it rather be something wrong in how we are receiving data from Maxima(lib)?

@nbruin
Copy link
Contributor

nbruin commented Jun 8, 2012

comment:4

I don't think maxima understands ln. If you do

maxima_calculus(" integrate(log(1+4/5*sin(x)), x, -3.1415, 3.1415);")

you see the same thing happening. No problem in vanilla maxima. But when we load abs_integrate:

(%i1) load(abs_integrate);
(%o1) /usr/local/sage/5.0/local/share/maxima/5.26.0/share/contrib/integration/abs_integrate.mac
(%i2) integrate(log(1+4/5*sin(x)), x, -3.1415, 3.1415);
...
Condition of type: STACK-OVERFLOW
BINDING-STACK overflow at size 8448. Stack can probably be resized.

FYI: with

from sage.interfaces.maxima_lib import *
from sage.libs.ecl import *
args=(ln(1+4/5*sin(x)), x, -3.1415, 3.1415)
I=EclObject(([max_integrate],[sr_to_max(SR(a)) for a in args]))
I

you see what expression gets passed to maxima_lib. With

EclObject('#$integrate(log(1+4/5*sin(x)), x, -3.1415, 3.1415)$')

you see what maxima's parser would produce. With

maxima_eval(I)

you can trigger the same explosion. Note that with this trick, you can quickly see that

EclObject('#$integrate(ln(1+4/5*sin(x)), x, -3.1415, 3.1415)$')

creates an essentially different expression.

@nbruin
Copy link
Contributor

nbruin commented Jun 9, 2012

comment:5

The problem can be simplified to

integrate(log(sin(x)),x);

which maxima without abs_integrate can do (or at least it returns an answer).

This is now Maxima Artifact 3533723

@nbruin
Copy link
Contributor

nbruin commented Jun 9, 2012

Upstream: Reported upstream. No feedback yet.

@kcrisman
Copy link
Member Author

kcrisman commented Jun 9, 2012

comment:6

I don't think maxima understands ln. If you do

Well, egg on my face! Sorry for that noise. I just don't use Maxima enough beyond trying to generate bug reports or find new functionality for Sage :)

And good diagnosis; I guess if I had tried log instead I would have gotten the same problem.

@dimpase
Copy link
Member

dimpase commented Jun 9, 2012

comment:7

Replying to @nbruin:

I don't think maxima understands ln.

facepalm. Sorry for noise on sage-support

@nbruin
Copy link
Contributor

nbruin commented Jun 9, 2012

Changed upstream from Reported upstream. No feedback yet. to Reported upstream. Developers acknowledge bug.

@nbruin
Copy link
Contributor

nbruin commented Jun 9, 2012

comment:8

We really need more options for "upstream" ;-). How about "Developers acknowledge bug, propose fix, but haven't gotten around to merging it because they got the fix with less than 24 hours round trip time"? See Maxima tracker. I have no doubt this will be fixed in some future Maxima release.

@nbruin
Copy link
Contributor

nbruin commented Jun 9, 2012

comment:9

We can monkey-patch Barton Willis's fix into sage's maxima:

sage: L="""signum_int(q,x) :=
....: block([w : 1, acc : [], sgn, v, f, listconstvars : true],
....:   q : convert_to_signum(q),
....:   if freeof('signum, q) then
....:     (false)
....:   else (
....:     q : almost_everywhere_simp(q),
....:     v : listofvars(q),
....:     q : block([expandwrt_denom : true], expandwrt(q,'signum)),
....:     if (f : abs_int_extra(q,x)) # false then f
....:     else if (f : partition_as_signum(q,x)) # false then (
....:       w : first(f),
....:       acc : second(f),
....:       if every(lambda([s], linear_in_p(s,x)), acc) then (
....:       sgn : xreduce("*", map(lambda([s], diff(s,x)),acc)),
....:       acc : map(lambda([s], rhs(first(linsolve(s, x)))),acc),
....:       signum_int_helper(signum(sgn) * w, sort(acc), x)))
....:     else if (safe_op(q) = "+") then (
....:         f : map(lambda([s], signum_int(s,x)), args(q)),
....:         if member(false, f) then false else xreduce("+", f))
....:       else block([extra_integration_methods : [],
....:         extra_definite_integration_methods : []],integrate(q,x))
....:   )
....: );"""
sage:  integrate(ln(1+4/5*sin(x)), x, -3.1415, 3.1415)
integrate(log(4/5*sin(x) + 1), x, -3.1415, 3.1415)
sage: integrate(ln(sin(x)),x)
1/2*I*x^2 - 1/2*x*log(sin(x)^2 + cos(x)^2 - 2*cos(x) + 1) - 1/2*x*log(sin(x)^2 + cos(x)^2 + 2*cos(x) + 1) + x*log(sin(x)) + I*x*arctan2(sin(x), -cos(x) + 1) - I*x*arctan2(sin(x), cos(x) + 1) + I*polylog(2, -e^(I*x)) + I*polylog(2, e^(I*x))

This just patches a routine defined in abs_integrate.mac. It's a LOT slower than in 4.7.1, though, so if performance is any concern, we might want to reconsider whether abs_integrate should be loaded by default. By manipulating the maxima variables extra_integration_methods and extra_definite_integration_methods it should be possible to control which integration methods maxima tries to use (this is what abs_integrate hooks into).

@kcrisman
Copy link
Member Author

kcrisman commented Jul 7, 2012

Changed upstream from Reported upstream. Developers acknowledge bug. to Fixed upstream, but not in a stable release.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@fchapoton
Copy link
Contributor

Changed keywords from none to integral

@dimpase
Copy link
Member

dimpase commented Sep 22, 2020

comment:16

I don't see crashes 8 years later on:

┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.2.beta12, Release Date: 2020-09-06              │
│ Using Python 3.8.5. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
sage: integrate(ln(1+4/5*sin(x)), x, -3.1415, 3.1415)                                                                                
-1.40205228301
sage: integrate(ln(1+4/5*sin(x)), x, -pi, pi)                                                                                        
integrate(log(4/5*sin(x) + 1), x, -pi, pi)
sage: integrate(log(sin(x)),x)                                                                                                       
1/2*I*x^2 - I*x*arctan2(sin(x), cos(x) + 1) + I*x*arctan2(sin(x), -cos(x) + 1) - 1/2*x*log(cos(x)^2 + sin(x)^2 + 2*cos(x) + 1) - 1/2*x*log(cos(x)^2 + sin(x)^2 - 2*cos(x) + 1) + x*log(sin(x)) + I*dilog(-e^(I*x)) + I*dilog(e^(I*x))

propose to close as worksforme.

@dimpase dimpase removed this from the sage-6.4 milestone Sep 22, 2020
@fchapoton
Copy link
Contributor

comment:17

ok, then

@kcrisman
Copy link
Member Author

comment:18

As always, doctest ...

@kcrisman
Copy link
Member Author

comment:19

Also, it was indeed applied in Maxima.

@kcrisman
Copy link
Member Author

Changed upstream from Fixed upstream, but not in a stable release. to Fixed upstream, in a later stable release.

@fchapoton
Copy link
Contributor

comment:20

ok, you are right, but I will wait until #25119 is in sage

@kcrisman
Copy link
Member Author

comment:21

obviously no rush whatsoever since it's fixed

@DaveWitteMorris
Copy link
Member

Branch: public/13097

@DaveWitteMorris
Copy link
Member

comment:23

The PR adds the original issue as a doctest.


New commits:

3f41b09doctest for trac 13097

@DaveWitteMorris
Copy link
Member

Author: Dave Morris

@DaveWitteMorris
Copy link
Member

Commit: 3f41b09

@kcrisman
Copy link
Member Author

comment:24

Thanks!

@kcrisman
Copy link
Member Author

Reviewer: Karl-Dieter Crisman

@vbraun
Copy link
Member

vbraun commented Mar 9, 2021

Changed branch from public/13097 to 3f41b09

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

8 participants