The binomial theorem and composite functions A question begins with this context (I'm paraphrasing a bit):
(1) Under the context of function composition, raising a function to a power means we compose, for example, $f^2 = fof$, $(fog)^2 = fogofog$, and so on
(2) Function composition is not commutative, $fog(x)$ is not always $gof(x)$
Then the Q: Will the binomial expansion theorem work with function composition, why or why not? (so we can't just contradict by a numerical case, but we can do a contradiction in the quadratic case using general variables)
The answer to the question considers $(fog+gof)^2$, and sees that it's equal to $(fog)(fog)+(fog)(gof)+(gof)(fog)+(gof)(gof)$, by the $distr. prop.$ which can easily be motivated
If the $B.th.$ does work, it should be simplified down to $(fog)^2 + 2(fog)(gof) + (gof)^2$
Now here's the confusion:
The answer says that the $B.th.$ does not work because if $fog = a$ and $gof = b$, then $(fog)(gof) = ab$ and $(gof)(fog) = ba$, since ab is not equal to $ba$, it can't just be $2ab$
If you just have $fog(x)$ and $gof(x)$ as two things that multiply to each other in parenthesis as shown in the $FOILED$ out form, then can't we just simply factor it to $2ab$, it seems completely fine algebraically?
Now, if we had our thing with the context that was going on with how $(fog)^2 = fogofog$, I would understand, but what doesn't make sense (the $"right?"$'s are not me be being certain and asking for agreement, they are questions):
  isn't just that we use the exponent as notation, surely it isn't algebraic 
  that $(fog(x))^2 = 
  fogofog(x)$, right?

  So then if we multiply using $FOIL$, we can just rewrite $ab + ba = 2ab$, 
  because if just doing this 
  algebraic multiplication, it is commutative, right?

  It seems that we don't have to worry about whether the $b.th.$ uses 
  exponents as function 
  composition, because the answer given to this question says that $ab + ba$ 
  is 
  not $2ab$, so we should 
  be good enough by just clearing that up

 A: You should think about it like this $(f\circ g)(x)\cdot (g\circ f)(x)= f(g(x))\cdot g(f(x))=g(f(x))\cdot f(g(x))=(g\circ f)(x)\cdot (f\circ g)(x)$\
In essence, it is true that $(f\circ g)(x)\neq (g\circ f)(x)$ but functions are still commutative. In fact, $fg=gf$
A: According to (1) we consider powers of functions as compositions. In this problem we do not have any multiplication of functions but only addition and composition of functions. We define
\begin{align*}
f^2&:= f\circ f\tag{1.1}
\end{align*}
and squaring a sum of functions in this context means composition of a sum of functions.

We obtain
\begin{align*}
\color{blue}{(f+g)^2}&=(f+g)\color{blue}{\circ}(f+g)\tag{2.1}\\
&=\left(f\circ(f+g)\right) + \left(g\circ(f+g)\right)\tag{2.2}\\
&=f\circ f+f\circ g + g\circ f + g\circ f\tag{2.3}\\
&\,\,\color{blue}{=f^2+f\circ g + g\circ f +g^2}\tag{2.4}
\end{align*}

Comment:

*

*In (2.1) we use when squaring $(f+g)$ the composition of functions as in (1.1).


*In (2.2) we apply the distributive law, noting that composition of function takes precedence over addition of functions.


*In (2.3) we use the distributive law again.


*In (2.4) we use the power notation for compositions of $f$ and $g$ with itself.

Substituting $f$ with $f\circ g$ and $g$ with $g\circ f$ in (2.1) we obtain the binomial expansion of a composition of functions.
\begin{align*}
&\color{blue}{(\left(f\circ g\right)+\left(g\circ f\right) )^2}\\
&\quad=(\left(f\circ g\right)+\left(g\circ f\right) )\color{blue}{\circ}(\left(f\circ g\right)+\left(g\circ f\right) )\\
&\quad=\left(f\circ g\right)\circ(\left(f\circ g\right)+\left(g\circ f\right))\\
&\qquad\qquad+ \left(g\circ f\right)\circ(\left(f\circ g\right)+\left(g\circ f\right))\\
&\quad=\left(f\circ g\right)\circ \left(f\circ g\right)+\left(f\circ g\right)\circ \left(g\circ f\right)\\
&\quad\qquad+ \left(g\circ f\right) \circ \left(f\circ g\right) + \left(g\circ f\right) \circ \left(g\circ f\right) \\
&\quad=\left(f\circ g\right)^2+\left(f\circ g\right)\circ \left(g\circ f\right)\\
&\qquad\qquad  + \left(g\circ f\right) \circ \left(f\circ g\right) +\left(g\circ f\right) ^2\\
&\,\,\color{blue}{\quad=\left(f\circ g\right)^2+f\circ g^2\circ f  + g\circ f^2\circ g+\left(g\circ f\right)^2}\tag{3.1}
\end{align*}

In (3.1) we use the associativity of the composition of functions. We observe that since composition of functions is not commutative, i.e. we do not have in general $f\circ g=g\circ f$, the binomial expansion theorem $(a+b)^2=a^2+\color{blue}{2}ab+b^2$ does not hold in general for function compositions.
