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. Mathematics is the body of Knowledge and Academic discipline that studies such concepts as Quantity, Structure, Space and Order theory is a branch of Mathematics that studies various kinds of Binary relations that capture the intuitive notion of ordering providing a framework for saying Cartesian square redirects here For Cartesian squares in Category theory, see Cartesian square (category theory.

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 aa′ or (a = a′ and bb′). In Mathematics, especially Order theory, a partially ordered set (or poset) formalizes the intuitive concept of an ordering sequencing or arrangement

The result is a partial order. If A and B are totally ordered, then the result is a total order also. In Mathematics and Set theory, a total order, linear order, simple order, or (non-strict ordering is a Binary relation

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)

a1a2 . A dictionary is a book of alphabetically listed Words in a specific language with definitions etymologies pronunciations and other information or a book of alphabetically . . ak

appears in a dictionary before a sequence

b1b2 . . . bk

if and only if the first ai which is different from bi comes before bi in the alphabet. An alphabet is a standardized set of letters basic written symbols each of which roughly represents a Phoneme, a Spoken language, either That assumes both have the same length; what is usually done is to pad out the shorter word with 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. In Mathematics, a well-order relation (or well-ordering) on a set S is a Total order on S with the property that every

An important exploitation of lexicographical ordering is expressed in the ISO 8601 date formatting scheme, which expresses a date as YYYY-MM-DD. ISO 8601 is an International standard for date and Time representations issued by the International Organization for Standardization (ISO 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. In Computer science and Mathematics, a sorting algorithm is an Algorithm that puts elements of a list in a certain 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

$\{ A_1, A_2, \dots, A_n \}$

is an n-tuple of sets, with respective total orderings

$\{ <_1, <_2, \cdots, <_n \}$

The dictionary ordering

$\ \ <^d$

of

$A_1 \times A_2 \times \cdots \times A_n$

is then

$(a_1, a_2, \dots, a_n) <^d (b_1,b_2, \dots, b_n) \iff (\exists\ m > 0) \ (\forall\ i < m) (a_i = b_i) \land (a_m <_m b_m)$

That is, if one of the terms

$\ \ a_m <_m b_m$

and all the preceding terms are equal.

Informally,

$\ \ a_1$

represents the first letter,

$\ \ a_2$

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

$\ \ C= A_j \times A_{j+1} \times \cdots \times A_k$

represented by

$\ \ <^d (C)$

This will satisfy

$a <^d (A_i) a' \iff (a <_i a')$
$(a,b) <^d (A_i \times B) (a',b') \iff a <^d (A_i) a' \lor ( a=a' \ \land \ b <^d (B) b')$

where $B = A_{i+1} \times A_{i+2} \times \cdots \times A_n.$

To put it more simply, 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. In Abstract algebra, an ordered group is a group (G+ equipped with a Partial order "≤" which is translation-invariant In Abstract algebra, a branch of Mathematics, an Archimedean group is an Algebraic structure consisting of a set together with a Binary 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. In Mathematics an ordered vector space or partially ordered vector space is a Vector space equipped with a Partial order which is compatible

## Ordering of sequences of various lengths

Given a partially ordered set A, the above considerations allow to define naturally a lexicographical partial order < d 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:

u < dv if
• u is a prefix of v, or
• u = wau' and v = wbv', where w is the longest common prefix of u and v, a and b are members of A such that a < b, and u' and v' are members of A*. In Abstract algebra, the free monoid on a set A is the Monoid whose elements are all the finite sequences (or strings) of zero or In Mathematics, a tuple is a Sequence (also known as an "ordered list" of values called the components of the tuple For concatenation of general lists see Append. In Computer programming, string concatenation is the operation of joining two character A prefix is a type of Affix attached to a stem which modifies the meaning of that stem

If < is a total order on A, then so is the lexicographic order <d on A*. If A is a finite and totally ordered alphabet, A* is the set of all words over A, and we retrieve the notion of dictionary ordering used in lexicography that gave its name to the lexicographic orderings. In Computer programming and some branches of Mathematics, a string is an ordered Sequence of Symbols. However, in general this is not a well-order, even though it is on the alphabet A; for instance, if A = {a, b}, the language {anb | n ≥ 0} has no least element: . In Mathematics, a well-order relation (or well-ordering) on a set S is a Total order on S with the property that every A formal language is a set of words, ie finite strings of letters, or symbols. . . <d aab <d ab <d b. A well-order for strings, based on the lexicographical order, is the shortlex order. The shortlex (or radix, or length-plus-lexicographic) order is an ordering for Ordered sets of objects where the sequences are primarily sorted by

Similarly we can also compare a finite and an infinite string, or two infinite strings.

Comparing strings of different lengths can also be modeled as comparing strings of infinite length by right-padding finite strings with blank spaces, if, as usual, the blank space is the least element of the alphabet (or, if it is originally not in the alphabet, adding it as least element).

## Generalization

Consider the set of functions f from a well-ordered set X to a totally ordered set Y. In Mathematics, a well-order relation (or well-ordering) on a set S is a Total order on S with the property that every In Mathematics and Set theory, a total order, linear order, simple order, or (non-strict ordering is a Binary relation For two such functions f and g, the order is determined by the values for the smallest x such that f(x) ≠ g(x).

If Y is also well-ordered and X is finite, then the resulting order is a well-order. As already shown above, if X is infinite this is in general not the case.

If X is infinite and Y has more than one element, then the resulting set YX is not a countable set, see also cardinal exponentiation. This article describes cardinal numbers in mathematics For cardinals in linguistics see Names of numbers in English.

Alternatively, consider the functions f from an inversely well-ordered X to a well-ordered Y with minimum 0, restricted to those which are non-zero at only a finite subset of X. The result is well-ordered. Correspondingly we can also consider a well-ordered X and apply lexicographical order where a higher x is a more significant position. This corresponds to exponentiation of ordinal numbers YX. In the mathematical field of Set theory, ordinal arithmetic describes the three usual operations on Ordinal numbers addition multiplication and exponentiation If X and Y are countable then the resulting set is also countable.

## Monomials

In algebra it is traditional to order terms in a polynomial, by ordering the monomials in the indeterminates. The word term is from the Latin terminus "boundary line limit" from the Indo-European root ter- "peg post boundary" In Mathematics, a polynomial is an expression constructed from Variables (also known as indeterminates and Constants using the operations In Mathematics, the word monomial means two different things in the context of Polynomials The first meaning is a product of powers of Variables Indeterminate has a variety of meanings in Mathematics: Indeterminate (variable Indeterminate equation Statically This is fundamental, in order to have a normal form. Normal form is a term that may refer to Normal form (databases Normal form (game theory Normal form (mathematics Such matters are typically left implicit in discussion between humans, but must of course be dealt with exactly in computer algebra. A computer algebra system ( CAS) is a software program that facilitates Symbolic mathematics. In practice one has an alphabet of indeterminates X, Y, . . . and orders all monomials formed from them by a variant of lexicographical order. For example if one decides to order the alphabet by

X < Y < . . .

and also to look at higher terms first, that means ordering

. . . < X3 < X2 < X

and also

X < Yk for all k.

There is some flexibility in ordering monomials, and this can be exploited in Gröbner basis theory. In Computer algebra, computational Algebraic geometry, and computational Commutative algebra, a Gröbner basis is a particular kind of generating subset

## Decimal fractions

For decimal fractions from the decimal point, a < b applies equivalently for the numerical order and the lexicographic order, provided that numbers with a recurring decimal 9 like . The decimal ( base ten or occasionally denary) Numeral system has ten as its base. 399999. . . are not included in the set of strings representing numbers. With that restriction there is an order-preserving bijection between the strings and the numbers.

## Lexicographic order with reversed significance

In a common variation of lexicographic order, one compares elements by reading from the right instead of from the left, i. e. , the right-most component is the most significant, e. g. applied in a rhyming dictionary. This article is about a type of reference work used in composing poetry

In the case of monomials one may sort the exponents downward, with the exponent of the first base variable as primary sort key, e. g. :

x2yz2 < xy3z2.

Alternatively, sorting may be done by the sum of the exponents, downward.