TITLE: If $f^2$ and $f^3$ are $C^{\infty}(\mathbb R)$ then $f$ is $C^{\infty}(\mathbb R)$
QUESTION [13 upvotes]: Since it is an exercise from an oral exam, I have added some indications I had.
$f : \mathbb R \to \mathbb R$, such that $f^2$ and $f^3$ are $C^{\infty}$, show that $f$ is $C^{\infty}$.
The two isolated hypothesis are not sufficient, since there is a problem in zero for the cube root, and since you can take $f$ that takes $1$ and $-1$ without regularity but its square will be constant.
How to proceed with the two hypothesis?

Here, the indications I have from the candidate who has taken the oral exam:
-First, show that $f$ is $C^1$:
Suppose $f(0) = 0$ (it is exactly the problem, and by translation we consider that it is in $0$). Suppose they exist and use the Taylor expansions of $f^2$ and $f^3$ up to a non-zero order. Find a polynomial link between both coefficients using equivalents. If they do not exist, $f^2 =o(h^4)$ so $f$ is $C^1$ in $0$ (?).
-Use the general Taylor expansion (with integral remain) for $f^3$.  Suppose the coefficients are not all zeros, (change the bounds to $0$ and $1$), show that the parameter integral is $C^{\infty}$, then take the cube root (??).

REPLY [5 votes]: This result was first proved in: 

Henri Joris, Une $C^\infty$ application non-immersive qui possède la propriété universelle des immersions, Arch. Math. (Basel), 39, 269-277, 1982. 

The proof we provide follows the general framework of the proof which appears in: 

Robert Myers, An Elementary Proof of Joris's Theorem, Amer. Math. Monthly, 112, no. 9, 829-831, 2005. 

We shall use the following notation
$$
P_{n,x_0}(x;F)=F(x_0)+F^{(1)}(x_0)(x-x_0)+\frac{F^{(2)}(x_0)}{2!}(x-x_0)^2
+\cdots+\frac{F^{(n)}(x_0)}{n!}(x-x_0)^n.
$$
where $F$ is a function $n$ times differentiable in some open interval $(a,b)$ 
containing $x_0$. We shall be using the following lemmata:
Lemma 1. Let $F: (a,b)\to\mathbb R$ be a function possessing all derivatives up to order $n$, for some $x_0\in(a,b)$. 
$F^{(1)}(x_0),\ldots,F^{(n)}(x_0)$. Then
$$
\lim_{x\to x_0}\frac{F(x)-P_{n,x_0}(x;F)}{(x-x_0)^n}=0.
$$
Proof. See Spivak.
Lemma 2. Let $\,F: (a,b)\to \mathbb R\,$ be function which is $k$ times differentiable in $(a,b)$ and $k+1$ times differentiable in $(a,b)\setminus\{x_0\}$, where $x_0\in(a,b)$. If
$$
L=\lim_{x\to x_0} \frac{F(x)-P_{k,x_0}(x;F)}{(x-x_0)^{k+1}} \in\mathbb R,
$$
then $f$ possesses derivative of $k+1$ order at $x_0$, and
$F^{(k+1)}(x_0)=(k+1)! L.$
Proof. Use L' Hôpital's Rule. 
Lemma 3.
Let $F\in C^{k+n}(a,b),\,$ $x_0\in(a,b),\,$ and
$$
G(x)=\left\{\begin{array}{ccl}
\dfrac{F(x)-P_{k,x_0}(x;F)}{( x-x_0)^{k+1}} & \text{if} & x\ne x_0, \\
(k+1)! F^{(k+1)}(x_0) & \text{if} & x= x_0, \\
\end{array}
\right.
$$
then $G\in\ C^n(a,b)$. In particular, if $\,F\in C^\infty(a,b)$, then $\,G\in C^\infty(a,b)$.
Proof. Use induction on the degree of 
$P_{k,x_0}$ and evoke Lemma 2.
Proof of Joris's Theorem.  Let us first note that, 
if $f(x_0)\ne 0$, for some  $x_0\in\mathbb R$, then $f$ maintain sign in a whole
open interval $I$, with $x_0\in I$, and as $h=f^3$ is $C^\infty$ in $I$, then $f$ is also $C^\infty$ in $I$, as the composition of $x^{1/3}$,
which is $C^\infty$ in $\,\mathbb R\setminus\{0\}\,$ and $f^3$. The hard part is to show that $f$ is $C^\infty$, where $f$ vanishes. We set 
$$
Z=\{x\in\mathbb R: f(x)=0\}
$$ 
and let $\,x_0\in Z$. We shall study separately the cases where
$x_0$ is an isolated point of $Z$ from the case where $x_0$ is an accumulation point of $Z$. 
It is important to point out that, in order for $f^{(k+1)}(x_0)$ to be definable, $f$ has to be $k$ times differentiable in an interval containing $x_0$.
Case A. $x_0$ is an isolated point of $Z$.
First sub-case. $\,h^{(n)}(x_0)=0,\,$ for all $n\in\mathbb N$.
We shall show in this sub-case that all the derivatives of $f$ exists
at $x=x_0$ and they all vanish.
Due to Lemma 1 we have that
$$
0=\lim_{x\to x_0}\frac{h(x)}{(x-x_0)^n}=\lim_{x\to x_0}\frac{f^3(x)}{(x-x_0)^n}, \quad 
\text{for all $n\in\mathbb N$,}
$$
since $P_{n,x_0}(x;h)\equiv 0$. Hence $\,\displaystyle\lim_{x\to x_0}\dfrac{f(x)}{(x-x_0)^n}=0$, for all $n\in\mathbb N$. 
In particular
$$
\lim_{x\to x_0}\frac{f(x)-f(x_0)}{x-x_0}=\lim_{x\to x_0}\frac{f(x)}{x-x_0}=0,
$$
and therefore $f$ is differentiable at $x=x_0$, and $f'(x_0)=0$. We shall show inductively that, for every $n\in\mathbb N$,the function $f$ is $n$ times differentiable at $x=x_0$ and $f^{(0)}(x_0)=f^{(1)}(x_0)=\cdots=f^{(n)}(x_0)=0$.  Assume that this is true for some $\,k\in\mathbb N$. 
Then $P_{k,x_0}(x;f)\equiv 0$ and thus Lemma 2 provides that $f$ is $k+1$ differentiable at $x=x_0$ and $f^{(k+1)}(x_0)=0$.
Second sub-case. There exists an $\,n\in\mathbb N$, such that $\,h^{(n)}(x_0)\ne 0$.
Let $k$ be the least positive integer, such that $\,h^{(k)}(x_0)\ne 0$. 
Lemma 3 provides that, there exists a function $\,H\in C^\infty(\mathbb R)$,
such that $\,h(x)=(x-x_0)^kH(x)$, with $H(x_0)\ne 0$. In particular, there exists an interval $\,(a,b)$, with $x_0\in (a,b)$, where $H$ maintains sign. 
Meanwhile we have that
$$
g^3(x)=h^2(x)=(x-x_0)^{2k}H^2(x),
$$
and hence,
$$
g(x)\big(H^2(x)\big)^{-1/3}=\big((x-x_0)^{3k}\big)^{1/3},
\quad\text{for all $x\in (a,b)$}.
$$
The right hand side of the above is $C^\infty$ in $(a,b)$, which implies that $2k/3$ is an integer, and hence $k=3k_1$, for some positive integer $k_1$. Thus
$h(x)=(x-x_0)^{3k_1}H(x)$, and consequently 
$$
f(x)=(x-x_0)^{k_1}H^{1/3}(x),
$$
and hence $f$ is $C^\infty$ in $(a,b)$.
Case B. $x_0$ is an accumulation point of $Z$.
In such case, there exists a sequence $\,\{x_n\}\subset Z$, such that $x_n\to x_0$. We may assume that this sequence in strictly monotone. Without loss of generality we assume that $\{x_n\}$ strictly increasing. Then
$$
0=h(x_1)=h(x_2)=\cdots=h(x_n)=\cdots.
$$
Due to Rolle's Theorem, there exist $\xi_i \in(x_i,x_{i+1})$, such that
$$
0=h'(\xi_1)=h'(\xi_2)=\cdots=h'(\xi_n)=\cdots.
$$
Thus $\,h'(x_0)=0$, since $h'$ is continuous and $\xi_n\to x_0$. Repeating the same procedure for $h'$ instead of $h$, we obtain that $h''(x_0)=0$, and 
inductively that $\,h^{(n)}(x_0)=0$, for all $n\in\mathbb N$. 
As in the study of the First sub-case, we obtain, by virtue of Lemma 1, that 
$$
0=\lim_{x\to x_0}\frac{h(x)}{(x-x_0)^n}=\lim_{x\to x_0}\frac{f^3(x)}{(x-x_0)^n}, \quad 
\text{for all $n\in\mathbb N$,}
$$
and thus
\begin{equation*}
\lim_{x\to x_0}\frac{f(x)-f(x_0)}{x-x_0}=\lim_{x\to x_0}\frac{f(x)}{x-x_0}=0.
\end{equation*}
Therefore, $f$ is differentiable at $x=x_0$, and $f'(x_0)=0$. Next, we shall show inductively that $f$ possesses derivatives of all orders at $x=x_0$, and that they all vanish. Combining all the studied cases so far we have that $f$ is differentiable in the whole of $\mathbb R$. We shall use induction to prove our claim. 
Assume that $f$ is $k$ times differentiable in $\mathbb R$ and also
$$
f^{(0)}(x_0)=f^{(1)}(x_0)=\cdots=f^{(k)}(x_0)=0,
$$
in every $x_0$, which is an accumulation point of $Z$. Then $f$ is $k+1$ times differentiable in the whole of $\mathbb R$, and $f^{(k+1)}(x_0)=0$, for every $x_0$, which is an accumulation point of $Z$. We have that 
$$
\lim_{x\to x_0}\frac{f(x)}{(x-x_0)^n}=0,
$$
for every $x_0$ which is an accumulation point of $Z$, and by virtue of Lemma 2,
$f$ possesses derivative of order $k+1$ in every such $x_0$. Combining all the studied cases we obtain that $f$ is $k+1$ times differentiable in the whole of $\mathbb R$. This establishes the induction hypothesis and completes the proof of Joris's Theorem.
Note. This proof can be easily generalised for the case when $\,f^k,f^\ell\in C^\infty(\mathbb R)$ and $(k,\ell)=1$.