Decorator for automatic algorithms optimization via fast matrix exponentiation