Error in evaluating $\int \left( \frac{df}{dx} \right)^2 dx$. I am playing around with some integrals and I am in need of helping to spot an error in my manipulations.
Let $f:\mathbb R \rightarrow \mathbb R$ be an arbitrary $C^\infty$ (infinitely differentiable) and consider the task of integrating $\int ( \frac{df}{dx} )^2 dx$.
Note: I use the abbreviations WLOG (without loss of generality) and COI (constant of integration) below.
$$\begin{align}
\int dx\ \left( \frac{df}{dx} \right)^2 & = \int df\ \frac{df}{dx} \\
&= \int df \int dx\ \frac{d^2f}{dx^2} \\
&= \int dx \int df\ \frac{d^2f}{dx^2} & \text{let $u=\frac{df}{dx}$, so $du = \frac{d^2 f}{dx^2}\ \frac{dx}{df}\ df$} \\
&= \int dx\ \int du\ u \\
&= \int dx\ \left[ \frac{u^2}{2} + \frac{C}{2} \right] & \text{WLOG let $\frac{C}{2} \in \mathbb R$ be COI} \\
&= \int dx\ \left[ \frac{1}{2} \left( \frac{df}{dx} \right)^2 + \frac{C}{2} \right] \\
&= \frac{Cx}{2} + \frac K2 +\frac{1}{2} \int dx\ \left( \frac{df}{dx} \right)^2 & \text{WLOG let $\frac{K}{2} \in \mathbb R$ be COI} \\
&= Cx + K
\end{align}$$
It is obviously nonsense to state that $\int ( \frac{df}{dx} )^2 dx$ must be a linear function in $x$ for all functions $f$, so where did I go wrong here?
 A: Suppose $f$ is increasing on $[0,1]$, is in $C^2[0,1]$, and $f'(x) = u(f(x))$ for some $u\in C^1[f(0),f(1)]$. Then for $y\in [0,1]$,
\begin{align} \int_0^y (f'(x))^2 dx 
&= \int_0^yu(f(x))f'(x)dx = \int_{f(0)}^{f(y)}u(\tilde f)d\tilde f \\&= \int_{f(0)}^{f(y)} u(f(0)) + \int_{f(0)}^\tilde f u'(z) dz d\tilde f\end{align}
So we see that we need $u(f(0)) = 0$. Note $$f''(x) = u'(f(x)) f'(x)$$ which means that
$$ u'(z) = \frac{f''(f^{-1}(z))}{f'(f^{-1}(z))} $$
Attempting to proceed with $u(f(0)) = 0$, we can invert the change of variables $z = f(\tilde x)$
$$\int_0^y (f')^2 dx = \int_{f(0)}^{f(y)}\int_0^{f^{-1}(\tilde f)}f''(\tilde x) d\tilde x d\tilde f$$
which is similar to what you have. the exchange of integrals now gives
$$\int_{f(0)}^{f(y)}\int_0^{f^{-1}(\tilde f)}f''(\tilde x) d\tilde x d\tilde f = \int_{0}^{y} f''(\tilde x) \int_{f(\tilde x)}^{f(y)}  d\tilde f d\tilde x$$
where $f''$ is written as a function of $\tilde x$, not of $\tilde f$, so it doesn't seem like it can be meaningfully involved in another change of variables for the $d\tilde f$ integral.
I think the rest of the computation can't be saved, but this identity is not without merit. It implies for instance an inequality betweeen norms of derivatives of functions in this class,
\begin{align} \|f'\|_{L^2}^2 & \le |f'(0)||f(1) - f(0)| + \int_0^1 |f''(x)| |f(1) - f(x)| dx \\ &\le 2\|f'\|_{L^\infty}\|f\|_{L^\infty}+ 2\|f''\|_{L^1} \|f\|_{L^\infty}\end{align}
