{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE LiberalTypeSynonyms #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module What4.Interface
(
SymExpr
, BoundVar
, SymFn
, SymAnnotation
, IsExpr(..)
, IsSymFn(..)
, SomeSymFn(..)
, SymFnWrapper(..)
, UnfoldPolicy(..)
, shouldUnfold
, IsExprBuilder(..)
, IsSymExprBuilder(..)
, SolverEvent(..)
, SolverStartSATQuery(..)
, SolverEndSATQuery(..)
, bvJoinVector
, bvSplitVector
, bvSwap
, bvBitreverse
, RoundingMode(..)
, Statistics(..)
, zeroStatistics
, Pred
, SymInteger
, SymReal
, SymFloat
, SymString
, SymCplx
, SymStruct
, SymBV
, SymArray
, SymNat
, asNat
, natLit
, natAdd
, natSub
, natMul
, natDiv
, natMod
, natIte
, natEq
, natLe
, natLt
, natToInteger
, natToIntegerPure
, bvToNat
, natToReal
, integerToNat
, realToNat
, freshBoundedNat
, freshNat
, printSymNat
, IndexLit(..)
, indexLit
, ArrayResultWrapper(..)
, asConcrete
, concreteToSym
, baseIsConcrete
, baseDefaultValue
, realExprAsInteger
, rationalAsInteger
, cplxExprAsRational
, cplxExprAsInteger
, SymEncoder(..)
, bvZero
, bvOne
, backendPred
, andAllOf
, orOneOf
, itePredM
, iteM
, iteList
, predToReal
, cplxDiv
, cplxLog
, cplxLogBase
, mkRational
, mkReal
, isNonZero
, isReal
, muxRange
, InvalidRange(..)
, module Data.Parameterized.NatRepr
, module What4.BaseTypes
, HasAbsValue
, What4.Symbol.SolverSymbol
, What4.Symbol.emptySymbol
, What4.Symbol.userSymbol
, What4.Symbol.safeSymbol
, ValueRange(..)
, StringLiteral(..)
, stringLiteralInfo
) where
#if !MIN_VERSION_base(4,13,0)
import Control.Monad.Fail( MonadFail )
#endif
import Control.Exception (assert, Exception)
import Control.Lens
import Control.Monad
import Control.Monad.IO.Class
import qualified Data.BitVector.Sized as BV
import Data.Coerce (coerce)
import Data.Foldable
import Data.Kind ( Type )
import Data.Map.Strict (Map)
import qualified Data.Map as Map
import Data.Parameterized.Classes
import qualified Data.Parameterized.Context as Ctx
import Data.Parameterized.Ctx
import Data.Parameterized.Utils.Endian (Endian(..))
import Data.Parameterized.Map (MapF)
import Data.Parameterized.NatRepr
import Data.Parameterized.TraversableFC
import qualified Data.Parameterized.Vector as Vector
import Data.Ratio
import Data.Scientific (Scientific)
import Data.Set (Set)
import GHC.Generics (Generic)
import Numeric.Natural
import LibBF (BigFloat)
import Prettyprinter (Doc)
import What4.BaseTypes
import What4.Config
import qualified What4.Expr.ArrayUpdateMap as AUM
import What4.IndexLit
import What4.ProgramLoc
import What4.Concrete
import What4.SatResult
import What4.SpecialFunctions
import What4.Symbol
import What4.Utils.AbstractDomains
import What4.Utils.Arithmetic
import What4.Utils.Complex
import What4.Utils.FloatHelpers (RoundingMode(..))
import What4.Utils.StringLiteral
type Pred sym = SymExpr sym BaseBoolType
type SymInteger sym = SymExpr sym BaseIntegerType
type SymReal sym = SymExpr sym BaseRealType
type SymFloat sym fpp = SymExpr sym (BaseFloatType fpp)
type SymCplx sym = SymExpr sym BaseComplexType
type SymStruct sym flds = SymExpr sym (BaseStructType flds)
type SymArray sym idx b = SymExpr sym (BaseArrayType idx b)
type SymBV sym n = SymExpr sym (BaseBVType n)
type SymString sym si = SymExpr sym (BaseStringType si)
type family SymExpr (sym :: Type) :: BaseType -> Type
type family BoundVar (sym :: Type) :: BaseType -> Type
type family SymAnnotation (sym :: Type) :: BaseType -> Type
itePredM :: (IsExpr (SymExpr sym), IsExprBuilder sym, MonadIO m)
=> sym
-> Pred sym
-> m (Pred sym)
-> m (Pred sym)
-> m (Pred sym)
itePredM :: forall sym (m :: Type -> Type).
(IsExpr (SymExpr sym), IsExprBuilder sym, MonadIO m) =>
sym -> Pred sym -> m (Pred sym) -> m (Pred sym) -> m (Pred sym)
itePredM sym
sym Pred sym
c m (Pred sym)
mx m (Pred sym)
my =
case Pred sym -> Maybe Bool
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseBoolType -> Maybe Bool
asConstantPred Pred sym
c of
Just Bool
True -> m (Pred sym)
mx
Just Bool
False -> m (Pred sym)
my
Maybe Bool
Nothing -> do
x <- m (Pred sym)
mx
y <- my
liftIO $ itePred sym c x y
class HasAbsValue e => IsExpr e where
asConstantPred :: e BaseBoolType -> Maybe Bool
asConstantPred e BaseBoolType
_ = Maybe Bool
forall a. Maybe a
Nothing
asInteger :: e BaseIntegerType -> Maybe Integer
asInteger e BaseIntegerType
_ = Maybe Integer
forall a. Maybe a
Nothing
integerBounds :: e BaseIntegerType -> ValueRange Integer
asRational :: e BaseRealType -> Maybe Rational
asRational e BaseRealType
_ = Maybe Rational
forall a. Maybe a
Nothing
asFloat :: e (BaseFloatType fpp) -> Maybe BigFloat
rationalBounds :: e BaseRealType -> ValueRange Rational
asComplex :: e BaseComplexType -> Maybe (Complex Rational)
asComplex e BaseComplexType
_ = Maybe (Complex Rational)
forall a. Maybe a
Nothing
asBV :: e (BaseBVType w) -> Maybe (BV.BV w)
asBV e (BaseBVType w)
_ = Maybe (BV w)
forall a. Maybe a
Nothing
unsignedBVBounds :: (1 <= w) => e (BaseBVType w) -> Maybe (Integer, Integer)
signedBVBounds :: (1 <= w) => e (BaseBVType w) -> Maybe (Integer, Integer)
asAffineVar :: e tp -> Maybe (ConcreteVal tp, e tp, ConcreteVal tp)
asString :: e (BaseStringType si) -> Maybe (StringLiteral si)
asString e (BaseStringType si)
_ = Maybe (StringLiteral si)
forall a. Maybe a
Nothing
stringInfo :: e (BaseStringType si) -> StringInfoRepr si
stringInfo e (BaseStringType si)
e =
case e (BaseStringType si) -> BaseTypeRepr (BaseStringType si)
forall (tp :: BaseType). e tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType e (BaseStringType si)
e of
BaseStringRepr StringInfoRepr si
si -> StringInfoRepr si
StringInfoRepr si
si
asConstantArray :: e (BaseArrayType idx bt) -> Maybe (e bt)
asConstantArray e (BaseArrayType idx bt)
_ = Maybe (e bt)
forall a. Maybe a
Nothing
asStruct :: e (BaseStructType flds) -> Maybe (Ctx.Assignment e flds)
asStruct e (BaseStructType flds)
_ = Maybe (Assignment e flds)
forall a. Maybe a
Nothing
exprType :: e tp -> BaseTypeRepr tp
bvWidth :: e (BaseBVType w) -> NatRepr w
bvWidth e (BaseBVType w)
e =
case e (BaseBVType w) -> BaseTypeRepr (BaseBVType w)
forall (tp :: BaseType). e tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType e (BaseBVType w)
e of
BaseBVRepr NatRepr w
w -> NatRepr w
NatRepr w
w
floatPrecision :: e (BaseFloatType fpp) -> FloatPrecisionRepr fpp
floatPrecision e (BaseFloatType fpp)
e =
case e (BaseFloatType fpp) -> BaseTypeRepr (BaseFloatType fpp)
forall (tp :: BaseType). e tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType e (BaseFloatType fpp)
e of
BaseFloatRepr FloatPrecisionRepr fpp
fpp -> FloatPrecisionRepr fpp
FloatPrecisionRepr fpp
fpp
printSymExpr :: e tp -> Doc ann
unsafeSetAbstractValue :: AbstractValue tp -> e tp -> e tp
newtype ArrayResultWrapper f idx tp =
ArrayResultWrapper { forall (f :: BaseType -> Type) (idx :: Ctx BaseType)
(tp :: BaseType).
ArrayResultWrapper f idx tp -> f (BaseArrayType idx tp)
unwrapArrayResult :: f (BaseArrayType idx tp) }
instance TestEquality f => TestEquality (ArrayResultWrapper f idx) where
testEquality :: forall (a :: BaseType) (b :: BaseType).
ArrayResultWrapper f idx a
-> ArrayResultWrapper f idx b -> Maybe (a :~: b)
testEquality (ArrayResultWrapper f (BaseArrayType idx a)
x) (ArrayResultWrapper f (BaseArrayType idx b)
y) = do
Refl <- f (BaseArrayType idx a)
-> f (BaseArrayType idx b)
-> Maybe (BaseArrayType idx a :~: BaseArrayType idx b)
forall {k} (f :: k -> Type) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
forall (a :: BaseType) (b :: BaseType).
f a -> f b -> Maybe (a :~: b)
testEquality f (BaseArrayType idx a)
x f (BaseArrayType idx b)
y
return Refl
instance HashableF e => HashableF (ArrayResultWrapper e idx) where
hashWithSaltF :: forall (tp :: BaseType). Int -> ArrayResultWrapper e idx tp -> Int
hashWithSaltF Int
s (ArrayResultWrapper e (BaseArrayType idx tp)
v) = Int -> e (BaseArrayType idx tp) -> Int
forall k (f :: k -> Type) (tp :: k).
HashableF f =>
Int -> f tp -> Int
forall (tp :: BaseType). Int -> e tp -> Int
hashWithSaltF Int
s e (BaseArrayType idx tp)
v
data SolverEvent
= SolverStartSATQuery SolverStartSATQuery
| SolverEndSATQuery SolverEndSATQuery
deriving (Int -> SolverEvent -> ShowS
[SolverEvent] -> ShowS
SolverEvent -> String
(Int -> SolverEvent -> ShowS)
-> (SolverEvent -> String)
-> ([SolverEvent] -> ShowS)
-> Show SolverEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SolverEvent -> ShowS
showsPrec :: Int -> SolverEvent -> ShowS
$cshow :: SolverEvent -> String
show :: SolverEvent -> String
$cshowList :: [SolverEvent] -> ShowS
showList :: [SolverEvent] -> ShowS
Show, (forall x. SolverEvent -> Rep SolverEvent x)
-> (forall x. Rep SolverEvent x -> SolverEvent)
-> Generic SolverEvent
forall x. Rep SolverEvent x -> SolverEvent
forall x. SolverEvent -> Rep SolverEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SolverEvent -> Rep SolverEvent x
from :: forall x. SolverEvent -> Rep SolverEvent x
$cto :: forall x. Rep SolverEvent x -> SolverEvent
to :: forall x. Rep SolverEvent x -> SolverEvent
Generic)
data SolverStartSATQuery = SolverStartSATQueryRec
{ SolverStartSATQuery -> String
satQuerySolverName :: !String
, SolverStartSATQuery -> String
satQueryReason :: !String
}
deriving (Int -> SolverStartSATQuery -> ShowS
[SolverStartSATQuery] -> ShowS
SolverStartSATQuery -> String
(Int -> SolverStartSATQuery -> ShowS)
-> (SolverStartSATQuery -> String)
-> ([SolverStartSATQuery] -> ShowS)
-> Show SolverStartSATQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SolverStartSATQuery -> ShowS
showsPrec :: Int -> SolverStartSATQuery -> ShowS
$cshow :: SolverStartSATQuery -> String
show :: SolverStartSATQuery -> String
$cshowList :: [SolverStartSATQuery] -> ShowS
showList :: [SolverStartSATQuery] -> ShowS
Show, (forall x. SolverStartSATQuery -> Rep SolverStartSATQuery x)
-> (forall x. Rep SolverStartSATQuery x -> SolverStartSATQuery)
-> Generic SolverStartSATQuery
forall x. Rep SolverStartSATQuery x -> SolverStartSATQuery
forall x. SolverStartSATQuery -> Rep SolverStartSATQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SolverStartSATQuery -> Rep SolverStartSATQuery x
from :: forall x. SolverStartSATQuery -> Rep SolverStartSATQuery x
$cto :: forall x. Rep SolverStartSATQuery x -> SolverStartSATQuery
to :: forall x. Rep SolverStartSATQuery x -> SolverStartSATQuery
Generic)
data SolverEndSATQuery = SolverEndSATQueryRec
{ SolverEndSATQuery -> SatResult () ()
satQueryResult :: !(SatResult () ())
, SolverEndSATQuery -> Maybe String
satQueryError :: !(Maybe String)
}
deriving (Int -> SolverEndSATQuery -> ShowS
[SolverEndSATQuery] -> ShowS
SolverEndSATQuery -> String
(Int -> SolverEndSATQuery -> ShowS)
-> (SolverEndSATQuery -> String)
-> ([SolverEndSATQuery] -> ShowS)
-> Show SolverEndSATQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SolverEndSATQuery -> ShowS
showsPrec :: Int -> SolverEndSATQuery -> ShowS
$cshow :: SolverEndSATQuery -> String
show :: SolverEndSATQuery -> String
$cshowList :: [SolverEndSATQuery] -> ShowS
showList :: [SolverEndSATQuery] -> ShowS
Show, (forall x. SolverEndSATQuery -> Rep SolverEndSATQuery x)
-> (forall x. Rep SolverEndSATQuery x -> SolverEndSATQuery)
-> Generic SolverEndSATQuery
forall x. Rep SolverEndSATQuery x -> SolverEndSATQuery
forall x. SolverEndSATQuery -> Rep SolverEndSATQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SolverEndSATQuery -> Rep SolverEndSATQuery x
from :: forall x. SolverEndSATQuery -> Rep SolverEndSATQuery x
$cto :: forall x. Rep SolverEndSATQuery x -> SolverEndSATQuery
to :: forall x. Rep SolverEndSATQuery x -> SolverEndSATQuery
Generic)
newtype SymNat sym =
SymNat
{
forall sym. SymNat sym -> SymExpr sym BaseIntegerType
_symNat :: SymExpr sym BaseIntegerType
}
asNat :: IsExpr (SymExpr sym) => SymNat sym -> Maybe Natural
asNat :: forall sym. IsExpr (SymExpr sym) => SymNat sym -> Maybe Nat
asNat (SymNat SymExpr sym BaseIntegerType
x) = Integer -> Nat
forall a. Num a => Integer -> a
fromInteger (Integer -> Nat) -> (Integer -> Integer) -> Integer -> Nat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Integer -> Integer
forall a. Ord a => a -> a -> a
max Integer
0 (Integer -> Nat) -> Maybe Integer -> Maybe Nat
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> SymExpr sym BaseIntegerType -> Maybe Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> Maybe Integer
asInteger SymExpr sym BaseIntegerType
x
natLit :: IsExprBuilder sym => sym -> Natural -> IO (SymNat sym)
natLit :: forall sym. IsExprBuilder sym => sym -> Nat -> IO (SymNat sym)
natLit sym
sym Nat
x = SymExpr sym BaseIntegerType -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymExpr sym BaseIntegerType -> SymNat sym)
-> IO (SymExpr sym BaseIntegerType) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym -> Integer -> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym -> Integer -> IO (SymInteger sym)
intLit sym
sym (Nat -> Integer
forall a. Integral a => a -> Integer
toInteger Nat
x)
natAdd :: IsExprBuilder sym => sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natAdd :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natAdd sym
sym (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) = SymExpr sym BaseIntegerType -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymExpr sym BaseIntegerType -> SymNat sym)
-> IO (SymExpr sym BaseIntegerType) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym
-> SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intAdd sym
sym SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y
natSub :: IsExprBuilder sym => sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natSub :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natSub sym
sym (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) =
do z <- sym
-> SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intSub sym
sym SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y
SymNat <$> (intMax sym z =<< intLit sym 0)
natMul :: IsExprBuilder sym => sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natMul :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natMul sym
sym (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) = SymExpr sym BaseIntegerType -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymExpr sym BaseIntegerType -> SymNat sym)
-> IO (SymExpr sym BaseIntegerType) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym
-> SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intMul sym
sym SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y
natDiv :: IsExprBuilder sym => sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natDiv :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natDiv sym
sym (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) = SymExpr sym BaseIntegerType -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymExpr sym BaseIntegerType -> SymNat sym)
-> IO (SymExpr sym BaseIntegerType) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym
-> SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intDiv sym
sym SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y
natMod :: IsExprBuilder sym => sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natMod :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natMod sym
sym (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) = SymExpr sym BaseIntegerType -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymExpr sym BaseIntegerType -> SymNat sym)
-> IO (SymExpr sym BaseIntegerType) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym
-> SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intMod sym
sym SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y
natIte :: IsExprBuilder sym => sym -> Pred sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natIte :: forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> SymNat sym -> SymNat sym -> IO (SymNat sym)
natIte sym
sym Pred sym
p (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) = SymExpr sym BaseIntegerType -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymExpr sym BaseIntegerType -> SymNat sym)
-> IO (SymExpr sym BaseIntegerType) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym
-> Pred sym
-> SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym
-> Pred sym
-> SymInteger sym
-> SymInteger sym
-> IO (SymInteger sym)
intIte sym
sym Pred sym
p SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y
natEq :: IsExprBuilder sym => sym -> SymNat sym -> SymNat sym -> IO (Pred sym)
natEq :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (Pred sym)
natEq sym
sym (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) = sym
-> SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intEq sym
sym SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y
natLe :: IsExprBuilder sym => sym -> SymNat sym -> SymNat sym -> IO (Pred sym)
natLe :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (Pred sym)
natLe sym
sym (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) = sym
-> SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intLe sym
sym SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y
natLt :: IsExprBuilder sym => sym -> SymNat sym -> SymNat sym -> IO (Pred sym)
natLt :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (Pred sym)
natLt sym
sym SymNat sym
x SymNat sym
y = sym -> SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym (SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType))
-> IO (SymExpr sym BaseBoolType) -> IO (SymExpr sym BaseBoolType)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymNat sym -> SymNat sym -> IO (SymExpr sym BaseBoolType)
forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> SymNat sym -> IO (Pred sym)
natLe sym
sym SymNat sym
y SymNat sym
x
natToInteger :: IsExprBuilder sym => sym -> SymNat sym -> IO (SymInteger sym)
natToInteger :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> IO (SymInteger sym)
natToInteger sym
_sym (SymNat SymExpr sym BaseIntegerType
x) = SymExpr sym BaseIntegerType -> IO (SymExpr sym BaseIntegerType)
forall a. a -> IO a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure SymExpr sym BaseIntegerType
x
natToIntegerPure :: SymNat sym -> SymInteger sym
natToIntegerPure :: forall sym. SymNat sym -> SymExpr sym BaseIntegerType
natToIntegerPure (SymNat SymExpr sym BaseIntegerType
x) = SymExpr sym BaseIntegerType
x
bvToNat :: (IsExprBuilder sym, 1 <= w) => sym -> SymBV sym w -> IO (SymNat sym)
bvToNat :: forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> IO (SymNat sym)
bvToNat sym
sym SymBV sym w
x = SymExpr sym BaseIntegerType -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymExpr sym BaseIntegerType -> SymNat sym)
-> IO (SymExpr sym BaseIntegerType) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym -> SymBV sym w -> IO (SymExpr sym BaseIntegerType)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> IO (SymExpr sym BaseIntegerType)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> IO (SymInteger sym)
bvToInteger sym
sym SymBV sym w
x
natToReal :: IsExprBuilder sym => sym -> SymNat sym -> IO (SymReal sym)
natToReal :: forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> IO (SymReal sym)
natToReal sym
sym = sym -> SymNat sym -> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym -> SymNat sym -> IO (SymInteger sym)
natToInteger sym
sym (SymNat sym -> IO (SymExpr sym BaseIntegerType))
-> (SymExpr sym BaseIntegerType -> IO (SymExpr sym BaseRealType))
-> SymNat sym
-> IO (SymExpr sym BaseRealType)
forall (m :: Type -> Type) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> sym -> SymExpr sym BaseIntegerType -> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> IO (SymReal sym)
integerToReal sym
sym
integerToNat :: IsExprBuilder sym => sym -> SymInteger sym -> IO (SymNat sym)
integerToNat :: forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> IO (SymNat sym)
integerToNat sym
sym SymInteger sym
x = SymInteger sym -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymInteger sym -> SymNat sym)
-> IO (SymInteger sym) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intMax sym
sym SymInteger sym
x (SymInteger sym -> IO (SymInteger sym))
-> IO (SymInteger sym) -> IO (SymInteger sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> Integer -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> Integer -> IO (SymInteger sym)
intLit sym
sym Integer
0)
realToNat :: IsExprBuilder sym => sym -> SymReal sym -> IO (SymNat sym)
realToNat :: forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymNat sym)
realToNat sym
sym SymReal sym
r = sym -> SymReal sym -> IO (SymExpr sym BaseIntegerType)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymInteger sym)
realToInteger sym
sym SymReal sym
r IO (SymExpr sym BaseIntegerType)
-> (SymExpr sym BaseIntegerType -> IO (SymNat sym))
-> IO (SymNat sym)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= sym -> SymExpr sym BaseIntegerType -> IO (SymNat sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> IO (SymNat sym)
integerToNat sym
sym
freshBoundedNat ::
IsSymExprBuilder sym =>
sym ->
SolverSymbol ->
Maybe Natural ->
Maybe Natural ->
IO (SymNat sym)
freshBoundedNat :: forall sym.
IsSymExprBuilder sym =>
sym -> SolverSymbol -> Maybe Nat -> Maybe Nat -> IO (SymNat sym)
freshBoundedNat sym
sym SolverSymbol
s Maybe Nat
lo Maybe Nat
hi = SymExpr sym BaseIntegerType -> SymNat sym
forall sym. SymExpr sym BaseIntegerType -> SymNat sym
SymNat (SymExpr sym BaseIntegerType -> SymNat sym)
-> IO (SymExpr sym BaseIntegerType) -> IO (SymNat sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (sym
-> SolverSymbol
-> Maybe Integer
-> Maybe Integer
-> IO (SymExpr sym BaseIntegerType)
forall sym.
IsSymExprBuilder sym =>
sym
-> SolverSymbol
-> Maybe Integer
-> Maybe Integer
-> IO (SymInteger sym)
freshBoundedInt sym
sym SolverSymbol
s Maybe Integer
lo' Maybe Integer
hi')
where
lo' :: Maybe Integer
lo' = Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Integer -> (Nat -> Integer) -> Maybe Nat -> Integer
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Integer
0 Nat -> Integer
forall a. Integral a => a -> Integer
toInteger Maybe Nat
lo)
hi' :: Maybe Integer
hi' = Nat -> Integer
forall a. Integral a => a -> Integer
toInteger (Nat -> Integer) -> Maybe Nat -> Maybe Integer
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Nat
hi
freshNat :: IsSymExprBuilder sym => sym -> SolverSymbol -> IO (SymNat sym)
freshNat :: forall sym.
IsSymExprBuilder sym =>
sym -> SolverSymbol -> IO (SymNat sym)
freshNat sym
sym SolverSymbol
s = sym -> SolverSymbol -> Maybe Nat -> Maybe Nat -> IO (SymNat sym)
forall sym.
IsSymExprBuilder sym =>
sym -> SolverSymbol -> Maybe Nat -> Maybe Nat -> IO (SymNat sym)
freshBoundedNat sym
sym SolverSymbol
s (Nat -> Maybe Nat
forall a. a -> Maybe a
Just Nat
0) Maybe Nat
forall a. Maybe a
Nothing
printSymNat :: IsExpr (SymExpr sym) => SymNat sym -> Doc ann
printSymNat :: forall sym ann. IsExpr (SymExpr sym) => SymNat sym -> Doc ann
printSymNat (SymNat SymExpr sym BaseIntegerType
x) = SymExpr sym BaseIntegerType -> Doc ann
forall (tp :: BaseType) ann. SymExpr sym tp -> Doc ann
forall (e :: BaseType -> Type) (tp :: BaseType) ann.
IsExpr e =>
e tp -> Doc ann
printSymExpr SymExpr sym BaseIntegerType
x
instance TestEquality (SymExpr sym) => Eq (SymNat sym) where
SymNat SymExpr sym BaseIntegerType
x == :: SymNat sym -> SymNat sym -> Bool
== SymNat SymExpr sym BaseIntegerType
y = Maybe (BaseIntegerType :~: BaseIntegerType) -> Bool
forall a. Maybe a -> Bool
isJust (SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> Maybe (BaseIntegerType :~: BaseIntegerType)
forall {k} (f :: k -> Type) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
forall (a :: BaseType) (b :: BaseType).
SymExpr sym a -> SymExpr sym b -> Maybe (a :~: b)
testEquality SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y)
instance OrdF (SymExpr sym) => Ord (SymNat sym) where
compare :: SymNat sym -> SymNat sym -> Ordering
compare (SymNat SymExpr sym BaseIntegerType
x) (SymNat SymExpr sym BaseIntegerType
y) = OrderingF BaseIntegerType BaseIntegerType -> Ordering
forall {k} (x :: k) (y :: k). OrderingF x y -> Ordering
toOrdering (SymExpr sym BaseIntegerType
-> SymExpr sym BaseIntegerType
-> OrderingF BaseIntegerType BaseIntegerType
forall k (ktp :: k -> Type) (x :: k) (y :: k).
OrdF ktp =>
ktp x -> ktp y -> OrderingF x y
forall (x :: BaseType) (y :: BaseType).
SymExpr sym x -> SymExpr sym y -> OrderingF x y
compareF SymExpr sym BaseIntegerType
x SymExpr sym BaseIntegerType
y)
instance (HashableF (SymExpr sym), TestEquality (SymExpr sym)) => Hashable (SymNat sym) where
hashWithSalt :: Int -> SymNat sym -> Int
hashWithSalt Int
s (SymNat SymExpr sym BaseIntegerType
x) = Int -> SymExpr sym BaseIntegerType -> Int
forall k (f :: k -> Type) (tp :: k).
HashableF f =>
Int -> f tp -> Int
forall (tp :: BaseType). Int -> SymExpr sym tp -> Int
hashWithSaltF Int
s SymExpr sym BaseIntegerType
x
class ( IsExpr (SymExpr sym), HashableF (SymExpr sym), HashableF (BoundVar sym)
, TestEquality (SymAnnotation sym), OrdF (SymAnnotation sym)
, HashableF (SymAnnotation sym)
) => IsExprBuilder sym where
getConfiguration :: sym -> Config
setSolverLogListener :: sym -> Maybe (SolverEvent -> IO ()) -> IO ()
getSolverLogListener :: sym -> IO (Maybe (SolverEvent -> IO ()))
logSolverEvent :: sym -> SolverEvent -> IO ()
getStatistics :: sym -> IO Statistics
getStatistics sym
_ = Statistics -> IO Statistics
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return Statistics
zeroStatistics
getCurrentProgramLoc :: sym -> IO ProgramLoc
setCurrentProgramLoc :: sym -> ProgramLoc -> IO ()
isEq :: sym -> SymExpr sym tp -> SymExpr sym tp -> IO (Pred sym)
isEq sym
sym SymExpr sym tp
x SymExpr sym tp
y =
case SymExpr sym tp -> BaseTypeRepr tp
forall (tp :: BaseType). SymExpr sym tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType SymExpr sym tp
x of
BaseTypeRepr tp
BaseBoolRepr -> sym -> Pred sym -> Pred sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> Pred sym -> IO (Pred sym)
eqPred sym
sym SymExpr sym tp
Pred sym
x SymExpr sym tp
Pred sym
y
BaseBVRepr{} -> sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvEq sym
sym SymExpr sym tp
SymBV sym w
x SymExpr sym tp
SymBV sym w
y
BaseTypeRepr tp
BaseIntegerRepr -> sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intEq sym
sym SymExpr sym tp
SymInteger sym
x SymExpr sym tp
SymInteger sym
y
BaseTypeRepr tp
BaseRealRepr -> sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realEq sym
sym SymExpr sym tp
SymReal sym
x SymExpr sym tp
SymReal sym
y
BaseFloatRepr{} -> sym -> SymFloat sym fpp -> SymFloat sym fpp -> IO (Pred sym)
forall sym (fpp :: FloatPrecision).
IsExprBuilder sym =>
sym -> SymFloat sym fpp -> SymFloat sym fpp -> IO (Pred sym)
forall (fpp :: FloatPrecision).
sym -> SymFloat sym fpp -> SymFloat sym fpp -> IO (Pred sym)
floatEq sym
sym SymExpr sym tp
SymFloat sym fpp
x SymExpr sym tp
SymFloat sym fpp
y
BaseTypeRepr tp
BaseComplexRepr -> sym -> SymCplx sym -> SymCplx sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> SymCplx sym -> IO (Pred sym)
cplxEq sym
sym SymExpr sym tp
SymCplx sym
x SymExpr sym tp
SymCplx sym
y
BaseStringRepr{} -> sym -> SymString sym si -> SymString sym si -> IO (Pred sym)
forall sym (si :: StringInfo).
IsExprBuilder sym =>
sym -> SymString sym si -> SymString sym si -> IO (Pred sym)
forall (si :: StringInfo).
sym -> SymString sym si -> SymString sym si -> IO (Pred sym)
stringEq sym
sym SymExpr sym tp
SymString sym si
x SymExpr sym tp
SymString sym si
y
BaseStructRepr{} -> sym -> SymStruct sym ctx -> SymStruct sym ctx -> IO (Pred sym)
forall sym (flds :: Ctx BaseType).
IsExprBuilder sym =>
sym -> SymStruct sym flds -> SymStruct sym flds -> IO (Pred sym)
forall (flds :: Ctx BaseType).
sym -> SymStruct sym flds -> SymStruct sym flds -> IO (Pred sym)
structEq sym
sym SymExpr sym tp
SymStruct sym ctx
x SymExpr sym tp
SymStruct sym ctx
y
BaseArrayRepr{} -> sym
-> SymArray sym (idx ::> tp) xs
-> SymArray sym (idx ::> tp) xs
-> IO (Pred sym)
forall sym (idx :: Ctx BaseType) (b :: BaseType).
IsExprBuilder sym =>
sym -> SymArray sym idx b -> SymArray sym idx b -> IO (Pred sym)
forall (idx :: Ctx BaseType) (b :: BaseType).
sym -> SymArray sym idx b -> SymArray sym idx b -> IO (Pred sym)
arrayEq sym
sym SymExpr sym tp
SymArray sym (idx ::> tp) xs
x SymExpr sym tp
SymArray sym (idx ::> tp) xs
y
baseTypeIte :: sym
-> Pred sym
-> SymExpr sym tp
-> SymExpr sym tp
-> IO (SymExpr sym tp)
baseTypeIte sym
sym Pred sym
c SymExpr sym tp
x SymExpr sym tp
y =
case SymExpr sym tp -> BaseTypeRepr tp
forall (tp :: BaseType). SymExpr sym tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType SymExpr sym tp
x of
BaseTypeRepr tp
BaseBoolRepr -> sym -> Pred sym -> Pred sym -> Pred sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> Pred sym -> Pred sym -> IO (Pred sym)
itePred sym
sym Pred sym
c SymExpr sym tp
Pred sym
x SymExpr sym tp
Pred sym
y
BaseBVRepr{} -> sym -> Pred sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> Pred sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> Pred sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
bvIte sym
sym Pred sym
c SymExpr sym tp
SymBV sym w
x SymExpr sym tp
SymBV sym w
y
BaseTypeRepr tp
BaseIntegerRepr -> sym
-> Pred sym
-> SymInteger sym
-> SymInteger sym
-> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym
-> Pred sym
-> SymInteger sym
-> SymInteger sym
-> IO (SymInteger sym)
intIte sym
sym Pred sym
c SymExpr sym tp
SymInteger sym
x SymExpr sym tp
SymInteger sym
y
BaseTypeRepr tp
BaseRealRepr -> sym -> Pred sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realIte sym
sym Pred sym
c SymExpr sym tp
SymReal sym
x SymExpr sym tp
SymReal sym
y
BaseFloatRepr{} -> sym
-> Pred sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
forall sym (fpp :: FloatPrecision).
IsExprBuilder sym =>
sym
-> Pred sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
forall (fpp :: FloatPrecision).
sym
-> Pred sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatIte sym
sym Pred sym
c SymExpr sym tp
SymFloat sym fpp
x SymExpr sym tp
SymFloat sym fpp
y
BaseStringRepr{} -> sym
-> Pred sym
-> SymString sym si
-> SymString sym si
-> IO (SymString sym si)
forall sym (si :: StringInfo).
IsExprBuilder sym =>
sym
-> Pred sym
-> SymString sym si
-> SymString sym si
-> IO (SymString sym si)
forall (si :: StringInfo).
sym
-> Pred sym
-> SymString sym si
-> SymString sym si
-> IO (SymString sym si)
stringIte sym
sym Pred sym
c SymExpr sym tp
SymString sym si
x SymExpr sym tp
SymString sym si
y
BaseTypeRepr tp
BaseComplexRepr -> sym -> Pred sym -> SymCplx sym -> SymCplx sym -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> SymCplx sym -> SymCplx sym -> IO (SymCplx sym)
cplxIte sym
sym Pred sym
c SymExpr sym tp
SymCplx sym
x SymExpr sym tp
SymCplx sym
y
BaseStructRepr{} -> sym
-> Pred sym
-> SymStruct sym ctx
-> SymStruct sym ctx
-> IO (SymStruct sym ctx)
forall sym (flds :: Ctx BaseType).
IsExprBuilder sym =>
sym
-> Pred sym
-> SymStruct sym flds
-> SymStruct sym flds
-> IO (SymStruct sym flds)
forall (flds :: Ctx BaseType).
sym
-> Pred sym
-> SymStruct sym flds
-> SymStruct sym flds
-> IO (SymStruct sym flds)
structIte sym
sym Pred sym
c SymExpr sym tp
SymStruct sym ctx
x SymExpr sym tp
SymStruct sym ctx
y
BaseArrayRepr{} -> sym
-> Pred sym
-> SymArray sym (idx ::> tp) xs
-> SymArray sym (idx ::> tp) xs
-> IO (SymArray sym (idx ::> tp) xs)
forall sym (idx :: Ctx BaseType) (b :: BaseType).
IsExprBuilder sym =>
sym
-> Pred sym
-> SymArray sym idx b
-> SymArray sym idx b
-> IO (SymArray sym idx b)
forall (idx :: Ctx BaseType) (b :: BaseType).
sym
-> Pred sym
-> SymArray sym idx b
-> SymArray sym idx b
-> IO (SymArray sym idx b)
arrayIte sym
sym Pred sym
c SymExpr sym tp
SymArray sym (idx ::> tp) xs
x SymExpr sym tp
SymArray sym (idx ::> tp) xs
y
annotateTerm :: sym -> SymExpr sym tp -> IO (SymAnnotation sym tp, SymExpr sym tp)
getAnnotation :: sym -> SymExpr sym tp -> Maybe (SymAnnotation sym tp)
getUnannotatedTerm :: sym -> SymExpr sym tp -> Maybe (SymExpr sym tp)
truePred :: sym -> Pred sym
falsePred :: sym -> Pred sym
notPred :: sym -> Pred sym -> IO (Pred sym)
andPred :: sym -> Pred sym -> Pred sym -> IO (Pred sym)
orPred :: sym -> Pred sym -> Pred sym -> IO (Pred sym)
impliesPred :: sym -> Pred sym -> Pred sym -> IO (Pred sym)
impliesPred sym
sym Pred sym
x Pred sym
y = do
nx <- sym -> Pred sym -> IO (Pred sym)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym Pred sym
x
orPred sym y nx
xorPred :: sym -> Pred sym -> Pred sym -> IO (Pred sym)
eqPred :: sym -> Pred sym -> Pred sym -> IO (Pred sym)
itePred :: sym -> Pred sym -> Pred sym -> Pred sym -> IO (Pred sym)
intLit :: sym -> Integer -> IO (SymInteger sym)
intNeg :: sym -> SymInteger sym -> IO (SymInteger sym)
intAdd :: sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intSub :: sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intSub sym
sym SymInteger sym
x SymInteger sym
y = sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intAdd sym
sym SymInteger sym
x (SymInteger sym -> IO (SymInteger sym))
-> IO (SymInteger sym) -> IO (SymInteger sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymInteger sym -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> IO (SymInteger sym)
intNeg sym
sym SymInteger sym
y
intMul :: sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intMin :: sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intMin sym
sym SymInteger sym
x SymInteger sym
y =
do x_le_y <- sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intLe sym
sym SymInteger sym
x SymInteger sym
y
y_le_x <- intLe sym y x
case (asConstantPred x_le_y, asConstantPred y_le_x) of
(Just Bool
True, Maybe Bool
_) -> SymInteger sym -> IO (SymInteger sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymInteger sym
x
(Maybe Bool
_, Just Bool
False) -> SymInteger sym -> IO (SymInteger sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymInteger sym
x
(Just Bool
False, Maybe Bool
_) -> SymInteger sym -> IO (SymInteger sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymInteger sym
y
(Maybe Bool
_, Just Bool
True) -> SymInteger sym -> IO (SymInteger sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymInteger sym
y
(Maybe Bool, Maybe Bool)
_ ->
do let rng_x :: ValueRange Integer
rng_x = SymInteger sym -> ValueRange Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> ValueRange Integer
integerBounds SymInteger sym
x
let rng_y :: ValueRange Integer
rng_y = SymInteger sym -> ValueRange Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> ValueRange Integer
integerBounds SymInteger sym
y
AbstractValue BaseIntegerType -> SymInteger sym -> SymInteger sym
forall (tp :: BaseType).
AbstractValue tp -> SymExpr sym tp -> SymExpr sym tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
AbstractValue tp -> e tp -> e tp
unsafeSetAbstractValue (ValueRange Integer -> ValueRange Integer -> ValueRange Integer
forall a. Ord a => ValueRange a -> ValueRange a -> ValueRange a
rangeMin ValueRange Integer
rng_x ValueRange Integer
rng_y) (SymInteger sym -> SymInteger sym)
-> IO (SymInteger sym) -> IO (SymInteger sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$>
sym
-> Pred sym
-> SymInteger sym
-> SymInteger sym
-> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym
-> Pred sym
-> SymInteger sym
-> SymInteger sym
-> IO (SymInteger sym)
intIte sym
sym Pred sym
x_le_y SymInteger sym
x SymInteger sym
y
intMax :: sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intMax sym
sym SymInteger sym
x SymInteger sym
y =
do x_le_y <- sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intLe sym
sym SymInteger sym
x SymInteger sym
y
y_le_x <- intLe sym y x
case (asConstantPred x_le_y, asConstantPred y_le_x) of
(Just Bool
True, Maybe Bool
_) -> SymInteger sym -> IO (SymInteger sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymInteger sym
y
(Maybe Bool
_, Just Bool
False) -> SymInteger sym -> IO (SymInteger sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymInteger sym
y
(Just Bool
False, Maybe Bool
_) -> SymInteger sym -> IO (SymInteger sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymInteger sym
x
(Maybe Bool
_, Just Bool
True) -> SymInteger sym -> IO (SymInteger sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymInteger sym
x
(Maybe Bool, Maybe Bool)
_ ->
do let rng_x :: ValueRange Integer
rng_x = SymInteger sym -> ValueRange Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> ValueRange Integer
integerBounds SymInteger sym
x
let rng_y :: ValueRange Integer
rng_y = SymInteger sym -> ValueRange Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> ValueRange Integer
integerBounds SymInteger sym
y
AbstractValue BaseIntegerType -> SymInteger sym -> SymInteger sym
forall (tp :: BaseType).
AbstractValue tp -> SymExpr sym tp -> SymExpr sym tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
AbstractValue tp -> e tp -> e tp
unsafeSetAbstractValue (ValueRange Integer -> ValueRange Integer -> ValueRange Integer
forall a. Ord a => ValueRange a -> ValueRange a -> ValueRange a
rangeMax ValueRange Integer
rng_x ValueRange Integer
rng_y) (SymInteger sym -> SymInteger sym)
-> IO (SymInteger sym) -> IO (SymInteger sym)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$>
sym
-> Pred sym
-> SymInteger sym
-> SymInteger sym
-> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym
-> Pred sym
-> SymInteger sym
-> SymInteger sym
-> IO (SymInteger sym)
intIte sym
sym Pred sym
x_le_y SymInteger sym
y SymInteger sym
x
intIte :: sym -> Pred sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intEq :: sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intLe :: sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intLt :: sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intLt sym
sym SymInteger sym
x SymInteger sym
y = sym -> Pred sym -> IO (Pred sym)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym (Pred sym -> IO (Pred sym)) -> IO (Pred sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> SymInteger sym -> IO (Pred sym)
intLe sym
sym SymInteger sym
y SymInteger sym
x
intAbs :: sym -> SymInteger sym -> IO (SymInteger sym)
intDiv :: sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intMod :: sym -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
intDivisible :: sym -> SymInteger sym -> Natural -> IO (Pred sym)
bvLit :: (1 <= w) => sym -> NatRepr w -> BV.BV w -> IO (SymBV sym w)
bvConcat :: (1 <= u, 1 <= v)
=> sym
-> SymBV sym u
-> SymBV sym v
-> IO (SymBV sym (u+v))
bvSelect :: forall idx n w. (1 <= n, idx + n <= w)
=> sym
-> NatRepr idx
-> NatRepr n
-> SymBV sym w
-> IO (SymBV sym n)
bvNeg :: (1 <= w)
=> sym
-> SymBV sym w
-> IO (SymBV sym w)
bvAdd :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvSub :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvSub sym
sym SymBV sym w
x SymBV sym w
y = sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
bvAdd sym
sym SymBV sym w
x (SymBV sym w -> IO (SymBV sym w))
-> IO (SymBV sym w) -> IO (SymBV sym w)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymBV sym w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> IO (SymBV sym w)
bvNeg sym
sym SymBV sym w
y
bvMul :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvUdiv :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvUrem :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvSdiv :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvSrem :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
testBitBV :: (1 <= w)
=> sym
-> Natural
-> SymBV sym w
-> IO (Pred sym)
bvIsNeg :: (1 <= w) => sym -> SymBV sym w -> IO (Pred sym)
bvIsNeg sym
sym SymBV sym w
x = sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSlt sym
sym SymBV sym w
x (SymBV sym w -> IO (Pred sym)) -> IO (SymBV sym w) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> NatRepr w -> IO (SymBV sym w)
forall (w :: Nat) sym.
(1 <= w, IsExprBuilder sym) =>
sym -> NatRepr w -> IO (SymBV sym w)
bvZero sym
sym (SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
x)
bvIte :: (1 <= w)
=> sym
-> Pred sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvEq :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (Pred sym)
bvNe :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (Pred sym)
bvNe sym
sym SymBV sym w
x SymBV sym w
y = sym -> Pred sym -> IO (Pred sym)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym (Pred sym -> IO (Pred sym)) -> IO (Pred sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvEq sym
sym SymBV sym w
x SymBV sym w
y
bvUlt :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (Pred sym)
bvUle :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (Pred sym)
bvUle sym
sym SymBV sym w
x SymBV sym w
y = sym -> Pred sym -> IO (Pred sym)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym (Pred sym -> IO (Pred sym)) -> IO (Pred sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvUlt sym
sym SymBV sym w
y SymBV sym w
x
bvUge :: (1 <= w) => sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvUge sym
sym SymBV sym w
x SymBV sym w
y = sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvUle sym
sym SymBV sym w
y SymBV sym w
x
bvUgt :: (1 <= w) => sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvUgt sym
sym SymBV sym w
x SymBV sym w
y = sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvUlt sym
sym SymBV sym w
y SymBV sym w
x
bvSlt :: (1 <= w) => sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSgt :: (1 <= w) => sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSgt sym
sym SymBV sym w
x SymBV sym w
y = sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSlt sym
sym SymBV sym w
y SymBV sym w
x
bvSle :: (1 <= w) => sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSle sym
sym SymBV sym w
x SymBV sym w
y = sym -> Pred sym -> IO (Pred sym)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym (Pred sym -> IO (Pred sym)) -> IO (Pred sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSlt sym
sym SymBV sym w
y SymBV sym w
x
bvSge :: (1 <= w) => sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSge sym
sym SymBV sym w
x SymBV sym w
y = sym -> Pred sym -> IO (Pred sym)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym (Pred sym -> IO (Pred sym)) -> IO (Pred sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSlt sym
sym SymBV sym w
x SymBV sym w
y
bvIsNonzero :: (1 <= w) => sym -> SymBV sym w -> IO (Pred sym)
bvShl :: (1 <= w) => sym ->
SymBV sym w ->
SymBV sym w ->
IO (SymBV sym w)
bvLshr :: (1 <= w) => sym ->
SymBV sym w ->
SymBV sym w ->
IO (SymBV sym w)
bvAshr :: (1 <= w) => sym ->
SymBV sym w ->
SymBV sym w ->
IO (SymBV sym w)
bvRol :: (1 <= w) =>
sym ->
SymBV sym w ->
SymBV sym w ->
IO (SymBV sym w)
bvRor :: (1 <= w) =>
sym ->
SymBV sym w ->
SymBV sym w ->
IO (SymBV sym w)
bvZext :: (1 <= u, u+1 <= r) => sym -> NatRepr r -> SymBV sym u -> IO (SymBV sym r)
bvSext :: (1 <= u, u+1 <= r) => sym -> NatRepr r -> SymBV sym u -> IO (SymBV sym r)
bvTrunc :: (1 <= r, r+1 <= w)
=> sym
-> NatRepr r
-> SymBV sym w
-> IO (SymBV sym r)
bvTrunc sym
sym NatRepr r
w SymBV sym w
x
| LeqProof r w
LeqProof <- LeqProof r (r + 1) -> LeqProof (r + 1) w -> LeqProof r w
forall (m :: Nat) (n :: Nat) (p :: Nat).
LeqProof m n -> LeqProof n p -> LeqProof m p
leqTrans
(NatRepr r -> NatRepr 1 -> LeqProof r (r + 1)
forall (f :: Nat -> Type) (n :: Nat) (g :: Nat -> Type) (m :: Nat).
f n -> g m -> LeqProof n (n + m)
addIsLeq NatRepr r
w (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @1))
(NatRepr (r + 1) -> NatRepr w -> LeqProof (r + 1) w
forall (m :: Nat) (n :: Nat) (f :: Nat -> Type) (g :: Nat -> Type).
(m <= n) =>
f m -> g n -> LeqProof m n
leqProof (NatRepr r -> NatRepr (r + 1)
forall (n :: Nat). NatRepr n -> NatRepr (n + 1)
incNat NatRepr r
w) (SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
x))
= sym -> NatRepr 0 -> NatRepr r -> SymBV sym w -> IO (SymBV sym r)
forall (idx :: Nat) (n :: Nat) (w :: Nat).
(1 <= n, (idx + n) <= w) =>
sym -> NatRepr idx -> NatRepr n -> SymBV sym w -> IO (SymBV sym n)
forall sym (idx :: Nat) (n :: Nat) (w :: Nat).
(IsExprBuilder sym, 1 <= n, (idx + n) <= w) =>
sym -> NatRepr idx -> NatRepr n -> SymBV sym w -> IO (SymBV sym n)
bvSelect sym
sym (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @0) NatRepr r
w SymBV sym w
x
bvAndBits :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvOrBits :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvXorBits :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w)
bvNotBits :: (1 <= w) => sym -> SymBV sym w -> IO (SymBV sym w)
bvSet :: forall w
. (1 <= w)
=> sym
-> SymBV sym w
-> Natural
-> Pred sym
-> IO (SymBV sym w)
bvSet sym
sym SymBV sym w
v Nat
i Pred sym
p = Bool -> IO (SymBV sym w) -> IO (SymBV sym w)
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Nat
i Nat -> Nat -> Bool
forall a. Ord a => a -> a -> Bool
< NatRepr w -> Nat
forall (n :: Nat). NatRepr n -> Nat
natValue (SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
v)) (IO (SymBV sym w) -> IO (SymBV sym w))
-> IO (SymBV sym w) -> IO (SymBV sym w)
forall a b. (a -> b) -> a -> b
$
do let w :: NatRepr w
w = SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
v
let mask :: BV w
mask = NatRepr w -> Nat -> BV w
forall (w :: Nat). NatRepr w -> Nat -> BV w
BV.bit' NatRepr w
w Nat
i
pbits <- sym -> NatRepr w -> Pred sym -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> Pred sym -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> Pred sym -> IO (SymBV sym w)
bvFill sym
sym NatRepr w
w Pred sym
p
vbits <- bvAndBits sym v =<< bvLit sym w (BV.complement w mask)
bvXorBits sym vbits =<< bvAndBits sym pbits =<< bvLit sym w mask
bvFill :: forall w. (1 <= w) =>
sym ->
NatRepr w ->
Pred sym ->
IO (SymBV sym w)
minUnsignedBV :: (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
minUnsignedBV sym
sym NatRepr w
w = sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w (NatRepr w -> BV w
forall (w :: Nat). NatRepr w -> BV w
BV.zero NatRepr w
w)
maxUnsignedBV :: (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
maxUnsignedBV sym
sym NatRepr w
w = sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w (NatRepr w -> BV w
forall (w :: Nat). NatRepr w -> BV w
BV.maxUnsigned NatRepr w
w)
maxSignedBV :: (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
maxSignedBV sym
sym NatRepr w
w = sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w (NatRepr w -> BV w
forall (w :: Nat). (1 <= w) => NatRepr w -> BV w
BV.maxSigned NatRepr w
w)
minSignedBV :: (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
minSignedBV sym
sym NatRepr w
w = sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w (NatRepr w -> BV w
forall (w :: Nat). (1 <= w) => NatRepr w -> BV w
BV.minSigned NatRepr w
w)
bvPopcount :: (1 <= w) => sym -> SymBV sym w -> IO (SymBV sym w)
bvCountLeadingZeros :: (1 <= w) => sym -> SymBV sym w -> IO (SymBV sym w)
bvCountTrailingZeros :: (1 <= w) => sym -> SymBV sym w -> IO (SymBV sym w)
addUnsignedOF :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (Pred sym, SymBV sym w)
addUnsignedOF sym
sym SymBV sym w
x SymBV sym w
y = do
r <- sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
bvAdd sym
sym SymBV sym w
x SymBV sym w
y
ovx <- bvUlt sym r x
ovy <- bvUlt sym r y
ov <- orPred sym ovx ovy
return (ov, r)
addSignedOF :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (Pred sym, SymBV sym w)
addSignedOF sym
sym SymBV sym w
x SymBV sym w
y = do
xy <- sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
bvAdd sym
sym SymBV sym w
x SymBV sym w
y
sx <- bvIsNeg sym x
sy <- bvIsNeg sym y
sxy <- bvIsNeg sym xy
not_sx <- notPred sym sx
not_sy <- notPred sym sy
not_sxy <- notPred sym sxy
ov1 <- andPred sym not_sxy =<< andPred sym sx sy
ov2 <- andPred sym sxy =<< andPred sym not_sx not_sy
ov <- orPred sym ov1 ov2
return (ov, xy)
subUnsignedOF ::
(1 <= w) =>
sym ->
SymBV sym w ->
SymBV sym w ->
IO (Pred sym, SymBV sym w)
subUnsignedOF sym
sym SymBV sym w
x SymBV sym w
y = do
xy <- sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
bvSub sym
sym SymBV sym w
x SymBV sym w
y
ov <- bvUlt sym x y
return (ov, xy)
subSignedOF :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (Pred sym, SymBV sym w)
subSignedOF sym
sym SymBV sym w
x SymBV sym w
y = do
xy <- sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (SymBV sym w)
bvSub sym
sym SymBV sym w
x SymBV sym w
y
sx <- bvIsNeg sym x
sy <- bvIsNeg sym y
sxy <- bvIsNeg sym xy
ov <- join (pure (andPred sym) <*> xorPred sym sx sxy <*> xorPred sym sx sy)
return (ov, xy)
carrylessMultiply ::
(1 <= w) =>
sym ->
SymBV sym w ->
SymBV sym w ->
IO (SymBV sym (w+w))
carrylessMultiply sym
sym SymBV sym w
x0 SymBV sym w
y0
| Just Integer
_ <- BV w -> Integer
forall (w :: Nat). BV w -> Integer
BV.asUnsigned (BV w -> Integer) -> Maybe (BV w) -> Maybe Integer
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> SymBV sym w -> Maybe (BV w)
forall (w :: Nat). SymExpr sym (BaseBVType w) -> Maybe (BV w)
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> Maybe (BV w)
asBV SymBV sym w
x0
, Maybe Integer
Nothing <- BV w -> Integer
forall (w :: Nat). BV w -> Integer
BV.asUnsigned (BV w -> Integer) -> Maybe (BV w) -> Maybe Integer
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> SymBV sym w -> Maybe (BV w)
forall (w :: Nat). SymExpr sym (BaseBVType w) -> Maybe (BV w)
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> Maybe (BV w)
asBV SymBV sym w
y0
= SymBV sym w
-> SymBV sym w -> IO (SymExpr sym ('BaseBVType (w + w)))
forall (w :: Nat).
(1 <= w) =>
SymBV sym w -> SymBV sym w -> IO (SymBV sym (w + w))
go SymBV sym w
y0 SymBV sym w
x0
| Bool
otherwise
= SymBV sym w
-> SymBV sym w -> IO (SymExpr sym ('BaseBVType (w + w)))
forall (w :: Nat).
(1 <= w) =>
SymBV sym w -> SymBV sym w -> IO (SymBV sym (w + w))
go SymBV sym w
x0 SymBV sym w
y0
where
go :: (1 <= w) => SymBV sym w -> SymBV sym w -> IO (SymBV sym (w+w))
go :: forall (w :: Nat).
(1 <= w) =>
SymBV sym w -> SymBV sym w -> IO (SymBV sym (w + w))
go SymBV sym w
x SymBV sym w
y =
do let w :: NatRepr w
w = SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
x
let w2 :: NatRepr (w + w)
w2 = NatRepr w -> NatRepr w -> NatRepr (w + w)
forall (m :: Nat) (n :: Nat).
NatRepr m -> NatRepr n -> NatRepr (m + n)
addNat NatRepr w
w NatRepr w
w
one_leq_w@LeqProof <- LeqProof 1 w -> IO (LeqProof 1 w)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (NatRepr 1 -> NatRepr w -> LeqProof 1 w
forall (m :: Nat) (n :: Nat) (f :: Nat -> Type) (g :: Nat -> Type).
(m <= n) =>
f m -> g n -> LeqProof m n
leqProof (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @1) NatRepr w
w)
LeqProof <- return (leqAdd one_leq_w w)
w_leq_w@LeqProof <- return (leqProof w w)
LeqProof <- return (leqAdd2 w_leq_w one_leq_w)
z <- bvLit sym w2 (BV.zero w2)
x' <- bvZext sym w2 x
xs <- sequence [ do p <- testBitBV sym (BV.asNatural i) y
iteM bvIte sym
p
(bvShl sym x' =<< bvLit sym w2 i)
(return z)
| i <- BV.enumFromToUnsigned (BV.zero w2) (BV.mkBV w2 (intValue w - 1))
]
foldM (bvXorBits sym) z xs
unsignedWideMultiplyBV :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w, SymBV sym w)
unsignedWideMultiplyBV sym
sym SymBV sym w
x SymBV sym w
y = do
let w :: NatRepr w
w = SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
x
let dbl_w :: NatRepr (w + w)
dbl_w = NatRepr w -> NatRepr w -> NatRepr (w + w)
forall (m :: Nat) (n :: Nat).
NatRepr m -> NatRepr n -> NatRepr (m + n)
addNat NatRepr w
w NatRepr w
w
one_leq_w@LeqProof <- LeqProof 1 w -> IO (LeqProof 1 w)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (NatRepr 1 -> NatRepr w -> LeqProof 1 w
forall (m :: Nat) (n :: Nat) (f :: Nat -> Type) (g :: Nat -> Type).
(m <= n) =>
f m -> g n -> LeqProof m n
leqProof (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @1) NatRepr w
w)
LeqProof <- return (leqAdd one_leq_w w)
w_leq_w@LeqProof <- return (leqProof w w)
LeqProof <- return (leqAdd2 w_leq_w one_leq_w)
x' <- bvZext sym dbl_w x
y' <- bvZext sym dbl_w y
s <- bvMul sym x' y'
lo <- bvTrunc sym w s
n <- bvLit sym dbl_w (BV.zext dbl_w (BV.width w))
hi <- bvTrunc sym w =<< bvLshr sym s n
return (hi, lo)
mulUnsignedOF ::
(1 <= w) =>
sym ->
SymBV sym w ->
SymBV sym w ->
IO (Pred sym, SymBV sym w)
mulUnsignedOF sym
sym SymBV sym w
x SymBV sym w
y =
do let w :: NatRepr w
w = SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
x
let dbl_w :: NatRepr (w + w)
dbl_w = NatRepr w -> NatRepr w -> NatRepr (w + w)
forall (m :: Nat) (n :: Nat).
NatRepr m -> NatRepr n -> NatRepr (m + n)
addNat NatRepr w
w NatRepr w
w
one_leq_w@LeqProof <- LeqProof 1 w -> IO (LeqProof 1 w)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (NatRepr 1 -> NatRepr w -> LeqProof 1 w
forall (m :: Nat) (n :: Nat) (f :: Nat -> Type) (g :: Nat -> Type).
(m <= n) =>
f m -> g n -> LeqProof m n
leqProof (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @1) NatRepr w
w)
LeqProof <- return (leqAdd one_leq_w w)
w_leq_w@LeqProof <- return (leqProof w w)
LeqProof <- return (leqAdd2 w_leq_w one_leq_w)
x' <- bvZext sym dbl_w x
y' <- bvZext sym dbl_w y
s <- bvMul sym x' y'
lo <- bvTrunc sym w s
ov <- bvUgt sym s =<< bvLit sym dbl_w (BV.zext dbl_w (BV.maxUnsigned w))
return (ov, lo)
signedWideMultiplyBV :: (1 <= w)
=> sym
-> SymBV sym w
-> SymBV sym w
-> IO (SymBV sym w, SymBV sym w)
signedWideMultiplyBV sym
sym SymBV sym w
x SymBV sym w
y = do
let w :: NatRepr w
w = SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
x
let dbl_w :: NatRepr (w + w)
dbl_w = NatRepr w -> NatRepr w -> NatRepr (w + w)
forall (m :: Nat) (n :: Nat).
NatRepr m -> NatRepr n -> NatRepr (m + n)
addNat NatRepr w
w NatRepr w
w
one_leq_w@LeqProof <- LeqProof 1 w -> IO (LeqProof 1 w)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (NatRepr 1 -> NatRepr w -> LeqProof 1 w
forall (m :: Nat) (n :: Nat) (f :: Nat -> Type) (g :: Nat -> Type).
(m <= n) =>
f m -> g n -> LeqProof m n
leqProof (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @1) NatRepr w
w)
LeqProof <- return (leqAdd one_leq_w w)
w_leq_w@LeqProof <- return (leqProof w w)
LeqProof <- return (leqAdd2 w_leq_w one_leq_w)
x' <- bvSext sym dbl_w x
y' <- bvSext sym dbl_w y
s <- bvMul sym x' y'
lo <- bvTrunc sym w s
n <- bvLit sym dbl_w (BV.zext dbl_w (BV.width w))
hi <- bvTrunc sym w =<< bvLshr sym s n
return (hi, lo)
mulSignedOF ::
(1 <= w) =>
sym ->
SymBV sym w ->
SymBV sym w ->
IO (Pred sym, SymBV sym w)
mulSignedOF sym
sym SymBV sym w
x SymBV sym w
y =
do let w :: NatRepr w
w = SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
x
let dbl_w :: NatRepr (w + w)
dbl_w = NatRepr w -> NatRepr w -> NatRepr (w + w)
forall (m :: Nat) (n :: Nat).
NatRepr m -> NatRepr n -> NatRepr (m + n)
addNat NatRepr w
w NatRepr w
w
one_leq_w@LeqProof <- LeqProof 1 w -> IO (LeqProof 1 w)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (NatRepr 1 -> NatRepr w -> LeqProof 1 w
forall (m :: Nat) (n :: Nat) (f :: Nat -> Type) (g :: Nat -> Type).
(m <= n) =>
f m -> g n -> LeqProof m n
leqProof (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @1) NatRepr w
w)
LeqProof <- return (leqAdd one_leq_w w)
w_leq_w@LeqProof <- return (leqProof w w)
LeqProof <- return (leqAdd2 w_leq_w one_leq_w)
x' <- bvSext sym dbl_w x
y' <- bvSext sym dbl_w y
s <- bvMul sym x' y'
lo <- bvTrunc sym w s
ov1 <- bvSlt sym s =<< bvLit sym dbl_w (BV.sext w dbl_w (BV.minSigned w))
ov2 <- bvSgt sym s =<< bvLit sym dbl_w (BV.sext w dbl_w (BV.maxSigned w))
ov <- orPred sym ov1 ov2
return (ov, lo)
mkStruct :: sym
-> Ctx.Assignment (SymExpr sym) flds
-> IO (SymStruct sym flds)
structField :: sym
-> SymStruct sym flds
-> Ctx.Index flds tp
-> IO (SymExpr sym tp)
structEq :: forall flds
. sym
-> SymStruct sym flds
-> SymStruct sym flds
-> IO (Pred sym)
structEq sym
sym SymStruct sym flds
x SymStruct sym flds
y = do
case SymStruct sym flds -> BaseTypeRepr (BaseStructType flds)
forall (tp :: BaseType). SymExpr sym tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType SymStruct sym flds
x of
BaseStructRepr Assignment BaseTypeRepr ctx
fld_types -> do
let sz :: Size ctx
sz = Assignment BaseTypeRepr ctx -> Size ctx
forall {k} (f :: k -> Type) (ctx :: Ctx k).
Assignment f ctx -> Size ctx
Ctx.size Assignment BaseTypeRepr ctx
fld_types
let f :: IO (Pred sym) -> Ctx.Index flds tp -> IO (Pred sym)
f :: forall (tp :: BaseType).
IO (Pred sym) -> Index flds tp -> IO (Pred sym)
f IO (Pred sym)
mp Index flds tp
i = do
xi <- sym -> SymStruct sym flds -> Index flds tp -> IO (SymExpr sym tp)
forall sym (flds :: Ctx BaseType) (tp :: BaseType).
IsExprBuilder sym =>
sym -> SymStruct sym flds -> Index flds tp -> IO (SymExpr sym tp)
forall (flds :: Ctx BaseType) (tp :: BaseType).
sym -> SymStruct sym flds -> Index flds tp -> IO (SymExpr sym tp)
structField sym
sym SymStruct sym flds
x Index flds tp
i
yi <- structField sym y i
i_eq <- isEq sym xi yi
case asConstantPred i_eq of
Just Bool
True -> IO (Pred sym)
mp
Just Bool
False -> Pred sym -> IO (Pred sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (sym -> Pred sym
forall sym. IsExprBuilder sym => sym -> Pred sym
falsePred sym
sym)
Maybe Bool
_ -> sym -> Pred sym -> Pred sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> Pred sym -> IO (Pred sym)
andPred sym
sym Pred sym
i_eq (Pred sym -> IO (Pred sym)) -> IO (Pred sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO (Pred sym)
mp
Size ctx
-> (forall (tp :: BaseType).
IO (Pred sym) -> Index ctx tp -> IO (Pred sym))
-> IO (Pred sym)
-> IO (Pred sym)
forall {k} (ctx :: Ctx k) r.
Size ctx -> (forall (tp :: k). r -> Index ctx tp -> r) -> r -> r
Ctx.forIndex Size ctx
sz IO (Pred sym) -> Index flds tp -> IO (Pred sym)
IO (Pred sym) -> Index ctx tp -> IO (Pred sym)
forall (tp :: BaseType).
IO (Pred sym) -> Index flds tp -> IO (Pred sym)
forall (tp :: BaseType).
IO (Pred sym) -> Index ctx tp -> IO (Pred sym)
f (Pred sym -> IO (Pred sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (sym -> Pred sym
forall sym. IsExprBuilder sym => sym -> Pred sym
truePred sym
sym))
structIte :: sym
-> Pred sym
-> SymStruct sym flds
-> SymStruct sym flds
-> IO (SymStruct sym flds)
constantArray :: sym
-> Ctx.Assignment BaseTypeRepr (idx::>tp)
-> SymExpr sym b
-> IO (SymArray sym (idx::>tp) b)
arrayFromFn :: sym
-> SymFn sym (idx ::> itp) ret
-> IO (SymArray sym (idx ::> itp) ret)
arrayMap :: sym
-> SymFn sym (ctx::>d) r
-> Ctx.Assignment (ArrayResultWrapper (SymExpr sym) (idx ::> itp)) (ctx::>d)
-> IO (SymArray sym (idx ::> itp) r)
arrayUpdate :: sym
-> SymArray sym (idx::>tp) b
-> Ctx.Assignment (SymExpr sym) (idx::>tp)
-> SymExpr sym b
-> IO (SymArray sym (idx::>tp) b)
arrayLookup :: sym
-> SymArray sym (idx::>tp) b
-> Ctx.Assignment (SymExpr sym) (idx::>tp)
-> IO (SymExpr sym b)
arrayCopy ::
(1 <= w) =>
sym ->
SymArray sym (SingleCtx (BaseBVType w)) a ->
SymBV sym w ->
SymArray sym (SingleCtx (BaseBVType w)) a ->
SymBV sym w ->
SymBV sym w ->
IO (SymArray sym (SingleCtx (BaseBVType w)) a)
arraySet ::
(1 <= w) =>
sym ->
SymArray sym (SingleCtx (BaseBVType w)) a ->
SymBV sym w ->
SymExpr sym a ->
SymBV sym w ->
IO (SymArray sym (SingleCtx (BaseBVType w)) a)
arrayRangeEq ::
(1 <= w) =>
sym ->
SymArray sym (SingleCtx (BaseBVType w)) a ->
SymBV sym w ->
SymArray sym (SingleCtx (BaseBVType w)) a ->
SymBV sym w ->
SymBV sym w ->
IO (Pred sym)
arrayFromMap :: sym
-> Ctx.Assignment BaseTypeRepr (idx ::> itp)
-> AUM.ArrayUpdateMap (SymExpr sym) (idx ::> itp) tp
-> SymExpr sym tp
-> IO (SymArray sym (idx ::> itp) tp)
arrayFromMap sym
sym Assignment BaseTypeRepr (idx ::> itp)
idx_tps ArrayUpdateMap (SymExpr sym) (idx ::> itp) tp
m SymExpr sym tp
default_value = do
a0 <- sym
-> Assignment BaseTypeRepr (idx ::> itp)
-> SymExpr sym tp
-> IO (SymExpr sym (BaseArrayType (idx ::> itp) tp))
forall sym (idx :: Ctx BaseType) (tp :: BaseType) (b :: BaseType).
IsExprBuilder sym =>
sym
-> Assignment BaseTypeRepr (idx ::> tp)
-> SymExpr sym b
-> IO (SymArray sym (idx ::> tp) b)
forall (idx :: Ctx BaseType) (tp :: BaseType) (b :: BaseType).
sym
-> Assignment BaseTypeRepr (idx ::> tp)
-> SymExpr sym b
-> IO (SymArray sym (idx ::> tp) b)
constantArray sym
sym Assignment BaseTypeRepr (idx ::> itp)
idx_tps SymExpr sym tp
default_value
arrayUpdateAtIdxLits sym m a0
arrayUpdateAtIdxLits :: sym
-> AUM.ArrayUpdateMap (SymExpr sym) (idx ::> itp) tp
-> SymArray sym (idx ::> itp) tp
-> IO (SymArray sym (idx ::> itp) tp)
arrayUpdateAtIdxLits sym
sym ArrayUpdateMap (SymExpr sym) (idx ::> itp) tp
m SymArray sym (idx ::> itp) tp
a0 = do
let updateAt :: SymArray sym (idx ::> itp) tp
-> (Assignment IndexLit (idx ::> itp), SymExpr sym tp)
-> IO (SymArray sym (idx ::> itp) tp)
updateAt SymArray sym (idx ::> itp) tp
a (Assignment IndexLit (idx ::> itp)
i,SymExpr sym tp
v) = do
idx <- (forall (x :: BaseType). IndexLit x -> IO (SymExpr sym x))
-> forall (x :: Ctx BaseType).
Assignment IndexLit x -> IO (Assignment (SymExpr sym) x)
forall k l (t :: (k -> Type) -> l -> Type) (f :: k -> Type)
(g :: k -> Type) (m :: Type -> Type).
(TraversableFC t, Applicative m) =>
(forall (x :: k). f x -> m (g x))
-> forall (x :: l). t f x -> m (t g x)
forall (f :: BaseType -> Type) (g :: BaseType -> Type)
(m :: Type -> Type).
Applicative m =>
(forall (x :: BaseType). f x -> m (g x))
-> forall (x :: Ctx BaseType). Assignment f x -> m (Assignment g x)
traverseFC (sym -> IndexLit x -> IO (SymExpr sym x)
forall sym (idx :: BaseType).
IsExprBuilder sym =>
sym -> IndexLit idx -> IO (SymExpr sym idx)
indexLit sym
sym) Assignment IndexLit (idx ::> itp)
i
arrayUpdate sym a idx v
(SymArray sym (idx ::> itp) tp
-> (Assignment IndexLit (idx ::> itp), SymExpr sym tp)
-> IO (SymArray sym (idx ::> itp) tp))
-> SymArray sym (idx ::> itp) tp
-> [(Assignment IndexLit (idx ::> itp), SymExpr sym tp)]
-> IO (SymArray sym (idx ::> itp) tp)
forall (t :: Type -> Type) (m :: Type -> Type) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM SymArray sym (idx ::> itp) tp
-> (Assignment IndexLit (idx ::> itp), SymExpr sym tp)
-> IO (SymArray sym (idx ::> itp) tp)
updateAt SymArray sym (idx ::> itp) tp
a0 (ArrayUpdateMap (SymExpr sym) (idx ::> itp) tp
-> [(Assignment IndexLit (idx ::> itp), SymExpr sym tp)]
forall (e :: BaseType -> Type) (ctx :: Ctx BaseType)
(tp :: BaseType).
ArrayUpdateMap e ctx tp -> [(Assignment IndexLit ctx, e tp)]
AUM.toList ArrayUpdateMap (SymExpr sym) (idx ::> itp) tp
m)
arrayIte :: sym
-> Pred sym
-> SymArray sym idx b
-> SymArray sym idx b
-> IO (SymArray sym idx b)
arrayEq :: sym
-> SymArray sym idx b
-> SymArray sym idx b
-> IO (Pred sym)
allTrueEntries :: sym -> SymArray sym idx BaseBoolType -> IO (Pred sym)
allTrueEntries sym
sym SymArray sym idx BaseBoolType
a = do
case SymArray sym idx BaseBoolType
-> BaseTypeRepr (BaseArrayType idx BaseBoolType)
forall (tp :: BaseType). SymExpr sym tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType SymArray sym idx BaseBoolType
a of
BaseArrayRepr Assignment BaseTypeRepr (idx ::> tp)
idx_tps BaseTypeRepr xs
_ ->
sym
-> SymExpr sym (BaseArrayType (idx ::> tp) BaseBoolType)
-> SymExpr sym (BaseArrayType (idx ::> tp) BaseBoolType)
-> IO (Pred sym)
forall sym (idx :: Ctx BaseType) (b :: BaseType).
IsExprBuilder sym =>
sym -> SymArray sym idx b -> SymArray sym idx b -> IO (Pred sym)
forall (idx :: Ctx BaseType) (b :: BaseType).
sym -> SymArray sym idx b -> SymArray sym idx b -> IO (Pred sym)
arrayEq sym
sym SymArray sym idx BaseBoolType
SymExpr sym (BaseArrayType (idx ::> tp) BaseBoolType)
a (SymExpr sym (BaseArrayType (idx ::> tp) BaseBoolType)
-> IO (Pred sym))
-> IO (SymExpr sym (BaseArrayType (idx ::> tp) BaseBoolType))
-> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym
-> Assignment BaseTypeRepr (idx ::> tp)
-> Pred sym
-> IO (SymExpr sym (BaseArrayType (idx ::> tp) BaseBoolType))
forall sym (idx :: Ctx BaseType) (tp :: BaseType) (b :: BaseType).
IsExprBuilder sym =>
sym
-> Assignment BaseTypeRepr (idx ::> tp)
-> SymExpr sym b
-> IO (SymArray sym (idx ::> tp) b)
forall (idx :: Ctx BaseType) (tp :: BaseType) (b :: BaseType).
sym
-> Assignment BaseTypeRepr (idx ::> tp)
-> SymExpr sym b
-> IO (SymArray sym (idx ::> tp) b)
constantArray sym
sym Assignment BaseTypeRepr (idx ::> tp)
idx_tps (sym -> Pred sym
forall sym. IsExprBuilder sym => sym -> Pred sym
truePred sym
sym)
arrayTrueOnEntries
:: sym
-> SymFn sym (idx::>itp) BaseBoolType
-> SymArray sym (idx ::> itp) BaseBoolType
-> IO (Pred sym)
integerToReal :: sym -> SymInteger sym -> IO (SymReal sym)
bvToInteger :: (1 <= w) => sym -> SymBV sym w -> IO (SymInteger sym)
sbvToInteger :: (1 <= w) => sym -> SymBV sym w -> IO (SymInteger sym)
predToBV :: (1 <= w) => sym -> Pred sym -> NatRepr w -> IO (SymBV sym w)
uintToReal :: (1 <= w) => sym -> SymBV sym w -> IO (SymReal sym)
uintToReal sym
sym = sym -> SymExpr sym (BaseBVType w) -> IO (SymInteger sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> IO (SymInteger sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> IO (SymInteger sym)
bvToInteger sym
sym (SymExpr sym (BaseBVType w) -> IO (SymInteger sym))
-> (SymInteger sym -> IO (SymReal sym))
-> SymExpr sym (BaseBVType w)
-> IO (SymReal sym)
forall (m :: Type -> Type) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> sym -> SymInteger sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> IO (SymReal sym)
integerToReal sym
sym
sbvToReal :: (1 <= w) => sym -> SymBV sym w -> IO (SymReal sym)
sbvToReal sym
sym = sym -> SymExpr sym (BaseBVType w) -> IO (SymInteger sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> IO (SymInteger sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> IO (SymInteger sym)
sbvToInteger sym
sym (SymExpr sym (BaseBVType w) -> IO (SymInteger sym))
-> (SymInteger sym -> IO (SymReal sym))
-> SymExpr sym (BaseBVType w)
-> IO (SymReal sym)
forall (m :: Type -> Type) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> sym -> SymInteger sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> IO (SymReal sym)
integerToReal sym
sym
realRound :: sym -> SymReal sym -> IO (SymInteger sym)
realRoundEven :: sym -> SymReal sym -> IO (SymInteger sym)
realFloor :: sym -> SymReal sym -> IO (SymInteger sym)
realCeil :: sym -> SymReal sym -> IO (SymInteger sym)
realTrunc :: sym -> SymReal sym -> IO (SymInteger sym)
realTrunc sym
sym SymReal sym
x =
do pneg <- sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLt sym
sym SymReal sym
x (SymReal sym -> IO (Pred sym)) -> IO (SymReal sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> Rational -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymReal sym)
realLit sym
sym Rational
0
iteM intIte sym pneg (realCeil sym x) (realFloor sym x)
integerToBV :: (1 <= w) => sym -> SymInteger sym -> NatRepr w -> IO (SymBV sym w)
realToInteger :: sym -> SymReal sym -> IO (SymInteger sym)
realToBV :: (1 <= w) => sym -> SymReal sym -> NatRepr w -> IO (SymBV sym w)
realToBV sym
sym SymReal sym
r NatRepr w
w = do
i <- sym -> SymReal sym -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymInteger sym)
realRound sym
sym SymReal sym
r
clampedIntToBV sym i w
realToSBV :: (1 <= w) => sym -> SymReal sym -> NatRepr w -> IO (SymBV sym w)
realToSBV sym
sym SymReal sym
r NatRepr w
w = do
i <- sym -> SymReal sym -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymInteger sym)
realRound sym
sym SymReal sym
r
clampedIntToSBV sym i w
clampedIntToSBV :: (1 <= w) => sym -> SymInteger sym -> NatRepr w -> IO (SymBV sym w)
clampedIntToSBV sym
sym SymInteger sym
i NatRepr w
w
| Just Integer
v <- SymInteger sym -> Maybe Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> Maybe Integer
asInteger SymInteger sym
i = do
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w (BV w -> IO (SymBV sym w)) -> BV w -> IO (SymBV sym w)
forall a b. (a -> b) -> a -> b
$ NatRepr w -> Integer -> BV w
forall (w :: Nat). (1 <= w) => NatRepr w -> Integer -> BV w
BV.signedClamp NatRepr w
w Integer
v
| Bool
otherwise = do
let min_val :: Integer
min_val = NatRepr w -> Integer
forall (w :: Nat). (1 <= w) => NatRepr w -> Integer
minSigned NatRepr w
w
min_val_bv :: BV w
min_val_bv = NatRepr w -> BV w
forall (w :: Nat). (1 <= w) => NatRepr w -> BV w
BV.minSigned NatRepr w
w
min_sym <- sym -> Integer -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> Integer -> IO (SymInteger sym)
intLit sym
sym Integer
min_val
is_lt <- intLt sym i min_sym
iteM bvIte sym is_lt (bvLit sym w min_val_bv) $ do
let max_val = NatRepr w -> Integer
forall (w :: Nat). (1 <= w) => NatRepr w -> Integer
maxSigned NatRepr w
w
max_val_bv = NatRepr w -> BV w
forall (w :: Nat). (1 <= w) => NatRepr w -> BV w
BV.maxSigned NatRepr w
w
max_sym <- intLit sym max_val
is_gt <- intLt sym max_sym i
iteM bvIte sym is_gt (bvLit sym w max_val_bv) $ do
integerToBV sym i w
clampedIntToBV :: (1 <= w) => sym -> SymInteger sym -> NatRepr w -> IO (SymBV sym w)
clampedIntToBV sym
sym SymInteger sym
i NatRepr w
w
| Just Integer
v <- SymInteger sym -> Maybe Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> Maybe Integer
asInteger SymInteger sym
i = do
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w (BV w -> IO (SymBV sym w)) -> BV w -> IO (SymBV sym w)
forall a b. (a -> b) -> a -> b
$ NatRepr w -> Integer -> BV w
forall (w :: Nat). NatRepr w -> Integer -> BV w
BV.unsignedClamp NatRepr w
w Integer
v
| Bool
otherwise = do
min_sym <- sym -> Integer -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> Integer -> IO (SymInteger sym)
intLit sym
sym Integer
0
is_lt <- intLt sym i min_sym
iteM bvIte sym is_lt (bvZero sym w) $ do
let max_val = NatRepr w -> Integer
forall (n :: Nat). NatRepr n -> Integer
maxUnsigned NatRepr w
w
max_val_bv = NatRepr w -> BV w
forall (w :: Nat). NatRepr w -> BV w
BV.maxUnsigned NatRepr w
w
max_sym <- intLit sym max_val
is_gt <- intLt sym max_sym i
iteM bvIte sym is_gt (bvLit sym w max_val_bv) $
integerToBV sym i w
intSetWidth :: (1 <= m, 1 <= n) => sym -> SymBV sym m -> NatRepr n -> IO (SymBV sym n)
intSetWidth sym
sym SymBV sym m
e NatRepr n
n = do
let m :: NatRepr m
m = SymBV sym m -> NatRepr m
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym m
e
case NatRepr n
n NatRepr n -> NatRepr m -> NatCases n m
forall (m :: Nat) (n :: Nat).
NatRepr m -> NatRepr n -> NatCases m n
`testNatCases` NatRepr m
m of
NatCaseLT LeqProof (n + 1) m
LeqProof -> do
does_underflow <- sym -> SymBV sym m -> SymBV sym m -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvSlt sym
sym SymBV sym m
e (SymBV sym m -> IO (Pred sym)) -> IO (SymBV sym m) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> NatRepr m -> BV m -> IO (SymBV sym m)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr m
m (NatRepr n -> NatRepr m -> BV n -> BV m
forall (w :: Nat) (w' :: Nat).
(1 <= w, (w + 1) <= w') =>
NatRepr w -> NatRepr w' -> BV w -> BV w'
BV.sext NatRepr n
n NatRepr m
m (NatRepr n -> BV n
forall (w :: Nat). (1 <= w) => NatRepr w -> BV w
BV.minSigned NatRepr n
n))
iteM bvIte sym does_underflow (bvLit sym n (BV.minSigned n)) $ do
does_overflow <- bvSgt sym e =<< bvLit sym m (BV.mkBV m (maxSigned n))
iteM bvIte sym does_overflow (bvLit sym n (BV.maxSigned n)) $ do
bvTrunc sym n e
NatCases n m
NatCaseEQ -> SymBV sym n -> IO (SymBV sym n)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymBV sym m
SymBV sym n
e
NatCaseGT LeqProof (m + 1) n
LeqProof -> sym -> NatRepr n -> SymBV sym m -> IO (SymBV sym n)
forall (u :: Nat) (r :: Nat).
(1 <= u, (u + 1) <= r) =>
sym -> NatRepr r -> SymBV sym u -> IO (SymBV sym r)
forall sym (u :: Nat) (r :: Nat).
(IsExprBuilder sym, 1 <= u, (u + 1) <= r) =>
sym -> NatRepr r -> SymBV sym u -> IO (SymBV sym r)
bvSext sym
sym NatRepr n
n SymBV sym m
e
uintSetWidth :: (1 <= m, 1 <= n) => sym -> SymBV sym m -> NatRepr n -> IO (SymBV sym n)
uintSetWidth sym
sym SymBV sym m
e NatRepr n
n = do
let m :: NatRepr m
m = SymBV sym m -> NatRepr m
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym m
e
case NatRepr n
n NatRepr n -> NatRepr m -> NatCases n m
forall (m :: Nat) (n :: Nat).
NatRepr m -> NatRepr n -> NatCases m n
`testNatCases` NatRepr m
m of
NatCaseLT LeqProof (n + 1) m
LeqProof -> do
does_overflow <- sym -> SymBV sym m -> SymBV sym m -> IO (Pred sym)
forall (w :: Nat).
(1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> SymBV sym w -> IO (Pred sym)
bvUgt sym
sym SymBV sym m
e (SymBV sym m -> IO (Pred sym)) -> IO (SymBV sym m) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> NatRepr m -> BV m -> IO (SymBV sym m)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr m
m (NatRepr m -> Integer -> BV m
forall (w :: Nat). NatRepr w -> Integer -> BV w
BV.mkBV NatRepr m
m (NatRepr n -> Integer
forall (n :: Nat). NatRepr n -> Integer
maxUnsigned NatRepr n
n))
iteM bvIte sym does_overflow (bvLit sym n (BV.maxUnsigned n)) $ bvTrunc sym n e
NatCases n m
NatCaseEQ -> SymBV sym n -> IO (SymBV sym n)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymBV sym m
SymBV sym n
e
NatCaseGT LeqProof (m + 1) n
LeqProof -> sym -> NatRepr n -> SymBV sym m -> IO (SymBV sym n)
forall (u :: Nat) (r :: Nat).
(1 <= u, (u + 1) <= r) =>
sym -> NatRepr r -> SymBV sym u -> IO (SymBV sym r)
forall sym (u :: Nat) (r :: Nat).
(IsExprBuilder sym, 1 <= u, (u + 1) <= r) =>
sym -> NatRepr r -> SymBV sym u -> IO (SymBV sym r)
bvZext sym
sym NatRepr n
n SymBV sym m
e
intToUInt :: (1 <= m, 1 <= n) => sym -> SymBV sym m -> NatRepr n -> IO (SymBV sym n)
intToUInt sym
sym SymBV sym m
e NatRepr n
w = do
p <- sym -> SymBV sym m -> IO (Pred sym)
forall (w :: Nat). (1 <= w) => sym -> SymBV sym w -> IO (Pred sym)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> SymBV sym w -> IO (Pred sym)
bvIsNeg sym
sym SymBV sym m
e
iteM bvIte sym p (bvZero sym w) (uintSetWidth sym e w)
uintToInt :: (1 <= m, 1 <= n) => sym -> SymBV sym m -> NatRepr n -> IO (SymBV sym n)
uintToInt sym
sym SymBV sym m
e NatRepr n
n = do
let m :: NatRepr m
m = SymBV sym m -> NatRepr m
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym m
e
case NatRepr n
n NatRepr n -> NatRepr m -> NatCases n m
forall (m :: Nat) (n :: Nat).
NatRepr m -> NatRepr n -> NatCases m n
`testNatCases` NatRepr m
m of
NatCaseLT LeqProof (n + 1) m
LeqProof -> do
max_val <- sym -> NatRepr m -> BV m -> IO (SymBV sym m)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr m
m (NatRepr n -> NatRepr m -> BV n -> BV m
forall (w :: Nat) (w' :: Nat).
(1 <= w, (w + 1) <= w') =>
NatRepr w -> NatRepr w' -> BV w -> BV w'
BV.sext NatRepr n
n NatRepr m
m (NatRepr n -> BV n
forall (w :: Nat). (1 <= w) => NatRepr w -> BV w
BV.maxSigned NatRepr n
n))
p <- bvUle sym e max_val
bvTrunc sym n =<< bvIte sym p e max_val
NatCases n m
NatCaseEQ -> do
max_val <- sym -> NatRepr n -> IO (SymBV sym n)
forall (w :: Nat). (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> IO (SymBV sym w)
maxSignedBV sym
sym NatRepr n
n
p <- bvUle sym e max_val
bvIte sym p e max_val
NatCaseGT LeqProof (m + 1) n
LeqProof -> do
sym -> NatRepr n -> SymBV sym m -> IO (SymBV sym n)
forall (u :: Nat) (r :: Nat).
(1 <= u, (u + 1) <= r) =>
sym -> NatRepr r -> SymBV sym u -> IO (SymBV sym r)
forall sym (u :: Nat) (r :: Nat).
(IsExprBuilder sym, 1 <= u, (u + 1) <= r) =>
sym -> NatRepr r -> SymBV sym u -> IO (SymBV sym r)
bvZext sym
sym NatRepr n
n SymBV sym m
e
stringEmpty :: sym -> StringInfoRepr si -> IO (SymString sym si)
stringLit :: sym -> StringLiteral si -> IO (SymString sym si)
stringEq :: sym -> SymString sym si -> SymString sym si -> IO (Pred sym)
stringIte :: sym -> Pred sym -> SymString sym si -> SymString sym si -> IO (SymString sym si)
stringConcat :: sym -> SymString sym si -> SymString sym si -> IO (SymString sym si)
stringContains ::
sym ->
SymString sym si ->
SymString sym si ->
IO (Pred sym)
stringIsPrefixOf ::
sym ->
SymString sym si ->
SymString sym si ->
IO (Pred sym)
stringIsSuffixOf ::
sym ->
SymString sym si ->
SymString sym si ->
IO (Pred sym)
stringIndexOf ::
sym ->
SymString sym si ->
SymString sym si ->
SymInteger sym ->
IO (SymInteger sym)
stringLength :: sym -> SymString sym si -> IO (SymInteger sym)
stringSubstring ::
sym ->
SymString sym si ->
SymInteger sym ->
SymInteger sym ->
IO (SymString sym si)
realZero :: sym -> SymReal sym
realLit :: sym -> Rational -> IO (SymReal sym)
sciLit :: sym -> Scientific -> IO (SymReal sym)
sciLit sym
sym Scientific
s = sym -> Rational -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymReal sym)
realLit sym
sym (Scientific -> Rational
forall a. Real a => a -> Rational
toRational Scientific
s)
realEq :: sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realNe :: sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realNe sym
sym SymReal sym
x SymReal sym
y = sym -> Pred sym -> IO (Pred sym)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym (Pred sym -> IO (Pred sym)) -> IO (Pred sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realEq sym
sym SymReal sym
x SymReal sym
y
realLe :: sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLt :: sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLt sym
sym SymReal sym
x SymReal sym
y = sym -> Pred sym -> IO (Pred sym)
forall sym. IsExprBuilder sym => sym -> Pred sym -> IO (Pred sym)
notPred sym
sym (Pred sym -> IO (Pred sym)) -> IO (Pred sym) -> IO (Pred sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLe sym
sym SymReal sym
y SymReal sym
x
realGe :: sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realGe sym
sym SymReal sym
x SymReal sym
y = sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLe sym
sym SymReal sym
y SymReal sym
x
realGt :: sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realGt sym
sym SymReal sym
x SymReal sym
y = sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLt sym
sym SymReal sym
y SymReal sym
x
realIte :: sym -> Pred sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realMin :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realMin sym
sym SymReal sym
x SymReal sym
y =
do p <- sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLe sym
sym SymReal sym
x SymReal sym
y
realIte sym p x y
realMax :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realMax sym
sym SymReal sym
x SymReal sym
y =
do p <- sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLe sym
sym SymReal sym
x SymReal sym
y
realIte sym p y x
realNeg :: sym -> SymReal sym -> IO (SymReal sym)
realAdd :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realMul :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realSub :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realSub sym
sym SymReal sym
x SymReal sym
y = sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realAdd sym
sym SymReal sym
x (SymReal sym -> IO (SymReal sym))
-> IO (SymReal sym) -> IO (SymReal sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realNeg sym
sym SymReal sym
y
realSq :: sym -> SymReal sym -> IO (SymReal sym)
realSq sym
sym SymReal sym
x = sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realMul sym
sym SymReal sym
x SymReal sym
x
realDiv :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realMod :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realMod sym
sym SymReal sym
x SymReal sym
y = do
isZero <- sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realEq sym
sym SymReal sym
y (sym -> SymReal sym
forall sym. IsExprBuilder sym => sym -> SymReal sym
realZero sym
sym)
iteM realIte sym isZero (return x) $ do
realSub sym x =<< realMul sym y
=<< integerToReal sym
=<< realFloor sym
=<< realDiv sym x y
isInteger :: sym -> SymReal sym -> IO (Pred sym)
realIsNonNeg :: sym -> SymReal sym -> IO (Pred sym)
realIsNonNeg sym
sym SymReal sym
x = sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realLe sym
sym (sym -> SymReal sym
forall sym. IsExprBuilder sym => sym -> SymReal sym
realZero sym
sym) SymReal sym
x
realSqrt :: sym -> SymReal sym -> IO (SymReal sym)
realPi :: sym -> IO (SymReal sym)
realPi sym
sym = sym -> SpecialFunction EmptyCtx -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SpecialFunction EmptyCtx -> IO (SymReal sym)
realSpecialFunction0 sym
sym SpecialFunction EmptyCtx
Pi
realLog :: sym -> SymReal sym -> IO (SymReal sym)
realLog sym
sym SymReal sym
x = sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
Log SymReal sym
x
realExp :: sym -> SymReal sym -> IO (SymReal sym)
realExp sym
sym SymReal sym
x = sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
Exp SymReal sym
x
realSin :: sym -> SymReal sym -> IO (SymReal sym)
realSin sym
sym SymReal sym
x = sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
Sin SymReal sym
x
realCos :: sym -> SymReal sym -> IO (SymReal sym)
realCos sym
sym SymReal sym
x = sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
Cos SymReal sym
x
realTan :: sym -> SymReal sym -> IO (SymReal sym)
realTan sym
sym SymReal sym
x = sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
Tan SymReal sym
x
realSinh :: sym -> SymReal sym -> IO (SymReal sym)
realSinh sym
sym SymReal sym
x = sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
Sinh SymReal sym
x
realCosh :: sym -> SymReal sym -> IO (SymReal sym)
realCosh sym
sym SymReal sym
x = sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
Cosh SymReal sym
x
realTanh :: sym -> SymReal sym -> IO (SymReal sym)
realTanh sym
sym SymReal sym
x = sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
Tanh SymReal sym
x
realAbs :: sym -> SymReal sym -> IO (SymReal sym)
realAbs sym
sym SymReal sym
x = do
c <- sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realGe sym
sym SymReal sym
x (sym -> SymReal sym
forall sym. IsExprBuilder sym => sym -> SymReal sym
realZero sym
sym)
realIte sym c x =<< realNeg sym x
realHypot :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realHypot sym
sym SymReal sym
x SymReal sym
y = do
case (SymReal sym -> Maybe Rational
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseRealType -> Maybe Rational
asRational SymReal sym
x, SymReal sym -> Maybe Rational
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseRealType -> Maybe Rational
asRational SymReal sym
y) of
(Just Rational
0, Maybe Rational
_) -> sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realAbs sym
sym SymReal sym
y
(Maybe Rational
_, Just Rational
0) -> sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realAbs sym
sym SymReal sym
x
(Maybe Rational, Maybe Rational)
_ -> do
x2 <- sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realSq sym
sym SymReal sym
x
y2 <- realSq sym y
realSqrt sym =<< realAdd sym x2 y2
realAtan2 :: sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realAtan2 sym
sym SymReal sym
y SymReal sym
x = sym
-> SpecialFunction ((EmptyCtx ::> R) ::> R)
-> SymReal sym
-> SymReal sym
-> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym
-> SpecialFunction ((EmptyCtx ::> R) ::> R)
-> SymReal sym
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction2 sym
sym SpecialFunction ((EmptyCtx ::> R) ::> R)
Arctan2 SymReal sym
y SymReal sym
x
realSpecialFunction
:: sym
-> SpecialFunction args
-> Ctx.Assignment (SpecialFnArg (SymExpr sym) BaseRealType) args
-> IO (SymReal sym)
realSpecialFunction0
:: sym
-> SpecialFunction EmptyCtx
-> IO (SymReal sym)
realSpecialFunction0 sym
sym SpecialFunction EmptyCtx
fn =
sym
-> SpecialFunction EmptyCtx
-> Assignment (SpecialFnArg (SymExpr sym) BaseRealType) EmptyCtx
-> IO (SymReal sym)
forall sym (args :: Ctx Type).
IsExprBuilder sym =>
sym
-> SpecialFunction args
-> Assignment (SpecialFnArg (SymExpr sym) BaseRealType) args
-> IO (SymReal sym)
forall (args :: Ctx Type).
sym
-> SpecialFunction args
-> Assignment (SpecialFnArg (SymExpr sym) BaseRealType) args
-> IO (SymReal sym)
realSpecialFunction sym
sym SpecialFunction EmptyCtx
fn Assignment (SpecialFnArg (SymExpr sym) BaseRealType) EmptyCtx
forall {k} (ctx :: Ctx k) (f :: k -> Type).
(ctx ~ EmptyCtx) =>
Assignment f ctx
Ctx.Empty
realSpecialFunction1
:: sym
-> SpecialFunction (EmptyCtx ::> R)
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction1 sym
sym SpecialFunction (EmptyCtx ::> R)
fn SymReal sym
x =
sym
-> SpecialFunction (EmptyCtx ::> R)
-> Assignment
(SpecialFnArg (SymExpr sym) BaseRealType) (EmptyCtx ::> R)
-> IO (SymReal sym)
forall sym (args :: Ctx Type).
IsExprBuilder sym =>
sym
-> SpecialFunction args
-> Assignment (SpecialFnArg (SymExpr sym) BaseRealType) args
-> IO (SymReal sym)
forall (args :: Ctx Type).
sym
-> SpecialFunction args
-> Assignment (SpecialFnArg (SymExpr sym) BaseRealType) args
-> IO (SymReal sym)
realSpecialFunction sym
sym SpecialFunction (EmptyCtx ::> R)
fn (Assignment (SpecialFnArg (SymExpr sym) BaseRealType) EmptyCtx
forall {k} (ctx :: Ctx k) (f :: k -> Type).
(ctx ~ EmptyCtx) =>
Assignment f ctx
Ctx.Empty Assignment (SpecialFnArg (SymExpr sym) BaseRealType) EmptyCtx
-> SpecialFnArg (SymExpr sym) BaseRealType R
-> Assignment
(SpecialFnArg (SymExpr sym) BaseRealType) (EmptyCtx ::> R)
forall {k} (ctx' :: Ctx k) (f :: k -> Type) (ctx :: Ctx k)
(tp :: k).
(ctx' ~ (ctx ::> tp)) =>
Assignment f ctx -> f tp -> Assignment f ctx'
Ctx.:> SymReal sym -> SpecialFnArg (SymExpr sym) BaseRealType R
forall {k} (e :: k -> Type) (tp :: k). e tp -> SpecialFnArg e tp R
SpecialFnArg SymReal sym
x)
realSpecialFunction2
:: sym
-> SpecialFunction (EmptyCtx ::> R ::> R)
-> SymReal sym
-> SymReal sym
-> IO (SymReal sym)
realSpecialFunction2 sym
sym SpecialFunction ((EmptyCtx ::> R) ::> R)
fn SymReal sym
x SymReal sym
y =
sym
-> SpecialFunction ((EmptyCtx ::> R) ::> R)
-> Assignment
(SpecialFnArg (SymExpr sym) BaseRealType) ((EmptyCtx ::> R) ::> R)
-> IO (SymReal sym)
forall sym (args :: Ctx Type).
IsExprBuilder sym =>
sym
-> SpecialFunction args
-> Assignment (SpecialFnArg (SymExpr sym) BaseRealType) args
-> IO (SymReal sym)
forall (args :: Ctx Type).
sym
-> SpecialFunction args
-> Assignment (SpecialFnArg (SymExpr sym) BaseRealType) args
-> IO (SymReal sym)
realSpecialFunction sym
sym SpecialFunction ((EmptyCtx ::> R) ::> R)
fn (Assignment (SpecialFnArg (SymExpr sym) BaseRealType) EmptyCtx
forall {k} (ctx :: Ctx k) (f :: k -> Type).
(ctx ~ EmptyCtx) =>
Assignment f ctx
Ctx.Empty Assignment (SpecialFnArg (SymExpr sym) BaseRealType) EmptyCtx
-> SpecialFnArg (SymExpr sym) BaseRealType R
-> Assignment
(SpecialFnArg (SymExpr sym) BaseRealType) (EmptyCtx ::> R)
forall {k} (ctx' :: Ctx k) (f :: k -> Type) (ctx :: Ctx k)
(tp :: k).
(ctx' ~ (ctx ::> tp)) =>
Assignment f ctx -> f tp -> Assignment f ctx'
Ctx.:> SymReal sym -> SpecialFnArg (SymExpr sym) BaseRealType R
forall {k} (e :: k -> Type) (tp :: k). e tp -> SpecialFnArg e tp R
SpecialFnArg SymReal sym
x Assignment
(SpecialFnArg (SymExpr sym) BaseRealType) (EmptyCtx ::> R)
-> SpecialFnArg (SymExpr sym) BaseRealType R
-> Assignment
(SpecialFnArg (SymExpr sym) BaseRealType) ((EmptyCtx ::> R) ::> R)
forall {k} (ctx' :: Ctx k) (f :: k -> Type) (ctx :: Ctx k)
(tp :: k).
(ctx' ~ (ctx ::> tp)) =>
Assignment f ctx -> f tp -> Assignment f ctx'
Ctx.:> SymReal sym -> SpecialFnArg (SymExpr sym) BaseRealType R
forall {k} (e :: k -> Type) (tp :: k). e tp -> SpecialFnArg e tp R
SpecialFnArg SymReal sym
y)
floatPZero :: sym -> FloatPrecisionRepr fpp -> IO (SymFloat sym fpp)
floatNZero :: sym -> FloatPrecisionRepr fpp -> IO (SymFloat sym fpp)
floatNaN :: sym -> FloatPrecisionRepr fpp -> IO (SymFloat sym fpp)
floatPInf :: sym -> FloatPrecisionRepr fpp -> IO (SymFloat sym fpp)
floatNInf :: sym -> FloatPrecisionRepr fpp -> IO (SymFloat sym fpp)
floatLitRational
:: sym -> FloatPrecisionRepr fpp -> Rational -> IO (SymFloat sym fpp)
floatLitRational sym
sym FloatPrecisionRepr fpp
fpp Rational
x = sym
-> FloatPrecisionRepr fpp
-> RoundingMode
-> SymReal sym
-> IO (SymExpr sym (BaseFloatType fpp))
forall sym (fpp :: FloatPrecision).
IsExprBuilder sym =>
sym
-> FloatPrecisionRepr fpp
-> RoundingMode
-> SymReal sym
-> IO (SymFloat sym fpp)
forall (fpp :: FloatPrecision).
sym
-> FloatPrecisionRepr fpp
-> RoundingMode
-> SymReal sym
-> IO (SymFloat sym fpp)
realToFloat sym
sym FloatPrecisionRepr fpp
fpp RoundingMode
RNE (SymReal sym -> IO (SymExpr sym (BaseFloatType fpp)))
-> IO (SymReal sym) -> IO (SymExpr sym (BaseFloatType fpp))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> Rational -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymReal sym)
realLit sym
sym Rational
x
floatLit :: sym -> FloatPrecisionRepr fpp -> BigFloat -> IO (SymFloat sym fpp)
floatNeg
:: sym
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatAbs
:: sym
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatSqrt
:: sym
-> RoundingMode
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatAdd
:: sym
-> RoundingMode
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatSub
:: sym
-> RoundingMode
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatMul
:: sym
-> RoundingMode
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatDiv
:: sym
-> RoundingMode
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatRem
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatMin
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatMax
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatFMA
:: sym
-> RoundingMode
-> SymFloat sym fpp
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatEq
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatNe
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatFpEq
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatFpApart
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatFpApart sym
sym SymFloat sym fpp
x SymFloat sym fpp
y =
do l <- sym -> SymFloat sym fpp -> SymFloat sym fpp -> IO (Pred sym)
forall sym (fpp :: FloatPrecision).
IsExprBuilder sym =>
sym -> SymFloat sym fpp -> SymFloat sym fpp -> IO (Pred sym)
forall (fpp :: FloatPrecision).
sym -> SymFloat sym fpp -> SymFloat sym fpp -> IO (Pred sym)
floatLt sym
sym SymFloat sym fpp
x SymFloat sym fpp
y
g <- floatGt sym x y
orPred sym l g
floatFpUnordered
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatFpUnordered sym
sym SymFloat sym fpp
x SymFloat sym fpp
y =
do xnan <- sym -> SymFloat sym fpp -> IO (Pred sym)
forall sym (fpp :: FloatPrecision).
IsExprBuilder sym =>
sym -> SymFloat sym fpp -> IO (Pred sym)
forall (fpp :: FloatPrecision).
sym -> SymFloat sym fpp -> IO (Pred sym)
floatIsNaN sym
sym SymFloat sym fpp
x
ynan <- floatIsNaN sym y
orPred sym xnan ynan
floatLe
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatLt
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatGe
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatGt
:: sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (Pred sym)
floatIsNaN :: sym -> SymFloat sym fpp -> IO (Pred sym)
floatIsInf :: sym -> SymFloat sym fpp -> IO (Pred sym)
floatIsZero :: sym -> SymFloat sym fpp -> IO (Pred sym)
floatIsPos :: sym -> SymFloat sym fpp -> IO (Pred sym)
floatIsNeg :: sym -> SymFloat sym fpp -> IO (Pred sym)
floatIsSubnorm :: sym -> SymFloat sym fpp -> IO (Pred sym)
floatIsNorm :: sym -> SymFloat sym fpp -> IO (Pred sym)
floatIte
:: sym
-> Pred sym
-> SymFloat sym fpp
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatCast
:: sym
-> FloatPrecisionRepr fpp
-> RoundingMode
-> SymFloat sym fpp'
-> IO (SymFloat sym fpp)
floatRound
:: sym
-> RoundingMode
-> SymFloat sym fpp
-> IO (SymFloat sym fpp)
floatFromBinary
:: (2 <= eb, 2 <= sb)
=> sym
-> FloatPrecisionRepr (FloatingPointPrecision eb sb)
-> SymBV sym (eb + sb)
-> IO (SymFloat sym (FloatingPointPrecision eb sb))
floatToBinary
:: (2 <= eb, 2 <= sb)
=> sym
-> SymFloat sym (FloatingPointPrecision eb sb)
-> IO (SymBV sym (eb + sb))
bvToFloat
:: (1 <= w)
=> sym
-> FloatPrecisionRepr fpp
-> RoundingMode
-> SymBV sym w
-> IO (SymFloat sym fpp)
sbvToFloat
:: (1 <= w)
=> sym
-> FloatPrecisionRepr fpp
-> RoundingMode
-> SymBV sym w
-> IO (SymFloat sym fpp)
realToFloat
:: sym
-> FloatPrecisionRepr fpp
-> RoundingMode
-> SymReal sym
-> IO (SymFloat sym fpp)
floatToBV
:: (1 <= w)
=> sym
-> NatRepr w
-> RoundingMode
-> SymFloat sym fpp
-> IO (SymBV sym w)
floatToSBV
:: (1 <= w)
=> sym
-> NatRepr w
-> RoundingMode
-> SymFloat sym fpp
-> IO (SymBV sym w)
floatToReal :: sym -> SymFloat sym fpp -> IO (SymReal sym)
floatSpecialFunction
:: sym
-> FloatPrecisionRepr fpp
-> SpecialFunction args
-> Ctx.Assignment (SpecialFnArg (SymExpr sym) (BaseFloatType fpp)) args
-> IO (SymFloat sym fpp)
mkComplex :: sym -> Complex (SymReal sym) -> IO (SymCplx sym)
getRealPart :: sym -> SymCplx sym -> IO (SymReal sym)
getImagPart :: sym -> SymCplx sym -> IO (SymReal sym)
cplxGetParts :: sym -> SymCplx sym -> IO (Complex (SymReal sym))
mkComplexLit :: sym -> Complex Rational -> IO (SymCplx sym)
mkComplexLit sym
sym Complex Rational
d = sym -> Complex (SymReal sym) -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex (SymReal sym) -> IO (SymCplx sym)
mkComplex sym
sym (Complex (SymReal sym) -> IO (SymCplx sym))
-> IO (Complex (SymReal sym)) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Rational -> IO (SymReal sym))
-> Complex Rational -> IO (Complex (SymReal sym))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Complex a -> f (Complex b)
traverse (sym -> Rational -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymReal sym)
realLit sym
sym) Complex Rational
d
cplxFromReal :: sym -> SymReal sym -> IO (SymCplx sym)
cplxFromReal sym
sym SymReal sym
r = sym -> Complex (SymReal sym) -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex (SymReal sym) -> IO (SymCplx sym)
mkComplex sym
sym (SymReal sym
r SymReal sym -> SymReal sym -> Complex (SymReal sym)
forall a. a -> a -> Complex a
:+ sym -> SymReal sym
forall sym. IsExprBuilder sym => sym -> SymReal sym
realZero sym
sym)
cplxIte :: sym -> Pred sym -> SymCplx sym -> SymCplx sym -> IO (SymCplx sym)
cplxIte sym
sym Pred sym
c SymCplx sym
x SymCplx sym
y = do
case Pred sym -> Maybe Bool
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseBoolType -> Maybe Bool
asConstantPred Pred sym
c of
Just Bool
True -> SymCplx sym -> IO (SymCplx sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymCplx sym
x
Just Bool
False -> SymCplx sym -> IO (SymCplx sym)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymCplx sym
y
Maybe Bool
_ -> do
xr :+ xi <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
yr :+ yi <- cplxGetParts sym y
zr <- realIte sym c xr yr
zi <- realIte sym c xi yi
mkComplex sym (zr :+ zi)
cplxNeg :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxNeg sym
sym SymCplx sym
x = sym -> Complex (SymReal sym) -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex (SymReal sym) -> IO (SymCplx sym)
mkComplex sym
sym (Complex (SymReal sym) -> IO (SymCplx sym))
-> IO (Complex (SymReal sym)) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< (SymReal sym -> IO (SymReal sym))
-> Complex (SymReal sym) -> IO (Complex (SymReal sym))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Complex a -> f (Complex b)
traverse (sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realNeg sym
sym) (Complex (SymReal sym) -> IO (Complex (SymReal sym)))
-> IO (Complex (SymReal sym)) -> IO (Complex (SymReal sym))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
cplxAdd :: sym -> SymCplx sym -> SymCplx sym -> IO (SymCplx sym)
cplxAdd sym
sym SymCplx sym
x SymCplx sym
y = do
xr :+ xi <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
yr :+ yi <- cplxGetParts sym y
zr <- realAdd sym xr yr
zi <- realAdd sym xi yi
mkComplex sym (zr :+ zi)
cplxSub :: sym -> SymCplx sym -> SymCplx sym -> IO (SymCplx sym)
cplxSub sym
sym SymCplx sym
x SymCplx sym
y = do
xr :+ xi <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
yr :+ yi <- cplxGetParts sym y
zr <- realSub sym xr yr
zi <- realSub sym xi yi
mkComplex sym (zr :+ zi)
cplxMul :: sym -> SymCplx sym -> SymCplx sym -> IO (SymCplx sym)
cplxMul sym
sym SymCplx sym
x SymCplx sym
y = do
xr :+ xi <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
yr :+ yi <- cplxGetParts sym y
rz0 <- realMul sym xr yr
rz <- realSub sym rz0 =<< realMul sym xi yi
iz0 <- realMul sym xi yr
iz <- realAdd sym iz0 =<< realMul sym xr yi
mkComplex sym (rz :+ iz)
cplxMag :: sym -> SymCplx sym -> IO (SymReal sym)
cplxMag sym
sym SymCplx sym
x = do
(xr :+ xi) <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
realHypot sym xr xi
cplxSqrt :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxSqrt sym
sym SymCplx sym
x = do
(r_part :+ i_part) <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
case (asRational r_part :+ asRational i_part)of
(Just Rational
r :+ Just Rational
i) | Just Complex Rational
z <- (Rational -> Maybe Rational)
-> Complex Rational -> Maybe (Complex Rational)
forall a (m :: Type -> Type).
(Ord a, Fractional a, Monad m) =>
(a -> m a) -> Complex a -> m (Complex a)
tryComplexSqrt Rational -> Maybe Rational
tryRationalSqrt (Rational
r Rational -> Rational -> Complex Rational
forall a. a -> a -> Complex a
:+ Rational
i) ->
sym -> Complex Rational -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex Rational -> IO (SymCplx sym)
mkComplexLit sym
sym Complex Rational
z
(Maybe Rational
_ :+ Just Rational
0) -> do
c <- sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (Pred sym)
realGe sym
sym SymReal sym
r_part (sym -> SymReal sym
forall sym. IsExprBuilder sym => sym -> SymReal sym
realZero sym
sym)
u <- iteM realIte sym c
(realSqrt sym r_part)
(realLit sym 0)
v <- iteM realIte sym c
(realLit sym 0)
(realSqrt sym =<< realNeg sym r_part)
mkComplex sym (u :+ v)
Complex (Maybe Rational)
_ -> do
m <- sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realHypot sym
sym SymReal sym
r_part SymReal sym
i_part
m_plus_r <- realAdd sym m r_part
m_sub_r <- realSub sym m r_part
two <- realLit sym 2
u <- realSqrt sym =<< realDiv sym m_plus_r two
v <- realSqrt sym =<< realDiv sym m_sub_r two
neg_v <- realNeg sym v
i_part_nonneg <- realIsNonNeg sym i_part
v' <- realIte sym i_part_nonneg v neg_v
mkComplex sym (u :+ v')
cplxSin :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxSin sym
sym SymCplx sym
arg = do
c@(x :+ y) <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
arg
case asRational <$> c of
(Just Rational
0 :+ Just Rational
0) -> sym -> SymReal sym -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymCplx sym)
cplxFromReal sym
sym (sym -> SymReal sym
forall sym. IsExprBuilder sym => sym -> SymReal sym
realZero sym
sym)
(Maybe Rational
_ :+ Just Rational
0) -> sym -> SymReal sym -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymCplx sym)
cplxFromReal sym
sym (SymReal sym -> IO (SymCplx sym))
-> IO (SymReal sym) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realSin sym
sym SymReal sym
x
(Just Rational
0 :+ Maybe Rational
_) -> do
sinh_y <- sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realSinh sym
sym SymReal sym
y
mkComplex sym (realZero sym :+ sinh_y)
Complex (Maybe Rational)
_ -> do
sin_x <- sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realSin sym
sym SymReal sym
x
cos_x <- realCos sym x
sinh_y <- realSinh sym y
cosh_y <- realCosh sym y
r_part <- realMul sym sin_x cosh_y
i_part <- realMul sym cos_x sinh_y
mkComplex sym (r_part :+ i_part)
cplxCos :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxCos sym
sym SymCplx sym
arg = do
c@(x :+ y) <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
arg
case asRational <$> c of
(Just Rational
0 :+ Just Rational
0) -> sym -> SymReal sym -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymCplx sym)
cplxFromReal sym
sym (SymReal sym -> IO (SymCplx sym))
-> IO (SymReal sym) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> Rational -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymReal sym)
realLit sym
sym Rational
1
(Maybe Rational
_ :+ Just Rational
0) -> sym -> SymReal sym -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymCplx sym)
cplxFromReal sym
sym (SymReal sym -> IO (SymCplx sym))
-> IO (SymReal sym) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realCos sym
sym SymReal sym
x
(Just Rational
0 :+ Maybe Rational
_) -> do
cosh_y <- sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realCosh sym
sym SymReal sym
y
cplxFromReal sym cosh_y
Complex (Maybe Rational)
_ -> do
neg_sin_x <- sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realNeg sym
sym (SymReal sym -> IO (SymReal sym))
-> IO (SymReal sym) -> IO (SymReal sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realSin sym
sym SymReal sym
x
cos_x <- realCos sym x
sinh_y <- realSinh sym y
cosh_y <- realCosh sym y
r_part <- realMul sym cos_x cosh_y
i_part <- realMul sym neg_sin_x sinh_y
mkComplex sym (r_part :+ i_part)
cplxTan :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxTan sym
sym SymCplx sym
arg = do
c@(x :+ y) <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
arg
case asRational <$> c of
(Just Rational
0 :+ Just Rational
0) -> sym -> SymReal sym -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymCplx sym)
cplxFromReal sym
sym (sym -> SymReal sym
forall sym. IsExprBuilder sym => sym -> SymReal sym
realZero sym
sym)
(Maybe Rational
_ :+ Just Rational
0) -> do
sym -> SymReal sym -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymCplx sym)
cplxFromReal sym
sym (SymReal sym -> IO (SymCplx sym))
-> IO (SymReal sym) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realTan sym
sym SymReal sym
x
(Just Rational
0 :+ Maybe Rational
_) -> do
i_part <- sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realTanh sym
sym SymReal sym
y
mkComplex sym (realZero sym :+ i_part)
Complex (Maybe Rational)
_ -> do
sin_x <- sym -> SymReal sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realSin sym
sym SymReal sym
x
cos_x <- realCos sym x
sinh_y <- realSinh sym y
cosh_y <- realCosh sym y
u <- realMul sym cos_x cosh_y
v <- realMul sym sin_x sinh_y
u2 <- realMul sym u u
v2 <- realMul sym v v
m <- realAdd sym u2 v2
sin_x_cos_x <- realMul sym sin_x cos_x
sinh_y_cosh_y <- realMul sym sinh_y cosh_y
r_part <- realDiv sym sin_x_cos_x m
i_part <- realDiv sym sinh_y_cosh_y m
mkComplex sym (r_part :+ i_part)
cplxHypot :: sym -> SymCplx sym -> SymCplx sym -> IO (SymCplx sym)
cplxHypot sym
sym SymCplx sym
x SymCplx sym
y = do
(xr :+ xi) <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
(yr :+ yi) <- cplxGetParts sym y
xr2 <- realSq sym xr
xi2 <- realSq sym xi
yr2 <- realSq sym yr
yi2 <- realSq sym yi
r2 <- foldM (realAdd sym) xr2 [xi2, yr2, yi2]
cplxFromReal sym =<< realSqrt sym r2
cplxRound :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxRound sym
sym SymCplx sym
x = do
c <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
mkComplex sym =<< traverse (integerToReal sym <=< realRound sym) c
cplxFloor :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxFloor sym
sym SymCplx sym
x =
sym -> Complex (SymReal sym) -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex (SymReal sym) -> IO (SymCplx sym)
mkComplex sym
sym (Complex (SymReal sym) -> IO (SymCplx sym))
-> IO (Complex (SymReal sym)) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< (SymReal sym -> IO (SymReal sym))
-> Complex (SymReal sym) -> IO (Complex (SymReal sym))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Complex a -> f (Complex b)
traverse (sym -> SymInteger sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> IO (SymReal sym)
integerToReal sym
sym (SymInteger sym -> IO (SymReal sym))
-> (SymReal sym -> IO (SymInteger sym))
-> SymReal sym
-> IO (SymReal sym)
forall (m :: Type -> Type) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< sym -> SymReal sym -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymInteger sym)
realFloor sym
sym)
(Complex (SymReal sym) -> IO (Complex (SymReal sym)))
-> IO (Complex (SymReal sym)) -> IO (Complex (SymReal sym))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
cplxCeil :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxCeil sym
sym SymCplx sym
x =
sym -> Complex (SymReal sym) -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex (SymReal sym) -> IO (SymCplx sym)
mkComplex sym
sym (Complex (SymReal sym) -> IO (SymCplx sym))
-> IO (Complex (SymReal sym)) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< (SymReal sym -> IO (SymReal sym))
-> Complex (SymReal sym) -> IO (Complex (SymReal sym))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Complex a -> f (Complex b)
traverse (sym -> SymInteger sym -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> SymInteger sym -> IO (SymReal sym)
integerToReal sym
sym (SymInteger sym -> IO (SymReal sym))
-> (SymReal sym -> IO (SymInteger sym))
-> SymReal sym
-> IO (SymReal sym)
forall (m :: Type -> Type) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< sym -> SymReal sym -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymInteger sym)
realCeil sym
sym)
(Complex (SymReal sym) -> IO (Complex (SymReal sym)))
-> IO (Complex (SymReal sym)) -> IO (Complex (SymReal sym))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
cplxConj :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxConj sym
sym SymCplx sym
x = do
r :+ i <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
ic <- realNeg sym i
mkComplex sym (r :+ ic)
cplxExp :: sym -> SymCplx sym -> IO (SymCplx sym)
cplxExp sym
sym SymCplx sym
x = do
(rx :+ i_part) <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
expx <- realExp sym rx
cosx <- realCos sym i_part
sinx <- realSin sym i_part
rz <- realMul sym expx cosx
iz <- realMul sym expx sinx
mkComplex sym (rz :+ iz)
cplxEq :: sym -> SymCplx sym -> SymCplx sym -> IO (Pred sym)
cplxEq sym
sym SymCplx sym
x SymCplx sym
y = do
xr :+ xi <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
yr :+ yi <- cplxGetParts sym y
pr <- realEq sym xr yr
pj <- realEq sym xi yi
andPred sym pr pj
cplxNe :: sym -> SymCplx sym -> SymCplx sym -> IO (Pred sym)
cplxNe sym
sym SymCplx sym
x SymCplx sym
y = do
xr :+ xi <- sym -> SymCplx sym -> IO (Complex (SymReal sym))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
yr :+ yi <- cplxGetParts sym y
pr <- realNe sym xr yr
pj <- realNe sym xi yi
orPred sym pr pj
newtype SymBV' sym w = MkSymBV' (SymBV sym w)
bvJoinVector :: forall sym n w. (1 <= w, IsExprBuilder sym)
=> sym
-> NatRepr w
-> Vector.Vector n (SymBV sym w)
-> IO (SymBV sym (n * w))
bvJoinVector :: forall sym (n :: Nat) (w :: Nat).
(1 <= w, IsExprBuilder sym) =>
sym
-> NatRepr w -> Vector n (SymBV sym w) -> IO (SymBV sym (n * w))
bvJoinVector sym
sym NatRepr w
w =
(Vector n (SymBV' sym w) -> IO (SymBV' sym (n * w)))
-> Vector n (SymExpr sym (BaseBVType w))
-> IO (SymExpr sym (BaseBVType (n * w)))
forall a b. Coercible a b => a -> b
coerce ((Vector n (SymBV' sym w) -> IO (SymBV' sym (n * w)))
-> Vector n (SymExpr sym (BaseBVType w))
-> IO (SymExpr sym (BaseBVType (n * w))))
-> (Vector n (SymBV' sym w) -> IO (SymBV' sym (n * w)))
-> Vector n (SymExpr sym (BaseBVType w))
-> IO (SymExpr sym (BaseBVType (n * w)))
forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type) (f :: Nat -> Type) (n :: Nat)
(w :: Nat).
(1 <= w, Monad m) =>
(forall (l :: Nat).
(1 <= l) =>
NatRepr l -> f w -> f l -> m (f (w + l)))
-> NatRepr w -> Vector n (f w) -> m (f (n * w))
Vector.joinWithM @IO @(SymBV' sym) @n NatRepr l
-> SymBV' sym w -> SymBV' sym l -> IO (SymBV' sym (w + l))
forall (l :: Nat).
(1 <= l) =>
NatRepr l
-> SymBV' sym w -> SymBV' sym l -> IO (SymBV' sym (w + l))
bvConcat' NatRepr w
w
where bvConcat' :: forall l. (1 <= l)
=> NatRepr l
-> SymBV' sym w
-> SymBV' sym l
-> IO (SymBV' sym (w + l))
bvConcat' :: forall (l :: Nat).
(1 <= l) =>
NatRepr l
-> SymBV' sym w -> SymBV' sym l -> IO (SymBV' sym (w + l))
bvConcat' NatRepr l
_ (MkSymBV' SymExpr sym (BaseBVType w)
x) (MkSymBV' SymBV sym l
y) = SymBV sym (w + l) -> SymBV' sym (w + l)
forall sym (w :: Nat). SymBV sym w -> SymBV' sym w
MkSymBV' (SymBV sym (w + l) -> SymBV' sym (w + l))
-> IO (SymBV sym (w + l)) -> IO (SymBV' sym (w + l))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym
-> SymExpr sym (BaseBVType w)
-> SymBV sym l
-> IO (SymBV sym (w + l))
forall (u :: Nat) (v :: Nat).
(1 <= u, 1 <= v) =>
sym -> SymBV sym u -> SymBV sym v -> IO (SymBV sym (u + v))
forall sym (u :: Nat) (v :: Nat).
(IsExprBuilder sym, 1 <= u, 1 <= v) =>
sym -> SymBV sym u -> SymBV sym v -> IO (SymBV sym (u + v))
bvConcat sym
sym SymExpr sym (BaseBVType w)
x SymBV sym l
y
bvSplitVector :: forall sym n w. (IsExprBuilder sym, 1 <= w, 1 <= n)
=> sym
-> NatRepr n
-> NatRepr w
-> SymBV sym (n * w)
-> IO (Vector.Vector n (SymBV sym w))
bvSplitVector :: forall sym (n :: Nat) (w :: Nat).
(IsExprBuilder sym, 1 <= w, 1 <= n) =>
sym
-> NatRepr n
-> NatRepr w
-> SymBV sym (n * w)
-> IO (Vector n (SymBV sym w))
bvSplitVector sym
sym NatRepr n
n NatRepr w
w SymBV sym (n * w)
x =
IO (Vector n (SymBV' sym w))
-> IO (Vector n (SymExpr sym (BaseBVType w)))
forall a b. Coercible a b => a -> b
coerce (IO (Vector n (SymBV' sym w))
-> IO (Vector n (SymExpr sym (BaseBVType w))))
-> IO (Vector n (SymBV' sym w))
-> IO (Vector n (SymExpr sym (BaseBVType w)))
forall a b. (a -> b) -> a -> b
$ forall (f :: Type -> Type) (g :: Nat -> Type) (w :: Nat)
(n :: Nat).
(Applicative f, 1 <= w, 1 <= n) =>
Endian
-> (forall (i :: Nat).
((i + w) <= (n * w)) =>
NatRepr (n * w) -> NatRepr i -> g (n * w) -> f (g w))
-> NatRepr n
-> NatRepr w
-> g (n * w)
-> f (Vector n (g w))
Vector.splitWithA @IO Endian
BigEndian NatRepr (n * w)
-> NatRepr i -> SymBV' sym (n * w) -> IO (SymBV' sym w)
forall (i :: Nat).
((i + w) <= (n * w)) =>
NatRepr (n * w)
-> NatRepr i -> SymBV' sym (n * w) -> IO (SymBV' sym w)
bvSelect' NatRepr n
n NatRepr w
w (forall sym (w :: Nat). SymBV sym w -> SymBV' sym w
MkSymBV' @sym SymBV sym (n * w)
x)
where
bvSelect' :: forall i. (i + w <= n * w)
=> NatRepr (n * w)
-> NatRepr i
-> SymBV' sym (n * w)
-> IO (SymBV' sym w)
bvSelect' :: forall (i :: Nat).
((i + w) <= (n * w)) =>
NatRepr (n * w)
-> NatRepr i -> SymBV' sym (n * w) -> IO (SymBV' sym w)
bvSelect' NatRepr (n * w)
_ NatRepr i
i (MkSymBV' SymBV sym (n * w)
y) =
(SymExpr sym (BaseBVType w) -> SymBV' sym w)
-> IO (SymExpr sym (BaseBVType w)) -> IO (SymBV' sym w)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap SymExpr sym (BaseBVType w) -> SymBV' sym w
forall sym (w :: Nat). SymBV sym w -> SymBV' sym w
MkSymBV' (IO (SymExpr sym (BaseBVType w)) -> IO (SymBV' sym w))
-> IO (SymExpr sym (BaseBVType w)) -> IO (SymBV' sym w)
forall a b. (a -> b) -> a -> b
$ forall sym (idx :: Nat) (n :: Nat) (w :: Nat).
(IsExprBuilder sym, 1 <= n, (idx + n) <= w) =>
sym -> NatRepr idx -> NatRepr n -> SymBV sym w -> IO (SymBV sym n)
bvSelect @_ @i @w sym
sym NatRepr i
i NatRepr w
w SymBV sym (n * w)
y
bvSwap :: forall sym n. (1 <= n, IsExprBuilder sym)
=> sym
-> NatRepr n
-> SymBV sym (n*8)
-> IO (SymBV sym (n*8))
bvSwap :: forall sym (n :: Nat).
(1 <= n, IsExprBuilder sym) =>
sym -> NatRepr n -> SymBV sym (n * 8) -> IO (SymBV sym (n * 8))
bvSwap sym
sym NatRepr n
n SymBV sym (n * 8)
v = do
sym
-> NatRepr 8
-> Vector n (SymExpr sym (BaseBVType 8))
-> IO (SymBV sym (n * 8))
forall sym (n :: Nat) (w :: Nat).
(1 <= w, IsExprBuilder sym) =>
sym
-> NatRepr w -> Vector n (SymBV sym w) -> IO (SymBV sym (n * w))
bvJoinVector sym
sym (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @8) (Vector n (SymExpr sym (BaseBVType 8)) -> IO (SymBV sym (n * 8)))
-> (Vector n (SymExpr sym (BaseBVType 8))
-> Vector n (SymExpr sym (BaseBVType 8)))
-> Vector n (SymExpr sym (BaseBVType 8))
-> IO (SymBV sym (n * 8))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector n (SymExpr sym (BaseBVType 8))
-> Vector n (SymExpr sym (BaseBVType 8))
forall a (n :: Nat). (1 <= n) => Vector n a -> Vector n a
Vector.reverse
(Vector n (SymExpr sym (BaseBVType 8)) -> IO (SymBV sym (n * 8)))
-> IO (Vector n (SymExpr sym (BaseBVType 8)))
-> IO (SymBV sym (n * 8))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym
-> NatRepr n
-> NatRepr 8
-> SymBV sym (n * 8)
-> IO (Vector n (SymExpr sym (BaseBVType 8)))
forall sym (n :: Nat) (w :: Nat).
(IsExprBuilder sym, 1 <= w, 1 <= n) =>
sym
-> NatRepr n
-> NatRepr w
-> SymBV sym (n * w)
-> IO (Vector n (SymBV sym w))
bvSplitVector sym
sym NatRepr n
n (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @8) SymBV sym (n * 8)
v
bvBitreverse :: forall sym w.
(1 <= w, IsExprBuilder sym) =>
sym ->
SymBV sym w ->
IO (SymBV sym w)
bvBitreverse :: forall sym (w :: Nat).
(1 <= w, IsExprBuilder sym) =>
sym -> SymBV sym w -> IO (SymBV sym w)
bvBitreverse sym
sym SymBV sym w
v = do
sym
-> NatRepr 1
-> Vector w (SymExpr sym (BaseBVType 1))
-> IO (SymBV sym (w * 1))
forall sym (n :: Nat) (w :: Nat).
(1 <= w, IsExprBuilder sym) =>
sym
-> NatRepr w -> Vector n (SymBV sym w) -> IO (SymBV sym (n * w))
bvJoinVector sym
sym (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @1) (Vector w (SymExpr sym (BaseBVType 1)) -> IO (SymBV sym w))
-> (Vector w (SymExpr sym (BaseBVType 1))
-> Vector w (SymExpr sym (BaseBVType 1)))
-> Vector w (SymExpr sym (BaseBVType 1))
-> IO (SymBV sym w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector w (SymExpr sym (BaseBVType 1))
-> Vector w (SymExpr sym (BaseBVType 1))
forall a (n :: Nat). (1 <= n) => Vector n a -> Vector n a
Vector.reverse
(Vector w (SymExpr sym (BaseBVType 1)) -> IO (SymBV sym w))
-> IO (Vector w (SymExpr sym (BaseBVType 1))) -> IO (SymBV sym w)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym
-> NatRepr w
-> NatRepr 1
-> SymBV sym (w * 1)
-> IO (Vector w (SymExpr sym (BaseBVType 1)))
forall sym (n :: Nat) (w :: Nat).
(IsExprBuilder sym, 1 <= w, 1 <= n) =>
sym
-> NatRepr n
-> NatRepr w
-> SymBV sym (n * w)
-> IO (Vector n (SymBV sym w))
bvSplitVector sym
sym (SymBV sym w -> NatRepr w
forall (w :: Nat). SymExpr sym (BaseBVType w) -> NatRepr w
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> NatRepr w
bvWidth SymBV sym w
v) (forall (n :: Nat). KnownNat n => NatRepr n
knownNat @1) SymBV sym w
SymBV sym (w * 1)
v
indexLit :: IsExprBuilder sym => sym -> IndexLit idx -> IO (SymExpr sym idx)
indexLit :: forall sym (idx :: BaseType).
IsExprBuilder sym =>
sym -> IndexLit idx -> IO (SymExpr sym idx)
indexLit sym
sym (IntIndexLit Integer
i) = sym -> Integer -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> Integer -> IO (SymInteger sym)
intLit sym
sym Integer
i
indexLit sym
sym (BVIndexLit NatRepr w
w BV w
v) = sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w BV w
v
iteM :: IsExprBuilder sym =>
(sym -> Pred sym -> v -> v -> IO v) ->
sym -> Pred sym -> IO v -> IO v -> IO v
iteM :: forall sym v.
IsExprBuilder sym =>
(sym -> Pred sym -> v -> v -> IO v)
-> sym -> Pred sym -> IO v -> IO v -> IO v
iteM sym -> Pred sym -> v -> v -> IO v
ite sym
sym Pred sym
p IO v
mx IO v
my = do
case Pred sym -> Maybe Bool
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseBoolType -> Maybe Bool
asConstantPred Pred sym
p of
Just Bool
True -> IO v
mx
Just Bool
False -> IO v
my
Maybe Bool
Nothing -> IO (IO v) -> IO v
forall (m :: Type -> Type) a. Monad m => m (m a) -> m a
join (IO (IO v) -> IO v) -> IO (IO v) -> IO v
forall a b. (a -> b) -> a -> b
$ sym -> Pred sym -> v -> v -> IO v
ite sym
sym Pred sym
p (v -> v -> IO v) -> IO v -> IO (v -> IO v)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> IO v
mx IO (v -> IO v) -> IO v -> IO (IO v)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> IO v
my
iteList :: IsExprBuilder sym =>
(sym -> Pred sym -> v -> v -> IO v) ->
sym ->
[(IO (Pred sym), IO v)] ->
(IO v) ->
IO v
iteList :: forall sym v.
IsExprBuilder sym =>
(sym -> Pred sym -> v -> v -> IO v)
-> sym -> [(IO (Pred sym), IO v)] -> IO v -> IO v
iteList sym -> Pred sym -> v -> v -> IO v
_ite sym
_sym [] IO v
def = IO v
def
iteList sym -> Pred sym -> v -> v -> IO v
ite sym
sym ((IO (Pred sym)
mp,IO v
mx):[(IO (Pred sym), IO v)]
xs) IO v
def =
do p <- IO (Pred sym)
mp
iteM ite sym p mx (iteList ite sym xs def)
type family SymFn sym :: Ctx BaseType -> BaseType -> Type
data SomeSymFn sym = forall args ret . SomeSymFn (SymFn sym args ret)
instance IsSymFn (SymFn sym) => Eq (SomeSymFn sym) where
(SomeSymFn SymFn sym args ret
fn1) == :: SomeSymFn sym -> SomeSymFn sym -> Bool
== (SomeSymFn SymFn sym args ret
fn2) = Maybe ((args ::> ret) :~: (args ::> ret)) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe ((args ::> ret) :~: (args ::> ret)) -> Bool)
-> Maybe ((args ::> ret) :~: (args ::> ret)) -> Bool
forall a b. (a -> b) -> a -> b
$ SymFn sym args ret
-> SymFn sym args ret -> Maybe ((args ::> ret) :~: (args ::> ret))
forall (args1 :: Ctx BaseType) (ret1 :: BaseType)
(args2 :: Ctx BaseType) (ret2 :: BaseType).
SymFn sym args1 ret1
-> SymFn sym args2 ret2
-> Maybe ((args1 ::> ret1) :~: (args2 ::> ret2))
forall (fn :: Ctx BaseType -> BaseType -> Type)
(args1 :: Ctx BaseType) (ret1 :: BaseType) (args2 :: Ctx BaseType)
(ret2 :: BaseType).
IsSymFn fn =>
fn args1 ret1
-> fn args2 ret2 -> Maybe ((args1 ::> ret1) :~: (args2 ::> ret2))
fnTestEquality SymFn sym args ret
fn1 SymFn sym args ret
fn2
instance IsSymFn (SymFn sym) => Ord (SomeSymFn sym) where
compare :: SomeSymFn sym -> SomeSymFn sym -> Ordering
compare (SomeSymFn SymFn sym args ret
fn1) (SomeSymFn SymFn sym args ret
fn2) = OrderingF (args ::> ret) (args ::> ret) -> Ordering
forall {k} (x :: k) (y :: k). OrderingF x y -> Ordering
toOrdering (OrderingF (args ::> ret) (args ::> ret) -> Ordering)
-> OrderingF (args ::> ret) (args ::> ret) -> Ordering
forall a b. (a -> b) -> a -> b
$ SymFn sym args ret
-> SymFn sym args ret -> OrderingF (args ::> ret) (args ::> ret)
forall (args1 :: Ctx BaseType) (ret1 :: BaseType)
(args2 :: Ctx BaseType) (ret2 :: BaseType).
SymFn sym args1 ret1
-> SymFn sym args2 ret2
-> OrderingF (args1 ::> ret1) (args2 ::> ret2)
forall (fn :: Ctx BaseType -> BaseType -> Type)
(args1 :: Ctx BaseType) (ret1 :: BaseType) (args2 :: Ctx BaseType)
(ret2 :: BaseType).
IsSymFn fn =>
fn args1 ret1
-> fn args2 ret2 -> OrderingF (args1 ::> ret1) (args2 ::> ret2)
fnCompare SymFn sym args ret
fn1 SymFn sym args ret
fn2
data SymFnWrapper sym ctx where
SymFnWrapper :: forall sym args ret . SymFn sym args ret -> SymFnWrapper sym (args ::> ret)
instance IsSymFn (SymFn sym) => TestEquality (SymFnWrapper sym) where
testEquality :: forall (a :: Ctx BaseType) (b :: Ctx BaseType).
SymFnWrapper sym a -> SymFnWrapper sym b -> Maybe (a :~: b)
testEquality (SymFnWrapper SymFn sym args ret
fn1) (SymFnWrapper SymFn sym args ret
fn2) = SymFn sym args ret
-> SymFn sym args ret
-> Maybe ((args '::> ret) :~: (args '::> ret))
forall (args1 :: Ctx BaseType) (ret1 :: BaseType)
(args2 :: Ctx BaseType) (ret2 :: BaseType).
SymFn sym args1 ret1
-> SymFn sym args2 ret2
-> Maybe ((args1 ::> ret1) :~: (args2 ::> ret2))
forall (fn :: Ctx BaseType -> BaseType -> Type)
(args1 :: Ctx BaseType) (ret1 :: BaseType) (args2 :: Ctx BaseType)
(ret2 :: BaseType).
IsSymFn fn =>
fn args1 ret1
-> fn args2 ret2 -> Maybe ((args1 ::> ret1) :~: (args2 ::> ret2))
fnTestEquality SymFn sym args ret
fn1 SymFn sym args ret
fn2
instance IsSymFn (SymFn sym) => OrdF (SymFnWrapper sym) where
compareF :: forall (x :: Ctx BaseType) (y :: Ctx BaseType).
SymFnWrapper sym x -> SymFnWrapper sym y -> OrderingF x y
compareF (SymFnWrapper SymFn sym args ret
fn1) (SymFnWrapper SymFn sym args ret
fn2) = SymFn sym args ret
-> SymFn sym args ret -> OrderingF (args '::> ret) (args '::> ret)
forall (args1 :: Ctx BaseType) (ret1 :: BaseType)
(args2 :: Ctx BaseType) (ret2 :: BaseType).
SymFn sym args1 ret1
-> SymFn sym args2 ret2
-> OrderingF (args1 ::> ret1) (args2 ::> ret2)
forall (fn :: Ctx BaseType -> BaseType -> Type)
(args1 :: Ctx BaseType) (ret1 :: BaseType) (args2 :: Ctx BaseType)
(ret2 :: BaseType).
IsSymFn fn =>
fn args1 ret1
-> fn args2 ret2 -> OrderingF (args1 ::> ret1) (args2 ::> ret2)
fnCompare SymFn sym args ret
fn1 SymFn sym args ret
fn2
class IsSymFn (fn :: Ctx BaseType -> BaseType -> Type) where
fnArgTypes :: fn args ret -> Ctx.Assignment BaseTypeRepr args
fnReturnType :: fn args ret -> BaseTypeRepr ret
fnTestEquality :: fn args1 ret1 -> fn args2 ret2 -> Maybe ((args1 ::> ret1) :~: (args2 ::> ret2))
fnCompare :: fn args1 ret1 -> fn args2 ret2 -> OrderingF (args1 ::> ret1) (args2 ::> ret2)
data UnfoldPolicy
= NeverUnfold
| AlwaysUnfold
| UnfoldConcrete
deriving (UnfoldPolicy -> UnfoldPolicy -> Bool
(UnfoldPolicy -> UnfoldPolicy -> Bool)
-> (UnfoldPolicy -> UnfoldPolicy -> Bool) -> Eq UnfoldPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnfoldPolicy -> UnfoldPolicy -> Bool
== :: UnfoldPolicy -> UnfoldPolicy -> Bool
$c/= :: UnfoldPolicy -> UnfoldPolicy -> Bool
/= :: UnfoldPolicy -> UnfoldPolicy -> Bool
Eq, Eq UnfoldPolicy
Eq UnfoldPolicy =>
(UnfoldPolicy -> UnfoldPolicy -> Ordering)
-> (UnfoldPolicy -> UnfoldPolicy -> Bool)
-> (UnfoldPolicy -> UnfoldPolicy -> Bool)
-> (UnfoldPolicy -> UnfoldPolicy -> Bool)
-> (UnfoldPolicy -> UnfoldPolicy -> Bool)
-> (UnfoldPolicy -> UnfoldPolicy -> UnfoldPolicy)
-> (UnfoldPolicy -> UnfoldPolicy -> UnfoldPolicy)
-> Ord UnfoldPolicy
UnfoldPolicy -> UnfoldPolicy -> Bool
UnfoldPolicy -> UnfoldPolicy -> Ordering
UnfoldPolicy -> UnfoldPolicy -> UnfoldPolicy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UnfoldPolicy -> UnfoldPolicy -> Ordering
compare :: UnfoldPolicy -> UnfoldPolicy -> Ordering
$c< :: UnfoldPolicy -> UnfoldPolicy -> Bool
< :: UnfoldPolicy -> UnfoldPolicy -> Bool
$c<= :: UnfoldPolicy -> UnfoldPolicy -> Bool
<= :: UnfoldPolicy -> UnfoldPolicy -> Bool
$c> :: UnfoldPolicy -> UnfoldPolicy -> Bool
> :: UnfoldPolicy -> UnfoldPolicy -> Bool
$c>= :: UnfoldPolicy -> UnfoldPolicy -> Bool
>= :: UnfoldPolicy -> UnfoldPolicy -> Bool
$cmax :: UnfoldPolicy -> UnfoldPolicy -> UnfoldPolicy
max :: UnfoldPolicy -> UnfoldPolicy -> UnfoldPolicy
$cmin :: UnfoldPolicy -> UnfoldPolicy -> UnfoldPolicy
min :: UnfoldPolicy -> UnfoldPolicy -> UnfoldPolicy
Ord, Int -> UnfoldPolicy -> ShowS
[UnfoldPolicy] -> ShowS
UnfoldPolicy -> String
(Int -> UnfoldPolicy -> ShowS)
-> (UnfoldPolicy -> String)
-> ([UnfoldPolicy] -> ShowS)
-> Show UnfoldPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnfoldPolicy -> ShowS
showsPrec :: Int -> UnfoldPolicy -> ShowS
$cshow :: UnfoldPolicy -> String
show :: UnfoldPolicy -> String
$cshowList :: [UnfoldPolicy] -> ShowS
showList :: [UnfoldPolicy] -> ShowS
Show)
shouldUnfold :: IsExpr e => UnfoldPolicy -> Ctx.Assignment e args -> Bool
shouldUnfold :: forall (e :: BaseType -> Type) (args :: Ctx BaseType).
IsExpr e =>
UnfoldPolicy -> Assignment e args -> Bool
shouldUnfold UnfoldPolicy
AlwaysUnfold Assignment e args
_ = Bool
True
shouldUnfold UnfoldPolicy
NeverUnfold Assignment e args
_ = Bool
False
shouldUnfold UnfoldPolicy
UnfoldConcrete Assignment e args
args = (forall (x :: BaseType). e x -> Bool)
-> forall (x :: Ctx BaseType). Assignment e x -> Bool
forall {k} {l} (t :: (k -> Type) -> l -> Type) (f :: k -> Type).
FoldableFC t =>
(forall (x :: k). f x -> Bool) -> forall (x :: l). t f x -> Bool
allFC e x -> Bool
forall (x :: BaseType). e x -> Bool
forall (e :: BaseType -> Type) (bt :: BaseType).
IsExpr e =>
e bt -> Bool
baseIsConcrete Assignment e args
args
data InvalidRange where
InvalidRange ::
BaseTypeRepr bt ->
Maybe (ConcreteValue bt) ->
Maybe (ConcreteValue bt) ->
InvalidRange
instance Exception InvalidRange
instance Show InvalidRange where
show :: InvalidRange -> String
show (InvalidRange BaseTypeRepr bt
bt Maybe (ConcreteValue bt)
mlo Maybe (ConcreteValue bt)
mhi) =
case BaseTypeRepr bt
bt of
BaseTypeRepr bt
BaseIntegerRepr -> [String] -> String
unwords [String
"invalid integer range", Maybe Integer -> String
forall a. Show a => a -> String
show Maybe Integer
Maybe (ConcreteValue bt)
mlo, Maybe Integer -> String
forall a. Show a => a -> String
show Maybe Integer
Maybe (ConcreteValue bt)
mhi]
BaseTypeRepr bt
BaseRealRepr -> [String] -> String
unwords [String
"invalid real range", Maybe Rational -> String
forall a. Show a => a -> String
show Maybe Rational
Maybe (ConcreteValue bt)
mlo, Maybe Rational -> String
forall a. Show a => a -> String
show Maybe Rational
Maybe (ConcreteValue bt)
mhi]
BaseBVRepr NatRepr w
w -> [String] -> String
unwords [String
"invalid bitvector range", NatRepr w -> String
forall a. Show a => a -> String
show NatRepr w
w String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"-bit", Maybe Integer -> String
forall a. Show a => a -> String
show Maybe Integer
Maybe (ConcreteValue bt)
mlo, Maybe Integer -> String
forall a. Show a => a -> String
show Maybe Integer
Maybe (ConcreteValue bt)
mhi]
BaseTypeRepr bt
_ -> [String] -> String
unwords [String
"invalid range for type", BaseTypeRepr bt -> String
forall a. Show a => a -> String
show BaseTypeRepr bt
bt]
class ( IsExprBuilder sym
, IsSymFn (SymFn sym)
, OrdF (SymExpr sym)
, OrdF (BoundVar sym)
) => IsSymExprBuilder sym where
freshConstant :: sym -> SolverSymbol -> BaseTypeRepr tp -> IO (SymExpr sym tp)
freshLatch :: sym -> SolverSymbol -> BaseTypeRepr tp -> IO (SymExpr sym tp)
freshBoundedBV :: (1 <= w) =>
sym ->
SolverSymbol ->
NatRepr w ->
Maybe Natural ->
Maybe Natural ->
IO (SymBV sym w)
freshBoundedSBV :: (1 <= w) =>
sym ->
SolverSymbol ->
NatRepr w ->
Maybe Integer ->
Maybe Integer ->
IO (SymBV sym w)
freshBoundedInt ::
sym ->
SolverSymbol ->
Maybe Integer ->
Maybe Integer ->
IO (SymInteger sym)
freshBoundedReal ::
sym ->
SolverSymbol ->
Maybe Rational ->
Maybe Rational ->
IO (SymReal sym)
exprUninterpConstants :: sym -> SymExpr sym tp -> Set (Some (BoundVar sym))
freshBoundVar :: sym -> SolverSymbol -> BaseTypeRepr tp -> IO (BoundVar sym tp)
varExpr :: sym -> BoundVar sym tp -> SymExpr sym tp
forallPred :: sym
-> BoundVar sym tp
-> Pred sym
-> IO (Pred sym)
existsPred :: sym
-> BoundVar sym tp
-> Pred sym
-> IO (Pred sym)
definedFn :: sym
-> SolverSymbol
-> Ctx.Assignment (BoundVar sym) args
-> SymExpr sym ret
-> UnfoldPolicy
-> IO (SymFn sym args ret)
inlineDefineFun :: Ctx.CurryAssignmentClass args
=> sym
-> SolverSymbol
-> Ctx.Assignment BaseTypeRepr args
-> UnfoldPolicy
-> Ctx.CurryAssignment args (SymExpr sym) (IO (SymExpr sym ret))
-> IO (SymFn sym args ret)
inlineDefineFun sym
sym SolverSymbol
nm Assignment BaseTypeRepr args
tps UnfoldPolicy
policy CurryAssignment args (SymExpr sym) (IO (SymExpr sym ret))
f = do
vars <- (forall (x :: BaseType). BaseTypeRepr x -> IO (BoundVar sym x))
-> forall (x :: Ctx BaseType).
Assignment BaseTypeRepr x -> IO (Assignment (BoundVar sym) x)
forall k l (t :: (k -> Type) -> l -> Type) (f :: k -> Type)
(g :: k -> Type) (m :: Type -> Type).
(TraversableFC t, Applicative m) =>
(forall (x :: k). f x -> m (g x))
-> forall (x :: l). t f x -> m (t g x)
forall (f :: BaseType -> Type) (g :: BaseType -> Type)
(m :: Type -> Type).
Applicative m =>
(forall (x :: BaseType). f x -> m (g x))
-> forall (x :: Ctx BaseType). Assignment f x -> m (Assignment g x)
traverseFC (sym -> SolverSymbol -> BaseTypeRepr x -> IO (BoundVar sym x)
forall sym (tp :: BaseType).
IsSymExprBuilder sym =>
sym -> SolverSymbol -> BaseTypeRepr tp -> IO (BoundVar sym tp)
forall (tp :: BaseType).
sym -> SolverSymbol -> BaseTypeRepr tp -> IO (BoundVar sym tp)
freshBoundVar sym
sym SolverSymbol
emptySymbol) Assignment BaseTypeRepr args
tps
r <- Ctx.uncurryAssignment f (fmapFC (varExpr sym) vars)
definedFn sym nm vars r policy
freshTotalUninterpFn :: forall args ret
. sym
-> SolverSymbol
-> Ctx.Assignment BaseTypeRepr args
-> BaseTypeRepr ret
-> IO (SymFn sym args ret)
applySymFn :: sym
-> SymFn sym args ret
-> Ctx.Assignment (SymExpr sym) args
-> IO (SymExpr sym ret)
substituteBoundVars ::
sym ->
MapF (BoundVar sym) (SymExpr sym) ->
SymExpr sym tp ->
IO (SymExpr sym tp)
substituteSymFns ::
sym ->
MapF (SymFnWrapper sym) (SymFnWrapper sym) ->
SymExpr sym tp ->
IO (SymExpr sym tp)
transformPredBV2LIA :: sym -> [Pred sym] -> IO ([Pred sym], Map (SomeSymFn sym) (SomeSymFn sym))
transformSymFnLIA2BV :: sym -> SomeSymFn sym -> IO (SomeSymFn sym)
baseIsConcrete :: forall e bt
. IsExpr e
=> e bt
-> Bool
baseIsConcrete :: forall (e :: BaseType -> Type) (bt :: BaseType).
IsExpr e =>
e bt -> Bool
baseIsConcrete e bt
x =
case e bt -> BaseTypeRepr bt
forall (tp :: BaseType). e tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType e bt
x of
BaseTypeRepr bt
BaseBoolRepr -> Maybe Bool -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Bool -> Bool) -> Maybe Bool -> Bool
forall a b. (a -> b) -> a -> b
$ e BaseBoolType -> Maybe Bool
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseBoolType -> Maybe Bool
asConstantPred e bt
e BaseBoolType
x
BaseTypeRepr bt
BaseIntegerRepr -> Maybe Integer -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Integer -> Bool) -> Maybe Integer -> Bool
forall a b. (a -> b) -> a -> b
$ e BaseIntegerType -> Maybe Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> Maybe Integer
asInteger e bt
e BaseIntegerType
x
BaseBVRepr NatRepr w
_ -> Maybe (BV w) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (BV w) -> Bool) -> Maybe (BV w) -> Bool
forall a b. (a -> b) -> a -> b
$ e ('BaseBVType w) -> Maybe (BV w)
forall (w :: Nat). e (BaseBVType w) -> Maybe (BV w)
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> Maybe (BV w)
asBV e bt
e ('BaseBVType w)
x
BaseTypeRepr bt
BaseRealRepr -> Maybe Rational -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Rational -> Bool) -> Maybe Rational -> Bool
forall a b. (a -> b) -> a -> b
$ e BaseRealType -> Maybe Rational
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseRealType -> Maybe Rational
asRational e bt
e BaseRealType
x
BaseFloatRepr FloatPrecisionRepr fpp
_ -> Bool
False
BaseStringRepr{} -> Maybe (StringLiteral si) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (StringLiteral si) -> Bool)
-> Maybe (StringLiteral si) -> Bool
forall a b. (a -> b) -> a -> b
$ e ('BaseStringType si) -> Maybe (StringLiteral si)
forall (si :: StringInfo).
e (BaseStringType si) -> Maybe (StringLiteral si)
forall (e :: BaseType -> Type) (si :: StringInfo).
IsExpr e =>
e (BaseStringType si) -> Maybe (StringLiteral si)
asString e bt
e ('BaseStringType si)
x
BaseTypeRepr bt
BaseComplexRepr -> Maybe (Complex Rational) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (Complex Rational) -> Bool)
-> Maybe (Complex Rational) -> Bool
forall a b. (a -> b) -> a -> b
$ e BaseComplexType -> Maybe (Complex Rational)
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseComplexType -> Maybe (Complex Rational)
asComplex e bt
e BaseComplexType
x
BaseStructRepr Assignment BaseTypeRepr ctx
_ -> case e ('BaseStructType ctx) -> Maybe (Assignment e ctx)
forall (flds :: Ctx BaseType).
e (BaseStructType flds) -> Maybe (Assignment e flds)
forall (e :: BaseType -> Type) (flds :: Ctx BaseType).
IsExpr e =>
e (BaseStructType flds) -> Maybe (Assignment e flds)
asStruct e bt
e ('BaseStructType ctx)
x of
Just Assignment e ctx
flds -> (forall (x :: BaseType). e x -> Bool)
-> forall (x :: Ctx BaseType). Assignment e x -> Bool
forall {k} {l} (t :: (k -> Type) -> l -> Type) (f :: k -> Type).
FoldableFC t =>
(forall (x :: k). f x -> Bool) -> forall (x :: l). t f x -> Bool
allFC e x -> Bool
forall (x :: BaseType). e x -> Bool
forall (e :: BaseType -> Type) (bt :: BaseType).
IsExpr e =>
e bt -> Bool
baseIsConcrete Assignment e ctx
flds
Maybe (Assignment e ctx)
Nothing -> Bool
False
BaseArrayRepr Assignment BaseTypeRepr (idx ::> tp)
_ BaseTypeRepr xs
_bt' -> do
case e ('BaseArrayType (idx ::> tp) xs) -> Maybe (e xs)
forall (idx :: Ctx BaseType) (bt :: BaseType).
e (BaseArrayType idx bt) -> Maybe (e bt)
forall (e :: BaseType -> Type) (idx :: Ctx BaseType)
(bt :: BaseType).
IsExpr e =>
e (BaseArrayType idx bt) -> Maybe (e bt)
asConstantArray e bt
e ('BaseArrayType (idx ::> tp) xs)
x of
Just e xs
x' -> e xs -> Bool
forall (e :: BaseType -> Type) (bt :: BaseType).
IsExpr e =>
e bt -> Bool
baseIsConcrete e xs
x'
Maybe (e xs)
Nothing -> Bool
False
baseDefaultValue :: forall sym bt
. IsExprBuilder sym
=> sym
-> BaseTypeRepr bt
-> IO (SymExpr sym bt)
baseDefaultValue :: forall sym (bt :: BaseType).
IsExprBuilder sym =>
sym -> BaseTypeRepr bt -> IO (SymExpr sym bt)
baseDefaultValue sym
sym BaseTypeRepr bt
bt =
case BaseTypeRepr bt
bt of
BaseTypeRepr bt
BaseBoolRepr -> SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType))
-> SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)
forall a b. (a -> b) -> a -> b
$! sym -> SymExpr sym BaseBoolType
forall sym. IsExprBuilder sym => sym -> Pred sym
falsePred sym
sym
BaseTypeRepr bt
BaseIntegerRepr -> sym -> Integer -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> Integer -> IO (SymInteger sym)
intLit sym
sym Integer
0
BaseBVRepr NatRepr w
w -> sym -> NatRepr w -> IO (SymBV sym w)
forall (w :: Nat) sym.
(1 <= w, IsExprBuilder sym) =>
sym -> NatRepr w -> IO (SymBV sym w)
bvZero sym
sym NatRepr w
w
BaseTypeRepr bt
BaseRealRepr -> SymExpr sym BaseRealType -> IO (SymExpr sym BaseRealType)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (SymExpr sym BaseRealType -> IO (SymExpr sym BaseRealType))
-> SymExpr sym BaseRealType -> IO (SymExpr sym BaseRealType)
forall a b. (a -> b) -> a -> b
$! sym -> SymExpr sym BaseRealType
forall sym. IsExprBuilder sym => sym -> SymReal sym
realZero sym
sym
BaseFloatRepr FloatPrecisionRepr fpp
fpp -> sym -> FloatPrecisionRepr fpp -> IO (SymFloat sym fpp)
forall sym (fpp :: FloatPrecision).
IsExprBuilder sym =>
sym -> FloatPrecisionRepr fpp -> IO (SymFloat sym fpp)
forall (fpp :: FloatPrecision).
sym -> FloatPrecisionRepr fpp -> IO (SymFloat sym fpp)
floatPZero sym
sym FloatPrecisionRepr fpp
fpp
BaseTypeRepr bt
BaseComplexRepr -> sym -> Complex Rational -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex Rational -> IO (SymCplx sym)
mkComplexLit sym
sym (Rational
0 Rational -> Rational -> Complex Rational
forall a. a -> a -> Complex a
:+ Rational
0)
BaseStringRepr StringInfoRepr si
si -> sym -> StringInfoRepr si -> IO (SymString sym si)
forall sym (si :: StringInfo).
IsExprBuilder sym =>
sym -> StringInfoRepr si -> IO (SymString sym si)
forall (si :: StringInfo).
sym -> StringInfoRepr si -> IO (SymString sym si)
stringEmpty sym
sym StringInfoRepr si
si
BaseStructRepr Assignment BaseTypeRepr ctx
flds -> do
let f :: BaseTypeRepr tp -> IO (SymExpr sym tp)
f :: forall (tp :: BaseType). BaseTypeRepr tp -> IO (SymExpr sym tp)
f BaseTypeRepr tp
v = sym -> BaseTypeRepr tp -> IO (SymExpr sym tp)
forall sym (bt :: BaseType).
IsExprBuilder sym =>
sym -> BaseTypeRepr bt -> IO (SymExpr sym bt)
baseDefaultValue sym
sym BaseTypeRepr tp
v
sym
-> Assignment (SymExpr sym) ctx
-> IO (SymExpr sym ('BaseStructType ctx))
forall sym (flds :: Ctx BaseType).
IsExprBuilder sym =>
sym -> Assignment (SymExpr sym) flds -> IO (SymStruct sym flds)
forall (flds :: Ctx BaseType).
sym -> Assignment (SymExpr sym) flds -> IO (SymStruct sym flds)
mkStruct sym
sym (Assignment (SymExpr sym) ctx
-> IO (SymExpr sym ('BaseStructType ctx)))
-> IO (Assignment (SymExpr sym) ctx)
-> IO (SymExpr sym ('BaseStructType ctx))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall (tp :: BaseType). BaseTypeRepr tp -> IO (SymExpr sym tp))
-> forall (x :: Ctx BaseType).
Assignment BaseTypeRepr x -> IO (Assignment (SymExpr sym) x)
forall k l (t :: (k -> Type) -> l -> Type) (f :: k -> Type)
(g :: k -> Type) (m :: Type -> Type).
(TraversableFC t, Applicative m) =>
(forall (x :: k). f x -> m (g x))
-> forall (x :: l). t f x -> m (t g x)
forall (f :: BaseType -> Type) (g :: BaseType -> Type)
(m :: Type -> Type).
Applicative m =>
(forall (x :: BaseType). f x -> m (g x))
-> forall (x :: Ctx BaseType). Assignment f x -> m (Assignment g x)
traverseFC BaseTypeRepr x -> IO (SymExpr sym x)
forall (tp :: BaseType). BaseTypeRepr tp -> IO (SymExpr sym tp)
f Assignment BaseTypeRepr ctx
flds
BaseArrayRepr Assignment BaseTypeRepr (idx ::> tp)
idx BaseTypeRepr xs
bt' -> do
elt <- sym -> BaseTypeRepr xs -> IO (SymExpr sym xs)
forall sym (bt :: BaseType).
IsExprBuilder sym =>
sym -> BaseTypeRepr bt -> IO (SymExpr sym bt)
baseDefaultValue sym
sym BaseTypeRepr xs
bt'
constantArray sym idx elt
backendPred :: IsExprBuilder sym => sym -> Bool -> Pred sym
backendPred :: forall sym. IsExprBuilder sym => sym -> Bool -> Pred sym
backendPred sym
sym Bool
True = sym -> Pred sym
forall sym. IsExprBuilder sym => sym -> Pred sym
truePred sym
sym
backendPred sym
sym Bool
False = sym -> Pred sym
forall sym. IsExprBuilder sym => sym -> Pred sym
falsePred sym
sym
mkRational :: IsExprBuilder sym => sym -> Rational -> IO (SymCplx sym)
mkRational :: forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymCplx sym)
mkRational sym
sym Rational
v = sym -> Complex Rational -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex Rational -> IO (SymCplx sym)
mkComplexLit sym
sym (Rational
v Rational -> Rational -> Complex Rational
forall a. a -> a -> Complex a
:+ Rational
0)
mkReal :: (IsExprBuilder sym, Real a) => sym -> a -> IO (SymCplx sym)
mkReal :: forall sym a.
(IsExprBuilder sym, Real a) =>
sym -> a -> IO (SymCplx sym)
mkReal sym
sym a
v = sym -> Rational -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymCplx sym)
mkRational sym
sym (a -> Rational
forall a. Real a => a -> Rational
toRational a
v)
predToReal :: IsExprBuilder sym => sym -> Pred sym -> IO (SymReal sym)
predToReal :: forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> IO (SymReal sym)
predToReal sym
sym Pred sym
p = do
r1 <- sym -> Rational -> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymReal sym)
realLit sym
sym Rational
1
realIte sym p r1 (realZero sym)
realExprAsRational :: (MonadFail m, IsExpr e) => e BaseRealType -> m Rational
realExprAsRational :: forall (m :: Type -> Type) (e :: BaseType -> Type).
(MonadFail m, IsExpr e) =>
e BaseRealType -> m Rational
realExprAsRational e BaseRealType
x = do
case e BaseRealType -> Maybe Rational
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseRealType -> Maybe Rational
asRational e BaseRealType
x of
Just Rational
r -> Rational -> m Rational
forall a. a -> m a
forall (m :: Type -> Type) a. Monad m => a -> m a
return Rational
r
Maybe Rational
Nothing -> String -> m Rational
forall a. String -> m a
forall (m :: Type -> Type) a. MonadFail m => String -> m a
fail String
"Value is not a constant expression."
cplxExprAsRational :: (MonadFail m, IsExpr e) => e BaseComplexType -> m Rational
cplxExprAsRational :: forall (m :: Type -> Type) (e :: BaseType -> Type).
(MonadFail m, IsExpr e) =>
e BaseComplexType -> m Rational
cplxExprAsRational e BaseComplexType
x = do
case e BaseComplexType -> Maybe (Complex Rational)
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseComplexType -> Maybe (Complex Rational)
asComplex e BaseComplexType
x of
Just (Rational
r :+ Rational
i) -> do
Bool -> m () -> m ()
forall (f :: Type -> Type). Applicative f => Bool -> f () -> f ()
when (Rational
i Rational -> Rational -> Bool
forall a. Eq a => a -> a -> Bool
/= Rational
0) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
String -> m ()
forall a. String -> m a
forall (m :: Type -> Type) a. MonadFail m => String -> m a
fail String
"Complex value has an imaginary part."
Rational -> m Rational
forall a. a -> m a
forall (m :: Type -> Type) a. Monad m => a -> m a
return Rational
r
Maybe (Complex Rational)
Nothing -> do
String -> m Rational
forall a. String -> m a
forall (m :: Type -> Type) a. MonadFail m => String -> m a
fail String
"Complex value is not a constant expression."
cplxExprAsInteger :: (MonadFail m, IsExpr e) => e BaseComplexType -> m Integer
cplxExprAsInteger :: forall (m :: Type -> Type) (e :: BaseType -> Type).
(MonadFail m, IsExpr e) =>
e BaseComplexType -> m Integer
cplxExprAsInteger e BaseComplexType
x = Rational -> m Integer
forall (m :: Type -> Type). MonadFail m => Rational -> m Integer
rationalAsInteger (Rational -> m Integer) -> m Rational -> m Integer
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< e BaseComplexType -> m Rational
forall (m :: Type -> Type) (e :: BaseType -> Type).
(MonadFail m, IsExpr e) =>
e BaseComplexType -> m Rational
cplxExprAsRational e BaseComplexType
x
rationalAsInteger :: MonadFail m => Rational -> m Integer
rationalAsInteger :: forall (m :: Type -> Type). MonadFail m => Rational -> m Integer
rationalAsInteger Rational
r = do
Bool -> m () -> m ()
forall (f :: Type -> Type). Applicative f => Bool -> f () -> f ()
when (Rational -> Integer
forall a. Ratio a -> a
denominator Rational
r Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
/= Integer
1) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
String -> m ()
forall a. String -> m a
forall (m :: Type -> Type) a. MonadFail m => String -> m a
fail String
"Value is not an integer."
Integer -> m Integer
forall a. a -> m a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (Rational -> Integer
forall a. Ratio a -> a
numerator Rational
r)
realExprAsInteger :: (IsExpr e, MonadFail m) => e BaseRealType -> m Integer
realExprAsInteger :: forall (e :: BaseType -> Type) (m :: Type -> Type).
(IsExpr e, MonadFail m) =>
e BaseRealType -> m Integer
realExprAsInteger e BaseRealType
x =
Rational -> m Integer
forall (m :: Type -> Type). MonadFail m => Rational -> m Integer
rationalAsInteger (Rational -> m Integer) -> m Rational -> m Integer
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< e BaseRealType -> m Rational
forall (m :: Type -> Type) (e :: BaseType -> Type).
(MonadFail m, IsExpr e) =>
e BaseRealType -> m Rational
realExprAsRational e BaseRealType
x
andAllOf :: IsExprBuilder sym
=> sym
-> Fold s (Pred sym)
-> s
-> IO (Pred sym)
andAllOf :: forall sym s.
IsExprBuilder sym =>
sym -> Fold s (Pred sym) -> s -> IO (Pred sym)
andAllOf sym
sym Fold s (SymExpr sym BaseBoolType)
f s
s = Getting
(Endo (SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)))
s
(SymExpr sym BaseBoolType)
-> (SymExpr sym BaseBoolType
-> SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType))
-> SymExpr sym BaseBoolType
-> s
-> IO (SymExpr sym BaseBoolType)
forall (m :: Type -> Type) r s a.
Monad m =>
Getting (Endo (r -> m r)) s a -> (r -> a -> m r) -> r -> s -> m r
foldlMOf Getting
(Endo (SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)))
s
(SymExpr sym BaseBoolType)
Fold s (SymExpr sym BaseBoolType)
f (sym
-> SymExpr sym BaseBoolType
-> SymExpr sym BaseBoolType
-> IO (SymExpr sym BaseBoolType)
forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> Pred sym -> IO (Pred sym)
andPred sym
sym) (sym -> SymExpr sym BaseBoolType
forall sym. IsExprBuilder sym => sym -> Pred sym
truePred sym
sym) s
s
orOneOf :: IsExprBuilder sym
=> sym
-> Fold s (Pred sym)
-> s
-> IO (Pred sym)
orOneOf :: forall sym s.
IsExprBuilder sym =>
sym -> Fold s (Pred sym) -> s -> IO (Pred sym)
orOneOf sym
sym Fold s (SymExpr sym BaseBoolType)
f s
s = Getting
(Endo (SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)))
s
(SymExpr sym BaseBoolType)
-> (SymExpr sym BaseBoolType
-> SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType))
-> SymExpr sym BaseBoolType
-> s
-> IO (SymExpr sym BaseBoolType)
forall (m :: Type -> Type) r s a.
Monad m =>
Getting (Endo (r -> m r)) s a -> (r -> a -> m r) -> r -> s -> m r
foldlMOf Getting
(Endo (SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)))
s
(SymExpr sym BaseBoolType)
Fold s (SymExpr sym BaseBoolType)
f (sym
-> SymExpr sym BaseBoolType
-> SymExpr sym BaseBoolType
-> IO (SymExpr sym BaseBoolType)
forall sym.
IsExprBuilder sym =>
sym -> Pred sym -> Pred sym -> IO (Pred sym)
orPred sym
sym) (sym -> SymExpr sym BaseBoolType
forall sym. IsExprBuilder sym => sym -> Pred sym
falsePred sym
sym) s
s
isNonZero :: IsExprBuilder sym => sym -> SymCplx sym -> IO (Pred sym)
isNonZero :: forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Pred sym)
isNonZero sym
sym SymCplx sym
v = sym -> SymCplx sym -> SymCplx sym -> IO (SymExpr sym BaseBoolType)
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> SymCplx sym -> IO (Pred sym)
cplxNe sym
sym SymCplx sym
v (SymCplx sym -> IO (SymExpr sym BaseBoolType))
-> IO (SymCplx sym) -> IO (SymExpr sym BaseBoolType)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> Rational -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymCplx sym)
mkRational sym
sym Rational
0
isReal :: IsExprBuilder sym => sym -> SymCplx sym -> IO (Pred sym)
isReal :: forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Pred sym)
isReal sym
sym SymCplx sym
v = do
i <- sym -> SymCplx sym -> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (SymReal sym)
getImagPart sym
sym SymCplx sym
v
realEq sym i (realZero sym)
cplxDiv :: IsExprBuilder sym
=> sym
-> SymCplx sym
-> SymCplx sym
-> IO (SymCplx sym)
cplxDiv :: forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> SymCplx sym -> IO (SymCplx sym)
cplxDiv sym
sym SymCplx sym
x SymCplx sym
y = do
xr :+ xi <- sym -> SymCplx sym -> IO (Complex (SymExpr sym BaseRealType))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
yc@(yr :+ yi) <- cplxGetParts sym y
case asRational <$> yc of
(Maybe Rational
_ :+ Just Rational
0) -> do
zc <- SymExpr sym BaseRealType
-> SymExpr sym BaseRealType -> Complex (SymExpr sym BaseRealType)
forall a. a -> a -> Complex a
(:+) (SymExpr sym BaseRealType
-> SymExpr sym BaseRealType -> Complex (SymExpr sym BaseRealType))
-> IO (SymExpr sym BaseRealType)
-> IO
(SymExpr sym BaseRealType -> Complex (SymExpr sym BaseRealType))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym
-> SymExpr sym BaseRealType
-> SymExpr sym BaseRealType
-> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realDiv sym
sym SymExpr sym BaseRealType
xr SymExpr sym BaseRealType
yr IO (SymExpr sym BaseRealType -> Complex (SymExpr sym BaseRealType))
-> IO (SymExpr sym BaseRealType)
-> IO (Complex (SymExpr sym BaseRealType))
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> sym
-> SymExpr sym BaseRealType
-> SymExpr sym BaseRealType
-> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realDiv sym
sym SymExpr sym BaseRealType
xi SymExpr sym BaseRealType
yr
mkComplex sym zc
(Just Rational
0 :+ Maybe Rational
_) -> do
zc <- SymExpr sym BaseRealType
-> SymExpr sym BaseRealType -> Complex (SymExpr sym BaseRealType)
forall a. a -> a -> Complex a
(:+) (SymExpr sym BaseRealType
-> SymExpr sym BaseRealType -> Complex (SymExpr sym BaseRealType))
-> IO (SymExpr sym BaseRealType)
-> IO
(SymExpr sym BaseRealType -> Complex (SymExpr sym BaseRealType))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> sym
-> SymExpr sym BaseRealType
-> SymExpr sym BaseRealType
-> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realDiv sym
sym SymExpr sym BaseRealType
xi SymExpr sym BaseRealType
yi IO (SymExpr sym BaseRealType -> Complex (SymExpr sym BaseRealType))
-> IO (SymExpr sym BaseRealType)
-> IO (Complex (SymExpr sym BaseRealType))
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> sym
-> SymExpr sym BaseRealType
-> SymExpr sym BaseRealType
-> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realDiv sym
sym SymExpr sym BaseRealType
xr SymExpr sym BaseRealType
yi
mkComplex sym zc
Complex (Maybe Rational)
_ -> do
yr_abs <- sym
-> SymExpr sym BaseRealType
-> SymExpr sym BaseRealType
-> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realMul sym
sym SymExpr sym BaseRealType
yr SymExpr sym BaseRealType
yr
yi_abs <- realMul sym yi yi
y_abs <- realAdd sym yr_abs yi_abs
zr_1 <- realMul sym xr yr
zr_2 <- realMul sym xi yi
zr <- realAdd sym zr_1 zr_2
zi_1 <- realMul sym xi yr
zi_2 <- realMul sym xr yi
zi <- realSub sym zi_1 zi_2
zc <- (:+) <$> realDiv sym zr y_abs <*> realDiv sym zi y_abs
mkComplex sym zc
cplxLog' :: IsExprBuilder sym
=> sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxLog' :: forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxLog' sym
sym SymCplx sym
x = do
xr :+ xi <- sym -> SymCplx sym -> IO (Complex (SymExpr sym BaseRealType))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxGetParts sym
sym SymCplx sym
x
xm <- realHypot sym xr xi
xa <- realAtan2 sym xi xr
zr <- realLog sym xm
return $! zr :+ xa
cplxLog :: IsExprBuilder sym
=> sym -> SymCplx sym -> IO (SymCplx sym)
cplxLog :: forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (SymCplx sym)
cplxLog sym
sym SymCplx sym
x = sym -> Complex (SymExpr sym BaseRealType) -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex (SymReal sym) -> IO (SymCplx sym)
mkComplex sym
sym (Complex (SymExpr sym BaseRealType) -> IO (SymCplx sym))
-> IO (Complex (SymExpr sym BaseRealType)) -> IO (SymCplx sym)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> SymCplx sym -> IO (Complex (SymExpr sym BaseRealType))
forall sym.
IsExprBuilder sym =>
sym -> SymCplx sym -> IO (Complex (SymReal sym))
cplxLog' sym
sym SymCplx sym
x
cplxLogBase :: IsExprBuilder sym
=> Rational
-> sym
-> SymCplx sym
-> IO (SymCplx sym)
cplxLogBase :: forall sym.
IsExprBuilder sym =>
Rational -> sym -> SymCplx sym -> IO (SymCplx sym)
cplxLogBase Rational
base sym
sym SymCplx sym
x = do
b <- sym -> SymExpr sym BaseRealType -> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> IO (SymReal sym)
realLog sym
sym (SymExpr sym BaseRealType -> IO (SymExpr sym BaseRealType))
-> IO (SymExpr sym BaseRealType) -> IO (SymExpr sym BaseRealType)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> Rational -> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymReal sym)
realLit sym
sym Rational
base
z <- traverse (\SymExpr sym BaseRealType
r -> sym
-> SymExpr sym BaseRealType
-> SymExpr sym BaseRealType
-> IO (SymExpr sym BaseRealType)
forall sym.
IsExprBuilder sym =>
sym -> SymReal sym -> SymReal sym -> IO (SymReal sym)
realDiv sym
sym SymExpr sym BaseRealType
r SymExpr sym BaseRealType
b) =<< cplxLog' sym x
mkComplex sym z
asConcrete :: IsExpr e => e tp -> Maybe (ConcreteVal tp)
asConcrete :: forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> Maybe (ConcreteVal tp)
asConcrete e tp
x =
case e tp -> BaseTypeRepr tp
forall (tp :: BaseType). e tp -> BaseTypeRepr tp
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> BaseTypeRepr tp
exprType e tp
x of
BaseTypeRepr tp
BaseBoolRepr -> Bool -> ConcreteVal tp
Bool -> ConcreteVal BaseBoolType
ConcreteBool (Bool -> ConcreteVal tp) -> Maybe Bool -> Maybe (ConcreteVal tp)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> e BaseBoolType -> Maybe Bool
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseBoolType -> Maybe Bool
asConstantPred e tp
e BaseBoolType
x
BaseTypeRepr tp
BaseIntegerRepr -> Integer -> ConcreteVal tp
Integer -> ConcreteVal BaseIntegerType
ConcreteInteger (Integer -> ConcreteVal tp)
-> Maybe Integer -> Maybe (ConcreteVal tp)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> e BaseIntegerType -> Maybe Integer
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseIntegerType -> Maybe Integer
asInteger e tp
e BaseIntegerType
x
BaseTypeRepr tp
BaseRealRepr -> Rational -> ConcreteVal tp
Rational -> ConcreteVal BaseRealType
ConcreteReal (Rational -> ConcreteVal tp)
-> Maybe Rational -> Maybe (ConcreteVal tp)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> e BaseRealType -> Maybe Rational
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseRealType -> Maybe Rational
asRational e tp
e BaseRealType
x
BaseStringRepr StringInfoRepr si
_si -> StringLiteral si -> ConcreteVal tp
StringLiteral si -> ConcreteVal ('BaseStringType si)
forall (si :: StringInfo).
StringLiteral si -> ConcreteVal ('BaseStringType si)
ConcreteString (StringLiteral si -> ConcreteVal tp)
-> Maybe (StringLiteral si) -> Maybe (ConcreteVal tp)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> e ('BaseStringType si) -> Maybe (StringLiteral si)
forall (si :: StringInfo).
e (BaseStringType si) -> Maybe (StringLiteral si)
forall (e :: BaseType -> Type) (si :: StringInfo).
IsExpr e =>
e (BaseStringType si) -> Maybe (StringLiteral si)
asString e tp
e ('BaseStringType si)
x
BaseTypeRepr tp
BaseComplexRepr -> Complex Rational -> ConcreteVal tp
Complex Rational -> ConcreteVal BaseComplexType
ConcreteComplex (Complex Rational -> ConcreteVal tp)
-> Maybe (Complex Rational) -> Maybe (ConcreteVal tp)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> e BaseComplexType -> Maybe (Complex Rational)
forall (e :: BaseType -> Type).
IsExpr e =>
e BaseComplexType -> Maybe (Complex Rational)
asComplex e tp
e BaseComplexType
x
BaseBVRepr NatRepr w
w -> NatRepr w -> BV w -> ConcreteVal ('BaseBVType w)
forall (w :: Nat).
(1 <= w) =>
NatRepr w -> BV w -> ConcreteVal ('BaseBVType w)
ConcreteBV NatRepr w
w (BV w -> ConcreteVal tp) -> Maybe (BV w) -> Maybe (ConcreteVal tp)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> e ('BaseBVType w) -> Maybe (BV w)
forall (w :: Nat). e (BaseBVType w) -> Maybe (BV w)
forall (e :: BaseType -> Type) (w :: Nat).
IsExpr e =>
e (BaseBVType w) -> Maybe (BV w)
asBV e tp
e ('BaseBVType w)
x
BaseFloatRepr FloatPrecisionRepr fpp
fpp -> FloatPrecisionRepr fpp
-> BigFloat -> ConcreteVal ('BaseFloatType fpp)
forall (fpp :: FloatPrecision).
FloatPrecisionRepr fpp
-> BigFloat -> ConcreteVal ('BaseFloatType fpp)
ConcreteFloat FloatPrecisionRepr fpp
fpp (BigFloat -> ConcreteVal tp)
-> Maybe BigFloat -> Maybe (ConcreteVal tp)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> e ('BaseFloatType fpp) -> Maybe BigFloat
forall (fpp :: FloatPrecision).
e (BaseFloatType fpp) -> Maybe BigFloat
forall (e :: BaseType -> Type) (fpp :: FloatPrecision).
IsExpr e =>
e (BaseFloatType fpp) -> Maybe BigFloat
asFloat e tp
e ('BaseFloatType fpp)
x
BaseStructRepr Assignment BaseTypeRepr ctx
_ -> Assignment ConcreteVal ctx -> ConcreteVal tp
Assignment ConcreteVal ctx -> ConcreteVal ('BaseStructType ctx)
forall (ctx :: Ctx BaseType).
Assignment ConcreteVal ctx -> ConcreteVal ('BaseStructType ctx)
ConcreteStruct (Assignment ConcreteVal ctx -> ConcreteVal tp)
-> Maybe (Assignment ConcreteVal ctx) -> Maybe (ConcreteVal tp)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (e ('BaseStructType ctx) -> Maybe (Assignment e ctx)
forall (flds :: Ctx BaseType).
e (BaseStructType flds) -> Maybe (Assignment e flds)
forall (e :: BaseType -> Type) (flds :: Ctx BaseType).
IsExpr e =>
e (BaseStructType flds) -> Maybe (Assignment e flds)
asStruct e tp
e ('BaseStructType ctx)
x Maybe (Assignment e ctx)
-> (Assignment e ctx -> Maybe (Assignment ConcreteVal ctx))
-> Maybe (Assignment ConcreteVal ctx)
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= (forall (x :: BaseType). e x -> Maybe (ConcreteVal x))
-> forall (x :: Ctx BaseType).
Assignment e x -> Maybe (Assignment ConcreteVal x)
forall k l (t :: (k -> Type) -> l -> Type) (f :: k -> Type)
(g :: k -> Type) (m :: Type -> Type).
(TraversableFC t, Applicative m) =>
(forall (x :: k). f x -> m (g x))
-> forall (x :: l). t f x -> m (t g x)
forall (f :: BaseType -> Type) (g :: BaseType -> Type)
(m :: Type -> Type).
Applicative m =>
(forall (x :: BaseType). f x -> m (g x))
-> forall (x :: Ctx BaseType). Assignment f x -> m (Assignment g x)
traverseFC e x -> Maybe (ConcreteVal x)
forall (x :: BaseType). e x -> Maybe (ConcreteVal x)
forall (e :: BaseType -> Type) (tp :: BaseType).
IsExpr e =>
e tp -> Maybe (ConcreteVal tp)
asConcrete)
BaseArrayRepr Assignment BaseTypeRepr (idx ::> tp)
idx BaseTypeRepr xs
_tp -> do
def <- e ('BaseArrayType (idx ::> tp) xs) -> Maybe (e xs)
forall (idx :: Ctx BaseType) (bt :: BaseType).
e (BaseArrayType idx bt) -> Maybe (e bt)
forall (e :: BaseType -> Type) (idx :: Ctx BaseType)
(bt :: BaseType).
IsExpr e =>
e (BaseArrayType idx bt) -> Maybe (e bt)
asConstantArray e tp
e ('BaseArrayType (idx ::> tp) xs)
x
c_def <- asConcrete def
pure (ConcreteArray idx c_def Map.empty)
concreteToSym :: IsExprBuilder sym => sym -> ConcreteVal tp -> IO (SymExpr sym tp)
concreteToSym :: forall sym (tp :: BaseType).
IsExprBuilder sym =>
sym -> ConcreteVal tp -> IO (SymExpr sym tp)
concreteToSym sym
sym = \case
ConcreteBool Bool
True -> SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (sym -> SymExpr sym BaseBoolType
forall sym. IsExprBuilder sym => sym -> Pred sym
truePred sym
sym)
ConcreteBool Bool
False -> SymExpr sym BaseBoolType -> IO (SymExpr sym BaseBoolType)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (sym -> SymExpr sym BaseBoolType
forall sym. IsExprBuilder sym => sym -> Pred sym
falsePred sym
sym)
ConcreteInteger Integer
x -> sym -> Integer -> IO (SymInteger sym)
forall sym.
IsExprBuilder sym =>
sym -> Integer -> IO (SymInteger sym)
intLit sym
sym Integer
x
ConcreteReal Rational
x -> sym -> Rational -> IO (SymReal sym)
forall sym.
IsExprBuilder sym =>
sym -> Rational -> IO (SymReal sym)
realLit sym
sym Rational
x
ConcreteFloat FloatPrecisionRepr fpp
fpp BigFloat
bf -> sym -> FloatPrecisionRepr fpp -> BigFloat -> IO (SymFloat sym fpp)
forall sym (fpp :: FloatPrecision).
IsExprBuilder sym =>
sym -> FloatPrecisionRepr fpp -> BigFloat -> IO (SymFloat sym fpp)
forall (fpp :: FloatPrecision).
sym -> FloatPrecisionRepr fpp -> BigFloat -> IO (SymFloat sym fpp)
floatLit sym
sym FloatPrecisionRepr fpp
fpp BigFloat
bf
ConcreteString StringLiteral si
x -> sym -> StringLiteral si -> IO (SymString sym si)
forall sym (si :: StringInfo).
IsExprBuilder sym =>
sym -> StringLiteral si -> IO (SymString sym si)
forall (si :: StringInfo).
sym -> StringLiteral si -> IO (SymString sym si)
stringLit sym
sym StringLiteral si
x
ConcreteComplex Complex Rational
x -> sym -> Complex Rational -> IO (SymCplx sym)
forall sym.
IsExprBuilder sym =>
sym -> Complex Rational -> IO (SymCplx sym)
mkComplexLit sym
sym Complex Rational
x
ConcreteBV NatRepr w
w BV w
x -> sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w BV w
x
ConcreteStruct Assignment ConcreteVal ctx
xs -> sym
-> Assignment (SymExpr sym) ctx
-> IO (SymExpr sym ('BaseStructType ctx))
forall sym (flds :: Ctx BaseType).
IsExprBuilder sym =>
sym -> Assignment (SymExpr sym) flds -> IO (SymStruct sym flds)
forall (flds :: Ctx BaseType).
sym -> Assignment (SymExpr sym) flds -> IO (SymStruct sym flds)
mkStruct sym
sym (Assignment (SymExpr sym) ctx
-> IO (SymExpr sym ('BaseStructType ctx)))
-> IO (Assignment (SymExpr sym) ctx)
-> IO (SymExpr sym ('BaseStructType ctx))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall (x :: BaseType). ConcreteVal x -> IO (SymExpr sym x))
-> forall (x :: Ctx BaseType).
Assignment ConcreteVal x -> IO (Assignment (SymExpr sym) x)
forall k l (t :: (k -> Type) -> l -> Type) (f :: k -> Type)
(g :: k -> Type) (m :: Type -> Type).
(TraversableFC t, Applicative m) =>
(forall (x :: k). f x -> m (g x))
-> forall (x :: l). t f x -> m (t g x)
forall (f :: BaseType -> Type) (g :: BaseType -> Type)
(m :: Type -> Type).
Applicative m =>
(forall (x :: BaseType). f x -> m (g x))
-> forall (x :: Ctx BaseType). Assignment f x -> m (Assignment g x)
traverseFC (sym -> ConcreteVal x -> IO (SymExpr sym x)
forall sym (tp :: BaseType).
IsExprBuilder sym =>
sym -> ConcreteVal tp -> IO (SymExpr sym tp)
concreteToSym sym
sym) Assignment ConcreteVal ctx
xs
ConcreteArray Assignment BaseTypeRepr (idx ::> i)
idxTy ConcreteVal b
def Map (Assignment ConcreteVal (idx ::> i)) (ConcreteVal b)
xs0 -> [(Assignment ConcreteVal (idx ::> i), ConcreteVal b)]
-> SymExpr sym ('BaseArrayType (idx ::> i) b)
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b))
go (Map (Assignment ConcreteVal (idx ::> i)) (ConcreteVal b)
-> [(Assignment ConcreteVal (idx ::> i), ConcreteVal b)]
forall k a. Map k a -> [(k, a)]
Map.toAscList Map (Assignment ConcreteVal (idx ::> i)) (ConcreteVal b)
xs0) (SymExpr sym ('BaseArrayType (idx ::> i) b)
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b)))
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b))
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym
-> Assignment BaseTypeRepr (idx ::> i)
-> SymExpr sym b
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b))
forall sym (idx :: Ctx BaseType) (tp :: BaseType) (b :: BaseType).
IsExprBuilder sym =>
sym
-> Assignment BaseTypeRepr (idx ::> tp)
-> SymExpr sym b
-> IO (SymArray sym (idx ::> tp) b)
forall (idx :: Ctx BaseType) (tp :: BaseType) (b :: BaseType).
sym
-> Assignment BaseTypeRepr (idx ::> tp)
-> SymExpr sym b
-> IO (SymArray sym (idx ::> tp) b)
constantArray sym
sym Assignment BaseTypeRepr (idx ::> i)
idxTy (SymExpr sym b -> IO (SymExpr sym ('BaseArrayType (idx ::> i) b)))
-> IO (SymExpr sym b)
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< sym -> ConcreteVal b -> IO (SymExpr sym b)
forall sym (tp :: BaseType).
IsExprBuilder sym =>
sym -> ConcreteVal tp -> IO (SymExpr sym tp)
concreteToSym sym
sym ConcreteVal b
def
where
go :: [(Assignment ConcreteVal (idx ::> i), ConcreteVal b)]
-> SymExpr sym ('BaseArrayType (idx ::> i) b)
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b))
go [] SymExpr sym ('BaseArrayType (idx ::> i) b)
arr = SymExpr sym ('BaseArrayType (idx ::> i) b)
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b))
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return SymExpr sym ('BaseArrayType (idx ::> i) b)
arr
go ((Assignment ConcreteVal (idx ::> i)
i,ConcreteVal b
x):[(Assignment ConcreteVal (idx ::> i), ConcreteVal b)]
xs) SymExpr sym ('BaseArrayType (idx ::> i) b)
arr =
do arr' <- [(Assignment ConcreteVal (idx ::> i), ConcreteVal b)]
-> SymExpr sym ('BaseArrayType (idx ::> i) b)
-> IO (SymExpr sym ('BaseArrayType (idx ::> i) b))
go [(Assignment ConcreteVal (idx ::> i), ConcreteVal b)]
xs SymExpr sym ('BaseArrayType (idx ::> i) b)
arr
i' <- traverseFC (concreteToSym sym) i
x' <- concreteToSym sym x
arrayUpdate sym arr' i' x'
{-# INLINABLE muxRange #-}
muxRange :: (IsExpr e, Monad m) =>
(Natural -> m (e BaseBoolType))
->
(e BaseBoolType -> a -> a -> m a) ->
(Natural -> m a) ->
Natural ->
Natural ->
m a
muxRange :: forall (e :: BaseType -> Type) (m :: Type -> Type) a.
(IsExpr e, Monad m) =>
(Nat -> m (e BaseBoolType))
-> (e BaseBoolType -> a -> a -> m a)
-> (Nat -> m a)
-> Nat
-> Nat
-> m a
muxRange Nat -> m (e BaseBoolType)
predFn e BaseBoolType -> a -> a -> m a
iteFn Nat -> m a
f Nat
l Nat
h
| Nat
l Nat -> Nat -> Bool
forall a. Ord a => a -> a -> Bool
< Nat
h = do
c <- Nat -> m (e BaseBoolType)
predFn Nat
l
case asConstantPred c of
Just Bool
True -> Nat -> m a
f Nat
l
Just Bool
False -> (Nat -> m (e BaseBoolType))
-> (e BaseBoolType -> a -> a -> m a)
-> (Nat -> m a)
-> Nat
-> Nat
-> m a
forall (e :: BaseType -> Type) (m :: Type -> Type) a.
(IsExpr e, Monad m) =>
(Nat -> m (e BaseBoolType))
-> (e BaseBoolType -> a -> a -> m a)
-> (Nat -> m a)
-> Nat
-> Nat
-> m a
muxRange Nat -> m (e BaseBoolType)
predFn e BaseBoolType -> a -> a -> m a
iteFn Nat -> m a
f (Nat -> Nat
forall a. Enum a => a -> a
succ Nat
l) Nat
h
Maybe Bool
Nothing ->
do match_branch <- Nat -> m a
f Nat
l
other_branch <- muxRange predFn iteFn f (succ l) h
iteFn c match_branch other_branch
| Bool
otherwise = Nat -> m a
f Nat
h
data SymEncoder sym v tp
= SymEncoder { forall sym v (tp :: BaseType).
SymEncoder sym v tp -> BaseTypeRepr tp
symEncoderType :: !(BaseTypeRepr tp)
, forall sym v (tp :: BaseType).
SymEncoder sym v tp -> sym -> SymExpr sym tp -> IO v
symFromExpr :: !(sym -> SymExpr sym tp -> IO v)
, forall sym v (tp :: BaseType).
SymEncoder sym v tp -> sym -> v -> IO (SymExpr sym tp)
symToExpr :: !(sym -> v -> IO (SymExpr sym tp))
}
data Statistics
= Statistics { Statistics -> Integer
statAllocs :: !Integer
, Statistics -> Integer
statNonLinearOps :: !Integer
}
deriving ( Int -> Statistics -> ShowS
[Statistics] -> ShowS
Statistics -> String
(Int -> Statistics -> ShowS)
-> (Statistics -> String)
-> ([Statistics] -> ShowS)
-> Show Statistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Statistics -> ShowS
showsPrec :: Int -> Statistics -> ShowS
$cshow :: Statistics -> String
show :: Statistics -> String
$cshowList :: [Statistics] -> ShowS
showList :: [Statistics] -> ShowS
Show )
zeroStatistics :: Statistics
zeroStatistics :: Statistics
zeroStatistics = Statistics { statAllocs :: Integer
statAllocs = Integer
0
, statNonLinearOps :: Integer
statNonLinearOps = Integer
0 }
bvZero :: (1 <= w, IsExprBuilder sym) => sym -> NatRepr w -> IO (SymBV sym w)
bvZero :: forall (w :: Nat) sym.
(1 <= w, IsExprBuilder sym) =>
sym -> NatRepr w -> IO (SymBV sym w)
bvZero = sym -> NatRepr w -> IO (SymBV sym w)
forall (w :: Nat). (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> IO (SymBV sym w)
minUnsignedBV
bvOne :: (1 <= w, IsExprBuilder sym) => sym -> NatRepr w -> IO (SymBV sym w)
bvOne :: forall (w :: Nat) sym.
(1 <= w, IsExprBuilder sym) =>
sym -> NatRepr w -> IO (SymBV sym w)
bvOne sym
sym NatRepr w
w = sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall (w :: Nat).
(1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
forall sym (w :: Nat).
(IsExprBuilder sym, 1 <= w) =>
sym -> NatRepr w -> BV w -> IO (SymBV sym w)
bvLit sym
sym NatRepr w
w (NatRepr w -> BV w
forall (w :: Nat). (1 <= w) => NatRepr w -> BV w
BV.one NatRepr w
w)