This is a rather simple question that I cannot quite figure out how to do. Basically, I have the result of some matrix multiplication in which my resultant matrix has a mixture of commutative and non-commutative symbols.

Is there a way to factor out the commutative symbols automatically? For example, one line in my matrix has non-commuting symbols e and g, and a constant $\Omega_1$ that commutes with everything.

I have used the following rules

SetCommutative[\[CapitalOmega]1, \[CapitalOmega]2, \[CapitalDelta]1, \[CapitalDelta]2]
SetNonCommutative[g, e, r]
DisplayRule = NonCommutativeMultiply[a__] :> Infix[NonCommutativeMultiply[a],"\InvisibleTimes]\[InvisibleTimes]"]

Which has allowed me to get NCAlgebra to output the following

$\Omega_1$ (e g) - $\Omega_1$ (g e)

and I would like it to factor to

$\Omega_1$ (e g - g e)

Is it possible to add another rule to get this sort of factorization I would like?


1 Answer 1


Ok, I found the function NCCollect from this question which can factor like so

NCCollect[a ** b ** c - a ** b ** d, {a, b}]

results in

a ** b ** (c - d)

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.