5 ms·
An std::vector is a vector in the mathematical sense, though. It's a homogeneous tuple. It's just that using an std::vector of std::vectors to store a list of p
by fluoridation 4y ago
An std::vector is a vector in the mathematical sense, though. It's a homogeneous tuple. It's just that using an std::vector of std::vectors to store a list of points would be inefficient.
- xigoi 4y agoA vector can't change its size or contain things that aren't elements of a field. A std::vector can.
- fluoridation 4y agoYes, you can have a vector of, say, naturals. I'm pretty sure you can even create a vector field out of vectors of non-reals.
- Koshkin 4y agoA "vector field" and a "field" are two completely different notions. (And yes, you can build a field from integers.) https://en.wikipedia.org/wiki/Finite_field https://en.wikipedia.org/wiki/Finite_field
- fluoridation 4y agoMy bad. I meant to say "vector space", not "vector field". I understand the difference, but I often make this mistake because the set of a vector space is almost always the set of an algebraic field (i.e. the reals).
- xigoi 4y agoReally? What is the additive inverse of (1, 2, 3) ∈ ℕ³ ?
- fluoridation 4y agoIt depends on how you define addition.
- xigoi 4y agoI guess you could make it a vector space through a bijection with the rational numbers, but something tells me C++ programmers don't have that in mind when writing std::vector<unsigned>. And it doesn't solve the problem that C++ “vectors” are resizable.
- fluoridation 4y agoSee my comment above on the subject.
- Koshkin 4y ago(-1, -2, -3), is it not?
- yakubin 4y agoIt's not. Vectors can be added together and multiplied by scalars. That they are often represented as tuples of coefficients is just notation, doesn't matter for the notion of vectors, and vice versa: a tuple is not necessarily a vector. 1. std::vector doesn't have a fixed dimensionality, as would a mathematical vector. A fixed-length array actually makes more sense as a vector. 2. It doesn't provide the operations of addition and multiplication by scalars out-of-the-box (though you can whip up your own). Moreover, in general those operations wouldn't make sense for the elements which can be stored in a std::vector. E.g. neither multiplying bank account numbers by scalars, nor adding two bank account numbers make any sense. It would be good if you modelled them with types which don't allow those operations. Yet storing them in a std::vector makes perfect sense. But std::vector (or tuple) of bank account numbers is not a vector.
- Koshkin 4y agoWorse, they have been calling the location of a pointer to a subroutine that handles an interrupt a "vector" - the word which was originally used to refer to the entire set of such locations. (Curiously, this usage is similar to how the word "sector" is used to refer to a physical record on a disk - simply because it usually comes last in the coordinate triple (cylinder, track, sector). This would be like calling a point in the 3-dimensional space a "Z".)
- fluoridation 4y ago1. That doesn't make it not-a-vector. It just means there isn't a one-to-one correspondence between std::vector<T> and T^n. However, a particular instance x of std::vector<T> is still a T^x.size(). 2. Operations are not intrinsic to a set, but to an algebra. Why would there need to be any correspondence between the operations of linear algebra and those of banking algebra in order to call an std::vector a vector?
- yakubin 4y ago2. I'm not sure I understand you here. A vector is defined by those operations. A set without those operations, even if it has the same elements, is not a set of vectors anymore. I don't understand your remark about sets here. The correspondence is necessary, because those operations on vectors are induced from the operations of the relevant field of scalars. The operation of adding vectors of bank numbers would be induced from the operation of adding bank numbers, if there was any such thing. The operation of multiplying vectors by scalars (bank numbers in this case) would need to be induced from the operation of multiplication of bank numbers, if there was any such thing. Anyway, I think you got hung up on the example, when the point is you can have std::vectors of types for which those operations don't make any sense. Now, imagining that perhaps there hypothetically might exist some definitions of those operations, just to convince oneself that std::vector is a vector is really stretching it, and I'm not even sure at this point if you're not trolling. Anyway, as another commenter pointed out, Stepanov himself, who gave this container its name, said that it has nothing to do with vectors, and he wouldn't name it vector, if he could correct this mistake.
- Kranar 4y agoNo it's not and even Stepanov, the person who gave it its name, has admitted it was a mistake: Link to lecture by Stepanov: https://www.youtube.com/watch?v=etZgaSjzqlU https://www.youtube.com/watch?v=etZgaSjzqlU Furthermore in his book "From Mathematics to Generic Programming", Stepanov says that if he could change its name, he'd have named it "array".
- Koshkin 4y agoIndeed, "vector" appears to be relatively recent terminology, it has been "array" since the dawn of programming. But it's too late now, and we already have the std::array anyway...
- Banana699 4y ago>An std::vector is a vector in the mathematical sense No, because you can't prove that std::vector<T> obeys all vector space axioms[1] for all T, which is good because it's impossible, I can trivially define a T that will break any number of axioms and the cpp compiler will happily let me instantiate std::vector on it. [1] https://www.math.ucla.edu/~tao/resource/general/121.1.00s/vector_axioms.html https://www.math.ucla.edu/~tao/resource/general/121.1.00s/ve...