Sparse Matrices
A sparse matrix is a matrix whose useful structure is carried by relatively few nonzero entries. Instead of storing every one of its entries, a sparse algorithm stores only the nonzeros and the indexing information needed to find them.
Sparse matrices matter in quantum mechanics because many numerical Hamiltonians are local. A finite-difference kinetic energy couples nearby grid points. A local spin-chain Hamiltonian changes only a few sites at a time. A tight-binding model connects neighboring orbitals. These systems may have enormous Hilbert spaces, while each basis vector couples to only a small fraction of all other basis vectors.
The word sparse is not only a visual description. It is a computational contract: algorithms should use the number of nonzero entries, not the number of possible entries, as the main cost scale.
Definition
Section titled “Definition”For an matrix , define
A dense algorithm typically stores and manipulates all entries. A sparse algorithm is useful when
The precise meaning depends on the family of problems. A tridiagonal matrix has only nonzero entries, so it remains sparse as grows. A matrix with nonzeros may look mostly empty on a small plot, but it is still quadratic in storage and usually behaves more like a dense matrix at large .
Why Quantum Hamiltonians Are Often Sparse
Section titled “Why Quantum Hamiltonians Are Often Sparse”Sparsity usually comes from locality or selection rules:
- a one-dimensional finite-difference Hamiltonian couples each grid point only to nearby grid points;
- a local potential is diagonal in a position grid;
- nearest-neighbor tight-binding models connect only adjacent sites;
- few-body spin interactions flip or compare a small number of spins;
- angular-momentum selection rules can forbid many matrix elements;
- symmetry block decomposition splits one large matrix into smaller independent blocks.
Sparsity is representation-dependent. The same operator can be sparse in one basis and dense in another. A kinetic-energy operator is diagonal in momentum space but a local potential is diagonal in position space. A Fourier method may avoid a sparse matrix entirely and use transforms instead.
For the continuum-to-finite step, see Discretization. For the standard grid derivative construction, see Finite Difference Methods.
Dense Versus Sparse Storage
Section titled “Dense Versus Sparse Storage”A dense matrix stores every entry:
This is simple and efficient for small matrices, but memory grows like . For , dense storage is not a practical representation.
Sparse storage records the nonzero values and enough integer indices to reconstruct their positions. The cost is roughly proportional to , with an additional indexing overhead. That overhead is worthwhile only when the matrix is genuinely sparse and the algorithm respects the sparse structure.
Common Sparse Formats
Section titled “Common Sparse Formats”Several storage formats are standard. The best one depends on how the matrix is assembled and used.
| Format | Idea | Typical use |
|---|---|---|
| COO | store triples | easy assembly from local contributions |
| CSR | compressed sparse row storage | fast row-wise matrix-vector products |
| CSC | compressed sparse column storage | column access and some factorizations |
| DIA | store diagonals by offset | banded finite-difference matrices |
| BSR | store dense blocks sparsely | spin, orbital, or multi-component systems |
COO is convenient while building a matrix because one can append local terms. CSR is usually better once the matrix is fixed, because matrix-vector multiplication reads one row at a time. CSC is the column-oriented analogue and is useful in some direct solvers.
Block sparse formats are common when each grid point or lattice site carries internal degrees of freedom. For example, a spinor wavefunction with two components per grid point often gives a sparse matrix whose nonzero entries are small dense blocks.
Finite-Difference Example
Section titled “Finite-Difference Example”For a one-dimensional grid with Dirichlet boundaries, the standard second-difference kinetic-energy operator has a tridiagonal matrix. Up to constants and the potential term, the Hamiltonian has the form
The diagonal entries include the potential and the diagonal kinetic contribution. The off-diagonal entries come from nearest-neighbor coupling. The number of nonzero entries is
This is why a grid with millions of points can still be meaningful for certain one-dimensional or structured problems, even though a dense matrix of the same dimension would be impossible to store.
Tensor-Product Grids
Section titled “Tensor-Product Grids”In more than one dimension, separable grid operators often have Kronecker-sum structure. For a two-dimensional Cartesian grid, a schematic Hamiltonian is
Here and are one-dimensional second-difference matrices, and is diagonal if the potential is evaluated pointwise. If there are points in each coordinate and total grid points, each row still couples to only a small stencil of nearby points. The storage grows like a constant times , not like .
For dimensions with a nearest-neighbor stencil, the number of nonzero entries is typically of order , where is the total number of grid points. This scaling is still large because grows rapidly with dimension, but sparsity prevents an additional square in the storage.
The tensor-product notation itself is reviewed in Tensor Products.
Matrix-Vector Products
Section titled “Matrix-Vector Products”The central sparse operation is not usually forming all eigenvectors. It is applying the matrix to a vector:
In components, a sparse matrix-vector product reads
The cost is proportional to rather than . This operation is the engine behind Sparse Eigensolvers, iterative linear solvers, many Time-Stepping Methods, and matrix-free operator implementations.
For a finite-difference Hamiltonian, the same multiplication can often be written directly as a stencil action. In one dimension,
This formula may be faster and clearer than explicitly storing the matrix, especially when boundary conditions are simple.
Matrix-Free Operators
Section titled “Matrix-Free Operators”Some large quantum calculations never store the sparse matrix at all. They provide a routine that computes for any input vector . This is called a matrix-free representation.
Matrix-free methods are natural when:
- the operator is a simple stencil;
- the Hamiltonian is assembled from local terms on demand;
- the basis is too large for even sparse storage;
- the action uses fast transforms rather than matrix entries;
- only a few eigenvalues or time steps are needed.
The tradeoff is that matrix-free operators are harder to inspect. One should still test Hermiticity, norms, boundary behavior, and benchmark cases.
Hermiticity and Weighted Inner Products
Section titled “Hermiticity and Weighted Inner Products”For closed-system quantum mechanics, the finite Hamiltonian should represent a self-adjoint operator. In an ordinary Euclidean finite-dimensional inner product, this means
Sparse assembly can accidentally break Hermiticity. Common causes include adding an off-diagonal entry without adding the conjugate entry , applying boundary rows asymmetrically, or mixing indexing conventions.
On nonuniform grids or quadrature-based discretizations, the correct inner product may be weighted:
Then self-adjointness is the condition
This is not the same as ordinary matrix symmetry unless is proportional to the identity. The weighted-inner-product issue is introduced in Discretization, and quadrature weights are treated in Numerical Quadrature.
Sparse Does Not Mean Easy
Section titled “Sparse Does Not Mean Easy”Sparse storage solves the memory problem for matrix entries, but it does not remove all numerical difficulty.
Sparse direct factorizations can create fill-in: entries that were zero in become nonzero in triangular factors. The inverse of a sparse matrix is usually dense. Therefore, computing explicitly is almost never the right way to solve a large quantum problem.
Conditioning is a separate issue. A sparse matrix can be ill conditioned, and a dense matrix can be well conditioned. For example, refining a finite-difference grid often makes derivative matrices larger and more ill conditioned, even though they remain sparse. The sensitivity language is developed in Conditioning and Stability.
Sparse Eigenvalue Problems
Section titled “Sparse Eigenvalue Problems”Dense diagonalization is appropriate when all eigenvalues and eigenvectors of a modest matrix are needed. Sparse Hamiltonians are different. One usually asks for a few extremal or interior eigenvalues, such as the ground state and low-lying excitations.
Those computations are built from repeated matrix-vector products, orthogonalization, residual checks, and convergence tests. The important point on this page is that sparse storage makes the matrix-vector products possible. The eigensolver algorithms themselves are treated in Sparse Eigensolvers.
Do not expect sparse methods to compute the entire spectrum of a huge Hamiltonian cheaply. Sparsity helps selected computations; it does not defeat Hilbert-space dimension.
Practical Assembly Checklist
Section titled “Practical Assembly Checklist”When assembling a sparse Hamiltonian, record:
- the basis or grid ordering;
- the indexing convention;
- the boundary rows or boundary terms;
- the storage format used for assembly and for computation;
- whether duplicate COO entries are summed;
- the inner product in which Hermiticity is tested;
- the number of degrees of freedom and ;
- the cost of one matrix-vector product;
- the benchmark problem used to test the implementation.
These details are not low-level clutter. They determine whether a numerical result is reproducible.
Common Mistakes
Section titled “Common Mistakes”- Building a dense matrix first and converting it to sparse afterward.
- Assuming a matrix is sparse because a small plot looks mostly empty.
- Confusing sparse storage with good conditioning.
- Forgetting the conjugate partner of an off-diagonal complex entry.
- Treating as the right test when the discretized inner product is weighted.
- Computing an explicit inverse instead of using solves or matrix-vector products.
- Ignoring fill-in during sparse factorization.
- Expecting a sparse eigensolver to return all eigenpairs efficiently.
- Changing basis and assuming sparsity survives.
- Reporting a large sparse calculation without , boundary conventions, or residual checks.
Cross-Links
Section titled “Cross-Links”- Discretization
- Finite Difference Methods
- Numerical Quadrature
- Matrix Diagonalization
- Sparse Eigensolvers
- Exact Diagonalization Preview
- Transverse-Field Ising Model
- XXZ Spin Chain
- Time-Stepping Methods
- Matrix Exponentials Numerically
- Conditioning and Stability
- Floating-Point Arithmetic
- Spectral Methods
- Matrices as Linear Maps
- Tensor Products
- Time-Independent Schrödinger Equation
References
Section titled “References”- T. A. Davis, Direct Methods for Sparse Linear Systems, SIAM, 2006.
- Y. Saad, Iterative Methods for Sparse Linear Systems, 2nd ed., SIAM, 2003.
- Y. Saad, Numerical Methods for Large Eigenvalue Problems, revised ed., SIAM, 2011.
- G. H. Golub and C. F. Van Loan, Matrix Computations, 4th ed., Johns Hopkins University Press, 2013.
- L. N. Trefethen and D. Bau, Numerical Linear Algebra, SIAM, 1997.
- J. M. Thijssen, Computational Physics, 2nd ed., Cambridge University Press, 2007.
Exercises
Section titled “Exercises”- A tridiagonal matrix has nonzero entries only on the main diagonal and the two neighboring diagonals. Count its nonzero entries.
Solution
The main diagonal contributes entries. The upper diagonal has entries, and the lower diagonal has entries. Therefore
- On a square grid, suppose each interior point couples to itself and its four nearest neighbors. How does the number of nonzero matrix entries scale with the total number of grid points?
Solution
Each interior row has about five nonzero entries, while boundary rows have fewer. Thus
up to boundary corrections. The scaling is linear in the number of grid points, not quadratic in .
- Why can a sparse finite-difference Hamiltonian fail to be Hermitian even when the intended differential operator is self-adjoint?
Solution
The discrete assembly may treat boundary rows asymmetrically, omit conjugate off-diagonal entries, use inconsistent indexing, or test symmetry in the wrong inner product. Self-adjointness is a property of the discretized operator with its chosen domain and inner product, not only of the formal differential expression.
- Explain why explicitly forming is usually a bad strategy for a large sparse linear problem.
Solution
Even when is sparse, its inverse is usually dense. Forming can destroy the memory advantage of sparsity and amplify numerical errors. Large sparse problems are usually solved by sparse factorizations, iterative methods, or matrix-vector-product based algorithms, depending on the structure and conditioning.