TITLE: How to prove that a function is class $C^{\infty}(\mathbb{R}).$
QUESTION [9 upvotes]: I would like to prove that this function (with the $a, b\in \mathbb{R}$ satisfying  $a < b$),
$$f(x)=\begin{cases} \exp\left(-\frac{1}{x-a}+\frac{1}{x-b}\right), & \text{if },x\in (a,b)\,, \\ 0, & \text{if }x\notin (a,b)\text{}
\end{cases}$$
is class $C^\infty (\mathbb{R}).$
But how?

REPLY [4 votes]: Suppose $a=0$ and $b=1$, because the same reasoning applies in general.  So we have $f(x)=\exp\left(\frac{1}{x(x-1)}\right)$ on $(0,1)$.  Compositions of $C^\infty$ functions are $C^\infty$, so the only possible problems are at $0$ and $1$.  Since $f(x)=f(1-x)$, it is enough to handle $0$.  
Let's start by showing that $f'(0)=0$.  The left-hand difference quotients at $0$ are $0$, so it is enough to show that $\lim\limits_{x\searrow 0}\frac{f(x)}{x}=0$.  Note that $
\frac{1}{x(x-1)}<-\frac{1}{x}$ for $x\in(0,1)$, so it is enough to show that $\lim\limits_{x\searrow 0}\frac{e^{-1/x}}{x}=0$.  This is probably easiest to see by a change of variables, $t=1/x$, to yield $\lim\limits_{x\searrow 0}\frac{e^{-1/x}}{x}=\lim\limits_{t\to\infty}\frac{e^{-t}}{1/t}=\lim\limits_{t\to\infty}\frac{t}{e^t}=0$.
So far we know that $f'$ exists everywhere.  Now as Davide Giraudo indicates in a comment, you can show by induction that in $(0,1)$, $f^{(k)}(x)=R_k(x)f(x)$ for some rational function $R_k$ having poles only at $0$ and $1$.  I'll omit proof of this.  Suppose that for some $k$ we know that $f^{(k)}(0)=0$.  To show that $f^{(k+1)}(0)=0$, we need to show that $\lim\limits_{x\searrow 0}\frac{R_k(x)f(x)}{x}=0$.  Note that $R_k(x)=\frac{g(x)}{x^{n}}$ for some integer $n$ and a function $g$ that is continuous at $0$.  Again, since $f(x)<e^{-1/x}$, it suffices to show that $\frac{e^{-1/x}}{x^{n+1}}\to 0$ as $x\searrow 0$, and this is straightforward from the same change of variables $t=1/x$.  (The base case $k=1$ wasn't really necessary to show since we are already given the base case $k=0$, but I though it might be helpful to start with the simplest case and make it more explicit.)
Again, since $f(x)=f(1-x)$, this also gives $f^{(k)}(1)=0$ for all $k$, and this shows (in sketch form) why $f$ is infinitely differentiable.