Implement matrix inversion with result caching