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 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.