I am considering formal functions of lists and used ** to define the concatination product:

bb /: bb[X_] ** bb[Y_] := be[Join[X, Y]]; 

So that for example bb[{a,b}]**bb[{c}] evaluates to bb[{a,b,c}]. Now I have a term of the form


And I want to evaluate this to (bb[{a,b}]-bb[{c}])/(b-c). But Mathematica does not evaluate it, even if I use Distribute or Expand. I tried to use the NCAlgebra package but with this NCExpand I get problems at other places in my code.

How can I tell mathematica to expand the above term the way I want? Is there a better way to define the concatination product for my purpose (as a noncommutative algebra over rational functions) ?

  • $\begingroup$ Welcome to Mathematica StackExchange. There are already several question regarding the NonCommutativeMultiply, such as this or this. $\endgroup$
    – Domen
    Dec 28, 2021 at 11:14

2 Answers 2


You should be able to use NCAlgebra to address your problem but I would be careful about some details.

First, I would not carry a List inside your function definition. A function in Mathematica is basically a list with a Head, so no need to carry one more list level.

Second, if you want your rule to trigger embedded in other products you need to add the possibility of left and right terms in your rule. Unfortunately NomCommutativeMultiply is not Flat, that is associative.

In NCAlgebra, something like

bb /: NonCommutativeMultiply[left___, bb[x__], bb[y__], right___] := NonCommutativeMultiply[left, bb[x, y], right];

would be such that

bb[A] ** ((bb[B] - bb[C])/(B - C)) // NCExpand

evaluates to

-(bb[A, C]/(B - C)) + bb[A, B]/(B - C)

when expanded. Note that I am using capital B and C since you are dividing by them, so I assume they are commutative. If you use b and c, which are by default noncommutative, then you would run into trouble.

The rule should also trigger with noncommutative left and right coefficients, as in

e ** bb[A] ** ((bb[B] ** d - bb[C])/(B - C)) // NCExpand

which evaluates to

-(e ** bb[A, C]/(B - C)) + bb[A, B] ** d/(B - C)

I do not anticipate any potential for bad interaction between such a rule and the rest of NCAlgebra.

  • $\begingroup$ Thank you very much for the detailed post. The answer of Daniel already helped to solve my original problem, but your answer will help to maybe implement it better. $\endgroup$
    – ayim691
    Feb 11, 2022 at 5:04

You must define the properties "bb" should have.

And you must make definitions that doe not lead to errors. E.g. what should "(b-c)" mean if b and c are list of different length?

Your example may be defined e.g. by:

bb /: bb[X_] ** bb[Y_] := bb[Join[X, Y]];
bb /: bb[x_] ** ( (bb[a_] - bb[b_])/c_) := (bb[Join[x, a]] - 
    bb[Join[x, b]])/c



enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.