Range 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)
I've always interpreted
[a,b)
to mean from (and including)a
upto (but not including)b
. /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
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') ?
The notation comes from mathematics where is very useful for open ranges of real numbers, for instance
[0,5)
is the open range containing all the real numbers from0
(included) up to5
excluded. It means an element of the range my go very very (arbitrary in fact) close to5
but can't reach it. You cannot use the[]
notation with this kind of range. Its usage with ranges of discrete elements (like in your examples) might be more arguable (however many folks don't find it confusing).Veni, vidi, vici.
-
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)
-
And this is exacly my Point - as explicitly as your Response is, this is my one: https://en.wikipedia.org/wiki/Integral[^] It is NOT the Standard to have an open range - the Standard is "for all values from (incl.) X to (incl.) Y do f(z) Am I missing something here, or am I just wrong, and ... did you read my original question, where I Asked for your opinion to explain the range to a customer for your API, and NOT asked to explain me what the Standard Notation (in YOUR opinium) for a range Definition is ? It was not my Goal to start a war of the notations, but to know what is usual for you AND YOUR CUSTOMERS. Sorry to let you go from your Bacon talk ...
Klaus-Werner Konrad wrote:
did you read my original question
Yes, I read your question. I'm not in the habit of posting random links in response to threads I haven't read. You asked if the notation was common; I pointed out that, in mathematics, it's the standard notation. Anyone with a mathematical background would understand
[x, y)
to meanx <= i < y
, which makes it a fairly common notation. It's also much simpler than your proposedFROM incl. x TO incl. Y
notation.Klaus-Werner Konrad wrote:
what is usual for you AND YOUR CUSTOMERS
Your original question made no mention of customers. You were talking about a book aimed at programmers. It's fairly reasonable to assume that most programmers will have at least a basic understanding of common mathematical notation. If it was aimed at people without such an understanding, you would most likely avoid any notation for limits unless you explained it first. FYI: In English, responding to answers with "did you read the question?" sounds patronising and antagonistic. I'm assuming that wasn't your intent?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Klaus-Werner Konrad wrote:
did you read my original question
Yes, I read your question. I'm not in the habit of posting random links in response to threads I haven't read. You asked if the notation was common; I pointed out that, in mathematics, it's the standard notation. Anyone with a mathematical background would understand
[x, y)
to meanx <= i < y
, which makes it a fairly common notation. It's also much simpler than your proposedFROM incl. x TO incl. Y
notation.Klaus-Werner Konrad wrote:
what is usual for you AND YOUR CUSTOMERS
Your original question made no mention of customers. You were talking about a book aimed at programmers. It's fairly reasonable to assume that most programmers will have at least a basic understanding of common mathematical notation. If it was aimed at people without such an understanding, you would most likely avoid any notation for limits unless you explained it first. FYI: In English, responding to answers with "did you read the question?" sounds patronising and antagonistic. I'm assuming that wasn't your intent?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Richard Deeming wrote:
Yes, I read your question. I'm not in the habit of posting random links in response to threads I haven't read.
You asked if the notation was common; I pointed out that, in mathematics, it's the standard notationHm... I followed your link again, and the first paragraph reads:
In mathematics, a (real) interval is a set of real numbers with the property that any number that lies between two numbers in the set is also included in the set. For example, the set of all numbers x satisfying 0 ≤ x ≤ 1 is an interval which contains 0 and 1, as well as all numbers between them
After the TOC is a paragraph titled 'Notations for intervals', that reads
The interval of numbers between a and b, including a and b, is often denoted [a, b]. The two numbers are called the endpoints of the interval. In countries where numbers are written with a decimal comma, a semicolon may be used as a separator, to avoid ambiguity.
Some paragraphs down is a paragraph titled 'Integer intervals' that reads
The notation [a .. b] when a and b are integers, or {a .. b} , or just a .. b is sometimes used to indicate the interval of all integers between a and b, including both. This notation is used in some programming languages; in Pascal, for example, it is used to define the set of valid indices of a vector.
Also ther is a link to https://en.wikipedia.org/wiki/Interval_arithmetic[^]There, too, all intervals are described with the [a,b] Notation. So - sorry, but I really doubt that [a,b) is the standard Notation, even in mathematics ...
Richard Deeming wrote:
It's also much simpler than your proposed
FROM incl. x TO incl. Y
notationWell - I just tried to emphasize the inclusion of x and y, but meant [x,y]. I don't want to introduce a new Notation :-)
Richard Deeming wrote:
Your original question made no mention of customers
If you write libraries (as I do) your customers are programmers, too. Last, I apologise; I didn't intend to be patronising, but your answer (just a link) was IMHO not really an answer to my question.
-
Richard Deeming wrote:
Yes, I read your question. I'm not in the habit of posting random links in response to threads I haven't read.
You asked if the notation was common; I pointed out that, in mathematics, it's the standard notationHm... I followed your link again, and the first paragraph reads:
In mathematics, a (real) interval is a set of real numbers with the property that any number that lies between two numbers in the set is also included in the set. For example, the set of all numbers x satisfying 0 ≤ x ≤ 1 is an interval which contains 0 and 1, as well as all numbers between them
After the TOC is a paragraph titled 'Notations for intervals', that reads
The interval of numbers between a and b, including a and b, is often denoted [a, b]. The two numbers are called the endpoints of the interval. In countries where numbers are written with a decimal comma, a semicolon may be used as a separator, to avoid ambiguity.
Some paragraphs down is a paragraph titled 'Integer intervals' that reads
The notation [a .. b] when a and b are integers, or {a .. b} , or just a .. b is sometimes used to indicate the interval of all integers between a and b, including both. This notation is used in some programming languages; in Pascal, for example, it is used to define the set of valid indices of a vector.
Also ther is a link to https://en.wikipedia.org/wiki/Interval_arithmetic[^]There, too, all intervals are described with the [a,b] Notation. So - sorry, but I really doubt that [a,b) is the standard Notation, even in mathematics ...
Richard Deeming wrote:
It's also much simpler than your proposed
FROM incl. x TO incl. Y
notationWell - I just tried to emphasize the inclusion of x and y, but meant [x,y]. I don't want to introduce a new Notation :-)
Richard Deeming wrote:
Your original question made no mention of customers
If you write libraries (as I do) your customers are programmers, too. Last, I apologise; I didn't intend to be patronising, but your answer (just a link) was IMHO not really an answer to my question.
All of the references to
[x, y]
are including both endpoints. I think you missed the section headed "Excluding the endpoints":To indicate that one of the endpoints is to be excluded from the set, the corresponding square bracket can be either replaced with a parenthesis, or reversed. Both notations are described in International standard ISO 31-11[^].
Which means that both
[x, y)
and[x, y[
are international standard representations of a right half-open interval.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
All of the references to
[x, y]
are including both endpoints. I think you missed the section headed "Excluding the endpoints":To indicate that one of the endpoints is to be excluded from the set, the corresponding square bracket can be either replaced with a parenthesis, or reversed. Both notations are described in International standard ISO 31-11[^].
Which means that both
[x, y)
and[x, y[
are international standard representations of a right half-open interval.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
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.
-
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.
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
-
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.
-
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)