Fence post failure

from Wikipedia, the free encyclopedia

A fence post error (from English fencepost error ) is an error that arises from the properties of confusion between the number in a row with the number of spaces between these objects. The result is either one too small or one too large. A fence post error thus leads to a one-off error .

The term originated in computer science , where it is also most commonly used.

Fence post problems alias errors exist in all areas of life. Their name comes from the fact that they can appear when calculating a fence consisting of stakes and intermediate fields . A typical fence post mistake is trying to equate the number of intermediate fields with the number of posts. The number of gaps in a fence (not closed in a ring) is always 1 less than the number of posts.

Illustration of the fence post problem on a fence:
Between 11 posts (in general: objects), not 11, but only 10 fence segments (in general: gaps that have to be filled here) can be installed.

Numbering, counting, subtracting

For example, if you look at an area that is defined by objects numbers 1 to 11 in an ascending order, the following applies:

  • The difference between the numbers plus 1, in the example 11 - 1 + 1 = 11, is the number of objects considered.
With a tape measure , the front edge with the value 0 cm corresponds to an object with the number 0. In this way (numbering starting with 0) the following numbers (values ​​in cm) correspond to the gaps counted from the front edge (1 cm each) and thus the measured Length.

To determine the number of spaces without an invoice, only by counting on a series of objects, offers itself, with the start object as 0 to count to begin, or omit the start object when counting the objects. Then the number of the end object corresponds to the number of spaces. The adjacent picture of the measuring tape illustrates this method: the measuring tape is not marked with 1, but with the front edge, which corresponds to the value 0, in order to determine the distance between two points.

In order to count the objects themselves, however, it is advisable to start counting as 1 with the start object. Then the number of the end object corresponds to the number of objects. If the counting methods are mixed up, there is a fence post error.

If the objects have constant distances of known size, the distance between two objects can be calculated from the number of spaces multiplied by the size of the spaces (that is, the distance between neighboring objects). In the example of the tape measure, the size of the spaces is 1 cm. In the example of the fence above, assuming that the fence posts are each 3 meters apart, the distance between the first and last post is (11 - 1) × 3 m = 30 m. That is the fence length.

Computer science

Fence post errors typically show up as a numerical value that is 1 too large or too small. In computer science, such errors are also called off-by-one errors . They belong to the following main groups:

  1. Confusion of distances and numbers.
  2. When it comes to the spacing of elements in a sequence, the software developer must be aware of whether one or both boundary elements are included or not.
  3. Counting from 0 or from 1: In everyday life, people usually start enumerations with 1 , but in many programming languages ​​such as C or Java , indexing starts with 0 by default . This is because in these programming languages ​​the index in a field (array) indicates a distance (an offset) to the start address of the field. The first element begins directly at the start address, ie has the offset 0. The elements of a field of length 5 have the indices 0, 1, 2, 3 and 4. A typical beginner's mistake is to loop the index up to the length of the field (5) run - which creates an addressing error - instead of up to the length of the field minus 1.

Related problems

The historical inclusive census

Distances and time has been converted from antiquity to postmedieval in time in accordance with the " inclusive count specified". With this counting method, both the beginning and the end element of a sequence are counted. The starting point is defined as “1” and counting continues from there. The distance 0 is assigned the numerical value "1", the distance 1 the numerical value "2", etc. The values ​​for distances, periods, etc. are always 1 larger in the inclusive counting than according to today's mathematical convention. Historically, inclusive counting is due to the fact that the concept of the number zero only became known in Europe with the introduction of Arabic- Indian numbers in the 13th century.

One of the earliest examples of fence post failure occurred during the calendar reform of Gaius Iulius Caesar . Caesar had ordered a leap year every fourth year. However, according to the inclusive count, the priests understood this to be a leap year every three years.

From the inclusive count, for example, comes the custom of saying “in a week” next to “in seven days” as well as “in eight days”, although everyone knows that a week has seven days. The current day of the week is included in the inclusive count:

Weekday: Monday Tuesday Wednesday Thursday Friday Saturday Sunday Monday
"Number" of the day: 1 2 3 4th 5 6th 7th 8th

In French, following the same scheme, “in two weeks” is often said “en quinze jours” (in 15 days).

Another example of the inclusive counting are the names of the musical intervals :

Distance between two tones: 0 1 2 3 4th 5 6th 7th
Name of the interval: Prime second third Fourth Fifth Sixth Seventh octave
Comes from the Latin number: 1 2 3 4th 5 6th 7th 8th

The fact that the name of each interval, which is common in music, is 1 too large, can be seen, among other things, from the addition of intervals. A fourth and a fifth add up to an octave . But 4 + 5 is not 8.

Time calculation

Year zero

The Christian calendar does not know a year zero , but starts from the year 1 BC. Directly into the year 1 AD. In the astronomical calendar , however, the year 1 BC is used. Chr. Calculated as year zero.

Christian year: 2 v. Chr. 1 v. Chr. 1 AD 2 AD
Astronomical year: −1 0 1 2

Centuries and the like

The well-known logo of the film studio 20th Century Fox . In English, the 20th century also refers to the century from 1901 to 2000.

There was no such thing as a “zero century”. The 1st  century lasted from January 1, 1 AD to December 31, 100 AD. A century always includes the hundred years that end with the corresponding full year . Similarly, the period from January 1, 1901 to December 31, 2000 is referred to as the 20th century, and the 21st century began on January 1, 2001.

In English , in addition to the normal designation of the centuries (20th century) , the centuries are also colloquially named in such a way that 1900s (pronounced “nineteen-hundreds”) describes the period from 1900 to 1999. In Italian , for example, in addition to XX secolo, there is also the option of using Novecento (literally: "nine hundred") to designate the period 1900–1999 (this is only possible for centuries from the year 1100). The same applies to the decades in German-speaking countries : The first decade of the 21st century covers the period January 1, 2001 to December 31, 2010, but the term 2000s in the sense of the expression January 1, 2000 to December 31, 2009 .

With regard to the now appearing "2" at the beginning of the year 2000, this was mathematically incorrectly equated with the term turn of the millennium and this was used for the turn of the year 1999/2000, which was the reason why already on New Year's Eve From December 31, 1999 to January 1, 2000 the dawn of the new millennium was celebrated intensively with numerous impressive events.

Anniversaries

Anniversaries are the recurrence of an event after a full year: 1st anniversary after one year, 2nd anniversary after two years, etc., since the event.

One example is the birthday, which could also be called the anniversary. So z. E.g .: 50th birthday = 50th anniversary (after fifty years of age), day of birth = "0. Birthday "=" 0. Anniversary ”, similar to the 0 mark on a centimeter ruler. The other marks correspond to the number of the birthday, the gaps to the number of the current year of life. If you add the birth event to be commemorated to the number of the day of remembrance (birthday), the fence post problem becomes apparent: the number of events (objects) is 1 greater than the number of years (spaces in between).

Geburtstage:
         Geburt 1.  2.  3.  4.  5.  6.  7.  8.  9. 10. 11. 12. 13. 14. 15. 16. 17. 18.
             \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ /
Lebensjahre:  1.  2.  3.  4.  5.  6.  7.  8.  9  10. 11. 12. 13. 14. 15. 16. 17. 18.

In some cultures, e.g. B. the Chinese culture , however, is different. There, for age information, it is not counted how long a person has been in the world, but in how many calendar years (according to the local calendar) he has lived. In the Chinese calendar , the turn of the year is the Chinese New Year . Therefore, in China, a newborn is already "1 year old" on the day it is born and on its first New Year celebration the child will already be "2 years old", even if it is not yet 12 months in the world.

For events that regularly take place once a year, a round anniversary edition and the corresponding old anniversary of the beginning of the event or edition series (the first edition) are one year apart, which often leads to ambiguities. The first Guinness Book of Records was issued in 1955 and the first Eurovision Song Contest was held in 1956 . For the 60th Eurovision Song Contest in 2015 it was reported that the Guinness Book of Records was also celebrating its 60th birthday, so the two were exactly the same age.

year 1955 1956 1957 ... 1964 1965 ... 2014 2015
Guinness Book No. 1 2 3 ... 10 11 ... 60 61
Eurovision Song Contest No. - 1 2 .. 9 10 ... 59 60

Finding the middle

If counting starts with 1, then the middle does not correspond to half the number of elements. For example, a scale from 1 to 10 is given. The 5 is not in the middle of the scale, but below it. The actual center is 5 12 :

1 2 3 4 5 6 7 8 9 10
         ^Mitte

The following may also seem unintuitive or “surprising” at first: Of five elements, numbered 1 2 3 4 5, the middle element is the one with the number 3 - although half of 5 is known to be 2 12 .

On the other hand, a scale from 0 to 10 has 11 indices and the middle is 5:

0 1 2 3 4 5 6 7 8 9 10
          ^Mitte

The reason for this is the same as the fence post problem described above. The upper scale has indices 1 to 10. These are considered points. The scale therefore only describes a length (distance, distance between beginning and end) of 9, because 10 - 1 = 9. Its center is therefore at half of 9, calculated from the index 1: 1 + (9/2) = 5 12 .

The lower scale with the indices 0 to 10, on the other hand, describes a length of 10 and its center is 0 + (10/2) = 5.

Floors

In the German language area of 1. floor the first set stock te, so the first upper storey, in contrast to the underlying ground basement or par terre . The same applies to borrowed from French 1st  floor : so this also means the first upper storey. In many cultures, however, e.g. For example, in the USA, Canada or the former Soviet Union, counting starts with the first floor as number 1. Even if levels are numbered consecutively instead of floors in Germany, counting often starts with level 1 on the first floor.

At three or at three and then?

“On three or on three and then?” Is a famous quote from the Lethal Weapon action film series . The problem here is whether you should start the jointly planned, surprising action after you have counted to three or exactly when you say “three”.

Notes and individual references

  1. Jesse Liberty, David Horvath: Now I'm learning C ++: the complete starter kit for an easy introduction to programming; [Start without prior knowledge] . Pearson Germany, 2004, ISBN 978-3-8272-6830-3 , pp. 290 ( books.google.com ). [1]
  2. Andrew Koenig: C Traps and Pitfalls . Pearson Education, 1988, ISBN 978-81-7758-139-3 , pp. Section 3.6 ( books.google.com ).
  3. ^ Steve Heller: C ++: a Dialogue: Programming with the C ++ Standard Library . Prentice Hall Professional, 2003, ISBN 978-0-13-009402-5 , pp. 353 ff . ( books.google.com ). [2]
  4. That was not possible in ancient times because the zero was not known. In ancient times, the inclusive counting , which included the initial object, was used when considering periods and intervals (see below).
  5. This different age calculation has nothing to do with the fact that the child's birth is preceded by around nine months during the mother's pregnancy.
  6. Eurovision Song Contest now holds Guinness world record. oe3.orf.at, 2015, last accessed January 18, 2016. "Guinness World Records is the globally recognized institution for the verification and certification of world records and this year, just like the Eurovision Song Contest, celebrates its 60th anniversary"