Solving the integral of a function with modulus 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?
 A: 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}
$$
A: The fraction $\frac{x}{|x|}$ equals $1$ if $x > 0$ and $-1$ if $x<0$. Observe this: for $a > b > 0$ 
$$\int_{-a}^{-b} \exp(-|x|) dx =  \int_{a}^b \exp(-x) dx = - \int_b^a \exp(-x) dx$$
Where the min sign comes since if $a > b > 0$ then $-a < -b < 0$. Thus, we see that only thing modulo does is give us a min sign if we integrate over negatives and instead integrates over positives. This is exactly what this fraction does for you.
A: An approach I prefer that avoids the somewhat messy $\frac{x}{|x|}$ terms or the chain rule/integration by parts approach - write:
$$\exp(-|x|)=\exp(x)\mathbb{I[x<0]}+\exp(-x)\mathbb{I[x\ge0]}=l(x)+r(x)$$
Now:
$$L(x):=\int_{-\infty}^xl(t)\,dt=\exp(x)\wedge1$$
$$R(x):=\int_x^{\infty}r(t)\,dt=\exp(-x)\wedge1$$
(using the standard $a\wedge b=\min\{a,b\}$ notation)
Then $L'=l,R'=-r$, so the integral of our original function is:
$$\int \exp(-|x|)\,dx=[\exp(x)\wedge1]-[\exp(-x)\wedge1]+C$$
This suits me better as it's manifestly continuous, and doesn't require us placing too much faith in the derivative of $|x|$.
A: This integral $$\int e^{-|x|}dx$$ is an even integral, such that we could define it as the amalgam of two integrals, each defined in a specific domain.
$$I_{1}=\int e^{-x}dx, x\geq 0 $$
$$I_{2}=\int e^{x}dx, x\leq 0 $$
As the question states, both these integrals are trivial.
$$I_{1}=- e^{-x} , x\geq 0 $$
$$I_{2}=e^{x}, x\leq 0 $$
We would like to write these two solutions as a single solution to the original integral. For this purpose, we need to appeal to some notation.
To begin with, we remember that, since we are on the Euclidean metric in one dimension, the magnitude the variable $x$ and the variable itself always have the same weight, such that
$$|x|= x , x\geq 0$$
$$|x|= -x , x\leq 0$$
In fact, we mae use of this very fact in order to establish that the integral was even.
But this property of the Euclidean Norm on the 1-D space means that
$$\frac{x}{|x|}= 1 , x> 0$$
$$\frac{x}{|x|}= 1 , x< 0$$
We then also note that
$$\lim_{x\rightarrow 0}\frac{x}{|x|}= 1$$
We can now return to the two integrals $I_{1}$ and $I_{2}$ and notice that they are both of the form
$$I = C e^{-|x|} $$
where $C = -1 $ when $x \geq 0$ and $ C = 1$ when $ x < 0 $. Thankfully, we already have a devise which has this property, so we employ is and claim that
$$I = -\frac{x}{|x|} e^{-|x|} +c_{1} $$
where we have also employed the arbitrary constant $c_{1}$ to highlight the fact that our integral is indefinite.
A: On $x \neq 0$, the derivative of $|x|$ is the mapping
$$ x \mapsto \begin{cases} 1 & x>0 \\ -1 & x<0\end{cases} $$
It can be written in various different ways; the expression $\frac{|x|}{x}$ is one such way.
One important feature of this function is that it is locally constant, which means you can use it in pretty much all of the ways you can use ordinary scalars — in particular, you can multiply it through the integral:
$$ \frac{|x|}{x} \int f(x) \, \mathrm{d}x
 = \int  \frac{|x|}{x} f(x) \, \mathrm{d}x $$
The reason for doing this is that having $e^{-|x|}$ in the integrand should immediately suggest making a substitution such as $u = |x|$ as a possible approach. Since we have
$$ \mathrm{d}u = \frac{|x|}{x} \mathrm{d} x$$
we rewrite the integral as
$$ \int e^{-|x|} \, \mathrm{d}x = \frac{x}{|x|}  \int e^{-|x|} \frac{|x|}{x} \, \mathrm{d}x  $$
so that we can make the substitution. Or equivalently, we don't do the rewriting, but we substitute
$$ \mathrm{d} x \mapsto \frac{x}{|x|} \mathrm{d}u  $$
One thing to be aware of is that the "constant of integration" is locally constant; since the domain $x \neq 0$ splits into two disjoint parts ($x>0$ and $x<0$), if you find one antiderivative $F$ on $x \neq 0$, the total solution on $x \neq 0$ is thus
$$ \int e^{-|x|} \, \mathrm{d}x = F(x) + C(x) $$
where $C(x)$ is a function of the form
$$ C(x) = \begin{cases} c_1 & x > 0 \\ c_2 & x < 0 \end{cases} $$
for constants $c_1$ and $c_2$.

Finally, to get an actual answer to the problem, you need to find an antiderivative that works for all $x$, not just on $x \neq 0$; that is, you need to find the conditions on the constant of integration so that the antiderivative can be continuously extended to have a value at $0$.
Your calculator has not done this final step; it only gave you an antiderivative on $x \neq 0$.
