Figuring out coefficients of composition of a first degree polynomial into a quadratic

Solution 1:

A more easy way is the following :

If $f(x)=ax+b$, then $$g \circ f(x) = (ax+b)^2 + (ax+b) - 2 = a^2x^2 + (2ab+a)x + (b^2+b-2)$$

By identification, you must have $a^2 = 4$, $2ab+a = -10$ and $b^2+b-2 = 4$. If $a=2$, you obtain $b=-3$ which works ; if $a=-2$, you obtain $b=2$ which also works. So you have two solutions : $$f(x) = 2x-3 \quad \text{ and } \quad f(x)=-2x+2 $$