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)
-
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)
It's the standard mathematical notation for an interval: https://en.wikipedia.org/wiki/Interval_%28mathematics%29#Notations_for_intervals[^]
"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)
-
It's the standard mathematical notation for an interval: https://en.wikipedia.org/wiki/Interval_%28mathematics%29#Notations_for_intervals[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
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)
-
(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.
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') ?
-
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') ?
-
Leslie Nelson[^] would like to have a word with you.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
Leslie Nelson[^] would like to have a word with you.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
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)
Klaus-Werner Konrad wrote:
It's one of the (Standard) notations,but not the Standard Notation !
He said MATHEMATICAL notation
If you think you can do a thing or think you can't do a thing, you're right - Henry Ford Emmanuel Medina Lopez
-
Klaus-Werner Konrad wrote:
It's one of the (Standard) notations,but not the Standard Notation !
He said MATHEMATICAL notation
If you think you can do a thing or think you can't do a thing, you're right - Henry Ford Emmanuel Medina Lopez
Emmanuel Medina Lopez wrote:
He said MATHEMATICAL notation
To be fair, I did say the standard mathematical notation. :-D
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Emmanuel Medina Lopez wrote:
He said MATHEMATICAL notation
To be fair, I did say the standard mathematical notation. :-D
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
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 ...
-
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') ?
I sometimes think it would be better if we remembered that we are talking about programming languages. Saying that std::vector has a range equal to [0,size()> or [begin(),end()> makes sense because we are talking about constructs that are used to specify computer programs, and personally I think it's a good idea to force the programmer to acknowledge that he/she is in fact creating a specification that will be used to generate a computer program.
Klaus-Werner Konrad wrote:
What is intuitive ?
What your accustomed to
Klaus-Werner Konrad wrote:
What is the natural thinking
I'm pretty sure your mind doesn't work exactly like mine, and even if we had the same idea we would express it differently. If I told you about my idea, your understanding of what I said would probably be something that would be slightly, or perhaps significantly, different from what I actually meant.
Klaus-Werner Konrad wrote:
against that indices 'MUST start with 0'
for i := 1 To 10: Will natural thinking give me 9 or 10 iterations? Natural thinking is ambiguous, and that is something we can't have in a programming language, and a very significant part of what goes on in the C++ committee is about clarifying and removing ambiguities from the specification. Having said that, it's fair to remind you that there is nothing that prevents you from creating a vector like container where you access all the elements like this:
sequence seq;
// add elements to the container
seq.add(1);
seq.add(2);
seq.add(3);
// and loop over the elements
for( int i = 1; i <= seq.count(); i++ )
{
int value = seq[i];
}I've worked with class libraries that did stuff like that back in the 90'ties, and personally I didn't find them intuitive at all - even if I'm pretty sure that the author did.
Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Projects promoting programming in "natural language" are intrinsically doomed to fail. Edsger W.Dijkstra
-
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:
if this Notation is (seen worlswide) really common
Maybe amongst mathemeticians, maybe not amongst bit-pushers.
Klaus-Werner Konrad wrote:
is just confusing
To me too.
Klaus-Werner Konrad wrote:
(FROM incl. x TO incl. Y)
X|
-
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.