Linear Algebra

Unitary Matrix

U*U = I — the complex isometry, the matrix model of a quantum gate

A unitary matrix U is a complex square matrix satisfying U*U = UU* = I — its conjugate transpose is its inverse. Equivalent characterisations: U preserves every inner product (⟨Ux, Uy⟩ = ⟨x, y⟩), every length, every angle; its eigenvalues lie on the unit circle; its columns form an orthonormal basis. Real-valued unitary matrices are exactly the orthogonal matrices. Every quantum gate is unitary.

  • Defining propertyU*U = UU* = I
  • InverseU⁻¹ = U* (one transpose + conjugate, no factorisation)
  • Length‖Ux‖ = ‖x‖ for every x
  • Inner products⟨Ux, Uy⟩ = ⟨x, y⟩ for every x, y
  • EigenvaluesAll have modulus 1; lie on the unit circle
  • Used inQuantum gates, QR / SVD, change of orthonormal basis, FFT

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

The defining equation

A complex n×n matrix U is unitary if

U* U = U U* = I.

That is, the conjugate transpose U* is the (two-sided) inverse of U. From the equation U*U = I, the columns of U satisfy ui* uj = δij — they form an orthonormal set in the complex inner product. From UU* = I, the rows do likewise. Unitarity is the joint condition that both columns and rows are orthonormal.

Because U*U = I and UU* = I are equivalent for square matrices, you only have to check one direction. The matrix is automatically invertible (det U ≠ 0), and the inverse is read off for free — no LU, no row reduction.

Why unitary preserves length

Compute the squared norm of Ux:

‖Ux‖² = (Ux)*(Ux) = x* U* U x = x* I x = x* x = ‖x‖²

So ‖Ux‖ = ‖x‖ — every vector is mapped to a vector of the same length. The same algebra with two different inputs gives the full inner-product law:

⟨Ux, Uy⟩ = (Ux)*(Uy) = x* U* U y = x* y = ⟨x, y⟩

A unitary matrix is therefore an isometry of complex inner-product space. Angles between vectors are preserved, and so is every metric quantity (distances, areas, volumes — |det U| = 1).

Why eigenvalues lie on the unit circle

Suppose Uv = λv with v ≠ 0. Length preservation gives

‖v‖ = ‖Uv‖ = ‖λv‖ = |λ| · ‖v‖

so |λ| = 1. Every eigenvalue has modulus 1, meaning each one can be written e for some real angle θ. Geometrically, a unitary matrix is "rotation by mixed angles" along its eigenspaces — different θ on each invariant subspace.

Worked example — 2×2 unitary

Take

U = (1/√2) · [[1, i], [i, 1]]

Check U*U. Conjugate-transpose: U* = (1/√2) · [[1, −i], [−i, 1]]. Multiply:

U* U = (1/2) · [[1, −i], [−i, 1]] · [[1, i], [i, 1]]
     = (1/2) · [[1 + 1, i + (−i)], [(−i) + i, (−i)·i + 1]]
     = (1/2) · [[2, 0], [0, 2]]
     = I  ✓

So U is unitary. Apply it to x = [1, 0]T: Ux = (1/√2)[1, i]T. Length check: ‖Ux‖² = (1/2)(1 + 1) = 1 = ‖x‖² ✓.

Eigenvalues. det(U − λI) = (1/√2 − λ)² − (i/√2)(i/√2) = (1/√2 − λ)² + 1/2. Setting this to zero gives (1/√2 − λ)² = −1/2, so 1/√2 − λ = ±i/√2 — λ = (1 ∓ i)/√2 = e∓iπ/4. Both have modulus 1, on the unit circle. ✓

Variants and adjacent classes

  • Orthogonal matrix. Real-valued unitary: QTQ = I. Rotations and reflections in ℝn.
  • Special unitary matrix SU(n). Unitary with determinant exactly 1 (not just |det| = 1). The matrices of SU(2) double-cover the rotations of ℝ³ and parametrise spin-1/2 transformations.
  • Discrete Fourier transform matrix. The n×n matrix F with Fjk = (1/√n) ωjk, where ω = e2πi/n, is unitary. F* = F−1 is why inverse FFT is essentially the same algorithm.
  • Permutation matrix. A real special case: rows are an orthonormal basis (one 1, rest 0). Permutations of a basis are real unitary.
  • Householder reflector. H = I − 2 vv* with ‖v‖ = 1. Self-inverse unitary reflection across the hyperplane orthogonal to v. The atomic building block of the QR algorithm.
  • Givens rotation. 2×2 rotation embedded in a larger identity matrix — selectively zeroes one entry. Backbone of QR for sparse and banded matrices.

Unitary vs related classes

PropertyUnitary UOrthogonal Q (real)Hermitian AGeneral invertible M
Defining relationU*U = IQTQ = IA = A*det M ≠ 0
InverseU* (free)QT (free)A⁻¹ ≠ A in generalO(n³) via LU
Eigenvalues|λ| = 1|λ| = 1 (complex pairs)λ ∈ ℝAnywhere in ℂ
Preserves ‖·‖?YesYesNoNo
Preserves ⟨·, ·⟩?YesYes (real inner product)NoNo
Condition number1 (perfect)1Can be hugeAnywhere ≥ 1
|det|11AnythingAnything ≠ 0

The "condition number 1" row is why numerical algorithms reach for unitary transforms: multiplying by U does not amplify finite-precision error.

Application — quantum gates and circuits

A pure quantum state of n qubits is a unit vector ψ in ℂ2n. Time evolution under the Schrödinger equation is the unitary operator U(t) = e−iHt/ℏ, exponentiated from the Hermitian Hamiltonian H. Discrete quantum gates are likewise unitary 2n×2n matrices.

  • Hadamard gate. H = (1/√2)[[1, 1], [1, −1]]. Real orthogonal — the simplest unitary. Maps |0⟩ → (|0⟩ + |1⟩)/√2.
  • Pauli gates. σx, σy, σz — each both unitary and Hermitian. Squaring them gives I.
  • CNOT gate. 4×4 unitary that flips the target qubit iff the control qubit is |1⟩.

A quantum circuit composes these gates into a single 2n×2n unitary. Unitarity is the precise mathematical condition that probability is preserved (Σ|ck|² stays 1 forever).

Application — numerical linear algebra

The QR decomposition factors A = QR with Q unitary (or real-orthogonal) and R upper triangular. The SVD factors A = UΣV* with U and V unitary and Σ diagonal with non-negative entries. Both decompositions use Householder reflectors or Givens rotations — unitary operations — to triangularise or diagonalise A in O(n³) flops with numerical stability superior to LU.

The intuition: applying a unitary matrix has condition number 1, meaning a perturbation δx of input produces a perturbation Uδx of output of the same size. No amplification of floating-point error. LU with partial pivoting can amplify error by 2n in the worst case; unitary algorithms cannot.

NumPy — checking unitarity

import numpy as np

# Build a unitary matrix from a random complex matrix via QR
A = np.random.randn(4, 4) + 1j * np.random.randn(4, 4)
Q, _ = np.linalg.qr(A)

# Unitarity check
print(np.allclose(Q.conj().T @ Q, np.eye(4)))  # True

# Eigenvalues should lie on the unit circle
eigvals = np.linalg.eigvals(Q)
print(np.abs(eigvals))                         # [1., 1., 1., 1.]

# Inverse equals conjugate transpose
print(np.allclose(np.linalg.inv(Q), Q.conj().T))  # True

The np.linalg.qr output Q is guaranteed unitary up to floating-point round-off. If you need an orthonormal basis with specific properties, generate it this way rather than hand-constructing one.

Common pitfalls

  • Confusing orthogonal with orthonormal columns. Pairwise-orthogonal columns make a matrix "having orthogonal columns" but not unitary until you also normalise each column to unit length.
  • Forgetting the conjugate. Over the complex numbers, UTU = I is not the unitarity condition. It is U*U = I — transpose and conjugate.
  • Assuming determinant 1. Unitary requires |det U| = 1, which permits det U = e for any phase. Special unitary SU(n) restricts to det U = 1 exactly.
  • Confusing length-preserving with shape-preserving. A 1D space's projection onto a hyperplane preserves nothing but lengths along that subspace. A genuine unitary preserves all lengths in the full space.
  • Reading "eigenvalues on unit circle" as "real". eiπ/3 is on the unit circle but not real. Unitary eigenvalues have modulus one — generally complex.
  • Inverting a unitary matrix the slow way. Calling np.linalg.inv(U) is O(n³) and accumulates round-off. U.conj().T is O(n²) and exact.

Frequently asked questions

What is a unitary matrix?

A complex square matrix U with U*U = UU* = I, where U* is the conjugate transpose. The inverse is the conjugate transpose, and the columns form an orthonormal basis under the complex inner product.

Why are unitary matrices length-preserving?

‖Ux‖² = (Ux)*(Ux) = x*U*Ux = x*Ix = ‖x‖². The same calculation gives ⟨Ux, Uy⟩ = ⟨x, y⟩ — angles and inner products preserved as well. Unitary maps are isometries of complex inner-product space.

Why do unitary eigenvalues lie on the unit circle?

If Uv = λv, then ‖v‖ = ‖Uv‖ = |λ| ‖v‖, so |λ| = 1. Each eigenvalue is e for some real θ.

What is the relationship between unitary and orthogonal matrices?

Orthogonal matrices are the real-valued unitary matrices. QTQ = I is the real specialisation of U*U = I (conjugation is identity on real numbers). Rotations and reflections in ℝn.

Why is every quantum gate unitary?

Quantum states are unit vectors, and total probability must be preserved — i.e. length must be preserved. The length-preserving linear maps are exactly the unitaries. Hadamard, Pauli, CNOT, every other gate.

Why do numerical algorithms favour unitary transforms?

Condition number 1 — multiplying by U neither magnifies nor shrinks small perturbations. QR, SVD, Householder reflectors, Givens rotations all use unitary or real-orthogonal transformations for this stability.

How do I check whether a matrix is unitary?

Compute U*U and check it equals I. In NumPy: np.allclose(U.conj().T @ U, np.eye(n)).