Copyright | (c) Kimiyuki Onaka 2021 |
---|---|
License | Apache License 2.0 |
Maintainer | kimiyuki95@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
\[ \newcommand\int{\mathbf{int}} \newcommand\bool{\mathbf{bool}} \newcommand\list{\mathbf{list}} \]
Synopsis
- run :: (MonadAlpha m, MonadError Error m) => Program -> m Program
- rule :: MonadAlpha m => RewriteRule m
- reduceSum :: MonadAlpha m => RewriteRule m
- reduceProduct :: Monad m => RewriteRule m
- reduceModSum :: MonadAlpha m => RewriteRule m
- reduceModProduct :: Monad m => RewriteRule m
Documentation
run :: (MonadAlpha m, MonadError Error m) => Program -> m Program Source #
run
reduces summations and products.
- This doen't do nothing about
Foldl
.
Examples
Before:
foldl (fun y x -> y + x) 0 (range n)
After:
x * (x - 1) / 2
List of builtin functions which are reduced
Target functions
Sum
\(: \list(\int) \to \int\)Product
\(: \list(\int) \to \int\)ModSum
\(: \list(\int) \to \int \to \int\)ModProduct
\(: \list(\int) \to \int \to \int\)
Arithmetical functions
Negate
\(: \int \to \int\)Plus
\(: \int \to \int \to \int\)Minus
\(: \int \to \int \to \int\)Mult
\(: \int \to \int \to \int\)Pow
\(: \int \to \int \to \int\)
Arithmetical functions with modulo
ModNegate
\(: \int \to \int \to \int\)ModPlus
\(: \int \to \int \to \int \to \int\)ModMinus
\(: \int \to \int \to \int \to \int\)ModMult
\(: \int \to \int \to \int \to \int\)ModPow
\(: \int \to \int \to \int \to \int\)
List Build functions
Nil
\(: \forall \alpha. \list(\alpha)\)Cons
\(: \forall \alpha. \alpha \to \list(\alpha) \to \list(\alpha)\)Range1
\(: \int \to \list(\int)\)
List Map functions
internal rules
rule :: MonadAlpha m => RewriteRule m Source #
reduceSum :: MonadAlpha m => RewriteRule m Source #
reduceProduct :: Monad m => RewriteRule m Source #
TODO: implement this.
reduceModSum :: MonadAlpha m => RewriteRule m Source #
- This assumes that
ModFloor
is already propagated.
reduceModProduct :: Monad m => RewriteRule m Source #
TODO: implement this.