Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am looking for non-canonical sorts of lists. A function that would give:

Sort[X, "order type"]

With "order type" being colex, revlex, etc.

share|improve this question
    
I assume your X's are list of numbers. Define a predicate that handles lex. Then many other orders can be attained by multiplying by an appropriate matrix. For example revlex would use a matrix with 1's on the antidiagonal and 0's elsewhere. –  Daniel Lichtblau Aug 10 '13 at 23:24

1 Answer 1

I believe you can effect any of the lex, colex, revlex, revcolex sorts by reversing elements and lists in the proper sequence.

Edit: My original answer used Sort and Reverse. Since at the moment I cannot see why I did not use SortBy[x, Reverse] as Simon Woods did in an answer to a similar question I am modifying my answer to use the simpler method.

Reverse Lexicographic

The simplest variation, merely reverse the list after sorting:

Reverse @ Sort[x]

Colexicographical

Reverse the elements before sorting, using SortBy:

SortBy[x, {Reverse}]

Reverse Colexicographic

Simply reverse the entire list in addition to the steps for the colex sort:

Reverse @ SortBy[x, {Reverse}]

Examples

A visualization function:

plot = ArrayPlot[SparseArray[List /@ # -> 1] & /@ #, ImageSize -> 80] &;

A random shuffle of subsets:

x = RandomSample @ Subsets[Range@7, {3}];

Our orderings:

lex      = Sort[x];
revlex   = Reverse @ Sort[x];
colex    = SortBy[x, {Reverse}];
revcolex = Reverse @ SortBy[x, {Reverse}];

A comparative graphic:

Row[plot /@ {lex, revcolex, colex, revlex}]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.