Linear Operators & Matrices

4 hours ~5 min read

Linear Operators & Matrices

Quantum gates, observables, Hamiltonians, and measurements are all linear operators. This lesson nails the operator toolkit: how an operator becomes a matrix once you fix a basis, how the adjoint is defined (it's where "Hermitian" and "unitary" will come from), and the basis-independent quantities — trace and determinant — we rely on constantly.

Learning Objectives

After this lesson you will be able to:

  1. Represent a linear operator as a matrix in a chosen basis and compute its action on kets.
  2. Define the adjoint AA^\dagger via the inner product and show it equals the conjugate transpose.
  3. Perform a change of basis and recognize similarity transformations.
  4. Compute and use the trace (cyclicity, basis-independence) and the determinant.
  5. Evaluate commutators [A,B][A,B] and explain why they matter physically.

Intuition

A linear operator is a function on vectors that respects addition and scaling: it sends lines to lines and the origin to the origin. Fix a basis and the operator is completely captured by what it does to the basis vectors — a finite table of numbers, i.e. a matrix. Change the basis and the same operator gets a different matrix. The quantities that don't change under such relabeling — trace, determinant, eigenvalues — are the operator's physical fingerprints.


Theory

Linear operators

A map A:HHA:\mathcal{H}\to\mathcal{H} is a linear operator if for all ψ,ϕ|\psi\rangle,|\phi\rangle and aCa\in\mathbb{C},

A(aψ+ϕ)=aAψ+Aϕ. A\big(a|\psi\rangle + |\phi\rangle\big) = a\,A|\psi\rangle + A|\phi\rangle .

Linearity means AA is determined by its action on a basis: if Aj=iAijiA|j\rangle = \sum_i A_{ij}|i\rangle, then for ψ=jcjj|\psi\rangle = \sum_j c_j|j\rangle,

Aψ=jcjAj=i(jAijcj)i. A|\psi\rangle = \sum_j c_j A|j\rangle = \sum_{i} \Big(\sum_j A_{ij} c_j\Big)|i\rangle .

The coefficients Aij=iAjA_{ij} = \langle i|A|j\rangle (from 0.1.3) are the matrix of AA; the formula above is matrix–vector multiplication. Composition is matrix multiplication: (AB)ik=jAijBjk(AB)_{ik} = \sum_j A_{ij}B_{jk}, derived by inserting completeness AB=AIB=jAjjBA B = A\,I\,B = \sum_j A|j\rangle\langle j|B.

The adjoint

The adjoint (Hermitian conjugate) AA^\dagger is defined by the inner-product relation

 ϕAψ=Aϕψfor all ϕ,ψ.  \boxed{\ \langle\phi|A\psi\rangle = \langle A^\dagger\phi|\psi\rangle \quad\text{for all }|\phi\rangle,|\psi\rangle.\ }

Equivalently ϕAψ=ψAϕ\langle\phi|A|\psi\rangle = \overline{\langle\psi|A^\dagger|\phi\rangle}. Claim: in any orthonormal basis, the matrix of AA^\dagger is the conjugate transpose of the matrix of AA: (A)ij=Aji(A^\dagger)_{ij} = \overline{A_{ji}}.

Proof. (A)ij=iAj(A^\dagger)_{ij} = \langle i|A^\dagger|j\rangle. By the defining relation with ϕ=j|\phi\rangle = |j\rangle, ψ=i|\psi\rangle = |i\rangle: $\langle j|A|i\rangle = \langle A^\dagger j|i\rangle = \overline{\langle i | A^\dagger | j\rangle} = \overline{(A^\dagger){ij}}.Hence. Hence (A^\dagger){ij} = \overline{\langle j|A|i\rangle} = \overline{A_{ji}}$. ∎

Properties (all from the definition): (A)=A(A^\dagger)^\dagger = A, (aA+B)=aA+B(aA+B)^\dagger = \overline{a}A^\dagger + B^\dagger, (AB)=BA(AB)^\dagger = B^\dagger A^\dagger, and (ψϕ)=ϕψ\big(|\psi\rangle\langle\phi|\big)^\dagger = |\phi\rangle\langle\psi|.

These three names — defined next lesson but anchored here — are adjoint conditions: Hermitian A=AA^\dagger = A, unitary U=U1U^\dagger = U^{-1}, normal AA=AAA^\dagger A = A A^\dagger.

Change of basis

Let {k}\{|k\rangle\} and {k}\{|k'\rangle\} be two orthonormal bases, related by a unitary SS with k=Sk|k'\rangle = S|k\rangle (columns of SS are the new basis vectors in old coordinates). A ket's coordinate column transforms as c=Scc' = S^\dagger c, and an operator's matrix transforms by a similarity transformation:

A=SAS. A' = S^\dagger A\, S .

Derivation. Aij=iAj=SiASj=iSASj=(SAS)ijA'_{ij} = \langle i'|A|j'\rangle = \langle S i|A|S j\rangle = \langle i|S^\dagger A S|j\rangle = (S^\dagger A S)_{ij}. Same operator, new matrix. Quantities preserved by ASASA\mapsto S^\dagger A S are exactly the physical invariants below.

Trace

The trace is Tr(A)=kAkk=kkAk\operatorname{Tr}(A) = \sum_k A_{kk} = \sum_k\langle k|A|k\rangle. Key properties:

  • Linear: Tr(aA+B)=aTr(A)+Tr(B)\operatorname{Tr}(aA+B) = a\operatorname{Tr}(A) + \operatorname{Tr}(B).
  • Cyclic: Tr(ABC)=Tr(CAB)=Tr(BCA)\operatorname{Tr}(ABC) = \operatorname{Tr}(CAB) = \operatorname{Tr}(BCA). (Proof: expand indices; Tr(AB)=i,jAijBji=Tr(BA)\operatorname{Tr}(AB) = \sum_{i,j}A_{ij}B_{ji} = \operatorname{Tr}(BA), then iterate.)
  • Basis-independent: $\operatorname{Tr}(S^\dagger A S) = \operatorname{Tr}(A S S^\dagger) = \operatorname{Tr}(A)bycyclicityand by cyclicity and SS^\dagger = I$. (We proved basis-independence directly in 0.1.3 E3 too.)
  • Equals the sum of eigenvalues (next lesson).

The trace is how expectation values and probabilities are computed in the density-matrix formalism: A=Tr(ρA)\langle A\rangle = \operatorname{Tr}(\rho A) (Term 1.5).

Determinant and commutator

The determinant detA\det A is the product of eigenvalues; it is multiplicative (det(AB)=detAdetB\det(AB) = \det A\,\det B), basis-independent (det(S1AS)=detA\det(S^{-1}AS) = \det A), and AA is invertible iff detA0\det A \neq 0. For unitaries detU=1|\det U| = 1.

The commutator [A,B]=ABBA[A,B] = AB - BA measures failure to commute; the anticommutator is {A,B}=AB+BA\{A,B\} = AB+BA. Commutators are central in quantum mechanics: observables commute iff they are simultaneously diagonalizable (Term 0.1.5) and can be measured together without disturbance; the canonical [x^,p^]=i[\hat x,\hat p] = i\hbar gives the uncertainty principle (Term 1.3). For Pauli matrices, [X,Y]=2iZ[X,Y] = 2iZ (see Appendix E).


Worked Examples

Example 1 — Building a matrix from its action

Define AA on a qubit by A0=1A|0\rangle = |1\rangle, A1=0A|1\rangle = |0\rangle (it swaps basis states). The columns of the matrix are the images of the basis kets in coordinates:

A=(A0  A1)=(0110)=X. A = \big(\,A|0\rangle \ \big|\ A|1\rangle\,\big) = \begin{pmatrix} 0 & 1 \\ 1 & 0\end{pmatrix} = X .

This is the Pauli-XX / NOT gate. Its adjoint is X=XT=XX^\dagger = \overline{X}^T = X (Hermitian), and since X2=IX^2 = I also X=X1X^\dagger = X^{-1} (unitary): XX is both Hermitian and unitary — a fact we'll see is special to involutions.

Example 2 — Change of basis: ZZ seen in the Hadamard basis

The Pauli-Z=diag(1,1)Z = \operatorname{diag}(1,-1) is diagonal in {0,1}\{|0\rangle,|1\rangle\}. Change to the Hadamard basis via S = H = \tfrac1{\sqrt2}\begin{psmallmatrix}1 & 1\\ 1 & -1\end{psmallmatrix} (which is unitary and Hermitian, so S=SS^\dagger = S):

Z=SZS=HZH=12(1111)(1001)(1111)=(0110)=X. Z' = S^\dagger Z S = H Z H = \tfrac12\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1&0\\0&-1\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix} = \begin{pmatrix}0 & 1\\ 1 & 0\end{pmatrix} = X .

So ZZ in the {+,}\{|+\rangle,|-\rangle\} basis is XX — the famous identity HZH=XHZH = X. Same operator, different matrix; note Tr\operatorname{Tr} and det\det are unchanged (00 and 1-1 respectively).


Hands-on (Python)

import numpy as np

def dag(A):
    return A.conj().T                       # adjoint = conjugate transpose

X = np.array([[0, 1], [1, 0]], dtype=complex)
Y = np.array([[0, -1j], [1j, 0]], dtype=complex)
Z = np.array([[1, 0], [0, -1]], dtype=complex)
H = np.array([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2)

# Build an operator column-by-column from its action on the basis:
ket0 = np.array([1, 0], dtype=complex)
ket1 = np.array([0, 1], dtype=complex)
A = np.column_stack([X @ ket0, X @ ket1])   # columns are A|0>, A|1>
print(np.allclose(A, X))                    # True

# Adjoint, trace, determinant:
print(np.allclose(dag(X), X))               # X is Hermitian
print(np.trace(Z), np.linalg.det(Z))        # 0,  (-1+0j)

# Change of basis HZH = X (similarity transform with S = H, S† = H):
print(np.allclose(dag(H) @ Z @ H, X))       # True
print(np.isclose(np.trace(dag(H) @ Z @ H), np.trace(Z)))  # trace invariant: True
# Commutators / anticommutators of Paulis:
def comm(A, B):  return A @ B - B @ A
def acomm(A, B): return A @ B + B @ A

print(np.allclose(comm(X, Y), 2j * Z))      # [X,Y] = 2iZ
print(np.allclose(acomm(X, Y), np.zeros((2, 2))))  # Paulis anticommute: {X,Y}=0

Braket preview. When you build Circuit().x(0) in Term 2, the SDK is composing exactly these operator matrices (as a unitary) and applying them to the state vector. The math here is what the simulator does under the hood.


Exercises

E1 (easy). Find the matrix of the operator A=01+10A = |0\rangle\langle 1| + |1\rangle\langle 0| and identify it.

Solution

|0\rangle\langle1| = \begin{psmallmatrix}0&1\\0&0\end{psmallmatrix}, |1\rangle\langle0| = \begin{psmallmatrix}0&0\\1&0\end{psmallmatrix}; their sum is \begin{psmallmatrix}0&1\\1&0\end{psmallmatrix} = X, the NOT gate.

E2 (easy). Verify (AB)=BA(AB)^\dagger = B^\dagger A^\dagger for A=XA = X, B=S=diag(1,i)B = S = \operatorname{diag}(1,i).

Solution

AB = X S = \begin{psmallmatrix}0&i\\1&0\end{psmallmatrix}, so (AB)^\dagger = \begin{psmallmatrix}0&1\\-i&0\end{psmallmatrix}. B=diag(1,i)B^\dagger = \operatorname{diag}(1,-i), A=XA^\dagger = X, so $B^\dagger A^\dagger = \operatorname{diag}(1,-i)X = \begin{psmallmatrix}0&1\-i&0\end{psmallmatrix}$. They match. ∎

E3 (medium). Prove Tr(AB)=Tr(BA)\operatorname{Tr}(AB) = \operatorname{Tr}(BA) from the index definition, and give a counterexample to Tr(ABC)=Tr(ACB)\operatorname{Tr}(ABC) = \operatorname{Tr}(ACB).

Solution

$\operatorname{Tr}(AB) = \sum_i (AB){ii} = \sum{i,j}A_{ij}B_{ji} = \sum_{j,i}B_{ji}A_{ij} = \sum_j (BA)_{jj} = \operatorname{Tr}(BA)$. But cyclicity allows only rotations, not arbitrary swaps. Counterexample with Paulis: Tr(XYZ)\operatorname{Tr}(XYZ) vs Tr(XZY)\operatorname{Tr}(XZY). Since XYZ=X(iX)=iX2=iIXYZ = X(iX) = iX^2 = iI... let's use Tr(XYZ)\operatorname{Tr}(XYZ): YZ=iXYZ = iX so XYZ=iX2=iIXYZ = iX^2 = iI, trace 2i2i. And XZYXZY: ZY=iXZY = -iX, so XZY=iX2=iIXZY = -iX^2 = -iI, trace 2i2i-2i \neq 2i. ∎

E4 (medium). Show that the trace of a commutator is always zero, Tr([A,B])=0\operatorname{Tr}([A,B]) = 0. What does this imply about whether [x^,p^]=iI[\hat x,\hat p] = i\hbar I can hold for finite matrices?

Solution

Tr(ABBA)=Tr(AB)Tr(BA)=0\operatorname{Tr}(AB - BA) = \operatorname{Tr}(AB) - \operatorname{Tr}(BA) = 0 by cyclicity. But Tr(iI)=in0\operatorname{Tr}(i\hbar I) = i\hbar\,n \neq 0 in dimension nn. So the canonical commutation relation [x^,p^]=iI[\hat x,\hat p] = i\hbar I has no finite-dimensional matrix realization — position and momentum require infinite-dimensional Hilbert spaces. (Qubits, being finite, only ever use bounded observables like the Paulis.)

E5 (hard). Prove that the trace is the unique (up to scale) linear functional ff on operators satisfying f(AB)=f(BA)f(AB) = f(BA) for all A,BA,B — i.e. cyclicity essentially characterizes the trace.

Solution sketch

Using f(AB)=f(BA)f(AB)=f(BA) with A=ijA = |i\rangle\langle j|, B=klB = |k\rangle\langle l|: AB=δjkilAB = \delta_{jk}|i\rangle\langle l| and BA=δlikjBA = \delta_{li}|k\rangle\langle j|, so f(il)δjk=f(kj)δlif(|i\rangle\langle l|)\delta_{jk} = f(|k\rangle\langle j|)\delta_{li}. Take j=kj=k, ili\neq l: forces f(il)=0f(|i\rangle\langle l|) = 0 for ili\neq l. Take i=li=l, j=kj=k: forces all diagonal values f(ii)f(|i\rangle\langle i|) equal, say to cc. Then by linearity $f(A) = \sum_i A_{ii},c = c\operatorname{Tr}(A).Hence. Hence f$ is a scalar multiple of the trace. ∎


Checkpoint

  1. How is an operator's matrix determined by its action on a basis?
  2. Give the defining inner-product relation for the adjoint and the resulting matrix rule.
  3. How does an operator's matrix transform under a change of orthonormal basis?
  4. List three properties of the trace and explain why basis-independence matters physically.
  5. What is the physical significance of two observables commuting?
Answers
  1. The jj-th column is AjA|j\rangle in coordinates; equivalently Aij=iAjA_{ij} = \langle i|A|j\rangle.
  2. ϕAψ=Aϕψ\langle\phi|A\psi\rangle = \langle A^\dagger\phi|\psi\rangle; in an ONB, (A)ij=Aji(A^\dagger)_{ij} = \overline{A_{ji}} (conjugate transpose).
  3. A=SASA' = S^\dagger A S with SS unitary (similarity transform).
  4. Linear, cyclic (Tr(AB)=Tr(BA)\operatorname{Tr}(AB)=\operatorname{Tr}(BA)), basis-independent, equals sum of eigenvalues. Basis-independence means physical predictions (e.g. Tr(ρA)\operatorname{Tr}(\rho A)) don't depend on the arbitrary choice of coordinates.
  5. Commuting observables share an eigenbasis, so they can be measured simultaneously with definite joint values and without mutual disturbance.

Further Reading

  • [Axl] Axler, Linear Algebra Done Right, Ch. 3, 5, 7, 10 — operators, adjoints, trace, determinant.
  • [NC] Nielsen & Chuang, §2.1.5–2.1.7 — operators, adjoints, the outer-product representation, trace.
  • [HJ] Horn & Johnson, Matrix Analysis — the definitive matrix reference.

← Prev: Dirac Notation · Up: Term 0 · Next: Eigenvalues & the Spectral Theorem

Ready to measure your state?

5 exercises · 10 checkpoint questions

Start the quiz