Is it possible to make ncalgebra factorize commutative coefficients to the left?
For example, if I define a non-commutative object W
and a commutative object a
by
SetNonCommutative[W];
SetCommutative[a];
and then write
a W
the output is, as expected, just a W
. Same for
W a
However, if I write
a[t] W
instead, for some reason a[t]
lands on the right and the output is
W a[t]
Even if I apply Simplify
to the latter, it still remains the same.
Finally, if I write
a[t] W + a[t] tp[W] // Simplify
then the output looks as I would want it to:
a[t] (W + tp[W])
I found two similar questions on the forum, but the approach with NCCollect
doesn't work here.
Here's a more real life example:
The commutative expression in
a
in the second parentheses got factored out to the left, but not the expression in the first.
By the way, the LeafCount
of the expression factored as I want it to be is one less than the LeafCount
of the output.
P.S. I found the following approach to my real life example:
First, it feels more like a kludge than a solution, but it does the job. Secondly, the commutative factor is still not on the left, but at least the formula it's taken out.
Is there a better way to do it?