Skip to main content
2 of 2
added 285 characters in body
JvT
  • 33
  • 3

Pattern Match "Empty" Term in NonCommutativeMultiply

Not sure if this has been asked before, please point me to the post if it has.

Is there a way to treat terms like (b+c), a**(b+c), (b+c)**d and a**(b+c)**d together? By that I mean, is there a pattern like a_(Something or nothing)**(b_+c_)**d_(Something or nothing) and which allows for distributivity to be defined as something like

NCExpand[a_(Something or nothing)**(b_+c_)**d_(Something or nothing)]:= a**b**d+a**c**d

where for the case where a or d is not present they are not present in the expanded version.

Edit

Based on what is said in the comments I've done

But as can be seen from the output it doesn't work when the head is not NonCommutativeMultiply. I would like to be able to include it in the same definition.

JvT
  • 33
  • 3