# Linear Algebra (trace): How to pull out $X^T[...]X$?

In fallowing equation - (1) $tr(X^TA^TAX+X^TLX)$ equals to $tr(X^T[A^TA+L]X)$.
My question is how about in the following equation
(2) $tr(X^TA^TAX+X^TXL)$, can we pull out $tr(X^T[...]X)$ like first equation (1)?
Any suggestions are welcome,

• If $L$ and $X$ commute, then that's the case. See Math.SO for When is matrix multiplication commutative? Feb 8, 2015 at 17:57
• For 1 x 1 matrices you always can, for 2 x 2 matrices you can create counterexamples. Very useful to work out a counterexample, will help you understand matrix multiplication better. Feb 8, 2015 at 19:45
• Why does the word "trace" appear in your title? While its not in general the case that you can pull the $X$ out on the right side in (2), if you're actually dealing with the trace, you should make certain to include that in the expressions in the body of your post, since there's important results with the trace you can use: $\text{tr}(AB)=\text{tr}(BA)$ Feb 9, 2015 at 1:11
• @Glen_b, sorry for about that, actually all notations are with the trace. I checked your link and still cannot solve it. Particularly, we have 3 matrices $tr(X^TXL)$, so I think we cannot apply it $tr(AB) = tr(BA)$, and I checked using MATLAB numerical toolbox. Feb 9, 2015 at 21:26
• Indeed, it's important to be clear about dimensions of all the objects; if the dimensions of X and L aren't suitable (in effect, if X and L aren't square), you can't do this -- it doesn't make sense to consider swapping the order of anything if the matrices aren't conformable. In Equation 1, the X is at the end of both expressions, so nothing is swapped. You're just using the distributive law. Feb 9, 2015 at 21:56

## 1 Answer

Here are some properties about matrix and traces. We assume in what follows that all matrices are square.

(i) $\text{tr}(AB) = \text{tr}(BA)$

(ii) $\text{tr}(A+B) = \text{tr}(B+A)$

(iii) $(AB)C = A(BC)$

(iv) $\text{tr}(A^t) = \text{tr}(A)$

(v) $(AB)^t = B^t A^t$

Fake Proposition: $\text{tr}(ABC) = \text{tr}(BAC) = \text{tr}(CBA) = ...$ (any permutation)

Proof: Actually this is false. See this, http://mathworld.wolfram.com/MatrixTrace.html

Now to return to your specific problem.

$\text{tr} (X^tA^tAX + X^tXL) = \text{tr} (X^tA^tAX) + \text{tr} (X^tXL)$ by (ii)

Look at the second summand, then use (iv)

$\text{tr} (X^tXL) = \text{tr} (X^tXL)^t= \text{tr} (L^t X^t X)$

Therefore, we are left with,

$\text{tr} (X^tA^tAX) + \text{tr} (L^t X^t X)$

If the Proposition was true,

$\text{tr} (L^t X^t X) = \text{tr} (X^t L^t X)$

Hence,

$$\text{tr} (X^tA^tAX) + \text{tr} (X^t L^t X) = \text{tr}[ X^t(A^tA + L^t) X]$$

But unfortunately, I do not think you can take that one last step to put it into the form you would like.