Show that $\int_{-\infty}^\infty fg'dx = -\int_{-\infty}^\infty f'g \space dx$ in the space of square-integrable functions. Suppose that $f$ and $g$ are continuously differentiable real-valued functions on $\mathbb{R}$ with $f,g,f',g' \in L^2(\mathbb{R})$. Show that
$$\int_{-\infty}^\infty fg'dx = -\int_{-\infty}^\infty f'g \space dx$$
Solution:
This implies that $\int_{-\infty}^\infty|f(x)||g(x)| \space dx < \infty$ and hence that there are sequences ${x_i}_{i=1}^\infty, {y_i}_{i=1}^\infty$ such that $\lim_{i \rightarrow \infty}x_i=-\infty$ and $\lim_{i \rightarrow \infty}y_i=\infty$ and $\lim_{i \rightarrow \infty}f(x_i)g(x_i)=\lim_{i \rightarrow \infty}f(y_i)g(y_i)=0$
Then
$$\int_{-\infty}^{\infty}(fg'+f'g) dx = \lim_{i\rightarrow \infty}\int_{x_i}^{y_i}(fg'+f'g) dx = \lim_{i \rightarrow \infty}(f(y_i)g(y_i)-f(x_i)g(x_i)) =0$$
Question: Honestly - I don't understand a single line of this proof. Specifically, why must those sequences exist to begin with, and why do they have the behavior described? I'm really lost here...can you help me relate this to facts from analysis?
 A: If the sequences did not exist, then there exists $\epsilon>0$ with $|f(x)g(x)|>\epsilon$ for all $x\gg0$ or for all $x\ll 0$.
Now let $F(x)=f(x)g(x)$. Then $F'(x)=f'(x)g(x)+f(x)g(x)$ and so $\int_{x_i}^{y_i}(f'(x)g(x)+f(x)g(x))\,\mathrm dx= F(y_i)-F(x_i)$
A: What you probably intuitively would want to do is using integration by parts
$$ \int_a^b f'g dx = [fg]_a^b - \int_a^b fg'dx $$
However, there is a problem here since, although for many concrete examples of $L^2$ functions $\lim_{|x|\to\infty}f(x) = 0$, this is not always the case. Consider e.g.
$$ \phi(x) = \begin{cases} n:& x\in[n,n+\frac{1}{n^4}], n\in\mathbb N \\ 0:& \text{else}  \end{cases} $$
Here, $\int \phi^2 dx = \sum 1/n^2 = \pi^2/6$ but clearly $\phi(x)\not\to 0$ as $x\to\infty$. How can we fix the intuition that a $L^p$ function should go $0$ so that the integral converges? The correct way to think about it is that the local average needs to go to zero in the sense that
$$ f\in L^p \implies \forall \epsilon>0 \lim_{a\to\infty} \int_{a}^{a+\epsilon} |f(x)|^p dx =0 \qquad (I)$$
Coming back to your original problem this shows that the given solution is not a very good one, since if we chose different sequences $x_i,y_i$, then the limit doesn't necessarily go to $0$. Indeed if we chose $f,g$ as differentiable versions of $h$, them the limit even goes to $+\infty$ for certain sequences!
Observe the following:
\begin{align}
\int_{-\infty}^{+\infty} h'(x) dx
&=\lim_{(a,b)\to(-\infty,+\infty)}\int_a^b \lim_{\epsilon\to 0} \frac{h(x+\epsilon)-h(x)}{\epsilon}dx
\\&= \lim_{(a,b)\to(-\infty,+\infty)}\lim_{\epsilon\to 0}\frac{1}{\epsilon}\Big(\int_{a+\epsilon}^{b+\epsilon}h(x)dx - \int_a^b h(x)dx\Big)
\\&= \lim_{(a,b)\to(-\infty,+\infty)}\lim_{\epsilon\to 0}\frac{1}{\epsilon}\Big( \int_b^{b+\epsilon} h(x)dx -\int_{a}^{a+\epsilon}h(x)dx\Big)
\end{align}
Now we are at a critical point: if we first evaluate the $\epsilon$ limit, then we get
$$  \lim_{(a,b)\to(-\infty,+\infty)} h(b)-h(a) $$
which may or may not exist as discussed above. However if we first evaluate the boundary limits we obtain $0$ by $(I)$. This apparent dilemma is resolved by the fact that we actually work with the Lebesgue integral which means that improper integrals of the type $\int_{-\infty}^{+\infty}f(x)dx$ are not evaluated as limits as we did above. 
Instead, the proof should rely on using the properties of the Lebesgue integral: we have that, by the Dominated convergence theorem 
$$ \lim_{\epsilon\to 0 }\int_{\mathbb R}|h_\epsilon - h'| dx = 0$$ 
where $h_\epsilon = (h(x+\epsilon)-h(x))/\epsilon$. Consequently:
$$ \int_{\mathbb R}h'(x) dx = \lim_{\epsilon\to 0}\int_{\mathbb R} h_\epsilon(x) dx = \lim_{\epsilon\to 0} 0 = 0$$
A: The first inequality is Cauchy Schwarz.
The second is a proprety of integrable positive functions they must vanish at infinity.
The last one is the relation $\int F'=F$ 
