The Gram–Schmidt process
Statement
Let \( V \) be an inner product space over \( \mathbb{F} \in \{\mathbb{R}, \mathbb{C}\} \), with inner product \( \langle \cdot, \cdot \rangle \) linear in the first slot and conjugate-linear in the second, and let \( (v_1, \dots, v_n) \) be a linearly independent list in \( V \). Then there exists an orthonormal list \( (e_1, \dots, e_n) \) in \( V \) — that is, \( \langle e_i, e_j \rangle = \delta_{ij} \) for all \( i, j \) — such that \[ \operatorname{span}(e_1, \dots, e_k) = \operatorname{span}(v_1, \dots, v_k) \quad \text{for every } k = 1, \dots, n. \] Moreover the list \( (e_1, \dots, e_k) \) satisfying this span condition is unique up to multiplying each \( e_k \) by a scalar of modulus \( 1 \); it is unique outright if one additionally demands \( \langle v_k, e_k \rangle \gt 0 \) for each \( k \). In particular, every finite-dimensional inner product space admits an orthonormal basis.
Why it matters
Gram–Schmidt is the constructive bridge between the algebraic notion of a basis and the geometric notion of an orthonormal frame. Orthonormal bases make everything computable: coordinates become inner products \( x = \sum_j \langle x, e_j \rangle e_j \), norms become Pythagorean sums \( \lVert x \rVert^2 = \sum_j \lvert \langle x, e_j \rangle \rvert^2 \), and orthogonal projections onto subspaces acquire explicit formulas. Without Gram–Schmidt, the existence of orthonormal bases — the fact underlying Fourier analysis, spectral theory, and least squares — would be a bare assertion.
The process is also the theoretical core of the \( QR \) decomposition, the workhorse of numerical linear algebra, and its infinite-dimensional avatar produces the classical families of orthogonal polynomials (Legendre, Hermite, Laguerre, Chebyshev) from the monomials \( 1, x, x^2, \dots \) by nothing more than a choice of inner product.
Hypotheses
Proof
We argue by induction on \( k \), constructing \( e_1, \dots, e_k \) orthonormal with \( \operatorname{span}(e_1, \dots, e_j) = \operatorname{span}(v_1, \dots, v_j) \) for all \( j \leq k \).
Result
Reading. Feed any linearly independent list into the machine one vector at a time; at each stage, subtract off the shadow the new vector casts on what you have already built, and rescale what remains to unit length. The output is an orthonormal list that spans exactly the same flag of subspaces — nothing is gained, nothing is lost, only the frame is straightened.
Scope. Valid in any real or complex inner product space, finite- or infinite-dimensional, complete or not; applies to any finite or countable linearly independent list. It does not require \( V \) itself to be finite-dimensional, and it fails as stated for indefinite bilinear forms, for scalar fields not closed under the needed square roots, and for uncountable lists.
Corollaries & converses
- Orthonormal bases exist. Every finite-dimensional inner product space has an orthonormal basis: apply the process to any basis.
- Extension. Every orthonormal list in a finite-dimensional inner product space extends to an orthonormal basis: extend to a basis, run Gram–Schmidt, and note the process leaves the already-orthonormal initial segment unchanged (each \( u_k = v_k \) when \( v_k \) is already unit and orthogonal to its predecessors).
- \( QR \) decomposition. Every \( A \in GL_n(\mathbb{F}) \) factors uniquely as \( A = QR \) with \( Q \) unitary (orthogonal if \( \mathbb{F} = \mathbb{R} \)) and \( R \) upper triangular with positive diagonal: Gram–Schmidt on the columns of \( A \), with the span condition supplying triangularity of the change of basis.
- Orthogonal complements. For any subspace \( U \) of a finite-dimensional inner product space \( V \), \( V = U \oplus U^{\perp} \): take an orthonormal basis of \( U \), extend, and split.
- Schur triangularisation. Every operator on a finite-dimensional complex inner product space has an upper-triangular matrix with respect to some orthonormal basis: Gram–Schmidt applied to a basis realising triangular form preserves the invariant flag.
- Converse direction. The natural converse — every orthonormal list arises as the Gram–Schmidt output of some independent list — is trivially true (feed the list to itself; the process fixes it). The sharper statement is the uniqueness clause: the span-flag condition pins each \( e_k \) down to a unimodular multiple, so Gram–Schmidt output is canonical once one normalises \( \langle v_k, e_k \rangle \gt 0 \). Note the process is not injective: many different independent lists (e.g. \( (v_1, v_2) \) and \( (v_1, v_2 + v_1) \)) produce the identical orthonormal list.
Fails without
- Positive definiteness dropped. On \( \mathbb{R}^2 \) with \( \langle x, y \rangle = x_1 y_1 - x_2 y_2 \) take \( v_1 = (1, 1) \), \( v_2 = (1, 0) \): a linearly independent list, yet \( \langle v_1, v_1 \rangle = 0 \), so \( e_1 \) cannot be formed — the "unit vector along \( v_1 \)" does not exist, and no list orthonormal for this form spans the null line \( \operatorname{span}(v_1) \).
- Linear independence dropped. In \( \mathbb{R}^2 \) take \( v_1 = (1, 0) \), \( v_2 = (2, 0) \). Then \( u_2 = v_2 - \langle v_2, e_1 \rangle e_1 = (2,0) - 2(1,0) = 0 \), and the recipe divides by \( \lVert u_2 \rVert = 0 \). No orthonormal list of length \( 2 \) can span the \( 1 \)-dimensional space \( \operatorname{span}(v_1, v_2) \), since orthonormal lists are independent.
- Field not closed under the required square roots. In \( \mathbb{Q}^3 \) with the restricted dot product, take \( v_1 = (1, 1, 0) \). Any unit vector spanning \( \operatorname{span}_{\mathbb{Q}}(v_1) \) is \( \pm (1,1,0)/\sqrt{2} \), which has irrational coordinates: orthogonalisation stays inside \( \mathbb{Q}^3 \) (only field operations are used) but orthonormalisation escapes it.
Common errors
- Projecting onto the original vectors. Writing \( u_k = v_k - \sum_j \frac{\langle v_k, v_j \rangle}{\langle v_j, v_j \rangle} v_j \) — subtracting projections onto the raw \( v_j \) rather than the already-orthogonalised \( e_j \) (or \( u_j \)). Unless the \( v_j \) happen to be orthogonal already, the output is not orthogonal.
- Mixing the normalised and unnormalised formulas. The two correct recipes are \( u_k = v_k - \sum_j \langle v_k, e_j \rangle e_j \) (unit \( e_j \)) and \( u_k = v_k - \sum_j \frac{\langle v_k, u_j \rangle}{\langle u_j, u_j \rangle} u_j \) (raw \( u_j \), with the Gram-coefficient denominator). Using unit vectors and dividing by \( \langle e_j, e_j \rangle \) is harmless (it is \( 1 \)), but using raw \( u_j \) without the denominator is wrong.
- Conjugation in the wrong slot (complex case). With the convention linear-in-first-slot, the coefficient is \( \langle v_k, e_j \rangle \), not \( \langle e_j, v_k \rangle = \overline{\langle v_k, e_j \rangle} \). Swapping them silently conjugates every coefficient and destroys orthogonality whenever the inner products are non-real.
- Forgetting the square root. Normalising by \( \langle u_k, u_k \rangle \) instead of \( \lVert u_k \rVert = \sqrt{\langle u_k, u_k \rangle} \), producing vectors of norm \( \lVert u_k \rVert^{-1} \) rather than \( 1 \).
- Assuming order does not matter. Running the process on \( (v_2, v_1) \) generally yields a different orthonormal basis than \( (v_1, v_2) \): the output depends on the flag of nested spans, not just on the subspace.
- Normalising a dependent list. Applying the process to a spanning-but-dependent list and dividing by \( \lVert u_k \rVert = 0 \) at the first redundancy, instead of discarding zero vectors as they appear.
Discussion
The process is named for Jørgen Pedersen Gram, who used the orthogonalisation idea in an 1883 paper on series expansions by least squares, and Erhard Schmidt, who in 1907 stated the recursion in its modern form while building the theory of integral equations that grew into Hilbert space theory. Schmidt himself credited Gram; in fact the essential device is older still, appearing in work of Laplace (1812, in the analysis of observational errors) and in Cauchy. The name is thus a small lesson in how theorems accrete attributions: what is remembered is the formulation that fed into the dominant framework — here, Schmidt's, because it became the existence proof for orthonormal systems in \( L^2 \).
Conceptually, the theorem says the unitary group acts transitively on flags: any complete flag of subspaces \( U_1 \subseteq U_2 \subseteq \dots \subseteq U_n \) with \( \dim U_k = k \) is the flag of an orthonormal basis. This is the geometric content of the span condition, and it is why Gram–Schmidt appears wherever triangular and unitary structures interact — Schur's triangularisation theorem, the \( QR \) decomposition, and the Iwasawa decomposition \( G = KAN \) of \( GL_n(\mathbb{R}) \) (with \( K = O(n) \), \( A \) positive diagonal, \( N \) unipotent upper triangular) are all Gram–Schmidt in different clothing.
Numerically, the classical recursion as proved above is unstable: in floating-point arithmetic, cancellation in \( v_k - \sum_j \langle v_k, e_j \rangle e_j \) makes the computed \( e_k \) lose orthogonality, with error growth governed by the condition number of the input. The modified Gram–Schmidt variant — subtracting each projection immediately, updating \( v_k \leftarrow v_k - \langle v_k, e_j \rangle e_j \) one \( j \) at a time — is mathematically identical (expand the recursion and compare) but dramatically more stable; for orthogonality to machine precision one uses Householder reflections or reorthogonalisation instead. The distinction matters in practice: least-squares solvers built on classical Gram–Schmidt can fail catastrophically on nearly-dependent data.
In infinite dimensions the theorem is the engine of separable Hilbert space theory: applying the process to a countable dense sequence (after discarding dependencies) shows every infinite-dimensional separable Hilbert space has a countable orthonormal basis, whence every such space is isometrically isomorphic to \( \ell^2 \). Applied to the monomials in \( L^2 \big( (a,b), w(x)\,dx \big) \) it produces the classical orthogonal polynomials, and the three-term recurrence they satisfy is a shadow of the fact that multiplication by \( x \) is symmetric. There is also a closed form bypassing the recursion: with Gram determinant \( G_k = \det \big( \langle v_i, v_j \rangle \big)_{i,j \leq k} \), one has \( \lVert u_k \rVert^2 = G_k / G_{k-1} \), and \( u_k \) itself is expressible as a determinant with last row \( v_1, \dots, v_k \) — positivity of all \( G_k \) is exactly linear independence, tying Gram–Schmidt to the theory of positive definite matrices and the Cholesky factorisation \( G = R^{*} R \).
Common misconceptions. The process does not require finite dimension, completeness, or a finite list — only a countable independent list in a pre-Hilbert space. It does not produce "the" orthonormal basis of a subspace: different orderings of the input give genuinely different outputs. And it is not merely approximate in exact arithmetic — instability is a floating-point phenomenon, not a defect of the theorem.
Worked examples
Example 1. Orthonormalise \( v_1 = (1,1,0) \), \( v_2 = (1,0,1) \), \( v_3 = (0,1,1) \) in \( \mathbb{R}^3 \) with the standard dot product.
Reading. An orthonormal basis of \( \mathbb{R}^3 \) whose first vector points along \( v_1 \) and whose first two vectors span the plane of \( v_1, v_2 \) — the nested-span guarantee in action.
Scope. Any reordering of the input would produce a different (equally valid) orthonormal basis.
Example 2 (Legendre polynomials). Orthonormalise \( 1, x, x^2 \) in the space \( \mathcal{P}_2(\mathbb{R}) \) with inner product \( \langle p, q \rangle = \int_{-1}^{1} p(x)\, q(x) \, dx \).
Reading. These are the normalised Legendre polynomials \( \sqrt{\smash[b]{k + \tfrac12}}\, P_k(x) \) for \( k = 0, 1, 2 \): the classical special functions fall out of Gram–Schmidt applied to plain monomials.
Scope. Changing the interval or inserting a weight \( w(x) \gt 0 \) into the integral produces the other classical families (Chebyshev, Hermite, Laguerre) by the identical computation.
Problems
- Apply Gram–Schmidt to \( v_1 = (3, 4) \), \( v_2 = (1, 0) \) in \( \mathbb{R}^2 \) with the dot product, and verify the output is orthonormal.
Solution
\( \lVert v_1 \rVert = \sqrt{9 + 16} = 5 \), so \( e_1 = \left( \tfrac35, \tfrac45 \right) \). Then \( \langle v_2, e_1 \rangle = \tfrac35 \), so \[ u_2 = (1, 0) - \tfrac{3}{5} \left( \tfrac{3}{5}, \tfrac{4}{5} \right) = \left( \tfrac{16}{25}, -\tfrac{12}{25} \right), \qquad \lVert u_2 \rVert = \tfrac{4}{25}\sqrt{16 + 9} = \tfrac{4}{5}, \] giving \( e_2 = \left( \tfrac45, -\tfrac35 \right) \). Verification: \( \langle e_1, e_2 \rangle = \tfrac{12}{25} - \tfrac{12}{25} = 0 \) and \( \lVert e_1 \rVert = \lVert e_2 \rVert = 1 \) since \( 3^2 + 4^2 = 25 \). - Orthonormalise \( v_1 = (1, i) \), \( v_2 = (1, 1) \) in \( \mathbb{C}^2 \) with \( \langle x, y \rangle = x_1 \overline{y_1} + x_2 \overline{y_2} \). Take care with the conjugation.
Solution
\( \lVert v_1 \rVert^2 = 1 + \lvert i \rvert^2 = 2 \), so \( e_1 = \tfrac{1}{\sqrt 2}(1, i) \). The coefficient is \[ \langle v_2, e_1 \rangle = \tfrac{1}{\sqrt 2}\left( 1 \cdot \overline{1} + 1 \cdot \overline{i} \right) = \tfrac{1 - i}{\sqrt 2}. \] Hence \[ u_2 = (1, 1) - \tfrac{1 - i}{\sqrt 2} \cdot \tfrac{1}{\sqrt 2}(1, i) = (1, 1) - \tfrac{1 - i}{2}(1, i) = \left( \tfrac{1 + i}{2}, \; 1 - \tfrac{i - i^2}{2} \right) = \left( \tfrac{1 + i}{2}, \tfrac{1 - i}{2} \right). \] Then \( \lVert u_2 \rVert^2 = \tfrac{\lvert 1 + i \rvert^2}{4} + \tfrac{\lvert 1 - i \rvert^2}{4} = \tfrac{2}{4} + \tfrac{2}{4} = 1 \), so \( e_2 = \left( \tfrac{1 + i}{2}, \tfrac{1 - i}{2} \right) \) already. Check: \[ \langle e_2, e_1 \rangle = \tfrac{1}{\sqrt 2}\left( \tfrac{1 + i}{2} \cdot \overline{1} + \tfrac{1 - i}{2} \cdot \overline{i} \right) = \tfrac{1}{2\sqrt 2}\left( (1 + i) + (1 - i)(-i) \right) = \tfrac{1}{2\sqrt 2}\left( 1 + i - i - 1 \right) = 0. \] The classic error here is to use \( \langle e_1, v_2 \rangle = \tfrac{1 + i}{\sqrt 2} \) instead: doing so leaves \( \langle u_2, e_1 \rangle = \tfrac{1-i}{\sqrt2} - \tfrac{1+i}{\sqrt2} \neq 0 \). - Prove directly that every orthonormal list \( (e_1, \dots, e_n) \) is linearly independent, and deduce that an orthonormal list in an \( n \)-dimensional inner product space has length at most \( n \).
Solution
Suppose \( \sum_{j=1}^{n} a_j e_j = 0 \) with \( a_j \in \mathbb{F} \). Fix \( i \) and take the inner product with \( e_i \): by linearity in the first slot, \[ 0 = \Big\langle \sum_j a_j e_j, \, e_i \Big\rangle = \sum_j a_j \langle e_j, e_i \rangle = \sum_j a_j \delta_{ji} = a_i. \] Since \( i \) was arbitrary, all coefficients vanish, so the list is independent. In an \( n \)-dimensional space every linearly independent list has length at most \( n \) (any list longer than a spanning list is dependent — the exchange lemma), so orthonormal lists have length at most \( n \). Equality forces the list to be a basis, since an independent list of length \( \dim V \) spans. - Find the first three orthonormal polynomials for the inner product \( \langle p, q \rangle = \int_{0}^{1} p(x) q(x)\, dx \) on \( \mathcal{P}_2(\mathbb{R}) \), starting from \( 1, x, x^2 \). (These are the shifted Legendre polynomials; parity no longer helps, so every projection must be computed.)
Solution
\( \lVert 1 \rVert^2 = \int_0^1 dx = 1 \), so \( e_1 = 1 \). Next, \( \langle x, e_1 \rangle = \int_0^1 x\,dx = \tfrac12 \), so \( u_2 = x - \tfrac12 \) and \[ \lVert u_2 \rVert^2 = \int_0^1 \left( x - \tfrac12 \right)^2 dx = \tfrac{1}{12}, \qquad e_2 = 2\sqrt{3}\left( x - \tfrac12 \right) = \sqrt{3}\,(2x - 1). \] For \( x^2 \): \( \langle x^2, e_1 \rangle = \tfrac13 \) and \[ \langle x^2, e_2 \rangle = 2\sqrt{3} \int_0^1 x^2 \left( x - \tfrac12 \right) dx = 2\sqrt{3}\left( \tfrac14 - \tfrac16 \right) = \tfrac{\sqrt 3}{6}. \] Hence \[ u_3 = x^2 - \tfrac13 - \tfrac{\sqrt 3}{6} \cdot 2\sqrt{3}\left( x - \tfrac12 \right) = x^2 - \tfrac13 - \left( x - \tfrac12 \right) = x^2 - x + \tfrac16. \] Then \[ \lVert u_3 \rVert^2 = \int_0^1 \left( x^4 - 2x^3 + \tfrac43 x^2 - \tfrac13 x + \tfrac{1}{36} \right) dx = \tfrac15 - \tfrac12 + \tfrac49 - \tfrac16 + \tfrac{1}{36} = \tfrac{36 - 90 + 80 - 30 + 5}{180} = \tfrac{1}{180}, \] so \( \lVert u_3 \rVert = \tfrac{1}{6\sqrt 5} \) and \( e_3 = 6\sqrt{5}\left( x^2 - x + \tfrac16 \right) = \sqrt{5}\,(6x^2 - 6x + 1) \). - (\( QR \) decomposition.) Let \( A \in GL_n(\mathbb{R}) \). Prove that \( A = QR \) for some orthogonal matrix \( Q \) and upper triangular \( R \) with strictly positive diagonal entries, and prove this factorisation is unique.
Solution
Existence. The columns \( v_1, \dots, v_n \) of \( A \) are linearly independent since \( A \) is invertible. Run Gram–Schmidt to obtain an orthonormal basis \( e_1, \dots, e_n \) of \( \mathbb{R}^n \) with \( \operatorname{span}(e_1, \dots, e_k) = \operatorname{span}(v_1, \dots, v_k) \) for all \( k \). By that span condition, each \( v_k \) is a combination of \( e_1, \dots, e_k \) only: \[ v_k = \sum_{j=1}^{k} r_{jk} e_j, \qquad r_{jk} = \langle v_k, e_j \rangle \ (j \lt k), \qquad r_{kk} = \lVert u_k \rVert \gt 0, \] reading off Step 7 of the theorem. Let \( Q \) have columns \( e_1, \dots, e_n \) (orthogonal because its columns are orthonormal) and let \( R = (r_{jk}) \), upper triangular with \( r_{kk} \gt 0 \). Column by column, \( QR \) has \( k \)-th column \( \sum_j r_{jk} e_j = v_k \), so \( A = QR \). Uniqueness. Suppose \( Q_1 R_1 = Q_2 R_2 \) with both factorisations of the stated form. Then \[ Q_2^{\top} Q_1 = R_2 R_1^{-1} =: S. \] The left side is orthogonal (product of orthogonals); the right side is upper triangular with positive diagonal (inverses and products of such matrices are such: the diagonal of \( R_2 R_1^{-1} \) is \( \big( (r_2)_{kk} / (r_1)_{kk} \big)_k \gt 0 \)). So \( S \) is an orthogonal, upper triangular matrix with positive diagonal. Then \( S^{-1} = S^{\top} \) is simultaneously upper triangular (inverse of upper triangular) and lower triangular (transpose of upper triangular), hence diagonal; so \( S \) is diagonal with \( S^{\top} S = I \), forcing \( s_{kk}^2 = 1 \), and positivity gives \( s_{kk} = 1 \). Thus \( S = I \), i.e. \( Q_1 = Q_2 \) and \( R_1 = R_2 \). (This mirrors the unimodular-uniqueness clause of the theorem: positive diagonal is exactly the normalisation \( \langle v_k, e_k \rangle \gt 0 \).)