TITLE: How to find $f$ and $g$ if $f\circ g$ and $g\circ f$ are given?
QUESTION [9 upvotes]: The question is: Let $f:\mathbb R\rightarrow \mathbb R$ and $g:\mathbb R\rightarrow \mathbb R$ be two functions such that $(f\circ g)(x)=4x^2+4x+1$ and $(g\circ f)(X)=x^2+2x+2$. Find $f(x)$ and $g(x)$.
I solved the problem like this.
Because both the compositions are polynomials is $x$, it is clear that $f(x)$ and $g(x)$ also both will be polynomials in $x$. Let $\deg (f)=m, \deg (g)=n$. Then it follows that $m, n\leq 2$ cause otherwise the compositions will be polynomials of degree more than 2.
Now if both $m, n=2$ then $f\circ g, g\circ f$ will be of degree more than 2, contradiction again. Hence one of them will be 2 and the other will be 1. WOLOG let us assume that $m=2, n=1$.
Then we assume $f(x)=ax^2+bx+c, g(x)=dx+e$ we have $f\circ g=a(dx+e)^2+b(dx+e)+c= ad^2x^2+(2ade+bd)x+ae^2+be+c$ and $g\circ f=d(ax^2+bx+c)+e=dax^2+dbx+dc+e$. Equating the coeffcicients of similar terms, we then get the values of $a, b, c, d, e$ and hence the problem is solved.
Please inform me whether my approach to solve this problem was correct or not.

REPLY [4 votes]: If you disregard the requirement that $f(x)$ be real, there is a non-polynomial solution
$$ f(x) = \dfrac{\sqrt{x-1}}{4} -\dfrac{1}{2},\ g(x) = 1 + 4 (8 x^2 + 8 x + 3)^2$$