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

Using integration by parts

$$\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|$.