Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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]
- compressNCM[expr_] := expr /. NonCommutativeMultiply[x__] :>
- StringJoin@(ToString /@ {x})
- toNCM[expr_] :=
- expr /. str_String :>
- NonCommutativeMultiply @@ (ToExpression /@ Characters[str])
- encm = expandNCM[(a ** b + c ** d) ** (e ** f + g ** h)]
- % // compressNCM
- encm == % // toNCM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement