Bug in symbolic integral

69 views
Skip to first unread message

Johannes Lippmann

unread,
Nov 12, 2014, 7:32:52 AM11/12/14
to sage-s...@googlegroups.com
Hi there,

I want to compute the integral from 2 to 3 of the funktion f(x)=1/log(x)^2. Sage gives conflicting results for different ways to compute it:

numerical way
(double checked by Wolfram Alpha and Maple):

sage: numerical_integral(1/log(x)^2,2,3)
(1.273097216447114, 1.4134218422857824e-14)

symbolic way
(I think this is wrong)

sage: N(integral(1/log(x)^2,(x,2,3)))
0.536566859259958


The funktion is not that evil in the interval [2,3], so I don't think it is just a numerical issue.

This is the minimal example. I am using sage 6.1 and 6.3 (tried both) on Ubuntu.

kcrisman

unread,
Nov 12, 2014, 10:01:06 AM11/12/14
to sage-s...@googlegroups.com
numerical way
(double checked by Wolfram Alpha and Maple):

sage: numerical_integral(1/log(x)^2,2,3)
(1.273097216447114, 1.4134218422857824e-14)

symbolic way
(I think this is wrong)

Of course you are right:

sage: (plot(1/(ln(x))^2, x,2,3)+plot(1,x,2,3,color='red')).show(ymin=0)
 

sage: N(integral(1/log(x)^2,(x,2,3)))
0.536566859259958




This is probably a problem with our evaluation of incomplete gamma functions, or possibly of Maxima giving a bad branch or something?

sage: integral(1/(ln(x))^2, x,2,3)
gamma(-1, -log(3)) - gamma(-1, -log(2))
 
sage: integral(1/(ln(x))^2, x)
gamma(-1, -log(x))

Maxima:
(%i3) integrate(1/log(x)^2,x);
(%o3)                   gamma_incomplete(- 1, - log(x))

This is ugly:

sage: plot(lambda t: numerical_integral(1/ln(x)^2,2,t)[0],2,3)+plot(lambda t: gamma(-1, -log(t)).real(),2,3,color='red')

I'm not at all an expert on such special functions, but this should be enough for someone else to diagnose it pretty quickly.

Robert Dodier

unread,
Nov 12, 2014, 2:49:34 PM11/12/14
to sage-s...@googlegroups.com
On 2014-11-12, Johannes Lippmann <johannes...@googlemail.com> wrote:

> *symbolic way*
> (I think this is wrong)
>
> sage: N(integral(1/log(x)^2,(x,2,3)))
> *0.536566859259958*

Hmm, I can't reproduce this problem. I am working w/ Maxima 5.34.1.

(%i1) display2d : false $
(%i2) foo : 1/log(x)^2 $
(%i3) integrate (foo, x, 2, 3);
(%o3) gamma_incomplete(-1,-log(3))-gamma_incomplete(-1,-log(2))
(%i4) %, numer;
(%o4) 1.273097216447114
(%i5) integrate (foo, x);
(%o5) gamma_incomplete(-1,-log(x))
(%i6) ev (%, x=3) - ev (%, x=2);
(%o6) gamma_incomplete(-1,-log(3))-gamma_incomplete(-1,-log(2))
(%i7) %, numer;
(%o7) 1.273097216447114
(%i8) quad_qags (foo, x, 2, 3);
(%o8) [1.273097216447114,1.413421842285782E-14,21,0]

Looks like Maxima handles the definite and indefinite integrals as
expected. Or perhaps I have misunderstood the problem?

Hope this helps,

Robert Dodier

kcrisman

unread,
Nov 12, 2014, 4:14:29 PM11/12/14
to sage-s...@googlegroups.com
Hmm, I can't reproduce this problem. I am working w/ Maxima 5.34.1.

  (%i1) display2d : false $
  (%i2) foo : 1/log(x)^2 $
  (%i3) integrate (foo, x, 2, 3);
  (%o3) gamma_incomplete(-1,-log(3))-gamma_incomplete(-1,-log(2))
  (%i4) %, numer;
  (%o4) 1.273097216447114
  (%i5) integrate (foo, x);
  (%o5) gamma_incomplete(-1,-log(x))
  (%i6) ev (%, x=3) - ev (%, x=2);
  (%o6) gamma_incomplete(-1,-log(3))-gamma_incomplete(-1,-log(2))
  (%i7) %, numer;
  (%o7) 1.273097216447114


 
Looks like Maxima handles the definite and indefinite integrals as
expected. Or perhaps I have misunderstood the problem?


Nope, you've just confirmed that the way Sage handles incomplete gamma evaluation is broken somehow.  I've opened http://trac.sagemath.org/ticket/17328 for this.

 

Peter Bruin

unread,
Nov 14, 2014, 5:16:05 PM11/14/14
to sage-s...@googlegroups.com
Hello,

This appears to be a bug in the evaluation of the incomplete Gamma function in the older PARI version(s) used by Sage up to and including 6.3.  The computation is correct in the newly released Sage 6.4, which uses the recent stable PARI release 2.7.1.

(See also http://trac.sagemath.org/ticket/17328 for a PARI example showing very different incomplete Gamma function outputs in the two different PARI versions.)

Peter


Op woensdag 12 november 2014 22:14:29 UTC+1 schreef kcrisman:
Reply all
Reply to author
Forward
0 new messages