(Redirected from Lexicographic order)In
mathematics, the 'lexicographic' or 'lexicographical order', (also known as 'dictionary order', 'alphabetic order' or 'lexicographic(al) product'), is a natural
order structure of the
Cartesian product of two ordered sets.
Given two
partially ordered sets ''A'' and ''B'', the lexicographical order on the Cartesian product ''A'' × ''B'' is defined as
:(''a'',''b'') ≤ (''a''′,''b''′) if and only if ''a'' < ''a''′ or (''a'' = ''a''′ and ''b'' ≤ ''b''′).
The result is a partial order. If ''A'' and ''B'' are
totally ordered, then the result is a total order also.
More generally, one can define the lexicographic order on the Cartesian product of ''n'' ordered sets, on the Cartesian product of a countably infinite family of ordered sets, and on the union of such sets.
Motivation and uses
The name of the lexicographic order comes from its generalizing the order given to words in a
dictionary: a sequence of letters (that is, a ''word'')
:''a''
1''a''
2 ... ''a''
''k''
appears in a dictionary before a sequence
:''b''
1''b''
2 ... ''b''
''k''
if and only if the first ''a
i'' which is different from ''b
i'' comes before ''b
i'' in the
alphabet. That assumes both have the same length; what is usually done is to pad out the shorter word for symbols for 'blanks', and to consider that a blank is a new minimum ('bottom') element.
For the purpose of dictionaries, etc., one may assume that all words have the same length, by adding blank spaces at the end, and considering the blank space as a special character which comes before any other letter in the alphabet. This also allows ordering of phrases. See
alphabetical order.
An important property of the lexicographical order is that it preserves
well-orders, that is, if ''A'' and ''B'' are well-ordered sets, then the product set ''A'' × ''B'' with the lexicographical order is also well-ordered.
An important exploitation of lexicographical ordering is expressed in the
ISO 8601 date formatting scheme, which expresses a date as YYYY-MM-DD. This date ordering lends itself to straightforward
computerized sorting of dates such that the sorting algorithm does not need to treat the numeric parts of the date string any differently from a string of non-numeric characters, and the dates will be sorted into chronological order. Note, however, that for this to work, there must always be four digits for the year, two for the month, and two for the day, so for example single-digit days must be padded with a zero yielding '01', '02', ... , '09'.
Case of multiple products
Suppose
:
is an n-tuple of sets, with respective total orderings
:
The dictionary ordering
:
of
:
is then
:
That is, if one of the terms
:
and all the preceding terms are equal.
Informally,
:
represents the first letter,
:
the second and so on when looking up a word in a dictionary, hence the name.
This could be more elegantly stated by recursively defining the ordering of any set
:
represented by
:
This will satisfy
:
:
where
To put it simpler, compare the first terms. If they are equal, compare the second terms — and so on. The relationship between the first corresponding terms that are not equal determines the relationship between the entire elements.
Groups and vector spaces
If the component sets are
ordered groups then the result is a non-
Archimedean group, because e.g. ''n''(0,1) < (1,0) for all ''n''.
If the component sets are
ordered vector spaces over 'R' (in particular just 'R'), then the result is also an ordered vector space.
Ordering of sequences of various lengths
Given a partially ordered set ''A'', the above considerations allow to define naturally a lexicographical partial order
over the
free monoid ''A''
★ formed by the set of all
finite sequences of elements in ''A'', with sequence
concatenation as the monoid operation, as follows:
:
if
:
★
is a
prefix of
, or
:
★
and
, where
is the longest common prefix of
and
,
and
are members of ''A'' such that