Integration by substitution, but I can't deduce what is happening here $$\int \left(f^{''}(x)\right)^2 dx = \int f^{''}(x)df^{'}(x) = - \int f^{'''}(x)f^{'}(x)dx = -\int f^{'''}(x)df(x) = \int f^{(4)}(x)f(x)dx$$
I understand the first and third equalities, but I don't get what happened in the second and fourth.
The first equality is a substitution $u=f^{'}(x)$, and similarly the third is $u=f(x)$. However I'm not so sure about the second and fourth. Since the idea should be integration by substitution, I thought of something like this:
$$\int f^{''}(x)df^{'}(x) = \int f^{''}(x)\cdot 1 df^{'}(x) = f^{''}(x)\cdot f^{'}(x) - \int \frac{df^{''}(x)}{df^{'}(x)}f^{'}(x) df^{'}(x).$$
However, what is $\frac{df^{''}(x)}{df^{'}(x)}$? And even if $\frac{df^{''}(x)}{df^{'}(x)} = f^{'''}(x)$, where did $ f^{''}(x)\cdot f^{'}(x)$ go? Something feels suspicious here.
Edit: I meant to say 'the idea should be integration by parts'. On the second equation 'group' I tried the int by parts idea but can't figure it out.
 A: Recall if things are nice, then $\int_{\Bbb{R}}gf'=-\int_{\Bbb{R}}g'f$. So, doing this twice, we get
\begin{align}
\int_{\Bbb{R}}gf''=-\int_{\Bbb{R}}g'f'=\int_{\Bbb{R}}g''f.
\end{align}
Now, take the special case $g=f''$ to recover the claimed identity $\int_{\Bbb{R}}(f'')^2=\int_{\Bbb{R}}f^{(4)}f$.
A: If we are talking about definite integrals, the equalities are probably held provided that $$
f^{\prime \prime}(x) f^{\prime}(x)-f^{\prime \prime \prime}(x) f(x) \textrm{ vanishes for the limits.} 
$$
If we are talking about definite integrals, using integration by parts, we have the following equalities:
$$
\begin{aligned}
\int\left(f^{\prime \prime}(x)\right)^2 d x & =\int f^{\prime \prime}(x) d\left(f^{\prime}(x)\right) \\
& =f^{\prime \prime}(x) f^{\prime}(x)-\int f^{\prime}(x) f^{\prime \prime \prime}(x) d x \\
& =f^{\prime \prime}(x) f^{\prime}(x)-\int f^{\prime \prime \prime}(x) d(f(x)) \\
& =f^{\prime \prime}(x) f^{\prime}(x)-f^{\prime \prime \prime}(x) f(x)+\int f^{(4)}(x) f(x)dx
\end{aligned}
$$
