<i>"The exponentiation algorithm is quite simple:<p>If the power is zero, we will return the identity matrix.
If the power is even (2N), we can recursively compute M^N, and then return the square of the obtained matrix.
If the power is odd (2N+1), it’s enough to recursively compute M^2N value, and return the obtained matrix, that has been multiplied by M."</i><p>Tidbit: that likely is the best approach in practice, but perhaps surprisingly, it is not optimal in the number of matrix multiplications. See <a href="http://en.m.wikipedia.org/wiki/Addition-chain_exponentiation" rel="nofollow">http://en.m.wikipedia.org/wiki/Addition-chain_exponentiation</a> and <a href="https://oeis.org/A003313" rel="nofollow">https://oeis.org/A003313</a>. Wikipedia has a link mentioning addition-subtraction chains, so it may even be beneficial to compute the inverse of the matrix in some cases (M^1023 likely is such a case, if inverting M isn't too hard)