Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#10923 closed defect (fixed)

Bad sign in integral()

Reported by: tmonteil Owned by: burcin
Priority: major Milestone: sage-5.0
Component: calculus Keywords: integral sd35.5
Cc: mjo Merged in: sage-5.0.beta3
Authors: Thierry Monteil, Michael Orlitzky Reviewers: Benjamin Jones, Karl-Dieter Crisman
Report Upstream: Fixed upstream, in a later stable release. Work issues:
Branch: Commit:
Dependencies: #12094 Stopgaps:

Description (last modified by benjaminfjones)

Here is the problem (tested on 4.6.2) :

sage: i = integral(e^(-1/x^2),x,0,1)
sage: i.numerical_approx()          
-0.0890738558907803

This should be a positive number since the map is positive.


Apply:

  1. sage-trac_10923.patch to Sage library

Attachments (2)

trac_10923_test_integral-tm.patch (854 bytes) - added by tmonteil 3 years ago.
To be applied when Maxima will be updated.
sage-trac_10923.patch (1.2 KB) - added by mjo 3 years ago.
Updated patch for maxima-5.24 against sage-4.8.alpha6.

Download all attachments as: .zip

Change History (24)

comment:1 Changed 3 years ago by kcrisman

This is probably a bug in Maxima.

sage: integral(e^(-1/x^2),x,0,1)
-1/2*gamma(-1/2, 1)
sage: integral(e^(-1/x^2),x,0,1).n()
-0.0890738558907803
sage: n(1/2*gamma(-1/2,1))
0.0890738558907803
sage: numerical_integral(e^(-1/x^2),0,1)
(0.08907385589078036, 1.4474177932169952e-15)

So probably a minus sign got in there somehow.

This is now Maxima bug 3211937.

comment:2 Changed 3 years ago by tmonteil

Thanks for reporting this to Maxima.

By the way, here is a direct link to the related maxima bug).

comment:3 Changed 3 years ago by kcrisman

  • Report Upstream changed from N/A to Fixed upstream, but not in a stable release.

Apparently this is now fixed. See the bug report above.

So this will need a doctest when we upgrade our Maxima.

Changed 3 years ago by tmonteil

To be applied when Maxima will be updated.

comment:4 Changed 3 years ago by tmonteil

As you suggested, i added a doctest to ensure that the correct integral is computed.

comment:5 Changed 3 years ago by kcrisman

  • Authors set to Thierry Monteil
  • Status changed from new to needs_info

Great. Once we get a Maxima in with this, I'll be sure to review the patch :)

Putting as 'needs info' because of waiting for that, which will likely be a little while since we just upgraded.

comment:6 Changed 3 years ago by mjo

  • Cc mjo added
  • Dependencies set to #12094
  • Report Upstream changed from Fixed upstream, but not in a stable release. to Fixed upstream, in a later stable release.

I've confirmed that this is fixed in maxima-5.24.0.

comment:7 Changed 3 years ago by kcrisman

  • Keywords sd35.5 added

This does not apply on sage-4.8.alpha5. We just tried it at Sage Days 35.5.

comment:8 Changed 3 years ago by mjo

We don't get such a nice answer, anyway, so the doctest from the patch would fail. With maxima-5.24,

sage: integral(e^(-1/x^2),x,0,1).full_simplify()
((e*erf(1) - e)*sqrt(pi) + 1)*e^(-1)

I can update the patch; should we test that the numerical approximation is close to what it should be, or should we check for the symbolic result?

comment:9 Changed 3 years ago by kcrisman

So are you participating remotely at Sage Days 35.5?

We should probably test both, though of course this is not as pretty.

sage: ((e*erf(1) - e)*sqrt(pi) + 1)*e^(-1)
((e*erf(1) - e)*sqrt(pi) + 1)*e^(-1)
sage: _.n()
0.0890738558907804

I never know what incomplete gamma is supposed to give in terms of "normal" functions.

comment:10 Changed 3 years ago by mjo

Is "participating remotely" the same thing as "goofing off at work"? If so, I'm doing it. One more question: is there a good way to test almost-equals, for the numerical approximation? Or do I just do abs(x - y) < epsilon?

comment:11 follow-up: Changed 3 years ago by kcrisman

Hmm. Yes, there is something new to do this much better. See #10952.

comment:12 in reply to: ↑ 11 Changed 3 years ago by mjo

Replying to kcrisman:

Hmm. Yes, there is something new to do this much better. See #10952.

Thanks for this tip. I have a documentation bug open at #12281 for these doctest options if you guys get bored up there at sage days!

Changed 3 years ago by mjo

Updated patch for maxima-5.24 against sage-4.8.alpha6.

comment:13 Changed 3 years ago by mjo

  • Authors changed from Thierry Monteil to Thierry Monteil, Michael Orlitzky
  • Status changed from needs_info to needs_review

There you go. I threw in a few orders of magnitude more tolerance than I think we need to account for platform differences.

comment:14 follow-up: Changed 3 years ago by benjaminfjones

Michael, can you post the location of your Maxima-5.24 spkg so we can test this patch?

comment:15 in reply to: ↑ 14 Changed 3 years ago by mjo

Replying to benjaminfjones:

Michael, can you post the location of your Maxima-5.24 spkg so we can test this patch?

Yup:

http://michael.orlitzky.com/sage/maxima-5.24.0.p0.spkg

comment:16 Changed 3 years ago by benjaminfjones

  • Reviewers set to Benjamin Jones

I can verify that the issue is solved after building the maxima-5.24 spkg that Michael provided and then applying the patch sage-trac_10923.patch.

sage: i = integral(e^(-1/x^2),x,0,1)
sage: i.numerical_approx()
0.0890738558907802

Doctests in the affected file all pass. I'm running all tests now, but pending that, I give the ticket a positive review.

comment:17 Changed 3 years ago by benjaminfjones

  • Description modified (diff)

comment:18 Changed 3 years ago by benjaminfjones

OK, make ptestlong finished. There were failures, but none of them are due to this ticket specifically as far as I can tell. They are all due to the maxima-5.24 spkg I believe. I need to look into #12094 to be sure but it's too late to do that tonight..

comment:19 Changed 3 years ago by kcrisman

  • Reviewers changed from Benjamin Jones to Benjamin Jones, Karl-Dieter Crisman
  • Status changed from needs_review to positive_review

Yes, this all works fine.

comment:20 Changed 3 years ago by jdemeyer

  • Merged in set to sage-5.0.beta3
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:21 Changed 3 years ago by mstreng

Something in this patch seems to trigger a doctesting bug. Try

./sage -t -only-optional=magma "devel/sage/sage/symbolic/integration/integral.py"

See sage release

comment:22 Changed 3 years ago by kcrisman

See #12493 for followup.

Note: See TracTickets for help on using tickets.