# Is there an inequality operator (Less, Greater) for lists of elements (as opposed to elements)?

Like multi-column sorting. For example,

{1,3,5} > {1,2,5}


would return True, while

{1,3,5} > {1,5,2}


would return False.

I'm betting there's a simple term for this and that term would lead straight to some function, but I can't think of the term. It'd be a trivial function to write, but there must be something built-in...

(I'm looking for a predicate I can supply to this PriorityQueue implementation.)

• Tiebreaking is a term that just came to mind, but searching it yields no results. – Andrew Cheong Mar 19 '15 at 6:29
• Look at OrderedQ... – ciao Mar 19 '15 at 6:35
• Agh, that was what I was looking for. Still not well-versed in $Mathematica$. I didn't think to read through the *Q functions, even after thinking the word "Predicate"—I guess I'd only seen more primitive *Q functions so didn't think I'd find my answer there. In case this question might help someone else searching the terms I've used, could you post your comment as an answer? Thanks. – Andrew Cheong Mar 19 '15 at 6:38
• It's been a long day. Thanks, I'll fix. – Andrew Cheong Mar 19 '15 at 8:07
• what about {1,3,5} > {1,2,7}? You could make a case for either answer. Or {1,3,5} > {1,1,3,5} ? – ControlAltDel Mar 19 '15 at 12:21

I propose using Order, assuming equal-length lists.

Order[{1, 3, 5}, {1, 3, 4}]
Order[{1, 3, 5}, {1, 5, 2}]
Order[{1, 3, 5}, {1, 3, 5}]

-1

1

0


You can assign an infix operator if you wish:

CirclePlus = Order;

{1, 3, 5} ⊕ {1, 3, 4}
{1, 3, 5} ⊕ {1, 5, 2}
{1, 3, 5} ⊕ {1, 3, 5}

-1

1

0


You can convert the numeric output to Boolean as needed, but often it is faster to use it numerically. An example of conversion:

Star = Composition[Negative, Order];

{1, 3, 5} ⋆ {1, 3, 4}
{1, 3, 5} ⋆ {1, 5, 2}
{1, 3, 5} ⋆ {1, 3, 5}

True

False

False

listGreater[l1_, l2_] := OrderedQ@{l2, l1}&& l1 =!= l2
listLess[l1_, l2_] := OrderedQ@{l1, l2}&& l1 =!= l2
listGreaterEqual[l1_, l2_] := OrderedQ@{l2, l1}
listLessEqual[l1_, l2_] := OrderedQ@{l1, l2}

{1, 3, 5}~listGreater~{1, 3, 4}

(* True *)