{-# LANGUAGE GADTs #-}

-- | Defines functions to render 'CodeExpr's as printable 'P.Expr's.
module Language.Drasil.Printing.Import.CodeExpr (codeExpr) where

import Language.Drasil (DomainDesc(..), Inclusive(..),
  RTopology(..), RealInterval(..), UID, LiteralC (int))
import Language.Drasil.Display (Symbol(..))
import Language.Drasil.Code.Expr.Development
import Language.Drasil.Literal.Development

import qualified Language.Drasil.Printing.AST as P
import Language.Drasil.Printing.PrintingInformation (PrintingInformation, ckdb, stg)

import Language.Drasil.Printing.Import.Helpers
    (lookupC, parens)
import Language.Drasil.Printing.Import.Literal (literal)
import Language.Drasil.Printing.Import.Symbol (symbol)

import Control.Lens ((^.))
import Data.List (intersperse)


-- | Helper that creates an expression row given printing information, an operator, and an expression.
mkCall :: PrintingInformation -> P.Ops -> CodeExpr -> P.Expr
mkCall :: PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall s :: PrintingInformation
s o :: Ops
o e :: CodeExpr
e = [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
o, Expr -> Expr
parens (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
e PrintingInformation
s]

-- | Helper that creates a binary expression row given printing information, an operator, and two expressions.
mkBOp :: PrintingInformation -> P.Ops -> CodeExpr -> CodeExpr -> P.Expr
mkBOp :: PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp sm :: PrintingInformation
sm o :: Ops
o a :: CodeExpr
a b :: CodeExpr
b = [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
sm, Ops -> Expr
P.MO Ops
o, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
sm]

-- | Helper that adds parenthesis to an expression where appropriate.
expr' :: PrintingInformation -> Int -> CodeExpr -> P.Expr
expr' :: PrintingInformation -> Int -> CodeExpr -> Expr
expr' s :: PrintingInformation
s p :: Int
p e :: CodeExpr
e = Expr -> Expr
fence (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
e PrintingInformation
s
  where fence :: Expr -> Expr
fence = if CodeExpr -> Int
eprec CodeExpr
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
p then Expr -> Expr
parens else Expr -> Expr
forall a. a -> a
id

-- | Helper for properly rendering negation of expressions.
neg' :: CodeExpr -> Bool
neg' :: CodeExpr -> Bool
neg' (Lit (Dbl _))          = Bool
True
neg' (Lit (Int _))          = Bool
True
neg' (Lit (ExactDbl _))     = Bool
True
neg' Operator{}             = Bool
True
neg' (AssocA MulI _)        = Bool
True
neg' (AssocA MulRe _)       = Bool
True
neg' (LABinaryOp Index _ _) = Bool
True
neg' (UnaryOp _ _)          = Bool
True
neg' (UnaryOpB _ _)         = Bool
True
neg' (UnaryOpVV _ _)        = Bool
True
neg' (C _)                  = Bool
True
neg' _                      = Bool
False

-- | Render negated expressions.
neg :: PrintingInformation -> CodeExpr -> P.Expr
neg :: PrintingInformation -> CodeExpr -> Expr
neg sm :: PrintingInformation
sm a :: CodeExpr
a = [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Neg, (if CodeExpr -> Bool
neg' CodeExpr
a then Expr -> Expr
forall a. a -> a
id else Expr -> Expr
parens) (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
sm]

-- | For printing indexes.
indx :: PrintingInformation -> CodeExpr -> CodeExpr -> P.Expr
indx :: PrintingInformation -> CodeExpr -> CodeExpr -> Expr
indx sm :: PrintingInformation
sm (C c :: UID
c) i :: CodeExpr
i = Symbol -> Expr
f Symbol
s
  where
    i' :: Expr
i' = CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
i PrintingInformation
sm
    s :: Symbol
s = Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg) (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
c
    f :: Symbol -> Expr
f (Corners [] [] [] [b :: Symbol
b] e :: Symbol
e) =
      let e' :: Expr
e' = Symbol -> Expr
symbol Symbol
e
          b' :: Expr
b' = Symbol -> Expr
symbol Symbol
b in
      [Expr] -> Expr
P.Row [[Expr] -> Expr
P.Row [Expr
e', Expr -> Expr
P.Sub ([Expr] -> Expr
P.Row [Expr
b', Ops -> Expr
P.MO Ops
P.Comma, Expr
i'])]] -- FIXME, extra Row
    f a :: Symbol
a@(Variable _) = [Expr] -> Expr
P.Row [Symbol -> Expr
symbol Symbol
a, Expr -> Expr
P.Sub Expr
i']
    f a :: Symbol
a@(Label _)    = [Expr] -> Expr
P.Row [Symbol -> Expr
symbol Symbol
a, Expr -> Expr
P.Sub Expr
i']
--    f a@(Greek _)  = P.Row [symbol a, P.Sub i']
    f   e :: Symbol
e          = let e' :: Expr
e' = Symbol -> Expr
symbol Symbol
e in [Expr] -> Expr
P.Row [[Expr] -> Expr
P.Row [Expr
e'], Expr -> Expr
P.Sub Expr
i']
indx sm :: PrintingInformation
sm a :: CodeExpr
a i :: CodeExpr
i = [Expr] -> Expr
P.Row [[Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
sm], Expr -> Expr
P.Sub (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
i PrintingInformation
sm]

-- | For printing expressions that call something.
call :: PrintingInformation -> UID -> [CodeExpr] -> [(UID, CodeExpr)] -> P.Expr
call :: PrintingInformation
-> UID -> [CodeExpr] -> [(UID, CodeExpr)] -> Expr
call sm :: PrintingInformation
sm f :: UID
f ps :: [CodeExpr]
ps ns :: [(UID, CodeExpr)]
ns = [Expr] -> Expr
P.Row [Symbol -> Expr
symbol (Symbol -> Expr) -> Symbol -> Expr
forall a b. (a -> b) -> a -> b
$ Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg) (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
f,
  Expr -> Expr
parens (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
P.Row ([Expr] -> Expr) -> [Expr] -> Expr
forall a b. (a -> b) -> a -> b
$ Expr -> [Expr] -> [Expr]
forall a. a -> [a] -> [a]
intersperse (Ops -> Expr
P.MO Ops
P.Comma) ([Expr] -> [Expr]) -> [Expr] -> [Expr]
forall a b. (a -> b) -> a -> b
$ (CodeExpr -> Expr) -> [CodeExpr] -> [Expr]
forall a b. (a -> b) -> [a] -> [b]
map (CodeExpr -> PrintingInformation -> Expr
`codeExpr` PrintingInformation
sm) [CodeExpr]
ps [Expr] -> [Expr] -> [Expr]
forall a. [a] -> [a] -> [a]
++
  (UID -> CodeExpr -> Expr) -> [UID] -> [CodeExpr] -> [Expr]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\n :: UID
n a :: CodeExpr
a -> [Expr] -> Expr
P.Row [Symbol -> Expr
symbol (Symbol -> Expr) -> Symbol -> Expr
forall a b. (a -> b) -> a -> b
$ Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg) (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
n,
  Ops -> Expr
P.MO Ops
P.Eq, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
sm]) (((UID, CodeExpr) -> UID) -> [(UID, CodeExpr)] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (UID, CodeExpr) -> UID
forall a b. (a, b) -> a
fst [(UID, CodeExpr)]
ns) (((UID, CodeExpr) -> CodeExpr) -> [(UID, CodeExpr)] -> [CodeExpr]
forall a b. (a -> b) -> [a] -> [b]
map (UID, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd [(UID, CodeExpr)]
ns)]

-- | Helper function for addition 'EOperator's.
eopAdds :: PrintingInformation -> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> P.Expr
eopAdds :: PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
eopAdds sm :: PrintingInformation
sm (BoundedDD v :: Symbol
v Continuous l :: CodeExpr
l h :: CodeExpr
h) e :: CodeExpr
e =
  [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Inte, Expr -> Expr
P.Sub (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
l PrintingInformation
sm), Expr -> Expr
P.Sup (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
h PrintingInformation
sm),
         [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
e PrintingInformation
sm], Spacing -> Expr
P.Spc Spacing
P.Thin, String -> Expr
P.Ident "d", Symbol -> Expr
symbol Symbol
v]
eopAdds sm :: PrintingInformation
sm (AllDD v :: Symbol
v Continuous) e :: CodeExpr
e =
  [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Inte, Expr -> Expr
P.Sub (Symbol -> Expr
symbol Symbol
v), [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
e PrintingInformation
sm], Spacing -> Expr
P.Spc Spacing
P.Thin,
         String -> Expr
P.Ident "d", Symbol -> Expr
symbol Symbol
v]
eopAdds sm :: PrintingInformation
sm (BoundedDD v :: Symbol
v Discrete l :: CodeExpr
l h :: CodeExpr
h) e :: CodeExpr
e =
  [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Summ, Expr -> Expr
P.Sub ([Expr] -> Expr
P.Row [Symbol -> Expr
symbol Symbol
v, Ops -> Expr
P.MO Ops
P.Eq, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
l PrintingInformation
sm]), Expr -> Expr
P.Sup (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
h PrintingInformation
sm),
         [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
e PrintingInformation
sm]]
eopAdds sm :: PrintingInformation
sm (AllDD _ Discrete) e :: CodeExpr
e = [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Summ, [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
e PrintingInformation
sm]]

-- | Helper function for multiplicative 'EOperator's.
eopMuls :: PrintingInformation -> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> P.Expr
eopMuls :: PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
eopMuls sm :: PrintingInformation
sm (BoundedDD v :: Symbol
v Discrete l :: CodeExpr
l h :: CodeExpr
h) e :: CodeExpr
e =
  [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Prod, Expr -> Expr
P.Sub ([Expr] -> Expr
P.Row [Symbol -> Expr
symbol Symbol
v, Ops -> Expr
P.MO Ops
P.Eq, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
l PrintingInformation
sm]), Expr -> Expr
P.Sup (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
h PrintingInformation
sm),
         [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
e PrintingInformation
sm]]
eopMuls sm :: PrintingInformation
sm (AllDD _ Discrete) e :: CodeExpr
e = [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Prod, [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
e PrintingInformation
sm]]
eopMuls _ (AllDD _ Continuous) _ = String -> Expr
forall a. HasCallStack => String -> a
error "Printing/Import.hs Product-Integral not implemented."
eopMuls _ (BoundedDD _ Continuous _ _) _ = String -> Expr
forall a. HasCallStack => String -> a
error "Printing/Import.hs Product-Integral not implemented."


-- | Helper function for translating 'EOperator's.
eop :: PrintingInformation -> AssocArithOper -> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> P.Expr
eop :: PrintingInformation
-> AssocArithOper
-> DomainDesc t CodeExpr CodeExpr
-> CodeExpr
-> Expr
eop sm :: PrintingInformation
sm AddI = PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
forall (t :: RTopology).
PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
eopAdds PrintingInformation
sm
eop sm :: PrintingInformation
sm AddRe = PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
forall (t :: RTopology).
PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
eopAdds PrintingInformation
sm
eop sm :: PrintingInformation
sm MulI = PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
forall (t :: RTopology).
PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
eopMuls PrintingInformation
sm
eop sm :: PrintingInformation
sm MulRe = PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
forall (t :: RTopology).
PrintingInformation
-> DomainDesc t CodeExpr CodeExpr -> CodeExpr -> Expr
eopMuls PrintingInformation
sm

-- | Translate 'CodeExpr's to printable layout AST 'Expr's.
codeExpr :: CodeExpr -> PrintingInformation -> P.Expr
codeExpr :: CodeExpr -> PrintingInformation -> Expr
codeExpr (Lit l :: Literal
l)                  sm :: PrintingInformation
sm = Literal -> PrintingInformation -> Expr
literal Literal
l PrintingInformation
sm
codeExpr (AssocB And l :: [CodeExpr]
l)           sm :: PrintingInformation
sm = Ops -> Int -> [CodeExpr] -> PrintingInformation -> Expr
assocExpr Ops
P.And (AssocBoolOper -> Int
precB AssocBoolOper
And) [CodeExpr]
l PrintingInformation
sm
codeExpr (AssocB Or l :: [CodeExpr]
l)            sm :: PrintingInformation
sm = Ops -> Int -> [CodeExpr] -> PrintingInformation -> Expr
assocExpr Ops
P.Or (AssocBoolOper -> Int
precB AssocBoolOper
Or) [CodeExpr]
l PrintingInformation
sm
codeExpr (AssocA AddI l :: [CodeExpr]
l)          sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row ([Expr] -> Expr) -> [Expr] -> Expr
forall a b. (a -> b) -> a -> b
$ [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
addExpr [CodeExpr]
l AssocArithOper
AddI PrintingInformation
sm
codeExpr (AssocA AddRe l :: [CodeExpr]
l)         sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row ([Expr] -> Expr) -> [Expr] -> Expr
forall a b. (a -> b) -> a -> b
$ [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
addExpr [CodeExpr]
l AssocArithOper
AddRe PrintingInformation
sm
codeExpr (AssocA MulI l :: [CodeExpr]
l)          sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row ([Expr] -> Expr) -> [Expr] -> Expr
forall a b. (a -> b) -> a -> b
$ [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
mulExpr [CodeExpr]
l AssocArithOper
MulI PrintingInformation
sm
codeExpr (AssocA MulRe l :: [CodeExpr]
l)         sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row ([Expr] -> Expr) -> [Expr] -> Expr
forall a b. (a -> b) -> a -> b
$ [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
mulExpr [CodeExpr]
l AssocArithOper
MulRe PrintingInformation
sm
codeExpr (C c :: UID
c)                    sm :: PrintingInformation
sm = Symbol -> Expr
symbol (Symbol -> Expr) -> Symbol -> Expr
forall a b. (a -> b) -> a -> b
$ Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg) (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
c
codeExpr (FCall f :: UID
f [x :: CodeExpr
x] [])         sm :: PrintingInformation
sm =
  [Expr] -> Expr
P.Row [Symbol -> Expr
symbol (Symbol -> Expr) -> Symbol -> Expr
forall a b. (a -> b) -> a -> b
$ Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg) (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
f, Expr -> Expr
parens (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
x PrintingInformation
sm]
codeExpr (FCall f :: UID
f l :: [CodeExpr]
l ns :: [(UID, CodeExpr)]
ns)           sm :: PrintingInformation
sm = PrintingInformation
-> UID -> [CodeExpr] -> [(UID, CodeExpr)] -> Expr
call PrintingInformation
sm UID
f [CodeExpr]
l [(UID, CodeExpr)]
ns
codeExpr (New c :: UID
c l :: [CodeExpr]
l ns :: [(UID, CodeExpr)]
ns)             sm :: PrintingInformation
sm = PrintingInformation
-> UID -> [CodeExpr] -> [(UID, CodeExpr)] -> Expr
call PrintingInformation
sm UID
c [CodeExpr]
l [(UID, CodeExpr)]
ns
codeExpr (Message a :: UID
a m :: UID
m l :: [CodeExpr]
l ns :: [(UID, CodeExpr)]
ns)       sm :: PrintingInformation
sm =
  [Expr] -> Expr
P.Row [Symbol -> Expr
symbol (Symbol -> Expr) -> Symbol -> Expr
forall a b. (a -> b) -> a -> b
$ Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg) (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
a, Ops -> Expr
P.MO Ops
P.Point, PrintingInformation
-> UID -> [CodeExpr] -> [(UID, CodeExpr)] -> Expr
call PrintingInformation
sm UID
m [CodeExpr]
l [(UID, CodeExpr)]
ns]
codeExpr (Field o :: UID
o f :: UID
f)              sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row [Symbol -> Expr
symbol (Symbol -> Expr) -> Symbol -> Expr
forall a b. (a -> b) -> a -> b
$ Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg) (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
o,
  Ops -> Expr
P.MO Ops
P.Point, Symbol -> Expr
symbol (Symbol -> Expr) -> Symbol -> Expr
forall a b. (a -> b) -> a -> b
$ Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg) (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
f]
codeExpr (Case _ ps :: [(CodeExpr, CodeExpr)]
ps)              sm :: PrintingInformation
sm =
  if [(CodeExpr, CodeExpr)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(CodeExpr, CodeExpr)]
ps Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 2
    then String -> Expr
forall a. HasCallStack => String -> a
error "Attempting to use multi-case codeExpr incorrectly"
    else [(Expr, Expr)] -> Expr
P.Case ([Expr] -> [Expr] -> [(Expr, Expr)]
forall a b. [a] -> [b] -> [(a, b)]
zip (((CodeExpr, CodeExpr) -> Expr) -> [(CodeExpr, CodeExpr)] -> [Expr]
forall a b. (a -> b) -> [a] -> [b]
map ((CodeExpr -> PrintingInformation -> Expr)
-> PrintingInformation -> CodeExpr -> Expr
forall a b c. (a -> b -> c) -> b -> a -> c
flip CodeExpr -> PrintingInformation -> Expr
codeExpr PrintingInformation
sm (CodeExpr -> Expr)
-> ((CodeExpr, CodeExpr) -> CodeExpr)
-> (CodeExpr, CodeExpr)
-> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CodeExpr, CodeExpr) -> CodeExpr
forall a b. (a, b) -> a
fst) [(CodeExpr, CodeExpr)]
ps) (((CodeExpr, CodeExpr) -> Expr) -> [(CodeExpr, CodeExpr)] -> [Expr]
forall a b. (a -> b) -> [a] -> [b]
map ((CodeExpr -> PrintingInformation -> Expr)
-> PrintingInformation -> CodeExpr -> Expr
forall a b c. (a -> b -> c) -> b -> a -> c
flip CodeExpr -> PrintingInformation -> Expr
codeExpr PrintingInformation
sm (CodeExpr -> Expr)
-> ((CodeExpr, CodeExpr) -> CodeExpr)
-> (CodeExpr, CodeExpr)
-> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CodeExpr, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(CodeExpr, CodeExpr)]
ps))
codeExpr (Matrix a :: [[CodeExpr]]
a)               sm :: PrintingInformation
sm = [[Expr]] -> Expr
P.Mtx ([[Expr]] -> Expr) -> [[Expr]] -> Expr
forall a b. (a -> b) -> a -> b
$ ([CodeExpr] -> [Expr]) -> [[CodeExpr]] -> [[Expr]]
forall a b. (a -> b) -> [a] -> [b]
map ((CodeExpr -> Expr) -> [CodeExpr] -> [Expr]
forall a b. (a -> b) -> [a] -> [b]
map (CodeExpr -> PrintingInformation -> Expr
`codeExpr` PrintingInformation
sm)) [[CodeExpr]]
a
codeExpr (UnaryOp Log u :: CodeExpr
u)          sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Log CodeExpr
u
codeExpr (UnaryOp Ln u :: CodeExpr
u)           sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Ln CodeExpr
u
codeExpr (UnaryOp Sin u :: CodeExpr
u)          sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Sin CodeExpr
u
codeExpr (UnaryOp Cos u :: CodeExpr
u)          sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Cos CodeExpr
u
codeExpr (UnaryOp Tan u :: CodeExpr
u)          sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Tan CodeExpr
u
codeExpr (UnaryOp Sec u :: CodeExpr
u)          sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Sec CodeExpr
u
codeExpr (UnaryOp Csc u :: CodeExpr
u)          sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Csc CodeExpr
u
codeExpr (UnaryOp Cot u :: CodeExpr
u)          sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Cot CodeExpr
u
codeExpr (UnaryOp Arcsin u :: CodeExpr
u)       sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Arcsin CodeExpr
u
codeExpr (UnaryOp Arccos u :: CodeExpr
u)       sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Arccos CodeExpr
u
codeExpr (UnaryOp Arctan u :: CodeExpr
u)       sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Arctan CodeExpr
u
codeExpr (UnaryOp Exp u :: CodeExpr
u)          sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Exp, Expr -> Expr
P.Sup (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
u PrintingInformation
sm]
codeExpr (UnaryOp Abs u :: CodeExpr
u)          sm :: PrintingInformation
sm = Fence -> Fence -> Expr -> Expr
P.Fenced Fence
P.Abs Fence
P.Abs (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
u PrintingInformation
sm
codeExpr (UnaryOpB Not u :: CodeExpr
u)         sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row [Ops -> Expr
P.MO Ops
P.Not, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
u PrintingInformation
sm]
codeExpr (UnaryOpVN Norm u :: CodeExpr
u)       sm :: PrintingInformation
sm = Fence -> Fence -> Expr -> Expr
P.Fenced Fence
P.Norm Fence
P.Norm (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
u PrintingInformation
sm
codeExpr (UnaryOpVN Dim u :: CodeExpr
u)        sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> Expr
mkCall PrintingInformation
sm Ops
P.Dim CodeExpr
u
codeExpr (UnaryOp Sqrt u :: CodeExpr
u)         sm :: PrintingInformation
sm = Expr -> Expr
P.Sqrt (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
u PrintingInformation
sm
codeExpr (UnaryOp Neg u :: CodeExpr
u)          sm :: PrintingInformation
sm = PrintingInformation -> CodeExpr -> Expr
neg PrintingInformation
sm CodeExpr
u
codeExpr (UnaryOpVV NegV u :: CodeExpr
u)       sm :: PrintingInformation
sm = PrintingInformation -> CodeExpr -> Expr
neg PrintingInformation
sm CodeExpr
u
codeExpr (ArithBinaryOp Frac a :: CodeExpr
a b :: CodeExpr
b) sm :: PrintingInformation
sm = Expr -> Expr -> Expr
P.Div (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
sm) (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
sm)
codeExpr (ArithBinaryOp Pow a :: CodeExpr
a b :: CodeExpr
b)  sm :: PrintingInformation
sm = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
pow PrintingInformation
sm CodeExpr
a CodeExpr
b
codeExpr (ArithBinaryOp Subt a :: CodeExpr
a b :: CodeExpr
b) sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
sm, Ops -> Expr
P.MO Ops
P.Subt, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
sm]
codeExpr (BoolBinaryOp Impl a :: CodeExpr
a b :: CodeExpr
b)  sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.Impl CodeExpr
a CodeExpr
b
codeExpr (BoolBinaryOp Iff a :: CodeExpr
a b :: CodeExpr
b)   sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.Iff CodeExpr
a CodeExpr
b
codeExpr (EqBinaryOp Eq a :: CodeExpr
a b :: CodeExpr
b)      sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.Eq CodeExpr
a CodeExpr
b
codeExpr (EqBinaryOp NEq a :: CodeExpr
a b :: CodeExpr
b)     sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.NEq CodeExpr
a CodeExpr
b
codeExpr (LABinaryOp Index a :: CodeExpr
a b :: CodeExpr
b)   sm :: PrintingInformation
sm = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
indx PrintingInformation
sm CodeExpr
a CodeExpr
b
codeExpr (OrdBinaryOp Lt a :: CodeExpr
a b :: CodeExpr
b)     sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.Lt CodeExpr
a CodeExpr
b
codeExpr (OrdBinaryOp Gt a :: CodeExpr
a b :: CodeExpr
b)     sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.Gt CodeExpr
a CodeExpr
b
codeExpr (OrdBinaryOp LEq a :: CodeExpr
a b :: CodeExpr
b)    sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.LEq CodeExpr
a CodeExpr
b
codeExpr (OrdBinaryOp GEq a :: CodeExpr
a b :: CodeExpr
b)    sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.GEq CodeExpr
a CodeExpr
b
codeExpr (VVNBinaryOp Dot a :: CodeExpr
a b :: CodeExpr
b)    sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.Dot CodeExpr
a CodeExpr
b
codeExpr (VVVBinaryOp Cross a :: CodeExpr
a b :: CodeExpr
b)  sm :: PrintingInformation
sm = PrintingInformation -> Ops -> CodeExpr -> CodeExpr -> Expr
mkBOp PrintingInformation
sm Ops
P.Cross CodeExpr
a CodeExpr
b
codeExpr (Operator o :: AssocArithOper
o d :: DiscreteDomainDesc CodeExpr CodeExpr
d e :: CodeExpr
e)         sm :: PrintingInformation
sm = PrintingInformation
-> AssocArithOper
-> DiscreteDomainDesc CodeExpr CodeExpr
-> CodeExpr
-> Expr
forall (t :: RTopology).
PrintingInformation
-> AssocArithOper
-> DomainDesc t CodeExpr CodeExpr
-> CodeExpr
-> Expr
eop PrintingInformation
sm AssocArithOper
o DiscreteDomainDesc CodeExpr CodeExpr
d CodeExpr
e
codeExpr (RealI c :: UID
c ri :: RealInterval CodeExpr CodeExpr
ri)             sm :: PrintingInformation
sm = PrintingInformation
-> Symbol -> RealInterval CodeExpr CodeExpr -> Expr
renderRealInt PrintingInformation
sm (Stage -> ChunkDB -> UID -> Symbol
lookupC (PrintingInformation
sm PrintingInformation
-> Getting Stage PrintingInformation Stage -> Stage
forall s a. s -> Getting a s a -> a
^. Getting Stage PrintingInformation Stage
Lens' PrintingInformation Stage
stg)
  (PrintingInformation
sm PrintingInformation
-> Getting ChunkDB PrintingInformation ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB PrintingInformation ChunkDB
Lens' PrintingInformation ChunkDB
ckdb) UID
c) RealInterval CodeExpr CodeExpr
ri

-- | Common method of converting associative operations into printable layout AST.
assocExpr :: P.Ops -> Int -> [CodeExpr] -> PrintingInformation -> P.Expr
assocExpr :: Ops -> Int -> [CodeExpr] -> PrintingInformation -> Expr
assocExpr op :: Ops
op prec :: Int
prec exprs :: [CodeExpr]
exprs sm :: PrintingInformation
sm = [Expr] -> Expr
P.Row ([Expr] -> Expr) -> [Expr] -> Expr
forall a b. (a -> b) -> a -> b
$ Expr -> [Expr] -> [Expr]
forall a. a -> [a] -> [a]
intersperse (Ops -> Expr
P.MO Ops
op) ([Expr] -> [Expr]) -> [Expr] -> [Expr]
forall a b. (a -> b) -> a -> b
$ (CodeExpr -> Expr) -> [CodeExpr] -> [Expr]
forall a b. (a -> b) -> [a] -> [b]
map (PrintingInformation -> Int -> CodeExpr -> Expr
expr' PrintingInformation
sm Int
prec) [CodeExpr]
exprs

-- | Helper for rendering printable expressions.
addExpr :: [CodeExpr] -> AssocArithOper -> PrintingInformation -> [P.Expr]
addExpr :: [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
addExpr exprs :: [CodeExpr]
exprs o :: AssocArithOper
o sm :: PrintingInformation
sm = [Expr] -> [Expr]
addExprFilter ((CodeExpr -> Expr) -> [CodeExpr] -> [Expr]
forall a b. (a -> b) -> [a] -> [b]
map (PrintingInformation -> Int -> CodeExpr -> Expr
expr' PrintingInformation
sm (AssocArithOper -> Int
precA AssocArithOper
o)) [CodeExpr]
exprs)

-- | Add add symbol only when the second Expr is not negation 
addExprFilter :: [P.Expr] -> [P.Expr]
addExprFilter :: [Expr] -> [Expr]
addExprFilter [] = []
addExprFilter [x :: Expr
x] = [Expr
x]
addExprFilter (x1 :: Expr
x1:P.Row[P.MO P.Neg, x2 :: Expr
x2]:xs :: [Expr]
xs) = Expr
x1 Expr -> [Expr] -> [Expr]
forall a. a -> [a] -> [a]
: [Expr] -> [Expr]
addExprFilter ([Expr] -> Expr
P.Row[Ops -> Expr
P.MO Ops
P.Neg, Expr
x2] Expr -> [Expr] -> [Expr]
forall a. a -> [a] -> [a]
: [Expr]
xs)
addExprFilter (x :: Expr
x:xs :: [Expr]
xs) = Expr
x Expr -> [Expr] -> [Expr]
forall a. a -> [a] -> [a]
: Ops -> Expr
P.MO Ops
P.Add Expr -> [Expr] -> [Expr]
forall a. a -> [a] -> [a]
: [Expr] -> [Expr]
addExprFilter [Expr]
xs

-- | Helper for rendering printable expressions.
mulExpr ::  [CodeExpr] -> AssocArithOper -> PrintingInformation -> [P.Expr]
mulExpr :: [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
mulExpr (hd1 :: CodeExpr
hd1:hd2 :: CodeExpr
hd2:tl :: [CodeExpr]
tl) o :: AssocArithOper
o sm :: PrintingInformation
sm = case (CodeExpr
hd1, CodeExpr
hd2) of
  (a :: CodeExpr
a, Lit (Int _))      ->  [PrintingInformation -> Int -> CodeExpr -> Expr
expr' PrintingInformation
sm (AssocArithOper -> Int
precA AssocArithOper
o) CodeExpr
a, Ops -> Expr
P.MO Ops
P.Dot] [Expr] -> [Expr] -> [Expr]
forall a. [a] -> [a] -> [a]
++ [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
mulExpr (CodeExpr
hd2 CodeExpr -> [CodeExpr] -> [CodeExpr]
forall a. a -> [a] -> [a]
: [CodeExpr]
tl) AssocArithOper
o PrintingInformation
sm
  (a :: CodeExpr
a, Lit (ExactDbl _)) ->  [PrintingInformation -> Int -> CodeExpr -> Expr
expr' PrintingInformation
sm (AssocArithOper -> Int
precA AssocArithOper
o) CodeExpr
a, Ops -> Expr
P.MO Ops
P.Dot] [Expr] -> [Expr] -> [Expr]
forall a. [a] -> [a] -> [a]
++ [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
mulExpr (CodeExpr
hd2 CodeExpr -> [CodeExpr] -> [CodeExpr]
forall a. a -> [a] -> [a]
: [CodeExpr]
tl) AssocArithOper
o PrintingInformation
sm
  (a :: CodeExpr
a, Lit (Dbl _))      ->  [PrintingInformation -> Int -> CodeExpr -> Expr
expr' PrintingInformation
sm (AssocArithOper -> Int
precA AssocArithOper
o) CodeExpr
a, Ops -> Expr
P.MO Ops
P.Dot] [Expr] -> [Expr] -> [Expr]
forall a. [a] -> [a] -> [a]
++ [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
mulExpr (CodeExpr
hd2 CodeExpr -> [CodeExpr] -> [CodeExpr]
forall a. a -> [a] -> [a]
: [CodeExpr]
tl) AssocArithOper
o PrintingInformation
sm
  (a :: CodeExpr
a, _)                ->  [PrintingInformation -> Int -> CodeExpr -> Expr
expr' PrintingInformation
sm (AssocArithOper -> Int
precA AssocArithOper
o) CodeExpr
a, Ops -> Expr
P.MO Ops
P.Mul] [Expr] -> [Expr] -> [Expr]
forall a. [a] -> [a] -> [a]
++ [CodeExpr] -> AssocArithOper -> PrintingInformation -> [Expr]
mulExpr (CodeExpr
hd2 CodeExpr -> [CodeExpr] -> [CodeExpr]
forall a. a -> [a] -> [a]
: [CodeExpr]
tl) AssocArithOper
o PrintingInformation
sm
mulExpr [hd :: CodeExpr
hd]         o :: AssocArithOper
o sm :: PrintingInformation
sm = [PrintingInformation -> Int -> CodeExpr -> Expr
expr' PrintingInformation
sm (AssocArithOper -> Int
precA AssocArithOper
o) CodeExpr
hd]
mulExpr []           o :: AssocArithOper
o sm :: PrintingInformation
sm = [PrintingInformation -> Int -> CodeExpr -> Expr
expr' PrintingInformation
sm (AssocArithOper -> Int
precA AssocArithOper
o) (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int 1)]


-- | Helper that adds parenthesis to the first expression. The second expression
-- is written as a superscript attached to the first.
withParens :: PrintingInformation -> CodeExpr -> CodeExpr -> P.Expr
withParens :: PrintingInformation -> CodeExpr -> CodeExpr -> Expr
withParens prI :: PrintingInformation
prI a :: CodeExpr
a b :: CodeExpr
b = [Expr] -> Expr
P.Row [Expr -> Expr
parens (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
prI), Expr -> Expr
P.Sup (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
prI)]

-- | Helper for properly rendering exponents.
pow :: PrintingInformation -> CodeExpr -> CodeExpr -> P.Expr
pow :: PrintingInformation -> CodeExpr -> CodeExpr -> Expr
pow prI :: PrintingInformation
prI a :: CodeExpr
a@(AssocA AddI _)          b :: CodeExpr
b = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
withParens PrintingInformation
prI CodeExpr
a CodeExpr
b
pow prI :: PrintingInformation
prI a :: CodeExpr
a@(AssocA AddRe _)         b :: CodeExpr
b = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
withParens PrintingInformation
prI CodeExpr
a CodeExpr
b
pow prI :: PrintingInformation
prI a :: CodeExpr
a@(AssocA MulI _)          b :: CodeExpr
b = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
withParens PrintingInformation
prI CodeExpr
a CodeExpr
b
pow prI :: PrintingInformation
prI a :: CodeExpr
a@(AssocA MulRe _)         b :: CodeExpr
b = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
withParens PrintingInformation
prI CodeExpr
a CodeExpr
b
pow prI :: PrintingInformation
prI a :: CodeExpr
a@(ArithBinaryOp Subt _ _) b :: CodeExpr
b = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
withParens PrintingInformation
prI CodeExpr
a CodeExpr
b
pow prI :: PrintingInformation
prI a :: CodeExpr
a@(ArithBinaryOp Frac _ _) b :: CodeExpr
b = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
withParens PrintingInformation
prI CodeExpr
a CodeExpr
b
pow prI :: PrintingInformation
prI a :: CodeExpr
a@(ArithBinaryOp Pow _ _)  b :: CodeExpr
b = PrintingInformation -> CodeExpr -> CodeExpr -> Expr
withParens PrintingInformation
prI CodeExpr
a CodeExpr
b
pow prI :: PrintingInformation
prI a :: CodeExpr
a                          b :: CodeExpr
b = [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
prI, Expr -> Expr
P.Sup (CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
prI)]

-- | Print a 'RealInterval'.
renderRealInt :: PrintingInformation -> Symbol -> RealInterval CodeExpr CodeExpr -> P.Expr
renderRealInt :: PrintingInformation
-> Symbol -> RealInterval CodeExpr CodeExpr -> Expr
renderRealInt st :: PrintingInformation
st s :: Symbol
s (Bounded (Inc,a :: CodeExpr
a) (Inc,b :: CodeExpr
b)) =
  [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
st, Ops -> Expr
P.MO Ops
P.LEq, Symbol -> Expr
symbol Symbol
s, Ops -> Expr
P.MO Ops
P.LEq, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
st]
renderRealInt st :: PrintingInformation
st s :: Symbol
s (Bounded (Inc,a :: CodeExpr
a) (Exc,b :: CodeExpr
b)) =
  [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
st, Ops -> Expr
P.MO Ops
P.LEq, Symbol -> Expr
symbol Symbol
s, Ops -> Expr
P.MO Ops
P.Lt, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
st]
renderRealInt st :: PrintingInformation
st s :: Symbol
s (Bounded (Exc,a :: CodeExpr
a) (Inc,b :: CodeExpr
b)) =
  [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
st, Ops -> Expr
P.MO Ops
P.Lt, Symbol -> Expr
symbol Symbol
s, Ops -> Expr
P.MO Ops
P.LEq, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
st]
renderRealInt st :: PrintingInformation
st s :: Symbol
s (Bounded (Exc,a :: CodeExpr
a) (Exc,b :: CodeExpr
b)) =
  [Expr] -> Expr
P.Row [CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
st, Ops -> Expr
P.MO Ops
P.Lt, Symbol -> Expr
symbol Symbol
s, Ops -> Expr
P.MO Ops
P.Lt, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
b PrintingInformation
st]
renderRealInt st :: PrintingInformation
st s :: Symbol
s (UpTo (Inc,a :: CodeExpr
a))   = [Expr] -> Expr
P.Row [Symbol -> Expr
symbol Symbol
s, Ops -> Expr
P.MO Ops
P.LEq, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
st]
renderRealInt st :: PrintingInformation
st s :: Symbol
s (UpTo (Exc,a :: CodeExpr
a))   = [Expr] -> Expr
P.Row [Symbol -> Expr
symbol Symbol
s, Ops -> Expr
P.MO Ops
P.Lt,  CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
st]
renderRealInt st :: PrintingInformation
st s :: Symbol
s (UpFrom (Inc,a :: CodeExpr
a)) = [Expr] -> Expr
P.Row [Symbol -> Expr
symbol Symbol
s, Ops -> Expr
P.MO Ops
P.GEq, CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
st]
renderRealInt st :: PrintingInformation
st s :: Symbol
s (UpFrom (Exc,a :: CodeExpr
a)) = [Expr] -> Expr
P.Row [Symbol -> Expr
symbol Symbol
s, Ops -> Expr
P.MO Ops
P.Gt,  CodeExpr -> PrintingInformation -> Expr
codeExpr CodeExpr
a PrintingInformation
st]