Are there non-commuting matrices for which $\mathrm{tr}(ABC)=\mathrm{tr}(BAC)$? For linear operators $A,B$ acting on $\mathbb{C}^n$ the fact that $\text{tr}(AB)=\text{tr}(BA)$ follows from the cyclic property of the trace, which says more generally that if $A,B,C$ are linear operators acting on $\mathbb{C}^n$ we have that $$\text{tr}(ABC)=\text{tr}(CAB)=\text{tr}(BCA)=\text{tr}(ABC).$$
My question is whether there are specific conditions on $A$, $B$, and $C$ such that $$\text{tr}(ABC)=\text{tr}(BAC)?$$ Clearly, its true if $A$ and $B$ commute, but its also sufficient for either $A$ or $B$ to commute with $C$, but are these necessary for this property to hold?
I should mention that I am primarily interested in the case that $A,B,C$ are invertible, since clearly if $A,B,C$ have zero divisors the property can be satisfied in a trivial sort of way.
 A: Given $C$ and $A$, $$\varphi(B) = \text{tr}(ABC) - \text{tr}(BAC)
= \text{tr}(B (CA-AC))$$ is a linear functional on $M_{n\times n}(\mathbb C)$, and if not identically $0$ it is $0$ on a linear subspace of $M_{n \times n}(\mathbb C)$ of
codimension $1$.  Thus for any $B_1$ and $B_2$ with $\varphi(B_2) \ne 0$, there is some $t$ such that $\varphi(B_1 + t B_2) = 0$ (namely $t = -\varphi(B_1)/\varphi(B_2)$).
A: it's worth mentioning an important special case that comes up e.g. in semi-definite programming.
Suppose $A,B,C$ are arbitrary real symmetric matrices, then
$\text{trace}\Big(ABC\Big)$
$=\text{trace}\Big(BCA\Big)$
$=\text{trace}\Big(\big(BCA\big)^T\Big)$
$=\text{trace}\Big(A^TC^TB^T\Big)$
$=\text{trace}\Big(ACB\Big)$
$=\text{trace}\Big(BAC\Big)$
(This proof of course formally works the same when all 3 are complex symmetric)
A: Consider three matrices in $M_{2 \times 2}(\mathbb{C})$ constructed from Pauli matrices & the identity:
$$
A = a_0 \mathbb{1}+ \sum_{i = 1}^3 a_i \sigma_i \qquad B = b_0 \mathbb{1} + \sum_{i = 1}^3 b_i \sigma_i \qquad C = c_0 \mathbb{1} + \sum_{i = 1}^3 c_i \sigma_i 
$$
The identity and the Pauli matrices form a basis for $M_{2 \times 2}(\mathbb{C})$, so any complex $2 \times 2$ matrix can be written in this form.
The commutator of any two Pauli matrices is $[\sigma_i, \sigma_j] = 2i \sum_k \epsilon_{ijk} \sigma_k$, where $\epsilon_{ijk}$ is the Levi Civita symbol.  We also have that $\mathrm{tr}(\sigma_i \sigma_j) = 2 \delta_{ij}$ and $\mathrm{tr}(\sigma_i) = 0$.   Combining these facts, it can be shown that
$$
\mathrm{tr}(ABC) - \mathrm{tr}(BAC) = 4 i \sum_{i,j,k=1}^3\epsilon_{ijk} a_i b_j c_k = 4 i \vec{a} \cdot (\vec{b} \times \vec{c})
$$
(the coefficients $a_0$, $b_0$, and $c_0$ drop out.)  So $\mathrm{tr}(ABC) = \mathrm{tr}(BAC)$ if and only if the vectors $\vec{a}$, $\vec{b}$, and $\vec{c}$ are not linearly independent.
As an example instance, consider
$$
A = \sigma_1 = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}, \quad B = \sigma_2 = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}, \quad C = A + B.
$$
No pair of the matrices $A$, $B$, and $C$ commute, and yet $ABC$ and $BAC$ both have zero trace.
A: Using Einstein notation:
$$tr(ABC) = A_{ij}B_{jk}C_{ki} = C_{ki}A_{ij}B_{jk} = B_{jk}C_{ki}A_{ij}$$
Therefore: $tr(ABC) = tr(CAB) = tr(BCA)$
$$tr(BAC) = B_{ij}A_{jk}C_{ki} = C_{ki}B_{ij}A_{jk} = A_{jk}C_{ki}B_{ij}$$
Therefore: $tr(BAC) = tr(CBA) = tr(ACB)$


*

*If $A$ and $B$ commute: $ABC = BAC$

*If $A$ and $C$ commute: $CAB = ACB$

*If $B$ and $C$ commute: $BCA = CBA$
In any of those cases:
$$tr(ABC) = tr(CAB) = tr(BCA) = tr(BAC) = tr(CBA) = tr(ACB)$$

Since the identity matrix always commute, for two matrices we have:
$$tr(AB) = tr(ABI) = tr(AIB) = tr(BAI) = tr(BA)$$

The condition $tr(ABC) = tr(BAC)$ will only be satisfied for all $C$ if $A$ and $B$ commute.
For a fixed non-commuting $C$, we need matrices $A$ and $B$ such that:
$$A_{ij}B_{jk}C_{ki} = B_{ij}A_{jk}C_{ki}$$

Here a numerical example with invertible non-commuting matrices, in which the property is satisfied:
$$A = \begin{bmatrix}1&2\\3&4\end{bmatrix} \;\;\; B = \begin{bmatrix}4&2\\3&1\end{bmatrix} \;\;\; C = \begin{bmatrix}1&0\\0&2\end{bmatrix}$$
