# why sage returns different output from giac?

When I call giac directly, it returns an output different from what sagemath returns using giac. Why is that?

I am using sagemath SageMath version 9.6.rc1, with latest giac 1.9.0.

Here is an example

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.6.rc1, Release Date: 2022-04-19                 │
│ Using Python 3.10.4. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: var('x')
x
sage: integrate((x^2-1)/(1+x)^(1/2)/(x^2+1)/(1+(1+x)^(1/2))^(1/2)/(1+(1+(1+x)^(1/2))^(1/2))^(1/2),x, algorithm="giac")
integrate((x^2 - 1)/((x^2 + 1)*sqrt(x + 1)*sqrt(sqrt(x + 1) + 1)*sqrt(sqrt(sqrt(x + 1) + 1) + 1)), x)

sage:  print(giac.version())
"giac 1.9.0, (c) B. Parisse and R. De Graeve, Institut Fourier, Universite de Grenoble I"


Notice that the result returned above is the input. But when I call giac directly using same integrand, it gives

>giac
// Maximum number of parallel threads 24
Welcome to giac readline interface, version 1.9.0
(c) 2001,2021 B. Parisse & others
Homepage http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
Released under the GPL license 3.0 or above
May contain BSD licensed software parts (lapack, atlas, tinymt)
-------------------------------------------------
Press CTRL and D simultaneously to finish session
Type ?commandname for help
0>>  integrate((x^2-1)/(1+x)^(1/2)/(x^2+1)/(1+(1+x)^(1/2))^(1/2)/(1+(1+(1+x)^(1/2))^(1/2))^(1/2),x)
Warning, integration of abs or sign assumes constant sign by intervals (correct if the argument is real):
Check [abs(4*x+1)]
Warning, integration of abs or sign assumes constant sign by intervals (correct if the argument is real):
Check [abs(4*t_nostep^4-8*t_nostep^2+1)]
Discontinuities at zeroes of 4*t_nostep^4-8*t_nostep^2+1 were not checked
-8*sqrt(sqrt(sqrt(x+1)+1)+1)+integrate(-2/(sqrt(x+1)*sqrt(sqrt(x+1)+1)*sqrt(sqrt(sqrt(x+1)+1)+1)*((sqrt(sqrt(x+1)+1)+1)^8-8*(sqrt(sqrt(x+1)+1)+1)^7+24*(sqrt(sqrt(x+1)+1)+1)^6-32*(sqrt(sqrt(x+1)+1)+1)^5+14*(sqrt(sqrt(x+1)+1)+1)^4+8*(sqrt(sqrt(x+1)+1)+1)^3-8*(sqrt(sqrt(x+1)+1)+1)^2+2)),x)
// Time 0.25
1>>


Not only that, calling giac directly returns the result instantly. But using sagemath, I had to wait for more than 10 minutes for the result.

I build giac from source as well as sagemath. All on Linux Ubuntu.

Is this a bug? Or is it possible that sagemath now checks if the result returned back has "integrate" still in it, and in this case it echo back the original input instead of what was actually returned by the external CAS?

>which giac
/usr/local/bin/giac
>giac --version
// Maximum number of parallel threads 24
// (c) 2001, 2021 B. Parisse & others
1.9.0
>
>cd \$SAGE_ROOT
>cd local/bin
>ls -lrt giac
lrwxrwxrwx 1 me me 19 Apr 20 04:55 giac -> /usr/local/bin/giac
>


fyi, created ticket https://trac.sagemath.org/ticket/3374...

edit retag close merge delete

WorksForMe(TM) somehow on 9.6.rc1 :

sage: %time integrate((x^2-1)/(1+x)^(1/2)/(x^2+1)/(1+(1+x)^(1/2))^(1/2)/(1+(1+(1
....: +x)^(1/2))^(1/2))^(1/2),x, algorithm="giac")
CPU times: user 6.17 ms, sys: 216 µs, total: 6.38 ms
Wall time: 2.83 s
integrate((x^2 - 1)/((x^2 + 1)*sqrt(x + 1)*sqrt(sqrt(x + 1) + 1)*sqrt(sqrt(sqrt(x + 1) + 1) + 1)), x)
sage: giac.version()
"giac 1.7.0, (c) B. Parisse and R. De Graeve, Institut Fourier, Universite de Grenoble I"


That's system's (Debian testing's) giac. In note that ./configure rejects giac > 1.7.999. Yours is 1.9.0...

Neither giac sympy nor maxima can integrate this one and return it unevaluated ; fricas fails ; mathematica returns a solution that Sage's interface cannot (yet) translate.

HTH,

( 2022-04-21 12:40:01 +0200 )edit

But I am using giac 1.9.0 not 1.7.0. I do build sagemath with the default giac, which is 1.7.0, but to be able to use newer 1.9.0, I simply make a symlink. I do the same with Maxima, since sagemath uses old maxima, but a newer one exist which I've build and also made a symlink to. So there is a problem. If you could try with giac 1.9.0 in order to reproduce this. The question is not why it can't integrate it, I knew that, but why sagemath takes over 10 minutes while giac finishes instantly, and why sagemath return different output than what giac shows.

( 2022-04-21 18:44:27 +0200 )edit

I will confirm what @EmmanuelCharpentier says, which is that I cannot reproduce the 10 minutes that you report. When I use "%time ...", then the time reported is 1.4 seconds. It is possible that there is something somewhat broken in your giac interface, since you are using an unsupported version of giac with Sage.

( 2022-04-21 19:02:33 +0200 )edit

But the only reason I use sagemath is to call giac. Since giac that comes with sagemath is old, I make a symlink in order to use newer version of giac. This is what I always did when the version that comes with sagemath is out-of-date. Same with Maxima. Maxima now is at 5.46 version, which is newer than what sagemath builds. Otherwise, if I can't use newer versions of the external CAS systems, what is the point of using sagemath?

( 2022-04-21 19:13:28 +0200 )edit

You are of course free to change the version of giac, but (especially since the Sage build process rejects versions newer than 1.7.999) you should not be surprised if the result doesn't work perfectly. I think it would be good to work on upgrading the version of giac included with Sage, as well as the system versions of giacthat Sage will accept. See https://trac.sagemath.org/ticket/31563.

( 2022-04-21 19:55:40 +0200 )edit