1

I am working on interactive notebooks with several symbolic calculations, among which there are two indefinite integrals involving square roots. These are integrals (29) and (30) of this table of integrals --> http://integral-table.com.

When I try to evaluate these indefinite integrals with wxMaxima and Sympy, I get wrong results:

wxMaxima:

(29) Similar to the correct one, but the argument of the log function is wrong.

(%i127) integrate(sqrt(x^2-a^2),x);
(%o127) (x*sqrt(x^2-a^2))/2-(a^2*log(2*sqrt(x^2-a^2)+2*x))/2

(30) Similar to the correct one, but with arcsin instead of arctan and wrong argument.

(%i128) integrate(sqrt(a^2-x^2), x);
(%o128) (a^2*asin(x/abs(a)))/2+(x*sqrt(a^2-x^2))/2

Sympy:

(29) Completely different and messy result.

from sympy import *
x, a = Symbol('x', real=True), Symbol('a', real=True)
integrate(sqrt(x**2 - a**2), x)

Result of integral (29) with Sympy

(30) Again, completely different and messy result.

integrate(sqrt(a**2-x**2),x)

Result of integral (30) with Sympy

Instead, with Wolfram Alpha I get the correct primitive functions:

(29) https://www.wolframalpha.com/input/?i=Integrate%5BSqrt%5B+x%5E2-a%5E2%5D%2C+x%5D

(30) https://www.wolframalpha.com/input/?i=Integrate%5BSqrt%5Ba%5E2+-+x%5E2%5D%2C+x%5D

Does anyone know how to circumvent this problem, at least with wxMaxima? Maybe there is some trick, or, as I think, these are bugs to be reported to the developers.

Thank you!

p.s.: I need to work on a free notebook, so using Wolfram Alpha or Mathematica is not a solution.

EDITED: With regard to integral (30), by googling around I just discovered this relation between arcsin and arctan functions:

asin(x/a) = atan(x/sqrt(a^2-x^2))

This makes the result I obtained with Maxima equal to that indicated in the Table of Integrals and given by Wolfram Alpha. However, it seems that wxMaxima doesn't know this relation, since:

(%i165) ratsimp(atan(x/sqrt(a^2-x^2))- asin(x/a));
(%o165) atan(x/sqrt(a^2-x^2))-asin(x/a)

or by setting a=2, for example:

(%i167) ratsimp(atan(x/sqrt(a^2-x^2))- asin(x/a)), a=2;
(%o167) atan(x/sqrt(4-x^2))-asin(x/2)

I tried to employ several simplification methods, but I never obtained zero, hence equivalence between asin(x/a) and atan(x/sqrt(a^2-x^2)).

  • After simplifying the result, verifying that it's indeed different and not just weirdly expanded, I'd recommend submitting a bug report – Mad Physicist Jun 29 '21 at 12:21
  • For example, your first case looks totally legitimate when you remember that log(2z) = log(z) + log(2) and that all these integrals are indefinite, i.e. any additive constant is allowed. I'm going to risk the assumption that you'll find similar simplifications for the others without working each out by hand and vote to close your question – Mad Physicist Jun 29 '21 at 12:26
  • Neat question though – Mad Physicist Jun 29 '21 at 12:28
  • @MadPhysicist I didn't think about the log(2z) = log(z) + log(2) fact, I mean that log(2) may be treated as an additive constant term. Does the same reasoning work also for the other integral? I have to think about it. Thanks, anyway! – PauerEightySix Jun 29 '21 at 12:39
  • In general there are no "correct primitive functions" for an antiderivative because many functions can be written in terms of others e.g. acosh in terms of log etc. – Oscar Benjamin Jun 29 '21 at 13:00
  • That's what it means when indefinite integrals formally have a +C at the end. It's why they're indefinite – Mad Physicist Jun 29 '21 at 13:31
  • @OscarBenjamin that's what I have to figure out actually. From my first attempts, namely by subtracting the two apparently different primitive functions, I didn't obtain zero, but maybe it was correct not obtaining it: I have to check what happens by considering definite integrals. – PauerEightySix Jun 29 '21 at 14:28
  • I think it's worth submitting bug reports to sympy and also maxima about these because at least the output from them could be made simpler. For your problem at hand it is worth considering what it is that you actually want. If you are primarily interested in definite integrals then the algorithms involved can be completely different. – Oscar Benjamin Jun 29 '21 at 18:45

1 Answers1

1

Thanks for investigating, I appreciate it a lot. I am a Maxima developer. Any mistaken results should be reported to the bug tracker: https://sourceforge.net/p/maxima/bugs/ It is necessary to have a Sourceforge account to submit a bug report. Also, most discussion about Maxima is conducted via the mailing list: https://sourceforge.net/projects/maxima/lists/maxima-discuss

About the results you mentioned, you can verify the results by differentiating with respect to x and then comparing to the integrand. When I do that, I get an identical result for the second one. The first one is different, but numerical evaluation suggests (doesn't prove, I know) that it's the same.

(%i2) e: sqrt(x^2 - a^2);
                                2    2
(%o2)                     sqrt(x  - a )
(%i3) integrate (e, x);
                 2    2     2             2    2
         x sqrt(x  - a )   a  log(2 sqrt(x  - a ) + 2 x)
(%o3)    --------------- - -----------------------------
                2                        2
(%i4) diff (%o3, x);
           2       2 x
          a  (------------- + 2)
                    2    2                  2    2
              sqrt(x  - a )           sqrt(x  - a )
(%o4) (- -------------------------) + -------------
                    2    2                  2
         2 (2 sqrt(x  - a ) + 2 x)
                                                         2
                                                        x
                                                + ---------------
                                                          2    2
                                                  2 sqrt(x  - a )
(%i5) ratsimp (%);
                            2    2     2    2
                    x sqrt(x  - a ) + x  - a
(%o5)               -------------------------
                              2    2
                        sqrt(x  - a ) + x

(omitting some exploratory gyrations here ... and now jump to final result)

(%i11) %o5 - e, a = 1;
                     2         2
             x sqrt(x  - 1) + x  - 1         2
(%o11)       ----------------------- - sqrt(x  - 1)
                      2
                sqrt(x  - 1) + x
(%i12) makelist (''%, x, makelist (i, i, 1, 10)), numer;
(%o12) [0.0, 0.0, 0.0, 0.0, 8.881784197001252E-16, 
8.881784197001252E-16, 0.0, 0.0, - 1.77635683940025E-15, 
- 1.77635683940025E-15]

Unfortunately I can honestly say that integration, both definite and indefinite, is a source of many bugs for Maxima. We are continuing to work on it, and towards that end it is very helpful for you to check results, so I encourage you to keep going.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • Thanks Robert for your reply. If I apply integration and then differentiation, I obtain zero for both functions, also for the first one. I repeated your calculations, except for (%i11), where I evaluated: ratsimp(%o5 -e), without setting a=1, and I obtained zero. So it works! – PauerEightySix Jun 30 '21 at 11:41