Isn't 'vector' a misnomer?

C

Carlo Milanesi

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'?
 
J

jeffc

Carlo Milanesi said:
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
 
E

Ekkehard Morgenstern

Hi Carlo Milanesi,

Carlo Milanesi said:
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.
 
E

E. Robert Tisdale

Carlo said:
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.
 
R

Rolf Magnus

E. Robert Tisdale said:
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 :)
 
X

Xenos

Carlo Milanesi said:
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'?


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.
 
M

Mike Wahler

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
 
E

E. Robert Tisdale

Xenos said:
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.
 
M

Mike Wahler

Rolf Magnus said:
Would the chemist say that or the astrologer? :)

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

-Mike
 
M

Micah Cowan

E. Robert Tisdale said:
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.
 
E

E. Robert Tisdale

Micah said:
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.
 
M

Micah Cowan

E. Robert Tisdale said:
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".

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. said:
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.
 
J

Jack Walker

jeffc said:
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
 
J

Jack Walker

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
 
N

Niklas Borson

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).
 
C

C Johnson

E. Robert Tisdale said:
Xenos said:
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
 
M

Mike Wahler

C Johnson said:
"E. Robert Tisdale" <[email protected]> wrote in message
Xenos said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top