Ask Your Question

Bug in integration of sqrt functions?

asked 2013-10-09 06:57:17 -0500

Shashank gravatar image

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


However, when I write the same integral in the form


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


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 flag offensive close merge delete


This has been reported upstream - - thanks, Dima!

kcrisman gravatar imagekcrisman ( 2013-10-10 03:47:19 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-10-09 15:27:33 -0500

dazedANDconfused gravatar image

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.

edit flag offensive delete link 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.

Shashank gravatar imageShashank ( 2013-10-09 15:33:22 -0500 )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.

kcrisman gravatar imagekcrisman ( 2013-10-10 03:54:55 -0500 )edit

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

Shashank gravatar imageShashank ( 2013-10-10 12:05:06 -0500 )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


Asked: 2013-10-09 06:57:17 -0500

Seen: 367 times

Last updated: Oct 09 '13