Suppose there is $c\in\mathbb{R}$ such that $(f(x)+c)^2$ is Riemann integrable on $[0,1]$. Does this imply that $f$ is also Riemann integrable on $[0,1]$?
At first I thought it does imply so, and my attempt to prove this was: $$\int_{0}(f(x)+c)^2dx=\int_{0}^{1}(f(x)f(x)+2f(x)+c^2)dx=\int_{0}^1(f(x)f(x)+c^2)dx+2\int_0^1f(x)dx$$ I know now that this false, but I cannot understand why it is wrong. Could someone please explain why is it wrong?
A counter-example was given: $$f(x)=19+D(x)$$ where $D$ is the Dirichlet function: $$D(x) = \begin{cases}1:& x\in\mathbb Q \\ 0:&x\in\mathbb R\setminus\mathbb Q\end{cases}$$ This I also fail to understand. When $x\in\mathbb{Q}$ we get $f(x)=19+1$, so $(f(x)+c)^2=400+40c+c^2$, which is a constant. Similarly, when $x\notin\mathbb{Q}$ we get $(f(x)+c)^2=361+38c+c^2$, which is another constant. How can this help me to counter the assumption?
Edit: I found out that you can simply solve the equation $400+40c+c^2=361+38c+c^2$ to find $c$ so that $(f(x)+c)^2)$ is a constant. However, I would still like if some one could shortly explain why can I not separate the integrals like I did.
Edit #2: oops forgot to multiply by $c$ in the middle: $$\int_{0}(f(x)+c)^2dx=\int_{0}^{1}(f(x)f(x)+2cf(x)+c^2)dx=\\\int_{0}^1(f(x)f(x)+c^2)dx+2c\int_0^1f(x)dx$$
Your error is that you use the formula
$$\int_0^{1}(p(x)+q(x))dx = \int_0^{1}p(x)dx + \int_0^{1}p(x)dx$$
(with $p(x)=f(x)f(x)+c^2$ and $q(x)=2f(x)$)
and only know that the integral on the left hand side exists. You want to get to the conclusion that both integrals on the right hand side exist, but that is not generally true!
The above formula works only in the other direction; if you know that $p(x)$ and $q(x)$ are integrable on the specified interval, then you can conclude their sum is integrable on that same interval and that the above summation formula is true.
That your conclusion can't work can be seen the moment you know of a specific, non-Riemann integrable function, like the Dirichlet function $D(x)$, because that would mean you could write:
$$\int_0^{1}1dx = \int_0^{1}D(x)dx + \int_0^{1}(1-D(x))dx.$$
The integral on the left hand side certainly exists, but neither integral on the right hand side does.
What happens when you usually use this formula to handle complicated integrals is that you intuitively select $p(x)$ and $q(x)$ to be "reasonable" functions, and further calculations bear that out and show that $p(x)$ and $q(x)$ are in fact integrable. This example is shows that this is formally not "OK", you'd need to start with the "base integrals" and work your way backwards.