# Forward substitution

 Forward substitution Sequential algorithm Serial complexity $O(n^2)$ Input data $O(n^2)$ Output data $n$ Parallel algorithm Parallel form height $O(n)$ Parallel form width $O(n)$

Primary authors of this description: A.V.Frolov, Vad.V.Voevodin (Section 2.2), A.M.Teplov (Section 2.4)

## 1 Properties and structure of the algorithm

### 1.1 General description of the algorithm

Forward substitution is the process of solving a system of linear algebraic equations (SLAE) $Lx = y$ with a lower triangular coefficient matrix $L$. The matrix $L$ is a factor of the matrix $A$ and results from either the $LU$-decomposition of the latter obtained by any of numerous ways (such as simple Gaussian elimination or Gaussian elimination with pivoting or compact schemes of Gaussian elimination) or other types of decomposition. The triangular form of $L$ ensures that the process of solving a SLAE is a modification of the general substitution method and this process can be described by simple formulas.

In[1], the process of solving a SLAE with a lower triangular coefficient matrix was named the back substitution. It was also noted in [1] that, in the literature, back substitution is usually regarded as solving a SLAE with a right triangular matrix, whereas the solution of left triangular systems is called the forward substitution. We adopt this nomenclature in order to avoid using identical names for different algorithms. Furthermore, unlike the forward substitution treated here, the back substitution, as presented in this algorithmic encyclopedia, is at the same time one of the stages in Gaussian elimination for solving SLAEs, namely, the final stage of this method.

Nevertheless, the structure of the forward substitution for a nonsingular left triangular matrix is virtually identical to the structure of the back substitution. Here, we consider the case where $L$ is a matrix obtained from a Gauss-like decomposition and, hence, $L$ has unit diagonal entries.

### 1.2 Mathematical description of the algorithm

Input data: left triangular matrix $L$ (with entries $l_{ij}$), right-hand side vector $b$ (with components $b_{i}$).

Output data: solution vector $y$ (with components $y_{i}$).

Formulas of the method:

\begin{align} y_{1} & = b_{1} \\ y_{i} & = b_{i} - \sum_{j = 1}^{i-1} l_{ij} y_{j}, \quad i \in [2, n]. \end{align}

There exists also a block version of the method; however, this description treats only the pointwise version.

### 1.3 Computational kernel of the algorithm

The computational kernel of the forward substitution could be compiled of repeated dot products of the rows of $L$ and the already determined portions of the vector $y$ (there are on the whole $n-1$ products) :

$\sum_{j = 1}^{i-1} l_{ij} y_{j}$

Depending on the problem requirements, these products are calculated with or without using the accumulation mode. Then they are subtracted from the corresponding components of the vector $b$, and the results are divided by the corresponding diagonal entries of $L$. This scheme is, however, not used in domestic implementations, even in serial ones. In these implementations, sums of the type

$b_{i} - \sum_{j = 1}^{i-1} l_{ij} y_{j}$

(and dot products are exactly such sums) are not calculated according to the rule "first, find the dot product and then subtract it from the given element". Instead, the componentwise products, which are summands of the dot product, are one by one subtracted from this element. Consequently, the calculation of the expressions

$b_{i} - \sum_{j = 1}^{i-1} l_{ij} y_{j}$

rather than dot products should be regarded as the computational kernel of the forward substitution. Depending on the problem requirements, these expressions are calculated with or without using the accumulation mode.

### 1.4 Macro structure of the algorithm

As already noted in the description of the computational kernel, the basic part of the forward substitution is compiled of repeated calculations of the sums

$b_{i} - \sum_{j = 1}^{i-1} l_{ij} y_{j}$

(there are on the whole $n-1$ sums). These calculations are performed with or without using the accumulation mode.

### 1.5 Implementation scheme of the serial algorithm

To make the order of calculations clearer, rewrite the formulas of the method as follows.

1. $y_{1} = b_{1}$

Then, for $i$ increasing from $2$ to $n$, do

2. $y_{i} = b_{i} - \sum_{j = 1}^{i-1} l_{ij} y_{j}$

We emphasize that sums of the form $b_{i} - \sum_{j = 1}^{i-1} l_{ij} y_{j}$ are calculated in the accumulation mode by subtracting from $b_{i}$ the products $l_{ij} y_{j}$for $j$ increasing from $1$ to $i-1$. Any other order of summation makes the parallel properties of the algorithm much worse.

### 1.6 Serial complexity of the algorithm

The forward substitution of order n in its serial (that is, the fastest) version requires

• $\frac{n^2-n}{2}$ multiplications and the same number of additions (subtractions).

The use of accumulation requires that multiplications and subtractions be done in the double precision mode (or such procedures as the Fortran function DPROD be used). This increases the computation time for performing the forward substitution.

In terms of serial complexity, the forward substitution is qualified as a quadratic complexity algorithm.

### 1.7 Information graph

We describe the graph of the algorithm both analytically and graphically.

Figure 1. Forward substitution

The graph of forward substitution consists of a single group of vertices placed at integer nodes of a two-dimensional domain. The corresponding operation is $a-bc$.

The natural coordinates of this domain are as follows:

• $i$ changes from $2$ to $n$, taking all the integer values in this range;
• $j$ changes from $1$ to $i-1$, taking all the integer values in this range.

The arguments of the operation are as follows:

• $a$ is:
• the element $b_{i}$ of the input data if $j = 1$;
• the result of performing the operation corresponding to the vertex with coordinates $i, j-1$ if $j \gt 1$;
• $b$ is the element $l_{ij}$ of the input data;
• $c$ is:
• the element $b_{1}$ of the input data if $j = 1$;
• the result of performing the operation corresponding to the vertex with coordinates $j, j-1$ if $j \gt 1$.

The result of performing the operation is:

• an intermediate data item if $j \lt i-1$ ;
• an output data item if $j = i-1$ .

The graph described can be seen in the figure corresponding to the case $n = 5$. The vertices are depicted in green. The supplies of the input data from the vector $b$ to the vertices of the left column and from the matrix $L$ to all the vertices are not shown in the figure.

### 1.8 Parallelization resource of the algorithm

The parallel version of the forward substitution of order n requires that the following layers be successively performed:

• $n - 1$ layers involving multiplications and additions / subtractions. (The number of operations changes linearly from $1$ to $n-1$.)

The use of accumulation requires that multiplications and subtractions be done in the double precision mode. For the parallel version, this implies that virtually all the intermediate calculations in the algorithm must be performed in double precision if the accumulation option is used. Unlike the situation with the serial version, this results in a certain increase in the required memory size.

In terms of the parallel form height, the forward substitution is qualified as a linear complexity algorithm. Its complexity is also linear in terms of the parallel form width.

### 1.9 Input and output data of the algorithm

Input data: left triangular matrix $L$ (with entries $l_{ij}$), right-hand side vector $b$ (with components $b_{i}$).

Size of the input data : $\frac{n (n + 1)}{2}$ (since $L$ is triangular and has unit diagonal entries, it suffices that only its subdiagonal entries be stored).

Output data : solution vector $y$ (with components $y_{i}$).

Size of the output data: $n~.$

### 1.10 Properties of the algorithm

It is clear that, in the case of unlimited resources, the ratio of the serial to parallel complexity is linear (since this is the ratio of the quadratic to linear complexity).

The computational power of the forward substitution, understood as the ratio of the number of operations to the total size of the input and output data, is only a constant.

In this version, the algorithm of forward substitution is completely determined. We do not consider any other order of performing operations because, otherwise, the structure of the algorithm would radically change and the parallel complexity would be quadratic.

## 2 Software implementation of the algorithm

### 2.1 Implementation peculiarities of the serial algorithm

In its simplest form, the forward substitution algorithm in Fortran can be written as follows:

        Y(1) = B(1)
DO  I = 2, N-1
S = B(I)
DO  J = 1, I-1
S = S - DPROD(L(I,J), Y(J))
END DO
END DO


In this case, the $S$ variable must be double precision to implement the accumulation mode.

## 3 References

1. Voevodin V.V., Kuznetsov Yu.A. Matrices and computations. Moscow, Nauka Publ., 1984. 320 p. (in russian)