title: Multiplying Two Compressed Upper Triangular Matrices
body: <p>I am terrible at linear algebra and I am having an incredibly hard time building my loops to multiply two compressed matrices without expanding them and including the zeros. </p>
  
  <p>For example,</p>
  
  <pre><code>0 1 2 3  * 10 11 12 13
  0 4 5 6    0  14 15 16
  0 0 7 8    0  0  17 18
  0 0 0 9    0  0  0  19
  </code></pre>
  
  <p>is actually just </p>
  
  <pre><code>a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
  b = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19}
  </code></pre>
  
  <p>I initially had </p>
  
  <pre><code>for(i = 0; i &lt; r1; ++i)
      for(j = 0; j &lt; c2; ++j)
          for(k = 0; k &lt; c1; ++k)
          {
              *(mult(i * cols) + j) += *(a(i * cols) + k) * (b + (k * cols) + j;
          }
  </code></pre>
  
  <p>but this obviously goes out of bounds because it is built as if they are 2D arrays and goes to 16 when the size of each array is only 10 elements. </p>
  
  <p>I have observed that the diagonals are just the products of only the elements on the diagonals, so for example c[4] = a[4] * b[4]. I also understand that for the first row you multiply the same number of terms as there are columns, the second row you multiply that many terms - 1 and so forth.</p>
  
  <p>But beyond that, I am fairly lost on how to construct the actual code. Any help is greatly appreciated. </p>