mathematical framework for memory switching