Jikka-5.0.11.1: A transpiler from Python to C++ for competitive programming

Jikka.Core.Convert.MatrixExponentiation

Description

Synopsis

Documentation

run :: (MonadAlpha m, MonadError Error m) => Program -> m Program Source #

run simplifies an affine functions from vectors to vectors in iterate (Iterate) functions.

Examples

This makes matrix multiplication. Before:

iterate n (fun xs -> (xs[0] + 2 * xs[1], xs[1])) xs

After:

matap (matpow ((1, 2), (0, 1)) n) xs

Also this works on integers. Before:

iterate n (fun x -> (2 x + 1)) x

After:

(2 ** n) * x + (2 ** n - 1) / (n - 1)