Under what conditions do we have $\int_{0}^{\infty} |f(x)|^2 dx \leq C \int_{0}^{\infty} x^2 |f^{\prime}(x)|^2 dx$? I have been trying to prove the inequality 

$$\int_{0}^{\infty} |f(x)|^2 dx \leq C \int_{0}^{\infty} x^2 |f^{\prime}(x)|^2 dx$$

for some constant $C$, under the most general set of assumptions possible. Obviously we need to have that $f$ is square-integrable and differentiable.
I can prove a version of the inequality with $C=4$, provided that additionally $x |f(x)|^2 \to 0$ as $x\to \infty$ (the proof is by integration by parts and the Cauchy-Schwartz inequality). Can this be improved? Thank you.
 A: Here are some thoughts about this question. My guess is that $C=4$ is the optimal value. The computations below are not totally rigorous and some arguments are missing. This can only give some directions for the question.
Consider the function $f$ defined on $[0, +\infty)$ as follows, with $a>1/2$ and $\varepsilon \in [0,1/10]$:
$$
f(x)=x^a\quad \mbox{ if } x\leq 1-\varepsilon \quad \mbox{and}\quad f(x)=x^{-a}\quad\mbox{ if } x\geq 1+\varepsilon.
$$
On $[1-\varepsilon, 1+\varepsilon]$ construct $f$ such as it is globally of class $\mathcal{C}^1$.
$f$ verifies the conditions and we have
$$
f'(x)=ax^{a-1}\quad \mbox{ if } x\leq 1-\varepsilon \quad \mbox{and}\quad f(x)=-ax^{-a-1}\quad\mbox{ if } x\geq 1+\varepsilon.
$$
Assuming $f'$ is bounded on $[1-\varepsilon, 1+\varepsilon]$ we can compute both integrals and we get, taking $\varepsilon \to 0$:
$$J\doteq \int_0^{\infty} f(x)^2\mbox{d}x\approx\int_0^1x^{2a}\mathrm{d}x+\int_1^{\infty}x^{-2a}\mathrm{d}x=\dfrac{4a}{4a^2-1}.$$
And similarly
$$K\doteq \int_0^{\infty} x^2f'(x)^2\mbox{d}x\approx\int_0^1 a^2 x^{2a}\mathrm{d}x+\int_1^{\infty} a^2 x^{-2a}\mathrm{d}x=a^2\dfrac{4a}{4a^2-1}=a^2 J.$$
Finally $$J\approx K/a^2.$$
Taking $a$ close from $1/2$ we obtain $J \approx 4 K$, indicating that $4$ should be the optimal constant. 
Note nevertheless that when $a \to 1/2$, we have $J \sim \dfrac{1}{2a-1}$ which diverges.
A: You say you can prove it if $x|f(x)|^2\to0$. It seems very likely that your proof can be modified to work without that extra assumption.
Because there must exist $x_n\to\infty$ such that $x_n|f(x_n)|^2\to0$; if not then $|f(x)|^2\ge c/x$ for all $x\ge A$, which implies that $\int|f(x)|^2=\infty$.
I haven't seen your proof, but "surely" it works just using integration by parts on the interval $(0,x_n)$ instead of an arbitrary interval.
