# Bug in integration of sqrt functions?

I have been experiencing a problem integrating a function with several terms. I have managed to narrow it down to a problem with integration.

When I type the following command I get 1 as I should

integrate(cos(x),x,0,pi/2)


However, when I write the same integral in the form

integrate((sqrt(1-sin(x)*sin(x))),x,0,pi/2)


I get an error "RuntimeError: ECL says: Error executing code in Maxima: atanh: argument 1 isn't in the domain of atanh."

I guess it is a result of the fact that

integrate((sqrt(1-sin(x)*sin(x))),x,0,pi/2)


gives $\tan(x)/\sqrt{(\tan(x)^2 + 1)}$ and sage is trying to substitute $x=\pi/2$ without trying to simplify the expression first or taking the limit of x to $\pi/2$. Is there a way to avoid this problem when the function I wrote is a part of a bigger function and I can't simplify by hand.

Both integrals are identical and I don't understand why I am getting an error in one case. Is this a bug or am I doing something wrong?

edit retag close merge delete

This has been reported upstream - http://www.math.utexas.edu/pipermail/maxima/2013/034222.html - thanks, Dima!

( 2013-10-10 03:47:19 -0600 )edit

Sort by » oldest newest most voted

I don't think I can answer your questions but maybe we can solve the problem: "Is there a way to avoid this problem when the function I wrote is a part of a bigger function and I can't simplify by hand.". For trig functions there is a simplification command, simplify_trig(), see here, that solves this particular problem but maybe a combination of commands that simplify might be what you need. The command integrate((tan(x)/(sqrt((tan(x)^2+1)))).simplify_trig(),(x,0,pi/2)) will evaluate to 1.

The function (sqrt(1-sin(x)*sin(x)) is really the absolute value of cosine (certainly over 0 to $\pi/2$ they're the same); maybe that's why we get the strange antiderivative. I tried integrate(abs(cos(x)),(x,0,pi)) in a sage notebook and got -1 which is definitely wrong. I couldn't get an answer in the Sage Cell server. The Fundamental Theorem of Calculus expects the antiderivative to be defined on the closed interval $[0,\pi/2]$, but $\tan(x)/\sqrt{(\tan(x)^2 + 1)}$ isn't defined when x is a multiple of $\pi/2$. You'll find Sage gives the same error message if you integrate from 0 to $\pi$. In summary, $\tan(x)/\sqrt{(\tan(x)^2 + 1)}$ looks incorrect to me because the domain is not all real numbers but maybe using the simplify commands will let you get your work done.

more

I know about simplify_trig() command. However, it is inconvenient when you are multiple calculations in a loop and there are several terms. My point was that you should not have to simplify and then take the limits.

( 2013-10-09 15:33:22 -0600 )edit

The above abs(cos(x)) error was already reported at Trac 11483 (currently Trac is down, but you can Google for it). Hopefully Trac 13973 will fix this for good.

( 2013-10-10 03:54:55 -0600 )edit

Thanks a lot. It seems it will be fixed in 5.13. Is there a release schedule for this and future versions?

( 2013-10-10 12:05:06 -0600 )edit