Talk:Zero-based numbering
This is the talk page for discussing improvements to the Zero-based numbering article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google (books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
Archives: 1Auto-archiving period: 365 days |
This article is rated C-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||||||||||||||||||
|
There is no such thing as "zero based indexing"
[edit]The article itself spells out the cause of the argument and the solution. "Referencing memory by an address and an offset... In this context using "zeroth" as an ordinal is not correct".
In computer languages we don't specify an index, we specify the 'offset' from the first index. These are very different things. An offset of zero does not make the first element the zeroth element. There is no such thing and there will never be a zeroth element. This is a perpetual mix-up of terminology.
The misleading math derivative example at the start finally makes since. A zero modifier on the first function returns the first function itself.
So languages are either "index based indexing" eg MatLab, Fortran or "offset based indexing". It is simply incorrect to say "zero based indexing".
It is like saying the "dark side of the moon". Most people know that we mean far side from earth but it is still and incorrect and misleading phrase that people should stop using.
BCPL anecdote
[edit]I find the BCPL anecdote misleading, not only have I have multiple multiple different versions of it, but it misquotes both Hoye and Stevens. The bit about the 7094 was not something Stevens said, it was Mike's speculation based on a separate document, and the indirection operation in BCPL was always at run-time because it was completely beyond the state of the art in compiler technology in the early '60s to track which words used in indirection were safe to optimize in the way he suggests.
BCPL arrays were zero-origin because it fell naturally out of the unification of pointers and other values in a low level language. Stevens says as much in the comment Mike quotes:
As for BCPL and C subscripts starting at zero. BCPL was essentially designed as typeless language close to machine code. Just as in machine code registers are typically all the same size and contain values that represent almost anything, such as integers, machine addresses, truth values, characters, etc. BCPL has typeless variables just like machine registers capable of representing anything. If a BCPL variable represents a pointer, it points to one or more consecutive words of memory. These words are the same size as BCPL variables. Just as machine code allows address arithmetic so does BCPL, so if p is a pointer p+1 is a pointer to the next word after the one p points to. Naturally p+0 has the same value as p. The monodic indirection operator ! takes a pointer as it’s argument and returns the contents of the word pointed to. If v is a pointer !(v+I) will access the word pointed to by v+I. As I varies from zero upwards we access consecutive locations starting at the one pointed to by v when I is zero. The dyadic version of ! is defined so that v!i = !(v+I). v!i behaves like a subscripted expression with v being a one dimensional array and I being an integer subscript. It is entirely natural for the first element of the array to have subscript zero. C copied BCPL’s approach using * for monodic ! and [ ] for array subscription. Note that, in BCPL v!5 = !(v+5) = !(5+v) = 5!v. The same happens in C, v[5] = 5[v]. I can see no sensible reason why the first element of a BCPL array should have subscript one. Note that 5!v is rather like a field selector accessing a field in a structure pointed to by v.
— Richard Stephens
But the speculation about performance considerations on the 7094, and especially the idea that it was precalculating indirection at compile time, are not supported by the original documentation. When you allocate a vector in BCPL, like "LET V = VEC 5", you actually allocated 6 words, the first of which contained the address of the second. Most if not all of the time you *created* it on the stack, at runtime. You could freely initialize words with addresses calculated at runtime, such as this example taken from the BCPL manual:
LET IOV = VEC 650
LET IOVP, IOVT = IOV, IOV + 650
The bias is this article
[edit]The article gives very lopsided, and arbitrary, arguments in favor of 0-based indexing without any semblance of fair discussions for the pros- and cons- of both approaches.
Wolfram
has a great counter example : https://reference.wolfram.com/language/howto/GetElementsOfLists.html
In[1] := v = Range[10]^2
Out[1] := {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}
And since
WolframAlpha
is 1-based indexing, the squares could be accessed in a very intuitive manner :
v[[3]] -> 9
3 x 3 := 9
However, using zero-based indexing instead, one needs to use list index
[2]
to get the square of 3
-
v[[2]] -> 9 ?????
which definitely causes more confusion, and require more clarification.
Or say a non-rectangular 2-dimensional list/map for days of the year :
calendar[ months : 1..12 ][ days : 1..(28-31) ]
With 1-based indexing, July 19th is practically self-explanatory :
calendar[7][19]
With 0-based indeexing, one has to use THIS :
calendar[6][18]
to obtain July 19th. 2603:7000:3C3D:4840:0:0:0:3C3 (talk) 17:55, 22 May 2024 (UTC)
he terms index and ordinal are different
[edit]In Mathematics the term ordinal refers to order type, including the order type of (the null set.)
Indexing is essentially a One-to-one mapping of a well ordered set into the set being indexed. Conventionally the indices are taken from (least transfinite ordinal) or a subsequence of it. Note that , whether defined as starting at 0 or at 1, is a subsequence of .
Adding to the confusion is the indexing of components of a, e.g., book, paper, are almost always 1-based, even in texts starting at 0. The exceptions seem to be in Computer Science rather than in Mathematics. -- Shmuel (Seymour J.) Metz Username:Chatul (talk) 13:06, 5 June 2024 (UTC)
- C-Class mathematics articles
- Low-priority mathematics articles
- C-Class Computing articles
- Mid-importance Computing articles
- C-Class software articles
- Mid-importance software articles
- C-Class software articles of Mid-importance
- All Software articles
- C-Class Computer science articles
- Mid-importance Computer science articles
- All Computing articles