This is a follow up to this question. In that question they use TagSetDelayed to give a symbol the distributive property. In my case this becomes
NonCommutativeMultiply /: Expand[NonCommutativeMultiply[a_,b_+c_]]:=Expand[NonCommutativeMultiply[a,b]]+
Expand[NonCommutativeMultiply[a,c]]
Indeed when I input it it expands
a**(b + c)//Expand
(* ==> a**b + a**c *)
This is nice but when this expression appear in a sum this expansion doesn't happen and the effect is ruined.
d + a**(b + c)//Expand
(* ==> d + a**(b + c) *)
I tried a few things but nothing worked (including ExpandAll
). I want a sum of many of these terms to distribute when I apply Expand
.
NonCommutativeMultiply[a_, b_ + c_] := NonCommutativeMultiply[a, b] + NonCommutativeMultiply[a, c]
? Thend + a ** (b + c)
automatically returnsd + a ** b + a ** c
, noExpand
required. $\endgroup$