Given two distinct orthogonal matrices $A$ and $B$, given some individual sequence of applications of these matrices such that each matrix appears an equal number of times (e.g. $AABBAB$, with $3$ occurrences of each matrix), if the application of this sequence is equal to the application of the sequences dual, where each of our matrices is replaced by the other (e.g. $AABBAB=BBAABA$), do $A$ and $B$ necessarily commute ($AB=BA$)?
This is clearly a sufficient condition, but is it a necessary one?
I am trying to show $A$ and $B$ must belong to a subgroup of $O(n)$ isomorphic to $O(2)$.
It also bears note that both $A$ and $B$ must vary continuously according to some parameter $t\in (0,1)$ while retaining this property.
Edit: it seems that should $A$ and $B$ satisfy this condition, then $A$ may be replaced by any element $B^ZAB^{-Z}$.
To clarify my question: if one sequence of applications of the two matrices $A$ and $B$ in equal number is equal to the dual of that sequence made by swapping the matrices, are the matrices $A$ and $B$ necessarily commutative?
It is easy to construct two matrices $A$ and $A$ such that $(AB)^n=(BA)^n$ for some $n$. Take two reflections with respect to lines that form an angle of $2\pi/n$. They don't commute.
On a different line, take two matrices $A$ and $B$ of order $3$ that do not commute and notice that $AAABBB=BBBAAA$.