The cause of the error message is that your function reg is returning all zero values for the first matrix H. Somewhere down the line Sage tries to take an inverse of zero and that returns an error. I've created a ticket to report this problem.