3 ms·
Programmers seem in general to know that 0-based works best, but mathematicians (and mathematical and statistical programming languages) seem to prefer 1-based,
by Aardwolf 8y ago
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 :)
- deleted 8y ago[deleted]
- gizmo686 8y agoInteresting 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.
- Aardwolf 8y agoNo, I don't want form of 1 based indexing at all :) an array with elements at index 0,1,2,3 has size 4