nd} \\
A \, A^{n-1} &amp; \quad\text{if } n &gt; 0.
\end{cases}
\]</span></p>
<p>where <span class="math inline">\(\textrm{I}\)</span> is the identity matrix. This definition can be
directly translated to a recursive function definition.</p>
<pre><code>matrix matrix_pow(matrix a, int n);

matrix matrix_pow(matrix a, int n) {
  if (n == 0)
    return diag_matrix(rep_vector(1, rows(a)));
  else
    return a *  matrix_pow(a, n - 1);
}</code></pre>
<p>The forward declaration of the function signature before it 