Opened 4 years ago

Closed 4 years ago

#25822 closed defect (invalid)

integral computation with giac crashes giac

Reported by: Thierry Monteil Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: symbolics Keywords: giac, integrate, crash, pexpect
Cc: Han Frederic, Bernard Parisse, Samuel Lelièvre Merged in:
Authors: Reviewers:
Report Upstream: Fixed upstream, but not in a stable release. Work issues:
Branch: Commit:
Dependencies: #26315 Stopgaps:

Status badges

Description (last modified by Samuel Lelièvre)

As reported on this Ask Sage question, Giac crashes on the following integral:

sage: print(version())
SageMath version 8.3.rc0, Release Date: 2018-07-08
sage: a, b, c, d, e, x = SR.var('a b c d e x')
sage: F = sqrt(d*x^2 + e*x + c)*sqrt((b*x^2 + a)^2)/x^4
sage: FF = integrate(F, x, algorithm='giac')
Giac crashed -- automatically restarting.
sage:

This is fixed upstream and will be part of the next stable version of Giac.

Another issue when using Giac for integration is the following:

sage: print(version())
SageMath version 8.3.rc0, Release Date: 2018-07-08
sage: a, b, c, d, e, f, g, n, x = SR.var('a b c d e f g n x')
sage: G = 1/((g*x + f)^2*(b*log((e*x + d)^n*c) + a)^3)
sage: GG = integrate(G, x, algorithm='giac')
sage: GG
Done
sage:

Quoting Frederic Han's comment (with minor edits):

this is a bug of the pexpect Giac interface that takes the string representation of the Giac output. The computation is done in Giac but when the output is large Giac just prints Done, and that is the string that the pxepect interface gets. It is not specific to integrate: it will concern all large Giac output.

Quoting Bernard Parisse's comment:

The maximal size of objects that will be printed should be controllable with the environment variable GIAC_TAILLEMAX (default 1000). Size is not the length of the printed string, but the size of the giac::gen as defined in symbolic.h:

unsigned taille(const gen & g,unsigned max);

Change History (22)

comment:1 Changed 4 years ago by Samuel Lelièvre

Cc: Han Frederic Bernard Parisse Samuel Lelièvre added
Keywords: giac integrate added

comment:2 Changed 4 years ago by Nasser

Here is another bug in GIAC/XCAS, may be it should be added to above? since it is also in integrate? I did not know if I should open a new one or not, since it is same system. Here it is. This is a bug in giac used by sagemath. It returns "done" as result of integrate.

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.3.rc0, Release Date: 2018-07-08                 │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

sage: var('x g b f n c a d');
sage: integrate(1/((g*x + f)^2*(b*log((e*x + d)^n*c) + a)^3),x, algorithm="giac")
Done
sage: 

Version 0, edited 4 years ago by Nasser (next)

comment:3 Changed 4 years ago by Bernard Parisse

This is expected, if the output is too large.

Last edited 4 years ago by Samuel Lelièvre (previous) (diff)

comment:4 Changed 4 years ago by Han Frederic

Indeed, this is a bug of the pexpect giac interface that takes the string representation of the giac output. The computation is done in giac but when the output is large giac just prints Done, and that is this string that the pxepect interface get. It is not typical for integrate it will concern all large output.

Bernard, is there a way to disable this in giac/icas or to obtain the string value of the computation?

Note that this problem doesn't appear in giacpy_sage (optionnal package)

sage: var('x g b f n c a d');
sage: F=(1/((g*x + f)^2*(b*log((e*x + d)^n*c) + a)^3))
sage: 
sage: integrate(F,x, algorithm="giac")
Done
sage: from giacpy_sage import libgiac
// Giac share root-directory:/home/fred-dev/sage/develop/sage.develop/local/share/giac/
// Giac share root-directory:/home/fred-dev/sage/develop/sage.develop/local/share/giac/
Help file /home/fred-dev/sage/develop/sage.develop/local/share/giac/doc/fr/aide_cas not found
Added 0 synonyms
sage: libgiac(F).integrate(x)
(2*a*d^2*g-a*d*f*exp(1)+3*a*d*g*x*exp(1)-a*f*x*exp(1)^2+a*g*x^2*exp(1)^2+2*b*d^2*g*n*ln(d+x*exp(1))+2*b*d^2*g*ln(c)-b*d*f*n*exp(1)*ln(d+x*exp(1))-b*d*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)^2*ln(d+x*exp(1))^2+4*b^4*g^3*n^3*x^3*exp(1)^2*ln(c)*ln(d+x*exp(1))+2*b^4*g^3*n^2*x^3*exp(1)^2*ln(c)^2)+integrate((-x^2*g^2*exp(1)^2+4*x*f*g*exp(1)^2-6*x*g^2*exp(1)*d-f^2*exp(1)^2+6*f*g*exp(1)*d-6*g^2*d^2)/(-2*ln(d+x*exp(1))*x^4*g^4*b^3*n^3*exp(1)^2-8*ln(d+x*exp(1))*x^3*f*g^3*b^3*n^3*exp(1)^2-12*ln(d+x*exp(1))*x^2*f^2*g^2*b^3*n^3*exp(1)^2-8*ln(d+x*exp(1))*x*f^3*g*b^3*n^3*exp(1)^2-2*ln(d+x*exp(1))*f^4*b^3*n^3*exp(1)^2-2*x^4*a*g^4*b^2*n^2*exp(1)^2-2*x^4*g^4*b^3*n^2*ln(c)*exp(1)^2-8*x^3*a*f*g^3*b^2*n^2*exp(1)^2-8*x^3*f*g^3*b^3*n^2*ln(c)*exp(1)^2-12*x^2*a*f^2*g^2*b^2*n^2*exp(1)^2-12*x^2*f^2*g^2*b^3*n^2*ln(c)*exp(1)^2-8*x*a*f^3*g*b^2*n^2*exp(1)^2-8*x*f^3*g*b^3*n^2*ln(c)*exp(1)^2-2*a*f^4*b^2*n^2*exp(1)^2-2*f^4*b^3*n^2*ln(c)*exp(1)^2),x)

comment:5 Changed 4 years ago by Bernard Parisse

The maximal size of objects that will be printed should be controllable with the environment variable GIAC_TAILLEMAX (default 1000). Size is not the length of the printed string, but the size of the giac::gen as defined in symbolic.h: unsigned taille(const gen & g,unsigned max);

comment:6 Changed 4 years ago by Samuel Lelièvre

Description: modified (diff)
Keywords: crash pexpect added
Report Upstream: Not yet reported upstream; Will do shortly.Fixed upstream, but not in a stable release.

comment:7 in reply to:  4 Changed 4 years ago by Samuel Lelièvre

Replying to frederichan:

Bernard, is there a way to disable this in giac/icas or to obtain the string value of the computation?

It seems we can ask Giac for the string representation using str.

At least in the web interface, it not return the shorter "Done" output:

comment:8 Changed 4 years ago by Han Frederic

But sage's pxepect interface is calling icas/giac so it is different than working with the library as does giacpy or the javascript interface. Adding string before evaluation will break manythings such as mulple commands, and after evaluation we will get the Done from icas.

So I think that the easiest thing is to change this in icas.cc, moreover there is already an "insage" booleen flag. I have test successfully the following patch.

Bernard, do you plan to remove the "Done" output in icas.cc when the insage flag is on so that next giac version will solve this without patch?

--- a/src/icas.cc	2017-10-02 10:25:46.000000000 +0200
+++ b/src/icas.cc	2018-07-14 10:50:01.650323754 +0200
@@ -1581,7 +1581,7 @@
 	int taillemax=1000;
 	if (getenv("GIAC_TAILLEMAX"))
 	  taillemax=atoi(getenv("GIAC_TAILLEMAX"));
-	string s=taille(ge,taillemax)>taillemax?"Done":ge.print(contextptr);
+	string s=((taille(ge,taillemax)>taillemax)&&(!insage))?"Done":ge.print(contextptr);
 	cout << s;
       }
       cout << endl;

comment:9 Changed 4 years ago by Bernard Parisse

Yes, I made the change in my source (with !insage first).

comment:10 Changed 4 years ago by Han Frederic

Thank you, so in sage the next giac update should solve these problems automatically.

comment:11 Changed 4 years ago by Nasser

fyi, this is similar giac crash. I tried to report it to giac, but could not get an account on giac tracking. I submitted request to join and never heard back. So posting it here. May be someone who knows how to report them to giac bugs database would be able to do this since I can't.

sage: version()
'SageMath version 8.3.rc0, Release Date: 2018-07-08

sage: var('d x c b a f e')
(d, x, c, b, a, f, e)
sage: integrate(sin((d*x + c)^(2/3)*b + a)/(f*x + e),x, algorithm="giac")
Giac crashed -- automatically restarting.
sage0*x


sage: integrate(sin((d*x + c)^(2/3)*b + a)/(f*x + e)^2,x,algorithm="giac")
Giac crashed -- automatically restarting.
sage4*x

sage:  integrate(sin(a + b/(d*x + c)^(2/3))/(f*x + e),x, algorithm="giac")
Giac crashed -- automatically restarting.
sage8*x

sage: integrate(sin(a + b/(d*x + c)^(2/3))/(f*x + e)^2,x, algorithm="giac")
Giac crashed -- automatically restarting.
sage12*x


comment:12 Changed 4 years ago by Bernard Parisse

Crash fixed in source. If you want to register in the Xcas forum, please choose a login or an email that can not be confused with a spammer, or send me a mail asking explicitly for activation.

comment:13 Changed 4 years ago by Dima Pasechnik

crash fixed by #26315. The 2nd integral is however not computed by giac 1.5.0-37, I get

sage: a, b, c, d, e, f, g, n, x = SR.var('a b c d e f g n x')
sage: G = 1/((g*x + f)^2*(b*log((e*x + d)^n*c) + a)^3)
sage: GG = integrate(G, x, algorithm='giac')
sage: GG
integrate(1/((g*x + f)^2*(b*log((e*x + d)^n*c) + a)^3), x)
sage: GG = integrate(G, x)
sage: GG
1/2*((a*e^2*g - (e^2*g*n - e^2*g*log(c))*b)*x^2 - (d*e*f - 2*d^2*g)*a - (d*e*f*n + (d*e*f - 2*d^2*g)*log(c))*b - ((e^2*f - 3*d*e*g)*a + (e^2*f*n + d*e*g*n + (e^2*f - 3*d*e*g)*log(c))*b)*x + (b*e^2*g*x^2 - (e^2*f - 3*d*e*g)*b*x - (d*e*f - 2*d^2*g)*b)*log((e*x + d)^n))/(b^4*e^2*f^3*n^2*log(c)^2 + 2*a*b^3*e^2*f^3*n^2*log(c) + a^2*b^2*e^2*f^3*n^2 + (b^4*e^2*g^3*n^2*log(c)^2 + 2*a*b^3*e^2*g^3*n^2*log(c) + a^2*b^2*e^2*g^3*n^2)*x^3 + 3*(b^4*e^2*f*g^2*n^2*log(c)^2 + 2*a*b^3*e^2*f*g^2*n^2*log(c) + a^2*b^2*e^2*f*g^2*n^2)*x^2 + (b^4*e^2*g^3*n^2*x^3 + 3*b^4*e^2*f*g^2*n^2*x^2 + 3*b^4*e^2*f^2*g*n^2*x + b^4*e^2*f^3*n^2)*log((e*x + d)^n)^2 + 3*(b^4*e^2*f^2*g*n^2*log(c)^2 + 2*a*b^3*e^2*f^2*g*n^2*log(c) + a^2*b^2*e^2*f^2*g*n^2)*x + 2*(b^4*e^2*f^3*n^2*log(c) + a*b^3*e^2*f^3*n^2 + (b^4*e^2*g^3*n^2*log(c) + a*b^3*e^2*g^3*n^2)*x^3 + 3*(b^4*e^2*f*g^2*n^2*log(c) + a*b^3*e^2*f*g^2*n^2)*x^2 + 3*(b^4*e^2*f^2*g*n^2*log(c) + a*b^3*e^2*f^2*g*n^2)*x)*log((e*x + d)^n)) + integrate(1/2*(e^2*g^2*x^2 + e^2*f^2 - 6*d*e*f*g + 6*d^2*g^2 - 2*(2*e^2*f*g - 3*d*e*g^2)*x)/(b^3*e^2*f^4*n^2*log(c) + a*b^2*e^2*f^4*n^2 + (b^3*e^2*g^4*n^2*log(c) + a*b^2*e^2*g^4*n^2)*x^4 + 4*(b^3*e^2*f*g^3*n^2*log(c) + a*b^2*e^2*f*g^3*n^2)*x^3 + 6*(b^3*e^2*f^2*g^2*n^2*log(c) + a*b^2*e^2*f^2*g^2*n^2)*x^2 + 4*(b^3*e^2*f^3*g*n^2*log(c) + a*b^2*e^2*f^3*g*n^2)*x + (b^3*e^2*g^4*n^2*x^4 + 4*b^3*e^2*f*g^3*n^2*x^3 + 6*b^3*e^2*f^2*g^2*n^2*x^2 + 4*b^3*e^2*f^3*g*n^2*x + b^3*e^2*f^4*n^2)*log((e*x + d)^n)), x)

It appears however that the latter integration (by maxima?) is not correct. Can this integral be computed in elementary functions?

comment:14 Changed 4 years ago by Dima Pasechnik

Milestone: sage-8.3sage-8.7
Status: newneeds_info

comment:15 in reply to:  13 Changed 4 years ago by Martin Rubey

Replying to dimpase:

crash fixed by #26315. The 2nd integral is however not computed by giac 1.5.0-37, I get

sage: a, b, c, d, e, f, g, n, x = SR.var('a b c d e f g n x')
sage: G = 1/((g*x + f)^2*(b*log((e*x + d)^n*c) + a)^3)

Can this integral be computed in elementary functions?

Very unlikely:

sage: a, b, c, d, e, f, g, n, x = SR.var('a b c d e f g n x')
sage: G = 1/((g*x + f)^2*(b*log((e*x + d)^n*c) + a)^3)
sage: G1 = G.subs(n=1, c=1, b=1, f=1, g=1, a=0, e=1); G1
1/((x + 1)^2*log(d + x)^3)
sage: integrate(G1, x, algorithm="fricas")
integral(1/((x^2 + 2*x + 1)*log(d + x)^3), x)

(I also tried a well known online tool.)

comment:16 Changed 4 years ago by Dima Pasechnik

Milestone: sage-8.7sage-duplicate/invalid/wontfix
Status: needs_infopositive_review

Yes, as integrate(G1, x) gives nonsense, this is yet another maxima bug. No problems with giac here, anyway, closing.

comment:17 in reply to:  16 ; Changed 4 years ago by Martin Rubey

Replying to dimpase:

Yes, as integrate(G1, x) gives nonsense, this is yet another maxima bug. No problems with giac here, anyway, closing.

No, the result is correct, it is just not very helpful:

sage: (diff(integrate(G1, x), x) - G1).simplify_full()
0

comment:18 in reply to:  17 Changed 4 years ago by Dima Pasechnik

Replying to mantepse:

Replying to dimpase:

Yes, as integrate(G1, x) gives nonsense, this is yet another maxima bug. No problems with giac here, anyway, closing.

No, the result is correct, it is just not very helpful:

sage: (diff(integrate(G1, x), x) - G1).simplify_full()
0

the result of the computation without fixing parameters seems to be incorrect, that's what I was trying to say.

Last edited 4 years ago by Dima Pasechnik (previous) (diff)

comment:19 Changed 4 years ago by Thierry Monteil

Milestone: sage-duplicate/invalid/wontfixsage-pending
Status: positive_reviewneeds_work

This is not fixed in 8.6, i still get the errors. This ticket should depend on #26315 and requires a dedicated doctest.

comment:20 Changed 4 years ago by Dima Pasechnik

Please add all the doctests you see fit on the branch of #26315 - I just don't see why we should test giac more than it tests itself...

comment:21 Changed 4 years ago by Dima Pasechnik

Dependencies: #26315
Milestone: sage-pendingsage-duplicate/invalid/wontfix
Status: needs_workpositive_review

no work should be done on this ticket, hence positive review.

comment:22 Changed 4 years ago by Erik Bray

Resolution: invalid
Status: positive_reviewclosed

Presuming these are all correctly reviewed as either duplicate, invalid, or wontfix.

Note: See TracTickets for help on using tickets.