SymPy was assuming that all variables behave like regular numbers (where 2 x3 is the same as 3x2).
However, in advanced math (like Matrices or Quantum Physics), the order matters (AxB is not the same as BxA). This is called Non-Commutative math.
SymPy was incorrectly using high-school formulas like:
This formula is wrong for Matrices. It should have stayed as just sin(A+B).
I added a "Guard Clause" (a safety check) to the code for sin, cos, and tan.
The logic I added is simple:
Before expanding a formula, the computer now asks: "Are these variables non-commutative?" * If Yes: It stops and leaves the expression alone (Fixed!).
If No: It expands it like normal (Standard math still works).