Why is the count starting from zero

Source: Internet
Author: User

Website: http://blog.jobbole.com/95826/

Why should I count starting from 0?

To avoid using hateful ellipses to denote natural number subsequence 2, 3, ..., 12, there are usually four ways of expression:

A) 2≤i < 13

b) 1 < i≤12

c) 2≤i≤12

d) 1 < i < 13

Is there any reason to prove that one is better than the others? The answer is yes. Depending on the observed expression, A and B) are more advantageous, because the margin of their boundary is exactly the same as the length of the subsequence. So the observation results show that the two adjacent sub-sequences with the above two expressions are equal to the upper boundary of one and the other. This observation is reasonable, but it does not help us to choose a) or B). So we're going to start the analysis again.

There is a minimum natural number. If you do not include the next boundary-for example, B) and D-a sub-sequence starting with the minimum natural number, the lower boundary will have to enter the non-natural number range. That would be ugly, so from the bottom of the border, we would prefer A and c). Now consider the subsequence that starts with the minimum natural number: When the sequence shrinks to a null value, the inclusion of the upper boundary becomes unnatural. This is also ugly, from the perspective of the upper boundary, such as A and d) used in the < will be more appropriate. So we can come to the conclusion that a is a relatively better way.

Note: The language Mesa developed by Xerox Parker Research Center (Xerox PARC) has special identifiers for the four commonly used integer representations. Many of the experience from Mesa shows that the other three representations are the source of program anomalies, so Mesa programmers now strongly recommend that you do not use the following three available expressions. I refer to this empirical evidence because if there is no proof of practice, some people will not be convinced of the above conclusions. (end of remark)

* *

*

When dealing with a sequence of length N, we want to be able to use subscripts to differentiate each element, and the other is how the subscript of the starting element is assigned. Support Mode A) the people think that starting with subscript 1, the scope of the underlying is 1≤i < n+1, but if starting from 0, there will be a better range 0≤i < N. So we start with ordinal 0: the ordinal (subscript) of an element equals the number of elements in the sequence that precede it. The moral of this story is that after a few centuries, we'd better think of 0 as the most natural number.

Note: Many programming languages do not pay attention to this detail at design time. such as FORTRAN subscript is starting from 1, ALGOL 60 and PASCAL used in the form of C). The recent SASL also follows FORTRAN practice: A sequence of SASL, and also a positive integer function. It's a pity! (Remark ends.) )

* *

*

The above is triggered by a recent incident, a great emotional outburst, a colleague of mathematics at my university (not a computer scientist) who accuses young computer scientists of "being pedantic" because they are accustomed to counting from 0. He deliberately picked the most reasonable practice to provoke. (with "... The practice of "ending" is really provocative, but this idiom is useful: I know that a student almost failed the exam, because he defaults to the bottom of the first page is the end of the problem. I think Antony Jay's statement was right: "In other similar areas, extremists are usually blown away, not because he may be wrong, but because he may be right." ”

Why is the count starting from zero

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.