Algorithm Search⌘K

Proofs: QR decomposition

These are the human proofs of QR decomposition, at full length.

Householder QR produces an orthogonal Q and an upper triangular R with A = Q R full

This proof shows: correctness, termination.

A∈Rm×nA \in \mathbb{R}^{m \times n} with m≥n≥1m \ge n \ge 1. Each loop has a fixed length, so the algorithm stops after nn steps.

The reflection

Lemma 1. For v≠0v \ne 0 and β=2/(vTv)\beta = 2/(v^T v), the matrix H=I−βvvTH = I - \beta v v^T is symmetric and orthogonal.

Proof. HT=HH^T = H is clear. HTH=H2=I−2βvvT+β2v(vTv)vT=I−2βvvT+2βvvT=IH^T H = H^2 = I - 2\beta v v^T + \beta^2 v (v^T v) v^T = I - 2\beta v v^T + 2\beta v v^T = I, using β vTv=2\beta\, v^T v = 2. □\square

Lemma 2. Let a∈Rpa \in \mathbb{R}^p be nonzero, α=−sign⁡(a1)∥a∥2\alpha = -\operatorname{sign}(a_1)\|a\|_2 with sign⁡(0)=1\operatorname{sign}(0) = 1, and v=a−αe1v = a - \alpha e_1. Then v≠0v \ne 0 and Ha=αe1H a = \alpha e_1.

Proof. v1=a1−α=a1+sign⁡(a1)∥a∥2v_1 = a_1 - \alpha = a_1 + \operatorname{sign}(a_1)\|a\|_2, and both terms have the same sign with ∥a∥2>0\|a\|_2 > 0, so ∣v1∣≥∥a∥2>0|v_1| \ge \|a\|_2 > 0. Next, vTv=∥a∥22−2αa1+α2=2(∥a∥22−αa1)v^T v = \|a\|_2^2 - 2\alpha a_1 + \alpha^2 = 2(\|a\|_2^2 - \alpha a_1) because α2=∥a∥22\alpha^2 = \|a\|_2^2, and vTa=∥a∥22−αa1v^T a = \|a\|_2^2 - \alpha a_1. So β vTa=1\beta\, v^T a = 1 and Ha=a−v=αe1H a = a - v = \alpha e_1. □\square

The algorithm

Invariant. Before step kk the array holds A(k)=Hk−1⋯H1AA^{(k)} = H_{k-1} \cdots H_1 A, where Hj=diag⁡(Ij−1,H~j)H_j = \operatorname{diag}(I_{j-1}, \tilde H_j) and H~j\tilde H_j is the reflection of step jj (the identity if the active column was zero). The first k−1k - 1 columns of A(k)A^{(k)} are zero below the diagonal.

Proof by induction on kk. For k=1k = 1 there is nothing to show. At step kk, if ak:m,k(k)=0a^{(k)}_{k:m,k} = 0, then Hk=IH_k = I and the claim for k+1k + 1 holds since column kk is already zero below the diagonal. Otherwise lines L2 and L3 build vv and β\beta as in Lemma 2 for a=ak:m,k(k)a = a^{(k)}_{k:m,k}, and line L5 records the result αe1\alpha e_1 of Lemma 2 in column kk. Line L4 applies H~k\tilde H_k to rows k,…,mk, \ldots, m of the columns j>kj > k: ak:m,j−βv(vTak:m,j)=H~kak:m,ja_{k:m,j} - \beta v (v^T a_{k:m,j}) = \tilde H_k a_{k:m,j}. Rows 1,…,k−11, \ldots, k - 1 are not touched, which is the action of Hk=diag⁡(Ik−1,H~k)H_k = \operatorname{diag}(I_{k-1}, \tilde H_k). Columns 1,…,k−11, \ldots, k - 1 are zero in rows k,…,mk, \ldots, m, so HkH_k leaves them unchanged and they stay zero below the diagonal. So the array is HkA(k)=A(k+1)H_k A^{(k)} = A^{(k+1)}, with columns 1,…,k1, \ldots, k zero below the diagonal. □\square

Theorem. After step nn, R=Hn⋯H1AR = H_n \cdots H_1 A is upper triangular and A=QRA = Q R with Q=H1H2⋯HnQ = H_1 H_2 \cdots H_n orthogonal.

Proof. By the invariant with k=n+1k = n + 1, all nn columns are zero below the diagonal. Each HkH_k is orthogonal and symmetric by Lemma 1, so Q=H1⋯HnQ = H_1 \cdots H_n is orthogonal and QT=Hn⋯H1Q^T = H_n \cdots H_1. Then QTA=RQ^T A = R, and A=QRA = Q R. ■\blacksquare

Least squares. If AA has full column rank, then R1R_1 (the top n×nn \times n block) is nonsingular, because R1TR1=RTR=ATQQTA=ATAR_1^T R_1 = R^T R = A^T Q Q^T A = A^T A is positive definite. For each xx, ∥b−Ax∥2=∥QTb−Rx∥2\|b - A x\|_2 = \|Q^T b - R x\|_2 because QTQ^T preserves the 2-norm, and with QTb=(c1,c2)Q^T b = (c_1, c_2) this equals (∥c1−R1x∥22+∥c2∥22)1/2(\|c_1 - R_1 x\|_2^2 + \|c_2\|_2^2)^{1/2}. It is minimized exactly when R1x=c1R_1 x = c_1. If some rkk=0r_{kk} = 0 then det⁡(ATA)=∏rkk2=0\det(A^T A) = \prod r_{kk}^2 = 0, so AA is rank deficient; the implementation reports this case.

Floating point

Higham (Section 19.3) proves that the computed R^\hat R satisfies A+ΔA=QR^A + \Delta A = Q \hat R for the exactly orthogonal Q=H1⋯HnQ = H_1 \cdots H_n built from the exact reflectors of the computed columns, with ∥Δaj∥2≤γ~mn∥aj∥2\|\Delta a_j\|_2 \le \tilde\gamma_{mn}\|a_j\|_2. The idea is that each computed application fl(H~ky)\mathrm{fl}(\tilde H_k y) equals H~k(y+Δy)\tilde H_k (y + \Delta y) with ∥Δy∥2≤γ~m∥y∥2\|\Delta y\|_2 \le \tilde\gamma_m \|y\|_2, because the computed v^\hat v is close to the exact vv relative to its norm (thanks to the sign choice of line L2), and an orthogonal map does not change the size of a perturbation. Accumulating nn such steps, each of relative size γ~m\tilde\gamma_m in the 2-norm of the column, gives γ~mn\tilde\gamma_{mn}. The tests measure ∥A−Q^R^∥F/∥A∥F\|A - \hat Q \hat R\|_F/\|A\|_F and ∥Q^TQ^−I∥F\|\hat Q^T \hat Q - I\|_F exactly and check them against 4mnu4 m n u.

Back to QR decomposition