14
$\begingroup$

I would like to write mathematically, if possible, the following statement:

Given a vector $x=[1,4,5,3]$ and an integer $j=3$, find the position of $j$ in $x$?

How to write this mathematically?

If I am looking for the position of the minimum value in $x$, I would achieve this by $\arg\min x$.

I guess $j^*=\operatorname{arg\,find} (x=j)$ but $\LaTeX$ does not recognize this.

$\endgroup$
  • $\begingroup$ @Masacroso Or rather a comparison against each possible unidimensional projection in the original vector's coordinate system. $\endgroup$ – Kyle Strand Mar 30 '16 at 16:52
  • 3
    $\begingroup$ Us programmers would usually call it indexOf, if that helps. $\endgroup$ – OrangeDog Mar 30 '16 at 17:50
  • 2
    $\begingroup$ @OrangeDog How does that help? I see no programming here. $\endgroup$ – David Richerby Apr 1 '16 at 0:24
  • $\begingroup$ I think in math you want to use the term '(finite) sequence' rather than 'vector'. (I doubt there's a standard mathematical notation for this, though, as I suspect it's a DP concept). $\endgroup$ – Jonathan Cast Apr 1 '16 at 15:26

10 Answers 10

22
$\begingroup$

Usually this is written as "Let $i$ be such that $x_i = j$." But that's not very compact. There isn't any standard notation for this that I know of. You could use $\arg \max_i [x_i = j ]$ which uses Iverson brackets to make things compact.

$\endgroup$
  • 31
    $\begingroup$ That's a funny abuse of argmax, although I would say unreadable, the text version is much better. $\endgroup$ – dtldarek Mar 30 '16 at 6:35
  • 6
    $\begingroup$ One could instead use ​ max({i : x$_i$ = j}) ​ or ​ min({i : x$_i$ = j}) . ​ ​ ​ ​ $\endgroup$ – user57159 Mar 30 '16 at 21:48
  • $\begingroup$ Isn't that just "Einstein notation"? en.wikipedia.org/wiki/Einstein_notation $\endgroup$ – Aron Mar 31 '16 at 4:59
21
$\begingroup$

If you want to talk about the $3$ in the vector $x=(1,2,3)$ then most people will just denote this element $x_3$ to indicate the third element of the vector.

If you are interested in the function that maps $x\to x_3$ then that function is denoted $\pi_3(x)$ and is called "the projection function (onto the third coordinate)". This function is pretty important in topology.

If you are interested in the function that tells you what index $k$ is, there isn't really a common notation for that because it's not necessarily a function. Besides, even when talking about it as a relation, in almost all circumstances if you know that $x$ contains a $3$, you can also just know which indices are $3$ and which are not as a consequences of knowing what x is

$\endgroup$
  • 9
    $\begingroup$ It's not just "not a commonly used function", it isn't necessarily a function at all. For the vector $x = (3,2,3)$ this could return 1 or 3. You need to define it more to get a sensible result. $\endgroup$ – Lacklub Mar 30 '16 at 17:17
  • $\begingroup$ @Lacklub changed my comment there, thanks. $\endgroup$ – Stella Biderman Mar 30 '16 at 19:51
  • 1
    $\begingroup$ Actually, that is a very common (and important) "function" (correspondence) in computer science. We call it which. $\endgroup$ – MichaelChirico Mar 30 '16 at 23:04
18
$\begingroup$

If you consider the vector $x$ as a function from $[1, n]$ to $\mathbb{N}$, you can use the inverse $x^{-1}$. See https://en.wikipedia.org/wiki/Inverse_function#Preimages.

In your example, if $x=(1,4,5,3)$ then $x^{-1} (\lbrace 3 \rbrace) = \lbrace 4 \rbrace$.

As Jonathan Gafar remarked, the inverse set might contain more than one element. Then you can use a minimum to get the first one.

For example, if $x=(1,2,5,7,2)$ then $x^{-1} (\lbrace 2\rbrace)= \lbrace 2, 5 \rbrace$ and $\min x^{-1} (\lbrace 2\rbrace) = 2$.

However, I don't recommend to use this notation without a proper introduction or definition, since the inverse symbol might be ambiguous.

$\endgroup$
  • 5
    $\begingroup$ The inverse set can also be empty, so remember to handle or rule out that possibility before applying $\min$. $\endgroup$ – filipos Mar 30 '16 at 13:06
  • $\begingroup$ the minimum of an empty set is usually defined to be +infinity, so that should not be a problem. But you are right that you should not assume that you get a sensible index back, as the element may not have any pre-images. $\endgroup$ – hkBst Apr 1 '16 at 9:57
15
$\begingroup$

In my opinion you should use plain text or perhaps define such a function yourself if you need it frequently. Of course, if you have plain-text definition, you can still add a formula, if you feel that it will help the potential reader.

We define $\operatorname{arg\,find}(v,\alpha)$ to be the index of the first occurence of $\alpha$ in $v$ or to be equal to $\operatorname{length}(v)+1$ if there is no such index. $$\operatorname{arg\,find}(v,\alpha)=\min\{i \in \mathbb{N}^+\mid i>\operatorname{length}(v)\lor v_i=\alpha\}$$ where $v_i$ denotes the $i$-th coordinate of the vector $v$.

I hope this helps $\ddot\smile$

$\endgroup$
  • 2
    $\begingroup$ I like the use of the one-past-the-last index to indicate that the vector does not contain the specified value. $\endgroup$ – Kyle Strand Mar 30 '16 at 16:55
  • $\begingroup$ Then it should be ${\rm arg\,first}(v,\alpha)$ $\endgroup$ – ja72 Mar 31 '16 at 17:01
14
$\begingroup$

A function $f$, to find the position of an integer $j$, within in a vector $x$ (of size $n$).

In the case that the integer $j$, may only occur once in the vector $x$:

The desired function can be composed of a sum $\sum$, and the delta function $\delta$.

Where the delta function is defined as $\quad\delta(a) := \begin{cases}0&a\neq0\\1&a=0\end{cases}$

$$f(x,j) = \sum_{i=1}^ni\delta(x_i-j)$$ (If zero is returned from this function, the vector does not include an element equal to $j$)

$$x=[1,4,5,3], \quad j =3$$

$$f\big([1,4,5,3], 3\big) = 1\delta(x_1-3) + 2\delta(x_2-3) + 3\delta(x_3-3)+ 4\delta(x_4-3)$$ $$=1(0)+2(0)+3(0)+4(1)$$ $$=4$$


In the case that the integer $j$, may occur more than once, and all occurrences are to be found (as a set):

The desired function can be composed of a union $\cup$, and the delta function $\delta$.

$$f(x,j) = \bigcup_{i=1}^ni\delta(x_i-j)\setminus 0$$ (If the empty set is returned from this function, $x$ does not include the element $j$)

$$x = [3,4,5,3], \quad j = 3$$

$$f\big([3,4,5,3], 3\big) = 1\delta(x_1-3) \cup 2\delta(x_2-3) \cup 3\delta(x_3-3) \cup 4\delta(x_4-3)\setminus 0$$ $$= 1(1)\cup2(0)\cup3(0)\cup4(1)\setminus 0$$ $$= \{1,0,4\}\setminus 0$$ $$= \{1,4\}$$

$\endgroup$
  • 12
    $\begingroup$ A perfect way to obscure your intention! $\endgroup$ – dtldarek Mar 30 '16 at 8:47
  • $\begingroup$ Very nice and clever solution, if not obfuscated. ;) $\endgroup$ – Conor O'Brien Mar 30 '16 at 13:50
  • 1
    $\begingroup$ Clever and neat, but gives... interesting results when the value occurs more than once (ie. gives the sum of indices). +1 for returning 0 when no match exists $\endgroup$ – Lacklub Mar 30 '16 at 17:24
11
$\begingroup$

So what you mean is, given some argument, return the component of the vector which contains that argument? So if $x = (1,3,4,2,6)$, then you would ask to find the position of $4$, and the result would be the third component of $x$?

Note that such a function would not be well-defined (if defined on all $n$-tuples). For example, if $x = (1,2,5,7,2)$, and you asked to find the position of $2$, then would the function return the second component or the fifth component? You would have to make a choice.

$\endgroup$
  • 5
    $\begingroup$ it is also not defined if the vector does not contain the value of course $\endgroup$ – jk. Mar 30 '16 at 10:20
11
$\begingroup$

Your question can be understood at least 2 ways.

(1) : you want a way to write this. I would suggest, given that there may be several such indices,

$$\{i : x_i=j\}.$$

If you can assume there is only one, then just let $i : x_i=j$.

(2) : you want to define a new notation. Everything is possible, one could for instance define a position function:

$$\text{pos}(j,x):=\min\{i : x_i=j\}.$$

$\endgroup$
  • 1
    $\begingroup$ +1 this is the proper answer. $\endgroup$ – Mehrdad Mar 31 '16 at 8:08
7
$\begingroup$

If you tell the reader to think of $x$ as a function, you can denote this $x^{-1}(j).$

More explicitly, let $\underline{4} = \{0,1,2,3\}$. Tell the reader to think of $x$ as a function $x : \underline{4} \rightarrow \mathbb{Z}$. Then the set of all $i \in \underline{4}$ satisfying $x(i) = j$ is denoted $x^{-1}(j)$.

$\endgroup$
3
$\begingroup$

Vector dot products do this. If you want the second element of a vector $X$, then $X \cdot \langle0, 1, 0, 0, 0\rangle $will give you that component if $X$ is a five-dimensional vector.

$\endgroup$
  • 5
    $\begingroup$ That isn't what the question is asking for. We're not trying to find the value in a particular position, but the position of a particular value. $\endgroup$ – Nate Eldredge Mar 31 '16 at 3:21
0
$\begingroup$

You could write code that does this, if you'll consider that a "mathematical function."

Write a $for$ loop which iterates over the elements of the array, checking if the position at the loop index is the same as the element you want to find. If you find an element where there is a match, break out of your loop. If not, return that no such element exists in the array.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.