[REBOL] Re: Natural numbers
From: joel:neely:fedex at: 4-Jul-2001 13:42
I guess the short version is this: if we're allowed to use
zero, we don't have to; if we're forbidden to use zero, then
we can't. The first sounds more permissive an option to me.
Larry Palmiter wrote:
> 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
> 1) Some of the recent posts seem to imply there is some
> intrinsic mathematical reason which justifies zero-based
There are intrinsic mathematical and performance reasons
which justify zero-based indexing for many non-numerical
(e.g. combinatorial and statistical) applications.
> These posts seem to ignore the fact that in the
> areas of mathematics where arrays, vectors, matrices,
> tensors, etc. are widely used...
I don't ignore those; it's simply that if one has zero-based
indexing, one always has the option of ignoring position
0 and treating the remainder as 1-origin if the logic of the
algorithm inherently calls for a 1-based view.
In contrast, if one only has 1-origin indexing, there is no
way to achieve a similar conversion to 0-based design. One
is forced to do surplus index manipulation.
> 2) In my own view, the whole issue of index base is fairly
> minor, you can do it either way.
Provided one's language ALLOWS one to do it either way...
> ... There are, however, good reasons for zero-base offsets
> when doing system programming that involves things like
> pointer arithmetic.
As stated above, and illustrated (at least I intended so)
by many examples I've used previously in this thread, there
are also good reasons for 0-based indexing when doing other
kinds of algorithms as well. This is not merely a "systems"
programming vs. "applications" programming issue.
> "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."
They are entitled to their own views. However, as someone
who has implemented lots of different classes of applications
(including language translation/interpretation, payroll, data
conversion, mailing list management, inventory management,
barcode decoding and printing, sales and commissions accounting,
artificial intelligence, neural networks, numerical analysis,
systems utilities, device drivers, text processing for pre-press
formatting, web application development, statistical processing
and reporting, education management, grades processing and
reporting, student records, manufacturing accounting and
production planning, and document management) in lots of different
languages (including Algol, FORTRAN, COBOL, RPG,
several dialects of Basic, various assemblers, NewtonScript,
LISP, TLWMNBN, Perl, SNOBOL, xBase, Java, a few incarnations
of FORTH, and last -- but certainly not least -- REBOL), I can
only say that I've experienced far fewer difficulties caused by
0-based indexing than by 1-based indexing.
> "We want to free you from the zero-offset thinking that C
> encourages but (as we see) does not require."
I wish I could free us from the 1-origin thinking that REBOL
both encourages and requires.
(However, I see another windmill that needs tilting... ;-)
Programming languages: compact, powerful, simple ...
Pick any two!