<s>[INST] absolute value integrated For example I have the function $f(x) = |x^2-1| = \sqrt{(x^2-1)^2}$
$\int \sqrt{(x^2-1)^2}dx = \frac{x(x^2-3)\sqrt{(x^2-1)^2)}}{3 (x^2-1)}+constant$
But plotted it looks like this: Plot 1. There are values < 0.
I have to take the absolute value again to get the correct function.
Plot 2 Why do I have to do it again? I integrated $|x^2-1|$ and not $x^2-1$
Edit: Part 2
 [/INST] To evaluate $\int_a^b |x^2-1|dx$ there are 6 possibilities depending on where $a,b$ lie. I am assuming $a\leq b$ in the following, if $a>b$ then use $\int_a^b = -\int_b^a$.
If $a,b \in (-\infty,-1]$ or $a,b \in [1,\infty)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (b^3-3b-a^3+3a)$.
If $a,b \in (-1,1)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (a^3-3a-b^3+3b)$.
If $a\in (-\infty,-1], b \in (-1,1)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (4-a^3+3a-b^3+3b)$.
If $a\in (-1,1), b \in [1,\infty)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (4+a^3-3a+b^3-3b)$.
If $a \in (-\infty,-1]$, $b \in [1,\infty)$, then $\int_a^b |x^2-1|dx= \frac{1}{3} (8-a^3+3a+b^3-3b)$.
</s>