# Is this function twice differentiable at $0$?

I have a function $f(x)$:

$$f(x)=\frac{\exp(-|x|)}{1-0.5|\tanh(2x)|}$$

If I try differentiating it in Mathematica (taking $|x|=(2\theta(x)-1)x$ where $\theta(x)$ is Heaviside step function), I get answer in terms of Heaviside functions. But looking at the derivative I can't really see any jump there, which is why I start thinking that it has a second derivative too. But differentiating once more, I get answer with Dirac functions, which don't disappear when evaluating the result at $x=0$.

If I instead represent $|x|=\sqrt{x^2}$, then for the first derivative I get an expression which has $0$ as its limit as $x\to0$, and for second derivative the limit appears to be 1. So from this I could make the conclusion that $f(x)$ is twice differentiable at $x=0$.

So the question: is this function differentiable at $x=0$? Is it twice differentiable?

-
$\large \left\vert x\right\vert = x\,\,\,{\rm sgn}\left(x\right)$ where $\large{\rm sgn}$ is the "sign function". –  Felix Marin Oct 28 '13 at 19:41
@FelixMarin right, fixed. –  Ruslan Oct 28 '13 at 19:43
Also, $\large\left\vert\tanh\left(2x\right)\right\vert = {\rm sgn}\left(x\right)\tanh\left(2\left\vert x \right\vert\right)$. –  Felix Marin Oct 28 '13 at 19:57
@FelixMarin Your second indication is wrong. –  Did Oct 28 '13 at 20:48

Since we are dealing with real $x$ (we are, aren't we?), we can write

$$\lvert \tanh (2x)\rvert = \tanh (2\lvert x\rvert).$$

We have $\frac12\tanh (2\lvert x\rvert) = \lvert x\rvert + O(\lvert x\rvert^3)$, so we can calculate

\begin{align} \frac{e^{-\lvert x\rvert}}{1 - \frac12\tanh(2\lvert x\rvert)} &= \left(1 - \lvert x\rvert + \frac{\lvert x\rvert^2}{2} + O(\lvert x\rvert^3)\right)\left(1 + \lvert x\rvert + \lvert x\rvert^2 + O(\lvert x\rvert^3)\right)\\ &= 1 + \frac{\lvert x\rvert^2}{2} + O(\lvert x\rvert^3). \end{align}

Since the two halves of the function are analytic, it follows that the function is twice continuously differentiable.

Generally, if we have a function of the form

$$f(x) = \begin{cases}g(x) &, x \geqslant 0\\ h(x) &, x \leqslant 0 \end{cases}$$

where $g$ and $h$ are continuously differentiable functions with $g(0) = h(0)$ - so that the definition of $f$ has no conflict - then $f$ is differentiable in $0$ if and only if $g'(0) = h'(0)$, and then $f$ is continuously differentiable with $f'(0) = g'(0) = h'(0)$.

If $g$ and $h$ are analytic, i.e. we have power series representations

$$g(x) = \sum_{n=0}^\infty a_n x^n,\qquad h(x) = \sum_{n=0}^\infty b_n x^n,$$

then $f$ is $k$ times (continuously) differentiable if and only if $a_n = b_n$ for $0 \leqslant n \leqslant k$. The computation above shows that the two functions

$$g(x) = \frac{e^{-x}}{1-\frac12\tanh(2x)}\quad\text{and}\quad h(x) = \frac{e^x}{1+\frac12\tanh(2x)}$$

both have power series expansions starting with $1 + \frac12 x^2$, so $f$ is twice continuously differentiable.

-
Nope. $\tanh$ is an odd function, and $\tanh x > 0$ for $x > 0$, so $\lvert \tanh x\rvert = \tanh \lvert x\rvert$. –  Daniel Fischer Oct 28 '13 at 20:21
That's true. My typo$\ldots$ Thanks. –  Felix Marin Oct 28 '13 at 20:43
Since a second-order Taylor approximation does not imply that the function is twice differentiable (unlike order one is equivalent to differentiability), maybe a few more details would be needed ;-) –  1015 Oct 28 '13 at 21:02
@julien Would you consider merely referring to the analyticity of both halves sufficient, or would you advise elaborating more? –  Daniel Fischer Oct 28 '13 at 21:10
I might be blind but I can't see why this is clearly analytic. But for all $x$ non zero (doing $x$ positive and negative separately), we have $f'(x)=\frac{\exp(-|x|)(2 \tanh(2|x|)+4\sech^2(2|x|)-4) }{(2-\tanh(2|x|))^2}$ and we can easily look at the limit of $(f'(x)-f'(0))/(x-0)=f'(x)/x$ from there. Which is indeed $1$. –  1015 Oct 28 '13 at 21:33


-
Sorry but this is not mathematics, even as hints. –  Did Oct 28 '13 at 20:49