I have an expression where there are terms like
a ** (b*Tr[a ** b])
and I want to simplify it to something like
Tr[a ** b]a ** b
How can it be done? I have tried with NCExpand
and haven't worked.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI have an expression where there are terms like
a ** (b*Tr[a ** b])
and I want to simplify it to something like
Tr[a ** b]a ** b
How can it be done? I have tried with NCExpand
and haven't worked.
See my edits for my earlier submission.
Edited:
The command SetCommutative[Tr]
forces all of the expressions whose head is Tr to be considered commutative.
If necessary, you can use
UnProtect[Tr];SetCommutative[Tr];Protect[Tr];
.
Another solution is Tr/:CommutativeQ[Tr[x_]] := True;
In NCAlgebra, expressions are considered commutative only if the Head and all arguments are commutative. That is why using SetCommutative[Tr]
will fail in this case. If Tr
is commutative, Tr[x]
will still be noncomutative if x is noncommutative. However, I would not recommend that you add rules to CommutativeQ
. That can become messy. Instead use the brand new command SetCommutativeFunction
which is available with the version 5.0.6 of NCAlgebra. I would also discourage you from using the built in protected symbol Tr
. For example,
SetCommutativeFunction[trace];
a ** (b*trace[a ** b])
would evaluate to
trace[a ** b] * a ** b
as you want. By the way, I also implemented an operator tr
that has the properties of the standard matrix trace. You might want to give it a try.