Bug with a very specific integral computed with giac

67 views
Skip to first unread message

Emmanuel Briand

unread,
Jan 28, 2022, 5:56:14 AM1/28/22
to sage-devel
Using Sage 9.4 installed with conda on Mac OS X 10.13.6,  I observe an erratic behaviour of "integrate" for a very specific integral.

The following command runs forever:

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

(The problem does not show up with another interval of integration, e.g. 0, pi or -pi, 0 instead of -pi, pi).

After interrupting, the following message is shown:

^CInterrupting Giac...

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

Running a second time the command returns the question, which is ok.

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

But running a third time (or fourth o more) the command returns a wrong result:

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

Actually, after that, no integral of th same function can be calculated:

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

Intgrls of other functions are ok.



The problem does not show up when avoiding giac:

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

Asking for the giac version gives no clue:

sage: giac.version()
"Done"

Should I open a ticket for this?

Emmanuel Briand



Emmanuel Charpentier

unread,
Jan 28, 2022, 3:23:08 PM1/28/22
to sage-devel

Can’t reproduce on Sage 9.5.rc1 running in Debian testing. First thing after session start :

sage: integrate(e^x/(x^2+1), x, -pi, pi)
// Giac share root-directory:/usr/share/giac/
// Giac share root-directory:/usr/share/giac/
Added 0 synonyms
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)

BTW:

sage: integrate(e^x/(x^2+1), x).simplify_full()
1/2*(2*I*cos(1/2)^2 + 2*cos(1/2)*sin(1/2) - I)*Ei(x + I) + 1/2*(-2*I*cos(1/2)^2 + 2*cos(1/2)*sin(1/2) + I)*Ei(x - I)
sage: integrate(e^x/(x^2+1), x, algorithm="fricas").simplify_full()
1/2*(-I*Ei(x - I)*e^(2*I) + I*Ei(x + I))*e^(-I)

And these expressions are equal :

sage: integrate(e^x/(x^2+1), x).trig_reduce().exponentialize().factor()
-1/2*I*(Ei(x - I)*e^(2*I) - Ei(x + I))*e^(-I)
sage: integrate(e^x/(x^2+1), x, algorithm="fricas")
-1/2*I*(Ei(x - I)*e^(2*I) - Ei(x + I))*e^(-I)

Mathematica gives the same (mathematical) result (but this can’t be backtranslated to Sage now, for lack of ExpIntegralEi in the translation dictionary) :

sage: mathematica.Integrate(e^x/(x^2+1), x)
((-I/2)*(E^(2*I)*ExpIntegralEi[-I + x] - ExpIntegralEi[I + x]))/E^I

HTH,

dmo...@deductivepress.ca

unread,
Jan 28, 2022, 5:10:23 PM1/28/22
to sage-devel
I confirm the problem so please open a ticket.

I tried 9.5rc4 on MacOS 11.5.2, I tried 9.4 and 9.5rc4 on Ubuntu 20.04 (CoCalc), and I tried 9.5rc3 on a 32-bit Debian virtual machine.  Maybe something would have happened eventually, but none of them gave an answer within 20 minutes.  The giac version seems to be 1.6.0 in all cases.

Emmanuel Charpentier

unread,
Jan 30, 2022, 12:10:25 AM1/30/22
to sage-devel

Okay. That’s a nice one…

After upgrading to 9.5.rc5 and disabling system’s pari and singular (for other reasons, see there), configure somehow decided to install the giac SPKG and not to use system’s giac.

This triggered the behaviour your reported. Ahiii…

FWIW, system’s giac version is 1.7.0, Sage’s is 1.6.0.

HTH,

Emmanuel Charpentier

unread,
Jan 30, 2022, 1:25:48 AM1/30/22
to sage-devel

To add insult to injury, trying to re-enable system’s giac (make giac-clean && configure failed. Somehow,./configurefinds no *suitable* systemgiacversion, and re-builds Sage's giac. It seems that I should also cleanpari` and consorts and re-re-build…

Sigh…

Le vendredi 28 janvier 2022 à 23:10:23 UTC+1, dmo...@deductivepress.ca a écrit :

Samuel Lelievre

unread,
Jan 30, 2022, 4:48:27 AM1/30/22
to sage-devel
2022-01-30 05:10:25 UTC, Emmanuel Charpentier:

>
> After upgrading to 9.5.rc5 and disabling system’s pari and singular

Did  you mean "after upgrading to 9.5.rc4"? So far,
 Sage 9.5.rc5 does not seem to have been released:

Emmanuel Charpentier

unread,
Jan 30, 2022, 5:51:37 AM1/30/22
to sage-devel
Le dimanche 30 janvier 2022 à 10:48:27 UTC+1, Samuel Lelievre a écrit :
2022-01-30 05:10:25 UTC, Emmanuel Charpentier:
>
> After upgrading to 9.5.rc5 and disabling system’s pari and singular

Did  you mean "after upgrading to 9.5.rc4"?

Yes, of course. The early bird gets to commit all the typos...
 
So far,
 Sage 9.5.rc5 does not seem to have been released:

Indeed. 

Emmanuel Charpentier

unread,
Jan 30, 2022, 7:38:38 AM1/30/22
to sage-devel

FWIW, after rebuilding Sage with system’s giac :

sage: integrate(e^x/(x^2+1), x, -pi, pi)
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)
sage: giac.version()
"giac 1.7.0, (c) B. Parisse and R. De Graeve, Institut Fourier, Universite de Grenoble I"

But now, ptestlong exhibits new bugs. Sigh (again)…

HTH,

Emmanuel Briand

unread,
Jan 30, 2022, 8:01:58 AM1/30/22
to sage-devel
This is now ticket #33245
Reply all
Reply to author
Forward
0 new messages