Simple proof for a simple case of Hardy's inequality I am trying to prove Hardy's inequality in the case of 2, so:
$$\int_0^\infty \frac{1}{x^2} \big(\int_0^x f\big)^2 dx\leq 2\int_0^\infty f^2$$
Where f is continuous over $\mathbb{R}_+$ and such that the integral of $f^2$ converges.

The way I'm trying to do it is via an integration by parts, so what I have so far is that:
$$\int_0^y \frac{1}{x^2} \big(\int_0^x f\big)^2 dx = -y\big(\frac{1}{y} \int_0^y f\big)^2 +2\int_0^y f(x)\frac{1}{x}\int_0^xf dx$$
I am however unable to prove that any of these three terms is finite, or to obtain a term ressembling the integral of $f^2$ as necessary.
 A: A viable approach is to prove first the discrete analogue
$$ \sum_{n=1}^{N}\left(\frac{A_n}{n}\right)^2 \leq 2\sum_{n=1}^{N}\frac{a_n A_n}{n},\qquad A_n=a_1+a_2+\ldots+a_n.\tag{1} $$
Let $B_n=\frac{A_n}{n}$. We have $a_n = A_n-A_{n-1}=nB_n-(n-1)B_{n-1}$, hence
$$ B_n^2 -2a_n B_n = B_n^2 - 2B_n (nB_n-(n-1)B_{n-1})=(1-2n)B_n^2+(2n-2)B_n B_{n-1}\tag{2}$$
and since $ab\leq\frac{a^2+b^2}{2}$ we have
$$ B_n^2-2a_n B_n \leq (n-1)B_{n-1}^2-n B_n^2 \tag{3}$$
where the RHS of $(3)$ is clearly telescopic, leading to
$$ \sum_{n=1}^{N}\left(B_n^2 -2a_n B_n\right)\leq \sum_{n=1}^{N}\left((n-1)B_{n-1}^2-n B_n^2\right)=-NB_N^2\leq 0.\tag{4} $$
Now $(1)$ is proved. By the Cauchy-Schwarz inequality
$$ S_N=\sum_{n=1}^{N}\left(\frac{A_n}{n}\right)^2 \leq 2\sum_{n=1}^{N}\frac{a_n A_n}{n}\leq 2\sqrt{\sum_{n=1}^{N}a_n^2\sum_{n=1}^{N}\left(\frac{A_n}{n}\right)^2}=2\sqrt{S_N\sum_{n=1}^{N}a_n^2}\tag{5}$$
hence it follows that
$$ \sum_{n=1}^{N}\left(\frac{A_n}{n}\right)^2\leq \color{red}{4}\sum_{n=1}^{N}a_n^2.\tag{6} $$
The factor $4$ is optimal. By considering $a_n=\sqrt{n}-\sqrt{n-1}$ we have $A_n=\sqrt{n}$ and $\sum_{n=1}^{N}\left(\frac{A_n}{n}\right)^2=H_N=\log(N)+O(1)$, while
$$ \sum_{n=1}^{N}a_n^2 = \sum_{n=1}^{N}\frac{1}{(\sqrt{n}+\sqrt{n-1})^2}\geq \frac{1}{4}H_N=\frac{1}{4}\log(N)+O(1).\tag{7}$$
By approximating a function in $L^2(\mathbb{R}^+)$ through simple functions we get that
$$ \int_{0}^{+\infty}\left(\frac{1}{x}\int_{0}^{x}f(t)\,dt\right)^2\,dx \leq \color{red}{4}\int_{0}^{+\infty}f(x)^2\,dx \tag{8}$$
follows from $(6)$, where the factor $4$ is optimal.
A: Here's a trick proof using nothing but the Cauchy-Schwarz inequality. It only works for $p=2$, and it gives a constant $4$ instead of $2$ (regarding which note that Jack says $4$ is optimal and other reliable sources agree), but it's extremely simple:
First note that we can assume $f\ge0$. This will simplify the notation, and also simplify a certain technicality below.
Now note that $$\frac1{x^2}\left(\int_0^xf(t)\,dt\right)^2
=\left(\int_0^1 f(xt)\,dt\right)^2=\int_0^1\int_0^1f(xt)f(xs)\,dtds.$$
(Changing the square of that integral into a double integral is why I call this a "trick" proof. I suspect you could do something similar if $p>2$ is an integer...)
Inserting this above and changing the order of integration you get
$$\int_0^\infty\frac1{x^2}\left(\int_0^xf(t)\,dt\right)^2\,dx
=\int_0^1\int_0^1\int_0^\infty f(xt)f(xs)\,dxdtds.$$
Detail: Someone objected to changing the order of integration without being careful about the hypotheses. Worrying about this is admirable, but in fact here there's no problem, since everything in sight is positive, and Tonelli's theorem says that Fubini is always ok for positive functions.
Now Cauchy-Schwarz shows that
$$\int_0^\infty f(xt)f(xs)\,dx\le\left(\int_0^\infty f(xt)^2\,dt\right)^{1/2}\left(\int_0^\infty f(xs)^2\,dt\right)^{1/2}
=s^{-1/2}t^{-1/2}\int_0^\infty f(x)^2\,dx,$$so
$$\int_0^\infty\frac1{x^2}\left(\int_0^xf(t)\,dt\right)^2\,dx\le\int_0^1\int_0^1s^{-1/2}t^{-1/2}\,dtds\int_0^\infty f(x)^2\,dx=4\int_0^\infty f(x)^2\,dx.$$
A: There is a very simple solution, from which I was averted by the fact that I thought it was a dead end (and quoted it as so in my question).
The integration by parts gave us:
$$\int_0^y \frac{1}{x^2} \big(\int_0^x f\big)^2 dx = -y\big(\frac{1}{y} \int_0^y f\big)^2 +2\int_0^y f(x)\frac{1}{x}\int_0^xf dx$$
Therefore,
$$\int_0^y \frac{1}{x^2} \big(\int_0^x f\big)^2 dx \leq 2\int_0^y f(x)\frac{1}{x}\int_0^xf dx \leq 2\sqrt{\int_0^y f^2 \int_0^y\frac{1}{x^2}\big(\int_0^xf \big)^2dx}$$
And thus, by dividing by a non-zero value and squaring:
$$\int_0^y \frac{1}{x^2} \big(\int_0^x f\big)^2 dx \leq 4\int_0^y f^2$$
(note that if the integral is zero, then it is clear that the inequality is trivial)
