# Is a probability density function necessarily a $L^2$ function?

If a nonnegative continuous real valued function $f$ is integrable over $\mathbb{R}$ with $$\int_\mathbb{R} f\,\mathrm{d}x = 1,$$ does it hold true $$\int_\mathbb{R} f^2 \,\mathrm{d}x<\infty?$$

Motivation: I am wondering if the mean squared error (MSE) is well defined, since we need the target density function to be in $L^2$ space in order to have a finite MSE.

• For the mean squared error to be defined, don't you rather need to have $\int_{\mathbb{R}}x^2 f(x)\,dx<\infty$? In any case, the answer to the question as asked is no. For a counterexample, assume $f(x)$ is proportional to $x^{-1/2}$ for small positive $x$. Apr 16, 2014 at 16:36
• This is the definition of squre-integrability for a random variable having density $f$, it's a different notion. The MSE the OP refers to arises for example in problems of function estimation, where it is usually assumed that the "true" density belongs to appropriate $L^2$ space. Apr 16, 2014 at 16:43
• I think the answer is no, even if $f$ is continuous. I can think of a pathological example of a continuous integrable function that is not square integrable. (It is slightly awkward to write down explicitly, but I'm thinking of a function with an infinite number of "bumps" whose heights tend to $\infty$ and whose widths tend to $0$.) Apr 16, 2014 at 17:21

The answer is no. But your continuity requirement makes it more difficult to find an explicit (constructed) example.

Define the function $\varphi$ on $\mathbb{R}$ as: $$\forall x\in\mathbb{R},\quad\varphi(x)=\begin{cases}\sin(x)&\text{if x\in[0,\pi]}\\0&\text{otherwise.}\end{cases}$$ Clearly, the function $\varphi$ is continuous on $\mathbb{R}$ (it's just a single arch of sine). It is well-known that $\lVert\varphi\rVert_1=2$ and that $\lVert\varphi\rVert_2^2=\pi/2$.

Define the sequence of function $(\varphi_n)_{n\geq1}$ on $\mathbb{R}$ by: $$\forall n\geq1,\quad\forall x\in\mathbb{R},\quad\varphi_n(x)=\varphi\bigl(8^n(x-2n\pi)\bigr).$$

It should be clear that the support of the $\varphi_n$'s are all distinct: the support of $\varphi_n$ is $(2n\pi,8^{-n}\pi+2n\pi)$.

Moreover, for all $n\geq1$, $$\lVert\varphi_n\rVert_1=\int_{\mathbb{R}}\varphi_n(x)\,\mathrm{d}x=\frac2{8^n}\quad\text{and}\quad\lVert\varphi_n\rVert_2^2=\int_{\mathbb{R}}\varphi_n(x)^2\,\mathrm{d}x=8^{-n}\frac{\pi}2.$$

Now, define the series of functions $f$ by: $$\forall x\in\mathbb{R},\quad f(x)=\frac12\sum_{n=1}^{+\infty}4^n\varphi_n(x)$$ (the graph of $f$ consists of bumps that are narrower but higher). It should be clear that $f$ is well-defined and continuous and non-negative. Since the support of the $\varphi_n$'s are distinct, we can integrate $f$ term by term: $$\lVert f\rVert_1=\int_{\mathbb{R}}f(x)\,\mathrm{d}x=\frac12\sum_{n=1}^{+\infty}4^n\int_{\mathbb{R}}\varphi_n(x)\,\mathrm{d}x=\sum_{n=1}^{+\infty}\frac{4^n}{8^n}=1.$$

Also, since the support of the $\varphi_n$'s are distinct, for all $x\in\mathbb{R}$: $$f(x)^2=\frac14\sum_{n=1}^{+\infty}16^n\varphi_n(x)^2$$ and $$\lVert f\rVert_2^2=\int_{\mathbb{R}}f(x)^2\,\mathrm{d}x =\frac14\sum_{n=1}^{+\infty}16^n\lVert\varphi_n\rVert_2^2=\frac14\sum_{n=1}^{+\infty}2^n\frac\pi2=+\infty.$$

• Nice answer (+1). I wonder if what happens if $f$ has to be differentiable. Would be possible to construct a counterexample in such a case? Jan 24, 2016 at 14:22
• @epsilone: of course it's possible ; it's even possible to have it of class $C^\infty$: replace the “generating” function $\varphi$ by something of class $C^\infty$, using a “flat” function of the form $$x\mapsto\begin{cases}\mathrm{e}^{-1/(x^2(x-1)^2)}&\text{if x\in(0,1)}\\0&\text{otherwise.}\end{cases}$$ Jan 24, 2016 at 14:53
• Thanks for the follow-up :) Good point, I guess I was puzzled on how to properly make $\varphi$ be zero outside $(0,1)$ while keeping differentiability at those points. But flat functions are quite handy for that purpose! Jan 24, 2016 at 15:06