LexicographicOrder
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
- Lexicographic order is also known as lexical order and dictionary order.
- Lexicographic order of two lists compares respective elements until one of the comparisons determines the order. If all elements coincide up to the length of the shorter list, that one is ordered first.
- By default, LexicographicOrder compares elements using canonical Order.
- LexicographicOrder[h[a1,a2,…],h[b1,b2,…],p] works for heads h other than List.
- LexicographicOrder[string1,string2] is equivalent to LexicographicOrder[Characters[string1],Characters[string2]].
- LexicographicOrder[p][list1,list2] is equivalent to LexicographicOrder[list1,list2,p].
Examples
open allclose allBasic Examples (1)
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:
Applications (2)
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]:
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]:
Text
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.
APA
Wolfram Language. (2021). LexicographicOrder. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LexicographicOrder.html