Math competition function with parameter problem Given a function $$f(x) = \frac{ax + 2}{3x - \frac{1}{a}}$$ find every possible value of the parameter $a$ such that for all real values $x$ for which $f(x)$ is defined it is true that $f(f(x))$ is also defined and $f(f(x))=x$
After manipulating the equation $$\frac{a\left(\frac{ax+2}{3x-\frac{1}{a}}\right)+2}{3\left(\frac{ax+2}{3x-\frac{1}{a}}\right)-\frac{1}{a}}$$ I got $$x\left(\left(a-\frac{1}{a}\right)x + \frac{1}{a^2} - a^2\right) = 0$$. This expression is zero if $x$ is zero or $\left(a-\frac{1}{a}\right)x + \frac{1}{a^2} - a^2$ is zero. Since the second expression must be zero for all $x$, $$a - \frac{1}{a}=0$$ and $$-a^2 + \frac{1}{a^2}=0$$.
Adding these two equations we get $$a^4 - a^3 - a + 1 = 0$$
Factoring this we get $$(a-1)(a+1)(a^2-a+1)=0$$
so $a$ can be 1 or -1 since $a^2-a+1$ doesn't have any real solutions.

From $$x\left(\left(a-\frac{1}{a}\right)x + \frac{1}{a^2} - a^2\right) = 0$$
you can ignore the possibility $x=0$ because this is supposed to work for all $x$, so we need $$\left(a-\frac{1}{a}\right)x + \frac{1}{a^2} - a^2 = 0$$
Now note that $\frac 1{a^2}-a^2-=(a-\frac1a)(a+\frac 1a) $ so our equation becomes either $$a-\frac 1a=0\\a=\pm 1$$
or $$x-a+\frac 1a=0$$
but this depends on $x$, so is not true for all values of $x$.  Our solution is $$a=\pm 1$$
