matrix inversion caching