<s>[INST] Finding polynomial functions that satisfy a given condition 
Find all polynomial functions $P(x)$ which satisfy $P(x)^2=P(P(x))$.

Attempt at reaching answer: 
Let $d$ be the degree of $p(x) $.
We have $d+d=d*d \implies d=0 \vee d=2$.
If $d=0$ we have that $p(x)$ is constant, and this is indeed a solution.
Otherwise, we have $d=2 \implies p(x)=ax^2+bx+c$.
Plugging this into the original equation, we get
$(ax^2+bx+c)^2=a(ax^2+bx+c)^2+b(ax^2+bx+c)+c$.
Checking the coefficient of $x^4$ gives trivially $a=1$.
Rewriting and simplifying gives
$bx^2+b^2x+bc+c=0 \forall x \implies b=0 $ , $ c=0$.
Hence our solutions are
$p(x) = x $ and $p(x)= c$, with $c \in \mathbb{R} $.
Apparently, the first function (p(x)=x) is correct, but the second one isn't because it's not a polynomial function and it doesn't work for $x^2+1$... What would the correct answer then be?
 [/INST] You may proceed as follows:
Differentiating gives
$$2P(x)P'(x) = P'(P(x))P'(x)$$
Obviously the identity is satisfied, if $P'(x) = 0 \Rightarrow P(x) = c \stackrel{c^2=c}{\Longrightarrow} c=0$ or $c=1$ .
Now, if $P'(x) \neq 0$, then setting $y=P(x)$ gives us on a non-empty open interval the polynomial equation
$$2y = \frac{dP}{dy} \Rightarrow P(y) = y^2+d$$
Plugging this into the original identity gives 
$$(y^2+d)^2 \stackrel{!}{=}(y^2+d)^2 + d \Leftrightarrow d=0$$
So, the possible polynomials are $P(x) =x^2$, $P(x) =1$, and $P(x) =0$.
</s>