MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Booelan matrices for ordering and sorting

  • To: mathgroup at
  • Subject: [mg124147] Booelan matrices for ordering and sorting
  • From: Chris Young <cy56 at>
  • Date: Wed, 11 Jan 2012 04:20:49 -0500 (EST)
  • Delivered-to:

Just to make sure I understood how Sort was using its ordering 
function, I created a boolean matrix for the sorting.

Are ordering matrices always upper triangular? Could have saved some 
time right there. In that case, all you have to do is enter the right 
size upper triangular booean matrix, right down the order you want to 
sort into, and you're done.

Wish I had a more concise way of picking out the matrix element. I had 
trouble using Extract and with mapping Position onto the elements.

Come to think of it, maybe if I give the whole sorted list, I don't 
need the boolean matrix. It may still be needed if I'm sorting lists 
longer or shorter than the sorted prototype though (?).

A picture and a notebook are at:

Returns true if the elements are in correct order as they occur in the list:

In[835]:= in\[HorizontalLine]order[e1_, e2_] :=
  sorted = {1, 2, a, b, A, B};
     {T, T, T, T, T, T},
     {F, T, T, T, T, T},
     {F, F, T, T, T, T},
     {F, F, F, T, T, T},
     {F, F, F, F, T, T},
     {F, F, F, F, F, T}
    } \
    [[Position[sorted, e1][[1, 1]], Position[sorted, e2][[1, 1]]]]
In[836]:= in\[HorizontalLine]order[#1, #2] & @@@ {{1, b}, {b, 2}, {2, A}, {A,
   B}, {B, a}}
Out[836]= {True, False, True, True, False}

Chris Young
cy56 at

  • Prev by Date: Re: Plotting an Array of Vectors
  • Next by Date: Re: Question about typesetting
  • Previous by thread: Tick marks don't scale proportionally with other elements of the
  • Next by thread: NMinimize Method suboptions