<s>[INST] How to find $f$ if $f(f(x))=\frac{x+1}{x+2}$ let $f:\mathbb R\to \mathbb R$,and such

$$f(f(x))=\dfrac{x+1}{x+2}$$

Find the $f(x)$
My try

I found $f(x)=\dfrac{1}{x+1}$
  because when $f(x)=\dfrac{1}{x+1}$,then
  $$f(f(x))=f\left(\dfrac{1}{x+1}\right)=\dfrac{1}{\dfrac{1}{x+1}+1}=\dfrac{x+1}{x+2}$$
  so $f(x)=\dfrac{1}{x+1}$ such this condition,But $f(x)$  Have other form? Thank you

 [/INST] Suppose $f(x)=\frac{ax+b}{x+c}$. Then 
$$
f(f(x))= \frac{(a^2+b)x+b(x+c)}{(a+c)x + b+c^2}=\frac{x+1}{x+2}
$$
yields the equations
$$
\frac{a^2+b}{a+c}=1, \frac{b(a+c)}{a+c}=b=1, \frac{b+c^2}{a+c}=2, \frac{a^2+1}{a+c}=1$$
from which we find
$$c=a^2-a+1$$
and hence
$$a^4-2a^3+a^2-2a=a(a^3-2a^2+a-2)=0$$
This last equation has but two real solutions, $a=0$ and $a=2$, corresponding to the two solutions given by sos440: $$ f(x)=\frac{1}{x+1} \mbox{ and } f(x)=\frac{2x+1}{x+3}.$$
Added: The last equation has $a=\pm i$ as roots, but these yield the degenerate functions $f(x)=i$ and $f(x)=-i$ which do not yield the required $f(f(x))$.
</s>