Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
0 votes

For example,

{\mu,\nu}::Indices(vector).
{a^{\mu},b^{\mu}}::NonCommuting.
ex:=a b a^{\mu} a b_{\mu} b+a b b^{\mu} b a_{\mu} a;
canonicalise(_);

I want to move 'a' & 'b' to left side, but I don't know how to do it ('factor_out' is not simple enough to do it).

asked in General questions by (480 points)

1 Answer

+2 votes
 
Best answer

Add a SortOrder property to determine how you want symbols to be sorted, and then use the sort_product algorithm:

{\mu,\nu}::Indices(vector).
{a,b,a{#},b{#}}::SortOrder.
{a^{\mu},b^{\mu}}::NonCommuting.
ex:=a b a^{\mu} a b_{\mu} b+a b b^{\mu} b a_{\mu} a;
sort_product(_);

which produces $$aabb a^{\mu} b_{\mu} + aabb b^{\mu} a_{\mu} .$$ If you want to do it, instead, with factor_out(_, $a,b$), then you will need a call to distribute(_) afterwards to get rid of the brackets again.

answered by (50.6k points)
selected by

It works, thx

...