Order
Order[e1, e2]
returns 1 if e1
should come before e2
in canonical ordering, -1 if it should come after, and 0 if the two expressions are equal.
Attributes[Order] := {Protected}
Simple examples
Find the relative order of symbols:
In[1]:= Order[a, b]
Out[1]= 1
In[2]:= Order[b, a]
Out[2]= -1
In[3]:= Order[a, aa]
Out[3]= 1
Find the relative order of numbers:
In[4]:= Order[2, 1.]
Out[4]= -1
In[5]:= Order[1, 2]
Out[5]= 1
In[6]:= Order[1, 1]
Out[6]= 0
Find the relative order of strings:
In[7]:= Order["a", "b"]
Out[7]= 1
In[8]:= Order["b", "a"]
Out[8]= -1
Find the relative order of heterogenous types:
In[9]:= Order[ab, 1]
Out[9]= -1
In[10]:= Order[1, ab]
Out[10]= 1
In[11]:= Order[y[a], x]
Out[11]= -1
Find the relative order of rationals:
In[12]:= Order[Rational[-5, 3], Rational[-4, 6]]
Out[12]= 1
In[13]:= Order[Rational[4, 6], 0.6]
Out[13]= -1
In[14]:= Order[0.6, Rational[4, 6]]
Out[14]= 1
In[15]:= Order[Rational[4, 6], 0.7]
Out[15]= 1
Find the relative order of expressions:
In[16]:= Order[bar[x, y], bar[x, y]]
Out[16]= 0
In[17]:= Order[fizz[bar[x, y]], fizz[bar[x, y, a]]]
Out[17]= 1