Cadabra
a field-theory motivated approach to computer algebra

sort_sum

Sort terms in a sum.
Sort terms in a sum, taking into account any SortOrder properties, or else sorting lexographically.
ex:=E+D+A+C+B;
\(\displaystyle{}E+D+A+C+B\)
sort_sum(_);
\(\displaystyle{}A+B+C+D+E\)
This is often useful in case sums appear as exponents; in this case it is necessary to first sort the sums before terms can be collected, as the following example shows.
ex:=a**(-1+d) - a**(d-1);
\(\displaystyle{}a^{\left(-1+d\right)}-a^{\left(d-1\right)}\)
sort_sum(_);
\(\displaystyle{}0\)
Copyright © 2001-2024 Kasper Peeters
Questions? info@cadabra.science