Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

B Index numbers vs. Quantity in a group

  1. Oct 13, 2017 #1
    "Quantity in a group"
    If you have 6 apples and you subtract 4, then you have 2 apples left "in the group".

    "Quantity in an Indexed group"
    I'm a computer programmer - I manipulate arrays of data (a.k.a. matrix)
    In a math formula format: x1, x2, x3... xn
    (as a side note - in a computer format: x[0], x[1], x[2]... x[n-1])
    If I want the "quantity" from 6 to 4, then I always have to add 1 (6-4=2, 2+1=3 quantity)
    Quantity of 3: x4, x5, x6

    Surprisingly, I was never taught this in grade school or high school.
    Not to mention I always thought it had to do with the fact that a computer's array starts with index 0: x[0]
    (It doesn't, although that fact adds confusion when turning math formulas into code)

    My question is: Does this "add 1" scenario have a mathematical name?
    (I've been trying to Google about it to add a note/comment to my code to explain "+1" without sounding stupid)

  2. jcsd
  3. Oct 13, 2017 #2


    Staff: Mentor

    The closest I can come up with for a name is when you miscount -- a "fence-post" error. The number of elements in the range ##x_m## through ##x_n##, inclusive, with ##n \ge m##, is n - m + 1. For example, the number of elements in the range ##x_3## through ##x_7##, again inclusive, is 7 - 3 + 1 = 5. They are ##x_3, x_4, x_5, x_6, x_7##. This type of counting typically isn't taught in grade school or high school (that I am aware of), but it is taught in basic computer science classes, or possibly in probability and statistics courses.
  4. Oct 13, 2017 #3
    Wow, perfect. I learned something new today.

    Wikipedia has it described under: Off-by-one error (OBOE)
    Thanks Mark
  5. Oct 13, 2017 #4
    Wow again...
    This also explains the age-old problem/confusion with year/century (e.g. the 1900's is the 20th century).
    Cool man.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted