Proof of Hardy inequality in $\mathbb{R}^n$ I've often seen people use the inequality 
$$\int_{\mathbb R^3} \frac{|u(x)|^2}{|x|^2}\,dx  \leq 4\int_{\mathbb R^3}|\nabla u(x)|^2\,dx,\qquad u\in C_0^\infty(\mathbb R^3) $$
without proof, refering to it as "Hardy's inequality". 
I struggled to find a direct proof of this in the literature and couldn't prove it myself. Does anyone know a straightforward proof of this or a book in which Hardy's inequality in this form is proved?
I would also be interested in the general form of this inequality, i.e. what happens if one replaces $\mathbb R^3$ with $\mathbb R^n$?
 A: This is in Evans' PDE book, page 296 in the second edition. The following discussions on this proof may also be useful,


*

*Hardy's inequality 

*A technical step in proving Hardy's inequality
However, it doesn't seem like the constant 4 is explicitly computed in Evans, and moreover it may be improved if the domain of $u$ is not convex. In the dimension 1 variant, it is optimal, and you can refer to Computing the best constant in classical Hardy's inequality. In higher dimensions, you may want to look at this paper On the best constant for Hardy's inequality in $\mathbb R^n$ by Marcus, Mizel and Pinchover, and its references.
A: I learned the following integration by parts method to prove Hardy inequalities from Luca Fanelli.
Assume that all functions are real-valued and define operators on $C^{\infty}_c(\mathbb R^d\setminus\{0\})$ by
$$
Su(x)=\frac{xu(x)}{|x|^2},\qquad Au(x)=\nabla u(x).$$
Notice that the sought inequality reads
$$
\int_{\mathbb R^d} \lvert Su(x)\rvert^2\,dx \le C\int_{\mathbb R^d} \lvert Au(x)\rvert^2\, dx.$$
So, for a $k\in \mathbb R$ yet to be determined, consider
$$\begin{split}
0&\le \int_{\mathbb R^d} \lvert Su+kAu\rvert^2\, dx\\&=\int_{\mathbb R^d} \lvert Su(x)\rvert^2\, dx +k^2\int_{\mathbb R^d} \lvert Au(x)\rvert^2\, dx+2k\int_{\mathbb R^d} Su(x)\cdot Au(x)\, dx.
\end{split}$$
The last summand is
$$
\int_{\mathbb R^d} Su\cdot Au\, dx=\int_{\mathbb R^d}  \frac{x}{\lvert x\rvert^2}\cdot u\nabla u\, dx =\int_{\mathbb R^d} \frac{x}{\lvert x \rvert^2}\cdot \nabla \left(\frac{u^2}{2}\right)\, dx, $$
and since
$$\nabla \cdot \frac{x}{\lvert x\rvert^2}=\frac{d-2}{\lvert x \rvert^2}, $$
integration by parts reveals that
$$\tag{*}
\int_{\mathbb R^d} Su(x)\cdot Au(x)\, dx = -\frac{d-2}{2}\int_{\mathbb R^d} \lvert Su(x)\rvert^2\,dx.$$
Going back to the first inequality, we have that
$$
0\le k^2\int_{\mathbb R^d} \lvert Au(x)\rvert^2\, dx+(1-(d-2)k)\int_{\mathbb R^d} \lvert Su(x)\rvert^2\, dx, $$
which is a second-degree polynomial in $k$, and it attains its minimal value for $k=\frac{d-2}{2}\frac{\int \lvert Su\rvert^2}{\int \lvert Au\rvert^2}$. Plugging this into the last inequality finally yields
$$
\int_{\mathbb R^d} \lvert Su(x)\rvert^2\, dx \le \left( \frac{2}{d-2}\right)^2\int_{\mathbb R^d} \lvert Au(x)\rvert^2\, dx, $$
which is the result we wanted. $\Box$

Remark 1. The multiplicative constant $\left( \frac{2}{d-2}\right)^2$ turns out to be sharp, but proving this needs further work.
Remark 2. This method of proof is interesting because it has some robustness. Changing the definition of $S$ and $A$ may yield more inequalities, provided that some suitable replacement of the identity  (*) holds. For example, taking
$$
Su(x)=\frac{u(x)}{\lvert x \rvert}, \qquad Au(x)=\frac{x}{\lvert x\rvert}\cdot \nabla u(x)$$
yields the following refinement of the Hardy inequality;
$$
\int_{\mathbb R^d} \frac{u^2(x)}{\lvert x \rvert^2}, dx \le \left( \frac{2}{d-2}\right)^2\int_{\mathbb R^d} \lvert \partial_r u(x)\rvert^2\, dx, $$
where $\partial_r$ stands for the radial derivative. This inequality is tighter than the previous one, because the right-hand side is smaller; indeed, here there are no angular derivatives.
