Index notation
In mathematics and computer programming, index notation is used to specify the elements of an array of numbers. The formalism of how indices are used varies according to the subject. In particular, there are different methods for referring to the elements of a list, a vector, or a matrix, depending on whether one is writing a formal mathematical paper for publication, or when one is writing a computer program.
In mathematics
It is frequently helpful in mathematics to refer to the elements of an array using subscripts. The subscripts can be integers or variables. The array takes the form of tensors in general, since these can be treated as multi-dimensional arrays. Special cases are vectors and matrices.The following is only an introduction to the concept: index notation is used in more detail in mathematics. See the main article for further details.
One-dimensional arrays (vectors)
A vector treated as an array of numbers by writing as a row vector or column vector :Index notation allows indication of the elements of the array by simply writing ai, where the index i is known to run from 1 to n, because of n-dimensions.
For example, given the vector:
then some entries are
The notation can be applied to vectors in mathematics and physics. The following vector equation
can also be written in terms of the elements of the vector, that is
where the indices take a given range of values. This expression represents a set of equations, one for each index. If the vectors each have n elements, meaning i = 1,2,…n, then the equations are explicitly
Hence, index notation serves as an efficient shorthand for
- representing the general structure to an equation,
- while applicable to individual components.
Two-dimensional arrays
The entry of a matrix A is written using two indices, say i and j, with or without commas to separate the indices: aij or ai,j, where the first subscript is the row number and the second is the column number. Juxtaposition is also used as notation for multiplication; this may be a source of confusion. For example, if
then some entries are
For indices larger than 9, the comma-based notation may be preferable.
Matrix equations are written similarly to vector equations, such as
in terms of the elements of the matrices
for all values of i and j. Again this expression represents a set of equations, one for each index. If the matrices each have m rows and n columns, meaning and, then there are mn equations.
Multi-dimensional arrays
The notation allows a clear generalization to multi-dimensional arrays of elements: tensors. For example,representing a set of many equations.
In tensor analysis, superscripts are used instead of subscripts to distinguish covariant from contravariant entities, see covariance and contravariance of vectors and raising and lowering indices.
In computing
In several programming languages, index notation is a way of addressing elements of an array. This method is used since it is closest to how it is implemented in assembly language whereby the address of the first element is used as a base, and a multiple of the element size is used to address inside the array.For example, if an array of integers is stored in a region of the computer's memory starting at the memory cell with address 3000, and each integer occupies four cells, then the elements of this array are at memory locations 0x3000, 0x3004, 0x3008, …, 0x3000 + 4. In general, the address of the ith element of an array with base address b and element size s is.
Implementation details
In the C programming language, we can write the above as or , which is exactly equivalent because the C standard defines the array indexing form as a transformation to pointer form. Coincidentally, since pointer addition is commutative, this allows for obscure expressions such as which is equivalent to.Multidimensional arrays
Things become more interesting when we consider arrays with more than one index, for example, a two-dimensional table. We have three possibilities:- make the two-dimensional array one-dimensional by computing a single index from the two
- consider a one-dimensional array where each element is another one-dimensional array, i.e. an array of arrays
- use additional storage to hold the array of addresses of each row of the original array, and store the rows of the original array as separate one-dimensional arrays
void mult3x3f