sort/polynomial
sort a polynomial
Calling Sequence
Parameters
Description
Thread Safety
Examples
Compatibility
sort(A)
sort(A, V, opt)
sort(A, order=o, opt)
A
-
algebraic; expression to be sorted
V
(optional) variables
o
(optional) monomial order
opt
(optional) either ascending or descending
The sort command sorts the terms of polynomials in an algebraic expression A into descending order. See the main sort help page for information about sorting lists and rtables.
In Maple, polynomials are not automatically stored in sorted order. They are stored in the order they were first created and printed in the order they are stored. The sort command can be used to sort polynomials.
Note: Sorting polynomials is a destructive operation: the input polynomial is sorted "in-place".
If V is given, it specifies the variable ordering to be used when sorting polynomials. It can be a name, a function, or a list or set of names (for the multivariate case).
All polynomials in the expression A are sorted into decreasing order in V. If V is a list or set then polynomials in V are sorted in total degree with ties broken by lexicographic order (this is called graded lexicographic order). If neither V nor o is specified then the indets appearing in A and graded lexicographic order are used.
Other monomial orders can be specified by using the order=o calling sequence. The supported orders are:
plex(x1, ..., xn) - lexicographic order
grlex(x1, ..., xn) - graded lexicographic order
tdeg(x1, ..., xn) - graded reverse lexicographic order
for indeterminates x1, ..., xn. For a description of these orders, see Monomial orders for multivariate polynomials.
When sorting polynomials the optional argument ascending or descending may be specified to put the terms into ascending or descending order, respectively. The default is descending order, which puts higher-degree terms before lower-degree terms.
The sorting algorithm used for sorting polynomials is an in-place Shell sort. Lexicographic ordering of strings and symbols assumes the collating sequence of the US-ASCII character set.
The sort command is thread safe as of Maple 15, provided that a polynomial is not being sorted. Sorting polynomials is not thread safe.
Sorting polynomials
sort1+x+x2
x2+x+1
f≔yz+y2+x+xy+x2+1+z+xz+y+z2+xyz+x3+z3+x2y+y2z
f≔x3+x2y+xyz+y2z+z3+x2+xy+xz+y2+yz+z2+x+y+z+1
sortf,x,y,z
x3+x2y+xyz+y2z+z3+x2+xy+xz+y2+yz+z2+x+y+z+1
sortf,x,y,z,ascending
1+z+y+x+z2+yz+y2+xz+xy+x2+z3+y2z+xyz+x2y+x3
sortf,order=grlexx,y,z
sortf,order=tdegx,y,z
x3+x2y+xyz+y2z+z3+x2+xy+y2+xz+yz+z2+x+y+z+1
sortf,order=plexx,y,z
x3+x2y+x2+xyz+xy+xz+x+y2z+y2+yz+y+z3+z2+z+1
sortf,order=plexx,y,z,descending
sortf,order=plexx,y,z,ascending
1+z+z2+z3+y+yz+y2+y2z+x+xz+xy+xyz+x2+x2y+x3
Notice the sorting is in-place; f uses the latest sorted order.
f
sorty+xy−x,x
x+y−x+y
sortax+by+cx2,x
cx2+ax+by
sortax+by+cx2,x,ascending
by+ax+cx2
The powers in an algebraic expression do not have to be positive integers. They can be negative integers or fractions.
f≔ax2+bx6+cx4+dx32
sortf,x
dx32+ax2+cx4+bx6
See Also
degree
Groebner/MonomialOrders
indets
length
lexorder
list
polynom
sort
Download Help Document