Search

Search papers and lessons

Commutator

Level 3 · 10 min read

The commutator of two matrices, AB minus BA, measures how much the order of applying them matters; when it is zero the two commute.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

For two matrices AA and BB, the product ABAB usually differs from BABA. The commutator [A,B]=AB−BA[A,B] = AB - BA is the difference between the two orders. It is zero exactly when AA and BB commute, and it is nonzero when the order of operations changes the result.

Where you'll see it: in quantum mechanics, where [x^,p^]=iℏ[\hat{x}, \hat{p}] = i\hbar is the reason position and momentum cannot both be known exactly, and in robotics and 3D graphics, where rotations applied in different orders give different orientations.

Intuition

Think about getting dressed. Putting on socks and then shoes gives a different result from putting on shoes and then socks. Both sequences start from the same bare feet and end with the same two items, but the outcomes differ. Operations that act on a state are often like this. The order is part of the answer.

Matrices are operations on vectors (see Linear Transformation). A matrix AA moves a vector, and BB moves it too. Applying BB first and then AA is the product ABAB, while applying AA first and then BB is BABA. The commutator asks how far apart those two results are:

flowchart LR
    S[Start vector] --> X1[Apply A first]
    X1 --> Y1[Then apply B]
    Y1 --> P[Result: BA times start]
    S --> X2[Apply B first]
    X2 --> Y2[Then apply A]
    Y2 --> Q[Result: AB times start]
    P --> D[Difference is commutator applied to start]
    Q --> D

If the two paths end at the same place for every starting vector, the operations commute and the commutator is zero. If they end at different places, the commutator is the nonzero matrix that describes the gap.

Why does this idea exist? Many problems involve several operations whose order is fixed by the physics or by the geometry. A rotation, a stretch and a shift do not commute. Quantum mechanics goes further: the act of measuring one quantity can change another, and the commutator is the exact measure of how much the order matters. Without a name for this gap, every calculation with non-commuting operators would have to carry the order around by hand.

The math

Definition: Commutator

For two n×nn \times n matrices AA and BB, the commutator is the n×nn \times n matrix

[A,B]=AB−BA.[A,B] = AB - BA.

Here ABAB is the matrix product from Matrix Multiplication, nn is the size of the square matrices, and [A,B][A,B] is itself an n×nn \times n matrix. The matrices AA and BB commute when [A,B]=0[A,B] = 0, that is when AB=BAAB = BA.

Basic properties

For all square matrices AA, BB, CC of the same size, and scalars cc:

  1. Antisymmetry. [A,B]=−[B,A][A,B] = -[B,A]. Swapping the two matrices flips the sign, since BA−AB=−(AB−BA)BA - AB = -(AB - BA).
  2. Linearity. [A,B+C]=[A,B]+[A,C][A, B + C] = [A,B] + [A,C] and [A,cB]=c[A,B][A, cB] = c[A,B]. Both follow by expanding the product term by term.
  3. Self-commutator. [A,A]=AA−AA=0[A,A] = AA - AA = 0.
  4. Jacobi identity.
[A,[B,C]]+[B,[C,A]]+[C,[A,B]]=0.[A,[B,C]] + [B,[C,A]] + [C,[A,B]] = 0.

Expanding each term gives four products, so there are twelve in all. Writing them out, [A,[B,C]]=ABC−ACB−BCA+CBA[A,[B,C]] = ABC - ACB - BCA + CBA, [B,[C,A]]=BCA−BAC−CAB+ACB[B,[C,A]] = BCA - BAC - CAB + ACB, and [C,[A,B]]=CAB−CBA−ABC+BAC[C,[A,B]] = CAB - CBA - ABC + BAC. Adding the three lines, every product cancels against one with the opposite sign. This identity is what makes the commutator a Lie bracket, which is why the term appears in the aliases.

The trace of a commutator is zero

The trace of a square matrix is the sum of its diagonal entries, tr⁡(M)=∑iMii\operatorname{tr}(M) = \sum_i M_{ii}. For any two n×nn \times n matrices, tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA), because

tr⁡(AB)=∑i∑jAijBji=∑j∑iBjiAij=tr⁡(BA).\operatorname{tr}(AB) = \sum_i \sum_j A_{ij} B_{ji} = \sum_j \sum_i B_{ji} A_{ij} = \operatorname{tr}(BA).

Subtracting, tr⁡([A,B])=0\operatorname{tr}([A,B]) = 0. A useful consequence: no commutator of matrices can equal the identity matrix II, because tr⁡(I)=n≠0\operatorname{tr}(I) = n \neq 0.

Commuting matrices share eigenvectors

This is the main reason commutation matters in linear algebra. Recall from Eigenvalues and Eigenvectors that an eigenvector vv of AA satisfies Av=λvAv = \lambda v. Suppose AB=BAAB = BA. Then

A(Bv)=(AB)v=(BA)v=B(Av)=B(λv)=λ(Bv).A(Bv) = (AB)v = (BA)v = B(Av) = B(\lambda v) = \lambda (Bv).

So BvBv is also an eigenvector of AA with the same eigenvalue λ\lambda. If that eigenspace has dimension one, BvBv must be a multiple of vv, which means vv is an eigenvector of BB too. Commuting matrices that are each diagonalisable can therefore be diagonalised in a common basis.

The canonical commutator in quantum mechanics

In quantum mechanics, position x^\hat{x} and momentum p^\hat{p} are operators on functions. Acting on a function ff of xx, they are x^f=xf\hat{x} f = x f and p^f=−iℏ dfdx\hat{p} f = -i\hbar \, \frac{df}{dx}, where ℏ\hbar is the reduced Planck constant. Compute both orders:

x^p^f=−iℏ xf′,p^x^f=−iℏ ddx(xf)=−iℏ (f+xf′).\hat{x}\hat{p} f = -i\hbar \, x f', \qquad \hat{p}\hat{x} f = -i\hbar \, \frac{d}{dx}(x f) = -i\hbar\,(f + x f').

Subtracting gives

[x^,p^]f=−iℏ xf′+iℏ (f+xf′)=iℏ f,[\hat{x}, \hat{p}] f = -i\hbar\,x f' + i\hbar\,(f + x f') = i\hbar\, f,

so [x^,p^]=iℏ[\hat{x}, \hat{p}] = i\hbar. The commutator is a nonzero constant, and that is the origin of the uncertainty principle. The general bound for two observables is σAσB≥12 ∣⟨[A,B]⟩∣\sigma_A \sigma_B \geq \tfrac{1}{2}\,|\langle [A,B] \rangle|, where σ\sigma denotes standard deviation. With [x^,p^]=iℏ[\hat{x},\hat{p}] = i\hbar, this gives σxσp≥ℏ/2\sigma_x \sigma_p \geq \hbar/2.

Worked examples

Example
A tiny 2 by 2 example

Let

A=(0110),B=(100−1).A = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, \qquad B = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}.
  1. Compute ABAB. Row 1 of AA is (0,1)(0, 1). Times column 1 of BB, (1,0)(1, 0), gives 00. Times column 2, (0,−1)(0, -1), gives −1-1. Row 2 of AA is (1,0)(1, 0), which gives 11 and 00. So AB=(0−110)AB = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}.
  2. Compute BABA. Row 1 of BB is (1,0)(1, 0), which gives (0,1)(0, 1). Row 2 of BB is (0,−1)(0, -1), which gives (−1,0)(-1, 0). So BA=(01−10)BA = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix}.
  3. Subtract entry by entry: [A,B]=AB−BA=(0−220)[A,B] = AB - BA = \begin{pmatrix} 0 & -2 \\ 2 & 0 \end{pmatrix}.
  4. The commutator is nonzero, so AA and BB do not commute. Its trace is 0+0=00 + 0 = 0, as the trace property predicts.

Interpretation: applying BB and then AA leaves the vector in a different place from applying AA and then BB. The gap is the matrix above.

Example
Rotations in 3D, a realistic case

Rotations are used to orient a robot arm or a camera. Let RxR_x be a rotation by 90∘90^\circ about the xx-axis and RyR_y a rotation by 90∘90^\circ about the yy-axis. With cos⁡90∘=0\cos 90^\circ = 0 and sin⁡90∘=1\sin 90^\circ = 1, the standard rotation matrices are

Rx=(10000−1010),Ry=(001010−100).R_x = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{pmatrix}, \qquad R_y = \begin{pmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0 \end{pmatrix}.
  1. Compute RxRyR_x R_y. Row 1 of RxR_x is (1,0,0)(1,0,0), which picks row 1 of RyR_y: (0,0,1)(0,0,1). Row 2 of RxR_x is (0,0,−1)(0,0,-1), which gives minus row 3 of RyR_y: (1,0,0)(1,0,0). Row 3 of RxR_x is (0,1,0)(0,1,0), which picks row 2 of RyR_y: (0,1,0)(0,1,0). So RxRy=(001100010)R_x R_y = \begin{pmatrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \end{pmatrix}.
  2. Compute RyRxR_y R_x. Row 1 of RyR_y is (0,0,1)(0,0,1), which picks row 3 of RxR_x: (0,1,0)(0,1,0). Row 2 of RyR_y is (0,1,0)(0,1,0), which picks row 2 of RxR_x: (0,0,−1)(0,0,-1). Row 3 of RyR_y is (−1,0,0)(-1,0,0), which gives minus row 1 of RxR_x: (−1,0,0)(-1,0,0). So RyRx=(01000−1−100)R_y R_x = \begin{pmatrix} 0 & 1 & 0 \\ 0 & 0 & -1 \\ -1 & 0 & 0 \end{pmatrix}.
  3. Subtract: [Rx,Ry]=(0−11101110)[R_x, R_y] = \begin{pmatrix} 0 & -1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix}.
  4. The two orders give different orientations. Take e1=(1,0,0)e_1 = (1,0,0). Applying RyR_y first and then RxR_x is RxRye1=Rx(0,0,−1)=(0,1,0)R_x R_y e_1 = R_x(0,0,-1) = (0,1,0). Applying RxR_x first and then RyR_y is RyRxe1=Ry(1,0,0)=(0,0,−1)R_y R_x e_1 = R_y(1,0,0) = (0,0,-1). The two results differ, and their difference (0,1,1)(0,1,1) is the first column of the commutator.

Interpretation: a robot that rotates about xx then yy ends up pointing somewhere other than one that rotates about yy then xx. Software that treats rotations as commuting will be wrong by an amount that depends on the commutator.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Assuming AB=BAAB = BA for rotations, robot joints or 3D orientationResults depend on the order, so the computed pose is wrongKeep the order explicit, or use quaternions with their own multiplication rules
Simultaneous diagonalisation of AA and BBRequires [A,B]=0[A,B] = 0; otherwise a common eigenbasis may not existCheck the commutator first; if it is nonzero, diagonalise one operator and treat the other in that basis
Splitting a time evolution et(A+B)e^{t(A+B)} into etAetBe^{tA}e^{tB}The splitting error is driven by commutators, so it is exact only when [A,B]=0[A,B] = 0Use a higher-order splitting, which cancels leading commutator terms
Reading quantum measurements as order-independentMeasuring x^\hat{x} then p^\hat{p} differs from p^\hat{p} then x^\hat{x}Use the commutator to decide which quantities can be known together

The commutator is not a flaw to be avoided. In many systems it is the physics. The practical rule is to compute it when order might matter and to use commuting shortcuts only when [A,B][A,B] is zero.

History

Arthur Cayley introduced matrix algebra as a systematic subject in the late 1850s, and he noted that matrix multiplication is generally not commutative. Hamilton's quaternions, from 1843, had a multiplication that was non-commutative, so the phenomenon was known early. Sophus Lie, in the late nineteenth century, studied continuous groups of transformations through their infinitesimal generators, and the commutator of those generators became the bracket of what are now called Lie algebras.

The idea became central in physics in 1925. Werner Heisenberg developed matrix mechanics, in which observables are matrices, and Max Born and Pascual Jordan showed that the canonical relation between position and momentum corresponds to a commutator with the value iℏi\hbar. Paul Dirac later made this algebraic structure the foundation of quantum theory. The commutator caught on because it turned a physical statement, that some quantities cannot be measured together, into a short algebraic condition.

Check yourself

QuestionWhat does it mean for two matrices AA and BB to commute, and what is the value of [A,B][A,B] in that case?Show answer

They commute when AB=BAAB = BA. Then [A,B]=AB−BA=0[A,B] = AB - BA = 0, the zero matrix. Commuting means the order in which the operations are applied does not change the result.

QuestionLet A=(1201)A = \begin{pmatrix} 1 & 2 \\ 0 & 1 \end{pmatrix} and B=(0110)B = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}. Compute [A,B][A,B].Show answer

AB=(2110)AB = \begin{pmatrix} 2 & 1 \\ 1 & 0 \end{pmatrix} and BA=(0112)BA = \begin{pmatrix} 0 & 1 \\ 1 & 2 \end{pmatrix}. Subtracting entry by entry gives [A,B]=(200−2)[A,B] = \begin{pmatrix} 2 & 0 \\ 0 & -2 \end{pmatrix}. Its trace is 2−2=02 - 2 = 0, as it must be.

QuestionShow that tr⁡([A,B])=0\operatorname{tr}([A,B]) = 0 for any two square matrices of the same size. Why does this mean no commutator can equal the identity matrix?Show answer

The trace is linear, so tr⁡(AB−BA)=tr⁡(AB)−tr⁡(BA)\operatorname{tr}(AB - BA) = \operatorname{tr}(AB) - \operatorname{tr}(BA). The trace satisfies tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA), as the double sum over entries shows, so the difference is zero. The identity matrix of size nn has trace nn, which is nonzero for n≥1n \geq 1, so it cannot be a commutator.

QuestionA physicist measures the position of a particle and then its momentum, and separately measures momentum and then position. Why can the two results not both be made arbitrarily precise, and what bound follows?Show answer

Position and momentum operators satisfy [x^,p^]=iℏ[\hat{x}, \hat{p}] = i\hbar, which is nonzero. Because the commutator is nonzero, the operators do not share a common eigenbasis, so no state has both sharp position and sharp momentum. The general uncertainty relation σxσp≥ℏ/2\sigma_x \sigma_p \geq \hbar/2 follows from the size of this commutator. The two orders of measurement give different statistics, which is exactly what the commutator encodes.

Sources