Question on foiling with vectors? Show that
$$\frac1{f}\sum_{i=1}^n(\mathbf{x}_i-\bar{\mathbf{x}})(\mathbf{x}_i-\bar{\mathbf{x}})'=\frac1{f}\sum_{i=1}^n(\mathbf{x}_i\mathbf{x}_i'-n\bar{\mathbf{x}}\bar {\mathbf{x}}').$$
I need this to understand an example in my textbook on Hotelling's $T^2$ but I can't figure out how they get this result. I imagine it's quite trivial but I can't seem to figure it out..
Edit, my textbook is using this result to simplify computation. Otherwise you need to sum a lot of vectors :/
 A: Sure, any bilinear form $\left<-,-\right>$ obeys FOIL (For those who haven't taken algebra in the US, this stands for first, outer, inner, last).
Given vectors $a$, $b$, $c$, and $d$:
\begin{align*}
\left<a+b,c+d\right> &= \left<a,c+d\right> + \left<b,c+d\right> \\
    &= \left<a,c\right> + \left<a,d\right> + \left<b,c\right> + \left<b,d\right> \\
\end{align*}
If, in addition, the form is symmetric, you can combine terms.  For instance,
\begin{align*}
    \left<x-y,x-y\right> &= \left<x,x\right> - \left<x,y\right> - \left<y,x\right> + \left<y,y\right>
\\  &= \left<x,x\right> - 2 \left<x,y\right> + \left<y,y\right>
\end{align*}
For the identity you're working on, the key is the identity $\sum_{j=1}^n \mathbf{x}_j = n \bar{\mathbf {x}}$.  We have
\begin{align*}
    \sum_{i=1}^n(\mathbf{x}_i - \bar{\mathbf{x}})(\mathbf{x}_i - \bar{\mathbf{x}})'
    &= \sum_{i=1}^n\left(\mathbf{x}_i\mathbf{x}_i' - \mathbf{x}_i\bar{\mathbf{x}}' - \bar{\mathbf{x}}\mathbf{x}_i' + \bar{\mathbf{x}}\bar{\mathbf{x}}'\right)
  \\&= \sum_{i=1}^n\mathbf{x}_i\mathbf{x}_i' - \sum_{i=1}^n\mathbf{x}_i \bar{\mathbf{x}}' - \sum_{i=1}^n \bar{\mathbf{x}}\mathbf{x}_i' + n \bar{\mathbf{x}}\bar{\mathbf{x}}'
\end{align*}
By the distributive property,
\begin{align*}
   \sum_{i=1}^n\mathbf{x}_i \bar{\mathbf{x}}'
  &=\left(\sum_{i=1}^n\mathbf{x}_i\right) \bar{\mathbf{x}}' = n \bar{\mathbf {x}}\bar{\mathbf{x}}' \\
\sum_{i=1}^n \bar{\mathbf{x}}\mathbf{x}_i'
&= \bar{\mathbf{x}}\left(\sum_{i=1}^n \mathbf{x}_i'\right)
 = \bar{\mathbf{x}}(n\bar{\mathbf{x}}') = n \bar{\mathbf{x}}\bar{\mathbf{x}}'
\end{align*}
So the middle two terms combine with the last, and the result is proved.
A: \begin{align}
\text{right: } (a+b)(c+d) & = ab+ad+bc+bd \\
\text{wrong: } (a+b)(c+d) & = ab+ad+cb+bd
\end{align}
This second one is wrong except in cases where it doesn't matter in which order you multiply; so it is correct if these are numbers but wrong if they are matrices.
The more basic fact is the distributive law:
\begin{align}
\text{right: } p(q+r) & = pq + pr \\
\text{wrong: } p(q+r) & = qp+rp
\end{align}
Now apply the distributive law three times:
\begin{align}
& (a+b)(c+d) \\[10pt]
= {} & (\cdots\cdots)(c+d) \\[10pt]
= {} & (\cdots\cdots)c + (\cdots\cdots) d  & & \text{(first application of the distributive law)} \\[10pt]
= {} & (a+b)c + (a+b)d \\[10pt]
= {} & ac + bc + (a+b)d & & \text{(second application of the distributive law)} \\[10pt]
= {} & ac + bc + ad + bd & & \text{(third application of the distributive law)}
\end{align}
In other words "FOIL" is a derived law rather than a primitive law. The associative law is primitive in this argument.
