Sponsored links: Algebra eBooks
 

Help Index

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

The Maxima on-line user's manual

Algebra Calculator

Search:

Sort Calculator

Sort

Function: sort (<L>, <P>)

load (newton1);
eq1:sin(x)+cos(3*x)+1;
plot2d(eq1,[x,-3.2,3.2]);
li:makelist (i/4, i, -3, 3);
sols:unique(map(round,flatten(sort(outermap(newton, [eq1], [x], li, [1E-6]))*1000))/1000),numer;

Function: sort (<L>) Sorts a list <L> according to a predicate P of two arguments, such that <P> (<L>[k], <L>[k + 1]) is true for any two successive elements. The predicate may be specified as the name of a function or binary infix operator, or as a lambda expression. If specified as the name of an operator, the name is enclosed in "double quotes".

The sorted list is returned as a new object; the argument <L> is not modified. To construct the return value, sort makes a shallow copy of the elements of <L>.

If the predicate <P> is not a total order on the elements of <L>, then sort might run to completion without error, but the result is undefined. sort complains if the predicate evaluates to something other than true or false.

sort (<L>) is equivalent to sort (<L>, orderlessp). That is, the default sorting order is ascending, as determined by orderlessp. All Maxima atoms and expressions are comparable under orderlessp.

The predicate ordergreatp sorts a list in descending order. The predicate ordermagnitudep sorts Maxima numbers, constant symbols with a numerical value, or expressions which can be evaluated to a constant by magnitude. All other elements of the list <L> are sorted by orderlessp. The predicate "<" allows the ordering by magnitude too, but does not order completely if elements in the list <L> are not comparable under "<".

Examples:

          (%i1) sort ([11, -17, 29b0, 7.55, 3, -5/2, b + a, 9 * c,
                19 - 3 * x]);
                         5
          (%o1) [- 17, - -, 3, 7.55, 11, 2.9b1, b + a, 9 c, 19 - 3 x]
                         2
          (%i2) sort ([11, -17, 29b0, 7.55, 3, -5/2, b + a, 9*c, 19 - 3*x],
                ordergreatp);
                                                             5
          (%o2) [19 - 3 x, 9 c, b + a, 2.9b1, 11, 7.55, 3, - -, - 17]
                                                             2
          (%i3) sort ([%pi, 3, 4, %e, %gamma]);
          (%o3)                [3, 4, %e, %gamma, %pi]
          (%i4) sort ([%pi, 3, 4, %e, %gamma], "<");
          (%o4)                [%gamma, %e, 3, %pi, 4]
          (%i5) my_list: [[aa,hh,uu], [ee,cc], [zz,xx,mm,cc], [%pi,%e]];
          (%o5) [[aa, hh, uu], [ee, cc], [zz, xx, mm, cc], [%pi, %e]]
          (%i6) sort (my_list);
          (%o6) [[%pi, %e], [aa, hh, uu], [ee, cc], [zz, xx, mm, cc]]
          (%i7) sort (my_list, lambda ([a, b], orderlessp (reverse (a),
                reverse (b))));
          (%o7) [[%pi, %e], [ee, cc], [zz, xx, mm, cc], [aa, hh, uu]]

Order Maxima numbers, constants, and constants expressions by magnitude, and all other elements in ascending sorting order:

          (%i8) sort([%i,1+%i,2*x,minf,inf,%e,sin(1),0,1,2,3,1.0,1.0b0],
                ordermagnitudep);
          (%o8)  [minf, 0, sin(1), 1, 1.0, 1.0b0, 2, %e, 3, inf, %i, %i + 1, 2 x]

There are also some inexact matches for sort. Try ?? sort to see them.

(%o1)                                true
(%i2) 

Sort Example

Related Examples

sort

l: [2,1,4,3];

o: sort(l);

Calculate

sort

a:[2,3,5,1,6,7];

sort(a);

Calculate

sort

a:[2,3,5,1,6,7];

sort(a,"<");

Calculate

sort

a :sort([1, 7, 3, 56,...

a[1];

Calculate

sort

a = sort([1, 7, 3, 56...

a;

Calculate

sort

sort([F, k, Q1, Q2, d]);

Calculate

sort

sort([12,23,3,14,124,...

Calculate

sort

a:[2,3,5,1,6,7];

sort(a,"<");

b:a;

Calculate

sort

l: [2,1,4,3];

o: sort(l);

Calculate

sort

l:[1,-1,2,-2];

ls:sort(l);

ls[1];

Calculate