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 0 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.
  • K Klaus Werner Konrad

    Well - let me repeat my reply to your first post:

    It's one of the (Standard) notations,but not the Standard Notation !

    And NO, I didn't miss the section headed 'Excluding the endpoints' Also, the notation [a,b] is listed in ISO 31-11, too.

    Richard DeemingR Offline
    Richard DeemingR Offline
    Richard Deeming
    wrote on last edited by
    #21

    Klaus-Werner Konrad wrote:

    It's one of the (Standard) notations,but not the Standard Notation !

    So what other standard notations for open-ended ranges are there? The only notations you've posted so far seem to be for closed ranges.


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

    K 1 Reply Last reply
    0
    • Richard DeemingR Richard Deeming

      Klaus-Werner Konrad wrote:

      It's one of the (Standard) notations,but not the Standard Notation !

      So what other standard notations for open-ended ranges are there? The only notations you've posted so far seem to be for closed ranges.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

      I never doubt that it's the stndard notation for an open-ended range, but that was not my question ... This is the excerpt from my original post:

      But that's not the Point; my query is to find out, if this notation is (seen worlswide) really common.
      For me, this notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation.

      So, to clarify it for you: What do you think is more common a) [a:b] --> closed range (that I named 'inbound') b) [a:b) --> right-open range What do you think is more intuitiv a) [a:b] --> closed range b) [a:b) --> right-open range Got it ?

      Richard DeemingR 1 Reply Last reply
      0
      • K Klaus Werner Konrad

        I never doubt that it's the stndard notation for an open-ended range, but that was not my question ... This is the excerpt from my original post:

        But that's not the Point; my query is to find out, if this notation is (seen worlswide) really common.
        For me, this notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation.

        So, to clarify it for you: What do you think is more common a) [a:b] --> closed range (that I named 'inbound') b) [a:b) --> right-open range What do you think is more intuitiv a) [a:b] --> closed range b) [a:b) --> right-open range Got it ?

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #23

        Ah, I see. I think we've been talking at cross-purposes. (And there's nothing worse than an angry cetacean[^]!) An open-ended range is uncommon for integers, since it's possible to specify an inclusive upper-bound. However, it shouldn't cause any confusion for anyone familiar with the notation.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • K Klaus Werner Konrad

          Well - had a (very short) discussion with Bjarne Stroustrup this day ... In a draft of his new book he explained a code fragment as

          double& Vector::operator[](int i)
          {
          if (i<0 || size()<=i) throw out_of_range{"Vector::operator[]"};
          retur n elem[i];
          }

          where size() returns the number of elements in the vector collection. But in the text he wrote: (can't find any link to 'quote' a clipboarded text) "Had we formally specified V ector’s subscript operator, we would have said something like ‘‘the index must be in the [0 : size()) range,’’ and that was in fact what we tested in our operator[]()." 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'. But that's not the Point; my query is to find out, if this Notation is (seen worlswide) really common. For me, this Notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation. What are your thoughts about it (please with Nation code, to weight the arguments)

          Y Offline
          Y Offline
          YvesDaoust
          wrote on last edited by
          #24

          What about [a [b, completely nonstandard ? Generalizes to [a [b [c ... in case of several contiguous ranges. Or more complex configurations like [a [b] c].

          1 Reply Last reply
          0
          • C CPallini

            (If I got you) Yes, [) is a common notation (at least here in Italy) for the right open range. I suppose it is a fair common mathematical notation also in the rest of the world.

            Veni, vidi, vici.

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

            Yes, not only in Italy. We already learn this in Mid-school here in Germany (I learned this around 5th or 6th grade). Also every calculus 101 is introducing this notation.

            K 1 Reply Last reply
            0
            • K Klaus Werner Konrad

              Well - had a (very short) discussion with Bjarne Stroustrup this day ... In a draft of his new book he explained a code fragment as

              double& Vector::operator[](int i)
              {
              if (i<0 || size()<=i) throw out_of_range{"Vector::operator[]"};
              retur n elem[i];
              }

              where size() returns the number of elements in the vector collection. But in the text he wrote: (can't find any link to 'quote' a clipboarded text) "Had we formally specified V ector’s subscript operator, we would have said something like ‘‘the index must be in the [0 : size()) range,’’ and that was in fact what we tested in our operator[]()." 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'. But that's not the Point; my query is to find out, if this Notation is (seen worlswide) really common. For me, this Notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation. What are your thoughts about it (please with Nation code, to weight the arguments)

              S Offline
              S Offline
              Stefan_Lang
              wrote on last edited by
              #26

              If your intention is to express a range of numbers from a to but not including b, then the mathematical notation for that is one of the following:

              [a,b)
              [a;b)
              [a,b[
              [a;b[

              The use of ';' instead of ',' is optional in countries that use ',' as a decimal point (e. g. germany). Otherwise you'd only use ','. That said, in mathematics open or half-open intervals are normally only used in the context of real numbers, not for integral numbers. Bjarne Stroustrup was obviously thinking of that notation, and that makes sense if his intention was to generalize the notation for use with floating point intervals. But, since the index range in this example can only be an integer interval, it would have been clearer to just write [0, size()-1] instead. Also, his use of ':', while common in computer science to express a range of values, does deviate from the mathematical notation. In CS a range is often expressed as a:b, with or without brackets of any type. The meaning, as I understand it, is always the range of values between and including a and b. Personally I can't remember having seen the half-open interval notation in the context of computer science in the past 30 years. If it is formally defined somewhere, I must have missed it. I suspect this is just a mixup of mathematical ([)) and CS (a:b) notation. (CH/DE)

              K 1 Reply Last reply
              0
              • K Klaus Werner Konrad

                Well - had a (very short) discussion with Bjarne Stroustrup this day ... In a draft of his new book he explained a code fragment as

                double& Vector::operator[](int i)
                {
                if (i<0 || size()<=i) throw out_of_range{"Vector::operator[]"};
                retur n elem[i];
                }

                where size() returns the number of elements in the vector collection. But in the text he wrote: (can't find any link to 'quote' a clipboarded text) "Had we formally specified V ector’s subscript operator, we would have said something like ‘‘the index must be in the [0 : size()) range,’’ and that was in fact what we tested in our operator[]()." 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'. But that's not the Point; my query is to find out, if this Notation is (seen worlswide) really common. For me, this Notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation. What are your thoughts about it (please with Nation code, to weight the arguments)

                R Offline
                R Offline
                Rob Grainger
                wrote on last edited by
                #27

                As all the STL algorithms are based on right open ranges, I think it's reasonable to assume knowledge of this notation. I was taught this in the UK, as far as I know it really is standard mathematical notation, internationally, so it seems reasonable to assume knowledge of it.

                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                K 1 Reply Last reply
                0
                • K Klaus Werner Konrad

                  Well - had a (very short) discussion with Bjarne Stroustrup this day ... In a draft of his new book he explained a code fragment as

                  double& Vector::operator[](int i)
                  {
                  if (i<0 || size()<=i) throw out_of_range{"Vector::operator[]"};
                  retur n elem[i];
                  }

                  where size() returns the number of elements in the vector collection. But in the text he wrote: (can't find any link to 'quote' a clipboarded text) "Had we formally specified V ector’s subscript operator, we would have said something like ‘‘the index must be in the [0 : size()) range,’’ and that was in fact what we tested in our operator[]()." 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'. But that's not the Point; my query is to find out, if this Notation is (seen worlswide) really common. For me, this Notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation. What are your thoughts about it (please with Nation code, to weight the arguments)

                  E Offline
                  E Offline
                  englebart
                  wrote on last edited by
                  #28

                  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 1 Reply Last reply
                  0
                  • K Klaus Werner Konrad

                    Well - had a (very short) discussion with Bjarne Stroustrup this day ... In a draft of his new book he explained a code fragment as

                    double& Vector::operator[](int i)
                    {
                    if (i<0 || size()<=i) throw out_of_range{"Vector::operator[]"};
                    retur n elem[i];
                    }

                    where size() returns the number of elements in the vector collection. But in the text he wrote: (can't find any link to 'quote' a clipboarded text) "Had we formally specified V ector’s subscript operator, we would have said something like ‘‘the index must be in the [0 : size()) range,’’ and that was in fact what we tested in our operator[]()." 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'. But that's not the Point; my query is to find out, if this Notation is (seen worlswide) really common. For me, this Notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation. What are your thoughts about it (please with Nation code, to weight the arguments)

                    C Offline
                    C Offline
                    cmmello
                    wrote on last edited by
                    #29

                    I was taught that notation in school here in Brazil too. Best regards Mello

                    K 1 Reply Last reply
                    0
                    • K Klaus Werner Konrad

                      Well - had a (very short) discussion with Bjarne Stroustrup this day ... In a draft of his new book he explained a code fragment as

                      double& Vector::operator[](int i)
                      {
                      if (i<0 || size()<=i) throw out_of_range{"Vector::operator[]"};
                      retur n elem[i];
                      }

                      where size() returns the number of elements in the vector collection. But in the text he wrote: (can't find any link to 'quote' a clipboarded text) "Had we formally specified V ector’s subscript operator, we would have said something like ‘‘the index must be in the [0 : size()) range,’’ and that was in fact what we tested in our operator[]()." 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'. But that's not the Point; my query is to find out, if this Notation is (seen worlswide) really common. For me, this Notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation. What are your thoughts about it (please with Nation code, to weight the arguments)

                      K Offline
                      K Offline
                      Keith Tyra
                      wrote on last edited by
                      #30

                      I know the notation, and learned it in math classes required for a computer science degree at a US university. But I wouldn't expect most US programmers to know it, since most of the people in my major did not like math. On hearing "Big O" these days, some of them would probably be thinking "giant robot". For my own use I sometimes use mathematical notations because they are concise and precise.

                      1 Reply Last reply
                      0
                      • K Klaus Werner Konrad

                        Well - had a (very short) discussion with Bjarne Stroustrup this day ... In a draft of his new book he explained a code fragment as

                        double& Vector::operator[](int i)
                        {
                        if (i<0 || size()<=i) throw out_of_range{"Vector::operator[]"};
                        retur n elem[i];
                        }

                        where size() returns the number of elements in the vector collection. But in the text he wrote: (can't find any link to 'quote' a clipboarded text) "Had we formally specified V ector’s subscript operator, we would have said something like ‘‘the index must be in the [0 : size()) range,’’ and that was in fact what we tested in our operator[]()." 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'. But that's not the Point; my query is to find out, if this Notation is (seen worlswide) really common. For me, this Notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation. What are your thoughts about it (please with Nation code, to weight the arguments)

                        R Offline
                        R Offline
                        RafagaX
                        wrote on last edited by
                        #31

                        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 1 Reply Last reply
                        0
                        • K Klaus Werner Konrad

                          Well - had a (very short) discussion with Bjarne Stroustrup this day ... In a draft of his new book he explained a code fragment as

                          double& Vector::operator[](int i)
                          {
                          if (i<0 || size()<=i) throw out_of_range{"Vector::operator[]"};
                          retur n elem[i];
                          }

                          where size() returns the number of elements in the vector collection. But in the text he wrote: (can't find any link to 'quote' a clipboarded text) "Had we formally specified V ector’s subscript operator, we would have said something like ‘‘the index must be in the [0 : size()) range,’’ and that was in fact what we tested in our operator[]()." 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'. But that's not the Point; my query is to find out, if this Notation is (seen worlswide) really common. For me, this Notation is just confusing; I prefer the inbound (FROM incl. x TO incl. Y) notation. What are your thoughts about it (please with Nation code, to weight the arguments)

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

                          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 1 Reply Last reply
                          0
                          • K Klaus Werner Konrad

                            You got me, thanks. May be I'm just ignorant, but I've never come across this notation, and it's (from a Logical thought) very uncomfortable, and also it's not common in the common sense ... Imagine: "Select - on a Scala from 1 to 10 =[1:10]" against "Select - on a Scala fron 1 to 10 =[1:11) What is intuitive ? What can you get only by cross-reading (the FM for the API)? What is the natural thinking (against that indices 'MUST start with 0') ?

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

                            "May be I'm just ignorant" There's no maybe about it.

                            K 1 Reply Last reply
                            0
                            • K Klaus Werner Konrad

                              Ahem ... It's one of the (Standard) notations,but not the Standard Notation ! Remember PASCAL ? And - especially for a novice programmer - this Notation can lead to the 'on off' bug 'cause of misinterpretation (I thought it was a typo, 'cause a ')' is a SHIFT+9, whereas a ']' is a ALTGR+9' (on a german keyboard) ... But my real question is, if you provide an API, in wich notation would you explain a range to your customer (app dev), and wich notation would you (as an app dev) expect (in cross-reading the doc.'cause your'e in a hurry)

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

                              It's the standard mathematical notation for an interval ... Pascal is irrelevant.

                              K 1 Reply Last reply
                              0
                              • J jibalt

                                It's the standard mathematical notation for an interval ... Pascal is irrelevant.

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

                                As I replied before, it's the standard notation for an right-open range, but not the standard notation for an interval ...

                                1 Reply Last reply
                                0
                                • J jibalt

                                  "May be I'm just ignorant" There's no maybe about it.

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

                                  Thank you very much for your helpful comment :rolleyes:

                                  J 1 Reply Last reply
                                  0
                                  • F Florian Rappl

                                    Yes, not only in Italy. We already learn this in Mid-school here in Germany (I learned this around 5th or 6th grade). Also every calculus 101 is introducing this notation.

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

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

                                    F 1 Reply Last reply
                                    0
                                    • S Stefan_Lang

                                      If your intention is to express a range of numbers from a to but not including b, then the mathematical notation for that is one of the following:

                                      [a,b)
                                      [a;b)
                                      [a,b[
                                      [a;b[

                                      The use of ';' instead of ',' is optional in countries that use ',' as a decimal point (e. g. germany). Otherwise you'd only use ','. That said, in mathematics open or half-open intervals are normally only used in the context of real numbers, not for integral numbers. Bjarne Stroustrup was obviously thinking of that notation, and that makes sense if his intention was to generalize the notation for use with floating point intervals. But, since the index range in this example can only be an integer interval, it would have been clearer to just write [0, size()-1] instead. Also, his use of ':', while common in computer science to express a range of values, does deviate from the mathematical notation. In CS a range is often expressed as a:b, with or without brackets of any type. The meaning, as I understand it, is always the range of values between and including a and b. Personally I can't remember having seen the half-open interval notation in the context of computer science in the past 30 years. If it is formally defined somewhere, I must have missed it. I suspect this is just a mixup of mathematical ([)) and CS (a:b) notation. (CH/DE)

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

                                      That was my thought, too; for me it was also total unfamiliar. As Richard Deeming pointed, it is the standard notation for right-open ranges according to https://en.wikipedia.org/wiki/ISO_31-11[^] As I wrote in another reply to him, this notation seems to be quite unusual in programming context, but I've read the next chapters of Bjarne's book, and he uses this notation at least consistent ...

                                      1 Reply Last reply
                                      0
                                      • R Rob Grainger

                                        As all the STL algorithms are based on right open ranges, I think it's reasonable to assume knowledge of this notation. I was taught this in the UK, as far as I know it really is standard mathematical notation, internationally, so it seems reasonable to assume knowledge of it.

                                        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

                                        Yes, I learned a bit about this stuff recently, but coming from plain C, where there are nothing of this fancy things, I've never come accross this Notation, although I used it all the time:

                                        for (i = 0; i < count; i++)
                                        {
                                        do_something( i );
                                        }

                                        1 Reply Last reply
                                        0
                                        • C cmmello

                                          I was taught that notation in school here in Brazil too. Best regards Mello

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

                                          Thanks for your reply, but my question was 'Is it common' (in use by programmers), not 'is it common' (to know it) May be my question was a little ambiguous - sorry for that, but english isn't my native language and some questions that in german language are total clear are not this clear in english language

                                          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