| License | BSD3 |
|---|---|
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Documentation.SBV.Examples.Uninterpreted.EUFLogic
Description
Demonstrates the ability to generate uninterpreted functions of arbitrarily many arguments, whose types are generated programmatically. The high-level idea of this module is to provide a strongly-typed representation, using a GADT, of a logic that includes uninterpreted functions. This module then defines an interpretation of this logic into SBV, which it uses to perform SMT queries in the logic.
Synopsis
- data EUFType
- data BVWidth (w :: Nat) = (KnownNat w, BVIsNonZero w) => BVWidth (SNat w)
- knownBVWidth :: forall (w :: Nat). (KnownNat w, BVIsNonZero w) => BVWidth w
- data TypeRepr (tp :: EUFType) where
- data TypeReprs (tps :: [EUFType]) where
- class KnownEUFType (tp :: EUFType) where
- knownEUFType :: TypeRepr tp
- class KnownEUFTypes (tps :: [EUFType]) where
- knownEUFTypes :: TypeReprs tps
- data UnintOp (ins :: [EUFType]) (out :: EUFType) = UnintOp {
- unintOpName :: String
- unintOpIns :: TypeReprs ins
- unintOpOut :: TypeRepr out
- data Op (ins :: [EUFType]) (out :: EUFType) where
- Op_Unint :: forall (ins :: [EUFType]) (out :: EUFType). UnintOp ins out -> Op ins out
- Op_And :: Op '['Tp_Bool, 'Tp_Bool] 'Tp_Bool
- Op_Or :: Op '['Tp_Bool, 'Tp_Bool] 'Tp_Bool
- Op_Not :: Op '['Tp_Bool] 'Tp_Bool
- Op_BoolLit :: Bool -> Op ('[] :: [EUFType]) 'Tp_Bool
- Op_IfThenElse :: forall (out :: EUFType). TypeRepr out -> Op '['Tp_Bool, out, out] out
- Op_Plus :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] ('Tp_BV w)
- Op_Minus :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] ('Tp_BV w)
- Op_Times :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] ('Tp_BV w)
- Op_Abs :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w] ('Tp_BV w)
- Op_Signum :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w] ('Tp_BV w)
- Op_BVLit :: forall (w :: Natural). BVWidth w -> Integer -> Op ('[] :: [EUFType]) ('Tp_BV w)
- Op_BVEq :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] 'Tp_Bool
- Op_BVLt :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] 'Tp_Bool
- mkUnintOp :: forall (ins :: [EUFType]) (out :: EUFType). (KnownEUFTypes ins, KnownEUFType out) => String -> Op ins out
- opInsOut :: forall (ins :: [EUFType]) (out :: EUFType). Op ins out -> (TypeReprs ins, TypeRepr out)
- opIns :: forall (ins :: [EUFType]) (out :: EUFType). Op ins out -> TypeReprs ins
- data EUFExpr (tp :: EUFType) where
- data EUFExprs (tps :: [EUFType]) where
- EUFExprsNil :: EUFExprs ('[] :: [EUFType])
- EUFExprsCons :: forall (tp :: EUFType) (tps1 :: [EUFType]). EUFExpr tp -> EUFExprs tps1 -> EUFExprs (tp ': tps1)
- type family EUFExprFun (ins :: [EUFType]) (out :: EUFType) where ...
- lambdaEUFExprFun :: forall (ins :: [EUFType]) (out :: EUFType). TypeReprs ins -> (EUFExprs ins -> EUFExpr out) -> EUFExprFun ins out
- applyOp :: forall (ins :: [EUFType]) (out :: EUFType). Op ins out -> EUFExprFun ins out
- mkUnintExpr :: forall (tp :: EUFType). KnownEUFType tp => String -> EUFExpr tp
- type family Type2SBV (tp :: EUFType) where ...
- type family OpTypes2SBV (ins :: [EUFType]) (out :: EUFType) where ...
- withSMTDefOpTypes :: forall (ins :: [EUFType]) (out :: EUFType) a. TypeReprs ins -> TypeRepr out -> (SMTDefinable (OpTypes2SBV ins out) => a) -> a
- data ResolvedUnintOp = ResolvedUnintOp (UnintOp ins out) (OpTypes2SBV ins out)
- type UnintMap = Map String ResolvedUnintOp
- unintEnsure :: forall (ins :: [EUFType]) (out :: EUFType). UnintOp ins out -> UnintMap -> (OpTypes2SBV ins out, UnintMap)
- type InterpM = State UnintMap
- runInterpM :: InterpM a -> a
- interpOp :: forall (ins :: [EUFType]) (out :: EUFType). Op ins out -> InterpM (OpTypes2SBV ins out)
- interpEUFExpr :: forall (tp :: EUFType). EUFExpr tp -> InterpM (Type2SBV tp)
- interpApplyEUFExprs :: forall ghost (out :: EUFType) (ins :: [EUFType]). ghost out -> OpTypes2SBV ins out -> EUFExprs ins -> InterpM (Type2SBV out)
- interpEUF :: forall (a :: EUFType). EUFExpr a -> Type2SBV a
- example :: EUFExpr 'Tp_Bool
Types of the EUF Logic
The datakind for the types in our EUF logic.
Instances
| TestEquality TypeRepr Source # | TestEquality instance for Type representations |
| KnownEUFTypes ('[] :: [EUFType]) Source # | |
Defined in Documentation.SBV.Examples.Uninterpreted.EUFLogic Methods knownEUFTypes :: TypeReprs ('[] :: [EUFType]) Source # | |
| TestEquality TypeReprs Source # | |
| (KnownEUFType tp, KnownEUFTypes tps) => KnownEUFTypes (tp ': tps) Source # | |
Defined in Documentation.SBV.Examples.Uninterpreted.EUFLogic Methods knownEUFTypes :: TypeReprs (tp ': tps) Source # | |
data BVWidth (w :: Nat) Source #
A singleton type for natural numbers that can be used as the widths of bitvectors.
Constructors
| (KnownNat w, BVIsNonZero w) => BVWidth (SNat w) |
Instances
| TestEquality BVWidth Source # | TestEquality instance for BVWidth. |
knownBVWidth :: forall (w :: Nat). (KnownNat w, BVIsNonZero w) => BVWidth w Source #
data TypeRepr (tp :: EUFType) where Source #
A singleton type that represents type-level EUFTypes at the object level
Constructors
| Repr_Bool :: TypeRepr 'Tp_Bool | |
| Repr_BV :: forall (w :: Natural). BVWidth w -> TypeRepr ('Tp_BV w) |
Instances
| TestEquality TypeRepr Source # | TestEquality instance for Type representations |
data TypeReprs (tps :: [EUFType]) where Source #
A list of TypeReprs for each type in a type-level list
Constructors
| Repr_Nil :: TypeReprs ('[] :: [EUFType]) | |
| Repr_Cons :: forall (tp :: EUFType) (tps1 :: [EUFType]). TypeRepr tp -> TypeReprs tps1 -> TypeReprs (tp ': tps1) |
Instances
class KnownEUFType (tp :: EUFType) where Source #
Methods
knownEUFType :: TypeRepr tp Source #
Instances
| KnownEUFType 'Tp_Bool Source # | Mapping from Tp_Bool |
Defined in Documentation.SBV.Examples.Uninterpreted.EUFLogic Methods | |
| (KnownNat w, BVIsNonZero w) => KnownEUFType ('Tp_BV w) Source # | Mapping from Tp_BV |
Defined in Documentation.SBV.Examples.Uninterpreted.EUFLogic Methods knownEUFType :: TypeRepr ('Tp_BV w) Source # | |
class KnownEUFTypes (tps :: [EUFType]) where Source #
Methods
knownEUFTypes :: TypeReprs tps Source #
Instances
| KnownEUFTypes ('[] :: [EUFType]) Source # | |
Defined in Documentation.SBV.Examples.Uninterpreted.EUFLogic Methods knownEUFTypes :: TypeReprs ('[] :: [EUFType]) Source # | |
| (KnownEUFType tp, KnownEUFTypes tps) => KnownEUFTypes (tp ': tps) Source # | |
Defined in Documentation.SBV.Examples.Uninterpreted.EUFLogic Methods knownEUFTypes :: TypeReprs (tp ': tps) Source # | |
Operations of the EUF Logic
data UnintOp (ins :: [EUFType]) (out :: EUFType) Source #
An uninterpreted function in our EUF logic, which is a string name plus the input and output types.
Constructors
| UnintOp | |
Fields
| |
data Op (ins :: [EUFType]) (out :: EUFType) where Source #
The operations of our EUF logic, which are indexed by a list of 0 or more input types and a single output type.
Constructors
| Op_Unint :: forall (ins :: [EUFType]) (out :: EUFType). UnintOp ins out -> Op ins out | |
| Op_And :: Op '['Tp_Bool, 'Tp_Bool] 'Tp_Bool | |
| Op_Or :: Op '['Tp_Bool, 'Tp_Bool] 'Tp_Bool | |
| Op_Not :: Op '['Tp_Bool] 'Tp_Bool | |
| Op_BoolLit :: Bool -> Op ('[] :: [EUFType]) 'Tp_Bool | |
| Op_IfThenElse :: forall (out :: EUFType). TypeRepr out -> Op '['Tp_Bool, out, out] out | |
| Op_Plus :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] ('Tp_BV w) | |
| Op_Minus :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] ('Tp_BV w) | |
| Op_Times :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] ('Tp_BV w) | |
| Op_Abs :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w] ('Tp_BV w) | |
| Op_Signum :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w] ('Tp_BV w) | |
| Op_BVLit :: forall (w :: Natural). BVWidth w -> Integer -> Op ('[] :: [EUFType]) ('Tp_BV w) | |
| Op_BVEq :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] 'Tp_Bool | |
| Op_BVLt :: forall (w :: Natural). BVWidth w -> Op '['Tp_BV w, 'Tp_BV w] 'Tp_Bool |
mkUnintOp :: forall (ins :: [EUFType]) (out :: EUFType). (KnownEUFTypes ins, KnownEUFType out) => String -> Op ins out Source #
Create an uninterpreted Op of known type
opInsOut :: forall (ins :: [EUFType]) (out :: EUFType). Op ins out -> (TypeReprs ins, TypeRepr out) Source #
Get the input types and output type of an Op
opIns :: forall (ins :: [EUFType]) (out :: EUFType). Op ins out -> TypeReprs ins Source #
Get the input types of an Op
Expressions of the EUF Logic
data EUFExpr (tp :: EUFType) where Source #
The expressions of our EUF logic, which are just operations applied to argument expressions.
Constructors
| EUFExpr :: forall (ins :: [EUFType]) (tp :: EUFType). Op ins tp -> EUFExprs ins -> EUFExpr tp |
Instances
| (KnownNat w, BVIsNonZero w) => Num (EUFExpr ('Tp_BV w)) Source # | |
Defined in Documentation.SBV.Examples.Uninterpreted.EUFLogic Methods (+) :: EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) # (-) :: EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) # (*) :: EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) # negate :: EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) # abs :: EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) # signum :: EUFExpr ('Tp_BV w) -> EUFExpr ('Tp_BV w) # fromInteger :: Integer -> EUFExpr ('Tp_BV w) # | |
data EUFExprs (tps :: [EUFType]) where Source #
A sequence of expressions for each type in a type-level list
Constructors
| EUFExprsNil :: EUFExprs ('[] :: [EUFType]) | |
| EUFExprsCons :: forall (tp :: EUFType) (tps1 :: [EUFType]). EUFExpr tp -> EUFExprs tps1 -> EUFExprs (tp ': tps1) |
type family EUFExprFun (ins :: [EUFType]) (out :: EUFType) where ... Source #
Equations
| EUFExprFun ('[] :: [EUFType]) out = EUFExpr out | |
| EUFExprFun (tp ': tps) out = EUFExpr tp -> EUFExprFun tps out |
lambdaEUFExprFun :: forall (ins :: [EUFType]) (out :: EUFType). TypeReprs ins -> (EUFExprs ins -> EUFExpr out) -> EUFExprFun ins out Source #
Build an EUFExprFun from a function on EUFExprs
mkUnintExpr :: forall (tp :: EUFType). KnownEUFType tp => String -> EUFExpr tp Source #
Build an expression from an uninterpreted operation of a known type
Interpreting the EUF Logic into SBV
type family Type2SBV (tp :: EUFType) where ... Source #
Convert an EUFType to a type of SBV expressions
type family OpTypes2SBV (ins :: [EUFType]) (out :: EUFType) where ... Source #
Equations
| OpTypes2SBV ('[] :: [EUFType]) out = Type2SBV out | |
| OpTypes2SBV (tp ': tps) out = Type2SBV tp -> OpTypes2SBV tps out |
withSMTDefOpTypes :: forall (ins :: [EUFType]) (out :: EUFType) a. TypeReprs ins -> TypeRepr out -> (SMTDefinable (OpTypes2SBV ins out) => a) -> a Source #
Create an SMTDefinable instance for the type returned by OpTypes2SBV and pass it to a local function
data ResolvedUnintOp Source #
An uninterpreted function that has been resolved to an SBV function
Constructors
| ResolvedUnintOp (UnintOp ins out) (OpTypes2SBV ins out) |
unintEnsure :: forall (ins :: [EUFType]) (out :: EUFType). UnintOp ins out -> UnintMap -> (OpTypes2SBV ins out, UnintMap) Source #
interpOp :: forall (ins :: [EUFType]) (out :: EUFType). Op ins out -> InterpM (OpTypes2SBV ins out) Source #
Interpret an Op into a function over SBV values
interpEUFExpr :: forall (tp :: EUFType). EUFExpr tp -> InterpM (Type2SBV tp) Source #
Interpret an EUFExpr into an SBV value.
interpApplyEUFExprs :: forall ghost (out :: EUFType) (ins :: [EUFType]). ghost out -> OpTypes2SBV ins out -> EUFExprs ins -> InterpM (Type2SBV out) Source #
Apply an interpretation of an operator to the interpretations of a sequence of arguments for it.
Examples
example :: EUFExpr 'Tp_Bool Source #
Example EUF problem
f (f (a) - f (b)) /= f (c), b >= a, a >= b + c, c >= 0
from https://goto.ucsd.edu/~rjhala/classes/sp13/cse291/slides/lec-smt.markdown.pdf
noting that x >= y is the same as not (x < y). We have:
>>>sat $ interpEUF exampleSatisfiable. Model: a = 996506182 :: Word32 b = 3298461113 :: Word32 c = 1445036292 :: Word32 f :: Word32 -> Word32 f 0 = 4188219399 f 1445036292 = 285239361 f 3298461113 = 4054018119 f 996506182 = 4054018119 f _ = 0
Note that the original example is unsatisfiable over integers. It is however satisfiable over 32-bit words, hence the model above.