WOLFRAM

LexicographicOrder[{a1,a2,},{b1,b2,}]

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

LexicographicOrder[{a1,a2,},{b1,b2,},p]

uses the ordering function p to compare ai with bi.

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

Details

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

Find whether two lists are ordered lexicographically:

Out[1]=1

Shorter lists are ordered first in canonical order:

Out[2]=2

Scope  (6)Survey of the scope of standard use cases

Use an ordering function to order elements of the expressions:

Out[1]=1

Canonical order places 0 before -Infinity:

Out[2]=2

Heads other than List can be used:

Out[1]=1

Use LexicographicOrder with two strings:

Out[1]=1

The computation is equivalent to:

Out[2]=2

Order associations lexicographically by their values:

Out[1]=1

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

Out[1]=1

Check whether several lists are sorted lexicographically:

Out[1]=1

Applications  (2)Sample problems that can be solved with this function

Sort subsets lexicographically:

Out[1]=1
Out[2]=2

Compare two monomials lexicographically:

Out[1]=1
Out[2]=2

The first monomial is ordered first:

Out[3]=3

Properties & Relations  (9)Properties of the function, and connections to other functions

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

Out[1]=1

LexicographicOrder returns 0 when the lists have the same elements:

Out[1]=1

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

Out[1]=1

The empty list is sorted before any other list:

Out[1]=1
Out[2]=2

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

Out[1]=1
Out[2]=2
Out[3]=3

Compare with canonical order:

Out[4]=4

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

Out[1]=1
Out[2]=2
Out[3]=3
Out[4]=4

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

Out[1]=1
Out[2]=2
Out[3]=3

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

Out[4]=4
Out[5]=5
Out[6]=6

Compare with the ordering of the first characters:

Out[7]=7

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

Out[2]=2
Out[3]=3

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

Out[2]=2
Out[3]=3
Out[4]=4
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.

Text

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.

CMS

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. Wolfram Research. https://reference.wolfram.com/language/ref/LexicographicOrder.html.

APA

Wolfram Language. (2021). LexicographicOrder. Wolfram Language & System Documentation Center. Retrieved from 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

BibTeX

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

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

BibLaTeX

@online{reference.wolfram_2025_lexicographicorder, organization={Wolfram Research}, title={LexicographicOrder}, year={2021}, url={https://reference.wolfram.com/language/ref/LexicographicOrder.html}, note=[Accessed: 18-May-2025 ]}

@online{reference.wolfram_2025_lexicographicorder, organization={Wolfram Research}, title={LexicographicOrder}, year={2021}, url={https://reference.wolfram.com/language/ref/LexicographicOrder.html}, note=[Accessed: 18-May-2025 ]}