Ordinals and Cardinals

Ordinals and Cardinals

In the early days of compiler writing, it was found that array references compiled into a little less code if array elements were numbered starting at 0.  Now that memory size is measured in gigabytes rather than kilobytes, this saving of code is insignificant.  However, the practice of numbering arrays from 0 became the norm.  Some computer scientists numbered everything starting at 0.

When I started designing TLA+, I too numbered a tuple's elements from 0.  However, I discovered that my specifications became a little simpler when I numbered them from 1.  I had rediscovered what people have known for thousands of years: the difference between cardinal and ordinal numbers.  The cardinal numbers are zero (originally called none), one, two, etc.  They answer the question How many?  The ordinal numbers are first, second, third, etc.  They answer the question Which one? 

Cardinal and ordinal numbers are written with the same arabic numerals.  We can tell them apart by their function.  A page number in a book answers the question Which page?  It is obviously an ordinal number because we talk about the third page, to which we naturally give the number 3.  Similarly, we talk about the third item in a tuple, so it's natural to give it the number 3.

One reason computer scientists think we should number lists with cardinal numbers is that they confuse cardinal numbers with a third kind of number that is used to name items arranged in a cycle.  Three such sets of items are the seconds, minutes, and hours on a clock.  It's most convenient to number N cyclically ordered items with the numbers 0 through N - 1.  If we go i items past item number m, we reach the item with the number mathematicians write as (i + m) mod N and is written in programming languages and TLA+ as (i + m) % N.  (Because it numbers hours from 0, calculating time differences on a 24-hour clock is easier than on a 12-hour clock.)  When used this way, the numbers 0 through N - 1 are usually called the set of numbers modulo N.  Mathematicians call this set ZN.