functions for create and use a matrix with an internal cache of the result of operations