Jikka-5.0.11.1: A transpiler from Python to C++ for competitive programming
Copyright (c) Kimiyuki Onaka 2021 Apache License 2.0 kimiyuki95@gmail.com experimental portable None Haskell2010

Jikka.Core.Convert.ConstantFolding

Description

$\newcommand\int{\mathbf{int}} \newcommand\bool{\mathbf{bool}} \newcommand\list{\mathbf{list}}$

Synopsis

# Documentation

run :: 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

## 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$$

## 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$$)

## 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$$
• If $$: \forall \alpha. \bool \to \alpha \to \alpha \to \alpha$$

## List of functions which are reduced

### Bitwise boolean functions

• BitNot $$: \int \to \int$$
• BitAnd $$: \int \to \int \to \int$$
• BitOr $$: \int \to \int \to \int$$
• BitXor $$: \int \to \int \to \int$$
• BitLeftShift $$: \int \to \int \to \int$$
• BitRightShift $$: \int \to \int \to \int$$

## 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$$)