I found this problem on a problem sheet about polynomials:
Let $P \in \mathbb{R}[X]$, $S_a = \{t \in \mathbb{C} \mid P(t) = a\}$, and $I = \{a \in \mathbb{R} \mid S_a \subset \mathbb{R}\}$. Show that $I$ is an interval.
I can see intuitively why this must be true: if we take a polyomial $P$ such that all the roots of $P'$ are real and simple, then the graph of $P$ shows that this interval is exactly the interval between the smallest maximum of $P$ and the largest minimum of $P$. I tried to show that this holds, but I couldn't.
Proof: Suppose$$ x^3 Q(x) - a = c\prod\limits_{k = 1}^n (x - x_k), $$ where $c \in \R^*$, $x_1, \cdots, x_n \in \R$. Comparing the coefficients of the lowest three terms yields:\begin{gather*} \begin{cases} \prod\limits_{k = 1}^n x_k \ne 0\\ \sum\limits_{k = 1}^n \prod\limits_{j \ne k} x_j = 0\\ \sum\limits_{k_1 < k_2} \prod\limits_{j \ne k_1, k_2} x_j = 0 \end{cases}, \end{gather*} thus$$ \sum_{k = 1}^n \frac{1}{x_k^2} = \paren{ \sum_{k = 1}^n \frac{1}{x_k} }^2 - 2 \sum_{k_1 < k_2} \frac{1}{ x_{k_1} x_{k_2} } = \paren{ \frac{ \sum\limits_{k = 1}^n \prod\limits_{j \ne k} x_j }{ \prod\limits_{k = 1}^n x_k } }^2 - \frac{ 2\sum\limits_{k_1 < k_2} \prod\limits_{j \ne k_1, k_2} x_j }{ \prod\limits_{k = 1}^n x_k } = 0, $$ a contradiction.
Now return to the problem.
Case 1: $P'$ has at least one real multiple root.
Suppose $x_0 \in \R$ is a multiple root of $P'$, then ${(x - x_0)}^3 \mid P(x) - P(x_0)$. For any $a \in \R \setminus \{P(x_0)\}$, note that$$ P(x) - a = {(x - x_0)}^3 \cdot \frac{ P(x) - P(x_0) }{ {(x - x_0)}^3 } - (a - P(x_0)), $$ thus the lemma shows that $a \notin I$. Therefore, $I = \emptyset$ or $\{P(x_0)\}$.
Case 2: All real roots of $P'$ are simple.
Suppose the real roots of $P'$ are $x_1 < \cdots < x_m$. (In case $P'$ has no real root, set $m = 0$.) Define $x_0 = -\infty$, $x_{m + 1} = +\infty$, and $I_k = (x_k, x_{k + 1})$ ($0 \le k \le m$).
For any fixed $a \in \R$, note that $P - a$ is strictly monotonic on each of $\overline{I_0}, \cdots, \overline{I_m}$. For any $0 \le k \le m$:
Therefore, the number of real roots of $P - a$ is:\begin{align*} &\= \sum_{k = 0}^m \delta(P - a \text{ has a root in } I_k) + 2\sum_{k = 1}^m \delta(P(x_k) = a)\\ &= \sum_{k = 1}^{m - 1} \delta(P - a \text{ has a root in } I_k) + \delta(P - a \text{ has a root in } I_0)\\ &\={} + \delta(P - a \text{ has a root in } I_m) + \sum_{k = 0}^{m - 1} \delta(P(x_{k + 1}) = a) + \sum_{k = 1}^m \delta(P(x_k) = a)\\ &= \sum_{k = 0}^m \delta(P - a \text{ has a root in } \overline{I_k})\\ &= |\{ 0 \le k \le m \mid a \in P(\overline{I_k}) \}|. \tag{1} \end{align*}
Note that $m \le \deg(P') \le \deg(P) - 1$, so $(1) \le \deg(P)$. Hence\begin{align*} &\mathrel{\hphantom{\iff}} (1) = \deg(P)\\ &\iff (m = n - 1) \land (\forall 0 \le k \le m\colon\ a \in P(\overline{I_k}))\\ &\iff (m = n - 1) \land \paren{ a \in \bigcap_{k = 0}^m P(\overline{I_k}) }. \end{align*}
Therefore, $I = \emptyset$ or $\bigcap\limits_{k = 0}^m P(\overline{I_k})$, the latter of which, being the intersection of intervals, is an interval or an empty set.