Booelan matrices for ordering and sorting

• To: mathgroup at smc.vnet.net
• Subject: [mg124147] Booelan matrices for ordering and sorting
• From: Chris Young <cy56 at comcast.net>
• Date: Wed, 11 Jan 2012 04:20:49 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

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:

http://home.comcast.net/~cy56/OrderMatrix.png
http://home.comcast.net/~cy56/OrderMatrix.nb

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

In[835]:= in\[HorizontalLine]order[e1_, e2_] :=
Module[
{sorted},
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 comcast.net

• 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