Range notation
-
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
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 ?
-
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 ?
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
-
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)
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]
. -
(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.
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.
-
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)
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 includinga
andb
. 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) -
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)
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.
-
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)
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.
-
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)
-
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)
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.
-
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)
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...
-
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)
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.
-
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') ?
-
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)
-
As I replied before, it's the standard notation for an right-open range, but not the standard notation for an interval ...
-
Thank you very much for your helpful comment :rolleyes:
-
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.
Interesting - I'm from Germay, too... But my time in scool was 'til 1976, maybe things (and stuff to learn) changed since then
-
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 includinga
andb
. 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)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 ...
-
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.
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 );
} -
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
-
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...
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 ...