Opened 9 years ago
Last modified 6 weeks ago
#13097 positive_review enhancement
integral of ln(1+4/5*sin(x)) from -3.1415 to 3.1415 crashes Maxima and Sage
Reported by: | kcrisman | Owned by: | burcin |
---|---|---|---|
Priority: | minor | Milestone: | sage-9.3 |
Component: | calculus | Keywords: | integral |
Cc: | benjaminfjones, dsm | Merged in: | |
Authors: | Dave Morris | Reviewers: | Karl-Dieter Crisman |
Report Upstream: | Fixed upstream, in a later stable release. | Work issues: | |
Branch: | public/13097 (Commits, GitHub, GitLab) | Commit: | 3f41b09a332040a3be9fb0376b03a9397b84eaff |
Dependencies: | Stopgaps: |
Description (last modified by )
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.
Change History (24)
comment:1 Changed 9 years ago by
- Cc benjaminfjones added
- Description modified (diff)
comment:2 Changed 9 years ago by
comment:3 Changed 9 years ago by
- Cc dsm added
comment:4 follow-ups: ↓ 6 ↓ 7 Changed 9 years ago by
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.
comment:5 Changed 9 years ago by
- Report Upstream changed from N/A to Reported upstream. No feedback yet.
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
comment:6 in reply to: ↑ 4 Changed 9 years ago by
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.
comment:7 in reply to: ↑ 4 Changed 9 years ago by
Replying to nbruin:
I don't think maxima understands
ln
.
*facepalm*. Sorry for noise on sage-support
comment:8 Changed 9 years ago by
- Report Upstream changed from Reported upstream. No feedback yet. to Reported upstream. Developers acknowledge bug.
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.
comment:9 Changed 9 years ago by
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).
comment:10 Changed 9 years ago by
- Report Upstream changed from Reported upstream. Developers acknowledge bug. to Fixed upstream, but not in a stable release.
comment:11 Changed 8 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:12 Changed 7 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:13 Changed 7 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:14 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:15 Changed 6 months ago by
- Keywords integral added
comment:16 Changed 6 months ago by
- Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
- Status changed from new to needs_review
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.
comment:17 Changed 6 months ago by
- Resolution set to worksforme
- Status changed from needs_review to closed
ok, then
comment:18 Changed 6 months ago by
- Resolution worksforme deleted
- Status changed from closed to new
As always, doctest ...
comment:19 Changed 6 months ago by
- Report Upstream changed from Fixed upstream, but not in a stable release. to Fixed upstream, in a later stable release.
Also, it was indeed applied in Maxima.
comment:20 Changed 6 months ago by
ok, you are right, but I will wait until #25119 is in sage
comment:21 Changed 5 months ago by
obviously no rush whatsoever since it's fixed
comment:22 Changed 6 weeks ago by
- Branch set to public/13097
comment:23 Changed 6 weeks ago by
- Commit set to 3f41b09a332040a3be9fb0376b03a9397b84eaff
- Milestone changed from sage-duplicate/invalid/wontfix to sage-9.3
- Priority changed from major to minor
- Status changed from new to needs_review
- Type changed from defect to enhancement
comment:24 Changed 6 weeks ago by
- Reviewers set to Karl-Dieter Crisman
- Status changed from needs_review to positive_review
Thanks!
Could it rather be something wrong in how we are receiving data from Maxima(lib)?