I have objects wrapped with head fv. So they are things like

fv[{1, 2}, {3, 4}, {5, 6}]

I then defined two operators, a and ad that act on these objects and spit back new objects, also with head fv:

a[v /; Head[v] == fv] = ... object returned that looks like fv[{1,2},{3, 4} ...];
ad[v /; Head[v] == fv] = ... object returned that looks like fv[{4, 5}, {6, 7} ...];
op[a] * fv[y_]  ^:= a[fv[y]];
op[ad] * fv[y_] ^:= ad[fv[y]];

So now I can evaluate expressions like op[a]*fv[{1, 2}, {3, 4}].

I now want to also be able to evaluate expressions like op[a]**op[ad]*fv[{1, 2}, {3, 4}] where the ** denotes non-commutative multiplication. When I try implementing this with

op[a] ** op[ad]*fv[y_] ^:= a[ad[fv[y]]];

Mathematica tells me that NonCommutativeMultiply is protected. How should I go about doing this?


1 Answer 1


The following, based on the post 'Non-Commutative Sorting in Mathematica', works well. I redefined the operator product so that it produces another object with head op and then generalized the definition of the action of these op objects.

op[x__] ** op[y__] ^:= op[x, y]
op[a] * fv[y__]  ^:= a[fv[y]];
op[x__, a] * fv[y__] ^:= op[x]*a[fv[y]];
...and similarly for ad

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.