# NonCommutativeMultiply question- syntax question

if I define id as:

id /: NonCommutativeMultiply[id, x_] := x
id /: NonCommutativeMultiply[y_, id] := y


then id ** a - a ** id gives 0. However if:

NCM[x___] := NonCommutativeMultiply[x];
id /: NCM[id, x_] := x
id /: NCM[y_, id] := y


then id ** a - a ** id gives -a ** id + id ** a  and not 0

I am confused as to why this happens(?)

• Attributes[TagSet] includes HoldAll, so NCM is not expanded during the definition of the pattern and NonCommutativeMultiply (which you have with **) does not match NCM. – eyorble Dec 19 '20 at 22:29
• thanks. So how do I change that? – geom Dec 19 '20 at 22:40
• Evaluate[NCM[...]], or just avoid using the abbreviation in the first place. ... /: id ** x_ and ... /: y_ ** id should also work. – eyorble Dec 19 '20 at 22:43

Attributes[TagSet] includes HoldAll, so NCM is not expanded during the definition of the pattern and NonCommutativeMultiply (which you have with **) does not match NCM.

To avoid this, you can either expand NCM explicitly in the pattern by using Evaluate:

id /: Evaluate@NCM[id, x_] := x
id /: Evaluate@NCM[y_, id] := y


Or by avoiding the abbreviation entirely:

id /: id ** x_ := x
id /: y_ ** id := y


Alternatively, you can theoretically Unprotect[TagSet] and ClearAttributes[TagSet,HoldAll]. I am not aware of how often TagSet is relied upon internally, but I am quite positive that this will have unintended and likely unwanted side effects, so I can't recommend it.

• Thanks for the detailed answer. I found NCM[x___] := NonCommutativeMultiply[x] here but I noticed that it can produce problems, hence my question – geom Dec 19 '20 at 23:12