Variation of function How to prove
"Let $g(t)$ be a continuous function on $[0,1]$, and denote by $s(a)$ the number of $t$'s such that $g(t)=a$. Then the variation of $g$ is $\displaystyle \int \limits _{-\infty}^\infty s(a)\,da$."
We have the variation of $g$ is $\displaystyle V_g
(t)=\lim \limits _{n\to \infty}\sum \limits _{i=1}^n|g(t^n_i)-g(t^n_{i-1})|$ where $0=t^n_0 <t^n_1 <.....t^n_n = 1$ partitions
of [0,1].
 A: Incomplete, but much too long for a comment
First, some notation and basic facts:

*

*For any real $A,B$, write $f(A,B)$ for the set of all real numbers between $A$ and $B$.  That is, $f(A,B) = (A, B) \cup (B, A).$

*Write $\chi(\cdot;I)$ for the indicator of $I$.  That is, $\chi(x;I) = 1$ if $x \in I$ and $\chi(x;I) = 0$ if $x \not\in I$.

*Note $|A-B| = \int_{-\infty}^\infty \chi(a;f(A,B))\,da$.

*Without loss of generality, we may assume the sequence of partitions $0=t^n_0 < t^n_1 < \cdots < t^n_n = 1$ are totally ordered by refinement.  That is, there is a unique $i_n$ such that $1 \leq i_n \leq n$ and $t^{n+1}_i = t^n_i$ for $i < i_n$ and $t^{n+1}_i = t^n_{i-1}$ for $i > i_n$.


With the above in mind, we may write the variation of $g$ on $[0,1]$ as
$$\begin{align*}V_g &= \lim_{n\to\infty}\sum_{i=1}^n \Big|g(t^n_i) - g(t^n_{i-1})\Big| \\ &= \lim_{n\to\infty}\sum_{i=1}^n\int_{-\infty}^\infty \chi\left(a; f\Big(g(t^n_i), g(t^n_{i-1})\Big)\right)\,da \\ &= \lim_{n\to\infty}\int_{-\infty}^\infty \underbrace{\left(\sum_{i=1}^n \chi\left(a; f\Big(g(t^n_i), g(t^n_{i-1})\Big)\right)\right)}_{s_n(a)}da\end{align*}$$
From here, the intermediate value theorem implies $s_n(a) \leq s(a)$ for any $n, a$, and therefore $$V_g = \lim_{n\to\infty} \int_{-\infty}^\infty s_n(a)\,da \leq \int_{-\infty}^\infty s(a)\,da,$$
which also gives us equality when $V_g=\infty$, so we may assume $g$ has bounded variation from here on out.
Further, since we've ordered the partitions by refinement, the triangle inequality implies $s_n(a) \leq s_{n+1}(a)$ for any $n,a$, so by the monotone convergence theorem, it follows that $$V_g = \int_{-\infty}^\infty s(a)\,da \iff \left\{a \in \mathbb{R} \,\middle|\, \lim_{n\to\infty}s_n(a) < s(a)\right\} \text{ has measure zero}$$
This is where I'm stuck.  It may be a property of bounded variation functions, but I don't know it.  This feels like a continuous analogue of Sard's theorem, and I don't think I've ever run into it.
