{-# LANGUAGE GADTs #-}
module Language.Drasil.ModelExpr.Lang where
import Prelude hiding (sqrt)
import Language.Drasil.Expr.Lang (Completeness)
import Language.Drasil.Literal.Lang (Literal(..))
import Language.Drasil.Space (Space, DomainDesc, RealInterval)
import Language.Drasil.UID (UID)
import Language.Drasil.Literal.Class (LiteralC(..))
data ArithBinOp = Frac | Pow | Subt
deriving ArithBinOp -> ArithBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArithBinOp -> ArithBinOp -> Bool
$c/= :: ArithBinOp -> ArithBinOp -> Bool
== :: ArithBinOp -> ArithBinOp -> Bool
$c== :: ArithBinOp -> ArithBinOp -> Bool
Eq
data EqBinOp = Eq | NEq
deriving EqBinOp -> EqBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EqBinOp -> EqBinOp -> Bool
$c/= :: EqBinOp -> EqBinOp -> Bool
== :: EqBinOp -> EqBinOp -> Bool
$c== :: EqBinOp -> EqBinOp -> Bool
Eq
data BoolBinOp = Impl | Iff
deriving BoolBinOp -> BoolBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BoolBinOp -> BoolBinOp -> Bool
$c/= :: BoolBinOp -> BoolBinOp -> Bool
== :: BoolBinOp -> BoolBinOp -> Bool
$c== :: BoolBinOp -> BoolBinOp -> Bool
Eq
data LABinOp = Index
deriving LABinOp -> LABinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LABinOp -> LABinOp -> Bool
$c/= :: LABinOp -> LABinOp -> Bool
== :: LABinOp -> LABinOp -> Bool
$c== :: LABinOp -> LABinOp -> Bool
Eq
data OrdBinOp = Lt | Gt | LEq | GEq
deriving OrdBinOp -> OrdBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrdBinOp -> OrdBinOp -> Bool
$c/= :: OrdBinOp -> OrdBinOp -> Bool
== :: OrdBinOp -> OrdBinOp -> Bool
$c== :: OrdBinOp -> OrdBinOp -> Bool
Eq
data VVVBinOp = Cross | VAdd | VSub
deriving VVVBinOp -> VVVBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VVVBinOp -> VVVBinOp -> Bool
$c/= :: VVVBinOp -> VVVBinOp -> Bool
== :: VVVBinOp -> VVVBinOp -> Bool
$c== :: VVVBinOp -> VVVBinOp -> Bool
Eq
data VVNBinOp = Dot
deriving VVNBinOp -> VVNBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VVNBinOp -> VVNBinOp -> Bool
$c/= :: VVNBinOp -> VVNBinOp -> Bool
== :: VVNBinOp -> VVNBinOp -> Bool
$c== :: VVNBinOp -> VVNBinOp -> Bool
Eq
data NVVBinOp = Scale
deriving NVVBinOp -> NVVBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NVVBinOp -> NVVBinOp -> Bool
$c/= :: NVVBinOp -> NVVBinOp -> Bool
== :: NVVBinOp -> NVVBinOp -> Bool
$c== :: NVVBinOp -> NVVBinOp -> Bool
Eq
data AssocArithOper = AddI | AddRe | MulI | MulRe
deriving AssocArithOper -> AssocArithOper -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssocArithOper -> AssocArithOper -> Bool
$c/= :: AssocArithOper -> AssocArithOper -> Bool
== :: AssocArithOper -> AssocArithOper -> Bool
$c== :: AssocArithOper -> AssocArithOper -> Bool
Eq
data AssocBoolOper = And | Or | Equivalence
deriving (AssocBoolOper -> AssocBoolOper -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssocBoolOper -> AssocBoolOper -> Bool
$c/= :: AssocBoolOper -> AssocBoolOper -> Bool
== :: AssocBoolOper -> AssocBoolOper -> Bool
$c== :: AssocBoolOper -> AssocBoolOper -> Bool
Eq, Int -> AssocBoolOper -> ShowS
[AssocBoolOper] -> ShowS
AssocBoolOper -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssocBoolOper] -> ShowS
$cshowList :: [AssocBoolOper] -> ShowS
show :: AssocBoolOper -> String
$cshow :: AssocBoolOper -> String
showsPrec :: Int -> AssocBoolOper -> ShowS
$cshowsPrec :: Int -> AssocBoolOper -> ShowS
Show)
data UFunc = Abs | Log | Ln | Sin | Cos | Tan | Sec | Csc | Cot | Arcsin
| Arccos | Arctan | Exp | Sqrt | Neg
deriving UFunc -> UFunc -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UFunc -> UFunc -> Bool
$c/= :: UFunc -> UFunc -> Bool
== :: UFunc -> UFunc -> Bool
$c== :: UFunc -> UFunc -> Bool
Eq
data UFuncB = Not
deriving UFuncB -> UFuncB -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UFuncB -> UFuncB -> Bool
$c/= :: UFuncB -> UFuncB -> Bool
== :: UFuncB -> UFuncB -> Bool
$c== :: UFuncB -> UFuncB -> Bool
Eq
data UFuncVV = NegV
deriving UFuncVV -> UFuncVV -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UFuncVV -> UFuncVV -> Bool
$c/= :: UFuncVV -> UFuncVV -> Bool
== :: UFuncVV -> UFuncVV -> Bool
$c== :: UFuncVV -> UFuncVV -> Bool
Eq
data UFuncVN = Norm | Dim
deriving UFuncVN -> UFuncVN -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UFuncVN -> UFuncVN -> Bool
$c/= :: UFuncVN -> UFuncVN -> Bool
== :: UFuncVN -> UFuncVN -> Bool
$c== :: UFuncVN -> UFuncVN -> Bool
Eq
data StatBinOp = Defines
deriving StatBinOp -> StatBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatBinOp -> StatBinOp -> Bool
$c/= :: StatBinOp -> StatBinOp -> Bool
== :: StatBinOp -> StatBinOp -> Bool
$c== :: StatBinOp -> StatBinOp -> Bool
Eq
data SpaceBinOp = IsIn
deriving SpaceBinOp -> SpaceBinOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpaceBinOp -> SpaceBinOp -> Bool
$c/= :: SpaceBinOp -> SpaceBinOp -> Bool
== :: SpaceBinOp -> SpaceBinOp -> Bool
$c== :: SpaceBinOp -> SpaceBinOp -> Bool
Eq
data DerivType = Part | Total
deriving DerivType -> DerivType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DerivType -> DerivType -> Bool
$c/= :: DerivType -> DerivType -> Bool
== :: DerivType -> DerivType -> Bool
$c== :: DerivType -> DerivType -> Bool
Eq
data ModelExpr where
Lit :: Literal -> ModelExpr
Spc :: Space -> ModelExpr
AssocA :: AssocArithOper -> [ModelExpr] -> ModelExpr
AssocB :: AssocBoolOper -> [ModelExpr] -> ModelExpr
Deriv :: Integer -> DerivType -> ModelExpr -> UID -> ModelExpr
C :: UID -> ModelExpr
FCall :: UID -> [ModelExpr] -> ModelExpr
Case :: Completeness -> [(ModelExpr, ModelExpr)] -> ModelExpr
Matrix :: [[ModelExpr]] -> ModelExpr
UnaryOp :: UFunc -> ModelExpr -> ModelExpr
UnaryOpB :: UFuncB -> ModelExpr -> ModelExpr
UnaryOpVV :: UFuncVV -> ModelExpr -> ModelExpr
UnaryOpVN :: UFuncVN -> ModelExpr -> ModelExpr
ArithBinaryOp :: ArithBinOp -> ModelExpr -> ModelExpr -> ModelExpr
BoolBinaryOp :: BoolBinOp -> ModelExpr -> ModelExpr -> ModelExpr
EqBinaryOp :: EqBinOp -> ModelExpr -> ModelExpr -> ModelExpr
LABinaryOp :: LABinOp -> ModelExpr -> ModelExpr -> ModelExpr
OrdBinaryOp :: OrdBinOp -> ModelExpr -> ModelExpr -> ModelExpr
SpaceBinaryOp :: SpaceBinOp -> ModelExpr -> ModelExpr -> ModelExpr
StatBinaryOp :: StatBinOp -> ModelExpr -> ModelExpr -> ModelExpr
VVVBinaryOp :: VVVBinOp -> ModelExpr -> ModelExpr -> ModelExpr
VVNBinaryOp :: VVNBinOp -> ModelExpr -> ModelExpr -> ModelExpr
NVVBinaryOp :: NVVBinOp -> ModelExpr -> ModelExpr -> ModelExpr
Operator :: AssocArithOper -> DomainDesc t ModelExpr ModelExpr -> ModelExpr -> ModelExpr
RealI :: UID -> RealInterval ModelExpr ModelExpr -> ModelExpr
ForAll :: UID -> Space -> ModelExpr -> ModelExpr
type Variable = String
instance Eq ModelExpr where
Lit Literal
l == :: ModelExpr -> ModelExpr -> Bool
== Lit Literal
r = Literal
l forall a. Eq a => a -> a -> Bool
== Literal
r
AssocA AssocArithOper
o1 [ModelExpr]
l1 == AssocA AssocArithOper
o2 [ModelExpr]
l2 = AssocArithOper
o1 forall a. Eq a => a -> a -> Bool
== AssocArithOper
o2 Bool -> Bool -> Bool
&& [ModelExpr]
l1 forall a. Eq a => a -> a -> Bool
== [ModelExpr]
l2
AssocB AssocBoolOper
o1 [ModelExpr]
l1 == AssocB AssocBoolOper
o2 [ModelExpr]
l2 = AssocBoolOper
o1 forall a. Eq a => a -> a -> Bool
== AssocBoolOper
o2 Bool -> Bool -> Bool
&& [ModelExpr]
l1 forall a. Eq a => a -> a -> Bool
== [ModelExpr]
l2
Deriv Integer
a DerivType
t1 ModelExpr
b UID
c == Deriv Integer
d DerivType
t2 ModelExpr
e UID
f = Integer
a forall a. Eq a => a -> a -> Bool
== Integer
d Bool -> Bool -> Bool
&& DerivType
t1 forall a. Eq a => a -> a -> Bool
== DerivType
t2 Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
e Bool -> Bool -> Bool
&& UID
c forall a. Eq a => a -> a -> Bool
== UID
f
C UID
a == C UID
b = UID
a forall a. Eq a => a -> a -> Bool
== UID
b
FCall UID
a [ModelExpr]
b == FCall UID
c [ModelExpr]
d = UID
a forall a. Eq a => a -> a -> Bool
== UID
c Bool -> Bool -> Bool
&& [ModelExpr]
b forall a. Eq a => a -> a -> Bool
== [ModelExpr]
d
Case Completeness
a [(ModelExpr, ModelExpr)]
b == Case Completeness
c [(ModelExpr, ModelExpr)]
d = Completeness
a forall a. Eq a => a -> a -> Bool
== Completeness
c Bool -> Bool -> Bool
&& [(ModelExpr, ModelExpr)]
b forall a. Eq a => a -> a -> Bool
== [(ModelExpr, ModelExpr)]
d
UnaryOp UFunc
a ModelExpr
b == UnaryOp UFunc
c ModelExpr
d = UFunc
a forall a. Eq a => a -> a -> Bool
== UFunc
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
UnaryOpB UFuncB
a ModelExpr
b == UnaryOpB UFuncB
c ModelExpr
d = UFuncB
a forall a. Eq a => a -> a -> Bool
== UFuncB
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
UnaryOpVV UFuncVV
a ModelExpr
b == UnaryOpVV UFuncVV
c ModelExpr
d = UFuncVV
a forall a. Eq a => a -> a -> Bool
== UFuncVV
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
UnaryOpVN UFuncVN
a ModelExpr
b == UnaryOpVN UFuncVN
c ModelExpr
d = UFuncVN
a forall a. Eq a => a -> a -> Bool
== UFuncVN
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
ArithBinaryOp ArithBinOp
o ModelExpr
a ModelExpr
b == ArithBinaryOp ArithBinOp
p ModelExpr
c ModelExpr
d = ArithBinOp
o forall a. Eq a => a -> a -> Bool
== ArithBinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
BoolBinaryOp BoolBinOp
o ModelExpr
a ModelExpr
b == BoolBinaryOp BoolBinOp
p ModelExpr
c ModelExpr
d = BoolBinOp
o forall a. Eq a => a -> a -> Bool
== BoolBinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
EqBinaryOp EqBinOp
o ModelExpr
a ModelExpr
b == EqBinaryOp EqBinOp
p ModelExpr
c ModelExpr
d = EqBinOp
o forall a. Eq a => a -> a -> Bool
== EqBinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
OrdBinaryOp OrdBinOp
o ModelExpr
a ModelExpr
b == OrdBinaryOp OrdBinOp
p ModelExpr
c ModelExpr
d = OrdBinOp
o forall a. Eq a => a -> a -> Bool
== OrdBinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
SpaceBinaryOp SpaceBinOp
o ModelExpr
a ModelExpr
b == SpaceBinaryOp SpaceBinOp
p ModelExpr
c ModelExpr
d = SpaceBinOp
o forall a. Eq a => a -> a -> Bool
== SpaceBinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
StatBinaryOp StatBinOp
o ModelExpr
a ModelExpr
b == StatBinaryOp StatBinOp
p ModelExpr
c ModelExpr
d = StatBinOp
o forall a. Eq a => a -> a -> Bool
== StatBinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
LABinaryOp LABinOp
o ModelExpr
a ModelExpr
b == LABinaryOp LABinOp
p ModelExpr
c ModelExpr
d = LABinOp
o forall a. Eq a => a -> a -> Bool
== LABinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
VVVBinaryOp VVVBinOp
o ModelExpr
a ModelExpr
b == VVVBinaryOp VVVBinOp
p ModelExpr
c ModelExpr
d = VVVBinOp
o forall a. Eq a => a -> a -> Bool
== VVVBinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
VVNBinaryOp VVNBinOp
o ModelExpr
a ModelExpr
b == VVNBinaryOp VVNBinOp
p ModelExpr
c ModelExpr
d = VVNBinOp
o forall a. Eq a => a -> a -> Bool
== VVNBinOp
p Bool -> Bool -> Bool
&& ModelExpr
a forall a. Eq a => a -> a -> Bool
== ModelExpr
c Bool -> Bool -> Bool
&& ModelExpr
b forall a. Eq a => a -> a -> Bool
== ModelExpr
d
ModelExpr
_ == ModelExpr
_ = Bool
False
instance LiteralC ModelExpr where
int :: Integer -> ModelExpr
int = Literal -> ModelExpr
Lit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. LiteralC r => Integer -> r
int
str :: String -> ModelExpr
str = Literal -> ModelExpr
Lit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. LiteralC r => String -> r
str
dbl :: Double -> ModelExpr
dbl = Literal -> ModelExpr
Lit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. LiteralC r => Double -> r
dbl
exactDbl :: Integer -> ModelExpr
exactDbl = Literal -> ModelExpr
Lit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. LiteralC r => Integer -> r
exactDbl
perc :: Integer -> Integer -> ModelExpr
perc Integer
l Integer
r = Literal -> ModelExpr
Lit forall a b. (a -> b) -> a -> b
$ forall r. LiteralC r => Integer -> Integer -> r
perc Integer
l Integer
r