sort - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


sort/polynomial

sort a polynomial

 

Calling Sequence

Parameters

Description

Thread Safety

Examples

Compatibility

Calling Sequence

sort(A)

sort(A, V, opt)

sort(A, order=o, opt)

Parameters

A

-

algebraic; expression to be sorted

V

-

(optional) variables

o

-

(optional) monomial order

opt

-

(optional) either ascending or descending

Description

• 

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.

Thread Safety

• 

The sort command is thread safe as of Maple 15, provided that a polynomial is not being sorted.  Sorting polynomials is not thread safe.

Examples

Sorting polynomials

sort1+x+x2

x2+x+1

(1)

fyz+y2+x+xy+x2+1+z+xz+y+z2+xyz+x3+z3+x2y+y2z

fx3+x2y+xyz+y2z+z3+x2+xy+xz+y2+yz+z2+x+y+z+1

(2)

sortf,x,y,z

x3+x2y+xyz+y2z+z3+x2+xy+xz+y2+yz+z2+x+y+z+1

(3)

sortf,x,y,z,ascending

1+z+y+x+z2+yz+y2+xz+xy+x2+z3+y2z+xyz+x2y+x3

(4)

sortf,order=grlexx,y,z

x3+x2y+xyz+y2z+z3+x2+xy+xz+y2+yz+z2+x+y+z+1

(5)

sortf,order=tdegx,y,z

x3+x2y+xyz+y2z+z3+x2+xy+y2+xz+yz+z2+x+y+z+1

(6)

sortf,order=plexx,y,z

x3+x2y+x2+xyz+xy+xz+x+y2z+y2+yz+y+z3+z2+z+1

(7)

sortf,order=plexx,y,z,descending

x3+x2y+x2+xyz+xy+xz+x+y2z+y2+yz+y+z3+z2+z+1

(8)

sortf,order=plexx,y,z,ascending

1+z+z2+z3+y+yz+y2+y2z+x+xz+xy+xyz+x2+x2y+x3

(9)

Notice the sorting is in-place; f uses the latest sorted order.

f

1+z+z2+z3+y+yz+y2+y2z+x+xz+xy+xyz+x2+x2y+x3

(10)

sorty+xyx,x

x+yx+y

(11)

sortax+by+cx2,x

cx2+ax+by

(12)

sortax+by+cx2,x,ascending

by+ax+cx2

(13)

The powers in an algebraic expression do not have to be positive integers. They can be negative integers or fractions.

fax2+bx6+cx4+dx32

fax2+bx6+cx4+dx32

(14)

sortf,x

dx32+ax2+cx4+bx6

(15)

Compatibility

See Also

degree

Groebner/MonomialOrders

indets

length

lexorder

list

polynom

sort

 


Download Help Document