Ordinals as strings of ∅, commas and braces
This week, my colleagues at Igalia were talking about cutting text at a 72-characters limit for word-wrapping emails. One might say that the real question is whether 72 is a cut or a limit. Or wonder how one has decided to set that particular value?
The latter link explains the recursive definition of 72 as a finite set, which can be written with only braces, commas and the empty set :
and so forth until
You can notice that has only one element and for any , in order to enumerate the elements of using only the four characters "∅"
, ","
, "{"
and "}"
, you first write the elements of , followed by a comma, followed by an opening brace, followed by the elements of and finally followed by a closing brace. One can write a simple JavaScript loop that initializes a variable string = "∅"
and performs the concatenation string += `,{${string}}`
at each step:
Length of the string
You notice that the length of the string obtained for already exceeds the 72-character limit. From the previous recursive construction of the string one can deduce a recursive definition of its length:
It is easy to see that so although the simple JavaScript loop above uses a time complexity of string concatenations, the space complexity is at least exponential. That’s why in the definition of 72 above I used dots instead of showing the whole string!
One can however easily modify the previous JavaScript loop to calculate the length of such a string. At Igalia, we have been working on a new native type called BigInt which is particularly useful to accurately calculate large integers. The case demonstrates why it is more appropriate than JavaScript Number:
One can do better and try to calculate an explicit formula for for any . Since for all , the sequence is a geometric sequence with common ratio 2 and for all we can write
Summing this up for :
Finally, given that and , one can write for all :
This formula can be used to calculate using built-in JavaScript exponentation instead of a loop, as done below.
Order-type of infinite strings
It is possible to generalize this problem to infinite ordinal numbers. The string and its length are defined by induction for any ordinal . is the empty string . is the string with one character "∅"
and . For , is the string obtained by concatenating the string , a comma character ","
, an opening brace character "{"
, the string and finally a closing brace character "}"
. It is of length . Beware that ordinal operations are not commutative so this cannot be simplified a priori!
For any limit ordinal , the string is obtained by taking the union of the -sequence for . This is still a well-defined sequence since these strings always agree on the character at a given index. is of length .
By construction, is an increasing sequence of ordinals and so . Can we calculate it more explicitly?
Let’s consider some examples. In the case , the string can be more easily seen as the -concatenation of finite strings: the empty set, a comma, surrounded by braces, a comma, surrounded by braces, a comma, surrounded by braces, a comma, etc So clearly and this aligns with the definition for limit ordinal.
In order to write , you first write the elements of , followed by a comma, followed by an opening brace, followed by the elements of and finally followed by a closing brace. So really this is an sequence. This aligns with the definition in the successor ordinal case, using the fact that for any :
Continuing for other successor ordinals, one can write
and more generally for all :
To calculate , one takes the union for of the -sequence of characters describing . Its length is
Then the exact same calculation as above leads for all to
Continuing this kind of calculations for larger values suggests the following conjecture: For every infinite ordinal , the order-type of the sequence describing its element is:
where and are the quotient and remainder of the euclidean division of by .
Let’s sketch the proof by induction on . We already explained the case in the example above. Similarly, for a given , it is enough to prove the case , the formula for follows, using the property and the calculations we gave for the case .
If the formula holds for some then because is limit and the lengths are increasing, the formula holds for :
Finally, if the formula holds for all below a limit ordinal then because the lengths are increasing the formula holds for too:
Q.E.D.