Upper and lower bound on characteristic function 
Let $\chi_{[a, b]} = 1$ when $x \in [a, b]$ and $0$ otherwise. Let $\epsilon > 0$ and show that there are compactly supported and smooth functions $f, g : \mathbb{R} \rightarrow [0, \infty]$ such that we have


$$f \leq \chi_{[a, b]} \leq g.$$


Also show that $\int_{\mathbb{R}} (f - g)dx < \epsilon$.

I understand the problem "visually" and intuitively, i.e. if I draw the graph of $\chi$ on some interval $[a, b]$, then $f$ must be equal to $1$ within the interval $[a, b]$ and then smoothly become $0$ once we move outside the interval. Whereas $g$ must be $1$ inside $[a, b]$ but smoothly vanish inside $[a, b]$. And then the area of the difference of these two functions must be arbitrarily small.
But I can't seem to be able to make this into a rigorous argument. I tried defining $f$ piecewise such that $f(x) = 1$ when $x \in [a, b]$ and then I would need some term that makes $f$ vanish when $x$ is outside of $[a, b]$.
 A: Lets write $X=\chi_{a,b}$. To get $f$, you just need to mollify an indicator of a smaller set, say $[a+\epsilon,b-\epsilon]$ (where $\epsilon\ll 1$),
$$ \tilde f(x) := \chi_{[a+\epsilon,b-\epsilon]}\le X.$$ Then take the standard mollifier $\phi_\epsilon(x) = \frac1{\epsilon}\phi(\frac x\epsilon)$ where $\phi$ is your favourite non-negative $C^\infty_c$ function with integral 1. Any choice will work (with slightly different details) but  I’ll choose one  with support in $[-1,1]$. Then $\phi_\epsilon$ is supported in $[-\epsilon,\epsilon]$ and also has integral $1$. Now form the convolution
$$f (x):= \tilde f*\phi_\epsilon(x)= 
\int_{-\epsilon}^\epsilon \tilde  f(x-y) \phi_{\epsilon}(y) dy = \int_{x-\epsilon}^{x+\epsilon} \tilde f(y) \phi_{\epsilon}(y-x) dy.  $$
Since both $\tilde f$ and $\phi_\epsilon$ have compact support, so does $f_\epsilon$. In fact, the support of the convolution is the sum of the supports, i.e. $\operatorname{supp }f= [a+\epsilon-\epsilon,b-\epsilon+\epsilon] = [a,b]$, so it turns out that I have the largest possible support for $f$ though this is of course not required. It is standard to check that $f$ is $C^\infty$; all derivatives can be made to fall on $\phi_\epsilon$. So one just needs to check that we have $f \le X$. This is because $\phi_\epsilon(y-x)dy$ acts to average the points $\epsilon$-close to $x$. If all the points $x$ on this set are less than $1$, then so is their average. So $0\le f\le X=1$ on $[a,b]$ (the support of $f$) and $f=X=0$ outside $[a,b]$.
One can bound the integral $\int X - f dx = \int |X-f|dx$ by drawing rectangles; one gets the bound 1 times the size of the set where they are different; this is $4\epsilon$.
Playing a similar game, we can construct $\tilde g=\chi_{[a-\epsilon,b+\epsilon]}\ge X$ and then mollify to get $g$, finishing the proof (we get the bound $\int (g-f)\le 8\epsilon$ but one can go back and use $\epsilon/8$ instead. Strictly speaking, the inequality in the question is also satisfied: $\int (f-g)\le 0 \le \epsilon$ ).
Here's a plot:  (interactive Desmos link)

