sagemath / sage

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

Many integrals fail now using sagemath 9.2 using giac algorithm #31222

Open nasser1 opened 3 years ago

nasser1 commented 3 years ago

Edit: the root cause of the problem described here is very high sensitivity of giac to the form of the input to its integrator: e.g. different order of terms in a product to be integrated may lead to huge slowdowns/hands,cf Example 8, and Sage does rewriting of terms before passing them to an external integrator. Namely, if F is the original input then giac gets F._giac_init_(), which is often not exacly F, although equavalent to F. In this sense, passing a string to giac might be more robust.


Hello. I am working on a new build and new reports for the independent CAS integration tests https://www.12000.org/my_notes/CAS_integration_tests/index.htm.

Now using sagemath 9.2 on Linux to test thousands of integrals using fricas, maxima and giac among other CAS systems.

I found that hundreds of integrals now fail when using giac version 1.6, which all work on giac itself, and also which all worked using sagemath 8.9 using giac 1.5 which I did last year.

It fails either by now hanging or not evaluating. The ones that hang in sagemath, complete immediately in giac.

Since there so many integrals that now fail, I will only show few examples below. Hopefully the cause of the failure is the same for all. If not, I can provide more examples.

Example 1, do not evaluate any more

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.2, Release Date: 2020-10-24                     │
│ Using Python 3.8.6. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
sage: x,a = var('x a')
sage: integrate(sin(2*x)/(a^2-4*sin(x)^2)^(1/3),x, algorithm="giac")
integrate(sin(2*x)/(a^2 - 4*sin(x)^2)^(1/3), x)
sage: 

Using giac directly

>giac
// Using locale /usr/share/locale/
// en_US.utf8
// /usr/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 2
Help file /usr/share/giac/doc/en/aide_cas not found
Added 26 synonyms
Welcome to giac readline interface
(c) 2001,2020 B. Parisse & others
Homepage http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
Released under the GPL license 3.0 or above
See http://www.gnu.org for license details
May contain BSD licensed software parts (lapack, atlas, tinymt)
-------------------------------------------------
Press CTRL and D simultaneously to finish session
Type ?commandname for help
0>> integrate(sin(2*x)/(a^2-4*sin(x)^2)^(1/3),x)
-3/4*((a^2-2*(-2*cos(2*x)/2+1))^(1/3))^2/2
// Time 0.01
1>> 

Example 2. Hangs now in sagemath

sage: x,a,b = var('x a b')
sage: integrate(x^(5/2)/(b*x+a)^(5/2),x, algorithm="giac")

While in giac, completes right away

>> integrate(x^(5/2)/(b*x+a)^(5/2),x)
2*(2*((9*b^4*a*1/36/b^5/a*sqrt(x)*sqrt(x)+60*b^3*a^2*1/36/b^5/a)*sqrt(x)*sqrt(x)+45*b^2*a^3*1/36/b^5/a)*sqrt(x)*sqrt(a+b*x)/(a+b*x)^2+10*a/4/b^3/sqrt(b)*ln(abs(sqrt(a+b*x)-sqrt(b)*sqrt(x))))
// Time 0.02

Example 3, hangs


integrate(x^(3/2)/(b*x+a)^(5/2),x, algorithm="giac")

Using giac directly, it completes right away

14>> integrate(x^(3/2)/(b*x+a)^(5/2),x)
2*(2*(-12*b^2*a*1/18/b^3/a*sqrt(x)*sqrt(x)-9*b*a^2*1/18/b^3/a)*sqrt(x)*sqrt(a+b*x)/(a+b*x)^2-1/b^2/sqrt(b)*ln(abs(sqrt(a+b*x)-sqrt(b)*sqrt(x))))
// Time 0.03

Most of the ones that fail now looks like due to hang. But also some fail because the integral do not evaluate in sagemath, but it does using giac directly.

Version information

which giac
/bin/giac
>
>
>giac --version
// Using locale /usr/share/locale/
// en_US.utf8
// /usr/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 2
// (c) 2001, 2018 B. Parisse & others
1.6.0
>
>

>which sage
/bin/sage
>sage --version
SageMath version 9.2, Release Date: 2020-10-24
>

Linux Manjaro running inside Oracle Virtual Box

>uname -r
5.4.80-2-MANJARO
>uname -a
Linux me-virtualbox 5.4.80-2-MANJARO #1 SMP PREEMPT Sat Nov 28 09:58:18 UTC 2020 x86_64 GNU/Linux
>

>lsb_release -a
LSB Version:    n/a
Distributor ID: ManjaroLinux
Description:    Manjaro Linux
Release:    20.2
Codename:   Nibia

Because of this, I stopped the tests. And will wait for next version of sagemath, hopefully it have a fix for this, as giac result are now looking not good due to this.

Please feel free to add any fields for the ticket if needed. I filled the ones I know about.

Thank you, --Nasser

Adding more examples

EXAMPLE 4 (hangs in sagemath)

>giac
// Using locale /usr/share/locale/
// en_US.utf8
// /usr/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 2
Help file /usr/share/giac/doc/en/aide_cas not found
Added 26 synonyms
Welcome to giac readline interface
(c) 2001,2020 B. Parisse & others
Homepage http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
Released under the GPL license 3.0 or above
See http://www.gnu.org for license details
May contain BSD licensed software parts (lapack, atlas, tinymt)
-------------------------------------------------
Press CTRL and D simultaneously to finish session
Type ?commandname for help
0>> integrate(x*(b*x^2+a)*(B*x^2+A),x)
1/2*(1/3*x^6*b*B+1/2*x^4*b*A+1/2*x^4*a*B+x^2*a*A)
// Time 0

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.2, Release Date: 2020-10-24                     │
│ Using Python 3.8.6. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
sage: x,a,b,B,A = var('x a b B A')
sage: integrate(x*(b*x^2+a)*(B*x^2+A),x, algorithm="giac")

EXAMPLE 5 (hangs in sagemath)

GIAC:

3>> integrate(x^m*(b*x^2+a)^3*(B*x^2+A),x)
(A*a^3*m^4*x*exp(m*ln(x))+24*A*a^3*m^3*x*exp(m*ln(x))+206*A*a^3*m^2*x*exp(m*ln(x))+744*A*a^3*m*x*exp(m*ln(x))+945*A*a^3*x*exp(m*ln(x))+3*A*a^2*b*m^4*x^3*exp(m*ln(x))+66*A*a^2*b*m^3*x^3*exp(m*ln(x))+492*A*a^2*b*m^2*x^3*exp(m*ln(x))+1374*A*a^2*b*m*x^3*exp(m*ln(x))+945*A*a^2*b*x^3*exp(m*ln(x))+3*A*a*b^2*m^4*x^5*exp(m*ln(x))+60*A*a*b^2*m^3*x^5*exp(m*ln(x))+390*A*a*b^2*m^2*x^5*exp(m*ln(x))+900*A*a*b^2*m*x^5*exp(m*ln(x))+567*A*a*b^2*x^5*exp(m*ln(x))+A*b^3*m^4*x^7*exp(m*ln(x))+18*A*b^3*m^3*x^7*exp(m*ln(x))+104*A*b^3*m^2*x^7*exp(m*ln(x))+222*A*b^3*m*x^7*exp(m*ln(x))+135*A*b^3*x^7*exp(m*ln(x))+B*a^3*m^4*x^3*exp(m*ln(x))+22*B*a^3*m^3*x^3*exp(m*ln(x))+164*B*a^3*m^2*x^3*exp(m*ln(x))+458*B*a^3*m*x^3*exp(m*ln(x))+315*B*a^3*x^3*exp(m*ln(x))+3*B*a^2*b*m^4*x^5*exp(m*ln(x))+60*B*a^2*b*m^3*x^5*exp(m*ln(x))+390*B*a^2*b*m^2*x^5*exp(m*ln(x))+900*B*a^2*b*m*x^5*exp(m*ln(x))+567*B*a^2*b*x^5*exp(m*ln(x))+3*B*a*b^2*m^4*x^7*exp(m*ln(x))+54*B*a*b^2*m^3*x^7*exp(m*ln(x))+312*B*a*b^2*m^2*x^7*exp(m*ln(x))+666*B*a*b^2*m*x^7*exp(m*ln(x))+405*B*a*b^2*x^7*exp(m*ln(x))+B*b^3*m^4*x^9*exp(m*ln(x))+16*B*b^3*m^3*x^9*exp(m*ln(x))+86*B*b^3*m^2*x^9*exp(m*ln(x))+176*B*b^3*m*x^9*exp(m*ln(x))+105*B*b^3*x^9*exp(m*ln(x)))/(m^5+25*m^4+230*m^3+950*m^2+1689*m+945)
// Time 0.01
4>> 

SAGEMATH:

sage: x,a,b,B,A,m = var('x a b B A m')
sage: integrate(x^m*(b*x^2+a)^3*(B*x^2+A),x, algorithm="giac")

EXAMPLE 6 (hangs in sagemath)

GIAC:

4>> integrate(x^4*log(d*(c*x^2+b*x+a)^n),x)
(-2/25*n+1/5*ln(d))*x^5+b*n/(20*c)*x^4+(2*a*c*n-b^2*n)/(15*c^2)*x^3+(-3*a*b*c*n+b^3*n)/(10*c^3)*x^2+(-2*a^2*c^2*n+4*a*b^2*c*n-b^4*n)/(5*c^4)*x+1/5*n*x^5*ln(a+b*x+c*x^2)+integrate((x*n*b^5-5*x*n*b^3*c*a+5*x*n*b*c^2*a^2+n*b^4*a-4*n*b^2*c*a^2+2*n*c^2*a^3)/(5*x^2*c^5+5*x*b*c^4+5*c^4*a),x)
// Time 0.01
5>> 

SAGEMATH:

sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c')
sage: integrate(x^4*log(d*(c*x^2+b*x+a)^n),x, algorithm="giac")

EXAMPLE 7 (hangs in sagemath)


5>> integrate(x^3*log(d*(c*x^2+b*x+a)^n),x)
(-1/8*n+1/4*ln(d))*x^4+b*n/(12*c)*x^3+(2*a*c*n-b^2*n)/(8*c^2)*x^2+(-3*a*b*c*n+b^3*n)/(4*c^3)*x+1/4*n*x^4*ln(a+b*x+c*x^2)+integrate((-x*n*b^4+4*x*n*b^2*c*a-2*x*n*c^2*a^2-n*b^3*a+3*n*b*c*a^2)/(4*x^2*c^4+4*x*b*c^3+4*c^3*a),x)
// Time 0.02

sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c')
sage: integrate(x^3*log(d*(c*x^2+b*x+a)^n),x, algorithm="giac")

EXAMPLE 8 (hangs in sagemath)


0>> integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c)^3,x)
Done
// Time 0.01

sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c')
sage: integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c)^3,x, algorithm="giac")

EXAMPLE 9 (hangs in sagemath)


1>> integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c),x)
(-x^5*d*b^9-4*x^4*a*d*b^8-x^4*c*b^9-5*x^4*d*b^8-6*x^3*a^2*d*b^7-4*x^3*a*c*b^8-16*x^3*a*d*b^7-4*x^3*c*b^8-20*x^3*d*b^7-4*x^2*a^3*d*b^6-6*x^2*a^2*c*b^7-18*x^2*a^2*d*b^6-12*x^2*a*c*b^7-48*x^2*a*d*b^6-12*x^2*c*b^7-60*x^2*d*b^6-x*a^4*d*b^5-4*x*a^3*c*b^6-8*x*a^3*d*b^5-12*x*a^2*c*b^6-36*x*a^2*d*b^5-24*x*a*c*b^6-96*x*a*d*b^5-24*x*c*b^6-120*x*d*b^5-a^4*c*b^5-a^4*d*b^4-4*a^3*c*b^5-8*a^3*d*b^4-12*a^2*c*b^5-36*a^2*d*b^4-24*a*c*b^5-96*a*d*b^4-24*c*b^5-120*d*b^4)/b^6*exp(-(a+b*x))
// Time 0

sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c')
sage: integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c),x, algorithm="giac")

Upstream: Reported upstream. Developers acknowledge bug.

CC: @fchapoton @EmmanuelCharpentier @frederichan-IMJPRG @mwageringel @nasser1 @slel

Component: symbolics

Keywords: integrate, giac, interface

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

nasser1 commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,6 +1,6 @@
-Hello. I am woking on a new build and new reports for CAS integration tests [https://www.12000.org/my_notes/CAS_integration_tests/index.htm](https://www.12000.org/my_notes/CAS_integration_tests/index.htm). 
+Hello. I am working on a new build and new reports for the independent CAS integration tests [https://www.12000.org/my_notes/CAS_integration_tests/index.htm](https://www.12000.org/my_notes/CAS_integration_tests/index.htm). 

-Now using sagemath 9.2 on Linux to test thousands of integrals using fricas, maxima and giac among other CAS systems.
+Now using sagemath 9.2 on Linux to test thousands of integrals using fricas, maxima and giac among other CAS systems. 

 I found that hundreds of integrals now fail when using giac version 1.6, which all work on giac itself, and also which all worked using sagemath 8.9 using giac 1.5 which I did last year.
dimpase commented 3 years ago
comment:3

everything works in the current beta. I guess your Sage install is broken.

│ SageMath version 9.3.beta5, Release Date: 2020-12-27               │
│ Using Python 3.7.7. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: sage: x,a = var('x a')                                                                                                                                                                                                                                            
sage: sage: integrate(sin(2*x)/(a^2-4*sin(x)^2)^(1/3),x, algorithm="giac")                                                                                                                                                                                              
-3/8*(a^2 - 16*tan(1/2*x)^2/(tan(1/2*x)^2 + 1)^2)^(2/3)
sage:             
dimpase commented 3 years ago
comment:4

It looks like this is about Sage 9.2 installed, as a system package, on a particular Linux, what is Linux in question?

nasser1 commented 3 years ago
comment:5

version information for linux

>uname -a
Linux me-virtualbox 5.4.80-2-MANJARO #1 SMP PREEMPT Sat Nov 28 09:58:18 UTC 2020 x86_64 GNU/Linux
>uname -r
5.4.80-2-MANJARO

I installed 9.2 via Linux package manager and all was installed correctly. sagemath works fine.

dimpase commented 3 years ago
comment:6

your report indicates that Sage's interface with giac is broken in your installation.

edd8e884-f507-429a-b577-5d554626c0fe commented 3 years ago
comment:7

@dimpase could you please try the other examples ? On my computer (Sage 9.3.beta5, compiled by myself, Debian buster), the first example works, but not the other ones.

edd8e884-f507-429a-b577-5d554626c0fe commented 3 years ago
comment:8

@nasser1 if you have interesting examples, you should add them as doctests within Sage so that we could see regressions immediately.

fchapoton commented 3 years ago
comment:9

The second example seems to hand in giac 1.5 itself. Maybe giac 1.6 makes a difference.

DaveWitteMorris commented 3 years ago
comment:10

FWIW: My experience matches that of tmonteil in comment:7. This is with 9.3.beta5 on MacOS 10.15.7.

(The result for the 1st integral is the same as reported by dimpase in comment:3. It looks different from what is reported in the ticket description, but I believe the two expressions are equal, so that is not a problem.)

DaveWitteMorris commented 3 years ago
comment:11

@nasser1: Thanks for reporting this problem. It seems to be serious, but I hope it will have an easy solution.

It seems that you have translated the rubi tests to sagemath format. If so, would you be willing to share the zip file, perhaps as an attachment to this ticket?

nasser1 commented 3 years ago

Description changed:

--- 
+++ 
@@ -110,11 +110,21 @@
 SageMath version 9.2, Release Date: 2020-10-24
 >

->which sage
-/bin/sage
->sage --version
-SageMath version 9.2, Release Date: 2020-10-24
->
+Linux Manjaro running inside Oracle Virtual Box
+
+>uname -r
+5.4.80-2-MANJARO
+>uname -a
+Linux me-virtualbox 5.4.80-2-MANJARO #1 SMP PREEMPT Sat Nov 28 09:58:18 UTC 2020 x86_64 GNU/Linux
+>
+
+>lsb_release -a
+LSB Version:   n/a
+Distributor ID:    ManjaroLinux
+Description:   Manjaro Linux
+Release:   20.2
+Codename:  Nibia
+

@@ -126,3 +136,133 @@ Thank you, --Nasser

+Adding more examples + + +EXAMPLE 4 (hangs in sagemath) + + + +>giac +// Using locale /usr/share/locale/ +// en_US.utf8 +// /usr/share/locale/ +// giac +// UTF-8 +// Maximum number of parallel threads 2 +Help file /usr/share/giac/doc/en/aide_cas not found +Added 26 synonyms +Welcome to giac readline interface +(c) 2001,2020 B. Parisse & others +Homepage http://www-fourier.ujf-grenoble.fr/~parisse/giac.html +Released under the GPL license 3.0 or above +See http://www.gnu.org for license details +May contain BSD licensed software parts (lapack, atlas, tinymt) +------------------------------------------------- +Press CTRL and D simultaneously to finish session +Type ?commandname for help +0>> integrate(x*(b*x^2+a)*(B*x^2+A),x) +1/2*(1/3*x^6*b*B+1/2*x^4*b*A+1/2*x^4*a*B+x^2*a*A) +// Time 0 + + +>sage +┌────────────────────────────────────────────────────────────────────┐ +│ SageMath version 9.2, Release Date: 2020-10-24 │ +│ Using Python 3.8.6. Type "help()" for help. │ +└────────────────────────────────────────────────────────────────────┘ +sage: x,a,b,B,A = var('x a b B A') +sage: integrate(x*(b*x^2+a)*(B*x^2+A),x, algorithm="giac") + + + + + +EXAMPLE 5 (hangs in sagemath) + + + +GIAC: + +3>> integrate(x^m*(b*x^2+a)^3*(B*x^2+A),x) +(A*a^3*m^4*x*exp(m*ln(x))+24*A*a^3*m^3*x*exp(m*ln(x))+206*A*a^3*m^2*x*exp(m*ln(x))+744*A*a^3*m*x*exp(m*ln(x))+945*A*a^3*x*exp(m*ln(x))+3*A*a^2*b*m^4*x^3*exp(m*ln(x))+66*A*a^2*b*m^3*x^3*exp(m*ln(x))+492*A*a^2*b*m^2*x^3*exp(m*ln(x))+1374*A*a^2*b*m*x^3*exp(m*ln(x))+945*A*a^2*b*x^3*exp(m*ln(x))+3*A*a*b^2*m^4*x^5*exp(m*ln(x))+60*A*a*b^2*m^3*x^5*exp(m*ln(x))+390*A*a*b^2*m^2*x^5*exp(m*ln(x))+900*A*a*b^2*m*x^5*exp(m*ln(x))+567*A*a*b^2*x^5*exp(m*ln(x))+A*b^3*m^4*x^7*exp(m*ln(x))+18*A*b^3*m^3*x^7*exp(m*ln(x))+104*A*b^3*m^2*x^7*exp(m*ln(x))+222*A*b^3*m*x^7*exp(m*ln(x))+135*A*b^3*x^7*exp(m*ln(x))+B*a^3*m^4*x^3*exp(m*ln(x))+22*B*a^3*m^3*x^3*exp(m*ln(x))+164*B*a^3*m^2*x^3*exp(m*ln(x))+458*B*a^3*m*x^3*exp(m*ln(x))+315*B*a^3*x^3*exp(m*ln(x))+3*B*a^2*b*m^4*x^5*exp(m*ln(x))+60*B*a^2*b*m^3*x^5*exp(m*ln(x))+390*B*a^2*b*m^2*x^5*exp(m*ln(x))+900*B*a^2*b*m*x^5*exp(m*ln(x))+567*B*a^2*b*x^5*exp(m*ln(x))+3*B*a*b^2*m^4*x^7*exp(m*ln(x))+54*B*a*b^2*m^3*x^7*exp(m*ln(x))+312*B*a*b^2*m^2*x^7*exp(m*ln(x))+666*B*a*b^2*m*x^7*exp(m*ln(x))+405*B*a*b^2*x^7*exp(m*ln(x))+B*b^3*m^4*x^9*exp(m*ln(x))+16*B*b^3*m^3*x^9*exp(m*ln(x))+86*B*b^3*m^2*x^9*exp(m*ln(x))+176*B*b^3*m*x^9*exp(m*ln(x))+105*B*b^3*x^9*exp(m*ln(x)))/(m^5+25*m^4+230*m^3+950*m^2+1689*m+945) +// Time 0.01 +4>> + + +SAGEMATH: + +sage: x,a,b,B,A,m = var('x a b B A m') +sage: integrate(x^m*(b*x^2+a)^3*(B*x^2+A),x, algorithm="giac") + + + + + +EXAMPLE 6 (hangs in sagemath) + + + +GIAC: + +4>> integrate(x^4*log(d*(c*x^2+b*x+a)^n),x) +(-2/25*n+1/5*ln(d))*x^5+b*n/(20*c)*x^4+(2*a*c*n-b^2*n)/(15*c^2)*x^3+(-3*a*b*c*n+b^3*n)/(10*c^3)*x^2+(-2*a^2*c^2*n+4*a*b^2*c*n-b^4*n)/(5*c^4)*x+1/5*n*x^5*ln(a+b*x+c*x^2)+integrate((x*n*b^5-5*x*n*b^3*c*a+5*x*n*b*c^2*a^2+n*b^4*a-4*n*b^2*c*a^2+2*n*c^2*a^3)/(5*x^2*c^5+5*x*b*c^4+5*c^4*a),x) +// Time 0.01 +5>> + +SAGEMATH: + +sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c') +sage: integrate(x^4*log(d*(c*x^2+b*x+a)^n),x, algorithm="giac") + + + + +EXAMPLE 7 (hangs in sagemath) + + + + +5>> integrate(x^3*log(d*(c*x^2+b*x+a)^n),x) +(-1/8*n+1/4*ln(d))*x^4+b*n/(12*c)*x^3+(2*a*c*n-b^2*n)/(8*c^2)*x^2+(-3*a*b*c*n+b^3*n)/(4*c^3)*x+1/4*n*x^4*ln(a+b*x+c*x^2)+integrate((-x*n*b^4+4*x*n*b^2*c*a-2*x*n*c^2*a^2-n*b^3*a+3*n*b*c*a^2)/(4*x^2*c^4+4*x*b*c^3+4*c^3*a),x) +// Time 0.02 + +sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c') +sage: integrate(x^3*log(d*(c*x^2+b*x+a)^n),x, algorithm="giac") + + + + + +EXAMPLE 8 (hangs in sagemath) + + + + +0>> integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c)^3,x) +Done +// Time 0.01 + +sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c') +sage: integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c)^3,x, algorithm="giac") + + + + +EXAMPLE 9 (hangs in sagemath) + + + +1>> integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c),x) +(-x^5*d*b^9-4*x^4*a*d*b^8-x^4*c*b^9-5*x^4*d*b^8-6*x^3*a^2*d*b^7-4*x^3*a*c*b^8-16*x^3*a*d*b^7-4*x^3*c*b^8-20*x^3*d*b^7-4*x^2*a^3*d*b^6-6*x^2*a^2*c*b^7-18*x^2*a^2*d*b^6-12*x^2*a*c*b^7-48*x^2*a*d*b^6-12*x^2*c*b^7-60*x^2*d*b^6-x*a^4*d*b^5-4*x*a^3*c*b^6-8*x*a^3*d*b^5-12*x*a^2*c*b^6-36*x*a^2*d*b^5-24*x*a*c*b^6-96*x*a*d*b^5-24*x*c*b^6-120*x*d*b^5-a^4*c*b^5-a^4*d*b^4-4*a^3*c*b^5-8*a^3*d*b^4-12*a^2*c*b^5-36*a^2*d*b^4-24*a*c*b^5-96*a*d*b^4-24*c*b^5-120*d*b^4)/b^6*exp(-(a+b*x)) +// Time 0 + +sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c') +sage: integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c),x, algorithm="giac") + + + + + + +

nasser1 commented 3 years ago

Contains RUBI integration problems in sagemath synyax

nasser1 commented 3 years ago
comment:13

Attachment: SAGE.zip

Replying to @DaveWitteMorris:

@nasser1: Thanks for reporting this problem. It seems to be serious, but I hope it will have an easy solution.

It seems that you have translated the rubi tests to sagemath format. If so, would you be willing to share the zip file, perhaps as an attachment to this ticket?

I seem to have lost what I wrote here. WIll try again.

I attached zip file to the ticket. Each file in the zip file, say "Hebisch_Problems.sage" has first line as the var command, followed by lis which is a list that contains all the integrals for that specific test.

To run one file you could do

fileName = "Hebisch_Problems.sage"
load(fileName) #read the problems into variable lis. This also contains the var('') statement.
for problem in lst: #problem[0] is the integrand, problem[1] is the integration variable.
    integrate(SR(problem[0]),problem[1],algorithm="giac")

Each row in the list has as first field the integrand (as a string) and the second field is the integration variable.

Of you could simply copy the integral from the files and past it to sagemath.

Here is an example of one small complete file. There are about 200 files, some contains thousands of integrals. But they all have this format:

var('x ')
lst=[["(x^6-x^5+x^4-x^3+1)*exp(x)",x,25,"871*exp(x)-870*exp(x)*x+435*exp(x)*x^2-145*exp(x)*x^3+36*exp(x)*x^4-7*exp(x)*x^5+exp(x)*x^6"],
["(-x^2+2)*exp(x/(x^2+2))/(x^3+2*x)",x,-5,"Ei(x/(x^2+2))"],
["(2*x^4-x^3+3*x^2+2*x+2)*exp(x/(x^2+2))/(x^3+2*x)",x,-5,"exp(x/(x^2+2))*(x^2+2)+Ei(x/(x^2+2))"],
["(1+exp(x))*exp(x+exp(x))/(x+exp(x))",x,2,"Ei(x+exp(x))"],
["(x^3-x^2-3*x+1)*exp(1/(x^2-1))/(x^3-x^2-x+1)",x,-6,"exp(1/(x^2-1))*(1+x)"],
["exp(1+1/log(x))*(-1+log(x)^2)/log(x)^2",x,1,"exp(1+1/log(x))*x"],
["exp(x+1/log(x))*(-1+(1+x)*log(x)^2)/log(x)^2",x,-2,"exp(x+1/log(x))*x"]]

--Nasser

DaveWitteMorris commented 3 years ago
comment:14

Replying to @nasser1:

I attached zip file to the ticket...

Thanks! Your instructions were very clear, so I had no problem running some tests (until I ran into one that hangs). As suggested by tmonteil in comment:8, I think a bunch of these should be added to the testing framework after this bug is cleared up.

dimpase commented 3 years ago
comment:15

Replying to @sagetrac-tmonteil:

@dimpase could you please try the other examples ? On my computer (Sage 9.3.beta5, compiled by myself, Debian buster), the first example works, but not the other ones.

oops, indeed, while the 1st example works for me, the 2nd one hangs. Sorry for noise.

dimpase commented 3 years ago
comment:16

Something silly is happening where the expression to pass to giac is formed. I've added

--- a/src/sage/interfaces/giac.py
+++ b/src/sage/interfaces/giac.py
@@ -1154,6 +1154,9 @@ class GiacElement(ExpectElement):
             sage: x,y=giac('x'),giac('y');integrate(cos(x+y),'x=0..pi').simplify()
             -2*sin(y)
         """
+        print(self.name())
+        print(self)
+        print(var)
         if min is None:
             return giac('int(%s,%s)' % (self.name(), var))
         else:

and as you see, the expression is malformed, e.g. there is no terminating ) so giac just waits for the end of the expression, which never comes, thus the hang.

sage: sage: x,a,b = var('x a b') 
....: sage: integrate((x/(b*x+a))^(5/2),x, algorithm="giac")                                                                                                                                                                                                                      
sage4
sqrt((b*x+a)^-1*x)*((b*x+a)^-1*x)^2
x
^CInterrupting Giac...
dimpase commented 3 years ago
comment:17

and here is the malformed giac input for Example 2 as given in the ticket description

sage: sage: x,a,b = var('x a b') 
....: sage: integrate(x^(5/2)/(b*x+a)^(5/2),x, algorithm="giac")                                                                                                                                                                                                                  
sage0
(sqrt(b*x+a))^-1*(b*x+a)^-2*sqrt(x)*x^2
x
^CInterrupting Giac...

somebody has damaged handling of non-integer exponents (for giac only?) since Sage 8.9, it seems.

dimpase commented 3 years ago
comment:18

On the other hand, integrate(x<sup>(5/2)/(b*x+a)</sup>(5/2),x, algorithm="fricas") works, which gives hope that the bug is specific to giac interface.

fchapoton commented 3 years ago
comment:19

sorry, but where do you see a missing parenthesis ? The following works fine:

sage: x,a,b = var('x a b')                                                      
sage: F=(x/(b*x+a))^(5/2)                                                       
sage: F._fricas_init_() == F._giac_init_()                                      
True
sage: giac(F).diff()                                                            
1/2*(-b*(b*x+a)^-2*x+(b*x+a)^-1)*(sqrt((b*x+a)^-1*x))^-1*((b*x+a)^-1*x)^2+2*sqrt((b*x+a)^-1*x)*(-b*(b*x+a)^-2*x+(b*x+a)^-1)*(b*x+a)^-1*x
sage: giac(F).sage()                                                            
x^2*sqrt(x/(b*x + a))/(b*x + a)^2
dimpase commented 3 years ago
comment:20

Replying to @fchapoton:

sorry, but where do you see a missing parenthesis ? The following works fine:

sage: x,a,b = var('x a b')                                                      
sage: F=(x/(b*x+a))^(5/2)                                                       
sage: F._fricas_init_() == F._giac_init_()                                      
True
sage: giac(F).diff()                                                            
1/2*(-b*(b*x+a)^-2*x+(b*x+a)^-1)*(sqrt((b*x+a)^-1*x))^-1*((b*x+a)^-1*x)^2+2*sqrt((b*x+a)^-1*x)*(-b*(b*x+a)^-2*x+(b*x+a)^-1)*(b*x+a)^-1*x
sage: giac(F).sage()                                                            
x^2*sqrt(x/(b*x + a))/(b*x + a)^2

see the output of the debugging print I inserted:

sage: integral(F,x,algorithm="giac")                                                                                                                                                                                                                                              
sage0
sqrt((b*x+a)^-1*x)*((b*x+a)^-1*x)^2
x

there is an attempted conversion to an expression involving sqrt(), but it does not go through!

Where the hell this is happening in the code, I don't know.

dimpase commented 3 years ago
comment:21

once again: sqrt((b*x+a)<sup>-1*x)*((b*x+a)</sup>-1*x)^2 is what's being passed to giac, and of course this does not fly.

dimpase commented 3 years ago
comment:22

Here it is, in another way:

sage: F._giac_()                                                                                                                                                                                                                                                                  
sqrt((b*x+a)^-1*x)*((b*x+a)^-1*x)^2

I don't know where this is happening, but it is obviously very wrong.

by the way

sage: F._fricas_()                                                                                                                                                                                                                                                                
       +-------+
     2 |   x
    x  |-------
      \|b x + a
-------------------
 2 2              2
b x  + 2 a b x + a
frederichan-IMJPRG commented 3 years ago
comment:23

There is indeed a filter between Expression and giac used to convert some keywords so giac(F) may not be the same as giac(str(F)) I guess it is in sage.symbolic.expression_conversions

fchapoton commented 3 years ago
comment:24

Replying to @dimpase:

once again: sqrt((b*x+a)<sup>-1*x)*((b*x+a)</sup>-1*x)^2 is what's being passed to giac, and of course this does not fly.

No, I do not think so. This is what giac is printing. What giac gets is the string given by _giac_init_, which is fine.

dimpase commented 3 years ago
comment:25

Replying to @fchapoton:

Replying to @dimpase:

once again: sqrt((b*x+a)<sup>-1*x)*((b*x+a)</sup>-1*x)^2 is what's being passed to giac, and of course this does not fly.

No, I do not think so. This is what giac is printing. What giac gets is the string given by _giac_init_, which is fine.

"passing" means "what giac tries to integrate". IMHO it is what Sage prepares to pass to giac, giac is not yet involved at this point.

giac is perfectly capable to take this _giac_init_ and integrate it.

dimpase commented 3 years ago
comment:26

meanwhile I looked at Example 8. The trouble there is that giac is highly sensitive to the expression format; we shuffle the terms around, and all of a sudden it has trouble integrating the expression.

0>> integrate((b*x+a)^4*(d*x+c)^3*exp(-b*x-a),x)
^CCtrl-C pressed (pid 21354)
Stopped by user interruption. Error: Bad Argument Value

Evaluation time: 50.4
"Stopped by user interruption. Error: Bad Argument Value"
// Time 50.4
1>> integrate(exp(-b*x-a)*(b*x+a)^4*(d*x+c)^3,x)
Done

and the first of these forms is what you get by doing

sage: F=exp(-b*x-a)*(b*x+a)^4*(d*x+c)^3
sage: F._giac_()

so that's why this particular example is stuck in Sage.

So it's more of a giac problem/bug for this example.

dimpase commented 3 years ago
comment:27

Oops, sorry, you're right, Example 2 is more of a giac problem, too (I took that _giac_init_() form):

0>> integrate((((((b)*(x))+(a))^(-1))*(x))^(5/2),x)
Warning, integration of abs or sign assumes constant sign by intervals (correct if the argument is real):
Check [abs(b*x+a)]
^CCtrl-C pressed (pid 32350)
dimpase commented 3 years ago
comment:28

Upstream notified in https://xcas.univ-grenoble-alpes.fr/forum/viewtopic.php?f=3&t=2600

dimpase commented 3 years ago

Upstream: Reported upstream. No feedback yet.

dimpase commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,3 +1,13 @@
+*Edit*: the root cause of the problem described here is very high 
+sensitivity of giac to the form of the input to its integrator: e.g.
+different order of terms in a product to be integrated may lead to 
+huge slowdowns/hands,cf Example 8.
+- and Sage does rewriting of terms before passing them to an
+external integrator. Namely, if `F` is the original input then giac
+gets `F._giac_init_()`, which is often not exacly `F`, although equavalent to `F`. In this sense, passing a string to giac might be more robust.
+
+---
+
 Hello. I am working on a new build and new reports for the independent CAS integration tests [https://www.12000.org/my_notes/CAS_integration_tests/index.htm](https://www.12000.org/my_notes/CAS_integration_tests/index.htm). 

 Now using sagemath 9.2 on Linux to test thousands of integrals using fricas, maxima and giac among other CAS systems. 
dimpase commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,8 +1,7 @@
 *Edit*: the root cause of the problem described here is very high 
 sensitivity of giac to the form of the input to its integrator: e.g.
 different order of terms in a product to be integrated may lead to 
-huge slowdowns/hands,cf Example 8.
-- and Sage does rewriting of terms before passing them to an
+huge slowdowns/hands,cf Example 8, and Sage does rewriting of terms before passing them to an
 external integrator. Namely, if `F` is the original input then giac
 gets `F._giac_init_()`, which is often not exacly `F`, although equavalent to `F`. In this sense, passing a string to giac might be more robust.
dimpase commented 3 years ago
comment:31

Replying to @DaveWitteMorris:

@nasser1: Thanks for reporting this problem. It seems to be serious, but I hope it will have an easy solution.

An easy solution, making sure that giac called from Sage does exactly the same as giac called stanadlone, is to bypass rewriting done by Sage, by using giac.eval(). E.g.

sage: x,a,b,B,A,m,n,d,c = var('x a b B A m n d c')                                                                                                                                           
sage: F='exp(-b*x-a)*(b*x+a)^4*(d*x+c)^3'                                                                                                                                                    
sage: giac.eval(F+',x')                                                                                                                                                                      
'exp(-b*x-a)*(b*x+a)^4*(d*x+c)^3,x'
sage: giac.eval('integrate('+F+',x)')                                                                                                                                                        
'(-x^7*d^3*b^11-4*x^6*...'

So you pass giac a string and get a string back. One can convert strings to Sage's symbolic expressions then, by calling SR().

dimpase commented 3 years ago
comment:32

the problem of Ex.8 has been fixed upstream: https://dev.geogebra.org/trac/changeset/69729/

dimpase commented 3 years ago

Changed upstream from Reported upstream. No feedback yet. to Reported upstream. Developers acknowledge bug.

mkoeppe commented 3 years ago
comment:33

Moving this ticket to 9.4, as it seems unlikely that it will be merged in 9.3, which is in the release candidate stage

slel commented 3 years ago
comment:34

Examples 2, 3, 5, 6, 7 have ln in Giac's output. Emmanuel Charpentier's answer to

points to the absence of conversion from Giac's ln to Sage's log being a problem.

sheerluck commented 3 years ago
comment:35

no example [1..9] hangs anymore:

https://asciinema.org/a/kPLdynWBPFraIDEJLvHOKP7xq

try it yourself with https://github.com/sheerluck/ticket-31222