When does function composition commute? [duplicate]

There are plenty of examples:

$$ f(x) = x + 3,\ g(x) = x + 5: fg(x) = gf(x) = x + 8 $$ $$ f(x) = 5x,\ g(x) = 2x: fg(x) = gf(x) = 10x $$ $$ f(x) = x^4,\ g(x) = x^7: fg(x) = gf(x) = x^{28} $$

A common thread among these is that they involve commutative operations.


Take $f(x) = x^{2}$ and $g(x) = x^{3}$. Then $f(g(x)) = g(f(x)) = x^{6}$. So, $f$ and $g$ commute