Well, the result is correct. It all comes down to
$\int \tan(x)dx$ which by the substitution
$u=\cos(x)$ becomes
$-\int \frac{1}{u}du$. When we do this by hand, the answer is
$-\log(|u|)+c$ where
$c$ is constant of integration. But CAS gives
$-\log(u)$ as the general result. i.e. it does not use the absolute value and constant of integration is never given but assumed in the antiderivative, since the derivative of constant is zero.
So Mathematica result is correct, CAS speaking. If you add Abs[]
and plot -Log[Abs@Cos[x]] - Sec[x]^2 + Sec[x]^4/4
you'll see it is the same. There is
$\frac{1}{4}$ constant offset, which was thrown away from the antiderivative that was returned. Hence, to get the same result as your hand calculation, use 1/4 - Log[Abs[Cos[x]]] - Sec[x]^2 + Sec[x]^4/4
which is also correct, but so is -Log[Abs@Cos[x]] - Sec[x]^2 + Sec[x]^4/4
and also -Log[Cos[x]] - Sec[x]^2 + Sec[x]^4/4
(without the Abs
). But if you do not use Abs
you'd have to worry about complex values when
$\cos(x)$ becomes negative since it is now it is an argument to the
$\ln(\cos(x))$
Should CAS return
$\ln(|u|)$ as result for
$\int \frac{1}{u} du$? Since CAS always returns general results, this is how all CAS systems work that I know about.