139. Canonical ordering

The canonical ordering, defined below, is often used on infinite sets of strings to remedy the problem described in Example 138.2.2. It is the most commonly used ordering on $\{0,1\}^{*}$.

139.1 Definition: canonical ordering

The canonical ordering on $\{0,1\}^{*}$, usually denoted “$\leq$”, is defined this way: $w\leq x$ if

a) $w$ is shorter than $x$ ($|w|<|x|$) or

b) $|w|=|x|$ and the integer represented by $w$ in binary notation is less than or equal to the integer represented by $x$ in binary notation.

139.1.1 Example 1110 comes before 00001 because it is shorter, and 0011 comes before 0101 because 0011 is 3 in binary and 0101 is 5.

139.1.2 Example In the canonical ordering of $\{0,1\}^{*}$, the first few strings are $\Lambda$, $0, 00, 01, 10, 11, 000, 001, 010, 011, 100$, …

139.1.3 Fact The canonical ordering is linear and, unlike the lexical ordering, there are only a finite number of strings between any two strings.

139.1.4 Remark This idea can obviously be extended to strings in the alphabet $\{0,1,\ldots,n\}$ where $n$ is a small integer (use base $n+1$).

139.1.5 Exercise List the elements of the set

$$A=\{00,01,110,111,0101,0111,10101,10111,01111\}$$

in the lexical ordering and in the canonical ordering. (Answer on page 251.)

139.1.6 Exercise Prove that the canonical ordering on $\{0,1\}^{*}$ is a total ordering, and that there are only a finite number of strings between any two given strings.

Page 212 of the book (PDF).