Check if an element is in a sequence

407 Views Asked by At

My concern here is the mathematical symbols for sequences and sets.

For a sequence $S =(s_1,\cdots,s_n)$, is it correct to write $s_x \in S$ when I want to check if element $s_x$ is an element in the sequence $S$. Also, when adding a new element to a sequence, is it correct to write $S = S \cup s_x$

3

There are 3 best solutions below

0
On

Note that a sequence $\{s_n\}$ is a function whose domain is the set of natural numbers

$ s_n$ is the value assigned to $n$ If you add a term to the sequence you change the function so you have to define the new function.

Adding a new term to the sequence is fine as long as you redefine your sequence.

0
On

If you want to be absolutely correct, then to denote that $s$ is an element of the sequence $S=(s_1,\dots,s_n)$, you could write that there is an $i\in\{1,\dots,n\}$ such that $s=s_i$. I think $s\in S$ is a little bit weird, but not totally uncommon. Especially if you state what you mean by it, there should be no confusion. I would personally just say that $s$ is an element / coordinate of $S$.

For adding a new element to the sequence, as was mentioned in the comments, $S=S\cup s$ looks very wrong. As was also mentioned in the comments, it is not clear enough to say you want to add the value to the sequence: where do you want to place the new value?

If you mean extending the sequence by putting an extra value at the end, then there is a symbol for string concatenation, namely the "frown": $S^\frown T$. So you could write $S^\frown (s)$, or $S^\frown s$. It is probably also best to explain here what you mean by your notation instead of assuming everyone knows what you mean. The safest bet would be to write out explicitly what you mean.

If you want to place the new element somewhere in the middle, it is probably best to just define the new sequence as $(s_1,\dots,s_j,s,s_{j+1},\dots,s_n)$.

0
On

I know this is an old post, but I was doing something similar: I guess your reason of wanting to write someting like $S = S \cup s_x$ is partially because you do not want an index (a "traditional" one at the lower right of the indexed symbol) for $S$ to indicate change because you might have several sequences that you want to add to and you would use that for distinction. But I think it is a wrong notation as the 2 sides are not equal, and in math we should not write such a thing as in programming languages.
Here is a related answer of mine regarding sets. In case of sequences, we can define $v\in\mathbb{N}$ for the state, $S^0=()$ for the initial empty sequence, and the addition based on this and Vsotvep's answer and other sources online can be $$S^{v+1}=S^v\frown\left(s_x\right)$$
This way you can have several of these sequences all denoted by $S$, and having the above mentioned "traditional" index for distinction.