2
$\begingroup$

{1, 2} < {3, 4} doesn't seem to work, but Sort[{{3, 4}, {1, 2}}] yields {{1, 2}, {3, 4}}.

I want to use the order relationship that Sort uses for my program

(lexicographic ordering will do fine, doesn't really matter what I use so long as it's a strict total order)

I'm used to Haskell automagically deriving such an order for any data types I construct, via the Ord class.

Edit: The Order function does what I need.

$\endgroup$
3
$\begingroup$

One way might be to use Ordering

list = {{3, 4}, {1, 2}};
ord = Ordering[list]

Mathematica graphics

list[[ord]]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ I've looked it up from your functions. It appears what I'm looking for is the Order function. $\endgroup$ Apr 16 '20 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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