Composition of Riemann-integrable and increasing functions. This is exercise 7.3.3 from Abbot's Understanding analysis. The section is Integrating functions with discontinuities.
I am struggling with this exercise. I can't either come up with any simple counterexamples or produce a satisfactory proof.
I was able to solve a), and here are some answers to b) that I don't understand well because they use a bit of measure theory: Answer 1, Answer 2. I still don't know whether c) is true or false.
Any hints to a proof, the proof itself, or simple counterexamples are highly appreciated.
The exercise reads:

Let $f$ and $g$ be functions defined on (possibly different) closed intervals, and assume the range of $f$ is contained in the domain of $g$ so that the composition $g \circ f$ is properly defined.
a) Show, by example, that it is not the case that if $f$ and $g$ are integrable, then $g\circ f$ is integrable.
Now decide on the validity of each of the following conjectures, supplying a proof or counterexample as appropriate.
b) If $f$ is increasing and $g$ is integrable, then $g\circ f$ is integrable.
c) If $f$ is integrable and $g$ is increasing, then $g\circ f$ is integrable.

EDIT
I found a solution to b) here, due to Chutong Wu. The solution seems to contradict the counterexamples from above, as it provides a proof of the statement. I reproduce the proof in full:
Fix $\epsilon > 0$. Because $g$ is integrable, we can find a partition $P_{g}=\{x_{0}<\cdots <x_{n}\}$ of $Rng(f)\subseteq Dom(g)$ such that $U(g\lvert_{Rng(f)}, P_{g})-L(g\lvert_{Rng(f)}, P_{g})<\epsilon$.
Because $f$ is increasing, it is one-to-one so $f^{-1}:Rng(f)\rightarrow Dom(f)$ is well-defined and also increasing. This means the set $P=\{f^{-1}(x_{0}),\cdots,f^{-1}(x_{n})\}$ is also a partition of $Dom(f)$.
We then have:
$
\begin{align}
U(g\circ f, P)-L(g\circ f, P)
  &=\sum_{k=1}^{n}(
    \underbrace{\sup_{[x_{k-1},x_{k}]} g\circ f}_{=(g\circ f)(f^{-1}(x_{k}))=g(x_{k})} -
    \underbrace{\inf_{[x_{k-1},x_{k}]} g\circ f}_{=(g\circ f)(f^{-1}(x_{k}))=g(x_{k-1})})
    [x_{k-1},x_{k}] \\
  &= U(g\lvert_{Rng(f)}, P_{g})-L(g\lvert_{Rng(f)}, P_{g})<\epsilon
\end{align}
$
 A: (c) Let $\phi:\mathbb{N}\rightarrow(0,\infty)$ be a monotone nonincreasing sequence such that $\phi(n)\xrightarrow{n\rightarrow\infty}0$.
Define $f:[0,1]\rightarrow\mathbb{R}$ as follows
$$f(x)=\left\{\begin{array}{lcr}1 &\text{if} & x=0\\
0 &\text{if} & x\in[0,1]\setminus\mathbb{Q}\\
\phi(n) &\text{if}& x=\frac{m}{n},\quad (m,n)=1
\end{array}
\right.
$$
The case $\phi(x)=\frac{1}{x}$ yields what is know as  Thomae's function. It  can be seen that $f$ is continuous at irrational points. Thus $f$ is $R$-integable over $[0,1]$ (by Lebesgue's criteria).
Consider the function $g(x)=\mathbb{1}_{(0,1]}(x)$. This function is monotone nondecreasing, and
$$h(x)=g(f(x))=\mathbb{1}_{[0,1]\cap\mathbb{Q}}(x)$$
which is not $R$-integrable.
By considering $G(x)=x+g(x)$, we obtain an strictly monotone increasing function such that $G\circ f$ is not $R$-integrble.

Just for completion, here is a proof that the Thomae-like function $f$ defined above is indeed continuous at every $x\in[0,1]\setminus\mathbb{Q}$. Fix $x_0\in [0,1]\setminus\mathbb{Q}$ and $\varepsilon>0$. Let $r\in\mathbb{R}$ such that $\phi(r) <\varepsilon$. For each $j\in\{1,\ldots r\}$ let $k_j=\lfloor jx_0\rfloor$. Since $x_0$ is irrational
$$k_j<jx_0<k_j+1$$
Let $\delta:=\min_{1\leq j\leq r}\left\{\big|x_0-\frac{k_j+1}{j}\big|,\big|x_0-\frac{k_j}{j}\big|\right\}$. Suppose $\operatorname{g.c.d}(p,q)=1$ and $|x-p/q|<\delta$. We claim that
$q>r$, otherwise $q\leq r$ and so $p\leq k_q$ or $p\geq k_p+1$. This in turn implies that
$$\big|x-\frac{p}{q}\big|\geq\delta$$
which leads to a  contradiction. Therefore, if $|x-p/q|<\delta$,
$$|f(p/q)-f(x)|=f(p/q)=\phi(q)\leq \phi(r)<\varepsilon$$
A: This is to address some comments by the OP regarding a proof to (b) that he found in the web. Other members of the community are welcome to add/improve this posting.
Suppose $f:[\alpha,\beta]\rightarrow\mathbb{R}$, $g:[a,b]\rightarrow\mathbb{R}$ are $R$-integrable, that $A:=f([\alpha,\beta])\subset[a,b]$ and that $f$ is monotone nondecreasing (strictly monotone increasing seems to be what the OP assumes, but for the time being the previous assumptions will do).

*

*The solution to (b) presented by Chutong Wu is not correct. There are at least to big error.


*

*(a)  Notice that even if $A$ were an interval, say $[c,d]\subset [a,b]$ and $f$ bijective. The error in Wu's argument stems from the fact if $\mathcal{P}=\{c=f(\alpha)=y_0<\ldots<y_n=d=f(\beta)\}$, and $\mathcal{P}'=f^{-1}(\mathcal{P})=\{\alpha=x_0<\ldots x_n=\beta\}$, the Riemann-Darboux sums for $g$
$$\begin{align}
U(g;\mathcal{P})&=\sum^n_{j=1}\big(\sup_{y\in[y_{j-1},y_j]}g(y)\big)(y_j-y_{j-1})\\
&=\sum^n_{j=1}\big(\sup_{x\in[x_{j-1},x_j]}g(f(x))\big)(f(x_j)-f(x_{j-1}))\\
L(g;\mathcal{P})&=\sum^n_{j=1}\big(\inf_{y\in[y_{j-1},y_j]}g(y)\big)(y_j-y_{j-1})\\
&=\sum^n_{j=1}\big(\inf_{x\in[x_{j-1},x_j]}g(f(x))\big)(f(x_j)-f(x_{j-1}))
\end{align}$$
are not Riemann-Darboux sums for $g\circ f$, that is, they are not of the form
$$\begin{align}
U(g\circ f;\mathcal{P}')&=\sum^n_{j=1}\big(\sup_{x\in[x_{j-1},x_j]}g(f(x))\big)(x_j-x_{j-1})\\
L(g\circ f;\mathcal{P}')&=\sum^n_{j=1}\big(\inf_{x\in[x_{j-1},x_j]}g(f(x))\big)(x_j-x_{j-1})
\end{align}$$

*(b) The Riemann integral is built on partitioning bounded closed intervals, not  arbitrary sets. That is, the $R$ integral of $g\mathbb{1}_A$ is build by partinoning $[a,b]$ (or any other subinterval that contains $A$), and not $A$ itself.



*The set $A$ may not be nice for Riemann integration, even when $g$ is $R$-integrable over $[a,b]$.  Take for example $g(x)=x$ and $A=\mathbb{Q}\cap[0,1]$. The function $g\mathbb{1}_A$ is not $R$-integrable in  $[0,1]$.

*The assumption that $f$ is $R$-integrable and monotone increasing over say, $[\alpha,\beta]$,  implies that $f$ admits at most a countable number of discontinuities (all of which are jump discontinuities). Still,  $f([\alpha,\beta])$ may not be interval or even the countable union of and ordered collection of closed intervals and points; in fact, it could be a rather nasty set (still nice in the sense of measure theory). Take for example Cantor's function (the devil's staircase) $F$. Define $Q:[0,1]\rightarrow[0,1]$ as $Q(y)=\inf\{x\in [0,1]: F(x)=F(y)\}$. It can bee seen that $Q$ is strictly monotone increasing (actually strictly increasing) and that $Q([0,1])$ is the Cantor set. $Q$ is continuous on $[0,1]\setminus D$, where $D=\{m2^{-n}: n\in\mathbb{Z}_+, m\in\mathbb{Z}_+\}\cap[0,1]$ is the set of dyadic numbers.




*The counterexample to (b) presented here is correct. The crux of the matter is to check that indeed there is a continuous  strictly monotone increasing  function $f:[0,1]\rightarrow[0,1]$ that maps a fat Cantor set $S$ onto the 1/3-Cantor set $C$. For then, $h(x)=\mathbb{1}_{C}(f(x))$ is discontinuous at every point $x\in S$. Since $S$ is not of (Lebesgue) measure $0$, then $h$ is not R-integrable and yet $\mathbb{1}_C$ and $f$ are $R$-integrable in $[0,1]$.

