I am working on some operator calculation; I do not want the commutation relation.
so xy ≠ yx.
I found the mathematica code from
https://reference.wolfram.com/language/ref/NonCommutativeMultiply.html
and from the example code,
ExpandNCM[(h : NonCommutativeMultiply)[a___, b_Plus, c___]] := Distribute[h[a, b, c], Plus, h, Plus, ExpandNCM[h[##]] &] ExpandNCM[(h : NonCommutativeMultiply)[a___, b_Times, c___]] := Most[b] ExpandNCM[h[a, Last[b], c]] ExpandNCM[a_] := ExpandAll[a] so that
ExpandNCM[(a + b) ** (c + z)] I got
a ** c + a ** z + b ** c + b ** z But the problem is, it does not recognize the real number such that
ExpandNCM[2 (a + b) ** (c + z)] 2 (a + b) ** (c + z) It will work if I make it like (Obviously)
2 * ExpandNCM[(a + b) ** (c + z)] 2 (a ** c + a ** z + b ** c + b ** z) Would you help me to add some condition that if the variable is Real number, then take it out front?