Functions to calculate inverse of row-reduce algorithm