$g \in C(\mathbb R)$ , $\lim_{x \to \infty}g(x)-x=\infty$ ; $g$ has finitely many fixed points , $f\in C(\mathbb R)$ , $f\circ g=f$ , is $f$ constant? Let $g:\mathbb R \to \mathbb R$ be continuous function , $\lim_{x \to \infty}g(x)-x=\infty$ ; and $g$ has at least one but finitely many fixed points and let $f:\mathbb R \to \mathbb R$ be a continuous function such that $f \circ g=f$ ; then is it true that $f$ is constant ?  
 A: Yes, $f$ must be constant.
To prove this, it suffices to show that $f$ can only take on a finite number of values, since a continuous function that only takes on a finite number of values must be constant. In particular, I will show that the only possible values of $f$ are those it takes on the fixed points of $g$.
First, I claim that if $x_M$ is the largest fixed point of $g$, then $f(y) = f(x_M)$ for $y>x_M$.
Note that $g(x_M)-x_M = 0$, and since $\lim\limits_{x\rightarrow\infty}{g(x)-x} = \infty$, and $x_M$ is the largest fixed point of $g$, it follows that $g(x)-x>0$ for $x>x_M$. Now, for any $x>x_M$, since $g(x)>x>x_M=g(x_M)$, by the intermediate value theorem there exists $x'\in(x_M,x)$ such that $g(x') = x$.
As such, fix any $y>x_M$, and construct the sequence $\{y_k\}_{k\in\mathbb{N}}$ by $y_0 = y$, and for $k\ge 0$ let $y_{k+1}$ be a number between $x_M$ and $y_k$ satisfying $g(y_{k+1})=y_k$. Note that for all $k$ we have $f(y_{k+1}) = f(g(y_{k+1})) = f(y_k)$, and so $f(y) = f(y_0) = f(y_k)$ for all $k$. Furthermore, since $\{y_k\}$ is a decreasing sequence bounded below by $x_M$, it must converge to some $y_{\infty}$, and by continuity $y_{\infty}$ must satisfy $g(y_{\infty}) = y_{\infty}$. It follows that $y_{\infty} = x_M$, since $x_M$ is the largest fixed point of $g$, and hence
$$ f(y) = \lim\limits_{k\rightarrow\infty}{f(y)} = \lim\limits_{k\rightarrow\infty}{f(y_k)} = f(x_M) $$
as desired.
To deal with the points to the left of $x_M$, let $x_m$ be the smallest fixed point of $g$. Notice that since $g(x)-x = 0$ at $x=x_m$ and $g(x)-x\ne 0$ for all $x<x_m$, it follows by continuity that either $g(x)-x<0$ for all $x<x_m$ or $g(x)-x>0$ for all $x<x_m$. We now divide the proof into cases:
Case 1: $g(x)-x<0$ for all $x<x_m$. In this case, notice that if $x<x_m$, then
$$ g(x)<x<x_m = g(x_m) $$
so by the intermediate value theorem, there exists $x'\in(x,x_m)$ such that $g(x') = x$. We can apply a similar argument as in the paragraphs above to conclude that $f(y) = f(x_m)$ for all $y<x_m$.
Now, let $y\in(x_m,x_M)$, and consider the sequence $\{y_k\}$ defined by $y_0 = y$ and $y_{k+1} = g(y_k)$. Note that $f(y_{k+1}) = f(g(y_k)) = f(y_k)$ for all $k$, and hence $f(y) = f(y_k)$ for all $k$. If $y_k$ exits $(x_m,x_M)$ at any point, then we know from above that $f(y_k)$, and hence $f(y)$, is equal to $f(x_m)$ or $f(x_M)$. Otherwise, $y_k\in(x_m,x_M)$ for all $k$. Then $\{y_k\}$ is a bounded sequence, so there exists a convergent subsequence which converges to some limit $y_{\infty}$, which by continuity must satisfy $g(y_{\infty}) = y_{\infty}$. Thus, there exists a subsequence converging to a fixed point of $g$, and so $f(y)$ must also be equal to the value of $f$ at that fixed point. Hence, for all $y$, we have that $f(y)$ is equal to the value of $f$ at some fixed point of $g$, which is what we wanted to show.
Case 2: $g(x)-x>0$ for all $x<x_m$.
Let $y<x_M$, and consider the sequence $\{y_k\}$ defined by $y_0=y$ and $y_{k+1} = g(y_k)$. Now, if $y_k<x_m$ for all $k$, then $y_{k+1} = g(y_k)>y_k$ for all $k$, i.e. the sequence is increasing and bounded above by $x_m$. It must then converge to a value that, by the discussion above, is also a fixed point of $g$ (which must be $x_m$ in this case), which, again by the discussion above, implies that $f(y) = f(x_m)$.
Otherwise, suppose $y_k>x_m$ for some $k$. If it is also true that $y_{k'}>x_M$ for some $k'$, then we're done, since we know that $f(y) = f(x_M)$ for $y>x_M$. Otherwise, assume the sequence is bounded above by $x_M$ as well. Let $c = \min\limits_{x\in[x_m,x_M]}{g(x)}$. I claim that the sequence is eventually bounded from below by $c$. To see this, suppose first that $c\ge x_m$. Then $y_k\in[x_m,x_M]\implies y_{k+1} = g(y_k)\in[c,x_M]\subset[x_m,x_M]$, and so by induction $y_k\in[x_m,x_M]$ for all large enough $k$. Otherwise, if $c<x_m$, then $\min\limits_{x\in[c,x_m]}{g(x)}\ge c$ since $g(x)>x$ for $x<x_m$, so $$\min\limits_{x\in[c,x_M]}{g(x)} = \min\left(\min\limits_{x\in[c,x_m]}{g(x)},\min\limits_{x\in[x_m,x_M]}{g(x)}\right) = c$$
and the same argument applies.
Thus, the sequence is bounded from above by $x_M$ and eventually bounded from below by $c$, so it has a subsequence converging to some limit that, by the discussion above, must be a fixed point of $g$. Once again, this implies that $f(y)$ is equal to the value of $f$ at some fixed point of $g$.
Thus, in all cases we have that $f(y)$ is the value of $f$ at some fixed point of $g$ for every $y$, and hence the only possible values of $f$ are those at the finite number of fixed points of $g$, as desired.
