Given:
$$ f(x) = 3x-1 $$
$$ g(x) = x^3+2 $$
If you evaluate $g(f(1))$ by doing $f(1)$ first and inputting its value into $g(1)$, you get:
$$ f(1) = 3(1) - 1 = 2 $$
$$ g(f(1)) = 2^3+2 = 10 $$
But if you try to substitute $x$ with $f(x)$ in $g(x)$, i.e:
$$ f(x) = 3x-1 $$
$$ g(x) = x^3+2 $$
$$ g(f(x)) = (3x-1)^3+2 $$
If you evaluate the last expression, you get:
$$ g(f(x)) = 27x^3-1+2 $$
i.e
$$ g(f(x)) = 27x^3+1 $$
$g(f(1))$ now gives a different value (28) instead of 10.
Did I make a mistake with the evaluation of the parenthesis or is there a rule here that the parenthesis shouldn't be evaluated in certain circumstances?
Thanks.