138. Lexical ordering

A finite totally ordered set $A$ used as an alphabet induces a total order on the strings in $A^{*}$ called the lexical order on $A^{*}$. When $A$ is the English alphabet, the result is the familiar alphabetical ordering of strings.

To define lexical ordering, we need a preliminary idea.

138.1 Definition: initial segment

A string $u$ is an initial segment of a string $w$ if $w=ux$ for some string $x$ in $A^{*}$.

138.1.1 Example ‘ab’ is an initial segment of ‘abbac’.

138.1.2 Example Any string is an initial segment of itself (since $\Lambda\in A^{*}$).

138.1.3 Example $\Lambda$ is an initial segment of any string.

138.2 Definition: lexical order

Let $(A,\alpha)$ be a finite totally ordered set. Then the lexical order or lexical ordering $\lambda$ on $A^{*}$ is defined as follows: $w\lambda x$ if either

LE.1 $w$ is an initial segment of $x$, or

LE.2 If $i$ is the first position where $w$ and $x$ differ, then $w_i\,\alpha\, x_i$.

138.2.1 Example If $A$ is the English alphabet with the usual ordering, ‘car’ comes before ‘card’ in alphabetical ordering because ‘car’ is an initial segment of ‘card’, and ‘car’ comes before ‘cat’ because the first place where ‘car’ and ‘cat’ differ is the third place, and ‘r’ comes before ‘t’.

138.2.2 Example If $A$ is nonempty, $A^{*}$ is an infinite set. Consider the lexical ordering on $\{0,1\}^{*}$, where $\{0,1\}$ is ordered so that 0 comes first. The first few elements of $\{0,1\}^{*}$ are $\Lambda$, ‘0’, ‘00’, ‘000’, ‘0000’, ‘00000’, … Thus if you go through the strings in order, there are strings such as ‘1’ that you can’t get to in a finite amount of time: there are an infinite number of strings in $\{0,1\}^{*}$ before ‘1’.

138.2.3 Exercise Prove that the lexical ordering on $\{0,1\}^{*}$ (with $0<1$) is a total ordering.

Page 211 of the book (PDF).