Implement special 'matrix' type and its cached inverse calculation