Algorithm Search⌘K

Proofs: Gram-Schmidt process

These are the human proofs of Gram-Schmidt process, at full length.

Flop count of Gram-Schmidt full

This proof shows: flops.worst, time.worst, space.extra.

Count additions, subtractions, multiplications and divisions; square roots are counted separately.

MGS. Pass jj: line L2 is a squared norm of length mm, 2m−12m - 1 flops, plus a square root; line L4 is mm divisions; for each of the n−jn - j values of kk, line L6 is a dot product (2m−12m - 1 flops) and line L7 a vector update (2m2m flops). Summing over jj:

∑j=1n(3m−1+(n−j)(4m−1))=n(3m−1)+n(n−1)2(4m−1)=2mn2+mn−n2+n2,\sum_{j=1}^{n} \bigl( 3m - 1 + (n - j)(4m - 1) \bigr) = n(3m - 1) + \frac{n(n - 1)}{2} (4m - 1) = 2 m n^2 + m n - \frac{n^2 + n}{2},

which is 2mn2+O(mn)2 m n^2 + O(m n), with nn square roots.

CGS. Column jj needs j−1j - 1 dot products and j−1j - 1 updates of length mm, the same counts as MGS for the pairs (i,j)(i, j) with i<ji < j, and the same norm and division. So the total is the same: 2mn2+O(mn)2 m n^2 + O(m n). CGS2 doubles the dot products and updates: 4mn2+O(mn)4 m n^2 + O(m n).

Time and space. Every flop takes constant time, so the time is Θ(mn2)\Theta(m n^2). Besides AA, which is overwritten by QQ, the algorithm stores RR: n(n+1)/2n(n + 1)/2 numbers, that is Θ(n2)\Theta(n^2). □\square

■\blacksquare

Gram-Schmidt computes the thin QR factorization full

This proof shows: correctness, termination.

Exact arithmetic. A=[a1,…,an]∈Rm×nA = [a_1, \ldots, a_n] \in \mathbb{R}^{m \times n}, Sj=span⁡{a1,…,aj}S_j = \operatorname{span}\{a_1, \ldots, a_j\}, S0={0}S_0 = \{0\}. Write ak(j)a_k^{(j)} for the content of column kk after the first jj passes of the outer loop of MGS (ak(0)=aka_k^{(0)} = a_k).

Lemma 1 (MGS invariant). Suppose passes 1,…,j1, \ldots, j of MGS completed. Then q1,…,qjq_1, \ldots, q_j are orthonormal, span⁡{q1,…,qi}=Si\operatorname{span}\{q_1, \ldots, q_i\} = S_i for i≤ji \le j, and for every k>jk > j

ak(j)=ak−∑i=1jrikqi,qiTak(j)=0 (i≤j),rik=qiTak (i≤j).a_k^{(j)} = a_k - \sum_{i=1}^{j} r_{ik} q_i, \qquad q_i^T a_k^{(j)} = 0 \ (i \le j), \qquad r_{ik} = q_i^T a_k \ (i \le j).

Proof. Induction on jj; j=0j = 0 is empty. Assume it for j−1j - 1. Pass jj sets qj=aj(j−1)/rjjq_j = a_j^{(j-1)} / r_{jj} with rjj=∥aj(j−1)∥2>0r_{jj} = \|a_j^{(j-1)}\|_2 > 0 (lines L2 to L4). By the hypothesis aj(j−1)a_j^{(j-1)} is orthogonal to q1,…,qj−1q_1, \ldots, q_{j-1}, so q1,…,qjq_1, \ldots, q_j are orthonormal. Also aj(j−1)=aj−∑i<jrijqia_j^{(j-1)} = a_j - \sum_{i<j} r_{ij} q_i lies in SjS_j and aja_j lies in span⁡{q1,…,qj}\operatorname{span}\{q_1, \ldots, q_j\}, so with span⁡{q1,…,qj−1}=Sj−1\operatorname{span}\{q_1, \ldots, q_{j-1}\} = S_{j-1} the spans agree. For k>jk > j, line L6 sets rjk=qjTak(j−1)=qjTak−∑i<jrikqjTqi=qjTakr_{jk} = q_j^T a_k^{(j-1)} = q_j^T a_k - \sum_{i<j} r_{ik} q_j^T q_i = q_j^T a_k, and line L7 gives ak(j)=ak(j−1)−rjkqja_k^{(j)} = a_k^{(j-1)} - r_{jk} q_j, which is the displayed formula. Then qjTak(j)=rjk−rjk=0q_j^T a_k^{(j)} = r_{jk} - r_{jk} = 0, and for i<ji < j, qiTak(j)=qiTak(j−1)−rjkqiTqj=0q_i^T a_k^{(j)} = q_i^T a_k^{(j-1)} - r_{jk} q_i^T q_j = 0. □\square

Theorem 1 (MGS). If AA has rank nn, MGS does not fail and returns QQ with QTQ=IQ^T Q = I and RR upper triangular with rjj>0r_{jj} > 0 and A=QRA = Q R. If AA has rank less than nn, MGS fails at the least jj with aj∈Sj−1a_j \in S_{j-1}.

Proof. Before pass jj, Lemma 1 gives aj(j−1)=aj−Pj−1aja_j^{(j-1)} = a_j - P_{j-1} a_j, where Pj−1=∑i<jqiqiTP_{j-1} = \sum_{i<j} q_i q_i^T is the orthogonal projector onto Sj−1S_{j-1}, since rij=qiTajr_{ij} = q_i^T a_j. So rjj=0r_{jj} = 0 exactly when aj∈Sj−1a_j \in S_{j-1}. With rank nn this never happens. Then aj=aj(j−1)+∑i<jrijqi=∑i≤jrijqia_j = a_j^{(j-1)} + \sum_{i<j} r_{ij} q_i = \sum_{i \le j} r_{ij} q_i, which is column jj of QRQ R with rij=0r_{ij} = 0 for i>ji > j. If the rank is less than nn, some aja_j lies in Sj−1S_{j-1}; at the least such jj the passes before it succeed and pass jj meets rjj=0r_{jj} = 0 in line L3. □\square

Theorem 2 (CGS gives the same factors). If AA has rank nn, CGS returns the same QQ and RR as MGS; it fails at the same step otherwise.

Proof. Induction on jj. If q1,…,qj−1q_1, \ldots, q_{j-1} agree, line C2 computes rij=qiTajr_{ij} = q_i^T a_j, which by Lemma 1 is what MGS uses, and line C3 computes v=aj−∑i<jrijqi=aj(j−1)v = a_j - \sum_{i<j} r_{ij} q_i = a_j^{(j-1)}. So rjjr_{jj} and qjq_j agree. □\square

Theorem 3 (uniqueness and the determinant formula). If A=QR=Q′R′A = Q R = Q' R' are two thin QR factorizations with positive diagonals, then Q=Q′Q = Q' and R=R′R = R'. Moreover rjj2=det⁡Gj/det⁡Gj−1r_{jj}^2 = \det G_j / \det G_{j-1}, where GjG_j is the leading j×jj \times j block of G=ATAG = A^T A and det⁡G0=1\det G_0 = 1.

Proof. ATA=RTR=R′TR′A^T A = R^T R = R'^T R' are two Cholesky factorizations of the positive definite ATAA^T A, and the Cholesky factor with positive diagonal is unique (see the Cholesky decomposition). So R=R′R = R' and Q=AR−1=Q′Q = A R^{-1} = Q'. The leading block satisfies Gj=RjTRjG_j = R_j^T R_j with RjR_j the leading block of RR, so det⁡Gj=∏i≤jrii2\det G_j = \prod_{i \le j} r_{ii}^2, and the ratio of consecutive determinants is rjj2r_{jj}^2. □\square

Termination. All loops have fixed bounds; the procedures stop after nn outer passes or at the first failure. □\square

■\blacksquare

Back to Gram-Schmidt process