# Is the following piecewise-defined function smooth $\in C^\infty(\mathbb{R})$?

Is the function $$q(x)=\begin{cases} 1& x=0\\ 0& |x|\geq 1\\ \dfrac{1}{1+\exp\left(\dfrac{1-2|x|}{x^2-|x|}\right)}&\text{otherwise}\end{cases}$$a smooth function class $$C^\infty(\mathbb{R})$$?

I found this function as is shown in Wiki by choosing $$f(x)=\exp\left(-\frac{1}{x}\right)\theta(x)$$ with $$\theta(x)$$ the Heaviside step function, then making $$g(x)=\frac{f(x)}{f(x)+f(1-x)}$$ and then lets $$q(x)=g\left(\frac{x-a}{b-a}\right)\cdot g\left(\frac{d-x}{d-c}\right)$$ with $$a=-1,\ b=c=0,\ d=1$$, as could be seen in Desmos.

But later in this question I found in the answers and comments it have some issues at specific points were is undefined, so now I tried to fix them by defining the function piecewise.

A simular construction is used in this answer in MSE to built an example of a smooth transition function so in the case of this $$q(x)$$, in principle, the points were could be some issues should be only $$x\in\{-1, 0,1\}$$, but since its defined piecewise now I am not sure if indeed this solve the situation making $$q(x)\in C^\infty(\mathbb{R})$$ a smooth function, or it still have issues that make it being non infinitely differentiable.

I was able to check it possitively until the 7th derivative in Wolfram-Alpha.

Motivation

I am trying to understand the properties in order to figure out this other question.

• Please consider fixing your title to not include display-style equations whenever possible. Jul 4 at 1:26
• @math-physicist I change it as required. Jul 4 at 1:39
• I think one way to show this is the case is showing that $q(1-x)\in o(x^n)$ for all $n$. That is, show that for all $n\in\mathbb{N}$ and $c>0$, there exists $x_0$ such that for all $0<x<x_0$, $q(1-x)<cx^n$. I'm not entirely sure if this is sufficient though. Jul 5 at 5:23
• @VarunVejalla thanks for commenting. At first glance I don't think the function is of polynomial order since is an example of flat function, which are examples of non-analytic smooth functions. But maybe I am mistaken. Hope you could elaborate in an answer. Jul 5 at 19:15
• I posted an answer that, although longer, is in some way more elementary/direct than @Varun's. It's more abstract but I still find the approach curious. Due to its length it's possible that I made some mistakes along the way, so I'd love to hear your output on it. I'd also suggest Does the function $(1+\exp((1-2x)/(x^2-x))^{-1}$ touch $y=0$ and $(0,1)$ smoothly? or similar as a more desciptive (than currently) title. Jul 16 at 23:12

It's symmetric about $$x=0$$ and continuous at $$x=0$$. It's also smooth for $$|x|< 1$$, so all we really need to check is whether $$\frac{d^n}{dx^n}\bigg|_{x=1^-}\frac{1}{1+\exp\left(\frac{1-2|x|}{x^2-|x|}\right)}=0$$ for all $$n\in\mathbb{N}$$, where here the derivative is just from the left-hand side. Just to get rid of the absolute values, and considering $$x>0$$, we can rewrite it as $$\frac{d^n}{dx^n}\bigg|_{x=1^-}\frac{1}{1+\exp\left(\frac{1-2x}{x^2-x}\right)}=0$$

Defining $$f(x)$$ as the function that is being differentiated, we can consider whether $$\frac{d^n}{dx^n}\big|_{x=0^+} f(1-x)=0$$ is true for all $$n\in\mathbb{N}$$. And $$g(x):=f(1-x)=\frac{1}{1+\exp\left(\frac{2x-1}{x^2-x}\right)}$$

Now with that out of the way, consider this from this question: $$g^{(n)}_+(x)=\lim_{\Delta x \to 0} \sum_{k=0}^{n}(-1)^k{n \choose k}\dfrac{g(x+\Delta x(n-k))}{\Delta x^n}$$ where $$g^{(n)}_+(x)$$ would be the right derivative. This actually doesn't always work for arbitrary $$g$$, but since in this case, $$g$$ is smooth for $$x\in(0,1)$$, we can use this (to be completely proper about it, you can consider it more like the limit as $$x\to 0^+$$ of the derivative).

Now suppose we can show that for all $$c>0,n\in\mathbb{N}$$, there exists a $$x_0>0$$ such that for all $$0\le x, $$0\le g(x)\le cx^n$$. This would mean that $$g^{(n)}_+(0)=\lim_{\Delta x \to 0} \frac{1}{\Delta x^n}\sum_{k=0}^{n}(-1)^k{n \choose k}g(\Delta x(n-k))$$ is bounded since we can just consider $$\Delta x. So then the lower bound is just $$0$$, while the upper bound is $$\lim_{\Delta x \to 0} \sum_{k=0}^{n}(-1)^k{n \choose k}c(n-k)^n=ca_n$$ where $$a_n$$ is some constant only dependent on $$n$$ (I think it evaluates to $$n!$$, but the exact value isn't important). So then $$0\le g^{(n)}_+(0)\le ca_n$$. But since we can make $$c$$ arbitrarily small, $$g^{(n)}_+(0)=0$$, and it follows that $$g$$, and thus $$f$$, is smooth.

So now all that's left is to show my claim: for all $$c>0,n\in\mathbb{N}$$, there exists a $$x_0>0$$ such that for all $$0\le x, $$0\le g(x)\le cx^n$$. $$g(x)\ge 0$$ is always true, which simplifies the problem a bit. For $$g(x)\le cx^n$$, we can rewrite it to $$\left(1+\text{exp}\left(\frac{2x-1}{x^{2}-x}\right)\right)x^n\ge\frac{1}{c}$$

For $$x<1/3$$, we have that $$1+\text{exp}\left(\frac{2x-1}{x^{2}-x}\right)>\text{exp}\left(\frac{2x-1}{x^{2}-x}\right)>\text{exp}\left(\frac{1}{2x}\right)$$ so we can just show there exists a $$x_0>0$$ such that for all $$0, $$\text{exp}\left(\frac{1}{2x}\right)x^n>\frac{1}{c}$$. Finally, using the series expansion of $$e^x$$, we have that $$\exp\left(\frac{1}{2x}\right)x^n>x^n\sum_{k=0}^{n+1}\frac{1}{k!}\left(\frac{1}{2x}\right)^k$$ which is a polynomial plus $$\frac{1}{2^{\left(n+1\right)}\left(n+1\right)!}\frac{1}{x}$$. Then there would exist some $$x_0$$ such that the claim holds.

• Thank you very much for taking the time to answer. Right now I am trying to understand its logic: Why being $0\leq g(x) < cx^n$ implies it is smooth? I am thinking in the example $x^2\sin(1/x)$ where even when $\frac{|f(x)-f(x_0)|}{|x-x_0|}<c$ it is still non-smooth. Jul 6 at 12:07
• I read you answer again today and there is another thing is not obvious to me: How do you know the function in question is smooth for $|x|<1$? Jul 6 at 22:23
• Sorry, I might have written it a bit unclearly. The point is that if we're given an arbitrary $c$ and $n$, we can always pick $x_0$ such that for all $0<x<x_0$, it's always true that $0\le g(x)<cx^n$. The expression for the $n$th derivative at $0$ then simplifies a bunch (since we can just consider $\Delta x<x_0$), giving us bounds on $g^{(n)}_+(0)$. Then as we make $c$ smaller and smaller, we get that $g^{(n)}_+(0)=0$. This means that the original function is smooth around $x=\pm 1$. Jul 7 at 6:07
• And it's smooth for $|x|<1$ because $q(x)$ is symmetric about $x=0$ (i.e. it's an even function), so we can just show it's smooth for $x\ge 0$. It's continuous since $\lim_{x\to0}q(x)=q(0)=1$. Then the otherwise case is smooth since $\frac{1-2x}{x^2-x}$ is smooth on $(0,1)$, so $\frac{1}{1+\exp(\text{that term})}$ would also be smooth. Jul 7 at 6:11
• thanks you very much for the explanation. It is an interesting approach. I were trying (unsuccesfully so far) to find a recursion for the derivatives such it were usefull to prove it is differentiable for all iterations. Jul 7 at 12:11

When you begin your mathematical journey, you're often taught to solve such problems by finding a general formula for all $$n$$ and then prove your property by induction. That is, you're encouraged "to look at the big picture" parametrized by $$n\in\mathbb N$$.

In a situation like this, even a general formula for $$\frac{d^nf}{dx^n}$$ is not a big enough picture. Even a "general" formula parametrized by $$n$$ is not general enough, because its particular form is too complex. You need to look at the very big picture. You need to see the shape of your function and all of its derivatives - find a property that $$f$$ and its derivatives have that will help you through the solution.

Sure, when you took the first 7 derivatives of your function, you could not find any particularly nice looking formula, but I'm sure you noticed that the shape of every derivative is quite predictable - it was all fractions of polynomials and exponents thereof. And if you played with the graph of your function, you'd notice that its behaviour at $$x=1^{-}$$ doesn't really change if you replace the 2 in the numerator in the exponent with, say, 5, or change the denominator from $$x(x-1)$$ to, say, $$(x+2)(x-1)$$. And if you replace the numerator of the entire function from 1 to, say, $$x$$ or $$1/x$$, you still get the same behaviour at $$1^{-}$$!

Let's try to see the bigger picture now!

1. First note that derivatives of proper rational functions are again proper rational functions: If $$R(x)=\frac {p(x)} {q(x)},\deg p<\deg q,$$ then $$\frac{dR(x)}{dx}=\frac {\tilde p(x)} {\tilde q(x)}$$ for some polynomials $$\tilde p,\tilde q$$ with $$\deg p<\deg q - 1$$ (prove it yourself - and the $$-1$$ here is important).
2. Next, derivatives of rational functions of exponentials are again rational functions of exponentials: if for some proper rational $$R(x)$$, $$g(y)=R(e^y),$$ then $$g'(y)=e^yR'(e^y)$$ is again of the form $$g'(y)=Q(e^y)$$ for some proper rational $$Q$$ precisely due to the $$(-1)$$ bound in the previous step (in fact, when I solved it first, I didn't note the stricter bound and only at this step did I see that I need it, and went back above).
3. Now the function classes above still do not cover the function in question. We need rational functions of exponentials of rational functions! Let's look at some $$f(x)=R(\exp(Q(x))=g(Q(x)),$$where $$R,Q$$ are proper rational and $$g$$ is as in step 2. Then $$f'(x)=g'(Q(x))Q'(x),$$ where $$g'$$ is again as in step 2, but we have a nasty factor of $$Q'$$, thus breaking the shape of $$f$$ we started with (rat's of exp's of rat's). Moreover, if we differentiate again, it get's even worse: $$g''(Q(x))Q'(x)Q'(x)+g'(Q(x))Q''(x)$$, i.e. a sum of such products. All is not lost, though, because upon a third differentiation, we just get more terms in the sum, while the overall shape stays the same.
4. Let's expand our picture again and look the most general shape of functions so far: $$f(x)=\sum_i R_i(x)g_i(Q_i(x))$$ where $$R_i,Q_i$$ are proper rational and $$g_i$$ are as in step 2. Now we take the derivative: $$f'(x)=\sum_i R'_i(x)g_i(Q_i(x))+R_i(x)Q'_i(x)g'(Q_i(x))$$ and see that it is again of this form - a sum of products of proper rationals with proper rationals of exponentials of proper rationals, haha (why? Because $$R_i'$$ and $$R_iQ'$$ are proper rationals as per step 1, and $$g'$$ is of the needed type as per step 2).
5. Finally, if we show that all functions of type as in step 4 converge to 0 as $$x\to 1$$, then we'll know all their derivatives do so too, because they're of the same type!
Assume (as in the original question) $$f$$ as in step 4, and all $$Q_i$$s have $$\lim_{x\to1^{-}}Q_i(x)=\infty.$$ Then $$\lim_{x\to1^{-}}f(x)=0$$ (why?). Now, not only $$f'(x)$$ is of the same shape, but $$\lim_{x\to1^{-}}f'(x)=0$$, too! (Why? Compute with $$f'$$ as expanded in step 4 - and note that the arguments to $$g_i$$ are only $$Q_i$$s).

To summarize: the function of the original question is of type as in step 4. A derivative of a function as in step 4 is again as in step 4. Hence all derivatives of the given function are of this shape. Moreover, if $$Q_i\to\infty$$ as $$x\to 1^{-}$$, then $$f\to 0$$, and this propagates to the first derivative, too. Therefore, $$f$$ and all its derivatives fulfill it! I skipped a few details in this already quite long answer and I encourage you to fill them in yourself.

The main point of this essay is to show how you could discover similar patterns yourself. When the derivatives get ugly, try to see what stays the same, what is invariant. Then try to see if what you want to prove translates to derivatives functions of this class. Sometimes, more general problems are easier - because the particular details (like $$R$$ and $$Q$$) - do not really matter!

• Thanks you very much for your answer. This was indeed the approach I was trying to follow but I got lost on factorizing the derivatives, this trying to follow the prove is shown Wiki. Making full sense you answer in my opinion, since it doesn't prove precisely what is asked I don't know if your answer fulfill the standards for MSE's answers (is like a plot of how you got the demonstration). (...) Jul 18 at 23:20
• (...) This is why I find interesting the approach of @VarunVejalla since look more straightforward, but since it works like the demonstration of continuity by epsilon-delta approach I also found it kind of "weird": I don't know if it is really proving the smoothness in the critical points, specially since in the question he mentioned there are a few "caution" comments done by "ParamanandSingh" about the formula could diverge to something different from the derivative, (...) Jul 18 at 23:25
• (...) but maybe for this specific function of the question it works (since it don't have singularities when applying limits). I don't have enough background to judge it unfortunately, so I think I gonna decide by "upvotes". Jul 18 at 23:26

We can leverage the fact that $$f(x)=e^{-1/x} \theta(x)$$ is well-known (vanishes for $$x\le 0$$, positive for $$x>0$$ , $$C^\infty$$ smooth on $$\mathbb R$$...) to avoid "getting our hands dirty". I am of course using the standard abuse of notation ("undefined$$\times 0 = 0$$") to well-define $$f$$ at $$x=0$$. Strictly speaking, we should instead write: $$f(x) := \begin{cases} e^{-1/x}, & x>0, \\ 0,& x\le0. \end{cases}$$

$$f'(x)=\frac1{x^2}e^{-1/x} \theta(x)$$ is strictly positive for $$x>0$$. This implies that for $$x\ge 1/2$$, $$f(x)+f(1-x) \ge f(x)\ge f(1/2)>0.$$ By symmetry across $$x=1/2$$, this inequality holds for all $$x\in\mathbb R$$. Hence, inductively applying quotient rule for derivatives (and sum rule and chain rule) shows that $$g(x):=\frac{f(x)}{f(x)+f(1-x)}$$ is smooth on the whole line (this means $$C^\infty(\mathbb R)$$). And by the product rule, the product of smooth functions is smooth, so this shows (together with chain rule) that $$\tilde q(x):= g(1+x)g(1-x)$$ is also smooth on the whole line. I put a tilde(~) on top of $$q$$ to distinguish it from the function $$q$$ you defined piecewise. If you are happy with $$q=\tilde q$$ then we are done, but I will go ahead and mechanically verify this equality by hand below.

We compute the values of $$g$$ and $$\tilde q$$ at each point: for $$0, $$g(x) = \left(1+\exp\left(\frac1x - \frac1{1-x}\right)\right)^{-1},$$ $$g(x)=0$$ if $$x\le 0$$, and if $$x\ge1$$, $$g(x) = \frac{f(x)}{f(x)+0} = 1$$. Therefore, for $$x\in(0,1)$$, \begin{align} \tilde q(x) &= g(1-x)g(1+x) = g(1-x) \cdot 1 \\&= \left(1+\exp\left(\frac1{1-x} - \frac1{x}\right)\right)^{-1} \\&= \left(1+\exp\left(\frac{2x-1}{x(1-x)}\right)\right)^{-1} \\&= \left(1+\exp\left(\frac{2|x|-1}{|x|-x^2}\right)\right)^{-1}, \end{align} for $$x\in(-1,0)$$, \begin{align}\tilde q(x) &= g(1-x)g(1+x) = 1\cdot g(1+x) \\&= \left(1+\exp\left(\frac1{1+x} + \frac1{x}\right)\right)^{-1} \\&= \left(1+\exp\left(\frac{2x+1}{x(1+x)}\right)\right)^{-1} \\&= \left(1+\exp\left(\frac{-2|x|+1}{-|x|+x^2}\right)\right)^{-1}, \end{align} and $$\tilde q(0)=g(1)^2 = 1$$. Finally, $$\tilde q(x)=0$$ iff $$g(1-x)$$ or $$g(1+x)$$ equals $$0$$. Since $$g(1-x)=0$$ iff $$1-x \le 0\iff 1\le x$$ and $$g(1+x)=0$$ iff $$1+x\le 0 \iff x \le -1$$, this shows that $$q(x) = 0$$ when $$x\ge 1$$ or $$x\le -1$$, i.e. $$|x|\ge 1$$. We have verified that $$\tilde q(x)=\begin{cases} 1& x=0\\ 0& |x|\geq 1\\ \dfrac{1}{1+\exp\left(\dfrac{1-2|x|}{x^2-|x|}\right)}&\text{otherwise}\end{cases}$$

which precisely means that $$q(x) = \tilde q(x)$$ for every $$x\in\mathbb R$$.

• Thank you very much for the answer. There is something in it I think is "weird": there is a subtle thing in the step when $\tilde{q}(x)=g(1-x)g(1+x),\quad x\in (-1,1)\setminus \{0\}$ is matched with $\tilde q(x)=\left(1+\exp\left(\dfrac{1-2|x|}{x^2-|x|}\right)\right)^{-1}$ at $x=0$, here $\tilde q(x=0)\neq 1$ but instead $\tilde q(x=0)=\text{undefined}$ as is point out in this answer, and could be seen since their is a division by zero in the fraction $\dfrac{1-2|x|}{x^2-|x|}$. Hope you could elaborate why this is different on your answer. Jul 19 at 13:28
• @Joako that answer is not wrong but neither is this answer, as we define $\tilde q$ using $g$ which uses $f$ which encodes the piecewise nature with the Heaviside function. So computing $\tilde q(x)$ using the $(1+\exp(...))^{-1}$ formula is incorrect for $x=0$; that formula is only correct for $x\in(-1,1)\setminus \{0\}$. Instead, $\tilde q(x) = g(1-x)g(1+x)$ (which is always correct by definition) at $x=0$ is $g(1)^2$ which is $1$. To reiterate: it is correct that $(1+\exp(...))^{-1}$ is not defined at $x=0$, but $\tilde q$ is not defined using this function at $x=0$. Jul 19 at 13:36