sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.32k stars 451 forks source link

Surprising error in numerical integration #30379

Open 7822f248-ba56-45f1-ab3d-4de7482bdf9f opened 4 years ago

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 4 years ago

Source : this ask.sagemath question.

sage: g(x)=gamma_inc(2,11/5)*x
sage: g(x).integrate(x,2,5).n() ## For reference
3.72298612097441

So far, so good. But :

sage: gamma_inc(2,11/5).n()*numerical_integral(x,2,5)[0]
3.72298612097441
sage: numerical_integral(g(x),2,5)
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-105-c9c90f4afa7c> in <module>
----> 1 numerical_integral(g(x),Integer(2),Integer(5))

/usr/local/sage-9/local/lib/python3.7/site-packages/sage/calculus/integration.pyx in sage.calculus.integration.numerical_integral (build/cythonized/sage/calculus/integration.c:4479)()
    380          _b = b
    381          W = <gsl_integration_workspace*> gsl_integration_workspace_alloc(n)
--> 382          sig_on()
    383          gsl_integration_qag(&F,_a,_b,eps_abs,eps_rel,n,rule,W,&result,&abs_err)
    384          sig_off()

SystemError: calling remove_from_pari_stack() inside sig_on()

Ouch... The problem seems to come from the ((unpurposeful) repeated) computation of gamma(2,11/5) inside the integrated function.

FWIW:

sage: numerical_integral(x*arctan(sqrt(3)),2,5)
(10.995574287564278, 1.2207539743030213e-13)

Component: numerical

Keywords: integral

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

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 4 years ago
comment:1

A few (alive, dead or zombie) fossils tickets, possibly related : #15219, #17328, #18210

fchapoton commented 3 years ago

Changed keywords from none to integral

mkoeppe commented 3 years ago
comment:4

Moving to 9.4, as 9.3 has been released.