# Define an operator with the distributive property that works in general expressions

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.

• Would it work if you simply defined NonCommutativeMultiply[a_, b_ + c_] := NonCommutativeMultiply[a, b] + NonCommutativeMultiply[a, c]? Then d + a ** (b + c) automatically returns d + a ** b + a ** c, no Expand required. – MarcoB May 18 '20 at 21:26
• I almost forgot that worked lol. But it's still less versatile. It means if you want to modify expressions you would always have to work with the expanded form. This would work for my specific use case but I'm leaving this question open because I feel this could be useful if it worked. – AccidentalTaylorExpansion May 18 '20 at 21:34
• Can you include an example of an expression for which the simpler definition does NOT do what you want? Maybe your minimal working example was too minimal here. – MarcoB May 18 '20 at 21:40