Math symbols on vectors e.g item in, item not in, for all

81 Views Asked by At

I have a vector s= <1,2,3> and I want to perform various operations on it like these ones:

check if an item x exists in s,

x not in s,

a for all i in s where i is the item.

What is the correct math symbols for doing this on a vector? This is perhaps an unconventional way of utilizing vectors. Note that set notation can't be used for my application as I am highly dependent on an ordered s.

3

There are 3 best solutions below

0
On BEST ANSWER

Viewing a (coordinate) vector as a map from an index set to the set of reals (or whatever), "$x$ is a component of $s$" is the same as saying that $x$ is in the image of that map ...

And unless you are also doing something really vector-ish with them, I'd prefer to call $s$ a finite sequence of reals.

0
On

It is indeed unconventional to use vectors in this way. I think it's safe to say that if you want to do something like check for an "element of a vector", you should invent the appropriate notation (perhaps by overloading the set-theoretic $\in$) and explain what you mean.

0
On

In terms of coding like c++, (I'm not overly familiar) but it seems you can use

std::find(std::begin(s), std::end(s), x);

or

std::find(s.begin(), s.end(), x)

to find $x$ in the vector s

This comes from the following in the order above.

http://en.cppreference.com/w/cpp/algorithm/find

https://stackoverflow.com/questions/3450860/check-if-a-stdvector-contains-a-certain-object

Otherwise in general linear algebra a vector $s=\langle 1,2 ,3 \rangle$ has those components or co-ordinates with respect to some basis. If this basis is $\{e_1,e_2,e_3\}$, and ordered basis if you like, one can write a vector $s=\langle s_1,s_2,s_3 \rangle=s_1 e_1+s_2 e_2+s_3 e_3$.

You can define projections $P_1,P_2,P_3$, such that $P_i(s)=s_i$ which just gives the co-ordinate $i$ or coefficient of $e_i$.

In this case you could ask

Is $P_i(s)=x$ for some $i=1,2,3$

but I think this might be overkill for the application to c++.

Hope this is helpful!