
6 CHAPTER 1. INTRODUCTION
than having to translate the R repeatedly for each line of the loop, at each
iteration.
In the code for mutoutser() above, the inner loops can be rewritten as a
matrix product, as we will see below, and that will turn out to eliminate
two of our loops.
3
To see the matrix formulation, suppose we have this matrix:
0 1 0 0 1
1 0 0 1 1
0 1 0 1 0
1 1 1 0 0
1 1 1 0 1
(1.1)
Consider the case in which i is 2 and j is 4 in the above pseudocode, Listing
1.4.1. The innermost loop, i.e., the one involving k, computes
1 · 1 + 0 · 1 + 0 · 1 + 1 · 0 + 1 · 0 = 1 (1.2)
But that is merely the inner product of rows i and j of the matrix! ...