Index notation
Adapted from Wikipedia · Discoverer experience
In mathematics and computer programming, index notation helps us point to specific numbers in a group or list. This is really useful when we have many numbers in a row, like when we talk about a list, a vector, or a matrix.
The way we use these indices, or positions, can change depending on what we are doing. If we are writing a math paper, we might use one style, but when we write a computer program, we use another. This helps everyone understand exactly which number we are talking about, making it easier to work with big groups of numbers.
Index notation is important because it makes it simpler to work with complex ideas in both math and computer science. Whether you’re solving equations or writing code, knowing how to use index notation helps you organize and find the exact number you need.
In mathematics
Main articles: Ricci calculus and Tensor
In math, we often use small numbers or letters below other numbers or letters to name parts of a group of numbers. These small numbers or letters are called "indices." They help us talk about groups of numbers called arrays, which can have one row (like a list), two rows and columns (like a grid), or even more rows and columns.
A simple group of numbers in a row is called a vector. For example, a vector might look like this: (10, 8, 9, 6, 3, 5). We can name each number in the vector using an index. So, the first number is a₁ (which is 10), the second is a₂ (which is 8), and so on.
We can also use indices for grids of numbers, which are called matrices. For example, a small grid might look like this:
Each number in this grid can be named using two indices. The number 9 is in the first row and first column, so we call it a₁₁. The number 8 is in the first row and second column, so we call it a₁₂, and so on.
Indices make it easier to work with these groups of numbers in equations. For example, if we have two vectors, a and b, and we want to add them to get a new vector c, we can write this as a simple equation using indices: aᵢ + bᵢ = cᵢ. This means that to get each number in c, we add the numbers in the same position from a and b.
Main article: Matrix (mathematics)
See also: Dyadics
Indices can also be used for more complex groups of numbers called tensors, which can have many rows and columns. In these cases, we might use more than two indices to name each number.
In computing
In many programming languages, index notation is a way to point to parts of an array. This method is used because it works like how computers handle memory in assembly language. The address of the first element is taken as a starting point, and a number (the index) multiplied by the size of each element helps find other elements in the array.
For example, if an array of whole numbers starts at memory address 3000, and each whole number takes up four bytes, the elements are found at addresses 3000, 3004, 3008, and so on. The address of the _i_th element in an array can be found using the base address and the size of each element.
Implementation details
In the C programming language, there are two ways to write the same thing: *(base + i) and base[i]. They mean the exact same thing because the rules of C say they are just different ways to write the same command.
When we have tables with more than one row and column, things get more interesting. There are three ways to handle these tables:
- We can flatten the table into a single line by calculating a single position from the two positions.
- We can think of the table as a line of smaller lines, where each smaller line is a row.
- We can keep extra information to remember where each row starts and treat each row as its own line.
In C, all three methods can be used. The first method lets the programmer decide how the table is stored in the computer's memory and provides the formulas to find each element. The second method is used when every row has the same number of elements, known when the program is written. The programmer declares the table, for example, with three columns, and refers to an element using two positions: tablename[first position][second position]. The computer figures out where each element is stored. The third method declares the table as a line of pointers and then uses these pointers to find the rows.
In other languages like Pascal, indices might start at 1 instead of 0. This can be handled by adjusting the memory location calculation to fit this starting point.
Related articles
This article is a child-friendly adaptation of the Wikipedia article on Index notation, available under CC BY-SA 4.0.
Safekipedia