# Are the upper sums of any bounded function also the upper sums of an integrable function?

Let $f:[a,b] \to \mathbb{R}$ be bounded.

Is there always a Riemann integrable function $g:[a,b] \to \mathbb{R}$ such that for any partition $P$, we have $U(g,P) = U(f,P)$?

Of course, if $f$ is Riemann integrable, we can simply take $g \equiv f$, but that's not generally true.

The motivation to ask this question was the function $f(x) = \mathbf{1}_{\mathbb{Q} \cap [0,1]}(x)$ defined on $[0,1]$. For any partition $P$, $f$ shares its upper sum with $f \equiv 1$ on $[0,1]$, which happens to be integrable.

I guess that a good candidate is the upper semicontinuous envelope $$g(x) := \lim_{r\to 0+} \left( \sup_{y\in B_r(x)} f(y) \right).$$ Indeed, $g\geq f$ and, for every interval $[c,d]\subset[a,b]$ one has $$\sup_{[c,d]} g = \sup_{[c,d]} f,$$ so that $U(g,P) = U(f,P)$ for every partition $P$.
The function $g$ is upper semicontinuous; on the other hand, an upper semicontinuous function can have a set of discontinuities of positive measure, hence need not be Riemann integrable. Such a function could be used to construct a counterexample.