4.5.7Linear Algebra (Full)

Matrix multiplication — definition, associativity, non-commutativity

1,545 words7 min readdifficulty · medium

1. The definition — derived, not dumped

WHY the sum-of-products? Let's derive it. A matrix BB acts on a vector x\mathbf{x} by (Bx)k=jBkjxj.(B\mathbf{x})_k = \sum_{j} B_{kj} x_j. We demand that ABAB be the single matrix doing "AA after BB", i.e. (AB)x=A(Bx)(AB)\mathbf{x} = A(B\mathbf{x}) for all x\mathbf{x}. Compute the ii-th entry: (A(Bx))i=kAik(Bx)k=kAik(jBkjxj)=j(kAikBkj=(AB)ij)xj.\big(A(B\mathbf{x})\big)_i = \sum_k A_{ik}(B\mathbf{x})_k = \sum_k A_{ik}\Big(\sum_j B_{kj}x_j\Big) = \sum_j \Big(\underbrace{\sum_k A_{ik}B_{kj}}_{=(AB)_{ij}}\Big)x_j.

So the coefficient multiplying xjx_j — which is (AB)ij(AB)_{ij} — is forced to be kAikBkj\sum_k A_{ik}B_{kj}. The definition isn't arbitrary; composition forces it.

Figure — Matrix multiplication — definition, associativity, non-commutativity

2. Worked examples


3. Associativity — WHY it's free

Algebraic proof (entrywise). With sizes compatible, ((AB)C)i=j(AB)ijCj=j(kAikBkj)Cj=kjAikBkjCj.\big((AB)C\big)_{i\ell}=\sum_j (AB)_{ij}C_{j\ell}=\sum_j\Big(\sum_k A_{ik}B_{kj}\Big)C_{j\ell}=\sum_{k}\sum_{j}A_{ik}B_{kj}C_{j\ell}. (A(BC))i=kAik(BC)k=kAik(jBkjCj)=kjAikBkjCj.\big(A(BC)\big)_{i\ell}=\sum_k A_{ik}(BC)_{k\ell}=\sum_k A_{ik}\Big(\sum_j B_{kj}C_{j\ell}\Big)=\sum_{k}\sum_{j}A_{ik}B_{kj}C_{j\ell}. Both equal the same double sum — finite sums can be reordered. Done. Associativity is why "ABCABC" is unambiguous.

Also note distributivity: A(B+C)=AB+ACA(B+C)=AB+AC and (A+B)C=AC+BC(A+B)C=AC+BC, and AI=IA=AA I = I A = A (identity).


4. Non-commutativity — WHY ABBAAB\neq BA in general

Three reasons ABBAAB\neq BA:

  1. Shape: ABAB and BABA can have different sizes (Example 2) — then they can't be equal.
  2. Even when both square: the dot products mix rows/cols differently. See RFRF vs FRFR above.
  3. Commutator measures failure: [A,B]:=ABBA[A,B]:=AB-BA. It is 00 iff they commute.

5. Steel-manned mistakes


Recall Feynman: explain to a 12-year-old (hidden)

Think of each matrix as a little recipe machine for moving dots on a grid. ABAB means "run machine BB, then machine AA, back to back, as one combined machine." To build that combined machine you slide each row of AA across each column of BB, multiply matching numbers and add them up — that's the row-dot-column rule. Because doing BB-then-AA is usually different from AA-then-BB (like socks-then-shoes vs shoes-then-socks), swapping the order usually gives a different machine — that's non-commutativity. But grouping three machines (AB)C(AB)C vs A(BC)A(BC) gives the same pipeline, so that grouping is free — that's associativity.


Active recall

For C=ABC=AB what is CijC_{ij}?
kAikBkj\sum_k A_{ik}B_{kj} — row ii of AA dotted with column jj of BB.
Which dimensions must match to form ABAB?
The inner ones: AA is m×nm\times n, BB is n×pn\times p; result is m×pm\times p.
WHY is the product defined by row·column sums and not entrywise?
So that (AB)x=A(Bx)(AB)\mathbf{x}=A(B\mathbf{x}), i.e. ABAB represents composition of the two linear maps.
State and justify associativity.
(AB)C=A(BC)(AB)C=A(BC); both apply maps in order C,B,AC,B,A to any vector, and entrywise both equal j,kAikBkjCj\sum_{j,k}A_{ik}B_{kj}C_{j\ell}.
Is matrix multiplication commutative? Give a counterexample.
No. E.g. (1101)(1011)\begin{pmatrix}1&1\\0&1\end{pmatrix}\begin{pmatrix}1&0\\1&1\end{pmatrix}\neq the reverse.
What is (AB)1(AB)^{-1}?
B1A1B^{-1}A^{-1} (order reverses).
Expand (A+B)2(A+B)^2 for matrices.
A2+AB+BA+B2A^2+AB+BA+B^2 (not A2+2AB+B2A^2+2AB+B^2 unless A,BA,B commute).
Define the commutator and what it measures.
[A,B]=ABBA[A,B]=AB-BA; it is 00 iff AA and BB commute.
Can AB=0AB=0 with A,BA,B both nonzero?
Yes — matrices have zero divisors, e.g. (0100)2=0\begin{pmatrix}0&1\\0&0\end{pmatrix}^2=0.

Connections

  • Linear Transformations — matrix product = composition of maps.
  • Identity and Inverse Matrices(AB)1=B1A1(AB)^{-1}=B^{-1}A^{-1}.
  • Dot Product — each entry of ABAB is a dot product.
  • Determinantsdet(AB)=detAdetB\det(AB)=\det A\det B (multiplicative despite non-commutativity).
  • Transpose(AB)=BA(AB)^\top=B^\top A^\top (order also reverses).
  • Matrix Powers and Diagonalization — commuting matrices share eigenvectors.

Concept Map

multiply = compose

forces

requires

three readings

used in

inherits

order matters

different shapes

shown by

illustrates

Matrix as linear map

Composition A after B

Definition Cij = sum Aik Bkj

Inner dims must match

Entry / Column / Row views

Worked examples

Associativity AB C = A BC

Non-commutativity AB != BA

Rotation then flip != flip then rotation

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, matrix ko ek machine samjho jo vectors ko transform karti hai (linear map). Jab tum ABAB multiply karte ho, tum do machines ko jod rahe ho — pehle BB chalao, phir AA. Isi "composition" ki wajah se row-into-column wala rule banta hai: (AB)ij(AB)_{ij} matlab AA ki ii-th row ka BB ki jj-th column ke saath dot product. Yeh definition koi randomly nahi hai — yeh isliye aati hai taaki (AB)x=A(Bx)(AB)\mathbf{x}=A(B\mathbf{x}) har vector ke liye sach ho. Inner dimensions match karne chahiye, aur outer dimensions result ka size dete hain.

Associativity ((AB)C=A(BC) (AB)C=A(BC)) free milti hai kyunki functions ko compose karna hamesha associative hota hai — "C phir B phir A" ek hi pipeline hai, bracket kahin bhi lagao farak nahi padta. Isliye hum "ABCABC" likh sakte hain bina confusion ke.

Lekin commutativity nahi hotiABAB aur BABA generally alag hote hain. Socho socks-then-shoes vs shoes-then-socks: order badal do, result badal jaata hai. Kabhi shape hi alag ho jaata hai, kabhi square hone par bhi entries alag aati hain. Iska measure hota hai commutator [A,B]=ABBA[A,B]=AB-BA, jo 00 tabhi hota hai jab dono commute karein.

Do common galtiyan yaad rakho: (AB)1=B1A1(AB)^{-1}=B^{-1}A^{-1} (order ulta hota hai, kyunki pehle A undo karna padta hai), aur (A+B)2=A2+AB+BA+B2(A+B)^2=A^2+AB+BA+B^2 — yahan 2AB2AB tabhi likh sakte ho jab A,BA,B commute karein. Mnemonic: Rows Cross Columns; Order Counts; Brackets Don't.

Go deeper — visual, from zero

Test yourself — Linear Algebra (Full)

Connections