I have proved that a continuous function $f(x): \mathbb{R} \rightarrow\mathbb{R}$ cannot take every value in its range exactly twice. How is the general case with an even number of times proved?
Here's my proof for the basic case.
Suppose continuous $f(x): \mathbb{R} \rightarrow \mathbb{R}$ takes every value in its range exactly twice.
Let $f(a) = f(b) = w$ with $a < b$.
Claim that $\forall x \in (a,b), \; f(x)>w$ or $f(x) < w$.
- If $f(x) = f(a) = f(b) \; \forall x \in (a,b)$, that clearly contradicts the hypothesis.
- If $\exists x_1,x_2 \in (a,b): \; f(x_1) < w < f(x_2)$, then by Intermediate Value Theorem, $\exists x_3 \in (x_1,x_2)$ or $(x_2,x_1)$ such that $f(x_3) = w$ contradicting the hypothesis.
Assume for the moment that $\forall x \in (a,b), \; f(x)>w$.
By Extreme Value Theorem, $f(x)$ attains maximum $f(c_1) > f(a)=f(b)$ at some $c_1 \in (a,b)$.
By the hypothesis, $\exists c_2 \in \mathbb{R}\setminus \{c_1\}$ such that $f(c_2) = f(c_1)$.
Claim that $c_2 \in (a,b)$.
- If $c_2 > b$, for some value $u \in \Big(f(a),f(c_1)\Big) = \Big(f(b),f(c_1)\Big) = \Big(f(b),f(c_2)\Big)$, $f(x) = u$ at least three times, namely $x_1 \in (a,c_1), \;x_2 \in(c_1,b), \;\text{and } x_3 \in(b,c_2)$, contradicting the hypothesis.
- By similar reasoning, $c_2 \nless a$.
Without loss of generality, assume $a < c_1 < c_2 < b$.
By Extreme Value Theorem, $f(x)$ attains minimum $f(d)$ at some $d \in (c_1, c_2)$.
Because $f(a) = f(b) < f(d) < f(c_1) = f(c_2)$, by Intermediate Value Theorem, $f(x) = f(d)$ at least three times, namely $x_1 \in (a,c_1), \; d, \text{ and } x_2 \in (c_2,b)$.
This is a contradiction to the hypothesis.
Now for the other case when $\forall x \in (a,b), \; f(x) < w$. Let $g(x) = -f(x)$ and apply the above proof to conclude that $g(x)$ cannot take every value in its range exactly twice, so neither $f(x)$.
Thanks.