Question: Sets????

You use curly braces, ie '{}' as a container. Within Maple such curly braces designate a set, and Maple will always display sets in "lexicographic" order.

Since order has no meaning for entries in a set, trying to "sort" a set is meaningless. You can only sort lists, Arrays etc where the concept of order meaningful

See the attached for examples of sorting sets, lists, Arrays, and note that sorting of sets doesn't do anything useful

For future reference

  1. This should be a "Question", not a "Post" (and if I knew how to move it I would!)
  2. When posting on this site, try to avoid using third party sites like dropbox. Upload code (not pictures of code) using the big green up-arrow in the Mapleprimes toolbar

  restart;
  alpha:=[2,3,4,5];
#
# Try sorting sets - won't work because
# order is meaningless in a set
#
  sort( {abs(alpha[1]-30),abs(alpha[2]-30),abs(alpha[3]-30),abs(alpha[4]-30)}, `<`);
  whattype(%);
  sort( {abs(alpha[1]-30),abs(alpha[2]-30),abs(alpha[3]-30),abs(alpha[4]-30)}, `>`);
  whattype(%);
#
# Do the same thing with lists, where order is significant
#
  sort( [abs(alpha[1]-30),abs(alpha[2]-30),abs(alpha[3]-30),abs(alpha[4]-30)], `<`);
  whattype(%);
  sort( [abs(alpha[1]-30),abs(alpha[2]-30),abs(alpha[3]-30),abs(alpha[4]-30)], `>`);
  whattype(%);
#
# You can also sort entries in an Array()
#
  sort(Array([abs(alpha[1]-30),abs(alpha[2]-30),abs(alpha[3]-30),abs(alpha[4]-30)]), `<`);
  whattype(%);
  sort(Array([abs(alpha[1]-30),abs(alpha[2]-30),abs(alpha[3]-30),abs(alpha[4]-30)]), `>`);
  whattype(%);

alpha := [2, 3, 4, 5]

 

{25, 26, 27, 28}

 

set

 

{25, 26, 27, 28}

 

set

 

[25, 26, 27, 28]

 

list

 

[28, 27, 26, 25]

 

list

 

Vector[row](4, {(1) = 25, (2) = 25, (3) = 25, (4) = 25})

 

Array

 

Array(%id = 18446744074423548974)

 

Array

(1)

 

Vector[row](4, {(1) = 25, (2) = 25, (3) = 25, (4) = 25})

 

Array

 

Array(%id = 18446744074423548974)

 

Array

(2)

 

Download sortSet.mw

Please Wait...