Zero-based numbering
Zero-based numbering is a way of
Numbering sequences starting at 0 is quite common in mathematics notation, in particular in
Computer programming
Origin
In 1982 Edsger W. Dijkstra in his pertinent note Why numbering should start at zero[8] argued that arrays subscripts should start at zero as the latter being the most natural number. Discussing possible designs of array ranges by enclosing them in a chained inequality, combining sharp and standard inequalities to four possibilities, demonstrating that to his conviction zero-based arrays are best represented by non-overlapping index ranges, which start at zero, alluding to open, half-open and closed intervals as with the real numbers. Dijkstra's criteria for preferring this convention are in detail that it represents empty sequences in a more natural way (a ≤ i < a ?) than closed "intervals" (a ≤ i ≤ (a − 1) ?), and that with half-open "intervals" of naturals, the length of a sub-sequence equals the upper minus the lower bound (a ≤ i < b gives (b − a) possible values for i, with a, b, i all integers).
Usage in programming languages
This usage follows from design choices embedded in many influential
Referencing memory by an address and an offset is represented directly in
Pascal allows the range of an array to be of any ordinal type (including enumerated types). APL allows setting the index origin to 0 or 1 during runtime programmatically.[9][10] Some recent languages, such as Lua and Visual Basic, have adopted the same convention for the same reason.
Zero is the lowest unsigned integer value, one of the most fundamental types in programming and hardware design. In computer science,
In recent years this trait has also been observed among many pure mathematicians, where many constructions are defined to be numbered from 0.[citation needed]
If an array is used to represent a cycle, it is convenient to obtain the index with a
Numerical properties
With zero-based numbering, a range can be expressed as the half-open
Another property of this convention is in the use of
Pointer operations can also be expressed more elegantly on a zero-based index due to the underlying address/offset logic mentioned above. To illustrate, suppose a is the memory address of the first element of an array, and i is the index of the desired element. To compute the address of the desired element, if the index numbers count from 1, the desired address is computed by this expression:
where s is the size of each element. In contrast, if the index numbers count from 0, the expression becomes
This simpler expression is more efficient to compute at
However, a language wishing to index arrays from 1 could adopt the convention that every array address is represented by a′ = a – s; that is, rather than using the address of the first array element, such a language would use the address of a fictitious element located immediately before the first actual element. The indexing expression for a 1-based index would then be
Hence, the efficiency benefit at run time of zero-based indexing is not inherent, but is an artifact of the decision to represent an array with the address of its first element rather than the address of the fictitious zeroth element. However, the address of that fictitious element could very well be the address of some other item in memory not related to the array.
Superficially, the fictitious element doesn't scale well to multidimensional arrays. Indexing multidimensional arrays from zero makes a naive (contiguous) conversion to a linear address space (systematically varying one index after the other) look simpler than when indexing from one. For instance, when mapping the three-dimensional array A[P][N][M] to a linear array L[M⋅N⋅P], both with M ⋅ N ⋅ P elements, the index r in the linear array to access a specific element with L[r] = A[z][y][x] in zero-based indexing, i.e. [0 ≤ x < P], [0 ≤ y < N], [0 ≤ z < M], and [0 ≤ r < M ⋅ N ⋅ P], is calculated by
Organizing all arrays with 1-based indices ([1 ≤ x′ ≤ P], [1 ≤ y′ ≤ N], [1 ≤ z′ ≤ M], [1 ≤ r′ ≤ M ⋅ N ⋅ P]), and assuming an analogous arrangement of the elements, gives
to access the same element, which arguably looks more complicated. Of course, r′ = r + 1, since [z = z′ – 1], [y = y′ – 1], and [x = x′ – 1]. A simple and everyday-life example is positional notation, which the invention of the zero made possible. In positional notation, tens, hundreds, thousands and all other digits start with zero, only units start at one.[12]
-
Zero-based indices xy0 1 2 .. .. 8 9 0 00 01 02 08 09 1 10 11 12 18 19 2 20 21 22 28 29 .. .. 8 80 81 82 88 89 9 90 91 92 98 99 The table content represents the index r. -
One-based indices x'y'1 2 3 .. .. 9 10 1 01 02 03 09 10 2 11 12 13 19 20 3 21 22 23 29 30 .. .. 9 81 82 83 89 90 10 91 92 93 99 100 The table content represents the index r′.
This situation can lead to some confusion in terminology. In a zero-based indexing scheme, the first element is "element number zero"; likewise, the twelfth element is "element number eleven". Therefore, an analogy from the ordinal numbers to the quantity of objects numbered appears; the highest index of n objects will be n − 1, and it refers to the nth element. For this reason, the first element is sometimes referred to as the
Science
In
In both mechanics and statistics, the zeroth moment is defined, representing total mass in the case of physical density, or total probability, i.e. one, for a probability distribution.
The zeroth law of thermodynamics was formulated after the first, second, and third laws, but considered more fundamental, thus its name.
In biology, an organism is said to have zero-order intentionality if it shows "no intention of anything at all". This would include a situation where the organism's genetically predetermined phenotype results in a fitness benefit to itself, because it did not "intend" to express its genes.[13] In the similar sense, a computer may be considered from this perspective a zero-order intentional entity, as it does not "intend" to express the code of the programs it runs.[14]
In biological or medical experiments, initial measurements made before any experimental time has passed are said to be on the 0 day of the experiment.[citation needed]
In genomics, both 0-based and 1-based systems are used for genome coordinates.[citation needed]
Patient zero (or
Other fields
The year zero does not exist in the widely used Gregorian calendar or in its predecessor, the Julian calendar. Under those systems, the year 1 BC is followed by AD 1. However, there is a year zero in astronomical year numbering (where it coincides with the Julian year 1 BC) and in ISO 8601:2004 (where it coincides with the Gregorian year 1 BC), as well as in all Buddhist and Hindu calendars.
In many countries, the ground floor in buildings is considered as floor number 0 rather than as the "1st floor", the naming convention usually found in the United States of America. This makes a consistent set with underground floors marked with negative numbers.
While the ordinal of 0 mostly finds use in communities directly connected to mathematics, physics, and computer science, there are also instances in classical music. The composer
In some universities, including Oxford and Cambridge, "week 0" or occasionally "noughth week" refers to the week before the first week of lectures in a term. In Australia, some universities refer to this as "O week", which serves as a pun on "
The United States Air Force starts basic training each Wednesday, and the first week (of eight) is considered to begin with the following Sunday. The four days before that Sunday are often referred to as "zero week".
24-hour clocks and the international standard ISO 8601 use 0 to denote the first (zeroth) hour of the day, consistent with using the 0 to denote the first (zeroth) minute of the hour and the first (zeroth) second of the minute. Also, the 12-hour clocks used in Japan use 0 to denote the hour immediately after midnight and noon in contrast to 12 used elsewhere, in order to avoid confusion whether 12 a.m. and 12 p.m. represent noon or midnight.
Robert Crumb's drawings for the first issue of Zap Comix were stolen, so he drew a whole new issue, which was published as issue 1. Later he re-inked his photocopies of the stolen artwork and published it as issue 0.
The
Zero is sometimes used in street addresses, especially in schemes where even numbers are one side of the street and odd numbers on the other. A case in point is Christ Church on Harvard Square, whose address is 0 Garden Street.
Formerly in Formula One, when a defending world champion did not compete in the following season, the number 1 was not assigned to any driver, but one driver of the world champion team would carry the number 0, and the other, number 2. This did happen both in 1993 and 1994 with Damon Hill carrying the number 0 in both seasons, as defending champion Nigel Mansell quit after 1992, and defending champion Alain Prost quit after 1993. However, in 2014 the series moved to drivers carrying career-long personalised numbers, instead of team-allocated numbers, other than the defending champion still having the option to carry number 1. Therefore 0 is no longer used in this scenario. It is not clear if it is available as a driver's chosen number, or whether they must be between 2 and 99, but it has not been used to date under this system.
Some team sports allow 0 to be chosen as a player's
A chronological prequel of a series may be numbered as 0, such as Ring 0: Birthday or Zork Zero.
The Swiss Federal Railways number certain classes of rolling stock from zero, for example, Re 460 000 to 118.
In the realm of fiction, Isaac Asimov eventually added a Zeroth Law to his Three Laws of Robotics, essentially making them four laws.
A standard roulette wheel contains the number 0 as well as 1-36. It appears in green, so is classed as neither a “red” nor “black” number for betting purposes. The card game Uno has number cards running from 0 to 9 along with special cards, within each coloured suit.
The Four Essential Freedoms of Free Software are numbered starting from zero. This is for historical reasons: the list originally had only three freedoms, and when the fourth was added it was placed in the zeroth position as it was considered more basic.
See also
- Zeroth-order approximation
- Off-by-one error
References
Citations
- ISBN 1852334509. Retrieved 11 February 2020.
- ^ Steve Eddins and Loren Shure. "Matrix Indexing in MATLAB". Retrieved 23 February 2021.
- ^ "How to : Get Elements of Lists". Wolfram. Retrieved 23 February 2021.
- ^ "Indexing Arrays, Matrices, and Vectors". Maplesoft. Retrieved 23 February 2021.
- ^ Martin Richards (1967). The BCPL Reference Manual (PDF). Massachusetts Institute of Technology. p. 11.
- ^ a b c Mike Hoye. "Citation Needed". Retrieved 28 January 2014.
- ^ Tom Van Vleck (1995). "The IBM 7094 and CTSS". Retrieved 28 January 2014.
- ^ a b Dijkstra, Edsger Wybe (May 2, 2008). "Why numbering should start at zero (EWD 831)". E. W. Dijkstra Archive. University of Texas at Austin. Retrieved 2011-03-16.
- S2CID 40187000.
- ^ Hui, Roger. "Is Index Origin 0 a Hindrance?". jsoftware.com. JSoftware. Retrieved 19 January 2015.
- ^ Programming Microsoft® Visual C# 2005 by Donis Marshall.
- ^ Sal Khan. Math 1st Grade / Place Value / Number grid. Khan Academy. Retrieved July 28, 2018.
Youtube title: Number grid / Counting / Early Math / Khan Academy
. - ^ Byrne, Richard W. "The Thinking Ape: Evolutionary Origins of Intelligence". Retrieved 2010-05-18.
- ^ Dunbar, Robin. "The Human Story – A new history of mankind's Evolution". Retrieved 2010-05-18.
Sources
- This article incorporates material taken from zeroth at the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the GFDL, version 1.3 or later.