sagemath / sage

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

computation of the integral of e^x/(x^2+1) over [-pi; pi] runs forever #33245

Open EmmanuelJeanBriand opened 2 years ago

EmmanuelJeanBriand commented 2 years ago

The following computation runs forever (> 20 min):

sage: integrate(e^x/(x^2+1), x, -pi, pi)

on the following versions/systems:

Interrupting gives the message:

^CInterrupting Giac...

integrate(e^x/(x^2 + 1), x, -pi, pi)

giac version is 1.6.0

After running once the command, and interrupting, running again the command several times may give wrong answers:

sage: integrate(e^x/(x^2+1), x, -pi, pi)
-pi*e^x/(x^2 + 1) - x*e^x/(x^2 + 1)

even with integrals of the same function on another interval:

sage: integrate(e^x/(x^2+1), x,0, 1)
-x*e^x/(x^2 + 1)

The problem does not arise

sage: integrate(e^x/(x^2+1), x, -pi, pi, algorithm='maxima')
integrate(e^x/(x^2 + 1), x, -pi, pi)

Component: calculus

Keywords: integrate, giac

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

fchapoton commented 2 years ago
comment:1

hmmm, giac and libgiac sort of works:

sage: giac('int(e^x/(x^2+1),x,-pi,pi)')
5.27595245778
sage: giac('int(e^x/(x^2+1),x)')
(im(Ei(x+i))*tan(1/2)^2-im(Ei(x+i))-im(Ei(x-i))*tan(1/2)^2+im(Ei(x-i))+2*re(Ei(x+i))*tan(1/2)+2*re(Ei(x-i))*tan(1/2))/(2*tan(1/2)^2+2)

sage: libgiac('int(e^x/(x^2+1),x,-pi,pi)')
// Giac share root-directory:/home/chapoton/sage/local/share/giac/
// Giac share root-directory:/home/chapoton/sage/local/share/giac/
Help file /home/chapoton/sage/local/share/giac/doc/fr/aide_cas not found
Added 0 synonyms
5.27595245778
sage: libgiac('int(e^x/(x^2+1),x)')
(im(Ei(x+i))*tan(1/2)^2-im(Ei(x+i))-im(Ei(x-i))*tan(1/2)^2+im(Ei(x-i))+2*re(Ei(x+i))*tan(1/2)+2*re(Ei(x-i))*tan(1/2))/(2*tan(1/2)^2+2)
fchapoton commented 1 year ago

This works in sage 10.1.beta3

sage: integrate(e^x/(x^2+1), x, -pi, pi, algorithm='giac')
1/2*(imag_part(Ei(pi + I))*tan(1/2)^2 - imag_part(Ei(pi - I))*tan(1/2)^2 + 2*real_part(Ei(pi + I))*tan(1/2) + 2*real_part(Ei(pi - I))*tan(1/2) - imag_part(Ei(pi + I)) + imag_part(Ei(pi - I)))/(tan(1/2)^2 + 1) - 1/2*(imag_part(Ei(-pi + I))*tan(1/2)^2 - imag_part(Ei(-pi - I))*tan(1/2)^2 + 2*real_part(Ei(-pi + I))*tan(1/2) + 2*real_part(Ei(-pi - I))*tan(1/2) - imag_part(Ei(-pi + I)) + imag_part(Ei(-pi - I)))/(tan(1/2)^2 + 1)