News for hackers. Stuff that matters.
Re:Numbering should start at zero: E.W. Dijkstra by Aardwolf on Friday March 21, 2025 @09:11AM (#43435246)
For math too, 0-based indexing is superior. When taking sub-matrices (blocks), with 1-based indexing you have to deal with + 1 and - 1 terms for the element indices. E.g. the third size-4 block of a 16x16 matrix begins at (3-1)*4+1 in 1-based indexing, at 2*4 in 0-based indexing (where the 2 is naturally the 0-indexed block index).

Also, the origin is at 0, not at 1. If you begin at 1, you've already moved some distance away from the origin at the start.

Re:Numbering should start at zero: E.W. Dijkstra by venusenvy47 on Friday March 21, 2025 @09:55AM (#43435752)
Just speaking anecdotally, I had the impression that math people prefer 1-based indexing. I've heard that Matlab is 1-based because it was written by math majors, rather than CS majors.
Re:Numbering should start at zero: E.W. Dijkstra by Aardwolf on Friday March 21, 2025 @10:25AM (#43436085)
Yes but I think it might be just habit, and it's exactly in matlab that dealing with for loops over sub matrices is so annoying due to this
Re:Numbering should start at zero: E.W. Dijkstra by BeetleB on Friday March 21, 2025 @01:05PM (#43438234)
Indeed. I was going to point out that mathematicians choose the index based on whatever is convenient for their problem. It could begin at -3, 2, or whatever. I've never heard a mathematician complain that another mathematician is using the "wrong" index. That's something only programmers seem to do.
Re:Numbering should start at zero: E.W. Dijkstra by shiandow on Friday March 21, 2025 @09:27AM (#43435414)
In mathematics, if it matters what index your matrix starts on then you're likely doing something wrong.

Besides, in the rare cases where it does matter you're free to pick whichever is convenient.