Jikka-5.5.0.0: A transpiler from Python to C++ for competitive programming
Copyright(c) Kimiyuki Onaka 2021
LicenseApache License 2.0
Maintainerkimiyuki95@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Jikka.Core.Convert.ConstantFolding

Description

\[ \newcommand\int{\mathbf{int}} \newcommand\bool{\mathbf{bool}} \newcommand\list{\mathbf{list}} \]

Synopsis

Documentation

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

run folds constants in given programs. For example, this converts the following:

3 x + 2 + 1

to the follwoing:

3 x + 3

internal rules

reduceConstArithmeticExpr :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Basic arithmetical functions

  • Negate \(: \int \to \int\)
  • Plus \(: \int \to \int \to \int\)
  • Minus \(: \int \to \int \to \int\)
  • Mult \(: \int \to \int \to \int\)
  • FloorDiv \(: \int \to \int \to \int\)
  • FloorMod \(: \int \to \int \to \int\)
  • CeilDiv \(: \int \to \int \to \int\)
  • CeilMod \(: \int \to \int \to \int\)
  • Pow \(: \int \to \int \to \int\)

Advanced arithmetical functions

  • Abs \(: \int \to \int\)
  • Gcd \(: \int \to \int \to \int\)
  • Lcm \(: \int \to \int \to \int\)

reduceConstMaxExpr :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Max functions

  • Min2 \(: \forall \alpha. \alpha \to \alpha \to \alpha\) (specialized to \(\alpha = \lbrace \bool, \int \rbrace\))
  • Max2 \(: \forall \alpha. \alpha \to \alpha \to \alpha\) (specialized to \(\alpha = \lbrace \bool, \int \rbrace\))

reduceIdempotentBooleanExpr :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Boolean functions

  • And \(: \bool \to \bool \to \bool\)
  • Or \(: \bool \to \bool \to \bool\)
  • Implies \(: \bool \to \bool \to \bool\)

reduceUnitBooleanExpr :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Boolean functions

  • Not \(: \bool \to \bool\)
  • And \(: \bool \to \bool \to \bool\)
  • Or \(: \bool \to \bool \to \bool\)
  • Implies \(: \bool \to \bool \to \bool\)

reduceConstBooleanExpr :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Boolean functions

  • If \(: \forall \alpha. \bool \to \alpha \to \alpha \to \alpha\)

reduceUnitBitExpr :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Bitwise boolean functions

reduceConstBitExpr :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Bitwise boolean functions

reduceConstIntComparison :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Comparison functions

  • LessThan \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • LessEqual \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • GreaterThan \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • GreaterEqual \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • Equal \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • NotEqual \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))

reduceUnitBooleanComparison :: (MonadAlpha m, MonadError Error m) => RewriteRule m Source #

List of functions which are reduced

Comparison functions

  • LessThan \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • LessEqual \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • GreaterThan \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • GreaterEqual \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • Equal \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))
  • NotEqual \(: \forall \alpha. \alpha \to \alpha \to \bool\) (specialized to \(\alpha \in \lbrace \bool, \int \rbrace\))