Isn't 'vector' a misnomer?

Discussion in 'C++' started by Carlo Milanesi, Nov 13, 2003.

  1. Mathematically speaking, a 'vector' is something you can add to another
    vector and multiply by a number. But in C++, the following code is
    illegal:

    std::vector<double> v1(3), v2(3);
    v1 + v2; // Illegal
    v1 * 2.; // Illegal

    In addition, vectors of different dimensions belong two different spaces
    (types). But in C++, the following code is legal:

    std::vector<double> v1(2), v2(3);
    v1 = v2; // Legal

    Why they were so dumb to call it 'vector', instead of, say, 'sequence'?

    --
    Carlo Milanesi
    http://digilander.libero.it/carlmila
     
    Carlo Milanesi, Nov 13, 2003
    #1
    1. Advertising

  2. Carlo Milanesi

    jeffc Guest

    "Carlo Milanesi" <> wrote in message
    news:...
    > Mathematically speaking, a 'vector' is something you can add to another
    > vector and multiply by a number. But in C++, the following code is
    > illegal:
    >
    > std::vector<double> v1(3), v2(3);
    > v1 + v2; // Illegal
    > v1 * 2.; // Illegal


    That's because C++ is a programming language, not mathematics.

    > In addition, vectors of different dimensions belong two different spaces
    > (types). But in C++, the following code is legal:
    >
    > std::vector<double> v1(2), v2(3);
    > v1 = v2; // Legal


    That says v1 = v2, not v1 == v2.

    > Why they were so dumb to call it 'vector', instead of, say, 'sequence'?


    Because they didn't have to adhere to predetermined meanings of words. What
    do you think "program" meant before computers were invented? See
    http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=vector&action=Search
     
    jeffc, Nov 13, 2003
    #2
    1. Advertising

  3. Hi Carlo Milanesi,

    "Carlo Milanesi" <> schrieb im Newsbeitrag
    news:...
    > Mathematically speaking, a 'vector' is something you can add to another
    > vector and multiply by a number. But in C++,


    The term is of historical origins. Since the BCPL programming language (the
    ancestor of C), arrays have been called "vectors". :)
    (perhaps b/c that's what they've been used for by the BCPL language inventor
    Martin Richards, or other people in the 1960ies or earlier even)

    I hope this helps.

    Regards,
    Ekkehard Morgenstern.
     
    Ekkehard Morgenstern, Nov 13, 2003
    #3
  4. Carlo Milanesi wrote:

    > Mathematically speaking, a 'vector' is something
    > that you can add to another vector and multiply by a number.
    > But in C++, the following code is illegal:
    >
    > std::vector<double> v1(3), v2(3);
    > v1 + v2; // Illegal
    > v1*2.0; // Illegal
    >
    > In addition, vectors of different dimensions belong two different spaces
    > (types). But in C++, the following code is legal:
    >
    > std::vector<double> v1(2), v2(3);
    > v1 = v2; // Legal
    >
    > Why they were so dumb to call it 'vector', instead of, say, 'sequence'?


    According to Bjarne Stroustrup,
    "The C++ Programming Language: Third Edition", Chapter 22: Numerics,
    Section 4: Vector Arithmetic, page 662:
    "One could argue that /valarray/ should have been called /vector/
    because it is a traditional mathematical vector
    and that /vector/ should have been called /array/."

    Evidently, Bjarne agrees with you.

    The standard vector class is actually a flexible [dynamic] array class.
    It probably isn't the best choice for vector arithmetic.
    If you want to use a standard C++ class template, use valarray.
     
    E. Robert Tisdale, Nov 14, 2003
    #4
  5. Carlo Milanesi

    Rolf Magnus Guest

    E. Robert Tisdale wrote:

    > According to Bjarne Stroustrup,
    > "The C++ Programming Language: Third Edition", Chapter 22: Numerics,
    > Section 4: Vector Arithmetic, page 662:
    > "One could argue that /valarray/ should have been called /vector/
    > because it is a traditional mathematical vector
    > and that /vector/ should have been called /array/."
    >
    > Evidently, Bjarne agrees with you.


    Well, he only said that "One could argue", not that he does :)
     
    Rolf Magnus, Nov 14, 2003
    #5
  6. Carlo Milanesi

    Rolf Magnus Guest

    Carlo Milanesi wrote:

    > Why they were so dumb to call it 'vector', instead of, say,
    > 'sequence'?


    'sequence' already has another meaning in C++.
     
    Rolf Magnus, Nov 14, 2003
    #6
  7. Carlo Milanesi

    Xenos Guest

    "Carlo Milanesi" <> wrote in message
    news:...
    > Mathematically speaking, a 'vector' is something you can add to another
    > vector and multiply by a number. But in C++, the following code is
    > illegal:
    >
    > std::vector<double> v1(3), v2(3);
    > v1 + v2; // Illegal
    > v1 * 2.; // Illegal
    >
    > In addition, vectors of different dimensions belong two different spaces
    > (types). But in C++, the following code is legal:
    >
    > std::vector<double> v1(2), v2(3);
    > v1 = v2; // Legal
    >
    > Why they were so dumb to call it 'vector', instead of, say, 'sequence'?
    >
    > --
    > Carlo Milanesi
    > http://digilander.libero.it/carlmila



    You could say that about a lot terms, such as functor. Different fields use
    the same terms for different things. Just ask a chemist and an astrologer
    (astrophysicist?) what "metal" means. You will get to different answers.
    Deal with it.
     
    Xenos, Nov 17, 2003
    #7
  8. Carlo Milanesi

    Mike Wahler Guest

    "Xenos" <> wrote in message
    news:bpbcvi$...

    > You could say that about a lot terms, such as functor. Different fields

    use
    > the same terms for different things. Just ask a chemist and an astrologer
    > (astrophysicist?) what "metal" means.


    It's a style of rock music. :)

    -Mike
     
    Mike Wahler, Nov 17, 2003
    #8
  9. Xenos wrote:

    > Carlo Milanesi wrote:
    >
    >>Mathematically speaking, a 'vector' is something you can add to another
    >>vector and multiply by a number. But in C++, the following code is
    >>illegal:
    >>
    >>std::vector<double> v1(3), v2(3);
    >>v1 + v2; // Illegal
    >>v1 * 2.; // Illegal
    >>
    >>In addition, vectors of different dimensions belong two different spaces
    >>(types). But in C++, the following code is legal:
    >>
    >>std::vector<double> v1(2), v2(3);
    >>v1 = v2; // Legal
    >>
    >>Why they were so dumb to call it 'vector', instead of, say, 'sequence'?
    >>
    >>--
    >>Carlo Milanesi
    >>http://digilander.libero.it/carlmila

    >
    >
    > You could say that about a lot terms, such as functor.
    > Different fields use the same terms for different things.


    No. It *is* a misnomer.
    It doesn't fit in with the jargon of *any* discipline.
    Deal with it.
     
    E. Robert Tisdale, Nov 17, 2003
    #9
  10. Carlo Milanesi

    Rolf Magnus Guest

    Mike Wahler wrote:

    >
    > "Xenos" <> wrote in message
    > news:bpbcvi$...
    >
    >> You could say that about a lot terms, such as functor. Different
    >> fields

    > use
    >> the same terms for different things. Just ask a chemist and an
    >> astrologer (astrophysicist?) what "metal" means.

    >
    > It's a style of rock music. :)


    Would the chemist say that or the astrologer? :)
     
    Rolf Magnus, Nov 17, 2003
    #10
  11. Carlo Milanesi

    Mike Wahler Guest

    "Rolf Magnus" <> wrote in message
    news:bpbfjq$b2j$05$-online.com...
    > Mike Wahler wrote:
    >
    > >
    > > "Xenos" <> wrote in message
    > > news:bpbcvi$...
    > >
    > >> You could say that about a lot terms, such as functor. Different
    > >> fields

    > > use
    > >> the same terms for different things. Just ask a chemist and an
    > >> astrologer (astrophysicist?) what "metal" means.

    > >
    > > It's a style of rock music. :)

    >
    > Would the chemist say that or the astrologer? :)


    An astrochemist. You know, the ones that make
    'out-of-this-world' recreational substances. :)

    -Mike
     
    Mike Wahler, Nov 18, 2003
    #11
  12. Carlo Milanesi

    Micah Cowan Guest

    "E. Robert Tisdale" <> writes:

    > Xenos wrote:
    >
    > > Carlo Milanesi wrote:
    > >
    > >>Mathematically speaking, a 'vector' is something you can add to another
    > >>vector and multiply by a number. But in C++, the following code is
    > >>illegal:
    > >>
    > >>std::vector<double> v1(3), v2(3);
    > >>v1 + v2; // Illegal
    > >>v1 * 2.; // Illegal
    > >>
    > >>In addition, vectors of different dimensions belong two different spaces
    > >>(types). But in C++, the following code is legal:
    > >>
    > >>std::vector<double> v1(2), v2(3);
    > >>v1 = v2; // Legal
    > >>
    > >>Why they were so dumb to call it 'vector', instead of, say, 'sequence'?
    > >>
    > >>--
    > >>Carlo Milanesi
    > >>http://digilander.libero.it/carlmila

    > > You could say that about a lot terms, such as functor.
    > > Different fields use the same terms for different things.

    >
    > No. It *is* a misnomer.
    > It doesn't fit in with the jargon of *any* discipline.
    > Deal with it.


    The term 'vector' has been used for quite some time (long before
    C++) in Computer Science to refer to what is also frequently
    referred to as an array. You will find it in many good, older CS
    textbooks. No idea where this usage originated, but it is
    definitely precedented, and seems quite appropriate, given that
    the term "array" is already in use for something else.

    Also, the term "sequence" is used in C++ to refer to a
    group of containers that include the list, queue, deque, and
    other classes. "Sequence" would be far to general to be an
    appropriate term for this beast, at any rate.

    --
    Micah J. Cowan
     
    Micah Cowan, Nov 18, 2003
    #12
  13. Micah Cowan wrote:

    > The term 'vector' has been used for quite some time
    > (long before C++) in Computer Science
    > to refer to what is also frequently referred to as an array.


    No. A vector is an array of *numbers*.

    > You will find it in many good, older CS textbooks.


    Please cite and quote one of these older CS textbooks.

    > I have no idea where this usage originated


    Probably with Fortran which, until Fortran 90,
    had no notion of vectors so Fortran programmers
    were forced to *improvise* with arrays of numbers
    and *pretend* that they were vectors.
    Until Fortran 90 and the introduction of derived types,
    arrays were always arrays of numbers (or characters).
    Note that vector arithmetic operations *are* defined
    on Fortran 90/95/00 arrays of numbers
    so they really are vectors now but Fortran programmers
    still use the term "array" to describe them.

    > but there is definitely a precedent
    > and it seems quite appropriate, given that
    > the term "array" is already in use for something else.


    Check out
    The American Heritage Dictionary of the English Language

    http://www.bartleby.com/61/

    array
    5. Computer Science An arrangement of memory elements
    in one or more planes.

    vector
    1. Mathematics a. A quantity, such as velocity,
    completely specified by a magnitude and a direction.
    b. A one-dimensional array. c. An element of a vector space.

    In computer science, an array is
    an array of memory elements of *any* type.
    A vector, on the other hand, is and array of numbers --
    a numerical quantity upon which the operations
    of vector arithmetic are defined.
    This definition does *not* apply
    to the standard vector class template.

    The word "array" is *not* a reserved keyword
    in the C++ computer programming language
    or in the standard C++ library.

    > Also, the term "sequence" is used in C++ to refer to a
    > group of containers that include the list, queue, deque, and
    > other classes. "Sequence" would be far to general to be an
    > appropriate term for this beast, at any rate.


    I don't think sequence is a good name
    for any standard C++ container class [template].

    Sometimes programmers choose names for new types unwisely.
    In the case of the standard vector class template,
    this was an unfortunate mistake that we are stuck with.
    Don't look for any wisdom in this choice
    because there simply isn't any.
     
    E. Robert Tisdale, Nov 18, 2003
    #13
  14. Carlo Milanesi

    jeffc Guest

    "Mike Wahler" <> wrote in message
    news:ensub.4848$...
    >
    > An astrochemist. You know, the ones that make
    > 'out-of-this-world' recreational substances. :)


    You're thinking of a cosmetologist.
     
    jeffc, Nov 18, 2003
    #14
  15. Carlo Milanesi

    Micah Cowan Guest

    "E. Robert Tisdale" <> writes:

    > Micah Cowan wrote:
    >
    > > The term 'vector' has been used for quite some time
    > > (long before C++) in Computer Science
    > > to refer to what is also frequently referred to as an array.

    >
    > No. A vector is an array of *numbers*.


    There is absolutely no reason to restrict it to numbers in CS,
    nor have I ever seen this restriction in practice. In fact,
    Scheme calls its general-purpose array type "vector". The
    following search on google turns up scads of non-C++ usages of
    the term "vector" in exactly the way I asserted it is used, in
    addition to usages of its mathematical meaning of course:

    http://www.google.com/search?q="vector of" -C++ programming

    Among these is a reference to Scheme, and a reference from a csh
    manual stating that all local variables are "vectors of strings".

    <snip>

    > Check out
    > The American Heritage Dictionary of the English Language
    >
    > http://www.bartleby.com/61/
    >
    > array
    > 5. Computer Science An arrangement of memory elements
    > in one or more planes.
    >
    > vector
    > 1. Mathematics a. A quantity, such as velocity,
    > completely specified by a magnitude and a direction.
    > b. A one-dimensional array. c. An element of a vector space.


    1b fits my definition. As does FOLDOC's definition:

    4. <programming> A one-dimensional {array}.

    > In computer science, an array is
    > an array of memory elements of *any* type.
    > A vector, on the other hand, is and array of numbers --
    > a numerical quantity upon which the operations
    > of vector arithmetic are defined.


    In Math. Not in CS. I have almost never seen the term "vector"
    used in CS to actually refer to anything having to do with vector
    arithmetic, unless the problem currently being solved actually
    had to do with vector math.

    > The word "array" is *not* a reserved keyword
    > in the C++ computer programming language
    > or in the standard C++ library.


    I didn't say it was. However, it is a word reserved for an
    entirely different usage in both the C++ Standard and in C and
    C++ terminology.

    > > Also, the term "sequence" is used in C++ to refer to a
    > > group of containers that include the list, queue, deque, and
    > > other classes. "Sequence" would be far to general to be an
    > > appropriate term for this beast, at any rate.

    >
    > I don't think sequence is a good name
    > for any standard C++ container class [template].


    I didn't say you did. That statement was directed at Carlo.

    > Sometimes programmers choose names for new types unwisely.
    > In the case of the standard vector class template,
    > this was an unfortunate mistake that we are stuck with.
    > Don't look for any wisdom in this choice
    > because there simply isn't any.


    It still fits in quite nicely with the usage in which I have seen
    it.

    --
    Micah J. Cowan
     
    Micah Cowan, Nov 21, 2003
    #15
  16. Carlo Milanesi

    Jack Walker Guest

    "jeffc" <> wrote in message news:<>...
    > "Mike Wahler" <> wrote in message
    > news:ensub.4848$...
    > >
    > > An astrochemist. You know, the ones that make
    > > 'out-of-this-world' recreational substances. :)

    >
    > You're thinking of a cosmetologist.

    Um, a cosmetologist is someone who applies women's make up
    (cosmetics). I hope you meant cosmologist.

    Jack Walker
     
    Jack Walker, Nov 21, 2003
    #16
  17. Carlo Milanesi

    Jack Walker Guest

    Micah Cowan <> wrote in message news:<>...

    Sometimes computer programmers have a narrow world view and an
    inflated sense of importance and do not consider established meanings
    of words that they adopt for program element names.

    On the otherhand as a mathematician I know that a vector space is an
    ordered quadruple consisting of a set of elements called vectors, a
    set of elements called scalers, and the operations vector addition and
    scaler multiplication. The vectors can be anything you can concieve
    of for which you can define the other 3 components. The set of
    continously differentable functions is an infinite dimensional vector
    space with the complex numbers as scalers. STL vectors do not define
    scalers, scaler multiplication, nor vector addition so as far as I am
    concerned they are not vectors.

    However this a minor flaw and given all of the other advantages of the
    STL it can be overlooked.

    Jack Walker
     
    Jack Walker, Nov 21, 2003
    #17
  18. Perhaps you're both right. Mr. Tisdale makes an interesting point
    about the origin of this usage, i.e., that in Fortran 90 arrays
    were used to *implement* the mathematical concept of a vector. It
    seems plausible to me that people conflated the implementation of
    the concept with the concept itself, leading to the widespread
    use of the term 'vector' to mean 'any one-dimensional array'.
    Thus, one could argue that this usage of 'vector' originated in
    a misunderstanding.

    On the other hand, it is also clear that this usage of the term
    long predates the C++ standard, and has long been widespread
    within the computer science community as a whole. Thus, the C++
    standard and STL merely follow a usage that (while perhaps
    originating in error) is quite normal in Computer Science.

    I would compare this with the way dictionaries work. Consider a
    word like "nauseous". Both Webster and the American Heritage
    provide two definitions of this word. The second usage was once
    considered "wrong", but has since been accepted as correct by
    both dictionaries.

    http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=nauseous
    http://www.bartleby.com/61/32/N0033200.html

    Dictionaries are both prescriptive and descriptive. They tend
    to reinforce "normal" usage (prescriptive) but also adapt (with
    some latency) as the norm changes over time (descriptive).
     
    Niklas Borson, Nov 21, 2003
    #18
  19. Carlo Milanesi

    C Johnson Guest

    "E. Robert Tisdale" <> wrote in message news:<>...
    > Xenos wrote:
    >
    > > Carlo Milanesi wrote:

    [snip]
    > > You could say that about a lot terms, such as functor.
    > > Different fields use the same terms for different things.

    >
    > No. It *is* a misnomer.
    > It doesn't fit in with the jargon of *any* discipline.
    > Deal with it.


    Wouldn't namespaces and typedef(s) make this issue trivial?

    As an aside, classes and operator overloading give the ability for you
    to create any type you wish and name it anything you *feel* is
    appropriate and operate with expected behavior from which the objects
    domain is modeled under, correct? Combine this with the above
    satement and this issue is beyond irrelevant and extremely easy to
    "deal with it", right?

    Not trolling - just curious if I have been applying what I know of the
    language correctly on both technical and "moral" principles such as
    this.

    -Chris
     
    C Johnson, Nov 21, 2003
    #19
  20. Carlo Milanesi

    Mike Wahler Guest

    "C Johnson" <> wrote in message
    news:...
    > "E. Robert Tisdale" <> wrote in message

    news:<>...
    > > Xenos wrote:
    > >
    > > > Carlo Milanesi wrote:

    > [snip]
    > > > You could say that about a lot terms, such as functor.
    > > > Different fields use the same terms for different things.

    > >
    > > No. It *is* a misnomer.
    > > It doesn't fit in with the jargon of *any* discipline.
    > > Deal with it.

    >
    > Wouldn't namespaces and typedef(s) make this issue trivial?
    >
    > As an aside, classes and operator overloading give the ability for you
    > to create any type you wish and name it anything you *feel* is
    > appropriate and operate with expected behavior from which the objects


    > domain is modeled under, correct? Combine this with the above

    ^^^^^^

    That's the key issue here, imo.

    > satement and this issue is beyond irrelevant and extremely easy to
    > "deal with it", right?
    >
    > Not trolling - just curious if I have been applying what I know of the
    > language correctly on both technical and "moral" principles such as
    > this.
    >
    > -Chris


    You make good points. For example, the term 'window' is often
    used to refer to a rectangular section of a video display.
    It's not really a 'window' but the term 'window' is used
    as a metaphor. Another common metaphor is the MS-Windows
    'desktop'. Robert ignores context.

    -Mike
     
    Mike Wahler, Nov 21, 2003
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pmatos
    Replies:
    6
    Views:
    24,135
  2. Ben Finney
    Replies:
    2
    Views:
    450
    Peter Hansen
    Jul 12, 2003
  3. Tim Peters
    Replies:
    2
    Views:
    1,101
    Ben Finney
    Jul 13, 2003
  4. Replies:
    8
    Views:
    2,006
    Csaba
    Feb 18, 2006
  5. Replies:
    6
    Views:
    481
    John Scheldroup
    Nov 29, 2007
Loading...

Share This Page