Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integral computation with giac crashes giac #25822

Closed
sagetrac-tmonteil mannequin opened this issue Jul 11, 2018 · 24 comments
Closed

integral computation with giac crashes giac #25822

sagetrac-tmonteil mannequin opened this issue Jul 11, 2018 · 24 comments

Comments

@sagetrac-tmonteil
Copy link
Mannequin

sagetrac-tmonteil mannequin commented Jul 11, 2018

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);

Depends on #26315

Upstream: Fixed upstream, but not in a stable release.

CC: @frederichan-IMJPRG @sagetrac-parisse @slel

Component: symbolics

Keywords: giac, integrate, crash, pexpect

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

@sagetrac-tmonteil sagetrac-tmonteil mannequin added this to the sage-8.3 milestone Jul 11, 2018
@slel
Copy link
Member

slel commented Jul 11, 2018

Changed keywords from none to giac, integrate

@nasser1
Copy link

nasser1 commented Jul 11, 2018

comment:2

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: version()
'SageMath version 8.3.rc0, Release Date: 2018-07-08'
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: 

@sagetrac-parisse
Copy link
Mannequin

sagetrac-parisse mannequin commented Jul 12, 2018

comment:3

This is expected, if the output is too large.

@frederichan-IMJPRG
Copy link

comment:4

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*f*n*exp(1)-b*d*f*exp(1)*ln(c)+3*b*d*g*n*x*exp(1)*ln(d+x*exp(1))-b*d*g*n*x*exp(1)+3*b*d*g*x*exp(1)*ln(c)-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)+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)

@sagetrac-parisse
Copy link
Mannequin

sagetrac-parisse mannequin commented Jul 12, 2018

comment:5

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);

@slel
Copy link
Member

slel commented Jul 12, 2018

Changed upstream from Not yet reported upstream; Will do shortly. to Fixed upstream, but not in a stable release.

@slel
Copy link
Member

slel commented Jul 12, 2018

Changed keywords from giac, integrate to giac, integrate, crash, pexpect

@slel

This comment has been minimized.

@slel
Copy link
Member

slel commented Jul 12, 2018

comment:7

Replying to @frederichan-IMJPRG:

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:

@frederichan-IMJPRG
Copy link

comment:8

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;

@sagetrac-parisse
Copy link
Mannequin

sagetrac-parisse mannequin commented Jul 14, 2018

comment:9

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

@frederichan-IMJPRG
Copy link

comment:10

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

@nasser1
Copy link

nasser1 commented Jul 17, 2018

comment:11

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


@sagetrac-parisse
Copy link
Mannequin

sagetrac-parisse mannequin commented Jul 17, 2018

comment:12

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.

@dimpase
Copy link
Member

dimpase commented Jan 16, 2019

comment:13

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?

@dimpase dimpase modified the milestones: sage-8.3, sage-8.7 Jan 16, 2019
@mantepse
Copy link
Contributor

comment:15

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.)

@dimpase
Copy link
Member

dimpase commented Jan 16, 2019

comment:16

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

@dimpase dimpase removed this from the sage-8.7 milestone Jan 16, 2019
@mantepse
Copy link
Contributor

comment:17

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

@dimpase
Copy link
Member

dimpase commented Jan 16, 2019

comment:18

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.

@sagetrac-tmonteil
Copy link
Mannequin Author

sagetrac-tmonteil mannequin commented Jan 16, 2019

comment:19

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

@dimpase
Copy link
Member

dimpase commented Jan 16, 2019

comment:20

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...

@dimpase
Copy link
Member

dimpase commented Jan 16, 2019

Dependencies: #26315

@dimpase
Copy link
Member

dimpase commented Jan 16, 2019

comment:21

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

@embray
Copy link
Contributor

embray commented Feb 26, 2019

comment:22

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants