This is problem #1 from chapter 3.9 in Advanced Calculus: Theory and Practice, my introductory real analysis textbook at Western Michigan University:
Suppose that \(f\) is continuous on \(\left[0, 2\right]\) and \(f(0) = f(2)\). Prove that there exist \(x_1\), \(x_2 \in \left[0, 2\right]\) such that \(x_2 – x_1 = 1\) and \(f(x_1) = f(x_2)\).
Informally, this says there are two \(x\)-values exactly \(1\) unit apart whose \(f\) values are equal. This result isn’t all that obvious, and I liked it so much because it’s a great example of the type of abstract, theoretical result you learn to prove in mathematical analysis.
Recall that the Intermediate Value Theorem states that if \(f\) is a continuous function on an interval \(\left[a, b\right]\) and \(f(a) \neq f(b)\), then for every \(C\) between \(f(a)\) and \(f(b)\), there exists \(c \in (a, b)\) such that \(f(c) = C\). Often the Intermediate Value Theorem is stated as a specific case, where \( f(a) < 0 \) and \( f(b) > 0 \), in which case there exists \( c \in (a, b) \) such that \(f(c) = 0\). This is the case that will be relevant here. Now the solution to the problem:
Proof: Let \(g(x) = f(x+1) ~- f(x)\), defined on \(\left[0, 1\right]\). The function \(g\) is continuous, and $$g(0) = f(1) ~- f(0)$$ and $$g(1) = f(2) ~- f(1) = f(0) ~- f(1) = -g(0).$$
If \(g(0) = 0\), then \(f(0+1) ~- f(0) = 0\), so \(f(1) = f(0)\) and the solution is to take \(x_1 = 0\) and \(x_2 = 1\). If \(g(0) \neq 0\), then \(g(1)\) and \(g(0)\) are nonzero numbers of equal magnitude but opposite sign. By the Intermediate Value Theorem, there exists \(c \in (0, 1)\) such that \(g(c) = 0\). Now the solution is to define \(x_1 = c\) and \(x_2 = c+1\). This makes \(g(c) = f(c+1) ~- f(c) = f(x_2) ~- f(x_1) = 0\), so \(f(x_2) = f(x_1)\). \(\blacksquare\)