Let $f$ be a convex function on $\mathbb R$ such that $f(0)=0$, let $g$ be such that for all $x$ in $\mathbb R$, $g(x)$ is a sub-gradient of $f$ at $x$, then it seems to me that for all $x\in \mathbb R$ \begin{align*} f(x) = \sup_{(x_0, \dots, x_{n+1})\in \mathcal S} \sum_{k=0}^{n} g(x_k) (x_{k+1}-x_k) \end{align*}
Where $\mathcal S = \{0\}\times\mathbb R^\ast\times\{x\} = \{ (0,x_1,\dots, x_n, x) : \forall i \in \{1,\dots,n\},~ x_i\in\mathbb R \}$.
For $f$ differentiable everywhere it seems to be the Riemann integral but when it is not, I feel like it is still an equality. Can anyone prove that it is wrong ? Or maybe is this something that exists alreadz and in this case I would appreciate some references.
It is easy to prove by property of the sub-gradient and induction that for all $(x_0, \dots, x_{n+1})\in \mathcal S$, $\sum_{k=0}^{n} g(x_k) (x_{k+1}-x_k)\leq f(x)$, I'm not sure on how to prove (or if it is doable) that there exists a sequence $(s_p)_{p\geq 1}$ of elements of $\mathcal S$ that converges to $f(x)$.
Since $f$ is convex, we have $f_-'(x_1)\leq f_+'(x_1)\leq f_-'(x_2)\leq f_+'(x_2)$ for $x_1\leq x_2$.
Now pick any function $g:[a,b]\rightarrow \mathbb{R}$ such that
$$g(x) = f'(x)$$
outside of a countable subset of $[a,b]$. Since $f$ is absolutely continuous, we have
$$f(x) = g(a) + \int^x_ag(t)dt$$
Since $g$ is equal to derivative $f'$, which is nondecreasing outside of a countable subset of $[a.b]$, the integral on the right hand side can be taken to be the usual Riemann integral. Note also that $g$ is equal to (sub)derivative of $f$ outside of a countable subset of $[a,b]$.