Mailing List Archive: 49091 messages

## [REBOL] Re: Natural numbers

### From: larry:ecotope at: 4-Jul-2001 13:34

```
Hi Joel,

> Recognizing 0 as the origin of the natural numbers is both
> explicit in Peano's Axioms, and too fundamentally useful to
> give up.  We learned long ago (from negative experience with
> FORTRAN, actually ;-) that requiring a minimum loop count of
> one instead of zero is often entirely too awkward.

Just a few quick comments about indexing of arrays (or REBOL blocks).

1) Some of the recent posts seem to imply there is some intrinsic
mathematical reason which justifies zero-based indexing. These posts seem to
ignore the fact that in the areas of mathematics where arrays, vectors,
matrices, tensors, etc. are widely used, it is almost universal to use
one-based offsets (check any book on linear algebra).  So that, e.g., a[1]
is notation for the first element of a vector, a[1,1] is the first element
in the first row of a matrix, etc. So for the purpose of indexing arrays,
mathematicians have always used one-based indexing.

2) In my own view, the whole issue of index base is fairly minor, you can do
it either way. However as a person who has implemented many array-based
mathematics packages in C, I have found the zero-based indexing of C to be
more often a hindrance than a help. There are, however, good reasons for
zero-base offsets when doing system programming that involves things like
pointer arithmetic. After all, C was designed for low-level systems
programming, not for doing mathematics. FORTRAN, on the other hand, was
designed to do scientific numerical computing on arrays and vectors, so the
choice of one-based array indexing was the natural one.

3) There is a thoughtful discussion of the subject in "Numerical Recipes in
C" by Press, et al. Second Edition 1992. It is in Chapter 1 Section 2 under
the heading Vectors and One-Dimensional Arrays p. 18. I would recommend a
careful reading this topic. In all of their C code for matrix/vector
operations they use one-based indexing (having shown a clever way to achieve
this in C). Here are a few quotes from their discussion (forgive my typos):

It is sometimes convenient to use zero-offset vectors, and sometimes
convenient to use unit-offset vectors. ... a vector of data points calls for
a unit-offset.

But suppose that your vector of length 7, now call it a, is perversely a
native C, zero-offset array (has range a[0..6]). Perhaps, this is the case
because you disagree with our aesthetic prejudices, Heaven help you!

We want to free you from the zero-offset thinking that C encourages but (as
we see) does not require.

Cheers
-Larry
```