Jikka-5.6.0.0: A transpiler from Python to C++ for competitive programming
Safe HaskellNone
LanguageHaskell2010

Jikka.Core.Language.ArithmeticExpr

Synopsis

Basic functions

parseArithmeticExpr :: Expr -> ArithmeticExpr Source #

parseArithmeticExpr converts a given expr to a normal form \(\sum_i \prod_j e _ {i,j})\). This assumes given exprs have the type \(\mathbf{int}\).

Advanced functions

unNPlusKPattern :: ArithmeticExpr -> Maybe (VarName, Integer) Source #

unNPlusKPattern recognizes a pattern of \(x + k\) for a variable \(x\) and an integer constant \(k \in \mathbb{Z}\).

makeVectorFromArithmeticExpr :: Vector VarName -> ArithmeticExpr -> Maybe (Vector ArithmeticExpr, ArithmeticExpr) Source #

makeVectorFromArithmeticExpr makes a vector \(f\) and a expr \(c\) from a given vector of variables \(x_0, x_1, \dots, x _ {n - 1}\) and a given expr \(e\) s.t. \(f\) and \(c\) don't have \(x_0, x_1, \dots, x _ {n - 1}\) as free variables and \(e = c + f \cdot (x_0, x_1, \dots, x _ {n - 1})\) holds. This assumes given variables and exprs have the type \(\mathbf{int}\).

  • The returned exprs are normalized with normalizeArithmeticExpr.

makeAffineFunctionFromArithmeticExpr :: VarName -> ArithmeticExpr -> Maybe (ArithmeticExpr, ArithmeticExpr) Source #

makeAffineFunctionFromArithmeticExpr is a specialized version of makeVectorFromArithmeticExpr. This function returns \(a, b\) for a given variable \(x\) and a given expr \(e = a x + b\) where \(a, b\) which doesn't use \(x\) free.

splitConstantFactorArithmeticExpr :: ArithmeticExpr -> (Integer, ArithmeticExpr) Source #

splitConstantFactorArithmeticExpr finds \(k\) and \(e'\) for given \(e\) s.t. \(e = k e'\).