I would like to solve the following: $$\int e^{-|x|}dx$$ The integral $\int e^{-x}dx = -e^{-x} +C$ is trivial, but the one with the modulus on $x$ seems to have a catch, as typing it into the integral calculator re-writes the integral and gives:
$$\frac{x}{|x|}\int e^{-|x|}\frac{|x|}{x}dx =-\frac{xe^{-|x|}}{|x|}$$
Why was the integral re-written like that? What would a general solution to future problems like this be?
The function you want to integrate is continuous, so it has a differentiable antiderivative. One can be computed quite easily as $$ \int_0^x e^{-|t|}\,dt $$ If $x\ge0$, we have $$ \int_0^x e^{-|t|}\,dt=\int_0^x e^{-t}\,dt=\Bigl[-e^{-t}\Bigr]_0^x= 1-e^{-x} $$ For $x<0$, we have $$ \int_0^x e^{-|t|}\,dt=\int_0^x e^{t}\,dt=\Bigl[e^{t}\Bigr]_0^x=e^x-1 $$ so we can conclude that an antiderivative is $$ F(x)=\begin{cases} 1-e^{-x} & \text{if $x\ge0$}\\[4px] e^{x}-1 & \text{if $x<0$} \end{cases} $$ and the most general antiderivative is $F(x)+c$, where $c$ is an arbitrary constant.
You can write it more compactly as $$ F(x)=(1-e^{-|x|})\operatorname{sgn}(x) $$ where $$ \operatorname{sgn}(x)=\begin{cases} 1 & \text{if $x>0$}\\[4px] 0 & \text{if $x=0$}\\[4px] -1 & \text{if $x<0$} \end{cases} $$