In this paper, we present a generalized version of the matrix chain algorithm to generate efficient code for linear algebra problems, a task for which human experts o en invest days or even weeks of works. e standard matrix chain problem consists in finding the parenthesization of a matrix product M := A 1 A 2 · · · A n that minimizes the number of scalar operations. In practical applications, however, one frequently encounters more complicated expressions, involving transposition, inversion, and matrix properties. Indeed, the computation of such expressions relies on a set of computational kernels that offer functionality well beyond the simple matrix product. e challenge then shi s from finding an optimal parenthesization to finding an optimal mapping of the input expression to the available kernels. Furthermore, it is o en the case that a solution based on the minimization of scalar operations does not result in the optimal solution in terms of execution time. In our experiments, the generated code outperforms other libraries and languages on average by a factor of about 9. e motivation for this work comes from the fact that-despite great advances in the development of compilers-the task of mapping linear algebra problems to optimized kernels is still to be done manually. In order to relieve the user from this complex task, new techniques for the compilation of linear algebra expressions have to be developed.