Algorithm Search⌘K

Proofs: LU decomposition

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

LU-DECOMPOSE returns P A = L U with U in echelon form, and LU-SOLVE solves A x = b full

This proof shows: correctness, termination.

We use the notation of the page. AA is m×nm \times n over a field KK. For a permutation π\pi of {1,…,m}\{1, \ldots, m\}, PπP_\pi is the matrix with (PπA)(P_\pi A) row rr equal to row π(r)\pi(r) of AA. EijE_{ij} is the m×mm \times m matrix with 11 in place (i,j)(i, j) and 00 elsewhere.

Termination. The loop of line L2 runs at most nn times, and the inner loops of lines L6 and L8 have fixed bounds. So LU-DECOMPOSE stops after O(mnmin⁡(m,n)+mn)O(m n \min(m, n) + m n) steps. LU-SOLVE has two loops of nn steps each.

Invariant. At each test of line L2, with cc the next column and rr the next pivot row:

(I1) PπA=LUP_\pi A = L U.

(I2) LL is unit lower triangular, and for each row i≥ri \ge r, L[i,k]=0L[i, k] = 0 for r≤k<ir \le k < i.

(I3) Rows 11 to r−1r - 1 of UU are nonzero, the first nonzero entry of row tt is in a column ptp_t with p1<⋯<pr−1<cp_1 < \cdots < p_{r-1} < c, and rows rr to mm of UU are zero in columns 11 to c−1c - 1.

Initialization. Line L1 sets U=AU = A, L=IL = I, π\pi the identity and r=1r = 1, before column c=1c = 1. Then PπA=A=IAP_\pi A = A = I A, L=IL = I satisfies (I2), and (I3) holds with no pivot rows and no columns before cc.

Maintenance. Consider one pass with column cc, and suppose r≤mr \le m (else line L3 stops the loop, and the invariant is not changed).

Case 1: no i≥ri \ge r has U[i,c]≠0U[i, c] \ne 0 (line L4 goes to the next column). Then rows rr to mm of UU are zero in columns 11 to cc, so (I3) holds for c+1c + 1. Nothing else changes.

Case 2: line L4 finds i≥ri \ge r with U[i,c]≠0U[i, c] \ne 0. Let TT be the transposition of rows rr and ii (the identity if i=ri = r). Line L5 replaces UU by TUT U and π\pi by the permutation with Pπ′=TPπP_{\pi'} = T P_\pi. It replaces LL by L′=TLTL' = T L T restricted as follows: TLTT L T swaps rows r,ir, i and columns r,ir, i of LL. By (I2), rows rr and ii of LL have zeros in the columns rr to mm except on the diagonal, so TLTT L T is obtained from LL by swapping only the entries in columns 11 to r−1r - 1 of rows rr and ii, which is exactly what line L5 does. Then

Pπ′A=TPπA=TLU=(TLT)(TU)=L′U′,P_{\pi'} A = T P_\pi A = T L U = (T L T)(T U) = L' U',

since TT=IT T = I. So (I1) holds after line L5. L′L' is still unit lower triangular and satisfies (I2), because the swap keeps zeros in columns rr to mm of the rows rr to mm, apart from the diagonal. (I3) still holds for rows 11 to r−1r - 1, which are not touched, and rows rr to mm are still zero in the columns before cc.

Now let u=U[r,c]≠0u = U[r, c] \ne 0. For i=r+1,…,mi = r + 1, \ldots, m, lines L7 and L8 set fi=U[i,c]/uf_i = U[i, c] / u, store L[i,r]=fiL[i, r] = f_i, and replace row ii of UU by row ii minus fif_i times row rr. This is U←GUU \leftarrow G U with G=I−∑i>rfiEirG = I - \sum_{i > r} f_i E_{ir}, and G−1=I+∑i>rfiEirG^{-1} = I + \sum_{i > r} f_i E_{ir}, because EirEi′r=0E_{ir} E_{i' r} = 0 for i,i′>ri, i' > r. Right multiplication by G−1G^{-1} adds fif_i times column ii of LL to column rr, for each i>ri > r. Column ii of LL is the unit vector eie_i: its entries above row ii are zero because LL is lower triangular, its diagonal entry is 11, and its entries in the rows i′>ii' > i are zero by (I2), because r≤i<i′r \le i < i'. Column rr of LL is ere_r for the same reason. So LG−1L G^{-1} is LL with fif_i put in place (i,r)(i, r), which is what line L7 stores. Hence LU=(LG−1)(GU)L U = (L G^{-1})(G U) and (I1) holds. After the update, U[i,c]=U[i,c]−fiu=0U[i, c] = U[i, c] - f_i u = 0 for i>ri > r; rows r+1r + 1 to mm are zero in columns 11 to cc (they were zero in columns before cc, and row rr is too). Row rr is nonzero, its first nonzero entry is in column pr=c>pr−1p_r = c > p_{r-1}. Line L9 sets r←r+1r \leftarrow r + 1. Now (I2) holds for the new rr, because the only new nonzero entries of LL below the diagonal are in column roldr_{\text{old}}, and (I3) holds for c+1c + 1.

Termination of the loop. When the loop ends, either cc ran past nn, or r>mr > m. In the first case (I3) with c=n+1c = n + 1 says that rows rr to mm of UU are zero and rows 11 to r−1r - 1 have strictly increasing leading columns: UU is in row echelon form. In the second case all mm rows are pivot rows with increasing leading columns, which is also an echelon form. With (I1) and (I2), line L10 returns π\pi, a unit lower triangular LL and an echelon UU with PπA=LUP_\pi A = L U. □\square

LU-SOLVE. Let AA be n×nn \times n and nonsingular. Then U=L−1PπAU = L^{-1} P_\pi A is nonsingular, and since it is in echelon form and square, its nn rows are pivot rows with leading columns p1<⋯<pnp_1 < \cdots < p_n in {1,…,n}\{1, \ldots, n\}, so pt=tp_t = t and UU is upper triangular with a nonzero diagonal. Line L11 computes, for i=1,…,ni = 1, \ldots, n in order, the unique yiy_i with ∑k<iL[i,k]yk+yi=(Pπb)i=bπ(i)\sum_{k < i} L[i, k] y_k + y_i = (P_\pi b)_i = b_{\pi(i)}, using only the yky_k with k<ik < i already computed; so Ly=PπbL y = P_\pi b. Line L12 computes, for i=n,…,1i = n, \ldots, 1, the unique xix_i with U[i,i]xi+∑k>iU[i,k]xk=yiU[i, i] x_i + \sum_{k > i} U[i, k] x_k = y_i, which is possible because U[i,i]≠0U[i, i] \ne 0; so Ux=yU x = y. Then PπAx=LUx=Ly=PπbP_\pi A x = L U x = L y = P_\pi b, and since PπP_\pi is invertible, Ax=bA x = b. The solution is unique because AA is nonsingular. ■\blacksquare

Determinant. For square AA, det⁡(Pπ)det⁡A=det⁡Ldet⁡U=∏iU[i,i]\det(P_\pi) \det A = \det L \det U = \prod_i U[i, i], and det⁡Pπ=sgn⁡(π)=±1\det P_\pi = \operatorname{sgn}(\pi) = \pm 1, so det⁡A=sgn⁡(π)∏iU[i,i]\det A = \operatorname{sgn}(\pi) \prod_i U[i, i]. If AA is singular, the echelon form UU has a zero row, so the product is 00, as it must be.

Back to LU decomposition