You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be convenient to have smart constructors for things like (&&) and (+) which directly handle constants. For example, in Language.Hasmtlib.Internal.Expr.Num you could write:
instanceNum (ExprIntSort) wherefromInteger=Constant.IntValue
{-# INLINE fromInteger #-}
(Constant (IntValue0)) + y = y
x + (Constant (IntValue0)) = x
x + y =Plus x y
{-# INLINE (+) #-}
x - (Constant (IntValue0)) = x
x - y =Plus x (Neg y)
{-# INLINE (-) #-}
(Constant (IntValue0)) * _ =0
_ * (Constant (IntValue0)) =0
(Constant (IntValue1)) * y = y
x * (Constant (IntValue1)) = x
x * y =Mul x y
{-# INLINE (*) #-}
negate=Neg
{-# INLINE negate #-}
abs=Abs
{-# INLINE abs #-}
signum x = ite (x ===0) 0$ ite (x <?0) (-1) 1
{-# INLINE signum #-}
and Language.Hasmtlib.Internal.Expr could look as follows:
instanceBoolean (ExprBoolSort) where
bool =Constant.BoolValue
{-# INLINE bool #-}
(Constant (BoolValue x)) && y =if x then y else false
x && (Constant (BoolValue y)) =if y then x else false
x && y =And x y
{-# INLINE (&&) #-}
(Constant (BoolValue x)) || y =if x then true else y
x || (Constant (BoolValue y)) =if y then true else x
x || y =Or x y
{-# INLINE (||) #-}
not (Constant (BoolValue x)) = bool .Prelude.not$ x
not x =Not x
{-# INLINE not #-}
xor (Constant (BoolValue x)) y =if x thenLanguage.Hasmtlib.Boolean.not y else y
xor x (Constant (BoolValue y)) =if y thenLanguage.Hasmtlib.Boolean.not x else x
xor x y =Xor x y
{-# INLINE xor #-}
I saw that as of version 2.3 the constructors of Expr are exported, so I can now just write wrappers which implement this functionality, but I think it's still a useful enhancement of the library :)
The text was updated successfully, but these errors were encountered:
It certainly is!
You may drop a PR if you want. Otherwise i will add it very soon.
This may actually decrease formula size by quite a lot in some use cases.
Thank you!
no specific reason - these are just the cases which I need at the moment ^^
It also just occured to me that I forgot to add proper constant folding for the Num instance, e.g.
It would be convenient to have smart constructors for things like (&&) and (+) which directly handle constants. For example, in Language.Hasmtlib.Internal.Expr.Num you could write:
and Language.Hasmtlib.Internal.Expr could look as follows:
I saw that as of version 2.3 the constructors of Expr are exported, so I can now just write wrappers which implement this functionality, but I think it's still a useful enhancement of the library :)
The text was updated successfully, but these errors were encountered: