8
$\begingroup$

Do matrices in linear algebra support an operation of indexing them analogous to array indexing?

For example:

$$ A = \left [\begin{array}{cc} 1 & 2 \\ 3 & 4 \end{array}\right] $$

In C, a fixed 2 by 2 array in 32 bit integer space could be described as:

int32_t A[][2] = {
    {1, 2}, 
    {3, 4}
};

and allows operations like:

A[0][0] = 2;

Is there a universally accepted equivalent to such an operation in linear algebra?

I understand that a Matrix is not a C Array equivalent, but I am curious whether such an operation is supported.

$\endgroup$
  • 6
    $\begingroup$ It's really not clear to me what you mean. Often one will write the $(i, j)$ entry of a matrix $A$ as $A_{ij}$ or $a_{ij}$. $\endgroup$ – Travis May 11 '16 at 12:26
  • $\begingroup$ I mean is there a non naive, universally accepted way to denote mutation/accessing of an element within a matrix. A universally "correct" way to denote such an operation. $\endgroup$ – Dmitry May 11 '16 at 12:27
  • 1
    $\begingroup$ The notation $A_{ij}$ "accesses" the element, but if you're referring to the operation that takes a matrix $A$, indices $i, j$ and a value $b$ and returns the matrix $A'$ whose entries are $A'_{kl} = A_{kl}$ for $(k, l) \neq (i, j)$ and $A'_{ij} = b$, then no, there is no widely familiar notation for this. Of course, you can always define such a notation and explain it yourself. $\endgroup$ – Travis May 11 '16 at 12:43
  • $\begingroup$ I think the title of this question should be modified to make clear that the question is about a notation for modifying a matrix entry. $\endgroup$ – Marc van Leeuwen May 12 '16 at 8:32
  • $\begingroup$ @MarcvanLeeuwen indexing/mutating. But from the responses I got so far, it appears a matrix is not a mutable construct, and instead new matrices must be created via transformation or reinitialization, so asking how to modify a matrix seems misleading. $\endgroup$ – Dmitry May 13 '16 at 16:40
26
$\begingroup$

$A_{ij}$ is a common notation for the $(i,j)$th entry of a matrix $A$.

$i$ specifies the row, $j$ specifies the column, and the indexes start with $1$, rather than $0$.

So if $A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}$, then $A_{11} = 1$, $A_{12} = 2$, $A_{21} = 3$, and $A_{22} = 4$.

$\endgroup$
  • $\begingroup$ A standard matrix is always row major then, right? $\endgroup$ – Dmitry May 11 '16 at 12:40
  • $\begingroup$ In the usual notation, the first index specifies the row. Is that what you mean by "row major"? $\endgroup$ – Omnomnomnom May 11 '16 at 15:35
  • $\begingroup$ @Dmitry Yes, it's row major order. $\endgroup$ – DylanSp May 11 '16 at 16:45
  • 12
    $\begingroup$ @Dmitry: I think you've misunderstood the term "row major". Row-major order has to do with the order in computer memory or storage -- whether the elements in the same row are always adjacent, vs. whether the elements in the same column are. In math, there's nothing analogous to that. $\endgroup$ – ruakh May 11 '16 at 20:31
  • 1
    $\begingroup$ @Dmitry: Again, nonsense. There are plenty of languages that use column-major order, including some of the earliest languages (e.g. Fortran). That's why the terms "row major" and "column major" even exist. But they all use the normal math notation, with the row index preceding the column index. (If they didn't, then there would actually be no difference between row-major and column-major orders: if you flip the notation and the storage, then the two flips cancel each other out.) $\endgroup$ – ruakh May 13 '16 at 18:21
14
$\begingroup$

The most common one is $A_{ij} $, although you will often $a_{ij} $ in lowercase. Slightly less common is $A_{i,j} $ (usually when the indices are themselves a formula). Far less common is $A (i,j) $; sometimes used when there are other subindices/superindices around.

$\endgroup$
9
$\begingroup$

No, quite independently of matrices there is no standard mathematical notation for mutating operations, because there is no notion of executing a mathematical text. If we wrote a hypothetical formula with a side effect, what would make that side effect actually happen? We are free to reread our formulas if we don't quite understand them the first time around; would that make the side effect happen a twice or more?

However, it is possible to describe mathematical values in en operational way, as "the result of taking such and so value and performing this and that operation on it". Note that the meaning of such a description does not change by "executing" it, since it specifies which value to start with. Things like bringing matrices into echelon form are often described using this kind of description, but it usually does not use a symbolic formalism to describe just what operations are to be performed.

One case that is somewhat of this nature is evaluating polynomials by writing say $P(2)$ (although I personally prefer the more explicit $P[X:=2]$), which means (more or less) the result of taking the expression referred to by $P$ and replacing every instance of $X$ by the value $2$, and then performing the arithmetic operations (addition, multiplications, powers,...).

But for modifying a matrix value in a specific way, I don't think there is any standardised notation.

$\endgroup$
  • $\begingroup$ Very important point! But I think the notation $A_{00} \leftarrow 2$ could be considered “standard mathematical notation for mutation”; this is what's used for most algorithm pseudocodes in CS papers. Arguably, such mutation still doesn't really make sense mathematically though. (Mutation can be described rigorously as a mathematical operation however, as a monadic action for instance.) $\endgroup$ – leftaroundabout May 11 '16 at 19:18
  • $\begingroup$ of course there's a notion of executing mathematical text. By construction, mathematics is nothing but a bunch of symbols until it is parsed by us and in the process of walking through the statements, we implicitly transform a default environment, consisting only of reserved variables bound to reserved values such as pi, e, to new environments with the new state of the environment. Like most programming languages, math statements are chained with implicit(or explicit) "then". Every statement is a side effect in the sense that our new environment has new variables/or a new object on our stack. $\endgroup$ – Dmitry Jan 19 '18 at 21:48
  • $\begingroup$ When we re-read an expression, we take an arbitrary environment, that we suppose is valid at this step, and interpret the statement and see what our new environment is, and use that as the input to the next step. This is of course can easily be optimized down to "changing state", since there's no other "threads" messed up if we mutate a value. $\endgroup$ – Dmitry Jan 19 '18 at 21:51
  • $\begingroup$ That said, you're right, there's no actual reason to care whether we redefine a variable or not because the statement "let x = 2, let x = 3" is no different than "(λΓ.(λx. (λx ...)(3))(2))" where (λx. x) is a lambda function, and λΓ denotes our implicit environment(with pi, e, more or less variables) and since we are allowed to have many functions that have the same named variable, mutation in a math statement is just an abstraction of lambda abstraction which allows us to use math without caring how it "works"(variable binding, concept of then, concept of environments and stacks). $\endgroup$ – Dmitry Jan 19 '18 at 22:03
  • $\begingroup$ My point is that math definitely has side effects, but you're right that as long as there is only one thread of reasoning, the concept of mutability is meaningless because mutability is isomorphic to shadowing(can easily convert to and from the two structures, a=2 a=3,a=4 and the (λΓ.(λx. (λx. (λx ...)(4))(3))(2)) that we execute by choosing an environment λΓ to start with. $\endgroup$ – Dmitry Jan 19 '18 at 22:17
8
$\begingroup$

Try $ e_i^t Ae_j = a_{ij} $ where $ e_i $ the i-th Standard Vector. $e_i = (0,…,0,1,0,….0)^t$ and the $1$ ist the i-th Element.

$\endgroup$
  • $\begingroup$ What does t denote? $\endgroup$ – Dmitry May 11 '16 at 12:31
  • 3
    $\begingroup$ The matrix you would obtain by changing the value of one of the entries of $A$, is a new, different matrix which is not equal to $A$. So it should have a new name, something other than $A$. It's not like a variable in programming where you can just change its value. $\endgroup$ – littleO May 11 '16 at 12:52
  • 1
    $\begingroup$ Ok that makes sense. Similar to Haskell constructs. $\endgroup$ – Dmitry May 11 '16 at 12:53
  • 1
    $\begingroup$ Hmm its $(e_j)^t $. You have a specific vector and then you transpose it. $\endgroup$ – user317721 May 11 '16 at 13:12
  • 5
    $\begingroup$ @Dmitry, I'm a little amused by the fact that you are familiar enough with functional programming and not with math to say "oh, math notation works like Haskell" rather than the reverse. There's nothing wrong with that, though. $\endgroup$ – Mark S. May 11 '16 at 18:07

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.