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 j: line L2 is a squared norm of length m, 2m−1 flops, plus a square root; line L4 is m divisions; for each of the n−j values of k, line L6 is a dot product (2m−1 flops) and line L7 a vector update (2m flops). Summing over j:
j=1∑n(3m−1+(n−j)(4m−1))=n(3m−1)+2n(n−1)(4m−1)=2mn2+mn−2n2+n, which is 2mn2+O(mn), with n square roots.
CGS. Column j needs j−1 dot products and j−1 updates of length m, the same counts as MGS for the pairs (i,j) with i<j, and the same norm and division. So the total is the same: 2mn2+O(mn). CGS2 doubles the dot products and updates: 4mn2+O(mn).
Time and space. Every flop takes constant time, so the time is Θ(mn2). Besides A, which is overwritten by Q, the algorithm stores R: n(n+1)/2 numbers, that is Θ(n2). □
■
Gram-Schmidt computes the thin QR factorization full
This proof shows: correctness, termination.
Exact arithmetic. A=[a1,…,an]∈Rm×n, Sj=span{a1,…,aj}, S0={0}. Write ak(j) for the content of column k after the first j passes of the outer loop of MGS (ak(0)=ak).
Lemma 1 (MGS invariant). Suppose passes 1,…,j of MGS completed. Then q1,…,qj are orthonormal, span{q1,…,qi}=Si for i≤j, and for every k>j
ak(j)=ak−i=1∑jrikqi,qiTak(j)=0 (i≤j),rik=qiTak (i≤j). Proof. Induction on j; j=0 is empty. Assume it for j−1. Pass j sets qj=aj(j−1)/rjj with rjj=∥aj(j−1)∥2>0 (lines L2 to L4). By the hypothesis aj(j−1) is orthogonal to q1,…,qj−1, so q1,…,qj are orthonormal. Also aj(j−1)=aj−∑i<jrijqi lies in Sj and aj lies in span{q1,…,qj}, so with span{q1,…,qj−1}=Sj−1 the spans agree. For k>j, line L6 sets rjk=qjTak(j−1)=qjTak−∑i<jrikqjTqi=qjTak, and line L7 gives ak(j)=ak(j−1)−rjkqj, which is the displayed formula. Then qjTak(j)=rjk−rjk=0, and for i<j, qiTak(j)=qiTak(j−1)−rjkqiTqj=0. □
Theorem 1 (MGS). If A has rank n, MGS does not fail and returns Q with QTQ=I and R upper triangular with rjj>0 and A=QR. If A has rank less than n, MGS fails at the least j with aj∈Sj−1.
Proof. Before pass j, Lemma 1 gives aj(j−1)=aj−Pj−1aj, where Pj−1=∑i<jqiqiT is the orthogonal projector onto Sj−1, since rij=qiTaj. So rjj=0 exactly when aj∈Sj−1. With rank n this never happens. Then aj=aj(j−1)+∑i<jrijqi=∑i≤jrijqi, which is column j of QR with rij=0 for i>j. If the rank is less than n, some aj lies in Sj−1; at the least such j the passes before it succeed and pass j meets rjj=0 in line L3. □
Theorem 2 (CGS gives the same factors). If A has rank n, CGS returns the same Q and R as MGS; it fails at the same step otherwise.
Proof. Induction on j. If q1,…,qj−1 agree, line C2 computes rij=qiTaj, which by Lemma 1 is what MGS uses, and line C3 computes v=aj−∑i<jrijqi=aj(j−1). So rjj and qj agree. □
Theorem 3 (uniqueness and the determinant formula). If A=QR=Q′R′ are two thin QR factorizations with positive diagonals, then Q=Q′ and R=R′. Moreover rjj2=detGj/detGj−1, where Gj is the leading j×j block of G=ATA and detG0=1.
Proof. ATA=RTR=R′TR′ are two Cholesky factorizations of the positive definite ATA, and the Cholesky factor with positive diagonal is unique (see the Cholesky decomposition). So R=R′ and Q=AR−1=Q′. The leading block satisfies Gj=RjTRj with Rj the leading block of R, so detGj=∏i≤jrii2, and the ratio of consecutive determinants is rjj2. □
Termination. All loops have fixed bounds; the procedures stop after n outer passes or at the first failure. □
■