Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Off-by-one error
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Fencepost error=== A '''fencepost error''' (occasionally called a '''telegraph pole,''' '''lamp-post,''' or '''picket fence error''') is a specific type of off-by-one error. An early description of this error appears in the works of [[Vitruvius]].<ref>{{citation|url=http://www.dsm.fordham.edu/~moniot/Opinions/fencepost-error-history.shtml|title=Who first described the "fence-post error?"|first=Robert K.|last=Moniot|publisher=[[Fordham University]]|access-date=2016-07-07|archive-url=https://web.archive.org/web/20160305221341/http://www.dsm.fordham.edu/~moniot/Opinions/fencepost-error-history.shtml|archive-date=2016-03-05}}.</ref> The following problem illustrates the error: {{Quote|If you build a straight [[fence]] 30 feet long with posts spaced 3 feet apart, how many posts do you need?}} [[Image:Fencepost error 01.svg|thumb|upright=1.2|A straight fence with 10 sections requires 11 posts. More generally, ''n'' sections would require {{Nowrap|''n'' + 1}} posts.]] The common answer of 10 posts is wrong. This response comes from dividing the length of the fence by the spacing apart from each post, with the quotient being erroneously classified as the number of posts. In actuality, the fence has 10 sections and 11 posts. In this scenario, a fence with ''n'' sections will have {{Nowrap|''n'' + 1}} posts. Conversely, if the fence contains ''n'' posts, it will contain {{Nowrap|''n'' β 1}} sections. This relationship is important to consider when dealing with the reverse error. The reverse error occurs when the number of posts is known and the number of sections is assumed to be the same. Depending on the design of the fence, this assumption can be correct or incorrect. The following problem demonstrates the reverse error: {{Quote|If you have ''n'' posts, how many sections are there between them?}} The interpretation for the fence's design changes the answer to this problem. The correct number of sections for a fence is {{nowrap|''n'' β 1}} if the fence is a free-standing line segment bounded by a post at each of its ends (e.g., a fence between two passageway gaps), ''n'' if the fence forms one complete, free-standing loop (e.g., enclosure accessible by surmounting, such as a boxing ring), or {{nowrap|''n'' + 1}} if posts do not occur at the ends of a line-segment-like fence (e.g., a fence between and wall-anchored to two buildings). The precise problem definition must be carefully considered, as the setup for one situation may give the wrong answer for other situations. Fencepost errors can also occur in units other than length. For example, the [[Time Pyramid]], consisting of 120 blocks placed at 10-year intervals between blocks, is scheduled to take 1,190 years to build (not 1,200), from the installation of the first block to the last block. One of the earliest fencepost errors involved time, where the [[Julian calendar]] originally [[Julian calendar#Leap year error|calculated leap years incorrectly]], due to counting inclusively rather than exclusively, yielding a leap year every three years rather than every four. In larger numbers, being off by one is often not a major issue. In smaller numbers, however, and specific cases where accuracy is paramount, committing an off-by-one error can be disastrous. Sometimes such an issue will also be repeated and, therefore, worsened, by someone passing on an incorrect calculation, if the following person makes the same kind of mistake again (of course, the error might also be reversed). An example of this error can occur in the computational language [[MATLAB]] with the <code>linspace()</code> [[linear interpolation]] function, whose parameters are <code>(''lower value'', ''upper value'', ''number of values'')</code> and not <code>(''lower value'', ''upper value'', ''number of increments'')</code>. A programmer who misunderstands the third parameter to be the number of increments might hope that <code>linspace(0,10,5)</code> would achieve a sequence {{nowrap|<code>[0, 2, 4, 6, 8, 10]</code>}} but instead would get {{nowrap|<code>[0, 2.5, 5, 7.5, 10]</code>}}.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)