Python "why" questions

Russ P. russ.paielli at gmail.com
Fri Aug 20 14:01:42 EDT 2010


On Aug 20, 1:23 am, Martin Braun <martin.br... at kit.edu> wrote:

> I find this thread extremely interesting, but what surprised me that
> everyone seems to agree that mathematics is 1-based, but we Pythoneers
> should stick to zero-based. I disagree. To make sure I'm not going
> crazy, I took the top five books lying on my desk, which were the DSP
> book by Oppenheim/Schafer, two books by Stephen M. Kay (Spectral
> Estimation and Estimation Theory) and the Channel Coding book by Lin &
> Costello. This is isn't pure mathematics (as in proving the Goldbach
> conjecture), but nevertheless, this is serious mathematics and,
> surprise, they most exclusively use zero-based notation.
> You probably don't have those books in grabbing distance, so here's some
> examples for zero-based stuff:

That's interesting, but I think zero-based indexing is rare in the
literature of mathematics, applied math, science and engineering. All
the literature I've ever seen that uses vectors and matrices is one-
based, and that includes text books and technical papers.

It all boils down to personal preference, but I just find it strange
that we would not try to make programming as consistent as possible
with notational conventions in the literature. If I try to implement
some algorithm I find in a technical book or paper, why should I have
to mentally offset every index by one? That's very error prone, and I
have more important things to think about. Then again, I don't do that
very often, so maybe it's not a big deal.

The zero-based indexing just seemed wrong to me when I first saw it.
I'm used to it by now, but it still doesn't seem quite right to me.
It's almost right -- but it's off by one. I still have a habit of
taking the "1" element when I really want the "0" element.

Most programmers probably never use vectors and matrices, so they
don't care about the inconsistency with standard mathematical
notation.

And yes, I understand that zero-based indexing can be slightly more
efficient. That's why I think it's appropriate for low-level languages
such as C. However, I think one-based indexing is more appropriate for
high-level languages.



More information about the Python-list mailing list