This preview shows pages 1–3. Sign up to view the full content.
How to Design Programs: An Introduction to Computing and Programming [Go to first, previous, next page; contents; index]Section 11Natural NumbersThe only self-referential data definitions we have seen thus far involved consand lists of arbitrary length. We needed such data definitions because the classes of lists that we wanted to process were of arbitrary size. Natural numbers are another class of data whose elements are of arbitrary size; after all, there is no limit on how large a natural number can be, and, at least in principle, a function should be able to process them all.In this section, we study how to describe natural numbers with self-referential data definitions and how to develop functions that process natural numbers in a systematic fashion. Since such functions come in many flavors, we study several different flavors of definitions.11.1 Defining Natural NumbersPeople normally introduce natural numbers via enumeration: 0, 1, 2, etc.34The abbreviation ``etc.'' at the end says that the series continues in this manner. Mathematicians and mathematics teachers often use dots for the same purpose. For us, however, neither the ``etc.'' nor the dots is good enough, if we wish to design functions on natural numbers systematically. So, the question is what it means to write down ``etc.,'' or put differently, what a complete, self-contained description of the natural numbers is.The only way to remove the informal ``etc.'' from the enumeration is to describe the collection of numbers with a self-referential description. Here is a first attempt: 0 is a natural number. If nis a natural number, then one more than nis one, too. While this description is still not quite rigorous,35it is a good starting point for a Scheme-style data description:A natural-numberis either 1. 0or (1 of 16) [2/5/2008 4:46:07 PM]
This preview
has intentionally blurred sections.
Sign up to view the full version.