Zero-based
   HOME

TheInfoList



OR:

Zero-based numbering is a way of
numbering There are many different numbering schemes for assigning nominal numbers to entities. These generally require an agreed set of rules, or a central coordinator. The schemes can be considered to be examples of a primary key of a database management ...
in which the initial element of a
sequence In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order matters. Like a set, it contains members (also called ''elements'', or ''terms''). The number of elements (possibly infinite) is calle ...
is assigned the index 0, rather than the index 1 as is typical in everyday ''non-mathematical'' or ''non-programming'' circumstances. Under zero-based numbering, the initial element is sometimes termed the ''
zeroth 0th or zeroth may refer to: Mathematics, science and technology * 0th or zeroth, an ordinal for the number zero * 0th dimension, a topological space * 0th element, of a data structure in computer science * Zeroth (software), deep learning softw ...
'' element, rather than the ''first'' element; ''zeroth'' is a coined ordinal number corresponding to the number
zero 0 (zero) is a number representing an empty quantity. In place-value notation such as the Hindu–Arabic numeral system, 0 also serves as a placeholder numerical digit, which works by multiplying digits to the left of 0 by the radix, usual ...
. In some cases, an object or value that does not (originally) belong to a given sequence, but which could be naturally placed before its initial element, may be termed the zeroth element. There is not wide agreement regarding the correctness of using zero as an ordinal (nor regarding the use of the term ''zeroth''), as it creates ambiguity for all subsequent elements of the sequence when lacking context. Numbering sequences starting at 0 is quite common in mathematics notation, in particular in combinatorics, though programming languages for mathematics usually index from 1. In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includi ...
,
array An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
indices usually start at 0 in modern programming languages, so computer programmers might use ''zeroth'' in situations where others might use ''first'', and so forth. In some mathematical contexts, zero-based numbering can be used without confusion, when ordinal forms have well established meaning with an obvious candidate to come before ''first''; for instance, a ''zeroth derivative'' of a function is the function itself, obtained by differentiating zero times. Such usage corresponds to naming an element not properly belonging to the sequence but preceding it: the zeroth derivative is not really a derivative at all. However, just as the ''first derivative'' precedes the ''second derivative'', so also does the ''zeroth derivative'' (or the original function itself) precede the ''first derivative''.


Computer programming


Origin

Martin Richards Martin Richards may refer to: * Martin Richards (computer scientist) (born 1940), British computer scientist * Martin Richards (police officer) Martin Richards QPM (born 1959) is a British retired police officer, whose last post was as the Ch ...
, creator of the BCPL language (a precursor of C), designed arrays initiating at 0 as the natural position to start accessing the array contents in the language, since the value of a pointer ''p'' used as an address accesses the position in memory. BCPL was first compiled for the IBM 7094; the language introduced no run-time indirection lookups, so the indirection optimization provided by these arrays was done at compile time. The optimization was nevertheless important. Edsger W. Dijkstra later wrote a pertinent note ''Why numbering should start at zero'' in 1982, analyzing the possible designs of array indices 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 than closed "intervals" (), and that with half-open "intervals" of naturals, the length of a sub-sequence equals the upper minus the lower bound ( gives possible values for ''i'', with ''a'', ''b'', ''i'' all integers).


Usage in programming languages

This usage follows from design choices embedded in many influential
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
s, including C,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
, and Lisp. In these three, sequence types (C arrays, Java arrays and lists, and Lisp lists and vectors) are indexed beginning with the zero subscript. Particularly in C, where arrays are closely tied to pointer arithmetic, this makes for a simpler implementation: the subscript refers to an offset from the starting position of an array, so the first element has an offset of zero. Referencing memory by an address and an offset is represented directly in computer hardware on virtually all computer architectures, so this design detail in C makes compilation easier, at the cost of some human factors. In this context using "zeroth" as an ordinal is not strictly correct, but a widespread habit in this profession. Other programming languages, such as Fortran or COBOL, have array subscripts starting with one, because they were meant as
high-level programming language In computer science, a high-level programming language is a programming language with strong abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be easier to us ...
s, and as such they had to have a correspondence to the usual
ordinal numbers In set theory, an ordinal number, or ordinal, is a generalization of ordinal numerals (first, second, th, etc.) aimed to extend enumeration to infinite sets. A finite set can be enumerated by successively labeling each element with the least ...
which predate the invention of the zero by a long time. 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 programatically. Some recent languages, such as
Lua Lua or LUA may refer to: Science and technology * Lua (programming language) * Latvia University of Agriculture * Last universal ancestor, in evolution Ethnicity and language * Lua people, of Laos * Lawa people, of Thailand sometimes referred t ...
and
Visual Basic Visual Basic is a name for a family of programming languages from Microsoft. It may refer to: * Visual Basic .NET (now simply referred to as "Visual Basic"), the current version of Visual Basic launched in 2002 which runs on .NET * 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,
zero 0 (zero) is a number representing an empty quantity. In place-value notation such as the Hindu–Arabic numeral system, 0 also serves as a placeholder numerical digit, which works by multiplying digits to the left of 0 by the radix, usual ...
is thus often used as the base case for many kinds of numerical
recursion Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathemati ...
. Proofs and other sorts of mathematical reasoning in computer science often begin with zero. For these reasons, in computer science it is not unusual to number from zero rather than one. In recent years this trait has also been observed among many pure mathematicians, where many constructions are defined to be numbered from 0. If an array is used to represent a cycle, it is convenient to obtain the index with a modulo function, which can result in zero.


Numerical properties

With zero-based numbering, a range can be expressed as the half-open interval, , as opposed to the closed interval, . Empty ranges, which often occur in algorithms, are tricky to express with a closed interval without resorting to obtuse conventions like . Because of this property, zero-based indexing potentially reduces off-by-one and fencepost errors. On the other hand, the repeat count ''n'' is calculated in advance, making the use of counting from 0 to (inclusive) less intuitive. Some authors prefer one-based indexing, as it corresponds more closely to how entities are indexed in other contexts. Another property of this convention is in the use of
modular arithmetic In mathematics, modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" when reaching a certain value, called the modulus. The modern approach to modular arithmetic was developed by Carl Friedrich Gauss in his boo ...
as implemented in modern computers. Usually, the modulo function maps any integer modulo ''N'' to one of the numbers , where . Because of this, many formulas in algorithms (such as that for calculating hash table indices) can be elegantly expressed in code using the modulo operation when array indices start at zero. 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 In computing, a memory address is a reference to a specific memory location used at various levels by software and hardware. Memory addresses are fixed-length sequences of digits conventionally displayed and manipulated as unsigned integers. ...
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: : ''a'' + ''s'' × (''i'' − 1), where ''s'' is the size of each element. In contrast, if the index numbers count from 0, the expression becomes : ''a'' + ''s'' × ''i''. This simpler expression is more efficient to compute at
run time Run(s) or RUN may refer to: Places * Run (island), one of the Banda Islands in Indonesia * Run (stream), a stream in the Dutch province of North Brabant People * Run (rapper), Joseph Simmons, now known as "Reverend Run", from the hip-hop group ...
. However, a language wishing to index arrays from 1 could adopt the convention that every array address is represented by ; 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 : ''a''′ + ''s'' × ''i''. 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 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 in zero-based indexing, i.e. ≤ ''x'' < ''P'' ≤ ''y'' < ''N'' ≤ ''z'' < ''M'' and ≤ ''r'' < ''M⋅N⋅P'' is calculated by . Organizing all arrays with 1-based indices ( ≤ ''x′'' ≤ ''P'' ≤ ''y′'' ≤ ''N'' ≤ ''z′'' ≤ ''M'' ≤ ''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, since and 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..
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 , and it refers to the ''n''th element. For this reason, the first element is sometimes referred to as the
zeroth 0th or zeroth may refer to: Mathematics, science and technology * 0th or zeroth, an ordinal for the number zero * 0th dimension, a topological space * 0th element, of a data structure in computer science * Zeroth (software), deep learning softw ...
element, in an attempt to avoid confusion.


Science

In mathematics, many sequences of numbers or of polynomials are indexed by nonnegative integers, for example, the
Bernoulli numbers In mathematics, the Bernoulli numbers are a sequence of rational numbers which occur frequently in analysis. The Bernoulli numbers appear in (and can be defined by) the Taylor series expansions of the tangent and hyperbolic tangent functions, ...
and the
Bell numbers In combinatorial mathematics, the Bell numbers count the possible partitions of a set. These numbers have been studied by mathematicians since the 19th century, and their roots go back to medieval Japan. In an example of Stigler's law of eponymy ...
. In both
mechanics Mechanics (from Ancient Greek: μηχανική, ''mēkhanikḗ'', "of machines") is the area of mathematics and physics concerned with the relationships between force, matter, and motion among physical objects. Forces applied to object ...
and statistics, the zeroth moment is defined, representing total mass in the case of physical
density Density (volumetric mass density or specific mass) is the substance's mass per unit of volume. The symbol most often used for density is ''ρ'' (the lower case Greek letter rho), although the Latin letter ''D'' can also be used. Mathematical ...
, or total probability, i.e. one, for a probability distribution. The ''
zeroth law of thermodynamics The zeroth law of thermodynamics is one of the four principal laws of thermodynamics. It provides an independent definition of temperature without reference to entropy, which is defined in the second law. The law was established by Ralph H. Fowl ...
'' 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. 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. 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. In genomics, both 0-based and 1-based systems are used for genome coordinates. Patient zero (or
index case The index case or patient zero is the first documented patient in a disease epidemic within a population, or the first documented patient included in an epidemiological study. It can also refer to the first case of a condition or syndrome (not n ...
) is the initial
patient A patient is any recipient of health care services that are performed by healthcare professionals. The patient is most often ill or injured and in need of treatment by a physician, nurse, optometrist, dentist, veterinarian, or other hea ...
in the population sample of an
epidemiological Epidemiology is the study and analysis of the distribution (who, when, and where), patterns and determinants of health and disease conditions in a defined population. It is a cornerstone of public health, and shapes policy decisions and evidenc ...
investigation.


Other fields

The
year zero A year zero does not exist in the Anno Domini (AD) calendar year system commonly used to number years in the Gregorian calendar (nor in its predecessor, the Julian calendar); in this system, the year is followed directly by year . However, the ...
does not exist in the widely used
Gregorian calendar The Gregorian calendar is the calendar used in most parts of the world. It was introduced in October 1582 by Pope Gregory XIII as a modification of, and replacement for, the Julian calendar. The principal change was to space leap years dif ...
or in its predecessor, the
Julian calendar The Julian calendar, proposed by Roman consul Julius Caesar in 46 BC, was a reform of the Roman calendar. It took effect on , by edict. It was designed with the aid of Greek mathematicians and astronomers such as Sosigenes of Alexandr ...
. Under those systems, the year 1 BC is followed by AD 1. However, there is a year zero in
astronomical year numbering Astronomical year numbering is based on AD/ CE year numbering, but follows normal decimal integer numbering more strictly. Thus, it has a year 0; the years before that are designated with negative numbers and the years after that are designated ...
(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 Buddhism ( , ), also known as Buddha Dharma and Dharmavinaya (), is an Indian religion or philosophical tradition based on teachings attributed to the Buddha. It originated in northern India as a -movement in the 5th century BCE, and ...
and
Hindu calendar The Hindu calendar, Panchanga () or Panjika is one of various lunisolar calendars that are traditionally used in the Indian subcontinent and Southeast Asia, with further regional variations for social and Hindu religious purposes. They adopt a ...
s. In many countries, the
ground floor A storey (British English) or story (American English) is any level part of a building with a floor that could be used by people (for living, work, storage, recreation, etc.). Plurals for the word are ''storeys'' (UK) and ''stories'' (US). T ...
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 Anton Bruckner regarded his early ''Symphony in D minor'' to be unworthy of including in the canon of his works, and he wrote ("doesn't count") on the score and a circle with a crossbar, intending it to mean "invalid". But posthumously, this work came to be known as ''Symphony No. 0 in D minor'', even though it was actually written after ''Symphony No. 1 in C minor''. There is an even earlier ''Symphony in F minor'' of Bruckner's, which is sometimes called ''No. 00''. The Russian composer
Alfred Schnittke Alfred Garrievich Schnittke (russian: Альфре́д Га́рриевич Шни́тке, link=no, Alfred Garriyevich Shnitke; 24 November 1934 – 3 August 1998) was a Russian composer of Jewish-German descent. Among the most performed and re ...
also wrote a Symphony No. 0. 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 "
orientation week Student orientation or new student orientation (often encapsulated into an orientation week, o-week, frosh week, welcome week or freshers' week) is a period before the start of an academic year at a university or tertiary institutions. A variety ...
". As a parallel, the introductory weeks at university educations in Sweden are generally called (zeroing). The
United States Air Force The United States Air Force (USAF) is the Aerial warfare, air military branch, service branch of the United States Armed Forces, and is one of the eight uniformed services of the United States. Originally created on 1 August 1907, as a part ...
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 clock The 12-hour clock is a time convention in which the 24 hours of the day are divided into two periods: a.m. (from Latin , translating to "before midday") and p.m. (from Latin , translating to "after midday"). For different opinions on represen ...
s 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. King's Cross station in London, Edinburgh Haymarket, and stations in
Uppsala Uppsala (, or all ending in , ; archaically spelled ''Upsala'') is the county seat of Uppsala County and the fourth-largest city in Sweden, after Stockholm, Gothenburg, and Malmö. It had 177,074 inhabitants in 2019. Located north of the c ...
,
Yonago is a city in western Tottori Prefecture, Japan, facing the Sea of Japan and making up part of the boundary of Lake Nakaumi. It is adjacent to Shimane Prefecture and across the lake from its capital of Matsue. It is the prefecture's second larges ...
, Stockport and
Cardiff Cardiff (; cy, Caerdydd ) is the capital and largest city of Wales. It forms a principal area, officially known as the City and County of Cardiff ( cy, Dinas a Sir Caerdydd, links=no), and the city is the eleventh-largest in the United Kingd ...
have a Platform 0.
Robert Crumb Robert Dennis Crumb (; born August 30, 1943) is an American cartoonist and musician who often signs his work R. Crumb. His work displays a nostalgia for American folk culture of the late 19th and early 20th centuries, and satire of contem ...
's drawings for the first issue of ''
Zap Comix ''Zap Comix'' is an underground comix series which was originally part of the youth counterculture of the late 1960s. While a few small-circulation self-published satirical comic books had been printed prior to this, ''Zap'' became the model for ...
'' 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
Brussels ring The Brussels Ring ( Dutch: ''Grote ring rond Brussel'', French: ''Ring de Bruxelles'') numbered R0, is a ring road surrounding the city of Brussels as well as other smaller towns south of Brussels. It is about long, with 2 or 3 lanes in each direc ...
road in Belgium is numbered R0. It was built after the ring road around Antwerp, but Brussels (being the capital city) was deemed deserving of a more basic number. Similarly the (unfinished) orbital motorway around
Budapest Budapest (, ; ) is the capital and most populous city of Hungary. It is the ninth-largest city in the European Union by population within city limits and the second-largest city on the Danube river; the city has an estimated population ...
in Hungary is called M0. 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. In
Formula One Formula One (also known as Formula 1 or F1) is the highest class of international racing for open-wheel single-seater formula racing cars sanctioned by the Fédération Internationale de l'Automobile (FIA). The World Drivers' Championship, ...
, when a defending world champion does not compete in the following season, the number 1 is not assigned to any driver, but one driver of the world champion team will carry the number 0, and the other, number 2. This did happen both in 1993 and 1994 with
Damon Hill Damon Graham Devereux Hill, (born 17 September 1960) is a British former professional racing driver from England and the 1996 Formula One World Champion. He is the son of Graham Hill, and, along with Nico Rosberg, one of two sons of a Formula ...
carrying the number 0 in both seasons, as defending champion Nigel Mansell quit after 1992, and defending champion
Alain Prost Alain Marie Pascal Prost (; born 24 February 1955) is a French retired racing driver and Formula One team owner. A four-time Formula One World Drivers' Champion, from 1987 until 2001 he held the record for most Grand Prix victories until Micha ...
quit after 1993. A chronological prequel of a series may be numbered as 0, such as '' Ring 0: Birthday'' or ''
Zork Zero ''Zork Zero: The Revenge of Megaboz'' is an interactive fiction computer game, written by Steve Meretzky over nearly 18 months and published by Infocom in 1988. Although it is the ninth and last ''Zork'' game released by Infocom before the company ...
''. 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 The Three Laws of Robotics (often shortened to The Three Laws or known as Asimov's Laws) are a set of rules devised by science fiction author Isaac Asimov. The rules were introduced in his 1942 short story " Runaround" (included in the 1950 colle ...
, essentially making them four laws.


See also

*
Zeroth-order approximation In science, engineering, and other quantitative disciplines, order of approximation refers to formal or informal expressions for how accurate an approximation is. Usage in science and engineering In formal expressions, the ordinal number used ...
*
Off-by-one error An off-by-one error or off-by-one bug (known by acronyms OBOE, OBO, OB1 and OBOB) is a logic error involving the discrete equivalent of a boundary condition. It often occurs in computer programming when an iterative loop iterates one time too m ...


References


Citations


Sources

* This article incorporates material taken fro
zeroth
at the
Free On-line Dictionary of Computing The Free On-line Dictionary of Computing (FOLDOC) is an online, searchable, encyclopedic dictionary of computing subjects. History FOLDOC was founded in 1985 by Denis Howe and was hosted by Imperial College London. In May 2015, the site was up ...
prior to 1 November 2008 and incorporated under the "relicensing" terms of the
GFDL The GNU Free Documentation License (GNU FDL or simply GFDL) is a copyleft license for free documentation, designed by the Free Software Foundation (FSF) for the GNU Project. It is similar to the GNU General Public License, giving readers the ...
, version 1.3 or later. {{refend Ordinal numbers 0 (number)