Algorithm Search⌘K

Proofs: Thomas algorithm

These are the human proofs of Thomas algorithm, at full length.

The Thomas algorithm computes the solution of a tridiagonal system whose leading principal minors are nonzero full

This proof shows: correctness, termination.

AA is tridiagonal of order nn, with subdiagonal a2,…,ana_2, \ldots, a_n, diagonal b1,…,bnb_1, \ldots, b_n and superdiagonal c1,…,cn−1c_1, \ldots, c_{n-1}. Let Ak=A1:k,1:kA_k = A_{1:k,1:k} and δk=det⁡Ak\delta_k = \det A_k, with δ0=1\delta_0 = 1. The loops have fixed lengths, so the algorithm stops; it stops early, at line L3 or L6, exactly when some pivot is zero.

Lemma 1 (the pivots). If δ1,…,δk−1\delta_1, \ldots, \delta_{k-1} are nonzero, then lines L1 to L4 compute u1,…,uku_1, \ldots, u_k with ui=δi/δi−1u_i = \delta_i/\delta_{i-1} for i≤ki \le k.

Proof. Expanding det⁡Ai\det A_i along its last row gives the three-term recurrence δi=biδi−1−aici−1δi−2\delta_i = b_i \delta_{i-1} - a_i c_{i-1} \delta_{i-2} for i≥2i \ge 2, with δ1=b1\delta_1 = b_1. For i=1i = 1, u1=b1=δ1/δ0u_1 = b_1 = \delta_1/\delta_0. For i≥2i \ge 2, assume ui−1=δi−1/δi−2u_{i-1} = \delta_{i-1}/\delta_{i-2}, which is nonzero. Line L3 gives li=ai/ui−1l_i = a_i/u_{i-1} and line L4 gives

ui=bi−aici−1ui−1=bi−aici−1δi−2δi−1=biδi−1−aici−1δi−2δi−1=δiδi−1.□u_i = b_i - \frac{a_i c_{i-1}}{u_{i-1}} = b_i - \frac{a_i c_{i-1} \delta_{i-2}}{\delta_{i-1}} = \frac{b_i \delta_{i-1} - a_i c_{i-1}\delta_{i-2}}{\delta_{i-1}} = \frac{\delta_i}{\delta_{i-1}}. \qquad \square

So no division by zero occurs if and only if δ1,…,δn−1\delta_1, \ldots, \delta_{n-1} are nonzero, and un≠0u_n \ne 0 if and only if moreover det⁡A=δn≠0\det A = \delta_n \ne 0.

Lemma 2 (the factorization). If all pivots are nonzero, then A=LUA = L U, where LL is unit lower bidiagonal with Li,i−1=liL_{i,i-1} = l_i and UU is upper bidiagonal with Uii=uiU_{ii} = u_i and Ui,i+1=ciU_{i,i+1} = c_i.

Proof. The product LUL U is tridiagonal. Its entry (1,1)(1,1) is u1=b1u_1 = b_1. For i≥2i \ge 2, row ii of LL has lil_i in column i−1i - 1 and 11 in column ii, so (LU)i,i−1=liui−1=ai(L U)_{i,i-1} = l_i u_{i-1} = a_i, (LU)ii=lici−1+ui=bi(L U)_{ii} = l_i c_{i-1} + u_i = b_i by line L4, and (LU)i,i+1=ci(L U)_{i,i+1} = c_i. □\square

Lemma 3 (the sweeps). Line L5 computes the solution yy of Ly=dL y = d, and lines L6 and L7 compute the solution xx of Ux=yU x = y.

Proof. Row ii of Ly=dL y = d is liyi−1+yi=dil_i y_{i-1} + y_i = d_i (with no first term for i=1i = 1), which is lines L1 and L5. Row ii of Ux=yU x = y is uixi+cixi+1=yiu_i x_i + c_i x_{i+1} = y_i (with no second term for i=ni = n). Going from i=ni = n down to 11, xi+1x_{i+1} is known when xix_i is computed, and lines L6 and L7 solve row ii for xix_i, which is possible because ui≠0u_i \ne 0. □\square

Theorem. If δ1,…,δn\delta_1, \ldots, \delta_n are nonzero, THOMAS returns the unique solution of Ax=dA x = d; otherwise it stops at the first zero pivot.

Proof. By Lemmas 2 and 3, Ax=LUx=Ly=dA x = L U x = L y = d, and AA is nonsingular because δn≠0\delta_n \ne 0. The second claim is Lemma 1. ■\blacksquare

Diagonal dominance gives nonzero pivots. Suppose AA is strictly diagonally dominant by rows: ∣bi∣>∣ai∣+∣ci∣|b_i| > |a_i| + |c_i| for all ii, with a1=cn=0a_1 = c_n = 0. Then ∣ui∣>∣ci∣|u_i| > |c_i| for all ii, so no pivot is zero. Indeed ∣u1∣=∣b1∣>∣c1∣|u_1| = |b_1| > |c_1|. If ∣ui−1∣>∣ci−1∣|u_{i-1}| > |c_{i-1}|, then ∣lici−1∣=∣ai∣ ∣ci−1∣/∣ui−1∣≤∣ai∣|l_i c_{i-1}| = |a_i|\,|c_{i-1}|/|u_{i-1}| \le |a_i|, so ∣ui∣≥∣bi∣−∣lici−1∣≥∣bi∣−∣ai∣>∣ci∣|u_i| \ge |b_i| - |l_i c_{i-1}| \ge |b_i| - |a_i| > |c_i|. The same induction shows ∣li∣≤∣ai∣/∣ui−1∣|l_i| \le |a_i|/|u_{i-1}| stays bounded, and that the pivots satisfy ∣ui∣≤∣bi∣+∣ai∣|u_i| \le |b_i| + |a_i|.

Floating point. Each computed quantity is one operation or one fused pair: l^i=(ai/u^i−1)(1+ϵ1)\hat l_i = (a_i/\hat u_{i-1})(1 + \epsilon_1), u^i=(bi−l^ici−1(1+ϵ2))(1+ϵ3)\hat u_i = (b_i - \hat l_i c_{i-1}(1 + \epsilon_2))(1 + \epsilon_3), and similarly for y^i\hat y_i and x^i\hat x_i, with ∣ϵj∣≤u|\epsilon_j| \le u. Moving these factors onto the entries of L^\hat L and U^\hat U gives the bound ∣ΔA∣≤f(u)∣L^∣∣U^∣|\Delta A| \le f(u)|\hat L||\hat U| with f(u)=4u+3u2+u3f(u) = 4u + 3u^2 + u^3 stated on the page (Higham, Section 9.6). The tests check the resulting residual inequality ∣d−Ax^∣≤f(u) ∣L^∣ ∣U^∣ ∣x^∣|d - A\hat x| \le f(u)\,|\hat L|\,|\hat U|\,|\hat x| exactly.

Back to Thomas algorithm