composition of $L^{p}$ functions

Suppose $f, g\in L^{p}(\mathbb R), (1\leq p < \infty).$

For simplicity, let us assume that, $g,f:\mathbb R\to \mathbb R$ so that composition of $f$ and $g$, namely,
$f\circ g(x)= f(g(x)); (x\in \mathbb R)$
is well-defined.

My Question is: Given real-valued functions $f,g \in L^{p}(\mathbb R).$ Can we expect its composition $f\circ g$ is again in $L^{p}(\mathbb R)$ ? If not, under what condition on $f$ one can expect that, $f\circ g\in L^{p}(\mathbb R)$ for all $g\in L^{p}(\mathbb R).$ ?

Thanks,

Solutions Collecting From Web of "composition of $L^{p}$ functions"

It is very easy to see that $f\circ g\in L^{p}\left(\mathbb{R}\right)$
holds for all $g\in L^{p}\left(\mathbb{R}\right)$ if $f$ is Borel
measurable with $\left|f\left(x\right)\right|\leq C\cdot\left|x\right|$
for all $x\in\mathbb{R}$ and some (fixed) $C\geq0$, so I will only
show the converse (and I will not go into Borel-measurability, because that is a rather natural condition).

To this end, first observe that $f\left(0\right)=0$, because otherwise
$f\circ0\notin L^{p}\left(\mathbb{R}\right)$, where $0$ is the constant
function $x\mapsto0$. Now assume (for a contradiction) that there
is no such $C\geq0$. We will construct pairwise distint numbers $x_{1},\dots,\in\mathbb{R}$
with $\left|f\left(x_{i}\right)\right|>i\cdot\left|x_{i}\right|$
for all $i\in\mathbb{N}$. This in particular implies $x_{i}\neq0$
for all $i$, because of $f\left(0\right)=0$.

For $i=1$, observe that by assumption $C=1$ is no valid choice,
so that there is some $x_{1}\in\mathbb{R}$ with $\left|f\left(x_{1}\right)\right|>1\cdot\left|x_{1}\right|$.

Now, assume that $x_{1},\dots,x_{n}$ have already been constructed.
By assumption, there is some $x_{n+1}\in\mathbb{R}$ with
$$
\left|f\left(x_{n+1}\right)\right|>\max\left\{ n+1,\frac{\left|f\left(x_{1}\right)\right|}{\left|x_{1}\right|},\dots,\frac{\left|f\left(x_{n}\right)\right|}{\left|x_{n}\right|}\right\} \cdot\left|x_{n+1}\right|\geq\left(n+1\right)\cdot\left|x_{n+1}\right|,
$$
because otherwise, $C=\max\left\{ n+1,\frac{\left|f\left(x_{1}\right)\right|}{\left|x_{1}\right|},\dots,\frac{\left|f\left(x_{n}\right)\right|}{\left|x_{n}\right|}\right\} $
would be a valid choice. Note that the above inequality shows that
$x_{n+1}\notin\left\{ x_{1},\dots,x_{n}\right\} $, so that the $\left(x_{n}\right)_{n\in\mathbb{N}}$
are indeed pairwise distinct.

Now define $y_{n}:=\sum_{i=1}^{n}\frac{1}{i^{2}\left|x_{i}\right|^{p}}$
for $n\in\mathbb{N}_{0}$, so that $\left(y_{n}\right)_{n\in\mathbb{N}_{0}}$
is strictly increasing, which entails that the intervals $\left(\left(y_{n-1},y_{n}\right)\right)_{n\in\mathbb{N}}$
are pairwise disjoint, and set
$$
g:=\sum_{n=1}^{\infty}\chi_{\left(y_{n-1},y_{n}\right)}\cdot x_{n}.
$$
This implies
$$
\left\Vert g\right\Vert _{p}^{p}=\sum_{n=1}^{\infty}\int_{y_{n-1}}^{y_{n}}\left|x_{n}\right|^{p}\, dx=\sum_{n=1}^{\infty}\left(y_{n}-y_{n-1}\right)\cdot\left|x_{n}\right|^{p}=\sum_{n=1}^{\infty}\frac{\left|x_{n}\right|^{p}}{n^{2}\cdot\left|x_{n}\right|^{p}}<\infty.
$$
But we also have (because the intervals are pairwise disjoint)
$$
\left(f\circ g\right)\left(x\right)=\sum_{n=1}^{\infty}\chi_{\left(y_{n-1},y_{n}\right)}\cdot f\left(x_{n}\right)
$$
and hence
\begin{eqnarray*}
\left\Vert f\circ g\right\Vert _{p}^{p} & = & \sum_{n=1}^{\infty}\int_{y_{n-1}}^{y_{n}}\left|f\left(x_{n}\right)\right|^{p}\, dx\geq\sum_{n=1}^{\infty}\int_{y_{n-1}}^{y_{n}}n^{p}\cdot\left|x_{n}\right|^{p}\, dx\\
& = & \sum_{n=1}^{\infty}\frac{n^{p}\cdot\left|x_{n}\right|^{p}}{n^{2}\cdot\left|x_{n}\right|^{p}}=\sum_{n=1}^{\infty}n^{p-2}=\infty,
\end{eqnarray*}
because of $p\geq1$, which entails $p-2\geq-1$.

But by assumption, $f\circ g\in L^{p}\left(\mathbb{R}\right)$. This
contradiction shows that $\left|f\left(x\right)\right|\leq C\cdot\left|x\right|$
must indeed be true for all $x\in\mathbb{R}$ and some $C\geq0$.

Note that basically the same proof works for $p > 0$, because one can take any power $\alpha \in (1,2)$ in the definition of $y_n$, i.e. one can take $y_{n}:=\sum_{i=1}^{n}\frac{1}{i^{\alpha}\left|x_{i}\right|^{p}}$ and will still have $g \in L^p$.