[Math] Prove that f is a constant function.

calculuscontinuityproof-verificationreal-analysis

My friend asked me for help on the following question:
If $f:\mathbb R \to \mathbb Z$ is a continuous function, prove that $f$ is a constant function.

I tried the following proof, but I am generally bad at writing proofs, so I would like to know if the following is acceptable:

Proof
Suppose $f$ isn't constant, then $\exists x_1, x_2 \in \mathbb R$ such that $x_1 \ne x_2$ and $f(x_1) \ne f(x_2)$.
Note that $f(x_1)$, $f(x_2) \in \mathbb Z$.
Assume, without loss of generality, that $f(x_2) > f(x_1)$.
Then $f(x_2) – f(x_1) \ge 1$ and so $f(x_2) > f(x_2) – 0.5 > f(x_1)$.
But $f(x_2) – 0.5 \not\in \mathbb Z$, so $\not \exists x \in \mathbb R$ such that $f(x) = f(x_2) – 0.5$.
By the Intermediate Value Theorem this means that $f$ isn't continuous; a contradiction.
Therefore $f$ is constant.

Best Answer

Looks good. I would just write:

Suppose $f$ is not constant, then there is $a>b$ with $f(a)\neq f(b)$. Let $y\in [f(a),f(b)]\cup [f[(b),f(a)]$ be a number that is not an integer. By the intermediate value theorem there is $x\in [a,b]$ so that $f(x)=y\not\in \mathbb Z$. Contradicting that the co-domain of $f$ is $\mathbb Z$