integrate(sqrt(1-cos(x)^2), x) gives cos(x)



On 3/17/2013 10:03 AM, David Scherfgen wrote:
> Hello,
>
> can anyone explain this obviously wrong behavior?
>
> (%i1) integrate(sqrt(1-cos(x)^2),x);
> (%o1)                               cos(x)
> (%i2) trigsimp(sqrt(1-cos(x)^2));
> (%o2)                             abs(sin(x))
> (%i3) integrate(abs(sin(x)),x);
>                                /
>                                [
> (%o3)                          I abs(sin(x)) dx
>                                ]
>                                /
>
> Seems like "integrate" does some additional simplification of the 
> input function which leads to a wrong result.
There are 2 square roots.  Sqrt(x^2) has 2 values,   x and -x. Neither 
one of them is functionally the same
as abs(x), which you can see by drawing plots of them.

The result from trigsimp, while perhaps useful sometimes because it 
sometimes coincides with
the expected answer, is algebraically wrong, and if followed too far, 
can lead to peculiar results.

A more correct answer from integrate might be something like
"cos(x)  or -cos(x) depending on choice of branch of sqrt"
>
> Even if it somehow simplified it to sin(x) instead of abs(sin(x)), the 
> result would still have the wrong sign, because it should be -cos(x) 
> then, and not cos(x).
The two square roots of   (sin(x))^2   are {sin(x),   -sin(x)}.  not 
abs(sin(x)). Which branch of the sqrt
is chosen is probably not so obvious.

Here is a way that you can get sqrt(1-cos(x)^2)  = - sin(x).
I do not know if integrate() did this, but maybe it did..

sqrt(1-cos(x)^2);
%,exponentialize;
radcan(%);
%,demoivre;
trigreduce(%);

In case you think radcan made a mistake (instead of just making a choice)
consider that it was given the square root of
1-(%e^(%i*x)+%e^(-%i*x))^2/4
which can be factored to this   (perfectly correct ...)

-   (%e^(-2*%i*x) *   (%e^(%i*x)-1)^2*    (%e^(%i*x)+1)^2)   /  4

the square root of that can be computed (perhaps) by computing the 
square root of each term. Easy.

%i  *  %e^(-%i*x)     * (%e^(%i*x)       * (%e^(%i*x) +1)      / 2


Which is -sin(x).


So if you want to claim there is an error in radcan, it is that 
sqrt(x^2)   sometimes should be -x.

Anyway, that shows the problem with imposing some single value for sqrt.
An interesting if slightly painful excursion.

RJF