Ask Your Question
3

integrate results that are different from using maxima

asked 2018-07-21 02:40:43 +0100

Nasser gravatar image

updated 2023-01-09 23:59:46 +0100

tmonteil gravatar image

Update

Thanks to comment below by @rburing, it turned out to be the following setting load(abs_integrate) which sagemath is applying before calling Maxima that is causing this problem.

Maxima 5.41.0 http://maxima.sourceforge.net using Lisp ECL 16.1.2

 (%i1)  domain:complex;
(%o1)                               complex

(%i2) display2d : false;

(%o2) false

(%i3) integrate (x*sqrt (cos (b*x + a)), x);

(%o3) 'integrate(x*sqrt(cos(b*x+a)),x)

(%i4) load(abs_integrate);
ARRSTORE: use_fast_arrays=false; allocate a new property hash table for $INTABLE2
(%o4) "/usr/share/maxima/5.41.0/share/contrib/integration/abs_integrate.mac"

(%i5) integrate (x*sqrt (cos (b*x + a)), x);

(%o5) (((1260*(b*x+a)*sin((5*(b*x+a))/2)+504*cos((5*(b*x+a))/2)
                                        +2100*(b*x+a)*sin((3*(b*x+a))/2)
                                        +1400*cos((3*(b*x+a))/2))
 *false
 -225*sin((7*(b*x+a))/2)+315*sin((5*(b*x+a))/2)+525*sin((3*(b*x+a))/2)
 -1575*sin((b*x+a)/2))
 /(1575*2^(5/2))
 -(a*((6*sin((5*(b*x+a))/2)+10*sin((3*(b*x+a))/2))*false
     -5*sin((3*(b*x+a))/2)+15*sin((b*x+a)/2)))
  /(15*2^(3/2)))
 /b^2
(%i6)

Therefore the question now becomes this: How could one tell Maxima, from inside SageMath to reverse the effect of the command load(abs_integrate), since this is causing wrong antiderivatives to be generated in these cases. And what is the reason SageMath selected to set these settings before calling Maxima?

Or is there a way a user can control these settings that SageMath is issuing under the cover before using Maxima integrate?

ps. I do not know where the word false came from in the above antiderivative. This seems like a bug in Maxima, as it does not show in SageMath result.

Original question

Hello;

I was going to make a bug entry on this, but thought to first check with the experts here, as I have a feeling I am missing something basic or making some mistake as I am newbie in SageMath and Maxima as well.

I am getting number of wrong antiderivatives from Sagemath intergate, using default algorithm (which should be Maxima), compared to using Maxima itself for same integral.

Using Maxima (and making sure to set domain to complex first), Maxima returns unevaluated for the same command, which is actually is the correct result, since these integrals are supposed to be non integrable and meant to test to see if CAS can determine this. However, sagemath, does return an antiderivative from Maxima.

Could someone please explain how sagemath managed to return such results, and from where it obtained it since Maxima itself does not return this result? In addition, I verified the SageMath result, and they all fail the verification I did.

Here are few examples of many I have:

Example 1

SageMath version 8.3.rc1, Release Date: 2018-07-14

sage: var('x e a b f c d m');
sage: integrate ((d*sin (f*x + e) + c)^(3/2)*(b*sin (f*x + e) + a)^m, x)
1/9*(c^3*sin(9/2*f*x + 9/2*e) - 3*c^3*sin(3/2*f*x + 3/2*e))*2^(-m - 5/2)/f

The above is clearly wrong, since the anti dropped/missing the parameters d,a,b in the integrand.

in Maxima

Maxima 5.41.0 http://maxima.sourceforge.net
using Lisp ECL 16.1.2

(%i1) domain:complex$    
(%i2) domain;
(%o2)                               complex

(%i3) integrate ((d*sin (f*x + e) + c)^(3/2)*(b*sin (f*x + e) + a)^m, x);
              /
              [                     m                     3/2
(%o3)         I (b sin(f x + e) + a)  (d sin(f x + e) + c)    dx
              ]
              /

Example 2

sage: integrate(sqrt(d*sin (f*x + e) + c)*(b*sin (f*x + e) + a)^m, x,algorithm="maxima")
1/3*(c*sin(3/2*f*x + 3/2*e) - 3*c*sin(1/2*f*x + 1/2*e))*2^(-m - 3/2)/f

The above is clearly wrong, since the anti dropped/missing the parameters d,a,b in the integrand.

Using Maxima

(%i7) integrate (sqrt (d*sin (f*x + e) + c)*(b*sin (f*x + e) + a)^m, x);
              /
              [                     m
(%o7)         I (b sin(f x + e) + a)  sqrt(d sin(f x + e) + c) dx
              ]
              /

The above is the correct result, since this integral is supposed to be non integrable.

Example 3

sage: integrate (x*sqrt (cos (b*x + a)), x,algorithm="maxima")
1/840*(70*sqrt(2)*a*(sin(3/2*b*x + 3/2*a) - 3*sin(1/2*b*x + 1/2*a)) - sqrt(2)*(15*sin(7/2*b*x + 7/2*a) - 21*sin(5/2*b*x + 5/2*a) - 35*sin(3/2*b*x + 3/2*a) + 105*sin(1/2*b*x + 1/2*a)))/b^2

The above result did not verify by differentiating the antiderivative.

Using Maxima

(%i9) integrate (x*sqrt (cos (b*x + a)), x);                 
                           /
                           [
(%o9)                      I x sqrt(cos(b x + a)) dx
                           ]
                           /

The above is the correct result, since this integral is supposed to be non integrable.

example 4

sage: integrate(x*cos(b*x + a)^(3/2), x, algorithm="maxima")
1/349920*(243*sqrt(2)*a*(3*sin(15/2*b*x + 15/2*a) + 5*sin(9/2*b*x + 9/2*a) - 30*sin(3/2*b*x + 3/2*a)) - 20*sqrt(2)*(2*(81*(b*x + a)^2 - 8)*cos(9/2*b*x + 9/2*a) - 162*(9*(b*x + a)^2 - 8)*cos(3/2*b*x + 3/2*a) + 9*(27*(b*x + a)^3 - 8*b*x - 8*a)*sin(9/2*b*x + 9/2*a) - 243*(3*(b*x + a)^3 - 8*b*x - 8*a)*sin(3/2*b*x + 3/2*a)))/b^2

The above result did not verify by differentiating the antiderivative.

Using Maxima

(%i10) integrate(x*cos(b*x + a)^(3/2), x);
                            /
                            [               3/2
(%o10)                      I x cos(b x + a)    dx
                            ]
                            /

The above is the correct result, since this integral is supposed to be non integrable.

Example 5

sage: integrate(cos (x)^(3/2)/x^3, x, algorithm="maxima")
-9/512*sqrt(2)*(25*gamma(-2, 15/2*I*x) + 9*gamma(-2, 9/2*I*x) - 2*gamma(-2, 3/2*I*x) - 2*gamma(-2, -3/2*I*x) + 9*gamma(-2, -9/2*I*x) + 25*gamma(-2, -15/2*I*x))

The above result did not verify by differentiating the antiderivative.

Maxima:

(%i11) integrate (cos (x)^(3/2)/x^3, x);
                                /       3/2
                                [ cos(x)
(%o11)                          I --------- dx
                                ]     3
                                /    x

The above is the correct result, since this integral is supposed to be non integrable.

Example 6

sage: integrate(cos(d*x + c)^(7/3)/sqrt(b*cos(d*x + c) + a), x,algorithm="maxima")
1/6366178138320*2^(1/6)*(61213251330*cos(13/2*d*x + 13/2*c) - 72342933390*cos(11/2*d*x + 11/2*c) - 82321269030*cos(29/6*d*x + 29/6*c) + 140430400110*cos(17/6*d*x + 17/6*c) - 217028800170*cos(11/6*d*x + 11/6*c) - 341045257410*cos(7/6*d*x + 7/6*c) + 23405066685*sin(17/2*d*x + 17/2*c) - 26525742243*sin(15/2*d*x + 15/2*c) - 29113619535*sin(41/6*d*x + 41/6*c) + 41160634515*sin(29/6*d*x + 29/6*c) - 44209570405*sin(9/2*d*x + 9/2*c) - 51898191345*sin(23/6*d*x + 23/6*c) + 56840876235*sin(7/2*d*x + 7/2*c) - 62824126365*sin(19/6*d*x + 19/6*c) + 70215200055*sin(17/6*d*x + 17/6*c) + 1193658400935*sin(1/6*d*x + 1/6*c))/(a*d)

The above result did not verify by differentiating the antiderivative.

Maxima:

(%i12) integrate (cos (d*x + c)^(7/3)/sqrt (b*cos (d*x + c) + a), x);
                         /                 7/3
                         [     cos(d x + c)
(%o12)                   I ------------------------ dx
                         ] sqrt(b cos(d x + c) + a)
                         /

The above is the correct result, since this integral is supposed to be non integrable.

Example 7

sage: integrate(cos(d*x + c)^(2/3)/sqrt(b*cos(d*x + c) + a), x,algorithm="maxima")
-1/54264*2^(5/6)*(1071*cos(19/6*d*x + 19/6*c) + 1197*cos(17/6*d*x + 17/6*c) - 2261*cos(3/2*d*x + 3/2*c) - 2907*cos(7/6*d*x + 7/6*c) + 6783*cos(1/2*d*x + 1/2*c) + 20349*cos(1/6*d*x + 1/6*c))/(a*d)

The above result did not verify by differentiating the antiderivative.

Maxima:

(%i13) integrate (cos (d*x + c)^(2/3)/sqrt (b*cos (d*x + c) + a), x);
                         /                 2/3
                         [     cos(d x + c)
(%o13)                   I ------------------------ dx
                         ] sqrt(b cos(d x + c) + a)
                         /

The above is the correct result, since this integral is supposed to be non integrable.

Example 8

sage: var('B A f x e b a c m')
(B, A, f, x, e, b, a, c, m)

sage: integrate((B*cos(f*x+e)+A)*(b*cos(f*x+e)+a)^(3/2)*(c*cos(f*x+e))^m,x)
1/3465*(385*(a^3*c^m*sin(9/2*f*x + 9/2*e) - 3*a^3*c^m*sin(3/2*f*x + 3/2*e))*2^(-m - 5/2)*A + 4*(231*a^3*sin(15/2*f*x + 15/2*e) + 630*a^3*sin(11/2*f*x + 11/2*e) - 770*a^3*sin(9/2*f*x + 9/2*e) + 495*a^3*sin(7/2*f*x + 7/2*e) - 2079*a^3*sin(5/2*f*x + 5/2*e) + 1155*a^3*sin(3/2*f*x + 3/2*e))*2^(-m - 13/2)*B)/f

The above result did not verify by differentiating the antiderivative.

Maxima:

(%i15) integrate((B*cos(f*x+e)+A)*(b*cos(f*x+e)+a)^(3/2)*(c*cos(f*x+e))^m,x);
       /
       [                 m                                          3/2
(%o15) I (c cos(f x + e))  (B cos(f x + e) + A) (b cos(f x + e) + a)    dx
       ]
       /

The above is the correct result, since this integral is supposed to be non integrable.

Example 9

sage: integrate((B*cos(f*x+e)+A)*sqrt(b*cos(f*x+e)+a)*(c*cos(f*x+e))^m,x)
1/315*(105*(a*c^m*sin(3/2*f*x + 3/2*e) - 3*a*c^m*sin(1/2*f*x + 1/2*e))*2^(-m - 3/2)*A + (35*a*sin(9/2*f*x + 9/2*e) - 90*a*sin(7/2*f*x + 7/2*e) + 189*a*sin(5/2*f*x + 5/2*e) - 315*a*sin(3/2*f*x + 3/2*e) + 315*a*sin(1/2*f*x + 1/2*e))*2^(-m - 7/2)*B)/f

The above result did not verify by differentiating the antiderivative.

Maxima:

(%i16) integrate((B*cos(f*x+e)+A)*sqrt(b*cos(f*x+e)+a)*(c*cos(f*x+e))^m,x);
       /
       [                 m
(%o16) I (c cos(f x + e))  (B cos(f x + e) + A) sqrt(b cos(f x + e) + a) dx
       ]
       /

The above is the correct result, since this integral is supposed to be non integrable.

Example 10

sage: integrate((B*cos(f*x+e)+A)*(b*cos(f*x+e)+a)^(3/2)*(c*sec(f*x+e))^m,x)
-1/2520*sqrt(2)*(35*2^m*A^3*a*sin(9/2*f*x + 9/2*e) + 630*(A^3*B - A^3*a)*2^m*log(cos(1/2*f*x + 1/2*e)^2 + sin(1/2*f*x + 1/2*e)^2 + 2*sin(1/2*f*x + 1/2*e) + 1) - 630*(A^3*B - A^3*a)*2^m*log(cos(1/2*f*x + 1/2*e)^2 + sin(1/2*f*x + 1/2*e)^2 - 2*sin(1/2*f*x + 1/2*e) + 1) + 45*(2*A^3*B - A^3*a)*2^m*sin(7/2*f*x + 7/2*e) - 63*(2*A^3*B - 3*A^3*a)*2^m*sin(5/2*f*x + 5/2*e) + 105*(4*A^3*B - 5*A^3*a)*2^m*sin(3/2*f*x + 3/2*e) - 630*(4*A^3*B - 3*A^3*a)*2^m*sin(1/2*f*x + 1/2*e))/f

The above result did not verify by differentiating the antiderivative.

Maxima:

(%i17) integrate((B*cos(f*x+e)+A)*(b*cos(f*x+e)+a)^(3/2)*(c*sec(f*x+e))^m,x);
       /
       [                                          3/2                 m
(%o17) I (B cos(f x + e) + A) (b cos(f x + e) + a)    (c sec(f x + e))  dx
       ]
       /

The above is the correct result, since this integral is supposed to be non integrable.

Example 11

sage: integrate((B*cos(f*x+e)+A)*sqrt(b*cos(f*x+e)+a)*(c*sec(f*x+e))^m,x)
1/40*(20*sqrt(2)*(2^m*a*c^m*log(cos(1/2*f*x + 1/2*e)^2 + sin(1/2*f*x + 1/2*e)^2 + 2*sin(1/2*f*x + 1/2*e) + 1) - 2^m*a*c^m*log(cos(1/2*f*x + 1/2*e)^2 + sin(1/2*f*x + 1/2*e)^2 - 2*sin(1/2*f*x + 1/2*e) + 1) - 2^(m + 1)*a*c^m*sin(1/2*f*x + 1/2*e))*A + sqrt(2)*(5*2^(m + 2)*a*log(cos(1/2*f*x + 1/2*e)^2 + sin(1/2*f*x + 1/2*e)^2 + 2*sin(1/2*f*x + 1/2*e) + 1) - 5*2^(m + 2)*a*log(cos(1/2*f*x + 1/2*e)^2 + sin(1/2*f*x + 1/2*e)^2 - 2*sin(1/2*f*x + 1/2*e) + 1) - 2^(m + 1)*a*sin(5/2*f*x + 5/2*e) + 5*2^(m + 1)*a*sin(3/2*f*x + 3/2*e) - 15*2^(m + 2)*a*sin(1/2*f*x + 1/2*e))*B)/f

The above result did not verify by differentiating the antiderivative.

Maxima:

(%i18) integrate((B*cos(f*x+e)+A)*sqrt(b*cos(f*x+e)+a)*(c*sec(f*x+e))^m,x);
       /
       [                                                               m
(%o18) I (B cos(f x + e) + A) sqrt(b cos(f x + e) + a) (c sec(f x + e))  dx
       ]
       /

The above is the correct result, since this integral is supposed to be non integrable.

edit retag flag offensive close merge delete

Comments

1

Sage sets some Maxima settings before passing integrate (or any) calls to Maxima, e.g.

init_code = ['besselexpand : true', 'display2d : false', 'domain : complex', 'keepfloat : true', 'load(to_poly_solve)', 'load(simplify_sum)', 'load(abs_integrate)', 'load(diag)']

This could account for the discrepancy.

rburing gravatar imagerburing ( 2018-07-22 08:21:23 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2018-07-22 14:04:25 +0100

rburing gravatar image

updated 2018-07-22 15:46:43 +0100

It seems Maxima's abs_integrate badly breaks some functionality, see trac #12731: Disable abs_integrate for a list.

A workaround communicated by the author of abs_integrate is mentioned in comment 11 of that trac ticket:

The assignments extra_definite_integration_methods : [] and extra_integration_methods : [] should render abs_integrate inoperative.

I would propose setting these by default, and restoring their values only when you want to play the abs_integrate roulette.

You can set these values from Sage as follows:

from sage.interfaces.maxima_lib import maxima_lib
maxima_lib.set('extra_definite_integration_methods', '[]')
maxima_lib.set('extra_integration_methods', '[]')
edit flag offensive delete link more

Comments

Thanks for the link. But I do not know how to issue these Maxima commands from SageMath. As I said, I am newbie in SageMath. I am not using Maxima directly, I am using SageMath to call Maxima. Could you please show the actual sage commands to type to do these assignments? When I type them as is, they do not work. I also tried the maxima.eval("") commands, and put these 2 commands inside the eval here, but it did not work.

Nasser gravatar imageNasser ( 2018-07-22 14:37:06 +0100 )edit

I added the commands to do it from Sage.

rburing gravatar imagerburing ( 2018-07-22 15:48:12 +0100 )edit
1

answered 2018-07-23 08:43:15 +0100

tmonteil gravatar image

If there is a wrong set of options passed by Sage to maxima, then it should be reported to https://trac.sagemath.org Do not forget to:

Note that even if a ticket exists, it is important to report the bugs so that they will be added ad doctests.

edit flag offensive delete link more

Comments

As you requested, I just made ticket on this. https://trac.sagemath.org/ticket/2590...

Nasser gravatar imageNasser ( 2018-07-23 09:08:11 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-07-21 02:40:43 +0100

Seen: 626 times

Last updated: Jul 23 '18