gives Order[ai,bi] for the first non-coinciding pair ai,bi of elements, and 0 if the lists are identical.


uses the ordering function p to compare ai with bi.


represents an operator form that compares lists when applied to {a1,a2,}, {b1,b2,}.



open allclose all

Basic Examples  (1)

Find whether two lists are ordered lexicographically:

Shorter lists are ordered first in canonical order:

Scope  (6)

Use an ordering function to order elements of the expressions:

Canonical order places 0 before -Infinity:

Heads other than List can be used:

Use LexicographicOrder with two strings:

The computation is equivalent to:

Order associations lexicographically by their values:

Use LexicographicOrder in Ordering to find the position of the last expression in lexical order:

Check whether several lists are sorted lexicographically:

Applications  (2)

Sort subsets lexicographically:

Compare two monomials lexicographically:

The first monomial is ordered first:

Properties & Relations  (9)

Order is determined by the first element that differs, regardless of total length:

LexicographicOrder returns 0 when the lists have the same elements:

When all elements coincide up to the shortest length, the shorter list is ordered first:

The empty list is sorted before any other list:

LexicographicSort[list] is equivalent to Sort[list,LexicographicOrder]:

Compare with canonical order:

For lists of the same length, LexicographicOrder is equivalent to Order:

LexicographicOrder with strings of letters is equivalent to AlphabeticOrder with default options:

AlphabeticOrder and Order are not lexicographic when the strings contain letters and numbers:

Compare with the ordering of the first characters:

For numeric vectors of equal length, LexicographicOrder[NumericalOrder] is equivalent to NumericalOrder:

VectorLess and related functions are similar to LexicographicOrder[NumericalOrder]:

Wolfram Research (2021), LexicographicOrder, Wolfram Language function, https://reference.wolfram.com/language/ref/LexicographicOrder.html.


Wolfram Research (2021), LexicographicOrder, Wolfram Language function, https://reference.wolfram.com/language/ref/LexicographicOrder.html.


Wolfram Language. 2021. "LexicographicOrder." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/LexicographicOrder.html.


Wolfram Language. (2021). LexicographicOrder. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LexicographicOrder.html


@misc{reference.wolfram_2024_lexicographicorder, author="Wolfram Research", title="{LexicographicOrder}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/LexicographicOrder.html}", note=[Accessed: 24-July-2024 ]}


@online{reference.wolfram_2024_lexicographicorder, organization={Wolfram Research}, title={LexicographicOrder}, year={2021}, url={https://reference.wolfram.com/language/ref/LexicographicOrder.html}, note=[Accessed: 24-July-2024 ]}