Noncommutative Expand over addition in Mathematica

2019-02-20 14:37发布

I need to write a function(s) that completely expands noncommutative multiplication over addition?
For example:
a ** (b + c^2) would expand to
a ** b + a ** c^2
and similarly from the right.

I am using ReplaceRepeated (.//). Since I am using NonCommutativeMultiply instead of Times, Expand does not work. I was using the NCAlgebra package which has NCExpand, however ReplaceRepeated does not work when using this package (as stated in the NCAlgebra documentation...argh).

To avoid breaking ReplaceRepeated , I need to code my own NCExpand that is not going to conflict.

All ideas are welcome, thanks...

2条回答
迷人小祖宗
2楼-- · 2019-02-20 15:17

Try this package which includes a noncommutative Expand as well as other functions rewritten for NC calculations.

From that package:

GExpand[a_, patt___] := Expand[a //. {x_NonCommutativeMultiply :> Distribute[x]}, patt];

In[1]  := GExpand[a ** (b + c^2)]
Out[1] := a ** b + a ** c^2

In[2]  := GExpand[a ** (b + c^2)] //. a -> foo
Out[2] := foo ** b + foo ** c^2
查看更多
看我几分像从前
3楼-- · 2019-02-20 15:20

The newest version of NCAlgebra supports ReplaceRepeated through NCReplaceRepeated.

查看更多
登录 后发表回答