Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Range notation

Range notation

Scheduled Pinned Locked Moved The Lounge
databasediscussiongraphicsquestionlearning
46 Posts 20 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R RafagaX

    As several other have pointed out this is standard mathematical notation, I remember seeing it in my mathematics courses for my degree, so at least on this side of the river (Mexico) it exists, however as a programmer I have never used it to describe anything, and i'm pretty sure that my ex classmates don't even remember what this is for. So answering your question in programming is not very common, but in mathematics it's.

    CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

    K Offline
    K Offline
    Klaus Werner Konrad
    wrote on last edited by
    #41

    Thanks for your reply. Coming from Germany (and - of course - using a german keyboard layout) for me it's more than just confusing, because: ')' is SHIFT+9 ']' is ALTGR+9 So there is naturally a doubt if the ')' is intended or a typo ...

    1 Reply Last reply
    0
    • P patbob

      Klaus-Werner Konrad wrote:

      ‘‘the index must be in the [0 : size()) range,’’

      His reply to my question about this discrepance was (as I asked for) that I'm missing that it is 'common (at least in US) a Notation for 'open range''; what's quiet not definite - it's a 'right open range'.

      Ah, but its not an open range. Stroustrup expressed it exactly correctly -- its a range inclusive of the value 0, and exclusive of the value "size()" . If you're bounds checking access to an array, that's exactly the correct range check to make on the index. The parenthesis/square-bracket notation is indeed a standard mathematical notation for expressing the inclusive/exclusiveness of the range endpoints. Like you, I find the notation confusing. Despite reading it and using it myself countless times, I still have to look it up to make sure I use the correct bracketing. I do it because the notation is compact enough to include in the description of a function parameter, where popup documentation tips (a la intellisense) can present it to the next programmer while they're writing their code.

      We can program with only 1's, but if all you've got are zeros, you've got nothing.

      K Offline
      K Offline
      Klaus Werner Konrad
      wrote on last edited by
      #42

      Ok, you're right, I was not precise enough... It's not a open range, but a half-open range, or, to be really precise, a 'right half open interval' Look at: https://en.wikipedia.org/wiki/ISO_31-11[^]

      P 1 Reply Last reply
      0
      • E englebart

        I think the [0, size()) makes sense. What I want to know is why he wrote size() <= i I would have written i >= size() was he trying to show that i was to the right of the valid range? Or maybe he reads right to left from the close parenthesis? Reading right to left on size() <= i makes more sense to me. This looks like it is talking about C++. Many loops are written with an "open interval" sequence that terminates when you pass the end of the valid interval and reach the "undefined/inaccessible" end() marker. for (itr = ..initialize..; itr != the.end(); ..advance..) { .. do the work .. } I always thought this looping structure was kind of like these driving directions: "Drive straight until you see empty air in front of you, then take a left at the top of the cliff" but it is an easy metaphor to implement for almost any container.

        K Offline
        K Offline
        Klaus Werner Konrad
        wrote on last edited by
        #43

        I always used

        for (i=0; i< Size(); i++)

        from the logical POV, but in reality I prefer

        int sz = size;
        for (i=0; i < sz; i++)

        to avoid the function call overhead in every condition check

        1 Reply Last reply
        0
        • K Klaus Werner Konrad

          Ok, you're right, I was not precise enough... It's not a open range, but a half-open range, or, to be really precise, a 'right half open interval' Look at: https://en.wikipedia.org/wiki/ISO_31-11[^]

          P Offline
          P Offline
          patbob
          wrote on last edited by
          #44

          Wow. Referring to that kind of range as an "open" range was not the terminology I expected. I was so sure it meant one end of the range was unbounded, that I didn't actually go read that terminology page until you replied.. so thanks for taking the time to reply -- I learned something today.

          We can program with only 1's, but if all you've got are zeros, you've got nothing.

          1 Reply Last reply
          0
          • K Klaus Werner Konrad

            Interesting - I'm from Germay, too... But my time in scool was 'til 1976, maybe things (and stuff to learn) changed since then

            F Offline
            F Offline
            Florian Rappl
            wrote on last edited by
            #45

            That is one possibility. There are several others: - Either you forgot (if you do not need it, you will simply forget it) - It is state dependent (rumors are that in Bavaria school is the "best", but I do not know if that has ever been correct) - Your school focused on something different (I went to a school with mathematics as primary direction) Either way - don't worry about it :)

            1 Reply Last reply
            0
            • K Klaus Werner Konrad

              Thank you very much for your helpful comment :rolleyes:

              J Offline
              J Offline
              jibalt
              wrote on last edited by
              #46

              Sure, no problem.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups