# Indefinite Integral of Absolute Value of x? Is there a closed form solution?

Been searching the net for awhile and everything just comes back about doing the definite integral. So just thought to ask here.

Title says it all. Is there a closed form solution for the indefinite integral $\int |x| dx$ ?

• Define $|x|$ as a piecewise function and integrate each piece independently. Also search $sgn(x)$ and use it to convert your piecewise integral back to one equation. – Ahmed S. Attaalla Oct 6 '15 at 22:57
• an antiderative of $f(x)=|x|$ is $F(x)=\frac 12 x |x|$ – WW1 Oct 6 '15 at 23:01

$$\int |x|~dx=\int \mathrm{sgn}(x)x~dx=|x|x-\int |x| ~dx$$
since $\frac{d}{dx} |x|=\mathrm{sgn}(x)$ on non-zero sets. This yields
$$\int |x| ~dx = \frac{|x|x}{2}~.$$
You are looking for a function $$f(x)$$ so that $$\int_a^b |x|dx=f(b)-f(a).$$ This is what is meant by $$\int |x|dx$$. I propose that $$f(x)=x|x|/2$$ is such a function. Let us test it. If both $$a$$ and $$b$$ are both positive, then $$\int_a^b |x|dx=\int_a^b x\,dx=b^2/2-a^2/2=b|b|/2-a|a|/2=f(b)-f(a).$$ If $$a$$ and $$b$$ are both negative, then $$\int_a^b |x|dx=-\int_a^b x\,dx=-b^2/2-(-a^2/2)=b|b|/2-a|a|/2=f(b)-f(a).$$ Finally, if $$a<0$$ and $$b>0$$, we get $$\int_a^b |x|dx=-\int_a^0 x\,dx+\int_0^b x\,dx=b^2/2+a^2/2=b|b|/2-a|a|/2=f(b)-f(a).$$ Of course, we could have $$b<0$$ and $$a>0$$, but then we could switch the limits, and this reduces to the third case.
Thus, $$f(x)=x|x|/2$$ is an indefinite integral, or antiderivative of $$|x|$$.