Writing a determinant function for a matrix larger than 3x3 is tedious and error prone. Determinant can be implemented recursively using co-factor expansion, but it can be difficult for a compiler to optimize. Here is a code generator that does it for you.