Live data from Hacker News

Why numbering should start at zero (1982)

cs.utexas.edu

51–60 of 72 posts

Re: Why numbering should start at zero (1982)

#51
post #2

There's one important use case for Dijkstra's alternative (c), that is, an interval closed at both ends. That is when your set has a maximum element and you want to be able to express an interval including the maximum. This is, of course, important in any programming language whose basic integer types have a bounded range. For instance, the following loop in C never halts: for(uint8_t i = 0; i What's even worse, the…

I don't quite understand what you're saying. If you change the code to for(uint8_t i = 0; i then it still doesn't halt.

You're right, of course. Apparently my brain doesn't work well today.

Re: Why numbering should start at zero (1982)

#52
There are cases where zero-based indexing is more natural than one-based indexing. An example is naming the centuries: It would be nicer if this were called the twentiethan century instead of the twenty-first. When people talk about the fifteenth century, I have to think for a bit to understand what they mean. As such, I propose adding a suffix "an" to the end of any ordinal number to indicate a zero-based convention is being used -- this century would then be the twentiethan century [twεntiθən] as well as the twenty-first. A bit like degrees vs radians.

Re: Why numbering should start at zero (1982)

#53

The initial sentence has always bothered me > To denote the subsequence of natural numbers 2, 3, ..., 12 without the pernicious three dots What's so pernicious about them? I don't see it. It seems like a clear and intuitive way to communicate a sequence to me. I even wrote a little range generator in JS to explore parsing declarations like that. https://github.com/chrisbroski/iterize It seems to work fine.

[deleted]

Re: Why numbering should start at zero (1982)

#54
Programmers seem in general to know that 0-based works best, but mathematicians (and mathematical and statistical programming languages) seem to prefer 1-based, and I don't understand why that is? Isn't mathematics also easier with 0-based?

E.g. if you divide a matrix of 100 columns into 20 vertical bands of width 5 each.

Mathematicians use 1-based indexing for both the element index and the band index, so there band n would start at coordinate "(n - 1) * 100 / 20 + 1"

For a programmer, band n would start at "n * 100 / 20"

That's two correction terms that you need to add in math which programmers don't!

I had to use Matlab for microphone arrays once and it was full of + 1's and - 1's everywhere due to that.

Another example of mathematics and off by one errors: a polynomial. They call it "degree n" if the highest power is n, except I see n+1 coefficients in there and need to allocate an n+1 sized array to contain its coefficients, so why not call its degree the amount of terms, including the "x^0" one. The powers themselves in the polynomial are already hinting at 0-based indexing in this case.

Mathematicians, please use coordinate "0,0" for the top left element of a matrix :)

Re: Why numbering should start at zero (1982)

#55

Programmers seem in general to know that 0-based works best, but mathematicians (and mathematical and statistical programming languages) seem to prefer 1-based, and I don't understand why that is? Isn't mathematics also easier with 0-based? E.g. if you divide a matrix of 100 columns into 20 vertical bands of width 5 each. Mathematicians use 1-based indexing for both the element index and the band index, so there band…

[deleted]

Re: Why numbering should start at zero (1982)

#57
post #56

So random question because I know I would get this wrong in an interview, but would a 0 based indexing system have fewer assembly language instructions to calculate a memory offset than a 1 based system?

Naively, yes. In practice, you could treat them exactly the same and either decrement the physical pointer by 1 unit (so an index of 0 would underflow) or leave the first index unused or for metadata (eg. array length)

There might be some other tricks you can play depending on your instruction set, but nothing comes to mind.

Re: Why numbering should start at zero (1982)

#58

Programmers seem in general to know that 0-based works best, but mathematicians (and mathematical and statistical programming languages) seem to prefer 1-based, and I don't understand why that is? Isn't mathematics also easier with 0-based? E.g. if you divide a matrix of 100 columns into 20 vertical bands of width 5 each. Mathematicians use 1-based indexing for both the element index and the band index, so there band…

Interesting that you mention polynomials, as the constant term in them is gennerally given the subscript 0. In fact, it sounds like you want some form of 1 based indexing, where constant polynomials are degree 1, linear degree 2, etc.

Re: Why numbering should start at zero (1982)

#59

Programmers seem in general to know that 0-based works best, but mathematicians (and mathematical and statistical programming languages) seem to prefer 1-based, and I don't understand why that is? Isn't mathematics also easier with 0-based? E.g. if you divide a matrix of 100 columns into 20 vertical bands of width 5 each. Mathematicians use 1-based indexing for both the element index and the band index, so there band…

Interesting that you mention polynomials, as the constant term in them is gennerally given the subscript 0. In fact, it sounds like you want some form of 1 based indexing, where constant polynomials are degree 1, linear degree 2, etc.

No, I don't want form of 1 based indexing at all :)

an array with elements at index 0,1,2,3 has size 4

Re: Why numbering should start at zero (1982)

#60

Earlier quoted context omitted.

Interesting that you mention polynomials, as the constant term in them is gennerally given the subscript 0. In fact, it sounds like you want some form of 1 based indexing, where constant polynomials are degree 1, linear degree 2, etc.

No, I don't want form of 1 based indexing at all :) an array with elements at index 0,1,2,3 has size 4

And the degree on a polynomial means the highest index of a non-0 coefficient.

I don't see how you can view calling a linear polynomial degree 2 an example of 0 based index.

Post reply on HN