Tutorials › Linear Algebra › Triangular Solve Costs and Repeated Right-Hand Sides

LU Factorization and Numerical Considerations · Tutorial 913 of 1000

Triangular Solve Costs and Repeated Right-Hand Sides

Learn how to count forward and back substitution, estimate the cost of reusing an LU factorization, and solve several right-hand sides efficiently.

Intermediate 11 min read

What You'll Learn

  • Count multiplications, additions or subtractions, and divisions in dense triangular solves.
  • Distinguish the cost of a unit lower-triangular solve from a general triangular solve.
  • Derive the arithmetic count for a dense LU factorization without pivoting.
  • Compare repeated independent factorizations with one factorization reused for many right-hand sides.
  • Solve a small matrix system with two right-hand sides and verify the result.

Counting the Work in a Triangular Solve

When a matrix has already been factored as \(\mathbf{A}=\mathbf{L}\mathbf{U}\), solving \(\mathbf{A}\mathbf{x}=\mathbf{b}\) requires two triangular solves: first solve \(\mathbf{L}\mathbf{y}=\mathbf{b}\), then solve \(\mathbf{U}\mathbf{x}=\mathbf{y}\). If many right-hand sides use the same matrix \(\mathbf{A}\), the factors can be reused. To understand the benefit, we need to count the work in each stage and keep factorization cost separate from solve cost.

Throughout this tutorial, count each scalar addition, subtraction, multiplication, and division as one arithmetic operation. Do not count copying entries, comparisons used for pivot selection, or the movement of rows under a permutation. The main counts describe dense triangular matrices: entries in the triangle being used are treated as nonzero, so every indicated arithmetic operation is needed. Particular zero entries or special right-hand sides can make a specific computation cheaper.

Definition: A lower-triangular matrix has zero entries above its main diagonal; an upper-triangular matrix has zero entries below it. A nonsingular triangular matrix has nonzero diagonal entries. A unit lower-triangular matrix is lower triangular with every diagonal entry equal to \(1\).

For a lower-triangular system \(\mathbf{L}\mathbf{y}=\mathbf{b}\), row \(i\) gives \(l_{ii}y_i=b_i-\sum_{j=1}^{i-1}l_{ij}y_j\). Thus, once \(y_1,\dots,y_{i-1}\) are known, the equation determines \(y_i\). An upper-triangular system is solved in the reverse order, beginning with its last row. These procedures are called forward substitution and back substitution, respectively.

Theorem (Correctness of triangular substitution): If a triangular matrix has nonzero diagonal entries, forward substitution for a lower-triangular system, or back substitution for an upper-triangular system, produces the unique solution for every right-hand side.

Proof. Consider first a lower-triangular system of size \(n\). In row \(1\), the equation is \(l_{11}y_1=b_1\), so the nonzero value \(l_{11}\) gives exactly one choice \(y_1=b_1/l_{11}\). Suppose the first \(i-1\) entries have been determined. Row \(i\) contains no entries multiplying \(y_j\) for \(j>i\), and its equation is \(l_{ii}y_i=b_i-\sum_{j=1}^{i-1}l_{ij}y_j\). The right-hand side is now known, and \(l_{ii}\ne0\), so this equation gives exactly one value of \(y_i\). Repeating for \(i=1,\dots,n\) constructs a solution and shows that no other solution is possible. For an upper-triangular system, row \(n\) first determines the unique \(x_n\); then row \(i\), considered in decreasing order, determines \(x_i\) from the already determined entries \(x_{i+1},\dots,x_n\), because its diagonal entry is nonzero. This constructs and uniquely determines the solution in that case as well. \(\square\)

Operation Counts for Forward and Back Substitution

In a dense lower-triangular solve, row \(i\) uses \(i-1\) multiplications to form the products \(l_{ij}y_j\), followed by \(i-1\) subtractions from \(b_i\). If the diagonal is not known to be \(1\), one more division gives \(y_i\). Summing over the rows gives the following count.

Result: For a dense \(n\times n\) lower- or upper-triangular system with nonzero diagonal, one substitution solve uses \(\frac{n(n-1)}{2}\) multiplications, \(\frac{n(n-1)}{2}\) additions or subtractions, and \(n\) divisions, for \(n^2\) arithmetic operations in total. For a unit lower-triangular solve, the \(n\) divisions are absent, so the total is \(n(n-1)\).

Proof. In forward substitution, row \(i\) has \(i-1\) entries strictly below the diagonal that can contribute products. Therefore the total number of such multiplications is \(\sum_{i=1}^{n}(i-1)=0+1+\cdots+(n-1)=n(n-1)/2\). There is one subtraction for each product, giving the same count of subtractions, and one division per row when the diagonal is not fixed to \(1\), giving \(n\) divisions. Adding these counts gives \(n(n-1)/2+n(n-1)/2+n=n^2\). In back substitution, row \(i\) uses the \(n-i\) entries strictly above the diagonal; summing gives \(\sum_{i=1}^{n}(n-i)=n(n-1)/2\), so the same total applies. In a unit lower-triangular system, division by the diagonal is unnecessary, leaving \(n(n-1)/2+n(n-1)/2=n(n-1)\) operations. \(\square\)

Worked Example: One Unit Lower-Triangular Solve

Solve \(\mathbf{L}\mathbf{y}=\mathbf{b}\) for \(\mathbf{L}=\begin{bmatrix}1&0&0\\2&1&0\\-1&3&1\end{bmatrix}\) and \(\mathbf{b}=\begin{bmatrix}2\\7\\2\end{bmatrix}\). Since \(\mathbf{L}\) is unit lower triangular, forward substitution requires no divisions.

Row 1 gives \(y_1=2\). Row 2 gives \(2y_1+y_2=7\), so \(y_2=7-2(2)=3\). Row 3 gives \(-y_1+3y_2+y_3=2\), so \(y_3=2-(-1)(2)-3(3)=2+2-9=-5\). Therefore

$$ \mathbf{y}=\begin{bmatrix}2\\3\\-5\end{bmatrix}. $$

Check: \(\mathbf{L}\mathbf{y}=\begin{bmatrix}2\\2(2)+3\\-2+3(3)-5\end{bmatrix}=\begin{bmatrix}2\\7\\2\end{bmatrix}=\mathbf{b}\). The dense unit lower-triangular count for \(n=3\) is \(3(3-1)=6\) operations: one multiplication and one subtraction in row 2, then two multiplications and two subtractions in row 3. This particular computation follows that count.

Counting the LU Factorization

For a dense matrix factored without pivoting, elimination step \(k\) computes \(n-k\) multipliers by division by the pivot. It then updates the entries in the remaining \((n-k)\times(n-k)\) block. Each updated entry takes one multiplication and one subtraction. This count assumes elimination succeeds: every pivot used as a divisor is nonzero. The count excludes pivot tests and row exchanges.

Result: A dense \(n\times n\) LU factorization without pivoting, when all required pivots are nonzero, uses \(F(n)=\frac{n(n-1)(4n+1)}{6}\) arithmetic operations under the counting convention above.

Proof. At step \(k\), there are \(n-k\) multipliers to compute, each using one division. Across all steps, the division count is \(\sum_{k=1}^{n-1}(n-k)=n(n-1)/2\). The trailing-block updates use one multiplication and one subtraction for each of \((n-k)^2\) entries at step \(k\). Thus their total is \(2\sum_{k=1}^{n-1}(n-k)^2=2\sum_{j=1}^{n-1}j^2=(n-1)n(2n-1)/3\). Adding divisions gives \(\frac{n(n-1)}{2}+\frac{n(n-1)(2n-1)}{3}=\frac{n(n-1)(4n+1)}{6}\), as claimed. \(\square\)

This is an arithmetic count for a generic dense factorization, not a claim that every matrix requires exactly this much work. A zero in the trailing block can reduce the number of nontrivial updates. Also, pivoting may require comparisons and row exchanges, which were excluded from this model. The leading term of \(F(n)\) is \(\frac{2}{3}n^3\), while a triangular solve grows quadratically with \(n\). This difference in growth rates is why reusing a factorization can matter.

Reusing Factors for Multiple Right-Hand Sides

Suppose \(\mathbf{A}\) has an LU factorization \(\mathbf{A}=\mathbf{L}\mathbf{U}\), with \(\mathbf{L}\) unit lower triangular and \(\mathbf{U}\) upper triangular with nonzero diagonal. For \(r\) right-hand sides, write them as the columns of \(\mathbf{B}\in\mathbb{R}^{n\times r}\). For each column \(\mathbf{b}_j\), solve \(\mathbf{L}\mathbf{y}_j=\mathbf{b}_j\), then \(\mathbf{U}\mathbf{x}_j=\mathbf{y}_j\). The unit lower solve takes \(n(n-1)\) operations and the upper solve takes \(n^2\), so the cost per right-hand side after factorization is \(S(n)=2n^2-n\).

Result: If the same matrix is used for \(r\) right-hand sides, factoring once and reusing the factors costs \(F(n)+rS(n)\). Factoring independently for each right-hand side costs \(r(F(n)+S(n))\). The arithmetic saved by reusing the factorization is \((r-1)F(n)\).

Proof. In the reuse strategy, the factorization is performed once, at cost \(F(n)\), and each of the \(r\) columns requires one lower and one upper solve, at cost \(S(n)\) per column. The total is therefore \(F(n)+rS(n)\). If each system is factored independently, each of the \(r\) systems incurs both costs, giving \(r(F(n)+S(n))\). Subtracting the reuse cost from the independent cost yields \(r(F(n)+S(n))-(F(n)+rS(n))=(r-1)F(n)\). Since \(F(n)\ge0\) for positive integer \(n\), the saving is nonnegative. It is positive when \(r>1\) and \(n\ge2\), because then \(F(n)>0\); when \(n=1\), \(F(1)=0\), so the saving is zero even if \(r>1\). \(\square\)

Worked Example: Comparing Costs for Four Unknowns

Compare the two strategies for a dense \(4\times4\) matrix and \(r=3\) right-hand sides, assuming a successful LU factorization without pivoting.

The factorization count is \(F(4)=4(4-1)(4\cdot4+1)/6=4\cdot3\cdot17/6=34\). Because \(\mathbf{L}\) is unit lower triangular, each lower solve costs \(4(4-1)=12\). Each upper solve costs \(4^2=16\). Hence \(S(4)=12+16=28\).

Factoring once and reusing the factors costs \(34+3(28)=34+84=118\) operations. Factoring independently for all three right-hand sides costs \(3(34+28)=3(62)=186\) operations. The difference is \(186-118=68\), which agrees with \((3-1)F(4)=2(34)=68\).

Solving Two Right-Hand Sides with the Same Factors

Worked Example: Two Columns Through Forward and Back Substitution

Let \(\mathbf{L}=\begin{bmatrix}1&0&0\\2&1&0\\-1&3&1\end{bmatrix}\) and \(\mathbf{U}=\begin{bmatrix}2&1&1\\0&3&2\\0&0&1\end{bmatrix}\). Their product is \(\mathbf{A}=\begin{bmatrix}2&1&1\\4&5&4\\-2&8&6\end{bmatrix}\). Solve \(\mathbf{A}\mathbf{X}=\mathbf{B}\) for \(\mathbf{B}=\begin{bmatrix}3&1\\10&8\\8&20\end{bmatrix}\) by first solving \(\mathbf{L}\mathbf{Y}=\mathbf{B}\).

For row 1 of the forward solve, \(Y_{1,\cdot}=(3,1)\). Row 2 subtracts twice row 1 of \(\mathbf{Y}\) from row 2 of \(\mathbf{B}\), giving \((10,8)-2(3,1)=(4,6)\). Row 3 subtracts \(-1\) times row 1 and \(3\) times row 2 of \(\mathbf{Y}\): \((8,20)-(-1)(3,1)-3(4,6)=(8,20)+(3,1)-(12,18)=(-1,3)\). Thus

$$ \mathbf{Y}=\begin{bmatrix}3&1\\4&6\\-1&3\end{bmatrix}. $$

Now solve \(\mathbf{U}\mathbf{X}=\mathbf{Y}\) by back substitution. The last row gives \(X_{3,\cdot}=(-1,3)\). Row 2 gives \(3X_{2,\cdot}=(4,6)-2(-1,3)=(6,0)\), so \(X_{2,\cdot}=(2,0)\). Row 1 gives \(2X_{1,\cdot}=(3,1)-(2,0)-(-1,3)=(2,-2)\), so \(X_{1,\cdot}=(1,-1)\). Therefore

$$ \mathbf{X}=\begin{bmatrix}1&-1\\2&0\\-1&3\end{bmatrix}. $$

Check: Multiplying \(\mathbf{A}\mathbf{X}\) column by column gives \(\mathbf{A}\begin{bmatrix}1\\2\\-1\end{bmatrix}=\begin{bmatrix}2+2-1\\4+10-4\\-2+16-6\end{bmatrix}=\begin{bmatrix}3\\10\\8\end{bmatrix}\) and \(\mathbf{A}\begin{bmatrix}-1\\0\\3\end{bmatrix}=\begin{bmatrix}-2+3\\-4+12\\2+18\end{bmatrix}=\begin{bmatrix}1\\8\\20\end{bmatrix}\). These are exactly the columns of \(\mathbf{B}\). The factors are indeed consistent with \(\mathbf{A}\): multiplying \(\mathbf{L}\mathbf{U}\) gives rows \((2,1,1)\), \((4,5,4)\), and \((-2,8,6)\).

For this \(n=3\) example, \(F(3)=3\cdot2\cdot13/6=13\), and two right-hand sides require \(2S(3)=2(2\cdot9-3)=30\) solve operations in the dense count. Reusing the factors therefore costs \(13+30=43\), compared with \(2(13+15)=56\) if each system is factored separately. The saving is \(13\), equal to \((2-1)F(3)\). The displayed arithmetic may involve cancellation, but the count is based on the dense triangular patterns.

Common Counting Pitfalls

Omitting one of the two triangular solves. A common incorrect estimate for the preceding two-right-hand-side example is \(13+2(9)=31\): it counts an \(n^2\) solve for each column but includes only one triangular solve per column. The correction is to count forward and back substitution separately. Here the lower factor is unit lower triangular and costs \(3(3-1)=6\) per column; the upper factor costs \(3^2=9\). Together they cost \(15\) per column, so the correct reused total is \(13+2(15)=43\).

Assuming every reuse saves a positive number of arithmetic operations. The formula \((r-1)F(n)\) is nonnegative, but it is not always positive. For \(n=1\), \(F(1)=1(1-1)(4+1)/6=0\). Reusing a factorization for several one-variable systems therefore saves zero operations under this model. For \(n\ge2\) and \(r>1\), the saving is positive.

Counting factorization as part of every solve. Once \(\mathbf{L}\) and \(\mathbf{U}\) have been computed, another right-hand side requires only the two triangular solves. Repeating the factorization for that same matrix adds work without changing the factors. This is the central computational reason to store and reuse an LU factorization when multiple right-hand sides are available.

Check Your Understanding

Use the stated arithmetic-counting convention and show enough steps to justify each answer.

  1. How many operations does a dense \(5\times5\) unit lower-triangular solve require? How many divisions does it use?
  2. For a dense \(5\times5\) upper-triangular solve with nonzero diagonal, give the separate counts of multiplications, subtractions, and divisions.
  3. Compute \(F(3)\) from the LU factorization formula by counting multiplier divisions and trailing-block updates separately.
  4. For \(n=3\) and \(r=4\), write the total operation count for one reused factorization and for four independent factorizations.
  5. Explain why the saving formula gives zero when \(n=1\), even when there is more than one right-hand side.

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon