2

Suppose some kind of structure to hold a (finite) number of elements is needed. The order of the elements matters and duplicate elements are allowed. When programming one would use a one-dimensional array for this.

What mathematical structure comes closest to such a one-dimensional array as seen in programming? I've seen both row and column vectors being used for this purpose, but it seems that a sequence would do as well. Is there any reason to choose one over the other or to choose an entirely other structure?

wevoda
  • 23
  • 4

1 Answers1

5

A vector is the wrong object to consider. While vectors (in $\mathbb{R}^d$) can be represented as ordered lists, calling something a vector implies that it comes from a space with a great deal more structure. Specifically, vectors can be added together, and can be scaled by field elements (in the case of vectors in $\mathbb{R}^n$, you can multiply a vector by a real number).

A closer analogy would be a sequence (if your array has infinite length, or if you are willing to pad it by zero) or an $n$-tuple (if your arrays are all of the same length $n$). Either of these objects may be thought of as a function from (a subset of) the natural numbers $\mathbb{N}$ to the appropriate set (e.g. the set of floating point numbers, the set of integers, the set of real numbers, etc).

For example, the array

 float array[5] = {3.14, 0.60309, 2.7183, 2, 1.618}

could be written as a $5$-tuple $$ (3.14, 0.60309, 2.7183, 2.0, 1.612), $$ which can be thought of as a function $ a : \{0,1,2,3,4\} \to (\text{Set of Floats})$ defined by $$ \begin{cases} 3.14 & \text{if $x=0$,} \\ 0.60309 & \text{if $x=1$,} \\ 2.7183 & \text{if $x=2$,} \\ 2.0 & \text{if $x=3$, and} \\ 1.612 & \text{if $x=4$.} \end{cases}$$ That is (for example) $a(2) = 2.7182$.

As rschwieb noted in a comment below, this last way of looking at a tuple or array is likely the most relevant for software engineers: one passes an index to the array, and gets back the value of the array element stored at that index. This is equivalent to evaluating the function at that index.