What is the indefinite integral $\int |x-2| dx$? 
What is the indefinite integral :
  $$\int |x-2| dx?$$


I tried doing it like this : 
$$\int x-2  dx$$ if $x \geq 2$
$$\int 2-x  dx$$ if $x < 2$
$$ \frac {x^2}{2} - 2x + C $$ if $x \geq 2$
$$ 2x - \frac {x^2}{2} +C $$ if $x < 2$
Is that correct ?
 A: Another method is $$\int |x| dx=\dfrac{x|x|}{2}+c\\\vdots \\\int |x-2| dx=\dfrac{(x-2)|x-2|}{2}+c$$
A: Your approach is correct. Here is another way.
Let $x-2=u\implies \text{d}x=\text{d}u$, hence $$\int |x-2|\text{d}x=\int |u|\text{d}u$$
Now, $$\int |u|\text{d}u=\frac{u}{|u|}\int |u|\cdot \frac{|u|}{u}\text{d}u=\frac{u}{|u|}\int u\text{d}u=\frac{u}{|u|}\cdot \frac{u^2}{2}+C=\frac{u|u|}{2}+C$$Thus $$\int |x-2|\text{d}x=\frac{(x-2)|x-2|}{2}+C$$
A: For $x>2$, an anti-derivative of $f(x):=|x-2|$ is $\frac{x^2}{2}-2x$; for $x<2$, an anti-derivative of $f$ is $2x-\frac{x^2}{2}$. We can then define
$$
F(x)=\begin{cases}
\frac{x^2}{2}-2x,&x> 2\\
-(\frac{x^2}{2}-2x),&x<2
\end{cases}
$$
 so that $F'(x)=f(x)$ for $\mathbb{R}\backslash\{0\}$. If we define $F(2)=0$, then we can check that $F$ is continuous on $\mathbb{R}$. Actually, we have $F$ being differentiable on $\mathbb{R}$ (check it!). In particular, $F'(2)$ exists and is equal to $0=f(2)$. Now we can say that
$$
F(x)=\begin{cases}
\frac{x^2}{2}-2x,&x\geq 2\\
-(\frac{x^2}{2}-2x),&x<2
\end{cases}
$$
gives an anti-derivative of $f$ on $\mathbb{R}$. By the meanvalue theorem, any anti-derivative of $f$ is of the form $F+C$ for some real constant $C$. 
Note that one can further write $F$ in a "compact way" as
$$
F(x)=\big(\frac{x^2}{2}-2x\big)\hbox{sgn}(x-2).
$$
Or alternatively, 
$$
F(x)=\big(\frac{(x-2)^2}{2}-2\big)\hbox{sgn}(x-2)=
\frac{|x-2|(x-2)}{2}-2.
$$
Since the constant $-2$ can be "absorbed", one can claim that any anti-derivative of $f$ is of the form $G+C$ where
$$
G(x):=\frac{|x-2|(x-2)}{2}.
$$
