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

Hello,

I noticed that sort_product doesn't work for powers:

> ex := C B A**2 D;
C*B*A**2*D
> sort_product(_);
B*C*D*A**2

Why is it so? In case of non-integer or negative degree even expand_power before sort_product will not change the result.

Thank you!

in General questions by (450 points)

1 Answer

+1 vote
 
Best answer

That's because internally A**2 is stored as \pow{A}{2} and is thus alphabetically 'larger' than D.

You can get around it (sort of, it's not ideal) by doing

{\pow{A}{n?}, B, C, D}::SortOrder;
ex:= C B A**2 D;
sort_product(_);

which gives

A**2 B C D

The pattern \pow{A}{n?} matches any power of A.

by (76.4k points)
selected by
...