{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PatternGuards              #-}
{-# LANGUAGE NamedFieldPuns             #-}
{-# LANGUAGE ScopedTypeVariables        #-}

-- |
-- Module    : Z3.Base
-- Copyright : (c) Iago Abal, 2012-2015
--             (c) David Castro, 2012-2015
-- License   : BSD3
-- Maintainer: Iago Abal <mail@iagoabal.eu>,
--             David Castro <david.castro.dcp@gmail.com>
--
-- Low-level bindings to Z3 API.
--
-- There is (mostly) a one-to-one correspondence with Z3 C API, thus see
-- <http://z3prover.github.io/api/html/group__capi.html>
-- for further details.

{- HACKING

Add here the IO-based wrapper for a new Z3 API function:

* Take a look to a few others API functions and follow the same coding style.
    * 2-space wide indentation, no tabs.
    * No trailing spaces, please.
    * ...
* Place the API function in the right section, according to the Z3's API documentation.
* Annotate the API function with a short but concise haddock comment.
    * Look at the Z3 API documentation for inspiration.
* Add the API function to the module export list, (only) if needed.

This should be straightforward for most cases using [MARSHALLING HELPERS].

Reference counting
------------------

When an object is returned by the C API, we:
* increment its reference counter (if applicable),
* wrap the pointer into a ForeignPtr, and
* install a finalizer to decrement the counter.

Objects with explicit /delete/ functions, instead of reference
counters, are handled analogously.In this way, we move memory
management into the GC.

Remarkably, a Z3_context cannot be deleted until we "free" every
object depending on it. But ForeignPtr finalizers do not provide
any ordering guarantee, and it's not possible to establish
dependencies between finalizers. Thus, we /count references/ to
a Z3_context and only delete it when this count reaches /zero/.

-}

module Z3.Base (

  -- * Types
    Config
  , Context
  , Symbol
  , AST
  , Sort
  , TupleType(..)
  , FuncDecl
  , App
  , Pattern
  , Constructor
  , Model
  , FuncInterp
  , FuncEntry
  , Params
  , Solver
  , SortKind(..)
  , ASTKind(..)
  , Tactic
  , ApplyResult
  , Goal
  -- ** Satisfiability result
  , Result(..)

  -- * Algebraic Numbers
  , algebraicIsValue
  , algebraicIsPos
  , algebraicIsNeg
  , algebraicIsZero
  , algebraicSign
  , algebraicAdd
  , algebraicSub
  , algebraicMul
  , algebraicDiv
  , algebraicRoot
  , algebraicPower
  , algebraicLt
  , algebraicGt
  , algebraicLe
  , algebraicGe
  , algebraicEq
  , algebraicNeq
  , algebraicRoots
  , algebraicEval

  -- * Global Parameters
  , globalParamSet
  , globalParamResetAll
  , globalParamGet

  -- * Create configuration
  , mkConfig
  , delConfig
  , setParamValue
  -- ** Helpers
  , withConfig

  -- * Create context
  , mkContext
  , withContext

  -- * Parameters
  , mkParams
  , paramsSetBool
  , paramsSetUInt
  , paramsSetDouble
  , paramsSetSymbol
  , paramsToString

  -- * Symbols
  , mkIntSymbol
  , mkStringSymbol

  -- * Sorts
  , mkUninterpretedSort
  , mkBoolSort
  , mkIntSort
  , mkRealSort
  , mkBvSort
  , mkFiniteDomainSort
  , mkArraySort
  , mkArraySortN
  , mkTupleSort
  , mkTupleType
  , mkTuple
  , mkIndexTuple
  , mkProjTuple
  , mkEnumerationSort
  , mkListSort
  , mkConstructor
  , mkDatatype
  , mkDatatypes
  , mkSetSort

  -- * Constants and Applications
  , mkFuncDecl
  , mkApp
  , mkConst
  , mkFreshFuncDecl
  , mkFreshConst
  , mkRecFuncDecl
  , addRecDef
  -- ** Helpers
  , mkVar
  , mkBoolVar
  , mkRealVar
  , mkIntVar
  , mkBvVar
  , mkFreshVar
  , mkFreshBoolVar
  , mkFreshRealVar
  , mkFreshIntVar
  , mkFreshBvVar

  -- * Propositional Logic and Equality
  , mkTrue
  , mkFalse
  , mkEq
  , mkNot
  , mkIte
  , mkIff
  , mkImplies
  , mkXor
  , mkAnd
  , mkOr
  , mkDistinct
  , mkDistinct1
  -- ** Helpers
  , mkBool

  -- * Arithmetic: Integers and Reals
  , mkAdd
  , mkMul
  , mkSub
  , mkSub1
  , mkUnaryMinus
  , mkDiv
  , mkMod
  , mkRem
  , mkPower
  , mkLt
  , mkLe
  , mkGt
  , mkGe
  , mkInt2Real
  , mkReal2Int
  , mkIsInt

  -- * Bit-vectors
  , mkBvnot
  , mkBvredand
  , mkBvredor
  , mkBvand
  , mkBvor
  , mkBvxor
  , mkBvnand
  , mkBvnor
  , mkBvxnor
  , mkBvneg
  , mkBvadd
  , mkBvsub
  , mkBvmul
  , mkBvudiv
  , mkBvsdiv
  , mkBvurem
  , mkBvsrem
  , mkBvsmod
  , mkBvult
  , mkBvslt
  , mkBvule
  , mkBvsle
  , mkBvuge
  , mkBvsge
  , mkBvugt
  , mkBvsgt
  , mkConcat
  , mkExtract
  , mkSignExt
  , mkZeroExt
  , mkRepeat
  , mkBvshl
  , mkBvlshr
  , mkBvashr
  , mkRotateLeft
  , mkRotateRight
  , mkExtRotateLeft
  , mkExtRotateRight
  , mkInt2bv
  , mkBv2int
  , mkBvnegNoOverflow
  , mkBvaddNoOverflow
  , mkBvaddNoUnderflow
  , mkBvsubNoOverflow
  , mkBvsubNoUnderflow
  , mkBvmulNoOverflow
  , mkBvmulNoUnderflow
  , mkBvsdivNoOverflow

  -- * Arrays
  , mkSelect
  , mkStore
  , mkConstArray
  , mkMap
  , mkArrayDefault

  -- * Sets
  , mkEmptySet
  , mkFullSet
  , mkSetAdd
  , mkSetDel
  , mkSetUnion
  , mkSetIntersect
  , mkSetDifference
  , mkSetComplement
  , mkSetMember
  , mkSetSubset

  -- * Numerals
  , mkNumeral
  , mkReal
  , mkInt
  , mkUnsignedInt
  , mkInt64
  , mkUnsignedInt64
  -- ** Helpers
  , mkIntegral
  , mkRational
  , mkFixed
  , mkRealNum
  , mkInteger
  , mkIntNum
  , mkBitvector
  , mkBvNum

  -- * Sequences and regular expressions
  , mkSeqSort
  , isSeqSort
  , mkReSort
  , isReSort
  , mkStringSort
  , isStringSort
  , mkString
  , isString
  , getString
  , mkSeqEmpty
  , mkSeqUnit
  , mkSeqConcat
  , mkSeqPrefix
  , mkSeqSuffix
  , mkSeqContains
  , mkStrLt
  , mkStrLe
  , mkSeqExtract
  , mkSeqReplace
  , mkSeqAt
  , mkSeqLength
  , mkSeqIndex
  , mkStrToInt
  , mkIntToStr
  , mkSeqToRe
  , mkSeqInRe
  , mkRePlus
  , mkReStar
  , mkReOption
  , mkReUnion
  , mkReConcat
  , mkReRange
  , mkReLoop
  , mkReIntersect
  , mkReComplement
  , mkReEmpty
  , mkReFull

  -- * Quantifiers
  , mkPattern
  , mkBound
  , mkForall
  , mkForallW
  , mkExists
  , mkExistsW
  , mkForallConst
  , mkForallWConst
  , mkExistsConst
  , mkExistsWConst

  -- * Accessors
  , getSymbolString
  , isEqSort
  , getSortName
  , sortToAst
  , getSortId
  , getSortKind
  , getBvSortSize
  , getFiniteDomainSortSize
  , getTupleSortMkDecl
  , getTupleSortNumFields
  , getTupleSortFieldDecl
  , getDatatypeSortConstructors
  , getDatatypeSortRecognizers
  , getDatatypeSortConstructorAccessors
  , mkAtMost
  , mkAtLeast
  , getDeclName
  , getArity
  , getDomain
  , getRange
  , getDeclNumParameters
  , appToAst
  , getAppDecl
  , getAppNumArgs
  , getAppArg
  , getAppArgs
  , getSort
  , isWellSorted
  , getArraySortDomain
  , getArraySortRange
  , getBoolValue
  , getAstKind
  , isApp
  , toApp
  , getNumeralString
  , getNumerator
  , getDenominator
  , simplify
  , simplifyEx
  , getIndexValue
  , isQuantifierForall
  , isQuantifierExists
  , getQuantifierWeight
  , getQuantifierNumPatterns
  , getQuantifierPatternAST
  , getQuantifierPatterns
  , getQuantifierNumNoPatterns
  , getQuantifierNoPatternAST
  , getQuantifierNoPatterns
  , getQuantifierNumBound
  , getQuantifierBoundName
  , getQuantifierBoundSort
  , getQuantifierBoundVars
  , getQuantifierBody
  -- ** Helpers
  , getBool
  , getInt
  , getReal

  -- * Modifiers
  , substituteVars
  , substitute

  -- * Models
  , modelTranslate
  , modelEval
  , evalArray
  , getConstInterp
  , getFuncInterp
  , hasInterp
  , numConsts
  , numFuncs
  , getConstDecl
  , getFuncDecl
  , getConsts
  , getFuncs
  , isAsArray
  , isEqAST
  , addFuncInterp
  , addConstInterp
  , getAsArrayFuncDecl
  , funcInterpGetNumEntries
  , funcInterpGetEntry
  , funcInterpGetElse
  , funcInterpGetArity
  , funcEntryGetValue
  , funcEntryGetNumArgs
  , funcEntryGetArg
  , modelToString
  , showModel
  -- ** Helpers
  , EvalAst
  , eval
  , evalBool
  , evalInt
  , evalReal
  , evalBv
  , mapEval
  , evalT
  , FuncModel (..)
  , evalFunc

  -- * Tactics
  , mkTactic
  , andThenTactic
  , orElseTactic
  , skipTactic
  , tryForTactic
  , tacticUsingParams
  , repeatTactic
  , mkQuantifierEliminationTactic
  , mkAndInverterGraphTactic
  , applyTactic
  , applyResultToString
  , getApplyResultNumSubgoals
  , getApplyResultSubgoal
  , getApplyResultSubgoals
  , mkGoal
  , goalAssert
  , getGoalSize
  , getGoalFormula
  , getGoalFormulas
  , goalToString
  , convertModel

  -- * String Conversion
  , ASTPrintMode(..)
  , setASTPrintMode
  , astToString
  , patternToString
  , sortToString
  , funcDeclToString
  , benchmarkToSMTLibString

  -- * Parser interface
  , parseSMTLib2String
  , parseSMTLib2File
  , evalSMTLib2String

  -- * Error Handling
  , Z3Error(..)
  , Z3ErrorCode(..)

  -- * Miscellaneous
  , Version(..)
  , getVersion

  -- * Fixedpoint
  , Fixedpoint (..)
  , mkFixedpoint
  , fixedpointAddRule
  , fixedpointSetParams
  , fixedpointRegisterRelation
  , fixedpointQueryRelations
  , fixedpointGetAnswer
  , fixedpointGetAssertions

  -- * Floating-Point Arithmetic
  , mkFpaRoundingModeSort
  , mkFpaRoundNearestTiesToEven
  , mkFpaRne
  , mkFpaRoundNearestTiesToAway
  , mkFpaRna
  , mkFpaRoundTowardPositive
  , mkFpaRtp
  , mkFpaRoundTowardNegative
  , mkFpaRtn
  , mkFpaRoundTowardZero
  , mkFpaRtz
  , mkFpaSort
  , mkFpaSortHalf
  , mkFpaSort16
  , mkFpaSortSingle
  , mkFpaSort32
  , mkFpaSortDouble
  , mkFpaSort64
  , mkFpaSortQuadruple
  , mkFpaSort128
  , mkFpaNaN
  , mkFpaInf
  , mkFpaZero
  , mkFpaFp
  , mkFpaNumeralFloat
  , mkFpaNumeralDouble
  , mkFpaNumeralInt
  , mkFpaNumeralIntUInt
  , mkFpaNumeralInt64UInt64
  , mkFpaAbs
  , mkFpaNeg
  , mkFpaAdd
  , mkFpaSub
  , mkFpaMul
  , mkFpaDiv
  , mkFpaFma
  , mkFpaSqrt
  , mkFpaRem
  , mkFpaRoundToIntegral
  , mkFpaMin
  , mkFpaMax
  , mkFpaLeq
  , mkFpaLt
  , mkFpaGeq
  , mkFpaGt
  , mkFpaEq
  , mkFpaIsNormal
  , mkFpaIsSubnormal
  , mkFpaIsZero
  , mkFpaIsInfinite
  , mkFpaIsNaN
  , mkFpaIsNegative
  , mkFpaIsPositive
  , mkFpaToFpBv
  , mkFpaToFpFloat
  , mkFpaToFpReal
  , mkFpaToFpSigned
  , mkFpaToFpUnsigned
  , mkFpaToUbv
  , mkFpaToSbv
  , mkFpaToReal

  -- * Z3-specific floating-point extensions
  , fpaGetEbits
  , fpaGetSbits
  , fpaIsNumeralNaN
  , fpaIsNumeralInf
  , fpaIsNumeralZero
  , fpaIsNumeralNormal
  , fpaIsNumeralSubnormal
  , fpaIsNumeralPositive
  , fpaIsNumeralNegative
  , fpaGetNumeralSignBv
  , fpaGetNumeralSignificandBv
  , fpaGetNumeralSignificandString
  , fpaGetNumeralExponentString
  , fpaGetNumeralExponentBv
  , mkFpaToIEEEBv
  , mkFpaToFpIntReal

  -- * Optimization
  , Optimize (..)
  , mkOptimize
  , optimizeAssert
  , optimizeAssertAndTrack
  , optimizeAssertSoft
  , optimizeMaximize
  , optimizeMinimize
  , optimizePush
  , optimizePop
  , optimizeCheck
  , optimizeGetReasonUnknown
  , optimizeGetModel
  , optimizeGetUnsatCore
  , optimizeSetParams
  , optimizeGetLower
  , optimizeGetUpper
  , optimizeGetUpperAsVector
  , optimizeGetLowerAsVector
  , optimizeToString
  , optimizeFromString
  , optimizeFromFile
  , optimizeGetHelp
  , optimizeGetAssertions
  , optimizeGetObjectives

  -- * Solvers
  , Logic(..)
  , mkSolver
  , mkSimpleSolver
  , mkSolverForLogic
  , solverGetHelp
  , solverSetParams
  , solverPush
  , solverPop
  , solverReset
  , solverGetNumScopes
  , solverAssertCnstr
  , solverAssertAndTrack
  , solverFromFile
  , solverFromString
  , solverGetAssertions
  , solverCheck
  , solverCheckAssumptions
  , solverGetModel
  , solverGetProof
  , solverGetUnsatCore
  , solverGetReasonUnknown
  , solverToString
  -- ** Helpers
  , solverCheckAndGetModel
  ) where

import Z3.Base.C
import Z3.Common
import Z3.RLock ( RLock, new, with)

import Control.Applicative ( (<$>), (<*>), (<*), pure )
import Control.Exception ( Exception, bracket, throw )
import Control.Monad ( join, when, forM )
import Data.Fixed ( Fixed, HasResolution )
import Data.Foldable ( Foldable (..) )
import Data.Int
import Data.IORef ( IORef, newIORef, atomicModifyIORef' )
import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
import Data.Maybe ( fromJust )
import Data.Ratio ( numerator, denominator, (%) )
import Data.Traversable ( Traversable )
import qualified Data.Traversable as T
import Data.Typeable ( Typeable )
import Data.Word
import Foreign hiding ( toBool, newForeignPtr )
import Foreign.Storable ( peek )
import Foreign.C
  ( CFloat, CDouble, CInt, CUInt, CLong, CULong, CLLong, CULLong, CString
  , peekCString
  , withCString )
import Foreign.Concurrent

---------------------------------------------------------------------
-- * Types

-- | A Z3 /configuration object/.
newtype Config = Config { Config -> Ptr Z3_config
unConfig :: Ptr Z3_config }
    deriving Config -> Config -> Bool
(Config -> Config -> Bool)
-> (Config -> Config -> Bool) -> Eq Config
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Config -> Config -> Bool
== :: Config -> Config -> Bool
$c/= :: Config -> Config -> Bool
/= :: Config -> Config -> Bool
Eq

-- | A Z3 /logical context/.
data Context =
    Context {
      Context -> ForeignPtr Z3_context
unContext :: ForeignPtr Z3_context
    , Context -> IORef Word
refCount  :: !(IORef Word)
    , Context -> RLock
lock :: RLock
    }
    deriving Context -> Context -> Bool
(Context -> Context -> Bool)
-> (Context -> Context -> Bool) -> Eq Context
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Context -> Context -> Bool
== :: Context -> Context -> Bool
$c/= :: Context -> Context -> Bool
/= :: Context -> Context -> Bool
Eq

-- | A Z3 /symbol/.
--
-- Used to name types, constants and functions.
newtype Symbol = Symbol { Symbol -> Ptr Z3_symbol
unSymbol :: Ptr Z3_symbol }
    deriving (Symbol -> Symbol -> Bool
(Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Bool) -> Eq Symbol
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Symbol -> Symbol -> Bool
== :: Symbol -> Symbol -> Bool
$c/= :: Symbol -> Symbol -> Bool
/= :: Symbol -> Symbol -> Bool
Eq, Eq Symbol
Eq Symbol
-> (Symbol -> Symbol -> Ordering)
-> (Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Bool)
-> (Symbol -> Symbol -> Symbol)
-> (Symbol -> Symbol -> Symbol)
-> Ord Symbol
Symbol -> Symbol -> Bool
Symbol -> Symbol -> Ordering
Symbol -> Symbol -> Symbol
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 :: Symbol -> Symbol -> Ordering
compare :: Symbol -> Symbol -> Ordering
$c< :: Symbol -> Symbol -> Bool
< :: Symbol -> Symbol -> Bool
$c<= :: Symbol -> Symbol -> Bool
<= :: Symbol -> Symbol -> Bool
$c> :: Symbol -> Symbol -> Bool
> :: Symbol -> Symbol -> Bool
$c>= :: Symbol -> Symbol -> Bool
>= :: Symbol -> Symbol -> Bool
$cmax :: Symbol -> Symbol -> Symbol
max :: Symbol -> Symbol -> Symbol
$cmin :: Symbol -> Symbol -> Symbol
min :: Symbol -> Symbol -> Symbol
Ord, Int -> Symbol -> ShowS
[Symbol] -> ShowS
Symbol -> String
(Int -> Symbol -> ShowS)
-> (Symbol -> String) -> ([Symbol] -> ShowS) -> Show Symbol
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Symbol -> ShowS
showsPrec :: Int -> Symbol -> ShowS
$cshow :: Symbol -> String
show :: Symbol -> String
$cshowList :: [Symbol] -> ShowS
showList :: [Symbol] -> ShowS
Show, Ptr Symbol -> IO Symbol
Ptr Symbol -> Int -> IO Symbol
Ptr Symbol -> Int -> Symbol -> IO ()
Ptr Symbol -> Symbol -> IO ()
Symbol -> Int
(Symbol -> Int)
-> (Symbol -> Int)
-> (Ptr Symbol -> Int -> IO Symbol)
-> (Ptr Symbol -> Int -> Symbol -> IO ())
-> (forall b. Ptr b -> Int -> IO Symbol)
-> (forall b. Ptr b -> Int -> Symbol -> IO ())
-> (Ptr Symbol -> IO Symbol)
-> (Ptr Symbol -> Symbol -> IO ())
-> Storable Symbol
forall b. Ptr b -> Int -> IO Symbol
forall b. Ptr b -> Int -> Symbol -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: Symbol -> Int
sizeOf :: Symbol -> Int
$calignment :: Symbol -> Int
alignment :: Symbol -> Int
$cpeekElemOff :: Ptr Symbol -> Int -> IO Symbol
peekElemOff :: Ptr Symbol -> Int -> IO Symbol
$cpokeElemOff :: Ptr Symbol -> Int -> Symbol -> IO ()
pokeElemOff :: Ptr Symbol -> Int -> Symbol -> IO ()
$cpeekByteOff :: forall b. Ptr b -> Int -> IO Symbol
peekByteOff :: forall b. Ptr b -> Int -> IO Symbol
$cpokeByteOff :: forall b. Ptr b -> Int -> Symbol -> IO ()
pokeByteOff :: forall b. Ptr b -> Int -> Symbol -> IO ()
$cpeek :: Ptr Symbol -> IO Symbol
peek :: Ptr Symbol -> IO Symbol
$cpoke :: Ptr Symbol -> Symbol -> IO ()
poke :: Ptr Symbol -> Symbol -> IO ()
Storable)

-- | A Z3 /AST node/.
--
-- This is the data-structure used in Z3 to represent terms, formulas and types.
newtype AST = AST { AST -> ForeignPtr Z3_ast
unAST :: ForeignPtr Z3_ast }
    deriving (AST -> AST -> Bool
(AST -> AST -> Bool) -> (AST -> AST -> Bool) -> Eq AST
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AST -> AST -> Bool
== :: AST -> AST -> Bool
$c/= :: AST -> AST -> Bool
/= :: AST -> AST -> Bool
Eq, Eq AST
Eq AST
-> (AST -> AST -> Ordering)
-> (AST -> AST -> Bool)
-> (AST -> AST -> Bool)
-> (AST -> AST -> Bool)
-> (AST -> AST -> Bool)
-> (AST -> AST -> AST)
-> (AST -> AST -> AST)
-> Ord AST
AST -> AST -> Bool
AST -> AST -> Ordering
AST -> AST -> AST
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 :: AST -> AST -> Ordering
compare :: AST -> AST -> Ordering
$c< :: AST -> AST -> Bool
< :: AST -> AST -> Bool
$c<= :: AST -> AST -> Bool
<= :: AST -> AST -> Bool
$c> :: AST -> AST -> Bool
> :: AST -> AST -> Bool
$c>= :: AST -> AST -> Bool
>= :: AST -> AST -> Bool
$cmax :: AST -> AST -> AST
max :: AST -> AST -> AST
$cmin :: AST -> AST -> AST
min :: AST -> AST -> AST
Ord, Int -> AST -> ShowS
[AST] -> ShowS
AST -> String
(Int -> AST -> ShowS)
-> (AST -> String) -> ([AST] -> ShowS) -> Show AST
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AST -> ShowS
showsPrec :: Int -> AST -> ShowS
$cshow :: AST -> String
show :: AST -> String
$cshowList :: [AST] -> ShowS
showList :: [AST] -> ShowS
Show, Typeable)

-- | A kind of AST representing /types/.
newtype Sort = Sort { Sort -> ForeignPtr Z3_sort
unSort :: ForeignPtr Z3_sort }
    deriving (Sort -> Sort -> Bool
(Sort -> Sort -> Bool) -> (Sort -> Sort -> Bool) -> Eq Sort
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Sort -> Sort -> Bool
== :: Sort -> Sort -> Bool
$c/= :: Sort -> Sort -> Bool
/= :: Sort -> Sort -> Bool
Eq, Eq Sort
Eq Sort
-> (Sort -> Sort -> Ordering)
-> (Sort -> Sort -> Bool)
-> (Sort -> Sort -> Bool)
-> (Sort -> Sort -> Bool)
-> (Sort -> Sort -> Bool)
-> (Sort -> Sort -> Sort)
-> (Sort -> Sort -> Sort)
-> Ord Sort
Sort -> Sort -> Bool
Sort -> Sort -> Ordering
Sort -> Sort -> Sort
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 :: Sort -> Sort -> Ordering
compare :: Sort -> Sort -> Ordering
$c< :: Sort -> Sort -> Bool
< :: Sort -> Sort -> Bool
$c<= :: Sort -> Sort -> Bool
<= :: Sort -> Sort -> Bool
$c> :: Sort -> Sort -> Bool
> :: Sort -> Sort -> Bool
$c>= :: Sort -> Sort -> Bool
>= :: Sort -> Sort -> Bool
$cmax :: Sort -> Sort -> Sort
max :: Sort -> Sort -> Sort
$cmin :: Sort -> Sort -> Sort
min :: Sort -> Sort -> Sort
Ord, Int -> Sort -> ShowS
[Sort] -> ShowS
Sort -> String
(Int -> Sort -> ShowS)
-> (Sort -> String) -> ([Sort] -> ShowS) -> Show Sort
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Sort -> ShowS
showsPrec :: Int -> Sort -> ShowS
$cshow :: Sort -> String
show :: Sort -> String
$cshowList :: [Sort] -> ShowS
showList :: [Sort] -> ShowS
Show)

-- | A sort representing named tuples with associated functions
data TupleType
  = TupleType {
      TupleType -> Sort
tupleSort :: Sort
    , TupleType -> FuncDecl
tupleCons :: FuncDecl                   -- ^ constructor function
    , TupleType -> [(String, FuncDecl)]
namedTupleProjs :: [(String, FuncDecl)] -- ^ projection functions
    }

tupleProjs :: TupleType -> [FuncDecl]
tupleProjs :: TupleType -> [FuncDecl]
tupleProjs = ((String, FuncDecl) -> FuncDecl)
-> [(String, FuncDecl)] -> [FuncDecl]
forall a b. (a -> b) -> [a] -> [b]
map (String, FuncDecl) -> FuncDecl
forall a b. (a, b) -> b
snd ([(String, FuncDecl)] -> [FuncDecl])
-> (TupleType -> [(String, FuncDecl)]) -> TupleType -> [FuncDecl]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupleType -> [(String, FuncDecl)]
namedTupleProjs

-- | A kind of AST representing function symbols.
newtype FuncDecl = FuncDecl { FuncDecl -> ForeignPtr Z3_func_decl
unFuncDecl :: ForeignPtr Z3_func_decl }
    deriving (FuncDecl -> FuncDecl -> Bool
(FuncDecl -> FuncDecl -> Bool)
-> (FuncDecl -> FuncDecl -> Bool) -> Eq FuncDecl
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FuncDecl -> FuncDecl -> Bool
== :: FuncDecl -> FuncDecl -> Bool
$c/= :: FuncDecl -> FuncDecl -> Bool
/= :: FuncDecl -> FuncDecl -> Bool
Eq, Eq FuncDecl
Eq FuncDecl
-> (FuncDecl -> FuncDecl -> Ordering)
-> (FuncDecl -> FuncDecl -> Bool)
-> (FuncDecl -> FuncDecl -> Bool)
-> (FuncDecl -> FuncDecl -> Bool)
-> (FuncDecl -> FuncDecl -> Bool)
-> (FuncDecl -> FuncDecl -> FuncDecl)
-> (FuncDecl -> FuncDecl -> FuncDecl)
-> Ord FuncDecl
FuncDecl -> FuncDecl -> Bool
FuncDecl -> FuncDecl -> Ordering
FuncDecl -> FuncDecl -> FuncDecl
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 :: FuncDecl -> FuncDecl -> Ordering
compare :: FuncDecl -> FuncDecl -> Ordering
$c< :: FuncDecl -> FuncDecl -> Bool
< :: FuncDecl -> FuncDecl -> Bool
$c<= :: FuncDecl -> FuncDecl -> Bool
<= :: FuncDecl -> FuncDecl -> Bool
$c> :: FuncDecl -> FuncDecl -> Bool
> :: FuncDecl -> FuncDecl -> Bool
$c>= :: FuncDecl -> FuncDecl -> Bool
>= :: FuncDecl -> FuncDecl -> Bool
$cmax :: FuncDecl -> FuncDecl -> FuncDecl
max :: FuncDecl -> FuncDecl -> FuncDecl
$cmin :: FuncDecl -> FuncDecl -> FuncDecl
min :: FuncDecl -> FuncDecl -> FuncDecl
Ord, Int -> FuncDecl -> ShowS
[FuncDecl] -> ShowS
FuncDecl -> String
(Int -> FuncDecl -> ShowS)
-> (FuncDecl -> String) -> ([FuncDecl] -> ShowS) -> Show FuncDecl
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FuncDecl -> ShowS
showsPrec :: Int -> FuncDecl -> ShowS
$cshow :: FuncDecl -> String
show :: FuncDecl -> String
$cshowList :: [FuncDecl] -> ShowS
showList :: [FuncDecl] -> ShowS
Show, Typeable)

-- | A kind of AST representing constant and function declarations.
newtype App = App { App -> ForeignPtr Z3_app
unApp :: ForeignPtr Z3_app }
    deriving (App -> App -> Bool
(App -> App -> Bool) -> (App -> App -> Bool) -> Eq App
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: App -> App -> Bool
== :: App -> App -> Bool
$c/= :: App -> App -> Bool
/= :: App -> App -> Bool
Eq, Eq App
Eq App
-> (App -> App -> Ordering)
-> (App -> App -> Bool)
-> (App -> App -> Bool)
-> (App -> App -> Bool)
-> (App -> App -> Bool)
-> (App -> App -> App)
-> (App -> App -> App)
-> Ord App
App -> App -> Bool
App -> App -> Ordering
App -> App -> App
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 :: App -> App -> Ordering
compare :: App -> App -> Ordering
$c< :: App -> App -> Bool
< :: App -> App -> Bool
$c<= :: App -> App -> Bool
<= :: App -> App -> Bool
$c> :: App -> App -> Bool
> :: App -> App -> Bool
$c>= :: App -> App -> Bool
>= :: App -> App -> Bool
$cmax :: App -> App -> App
max :: App -> App -> App
$cmin :: App -> App -> App
min :: App -> App -> App
Ord, Int -> App -> ShowS
[App] -> ShowS
App -> String
(Int -> App -> ShowS)
-> (App -> String) -> ([App] -> ShowS) -> Show App
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> App -> ShowS
showsPrec :: Int -> App -> ShowS
$cshow :: App -> String
show :: App -> String
$cshowList :: [App] -> ShowS
showList :: [App] -> ShowS
Show)

-- | A kind of AST representing pattern and multi-patterns to
-- guide quantifier instantiation.
newtype Pattern = Pattern { Pattern -> ForeignPtr Z3_pattern
unPattern :: ForeignPtr Z3_pattern }
    deriving (Pattern -> Pattern -> Bool
(Pattern -> Pattern -> Bool)
-> (Pattern -> Pattern -> Bool) -> Eq Pattern
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Pattern -> Pattern -> Bool
== :: Pattern -> Pattern -> Bool
$c/= :: Pattern -> Pattern -> Bool
/= :: Pattern -> Pattern -> Bool
Eq, Eq Pattern
Eq Pattern
-> (Pattern -> Pattern -> Ordering)
-> (Pattern -> Pattern -> Bool)
-> (Pattern -> Pattern -> Bool)
-> (Pattern -> Pattern -> Bool)
-> (Pattern -> Pattern -> Bool)
-> (Pattern -> Pattern -> Pattern)
-> (Pattern -> Pattern -> Pattern)
-> Ord Pattern
Pattern -> Pattern -> Bool
Pattern -> Pattern -> Ordering
Pattern -> Pattern -> Pattern
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 :: Pattern -> Pattern -> Ordering
compare :: Pattern -> Pattern -> Ordering
$c< :: Pattern -> Pattern -> Bool
< :: Pattern -> Pattern -> Bool
$c<= :: Pattern -> Pattern -> Bool
<= :: Pattern -> Pattern -> Bool
$c> :: Pattern -> Pattern -> Bool
> :: Pattern -> Pattern -> Bool
$c>= :: Pattern -> Pattern -> Bool
>= :: Pattern -> Pattern -> Bool
$cmax :: Pattern -> Pattern -> Pattern
max :: Pattern -> Pattern -> Pattern
$cmin :: Pattern -> Pattern -> Pattern
min :: Pattern -> Pattern -> Pattern
Ord, Int -> Pattern -> ShowS
[Pattern] -> ShowS
Pattern -> String
(Int -> Pattern -> ShowS)
-> (Pattern -> String) -> ([Pattern] -> ShowS) -> Show Pattern
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Pattern -> ShowS
showsPrec :: Int -> Pattern -> ShowS
$cshow :: Pattern -> String
show :: Pattern -> String
$cshowList :: [Pattern] -> ShowS
showList :: [Pattern] -> ShowS
Show)

-- | A type contructor for a (recursive) datatype.
newtype Constructor = Constructor { Constructor -> ForeignPtr Z3_constructor
unConstructor :: ForeignPtr Z3_constructor }
    deriving (Constructor -> Constructor -> Bool
(Constructor -> Constructor -> Bool)
-> (Constructor -> Constructor -> Bool) -> Eq Constructor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Constructor -> Constructor -> Bool
== :: Constructor -> Constructor -> Bool
$c/= :: Constructor -> Constructor -> Bool
/= :: Constructor -> Constructor -> Bool
Eq, Eq Constructor
Eq Constructor
-> (Constructor -> Constructor -> Ordering)
-> (Constructor -> Constructor -> Bool)
-> (Constructor -> Constructor -> Bool)
-> (Constructor -> Constructor -> Bool)
-> (Constructor -> Constructor -> Bool)
-> (Constructor -> Constructor -> Constructor)
-> (Constructor -> Constructor -> Constructor)
-> Ord Constructor
Constructor -> Constructor -> Bool
Constructor -> Constructor -> Ordering
Constructor -> Constructor -> Constructor
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 :: Constructor -> Constructor -> Ordering
compare :: Constructor -> Constructor -> Ordering
$c< :: Constructor -> Constructor -> Bool
< :: Constructor -> Constructor -> Bool
$c<= :: Constructor -> Constructor -> Bool
<= :: Constructor -> Constructor -> Bool
$c> :: Constructor -> Constructor -> Bool
> :: Constructor -> Constructor -> Bool
$c>= :: Constructor -> Constructor -> Bool
>= :: Constructor -> Constructor -> Bool
$cmax :: Constructor -> Constructor -> Constructor
max :: Constructor -> Constructor -> Constructor
$cmin :: Constructor -> Constructor -> Constructor
min :: Constructor -> Constructor -> Constructor
Ord, Int -> Constructor -> ShowS
[Constructor] -> ShowS
Constructor -> String
(Int -> Constructor -> ShowS)
-> (Constructor -> String)
-> ([Constructor] -> ShowS)
-> Show Constructor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Constructor -> ShowS
showsPrec :: Int -> Constructor -> ShowS
$cshow :: Constructor -> String
show :: Constructor -> String
$cshowList :: [Constructor] -> ShowS
showList :: [Constructor] -> ShowS
Show)

-- | A list of type contructors for (recursive) datatypes.
newtype ConstructorList = ConstructorList { ConstructorList -> ForeignPtr Z3_constructor_list
unConstructorList :: ForeignPtr Z3_constructor_list }
    deriving (ConstructorList -> ConstructorList -> Bool
(ConstructorList -> ConstructorList -> Bool)
-> (ConstructorList -> ConstructorList -> Bool)
-> Eq ConstructorList
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConstructorList -> ConstructorList -> Bool
== :: ConstructorList -> ConstructorList -> Bool
$c/= :: ConstructorList -> ConstructorList -> Bool
/= :: ConstructorList -> ConstructorList -> Bool
Eq, Eq ConstructorList
Eq ConstructorList
-> (ConstructorList -> ConstructorList -> Ordering)
-> (ConstructorList -> ConstructorList -> Bool)
-> (ConstructorList -> ConstructorList -> Bool)
-> (ConstructorList -> ConstructorList -> Bool)
-> (ConstructorList -> ConstructorList -> Bool)
-> (ConstructorList -> ConstructorList -> ConstructorList)
-> (ConstructorList -> ConstructorList -> ConstructorList)
-> Ord ConstructorList
ConstructorList -> ConstructorList -> Bool
ConstructorList -> ConstructorList -> Ordering
ConstructorList -> ConstructorList -> ConstructorList
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 :: ConstructorList -> ConstructorList -> Ordering
compare :: ConstructorList -> ConstructorList -> Ordering
$c< :: ConstructorList -> ConstructorList -> Bool
< :: ConstructorList -> ConstructorList -> Bool
$c<= :: ConstructorList -> ConstructorList -> Bool
<= :: ConstructorList -> ConstructorList -> Bool
$c> :: ConstructorList -> ConstructorList -> Bool
> :: ConstructorList -> ConstructorList -> Bool
$c>= :: ConstructorList -> ConstructorList -> Bool
>= :: ConstructorList -> ConstructorList -> Bool
$cmax :: ConstructorList -> ConstructorList -> ConstructorList
max :: ConstructorList -> ConstructorList -> ConstructorList
$cmin :: ConstructorList -> ConstructorList -> ConstructorList
min :: ConstructorList -> ConstructorList -> ConstructorList
Ord, Int -> ConstructorList -> ShowS
[ConstructorList] -> ShowS
ConstructorList -> String
(Int -> ConstructorList -> ShowS)
-> (ConstructorList -> String)
-> ([ConstructorList] -> ShowS)
-> Show ConstructorList
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConstructorList -> ShowS
showsPrec :: Int -> ConstructorList -> ShowS
$cshow :: ConstructorList -> String
show :: ConstructorList -> String
$cshowList :: [ConstructorList] -> ShowS
showList :: [ConstructorList] -> ShowS
Show)

-- | A model for the constraints asserted into the logical context.
newtype Model = Model { Model -> ForeignPtr Z3_model
unModel :: ForeignPtr Z3_model }
    deriving Model -> Model -> Bool
(Model -> Model -> Bool) -> (Model -> Model -> Bool) -> Eq Model
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Model -> Model -> Bool
== :: Model -> Model -> Bool
$c/= :: Model -> Model -> Bool
/= :: Model -> Model -> Bool
Eq

-- | An interpretation of a function in a model.
newtype FuncInterp = FuncInterp { FuncInterp -> ForeignPtr Z3_func_interp
unFuncInterp :: ForeignPtr Z3_func_interp }
    deriving FuncInterp -> FuncInterp -> Bool
(FuncInterp -> FuncInterp -> Bool)
-> (FuncInterp -> FuncInterp -> Bool) -> Eq FuncInterp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FuncInterp -> FuncInterp -> Bool
== :: FuncInterp -> FuncInterp -> Bool
$c/= :: FuncInterp -> FuncInterp -> Bool
/= :: FuncInterp -> FuncInterp -> Bool
Eq

-- | Representation of the value of a 'Z3_func_interp' at a particular point.
newtype FuncEntry = FuncEntry { FuncEntry -> ForeignPtr Z3_func_entry
unFuncEntry :: ForeignPtr Z3_func_entry }
    deriving FuncEntry -> FuncEntry -> Bool
(FuncEntry -> FuncEntry -> Bool)
-> (FuncEntry -> FuncEntry -> Bool) -> Eq FuncEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FuncEntry -> FuncEntry -> Bool
== :: FuncEntry -> FuncEntry -> Bool
$c/= :: FuncEntry -> FuncEntry -> Bool
/= :: FuncEntry -> FuncEntry -> Bool
Eq

-- | A tactic
newtype Tactic = Tactic { Tactic -> ForeignPtr Z3_tactic
unTactic :: ForeignPtr Z3_tactic }
    deriving Tactic -> Tactic -> Bool
(Tactic -> Tactic -> Bool)
-> (Tactic -> Tactic -> Bool) -> Eq Tactic
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Tactic -> Tactic -> Bool
== :: Tactic -> Tactic -> Bool
$c/= :: Tactic -> Tactic -> Bool
/= :: Tactic -> Tactic -> Bool
Eq

-- | A goal (aka problem)
newtype Goal = Goal { Goal -> ForeignPtr Z3_goal
unGoal :: ForeignPtr Z3_goal }
    deriving Goal -> Goal -> Bool
(Goal -> Goal -> Bool) -> (Goal -> Goal -> Bool) -> Eq Goal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Goal -> Goal -> Bool
== :: Goal -> Goal -> Bool
$c/= :: Goal -> Goal -> Bool
/= :: Goal -> Goal -> Bool
Eq

-- | A result of applying a tactic
newtype ApplyResult = ApplyResult { ApplyResult -> ForeignPtr Z3_apply_result
unApplyResult :: ForeignPtr Z3_apply_result }
    deriving ApplyResult -> ApplyResult -> Bool
(ApplyResult -> ApplyResult -> Bool)
-> (ApplyResult -> ApplyResult -> Bool) -> Eq ApplyResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ApplyResult -> ApplyResult -> Bool
== :: ApplyResult -> ApplyResult -> Bool
$c/= :: ApplyResult -> ApplyResult -> Bool
/= :: ApplyResult -> ApplyResult -> Bool
Eq

-- | A Z3 parameter set.
--
-- Starting at Z3 4.0, parameter sets are used to configure many components
-- such as: simplifiers, tactics, solvers, etc.
newtype Params = Params { Params -> ForeignPtr Z3_params
unParams :: ForeignPtr Z3_params }
    deriving Params -> Params -> Bool
(Params -> Params -> Bool)
-> (Params -> Params -> Bool) -> Eq Params
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Params -> Params -> Bool
== :: Params -> Params -> Bool
$c/= :: Params -> Params -> Bool
/= :: Params -> Params -> Bool
Eq

-- | A Z3 solver engine.
--
-- A(n) (incremental) solver, possibly specialized by a particular tactic
-- or logic.
newtype Solver = Solver { Solver -> ForeignPtr Z3_solver
unSolver :: ForeignPtr Z3_solver }
    deriving Solver -> Solver -> Bool
(Solver -> Solver -> Bool)
-> (Solver -> Solver -> Bool) -> Eq Solver
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Solver -> Solver -> Bool
== :: Solver -> Solver -> Bool
$c/= :: Solver -> Solver -> Bool
/= :: Solver -> Solver -> Bool
Eq

-- | Result of a satisfiability check.
--
-- This corresponds to the /z3_lbool/ type in the C API.
data Result
    = Sat
    | Unsat
    | Undef
    deriving (Result -> Result -> Bool
(Result -> Result -> Bool)
-> (Result -> Result -> Bool) -> Eq Result
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Result -> Result -> Bool
== :: Result -> Result -> Bool
$c/= :: Result -> Result -> Bool
/= :: Result -> Result -> Bool
Eq, Eq Result
Eq Result
-> (Result -> Result -> Ordering)
-> (Result -> Result -> Bool)
-> (Result -> Result -> Bool)
-> (Result -> Result -> Bool)
-> (Result -> Result -> Bool)
-> (Result -> Result -> Result)
-> (Result -> Result -> Result)
-> Ord Result
Result -> Result -> Bool
Result -> Result -> Ordering
Result -> Result -> Result
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 :: Result -> Result -> Ordering
compare :: Result -> Result -> Ordering
$c< :: Result -> Result -> Bool
< :: Result -> Result -> Bool
$c<= :: Result -> Result -> Bool
<= :: Result -> Result -> Bool
$c> :: Result -> Result -> Bool
> :: Result -> Result -> Bool
$c>= :: Result -> Result -> Bool
>= :: Result -> Result -> Bool
$cmax :: Result -> Result -> Result
max :: Result -> Result -> Result
$cmin :: Result -> Result -> Result
min :: Result -> Result -> Result
Ord, ReadPrec [Result]
ReadPrec Result
Int -> ReadS Result
ReadS [Result]
(Int -> ReadS Result)
-> ReadS [Result]
-> ReadPrec Result
-> ReadPrec [Result]
-> Read Result
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Result
readsPrec :: Int -> ReadS Result
$creadList :: ReadS [Result]
readList :: ReadS [Result]
$creadPrec :: ReadPrec Result
readPrec :: ReadPrec Result
$creadListPrec :: ReadPrec [Result]
readListPrec :: ReadPrec [Result]
Read, Int -> Result -> ShowS
[Result] -> ShowS
Result -> String
(Int -> Result -> ShowS)
-> (Result -> String) -> ([Result] -> ShowS) -> Show Result
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Result -> ShowS
showsPrec :: Int -> Result -> ShowS
$cshow :: Result -> String
show :: Result -> String
$cshowList :: [Result] -> ShowS
showList :: [Result] -> ShowS
Show)

-- | Different kinds of Z3 types.
data SortKind
    = Z3_UNINTERPRETED_SORT
    | Z3_BOOL_SORT
    | Z3_INT_SORT
    | Z3_REAL_SORT
    | Z3_BV_SORT
    | Z3_ARRAY_SORT
    | Z3_DATATYPE_SORT
    | Z3_RELATION_SORT
    | Z3_FINITE_DOMAIN_SORT
    | Z3_FLOATING_POINT_SORT
    | Z3_ROUNDING_MODE_SORT
    | Z3_UNKNOWN_SORT
    deriving (SortKind -> SortKind -> Bool
(SortKind -> SortKind -> Bool)
-> (SortKind -> SortKind -> Bool) -> Eq SortKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SortKind -> SortKind -> Bool
== :: SortKind -> SortKind -> Bool
$c/= :: SortKind -> SortKind -> Bool
/= :: SortKind -> SortKind -> Bool
Eq, Int -> SortKind -> ShowS
[SortKind] -> ShowS
SortKind -> String
(Int -> SortKind -> ShowS)
-> (SortKind -> String) -> ([SortKind] -> ShowS) -> Show SortKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SortKind -> ShowS
showsPrec :: Int -> SortKind -> ShowS
$cshow :: SortKind -> String
show :: SortKind -> String
$cshowList :: [SortKind] -> ShowS
showList :: [SortKind] -> ShowS
Show)

-- | Different kinds of Z3 AST nodes.
data ASTKind
    = Z3_NUMERAL_AST
    | Z3_APP_AST
    | Z3_VAR_AST
    | Z3_QUANTIFIER_AST
    | Z3_SORT_AST
    | Z3_FUNC_DECL_AST
    | Z3_UNKNOWN_AST
    deriving (ASTKind -> ASTKind -> Bool
(ASTKind -> ASTKind -> Bool)
-> (ASTKind -> ASTKind -> Bool) -> Eq ASTKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ASTKind -> ASTKind -> Bool
== :: ASTKind -> ASTKind -> Bool
$c/= :: ASTKind -> ASTKind -> Bool
/= :: ASTKind -> ASTKind -> Bool
Eq, Int -> ASTKind -> ShowS
[ASTKind] -> ShowS
ASTKind -> String
(Int -> ASTKind -> ShowS)
-> (ASTKind -> String) -> ([ASTKind] -> ShowS) -> Show ASTKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ASTKind -> ShowS
showsPrec :: Int -> ASTKind -> ShowS
$cshow :: ASTKind -> String
show :: ASTKind -> String
$cshowList :: [ASTKind] -> ShowS
showList :: [ASTKind] -> ShowS
Show)


---------------------------------------------------------------------
-- * Algebraic Numbers

algebraicIsValue :: Context -> AST -> IO Bool
algebraicIsValue :: Context -> AST -> IO Bool
algebraicIsValue = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_is_value


algebraicIsPos :: Context -> AST -> IO Bool
algebraicIsPos :: Context -> AST -> IO Bool
algebraicIsPos = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_is_pos

algebraicIsNeg :: Context -> AST -> IO Bool
algebraicIsNeg :: Context -> AST -> IO Bool
algebraicIsNeg = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_is_neg

algebraicIsZero :: Context -> AST -> IO Bool
algebraicIsZero :: Context -> AST -> IO Bool
algebraicIsZero = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_is_zero

algebraicSign :: Context -> AST -> IO Int
algebraicSign :: Context -> AST -> IO Int
algebraicSign = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_error_code)
-> Context -> AST -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_error_code
z3_algebraic_sign

algebraicAdd :: Context -> AST -> AST -> IO AST
algebraicAdd :: Context -> AST -> AST -> IO AST
algebraicAdd = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_algebraic_add

algebraicSub :: Context -> AST -> AST -> IO AST
algebraicSub :: Context -> AST -> AST -> IO AST
algebraicSub = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_algebraic_sub

algebraicMul :: Context -> AST -> AST -> IO AST
algebraicMul :: Context -> AST -> AST -> IO AST
algebraicMul = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_algebraic_mul

algebraicDiv :: Context -> AST -> AST -> IO AST
algebraicDiv :: Context -> AST -> AST -> IO AST
algebraicDiv = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_algebraic_div

algebraicRoot :: Context -> AST -> Int -> IO AST
algebraicRoot :: Context -> AST -> Int -> IO AST
algebraicRoot = (Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast))
-> Context -> AST -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast)
z3_algebraic_root

algebraicPower :: Context -> AST -> Int -> IO AST
algebraicPower :: Context -> AST -> Int -> IO AST
algebraicPower = (Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast))
-> Context -> AST -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast)
z3_algebraic_power

algebraicLt :: Context -> AST -> AST -> IO Bool
algebraicLt :: Context -> AST -> AST -> IO Bool
algebraicLt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> AST -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_lt

algebraicGt :: Context -> AST -> AST -> IO Bool
algebraicGt :: Context -> AST -> AST -> IO Bool
algebraicGt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> AST -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_gt

algebraicLe :: Context -> AST -> AST -> IO Bool
algebraicLe :: Context -> AST -> AST -> IO Bool
algebraicLe = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> AST -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_le

algebraicGe :: Context -> AST -> AST -> IO Bool
algebraicGe :: Context -> AST -> AST -> IO Bool
algebraicGe = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> AST -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_ge

algebraicEq :: Context -> AST -> AST -> IO Bool
algebraicEq :: Context -> AST -> AST -> IO Bool
algebraicEq = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> AST -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_eq

algebraicNeq :: Context -> AST -> AST -> IO Bool
algebraicNeq :: Context -> AST -> AST -> IO Bool
algebraicNeq = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> AST -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool
z3_algebraic_neq

algebraicRoots :: Context -> AST -> [AST] -> IO [AST]
algebraicRoots :: Context -> AST -> [AST] -> IO [AST]
algebraicRoots Context
ctx AST
p [AST]
args = (Ptr Z3_context
 -> Ptr Z3_ast
 -> CUInt
 -> Ptr (Ptr Z3_ast)
 -> IO (Ptr Z3_ast_vector))
-> Context
-> ((Ptr Z3_ast
     -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast_vector))
    -> IO (Ptr Z3_ast_vector))
-> IO [AST]
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_ast
-> CUInt
-> Ptr (Ptr Z3_ast)
-> IO (Ptr Z3_ast_vector)
z3_algebraic_roots Context
ctx (((Ptr Z3_ast
   -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast_vector))
  -> IO (Ptr Z3_ast_vector))
 -> IO [AST])
-> ((Ptr Z3_ast
     -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast_vector))
    -> IO (Ptr Z3_ast_vector))
-> IO [AST]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast_vector)
f ->
  AST
-> (Ptr Z3_ast -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector)
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
p ((Ptr Z3_ast -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector))
-> (Ptr Z3_ast -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
pPtr ->
    [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
args ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr ->
      Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast_vector)
f Ptr Z3_ast
pPtr CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr

algebraicEval :: Context -> AST -> [AST] -> IO Int
algebraicEval :: Context -> AST -> [AST] -> IO Int
algebraicEval Context
ctx AST
p [AST]
args = (Ptr Z3_context
 -> Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code)
-> Context
-> ((Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code)
    -> IO Z3_error_code)
-> IO Int
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code
z3_algebraic_eval Context
ctx (((Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code)
  -> IO Z3_error_code)
 -> IO Int)
-> ((Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code)
    -> IO Z3_error_code)
-> IO Int
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code
f ->
  AST -> (Ptr Z3_ast -> IO Z3_error_code) -> IO Z3_error_code
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
p ((Ptr Z3_ast -> IO Z3_error_code) -> IO Z3_error_code)
-> (Ptr Z3_ast -> IO Z3_error_code) -> IO Z3_error_code
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
pPtr ->
    [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code)
-> IO Z3_error_code
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
args ((CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code)
 -> IO Z3_error_code)
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code)
-> IO Z3_error_code
forall a b. (a -> b) -> a -> b
$ \CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr ->
      Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_error_code
f Ptr Z3_ast
pPtr CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr

---------------------------------------------------------------------
-- * Global Parameters

globalParamSet :: String -> String -> IO ()
globalParamSet :: String -> String -> IO ()
globalParamSet String
param String
value =
  String -> (Z3_string -> IO ()) -> IO ()
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
param ((Z3_string -> IO ()) -> IO ()) -> (Z3_string -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Z3_string
cParam ->
    String -> (Z3_string -> IO ()) -> IO ()
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
value ((Z3_string -> IO ()) -> IO ()) -> (Z3_string -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Z3_string
cValue ->
      Z3_string -> Z3_string -> IO ()
z3_global_param_set Z3_string
cParam Z3_string
cValue

globalParamResetAll :: IO ()
globalParamResetAll :: IO ()
globalParamResetAll = IO ()
z3_global_param_reset_all

globalParamGet :: String -> IO (Maybe String)
globalParamGet :: String -> IO (Maybe String)
globalParamGet String
param =
  String -> (Z3_string -> IO (Maybe String)) -> IO (Maybe String)
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
param ((Z3_string -> IO (Maybe String)) -> IO (Maybe String))
-> (Z3_string -> IO (Maybe String)) -> IO (Maybe String)
forall a b. (a -> b) -> a -> b
$ \Z3_string
cParam ->
    (Ptr Z3_string -> IO (Maybe String)) -> IO (Maybe String)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Z3_string -> IO (Maybe String)) -> IO (Maybe String))
-> (Ptr Z3_string -> IO (Maybe String)) -> IO (Maybe String)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_string
cValuePtr ->
      do Bool
success <- Z3_bool -> Bool
toBool (Z3_bool -> Bool) -> IO Z3_bool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Z3_string -> Ptr Z3_string -> IO Z3_bool
z3_global_param_get Z3_string
cParam Ptr Z3_string
cValuePtr
         Bool -> IO String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => Bool -> m a -> m (Maybe a)
returnValueToMaybe Bool
success (IO String -> IO (Maybe String)) -> IO String -> IO (Maybe String)
forall a b. (a -> b) -> a -> b
$ Z3_string -> IO String
peekCString (Z3_string -> IO String) -> IO Z3_string -> IO String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Z3_string -> IO Z3_string
forall a. Storable a => Ptr a -> IO a
peek Ptr Z3_string
cValuePtr

---------------------------------------------------------------------
-- * Create configuration

-- | Create a configuration.
--
-- See 'withConfig'.
mkConfig :: IO Config
mkConfig :: IO Config
mkConfig = Ptr Z3_config -> Config
Config (Ptr Z3_config -> Config) -> IO (Ptr Z3_config) -> IO Config
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO (Ptr Z3_config)
z3_mk_config

-- | Delete a configuration.
--
-- See 'withConfig'.
delConfig :: Config -> IO ()
delConfig :: Config -> IO ()
delConfig = Ptr Z3_config -> IO ()
z3_del_config (Ptr Z3_config -> IO ())
-> (Config -> Ptr Z3_config) -> Config -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Config -> Ptr Z3_config
unConfig

-- | Set a configuration parameter.
setParamValue :: Config -> String -> String -> IO ()
setParamValue :: Config -> String -> String -> IO ()
setParamValue Config
cfg String
s1 String
s2 =
  String -> (Z3_string -> IO ()) -> IO ()
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
s1  ((Z3_string -> IO ()) -> IO ()) -> (Z3_string -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Z3_string
cs1 ->
    String -> (Z3_string -> IO ()) -> IO ()
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
s2  ((Z3_string -> IO ()) -> IO ()) -> (Z3_string -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Z3_string
cs2 ->
      Ptr Z3_config -> Z3_string -> Z3_string -> IO ()
z3_set_param_value (Config -> Ptr Z3_config
unConfig Config
cfg) Z3_string
cs1 Z3_string
cs2

-------------------------------------------------
-- ** Helpers

-- | Run a computation using a temporally created configuration.
--
-- Note that the configuration object can be thrown away once
-- it has been used to create the Z3 'Context'.
withConfig :: (Config -> IO a) -> IO a
withConfig :: forall a. (Config -> IO a) -> IO a
withConfig = IO Config -> (Config -> IO ()) -> (Config -> IO a) -> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket IO Config
mkConfig Config -> IO ()
delConfig

---------------------------------------------------------------------
-- Create context

mkContextWith :: (Ptr Z3_config -> IO (Ptr Z3_context)) -> Config -> IO Context
mkContextWith :: (Ptr Z3_config -> IO (Ptr Z3_context)) -> Config -> IO Context
mkContextWith Ptr Z3_config -> IO (Ptr Z3_context)
mkCtx Config
cfg = do
  Ptr Z3_context
ctxPtr <- Ptr Z3_config -> IO (Ptr Z3_context)
mkCtx (Config -> Ptr Z3_config
unConfig Config
cfg)
  Ptr Z3_context -> FunPtr Z3_error_handler -> IO ()
z3_set_error_handler Ptr Z3_context
ctxPtr FunPtr Z3_error_handler
forall a. FunPtr a
nullFunPtr
  IORef Word
count <- Word -> IO (IORef Word)
forall a. a -> IO (IORef a)
newIORef Word
1
  ForeignPtr Z3_context -> IORef Word -> RLock -> Context
Context (ForeignPtr Z3_context -> IORef Word -> RLock -> Context)
-> IO (ForeignPtr Z3_context)
-> IO (IORef Word -> RLock -> Context)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Z3_context -> IO () -> IO (ForeignPtr Z3_context)
forall a. Ptr a -> IO () -> IO (ForeignPtr a)
newForeignPtr Ptr Z3_context
ctxPtr (Ptr Z3_context -> IORef Word -> IO ()
contextDecRef Ptr Z3_context
ctxPtr IORef Word
count)
          IO (IORef Word -> RLock -> Context)
-> IO (IORef Word) -> IO (RLock -> Context)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IORef Word -> IO (IORef Word)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure IORef Word
count
          IO (RLock -> Context) -> IO RLock -> IO Context
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO RLock
Z3.RLock.new

-- | Create a context using the given configuration.
--
-- /Z3_del_context/ is called by Haskell's garbage collector before
-- freeing the 'Context' object.
mkContext :: Config -> IO Context
mkContext :: Config -> IO Context
mkContext = (Ptr Z3_config -> IO (Ptr Z3_context)) -> Config -> IO Context
mkContextWith Ptr Z3_config -> IO (Ptr Z3_context)
z3_mk_context_rc

-- TODO: Z3_update_param_value
-- TODO: Z3_interrupt

-------------------------------------------------
-- Reference counting of Context

contextIncRef :: Context -> IO ()
contextIncRef :: Context -> IO ()
contextIncRef Context
ctx = IORef Word -> (Word -> (Word, ())) -> IO ()
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' (Context -> IORef Word
refCount Context
ctx) ((Word -> (Word, ())) -> IO ()) -> (Word -> (Word, ())) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Word
n ->
  (Word
nWord -> Word -> Word
forall a. Num a => a -> a -> a
+Word
1, ())

contextDecRef :: Ptr Z3_context -> IORef Word -> IO ()
contextDecRef :: Ptr Z3_context -> IORef Word -> IO ()
contextDecRef Ptr Z3_context
ctxPtr IORef Word
count = IO (IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (IO (IO ()) -> IO ()) -> IO (IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ IORef Word -> (Word -> (Word, IO ())) -> IO (IO ())
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef Word
count ((Word -> (Word, IO ())) -> IO (IO ()))
-> (Word -> (Word, IO ())) -> IO (IO ())
forall a b. (a -> b) -> a -> b
$ \Word
n ->
  if Word
n Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
> Word
1
    then (Word
nWord -> Word -> Word
forall a. Num a => a -> a -> a
-Word
1, () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
    else (  Word
0, Ptr Z3_context -> IO ()
z3_del_context Ptr Z3_context
ctxPtr)

---------------------------------------------------------------------
-- Parameters

-- | Create a Z3 (empty) parameter set.
--
-- Starting at Z3 4.0, parameter sets are used to configure many components
-- such as: simplifiers, tactics, solvers, etc.
mkParams :: Context -> IO Params
mkParams :: Context -> IO Params
mkParams = (Ptr Z3_context -> IO (Ptr Z3_params)) -> Context -> IO Params
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_params)
z3_mk_params

-- | Add a Boolean parameter /k/ with value /v/ to the parameter set /p/.
paramsSetBool :: Context -> Params -> Symbol -> Bool -> IO ()
paramsSetBool :: Context -> Params -> Symbol -> Bool -> IO ()
paramsSetBool = (Ptr Z3_context
 -> Ptr Z3_params -> Ptr Z3_symbol -> Z3_bool -> IO ())
-> Context -> Params -> Symbol -> Bool -> IO ()
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_params -> Ptr Z3_symbol -> Z3_bool -> IO ()
z3_params_set_bool

-- | Add a unsigned parameter /k/ with value /v/ to the parameter set /p/.
paramsSetUInt :: Context -> Params -> Symbol -> Word -> IO ()
paramsSetUInt :: Context -> Params -> Symbol -> Word -> IO ()
paramsSetUInt = (Ptr Z3_context
 -> Ptr Z3_params -> Ptr Z3_symbol -> CUInt -> IO ())
-> Context -> Params -> Symbol -> Word -> IO ()
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context -> Ptr Z3_params -> Ptr Z3_symbol -> CUInt -> IO ()
z3_params_set_uint

-- | Add a double parameter /k/ with value /v/ to the parameter set /p/.
paramsSetDouble :: Context -> Params -> Symbol -> Double -> IO ()
paramsSetDouble :: Context -> Params -> Symbol -> Double -> IO ()
paramsSetDouble = (Ptr Z3_context
 -> Ptr Z3_params -> Ptr Z3_symbol -> CDouble -> IO ())
-> Context -> Params -> Symbol -> Double -> IO ()
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_params -> Ptr Z3_symbol -> CDouble -> IO ()
z3_params_set_double

-- | Add a symbol parameter /k/ with value /v/ to the parameter set /p/.
paramsSetSymbol :: Context -> Params -> Symbol -> Symbol -> IO ()
paramsSetSymbol :: Context -> Params -> Symbol -> Symbol -> IO ()
paramsSetSymbol = (Ptr Z3_context
 -> Ptr Z3_params -> Ptr Z3_symbol -> Ptr Z3_symbol -> IO ())
-> Context -> Params -> Symbol -> Symbol -> IO ()
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_params -> Ptr Z3_symbol -> Ptr Z3_symbol -> IO ()
z3_params_set_symbol

-- | Convert a parameter set into a string.
--
-- This function is mainly used for printing the contents of a parameter set.
paramsToString :: Context -> Params -> IO String
paramsToString :: Context -> Params -> IO String
paramsToString = (Ptr Z3_context -> Ptr Z3_params -> IO Z3_string)
-> Context -> Params -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_params -> IO Z3_string
z3_params_to_string

-- TODO: Z3_params_validate

---------------------------------------------------------------------
-- Parameter Descriptions

-- TODO

---------------------------------------------------------------------
-- Symbols

-- | Create a Z3 symbol using an integer.
--
-- @mkIntSymbol c i@ /requires/ @0 <= i < 2^30@
mkIntSymbol :: Integral int => Context -> int -> IO Symbol
mkIntSymbol :: forall int. Integral int => Context -> int -> IO Symbol
mkIntSymbol Context
c int
i
  | int
0 int -> int -> Bool
forall a. Ord a => a -> a -> Bool
<= int
i Bool -> Bool -> Bool
&& int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
<= int
2int -> Int -> int
forall a b. (Num a, Integral b) => a -> b -> a
^(Int
30::Int)int -> int -> int
forall a. Num a => a -> a -> a
-int
1
  = (Ptr Z3_context -> Z3_error_code -> IO (Ptr Z3_symbol))
-> Context -> int -> IO Symbol
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Z3_error_code -> IO (Ptr Z3_symbol)
z3_mk_int_symbol Context
c int
i
  | Bool
otherwise
  = String -> IO Symbol
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkIntSymbol: invalid range"

-- | Create a Z3 symbol using a 'String'.
mkStringSymbol :: Context -> String -> IO Symbol
mkStringSymbol :: Context -> String -> IO Symbol
mkStringSymbol = (Ptr Z3_context -> Z3_string -> IO (Ptr Z3_symbol))
-> Context -> String -> IO Symbol
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Z3_string -> IO (Ptr Z3_symbol)
z3_mk_string_symbol

---------------------------------------------------------------------
-- Sorts

-- | Create a free (uninterpreted) type using the given name (symbol).
--
-- Two free types are considered the same iff the have the same name.
mkUninterpretedSort :: Context -> Symbol -> IO Sort
mkUninterpretedSort :: Context -> Symbol -> IO Sort
mkUninterpretedSort = (Ptr Z3_context -> Ptr Z3_symbol -> IO (Ptr Z3_sort))
-> Context -> Symbol -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_symbol -> IO (Ptr Z3_sort)
z3_mk_uninterpreted_sort

-- | Create the /boolean/ type.
--
-- This type is used to create propositional variables and predicates.
mkBoolSort :: Context -> IO Sort
mkBoolSort :: Context -> IO Sort
mkBoolSort = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_bool_sort

-- | Create the /integer/ type.
--
-- This is the type of arbitrary precision integers.
-- A machine integer can be represented using bit-vectors, see 'mkBvSort'.
mkIntSort :: Context -> IO Sort
mkIntSort :: Context -> IO Sort
mkIntSort = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_int_sort

-- | Create the /real/ type.
--
-- This type is not a floating point number.
-- Z3 does not have support for floating point numbers yet.
mkRealSort :: Context -> IO Sort
mkRealSort :: Context -> IO Sort
mkRealSort = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_real_sort

-- | Create a bit-vector type of the given size.
--
-- This type can also be seen as a machine integer.
--
-- @mkBvSort c sz@ /requires/ @sz >= 0@
mkBvSort :: Integral int => Context -> int -> IO Sort
mkBvSort :: forall int. Integral int => Context -> int -> IO Sort
mkBvSort Context
c int
i
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
>= int
0    = (Ptr Z3_context -> CUInt -> IO (Ptr Z3_sort))
-> Context -> int -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> CUInt -> IO (Ptr Z3_sort)
z3_mk_bv_sort Context
c int
i
  | Bool
otherwise = String -> IO Sort
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkBvSort: negative size"

-- | Create a finite-domain type.
mkFiniteDomainSort :: Context -> Symbol -> Word64 -> IO Sort
mkFiniteDomainSort :: Context -> Symbol -> Word64 -> IO Sort
mkFiniteDomainSort = (Ptr Z3_context -> Ptr Z3_symbol -> CULLong -> IO (Ptr Z3_sort))
-> Context -> Symbol -> Word64 -> IO Sort
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_symbol -> CULLong -> IO (Ptr Z3_sort)
z3_mk_finite_domain_sort

-- | Create an array type
--
-- We usually represent the array type as: [domain -> range].
-- Arrays are usually used to model the heap/memory in software verification.
mkArraySort :: Context -> Sort -> Sort -> IO Sort
mkArraySort :: Context -> Sort -> Sort -> IO Sort
mkArraySort = (Ptr Z3_context -> Ptr Z3_sort -> Ptr Z3_sort -> IO (Ptr Z3_sort))
-> Context -> Sort -> Sort -> IO Sort
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_sort -> Ptr Z3_sort -> IO (Ptr Z3_sort)
z3_mk_array_sort

-- | Create an array type with N arguments.
mkArraySortN :: Context -> [Sort] -> Sort -> IO Sort
mkArraySortN :: Context -> [Sort] -> Sort -> IO Sort
mkArraySortN Context
ctx [Sort]
argSorts Sort
rangeSort = (Ptr Z3_context
 -> CUInt -> Ptr (Ptr Z3_sort) -> Ptr Z3_sort -> IO (Ptr Z3_sort))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_sort) -> Ptr Z3_sort -> IO (Ptr Z3_sort))
    -> IO (Ptr Z3_sort))
-> IO Sort
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> CUInt -> Ptr (Ptr Z3_sort) -> Ptr Z3_sort -> IO (Ptr Z3_sort)
z3_mk_array_sort_n Context
ctx (((CUInt -> Ptr (Ptr Z3_sort) -> Ptr Z3_sort -> IO (Ptr Z3_sort))
  -> IO (Ptr Z3_sort))
 -> IO Sort)
-> ((CUInt -> Ptr (Ptr Z3_sort) -> Ptr Z3_sort -> IO (Ptr Z3_sort))
    -> IO (Ptr Z3_sort))
-> IO Sort
forall a b. (a -> b) -> a -> b
$ \CUInt -> Ptr (Ptr Z3_sort) -> Ptr Z3_sort -> IO (Ptr Z3_sort)
f ->
  [Sort]
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_sort))
-> IO (Ptr Z3_sort)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Sort]
argSorts ((CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_sort))
 -> IO (Ptr Z3_sort))
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_sort))
-> IO (Ptr Z3_sort)
forall a b. (a -> b) -> a -> b
$ \CUInt
nArgs Ptr (Ptr Z3_sort)
argSortsPtr ->
    Sort -> (Ptr Z3_sort -> IO (Ptr Z3_sort)) -> IO (Ptr Z3_sort)
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
rangeSort ((Ptr Z3_sort -> IO (Ptr Z3_sort)) -> IO (Ptr Z3_sort))
-> (Ptr Z3_sort -> IO (Ptr Z3_sort)) -> IO (Ptr Z3_sort)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
rangeSortPtr ->
      CUInt -> Ptr (Ptr Z3_sort) -> Ptr Z3_sort -> IO (Ptr Z3_sort)
f CUInt
nArgs Ptr (Ptr Z3_sort)
argSortsPtr Ptr Z3_sort
rangeSortPtr

-- | Create a tuple type
--
-- A tuple with n fields has a constructor and n projections.
-- This function will also declare the constructor and projection functions.
mkTupleSort :: Context                         -- ^ Context
            -> Symbol                          -- ^ Name of the sort
            -> [(Symbol, Sort)]                -- ^ Name and sort of each field
            -> IO (Sort, FuncDecl, [FuncDecl]) -- ^ Resulting sort, and function
                                               -- declarations for the
                                               -- constructor and projections.
mkTupleSort :: Context
-> Symbol -> [(Symbol, Sort)] -> IO (Sort, FuncDecl, [FuncDecl])
mkTupleSort Context
c Symbol
sym [(Symbol, Sort)]
symSorts = Context
-> (Ptr Z3_context -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c ((Ptr Z3_context -> IO (Sort, FuncDecl, [FuncDecl]))
 -> IO (Sort, FuncDecl, [FuncDecl]))
-> (Ptr Z3_context -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr ->
  Symbol
-> (Ptr Z3_symbol -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Symbol
sym ((Ptr Z3_symbol -> IO (Sort, FuncDecl, [FuncDecl]))
 -> IO (Sort, FuncDecl, [FuncDecl]))
-> (Ptr Z3_symbol -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
symPtr ->
  [Symbol]
-> (Int -> Ptr (Ptr Z3_symbol) -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Symbol]
syms ((Int -> Ptr (Ptr Z3_symbol) -> IO (Sort, FuncDecl, [FuncDecl]))
 -> IO (Sort, FuncDecl, [FuncDecl]))
-> (Int -> Ptr (Ptr Z3_symbol) -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall a b. (a -> b) -> a -> b
$ \ Int
n Ptr (Ptr Z3_symbol)
symsPtr ->
  [Sort]
-> (Ptr (Ptr Z3_sort) -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [Sort]
sorts ((Ptr (Ptr Z3_sort) -> IO (Sort, FuncDecl, [FuncDecl]))
 -> IO (Sort, FuncDecl, [FuncDecl]))
-> (Ptr (Ptr Z3_sort) -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall a b. (a -> b) -> a -> b
$ \ Ptr (Ptr Z3_sort)
sortsPtr ->
  (Ptr (Ptr Z3_func_decl) -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr Z3_func_decl) -> IO (Sort, FuncDecl, [FuncDecl]))
 -> IO (Sort, FuncDecl, [FuncDecl]))
-> (Ptr (Ptr Z3_func_decl) -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall a b. (a -> b) -> a -> b
$ \ Ptr (Ptr Z3_func_decl)
outConstrPtr ->
  Int
-> (Ptr (Ptr Z3_func_decl) -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray Int
n ((Ptr (Ptr Z3_func_decl) -> IO (Sort, FuncDecl, [FuncDecl]))
 -> IO (Sort, FuncDecl, [FuncDecl]))
-> (Ptr (Ptr Z3_func_decl) -> IO (Sort, FuncDecl, [FuncDecl]))
-> IO (Sort, FuncDecl, [FuncDecl])
forall a b. (a -> b) -> a -> b
$ \ Ptr (Ptr Z3_func_decl)
outProjsPtr -> do
    Ptr Z3_sort
srtPtr <- Ptr Z3_context -> IO (Ptr Z3_sort) -> IO (Ptr Z3_sort)
forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
cPtr (IO (Ptr Z3_sort) -> IO (Ptr Z3_sort))
-> IO (Ptr Z3_sort) -> IO (Ptr Z3_sort)
forall a b. (a -> b) -> a -> b
$ Ptr Z3_context
-> Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_sort)
z3_mk_tuple_sort Ptr Z3_context
cPtr Ptr Z3_symbol
symPtr
                                  (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) Ptr (Ptr Z3_symbol)
symsPtr Ptr (Ptr Z3_sort)
sortsPtr
                                  Ptr (Ptr Z3_func_decl)
outConstrPtr Ptr (Ptr Z3_func_decl)
outProjsPtr
    Ptr Z3_func_decl
outConstr <- Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_func_decl)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Z3_func_decl)
outConstrPtr
    [Ptr Z3_func_decl]
outProjs  <- Int -> Ptr (Ptr Z3_func_decl) -> IO [Ptr Z3_func_decl]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
n Ptr (Ptr Z3_func_decl)
outProjsPtr
    Sort
tupleSort <- Context -> Ptr Z3_sort -> IO Sort
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
c Ptr Z3_sort
srtPtr
    FuncDecl
tupleCons <- Context -> Ptr Z3_func_decl -> IO FuncDecl
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
c Ptr Z3_func_decl
outConstr
    [FuncDecl]
tupleProjs <- (Ptr Z3_func_decl -> IO FuncDecl)
-> [Ptr Z3_func_decl] -> IO [FuncDecl]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Context -> Ptr Z3_func_decl -> IO FuncDecl
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
c) [Ptr Z3_func_decl]
outProjs
    (Sort, FuncDecl, [FuncDecl]) -> IO (Sort, FuncDecl, [FuncDecl])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sort
tupleSort, FuncDecl
tupleCons, [FuncDecl]
tupleProjs)
  where ([Symbol]
syms, [Sort]
sorts) = [(Symbol, Sort)] -> ([Symbol], [Sort])
forall a b. [(a, b)] -> ([a], [b])
unzip [(Symbol, Sort)]
symSorts

-- | Like 'mkTupleSort' but wraps the result in a 'TupleType' record
mkTupleType :: Context -> Symbol -> [(String, Sort)] -> IO TupleType
mkTupleType :: Context -> Symbol -> [(String, Sort)] -> IO TupleType
mkTupleType Context
ctx Symbol
sym [(String, Sort)]
fs = do [(Symbol, Sort)]
fs' <- ([Symbol] -> [Sort] -> [(Symbol, Sort)])
-> [Sort] -> [Symbol] -> [(Symbol, Sort)]
forall a b c. (a -> b -> c) -> b -> a -> c
flip [Symbol] -> [Sort] -> [(Symbol, Sort)]
forall a b. [a] -> [b] -> [(a, b)]
zip (((String, Sort) -> Sort) -> [(String, Sort)] -> [Sort]
forall a b. (a -> b) -> [a] -> [b]
map (String, Sort) -> Sort
forall a b. (a, b) -> b
snd [(String, Sort)]
fs) ([Symbol] -> [(Symbol, Sort)])
-> IO [Symbol] -> IO [(Symbol, Sort)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((String, Sort) -> IO Symbol) -> [(String, Sort)] -> IO [Symbol]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Context -> String -> IO Symbol
mkStringSymbol Context
ctx (String -> IO Symbol)
-> ((String, Sort) -> String) -> (String, Sort) -> IO Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String, Sort) -> String
forall a b. (a, b) -> a
fst) [(String, Sort)]
fs
                            (Sort
tupleSort, FuncDecl
tupleCons, [FuncDecl]
tupleProjs) <- Context
-> Symbol -> [(Symbol, Sort)] -> IO (Sort, FuncDecl, [FuncDecl])
mkTupleSort Context
ctx Symbol
sym [(Symbol, Sort)]
fs'
                            let namedTupleProjs :: [(String, FuncDecl)]
namedTupleProjs = [String] -> [FuncDecl] -> [(String, FuncDecl)]
forall a b. [a] -> [b] -> [(a, b)]
zip (((String, Sort) -> String) -> [(String, Sort)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, Sort) -> String
forall a b. (a, b) -> a
fst [(String, Sort)]
fs) [FuncDecl]
tupleProjs
                            TupleType -> IO TupleType
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (TupleType -> IO TupleType) -> TupleType -> IO TupleType
forall a b. (a -> b) -> a -> b
$ TupleType {Sort
tupleSort :: Sort
tupleSort :: Sort
tupleSort, FuncDecl
tupleCons :: FuncDecl
tupleCons :: FuncDecl
tupleCons, [(String, FuncDecl)]
namedTupleProjs :: [(String, FuncDecl)]
namedTupleProjs :: [(String, FuncDecl)]
namedTupleProjs}

-- | Create an instance of the tuple sort wrapped in 'TupleType'
mkTuple :: Context -> TupleType -> [AST] -> IO AST
mkTuple :: Context -> TupleType -> [AST] -> IO AST
mkTuple Context
ctx TupleType{FuncDecl
tupleCons :: TupleType -> FuncDecl
tupleCons :: FuncDecl
tupleCons} [AST]
args = Context -> FuncDecl -> [AST] -> IO AST
mkApp Context
ctx FuncDecl
tupleCons [AST]
args

-- | Project the i-th field of the given tuple,
mkIndexTuple :: Context -> TupleType -> Int -> AST -> IO AST
mkIndexTuple :: Context -> TupleType -> Int -> AST -> IO AST
mkIndexTuple Context
ctx TupleType
tt Int
i AST
tup
  | Int
0 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
i Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< [FuncDecl] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (TupleType -> [FuncDecl]
tupleProjs TupleType
tt) = Context -> FuncDecl -> [AST] -> IO AST
mkApp Context
ctx (TupleType -> [FuncDecl]
tupleProjs TupleType
tt [FuncDecl] -> Int -> FuncDecl
forall a. HasCallStack => [a] -> Int -> a
!! Int
i) [AST
tup]
  | Bool
otherwise                            = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Invalid tuple index used."

-- | Project a field of the given tuple by name,
mkProjTuple :: Context -> TupleType -> String -> AST -> IO AST
mkProjTuple :: Context -> TupleType -> String -> AST -> IO AST
mkProjTuple Context
ctx TupleType{[(String, FuncDecl)]
namedTupleProjs :: TupleType -> [(String, FuncDecl)]
namedTupleProjs :: [(String, FuncDecl)]
namedTupleProjs} String
f AST
tup = case String -> [(String, FuncDecl)] -> Maybe FuncDecl
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
f [(String, FuncDecl)]
namedTupleProjs of
  Just FuncDecl
proj -> Context -> FuncDecl -> [AST] -> IO AST
mkApp Context
ctx FuncDecl
proj [AST
tup]
  Maybe FuncDecl
Nothing   -> String -> IO AST
forall a. HasCallStack => String -> a
error String
"Invalid tuple field used."

-- | Create a enumeration sort.
--
-- An enumeration sort with n elements. This function will also declare the functions corresponding to the enumerations:
--
-- * @enum_consts@: constants corresponding to the enumerated elements.
-- * @enum_testers@: predicates testing if terms of the enumeration sort correspond to an enumeration.
--
mkEnumerationSort :: Context                           -- ^ logical context
                  -> Symbol                            -- ^ name of the enumeration sort
                  -> [Symbol]                          -- ^ names of the enumerated elements
                  -> IO (Sort, [FuncDecl], [FuncDecl]) -- ^ the created enumeration sort, @enum_consts@, @enum_testers@
mkEnumerationSort :: Context -> Symbol -> [Symbol] -> IO (Sort, [FuncDecl], [FuncDecl])
mkEnumerationSort Context
ctx Symbol
sortName [Symbol]
constNames = let hn :: Int
hn = [Symbol] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Symbol]
constNames in
  Int
-> (Ptr (Ptr Z3_func_decl) -> IO (Sort, [FuncDecl], [FuncDecl]))
-> IO (Sort, [FuncDecl], [FuncDecl])
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray Int
hn ((Ptr (Ptr Z3_func_decl) -> IO (Sort, [FuncDecl], [FuncDecl]))
 -> IO (Sort, [FuncDecl], [FuncDecl]))
-> (Ptr (Ptr Z3_func_decl) -> IO (Sort, [FuncDecl], [FuncDecl]))
-> IO (Sort, [FuncDecl], [FuncDecl])
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_func_decl)
constDeclsPtr ->
    Int
-> (Ptr (Ptr Z3_func_decl) -> IO (Sort, [FuncDecl], [FuncDecl]))
-> IO (Sort, [FuncDecl], [FuncDecl])
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray Int
hn ((Ptr (Ptr Z3_func_decl) -> IO (Sort, [FuncDecl], [FuncDecl]))
 -> IO (Sort, [FuncDecl], [FuncDecl]))
-> (Ptr (Ptr Z3_func_decl) -> IO (Sort, [FuncDecl], [FuncDecl]))
-> IO (Sort, [FuncDecl], [FuncDecl])
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_func_decl)
testDeclsPtr ->
      do Sort
s <- (Ptr Z3_context
 -> Ptr Z3_symbol
 -> CUInt
 -> Ptr (Ptr Z3_symbol)
 -> Ptr (Ptr Z3_func_decl)
 -> Ptr (Ptr Z3_func_decl)
 -> IO (Ptr Z3_sort))
-> Context
-> ((Ptr Z3_symbol
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> IO (Ptr Z3_sort))
    -> IO (Ptr Z3_sort))
-> IO Sort
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_sort)
z3_mk_enumeration_sort Context
ctx (((Ptr Z3_symbol
   -> CUInt
   -> Ptr (Ptr Z3_symbol)
   -> Ptr (Ptr Z3_func_decl)
   -> Ptr (Ptr Z3_func_decl)
   -> IO (Ptr Z3_sort))
  -> IO (Ptr Z3_sort))
 -> IO Sort)
-> ((Ptr Z3_symbol
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> IO (Ptr Z3_sort))
    -> IO (Ptr Z3_sort))
-> IO Sort
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_sort)
f ->
                [Symbol]
-> (CUInt -> Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_sort))
-> IO (Ptr Z3_sort)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Symbol]
constNames ((CUInt -> Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_sort))
 -> IO (Ptr Z3_sort))
-> (CUInt -> Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_sort))
-> IO (Ptr Z3_sort)
forall a b. (a -> b) -> a -> b
$ \CUInt
n Ptr (Ptr Z3_symbol)
constNamesPtr ->
                  Symbol -> (Ptr Z3_symbol -> IO (Ptr Z3_sort)) -> IO (Ptr Z3_sort)
forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Symbol
sortName ((Ptr Z3_symbol -> IO (Ptr Z3_sort)) -> IO (Ptr Z3_sort))
-> (Ptr Z3_symbol -> IO (Ptr Z3_sort)) -> IO (Ptr Z3_sort)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
sortNamePtr ->
                    Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_sort)
f Ptr Z3_symbol
sortNamePtr CUInt
n Ptr (Ptr Z3_symbol)
constNamesPtr Ptr (Ptr Z3_func_decl)
constDeclsPtr Ptr (Ptr Z3_func_decl)
testDeclsPtr
         [FuncDecl]
constDecls <- Context -> Int -> Ptr (Ptr Z3_func_decl) -> IO [FuncDecl]
forall h c.
(Marshal h c, Storable c) =>
Context -> Int -> Ptr c -> IO [h]
peekArrayToHs Context
ctx Int
hn Ptr (Ptr Z3_func_decl)
constDeclsPtr
         [FuncDecl]
testDecls <- Context -> Int -> Ptr (Ptr Z3_func_decl) -> IO [FuncDecl]
forall h c.
(Marshal h c, Storable c) =>
Context -> Int -> Ptr c -> IO [h]
peekArrayToHs Context
ctx Int
hn Ptr (Ptr Z3_func_decl)
testDeclsPtr
         (Sort, [FuncDecl], [FuncDecl]) -> IO (Sort, [FuncDecl], [FuncDecl])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sort
s, [FuncDecl]
constDecls, [FuncDecl]
testDecls)

-- | Create a list sort.
--
-- A list sort over elem_sort. This function declares the corresponding constructors and testers for lists:
--
-- * @nilDecl@: declaration for the empty list
-- * @isnilDecl@:	test for the empty list
-- * @consDecl@:	declaration for a cons cell
-- * @isconsDecl@:	cons cell test
-- * @headDecl@:	list head
-- * @tailDecl@:	list tail
mkListSort :: Context       -- ^ Context
           -> Symbol        -- ^ name of the list sort
           -> Sort          -- ^ sort of list elements
           -> IO (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl) -- ^ the created list sort, @nilDecl@
                                                                                    -- @isnilDecl@, @consDecl@, @isconsDecl@
                                                                                    -- @headDecl@, @tailDecl@
mkListSort :: Context
-> Symbol
-> Sort
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
mkListSort Context
ctx Symbol
sortName Sort
elemSort =
  (Ptr (Ptr Z3_func_decl)
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr Z3_func_decl)
  -> IO
       (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> (Ptr (Ptr Z3_func_decl)
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_func_decl)
nilDeclPtr ->
  (Ptr (Ptr Z3_func_decl)
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr Z3_func_decl)
  -> IO
       (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> (Ptr (Ptr Z3_func_decl)
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_func_decl)
isNilDeclPtr ->
  (Ptr (Ptr Z3_func_decl)
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr Z3_func_decl)
  -> IO
       (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> (Ptr (Ptr Z3_func_decl)
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_func_decl)
consDeclPtr ->
  (Ptr (Ptr Z3_func_decl)
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr Z3_func_decl)
  -> IO
       (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> (Ptr (Ptr Z3_func_decl)
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_func_decl)
isConsDeclPtr ->
  (Ptr (Ptr Z3_func_decl)
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr Z3_func_decl)
  -> IO
       (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> (Ptr (Ptr Z3_func_decl)
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_func_decl)
headDeclPtr ->
  (Ptr (Ptr Z3_func_decl)
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr Z3_func_decl)
  -> IO
       (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> (Ptr (Ptr Z3_func_decl)
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_func_decl)
tailDeclPtr ->
  Symbol
-> (Ptr Z3_symbol
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Symbol
sortName ((Ptr Z3_symbol
  -> IO
       (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> (Ptr Z3_symbol
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
sortNamePtr ->
    Sort
-> (Ptr Z3_sort
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
elemSort ((Ptr Z3_sort
  -> IO
       (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
 -> IO
      (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> (Ptr Z3_sort
    -> IO
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl))
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
elemSortPtr ->
      do Sort
listSort <- (Ptr Z3_context
 -> Ptr Z3_symbol
 -> Ptr Z3_sort
 -> Ptr (Ptr Z3_func_decl)
 -> Ptr (Ptr Z3_func_decl)
 -> Ptr (Ptr Z3_func_decl)
 -> Ptr (Ptr Z3_func_decl)
 -> Ptr (Ptr Z3_func_decl)
 -> Ptr (Ptr Z3_func_decl)
 -> IO (Ptr Z3_sort))
-> Context
-> ((Ptr Z3_symbol
     -> Ptr Z3_sort
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> IO (Ptr Z3_sort))
    -> IO (Ptr Z3_sort))
-> IO Sort
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_symbol
-> Ptr Z3_sort
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_sort)
z3_mk_list_sort Context
ctx (((Ptr Z3_symbol
   -> Ptr Z3_sort
   -> Ptr (Ptr Z3_func_decl)
   -> Ptr (Ptr Z3_func_decl)
   -> Ptr (Ptr Z3_func_decl)
   -> Ptr (Ptr Z3_func_decl)
   -> Ptr (Ptr Z3_func_decl)
   -> Ptr (Ptr Z3_func_decl)
   -> IO (Ptr Z3_sort))
  -> IO (Ptr Z3_sort))
 -> IO Sort)
-> ((Ptr Z3_symbol
     -> Ptr Z3_sort
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> Ptr (Ptr Z3_func_decl)
     -> IO (Ptr Z3_sort))
    -> IO (Ptr Z3_sort))
-> IO Sort
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
-> Ptr Z3_sort
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_sort)
f ->
           Ptr Z3_symbol
-> Ptr Z3_sort
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_sort)
f Ptr Z3_symbol
sortNamePtr Ptr Z3_sort
elemSortPtr Ptr (Ptr Z3_func_decl)
nilDeclPtr Ptr (Ptr Z3_func_decl)
isNilDeclPtr Ptr (Ptr Z3_func_decl)
consDeclPtr Ptr (Ptr Z3_func_decl)
isConsDeclPtr Ptr (Ptr Z3_func_decl)
headDeclPtr Ptr (Ptr Z3_func_decl)
tailDeclPtr
         FuncDecl
nilDecl <- Context -> Ptr Z3_func_decl -> IO FuncDecl
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx (Ptr Z3_func_decl -> IO FuncDecl)
-> IO (Ptr Z3_func_decl) -> IO FuncDecl
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_func_decl)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Z3_func_decl)
nilDeclPtr
         FuncDecl
isNilDecl <- Context -> Ptr Z3_func_decl -> IO FuncDecl
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx (Ptr Z3_func_decl -> IO FuncDecl)
-> IO (Ptr Z3_func_decl) -> IO FuncDecl
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_func_decl)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Z3_func_decl)
isNilDeclPtr
         FuncDecl
consDecl <- Context -> Ptr Z3_func_decl -> IO FuncDecl
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx (Ptr Z3_func_decl -> IO FuncDecl)
-> IO (Ptr Z3_func_decl) -> IO FuncDecl
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_func_decl)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Z3_func_decl)
consDeclPtr
         FuncDecl
isConsDecl <- Context -> Ptr Z3_func_decl -> IO FuncDecl
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx (Ptr Z3_func_decl -> IO FuncDecl)
-> IO (Ptr Z3_func_decl) -> IO FuncDecl
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_func_decl)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Z3_func_decl)
isConsDeclPtr
         FuncDecl
headDecl <- Context -> Ptr Z3_func_decl -> IO FuncDecl
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx (Ptr Z3_func_decl -> IO FuncDecl)
-> IO (Ptr Z3_func_decl) -> IO FuncDecl
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_func_decl)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Z3_func_decl)
headDeclPtr
         FuncDecl
tailDecl <- Context -> Ptr Z3_func_decl -> IO FuncDecl
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx (Ptr Z3_func_decl -> IO FuncDecl)
-> IO (Ptr Z3_func_decl) -> IO FuncDecl
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_func_decl)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Z3_func_decl)
tailDeclPtr
         (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
-> IO
     (Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sort
listSort, FuncDecl
nilDecl, FuncDecl
isNilDecl, FuncDecl
consDecl, FuncDecl
isConsDecl, FuncDecl
headDecl, FuncDecl
tailDecl)

-- | Create a contructor
mkConstructor :: Context                      -- ^ Context
              -> Symbol                       -- ^ Name of the constructor
              -> Symbol                       -- ^ Name of recognizer function
              -> [(Symbol, Maybe Sort, Int)]  -- ^ Name, sort option, and sortRefs
              -> IO Constructor
mkConstructor :: Context
-> Symbol
-> Symbol
-> [(Symbol, Maybe Sort, Int)]
-> IO Constructor
mkConstructor Context
c Symbol
sym Symbol
recog [(Symbol, Maybe Sort, Int)]
symSortsRefs =
  Context -> (Ptr Z3_context -> IO Constructor) -> IO Constructor
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c ((Ptr Z3_context -> IO Constructor) -> IO Constructor)
-> (Ptr Z3_context -> IO Constructor) -> IO Constructor
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr ->
  Symbol -> (Ptr Z3_symbol -> IO Constructor) -> IO Constructor
forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Symbol
sym ((Ptr Z3_symbol -> IO Constructor) -> IO Constructor)
-> (Ptr Z3_symbol -> IO Constructor) -> IO Constructor
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
symPtr ->
  Symbol -> (Ptr Z3_symbol -> IO Constructor) -> IO Constructor
forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Symbol
recog ((Ptr Z3_symbol -> IO Constructor) -> IO Constructor)
-> (Ptr Z3_symbol -> IO Constructor) -> IO Constructor
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
recogPtr ->
  [Symbol]
-> (CUInt -> Ptr (Ptr Z3_symbol) -> IO Constructor)
-> IO Constructor
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Symbol]
syms ((CUInt -> Ptr (Ptr Z3_symbol) -> IO Constructor)
 -> IO Constructor)
-> (CUInt -> Ptr (Ptr Z3_symbol) -> IO Constructor)
-> IO Constructor
forall a b. (a -> b) -> a -> b
$ \ CUInt
n Ptr (Ptr Z3_symbol)
symsPtr ->
  [Maybe Sort]
-> (Ptr (Ptr Z3_sort) -> IO Constructor) -> IO Constructor
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [Maybe Sort]
maybeSorts ((Ptr (Ptr Z3_sort) -> IO Constructor) -> IO Constructor)
-> (Ptr (Ptr Z3_sort) -> IO Constructor) -> IO Constructor
forall a b. (a -> b) -> a -> b
$ \ Ptr (Ptr Z3_sort)
sortsPtr ->
  [Integer] -> (Ptr CUInt -> IO Constructor) -> IO Constructor
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray ((Int -> Integer) -> [Int] -> [Integer]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Integer
forall a. Integral a => a -> Integer
toInteger [Int]
refs) ((Ptr CUInt -> IO Constructor) -> IO Constructor)
-> (Ptr CUInt -> IO Constructor) -> IO Constructor
forall a b. (a -> b) -> a -> b
$ \ Ptr CUInt
refsPtr -> do
    Ptr Z3_constructor
constructor <- Ptr Z3_context
-> IO (Ptr Z3_constructor) -> IO (Ptr Z3_constructor)
forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
cPtr (IO (Ptr Z3_constructor) -> IO (Ptr Z3_constructor))
-> IO (Ptr Z3_constructor) -> IO (Ptr Z3_constructor)
forall a b. (a -> b) -> a -> b
$ Ptr Z3_context
-> Ptr Z3_symbol
-> Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> Ptr CUInt
-> IO (Ptr Z3_constructor)
z3_mk_constructor
                       Ptr Z3_context
cPtr Ptr Z3_symbol
symPtr Ptr Z3_symbol
recogPtr CUInt
n Ptr (Ptr Z3_symbol)
symsPtr Ptr (Ptr Z3_sort)
sortsPtr Ptr CUInt
refsPtr
    Context -> Ptr Z3_constructor -> IO Constructor
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
c Ptr Z3_constructor
constructor
  where ([Symbol]
syms, [Maybe Sort]
maybeSorts, [Int]
refs) = [(Symbol, Maybe Sort, Int)] -> ([Symbol], [Maybe Sort], [Int])
forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 [(Symbol, Maybe Sort, Int)]
symSortsRefs

-- | Create datatype, such as lists, trees, records,
-- enumerations or unions of records.
--
-- The datatype may be recursive.
-- Returns the datatype sort.
mkDatatype :: Context
           -> Symbol
           -> [Constructor]
           -> IO Sort
mkDatatype :: Context -> Symbol -> [Constructor] -> IO Sort
mkDatatype Context
c Symbol
sym [Constructor]
consList = [Constructor]
-> (CUInt -> Ptr (Ptr Z3_constructor) -> IO Sort) -> IO Sort
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Constructor]
consList ((CUInt -> Ptr (Ptr Z3_constructor) -> IO Sort) -> IO Sort)
-> (CUInt -> Ptr (Ptr Z3_constructor) -> IO Sort) -> IO Sort
forall a b. (a -> b) -> a -> b
$ \ CUInt
n Ptr (Ptr Z3_constructor)
consPtrs -> do
  Context -> (Ptr Z3_context -> IO (Ptr Z3_sort)) -> IO Sort
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO (Ptr Z3_sort)) -> IO Sort)
-> (Ptr Z3_context -> IO (Ptr Z3_sort)) -> IO Sort
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context
-> Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_constructor)
-> IO (Ptr Z3_sort)
z3_mk_datatype Ptr Z3_context
cPtr (Symbol -> Ptr Z3_symbol
unSymbol Symbol
sym) CUInt
n Ptr (Ptr Z3_constructor)
consPtrs

-- | Create list of constructors
mkConstructorList :: Context                      -- ^ Context
                  -> [Constructor]                -- ^ List of Constructors
                  -> IO ConstructorList
mkConstructorList :: Context -> [Constructor] -> IO ConstructorList
mkConstructorList Context
c [Constructor]
consList = [Constructor]
-> (CUInt -> Ptr (Ptr Z3_constructor) -> IO ConstructorList)
-> IO ConstructorList
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Constructor]
consList ((CUInt -> Ptr (Ptr Z3_constructor) -> IO ConstructorList)
 -> IO ConstructorList)
-> (CUInt -> Ptr (Ptr Z3_constructor) -> IO ConstructorList)
-> IO ConstructorList
forall a b. (a -> b) -> a -> b
$ \ CUInt
n Ptr (Ptr Z3_constructor)
consPtrs -> do
  Context
-> (Ptr Z3_context -> IO (Ptr Z3_constructor_list))
-> IO ConstructorList
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO (Ptr Z3_constructor_list))
 -> IO ConstructorList)
-> (Ptr Z3_context -> IO (Ptr Z3_constructor_list))
-> IO ConstructorList
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context
-> CUInt
-> Ptr (Ptr Z3_constructor)
-> IO (Ptr Z3_constructor_list)
z3_mk_constructor_list Ptr Z3_context
cPtr CUInt
n Ptr (Ptr Z3_constructor)
consPtrs

-- | Create mutually recursive datatypes, such as a tree and forest.
--
-- Returns the datatype sorts
mkDatatypes :: Context
            -> [Symbol]
            -> [[Constructor]]
            -> IO ([Sort])
mkDatatypes :: Context -> [Symbol] -> [[Constructor]] -> IO [Sort]
mkDatatypes Context
c [Symbol]
syms [[Constructor]]
consLists =
  if [[Constructor]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Constructor]]
consLists Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n then do
    [ConstructorList]
consLists' <- ([Constructor] -> IO ConstructorList)
-> [[Constructor]] -> IO [ConstructorList]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Context -> [Constructor] -> IO ConstructorList
mkConstructorList Context
c) [[Constructor]]
consLists

    Context -> (Ptr Z3_context -> IO [Sort]) -> IO [Sort]
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c ((Ptr Z3_context -> IO [Sort]) -> IO [Sort])
-> (Ptr Z3_context -> IO [Sort]) -> IO [Sort]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr ->
      [Symbol]
-> (CUInt -> Ptr (Ptr Z3_symbol) -> IO [Sort]) -> IO [Sort]
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Symbol]
syms ((CUInt -> Ptr (Ptr Z3_symbol) -> IO [Sort]) -> IO [Sort])
-> (CUInt -> Ptr (Ptr Z3_symbol) -> IO [Sort]) -> IO [Sort]
forall a b. (a -> b) -> a -> b
$ \ CUInt
symLen Ptr (Ptr Z3_symbol)
symsPtr ->
        [ConstructorList]
-> (Ptr (Ptr Z3_constructor_list) -> IO [Sort]) -> IO [Sort]
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [ConstructorList]
consLists' ((Ptr (Ptr Z3_constructor_list) -> IO [Sort]) -> IO [Sort])
-> (Ptr (Ptr Z3_constructor_list) -> IO [Sort]) -> IO [Sort]
forall a b. (a -> b) -> a -> b
$ \ Ptr (Ptr Z3_constructor_list)
consPtr ->
          Int -> (Ptr (Ptr Z3_sort) -> IO [Sort]) -> IO [Sort]
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray Int
n ((Ptr (Ptr Z3_sort) -> IO [Sort]) -> IO [Sort])
-> (Ptr (Ptr Z3_sort) -> IO [Sort]) -> IO [Sort]
forall a b. (a -> b) -> a -> b
$ \ Ptr (Ptr Z3_sort)
sortsPtr -> do
            Ptr Z3_context
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> Ptr (Ptr Z3_constructor_list)
-> IO ()
z3_mk_datatypes Ptr Z3_context
cPtr CUInt
symLen Ptr (Ptr Z3_symbol)
symsPtr Ptr (Ptr Z3_sort)
sortsPtr Ptr (Ptr Z3_constructor_list)
consPtr
            Context -> Int -> Ptr (Ptr Z3_sort) -> IO [Sort]
forall h c.
(Marshal h c, Storable c) =>
Context -> Int -> Ptr c -> IO [h]
peekArrayToHs Context
c Int
n Ptr (Ptr Z3_sort)
sortsPtr
    else
      String -> IO [Sort]
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkDatatypes: lists of different length"
  where n :: Int
n = [Symbol] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Symbol]
syms

-- | Create an set type with a given domain type
mkSetSort :: Context -> Sort -> IO Sort
mkSetSort :: Context -> Sort -> IO Sort
mkSetSort = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort))
-> Context -> Sort -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort)
z3_mk_set_sort

---------------------------------------------------------------------
-- * Constants and Applications

-- | Declare a constant or function.
mkFuncDecl :: Context   -- ^ Logical context.
            -> Symbol   -- ^ Name of the function (or constant).
            -> [Sort]   -- ^ Function domain (empty for constants).
            -> Sort     -- ^ Return sort of the function.
            -> IO FuncDecl
mkFuncDecl :: Context -> Symbol -> [Sort] -> Sort -> IO FuncDecl
mkFuncDecl Context
ctx Symbol
smb [Sort]
dom Sort
rng =
  (Ptr Z3_context
 -> Ptr Z3_symbol
 -> CUInt
 -> Ptr (Ptr Z3_sort)
 -> Ptr Z3_sort
 -> IO (Ptr Z3_func_decl))
-> Context
-> ((Ptr Z3_symbol
     -> CUInt
     -> Ptr (Ptr Z3_sort)
     -> Ptr Z3_sort
     -> IO (Ptr Z3_func_decl))
    -> IO (Ptr Z3_func_decl))
-> IO FuncDecl
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
z3_mk_func_decl Context
ctx (((Ptr Z3_symbol
   -> CUInt
   -> Ptr (Ptr Z3_sort)
   -> Ptr Z3_sort
   -> IO (Ptr Z3_func_decl))
  -> IO (Ptr Z3_func_decl))
 -> IO FuncDecl)
-> ((Ptr Z3_symbol
     -> CUInt
     -> Ptr (Ptr Z3_sort)
     -> Ptr Z3_sort
     -> IO (Ptr Z3_func_decl))
    -> IO (Ptr Z3_func_decl))
-> IO FuncDecl
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
f ->
    Symbol
-> (Ptr Z3_symbol -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Symbol
smb ((Ptr Z3_symbol -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl))
-> (Ptr Z3_symbol -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
ptrSym ->
    [Sort]
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Sort]
dom ((CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
 -> IO (Ptr Z3_func_decl))
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \CUInt
domNum Ptr (Ptr Z3_sort)
domArr ->
    Sort
-> (Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl)
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
rng ((Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl))
-> (Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
ptrRange ->
      Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
f Ptr Z3_symbol
ptrSym CUInt
domNum Ptr (Ptr Z3_sort)
domArr Ptr Z3_sort
ptrRange

-- | Create a constant or function application.
mkApp :: Context -> FuncDecl -> [AST] -> IO AST
mkApp :: Context -> FuncDecl -> [AST] -> IO AST
mkApp Context
ctx FuncDecl
fd [AST]
args = (Ptr Z3_context
 -> Ptr Z3_func_decl
 -> CUInt
 -> Ptr (Ptr Z3_ast)
 -> IO (Ptr Z3_ast))
-> Context
-> ((Ptr Z3_func_decl
     -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_func_decl -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_app Context
ctx (((Ptr Z3_func_decl
   -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((Ptr Z3_func_decl
     -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f ->
  FuncDecl
-> (Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. FuncDecl -> (Ptr Z3_func_decl -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c FuncDecl
fd ((Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl
fdPtr ->
  [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
args ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr ->
    Ptr Z3_func_decl -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Ptr Z3_func_decl
fdPtr CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr

-- | Declare and create a constant.
--
-- This is a shorthand for:
-- @do xd <- mkFunDecl c x [] s; mkApp c xd []@
mkConst :: Context -> Symbol -> Sort -> IO AST
mkConst :: Context -> Symbol -> Sort -> IO AST
mkConst = (Ptr Z3_context -> Ptr Z3_symbol -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Symbol -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_symbol -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_const

-- | Declare a fresh constant or function.
mkFreshFuncDecl :: Context -> String -> [Sort] -> Sort -> IO FuncDecl
mkFreshFuncDecl :: Context -> String -> [Sort] -> Sort -> IO FuncDecl
mkFreshFuncDecl Context
ctx String
str [Sort]
dom Sort
rng =
  String -> (Z3_string -> IO FuncDecl) -> IO FuncDecl
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
str ((Z3_string -> IO FuncDecl) -> IO FuncDecl)
-> (Z3_string -> IO FuncDecl) -> IO FuncDecl
forall a b. (a -> b) -> a -> b
$ \Z3_string
cstr ->
    (Ptr Z3_context
 -> Z3_string
 -> CUInt
 -> Ptr (Ptr Z3_sort)
 -> Ptr Z3_sort
 -> IO (Ptr Z3_func_decl))
-> Context
-> ((Z3_string
     -> CUInt
     -> Ptr (Ptr Z3_sort)
     -> Ptr Z3_sort
     -> IO (Ptr Z3_func_decl))
    -> IO (Ptr Z3_func_decl))
-> IO FuncDecl
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Z3_string
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
forall z3_context.
Ptr z3_context
-> Z3_string
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
z3_mk_fresh_func_decl Context
ctx (((Z3_string
   -> CUInt
   -> Ptr (Ptr Z3_sort)
   -> Ptr Z3_sort
   -> IO (Ptr Z3_func_decl))
  -> IO (Ptr Z3_func_decl))
 -> IO FuncDecl)
-> ((Z3_string
     -> CUInt
     -> Ptr (Ptr Z3_sort)
     -> Ptr Z3_sort
     -> IO (Ptr Z3_func_decl))
    -> IO (Ptr Z3_func_decl))
-> IO FuncDecl
forall a b. (a -> b) -> a -> b
$ \Z3_string
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
f ->
    [Sort]
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Sort]
dom ((CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
 -> IO (Ptr Z3_func_decl))
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \CUInt
domNum Ptr (Ptr Z3_sort)
domArr ->
    Sort
-> (Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl)
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
rng ((Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl))
-> (Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
ptrRange ->
      Z3_string
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
f Z3_string
cstr CUInt
domNum Ptr (Ptr Z3_sort)
domArr Ptr Z3_sort
ptrRange

-- | Declare and create a fresh constant.
mkFreshConst :: Context -- ^ Logical context.
             -> String  -- ^ Prefix.
             -> Sort    -- ^ Sort of the constant.
             -> IO AST
mkFreshConst :: Context -> String -> Sort -> IO AST
mkFreshConst = (Ptr Z3_context -> Z3_string -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> String -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Z3_string -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fresh_const

-- | Declare a recursive function.
mkRecFuncDecl :: Context   -- ^ Logical context.
            -> Symbol   -- ^ Name of the function (or constant).
            -> [Sort]   -- ^ Function domain (empty for constants).
            -> Sort     -- ^ Return sort of the function.
            -> IO FuncDecl
mkRecFuncDecl :: Context -> Symbol -> [Sort] -> Sort -> IO FuncDecl
mkRecFuncDecl Context
ctx Symbol
smb [Sort]
dom Sort
rng =
  (Ptr Z3_context
 -> Ptr Z3_symbol
 -> CUInt
 -> Ptr (Ptr Z3_sort)
 -> Ptr Z3_sort
 -> IO (Ptr Z3_func_decl))
-> Context
-> ((Ptr Z3_symbol
     -> CUInt
     -> Ptr (Ptr Z3_sort)
     -> Ptr Z3_sort
     -> IO (Ptr Z3_func_decl))
    -> IO (Ptr Z3_func_decl))
-> IO FuncDecl
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
z3_mk_rec_func_decl Context
ctx (((Ptr Z3_symbol
   -> CUInt
   -> Ptr (Ptr Z3_sort)
   -> Ptr Z3_sort
   -> IO (Ptr Z3_func_decl))
  -> IO (Ptr Z3_func_decl))
 -> IO FuncDecl)
-> ((Ptr Z3_symbol
     -> CUInt
     -> Ptr (Ptr Z3_sort)
     -> Ptr Z3_sort
     -> IO (Ptr Z3_func_decl))
    -> IO (Ptr Z3_func_decl))
-> IO FuncDecl
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
f ->
    Symbol
-> (Ptr Z3_symbol -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Symbol
smb ((Ptr Z3_symbol -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl))
-> (Ptr Z3_symbol -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
ptrSym ->
    [Sort]
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Sort]
dom ((CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
 -> IO (Ptr Z3_func_decl))
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \CUInt
domNum Ptr (Ptr Z3_sort)
domArr ->
    Sort
-> (Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl)
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
rng ((Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl))
-> (Ptr Z3_sort -> IO (Ptr Z3_func_decl)) -> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
ptrRange ->
      Ptr Z3_symbol
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr Z3_sort
-> IO (Ptr Z3_func_decl)
f Ptr Z3_symbol
ptrSym CUInt
domNum Ptr (Ptr Z3_sort)
domArr Ptr Z3_sort
ptrRange

-- | Define the body of a recursive function.
-- Declare it first with mkRecFuncDecl
addRecDef :: Context -- ^ Logical context.
          -> FuncDecl -- ^ Declaration of the function being defined.
          -> [AST] -- ^ Constants to use as the function's formal arguments.
          -> AST   -- ^ Body of the function to define
          -> IO ()
addRecDef :: Context -> FuncDecl -> [AST] -> AST -> IO ()
addRecDef Context
ctx FuncDecl
decl [AST]
args AST
body =
  (Ptr Z3_context
 -> Ptr Z3_func_decl
 -> CUInt
 -> Ptr (Ptr Z3_ast)
 -> Ptr Z3_ast
 -> IO ())
-> Context
-> ((Ptr Z3_func_decl
     -> CUInt -> Ptr (Ptr Z3_ast) -> Ptr Z3_ast -> IO ())
    -> IO ())
-> IO ()
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_func_decl
-> CUInt
-> Ptr (Ptr Z3_ast)
-> Ptr Z3_ast
-> IO ()
z3_add_rec_def Context
ctx (((Ptr Z3_func_decl
   -> CUInt -> Ptr (Ptr Z3_ast) -> Ptr Z3_ast -> IO ())
  -> IO ())
 -> IO ())
-> ((Ptr Z3_func_decl
     -> CUInt -> Ptr (Ptr Z3_ast) -> Ptr Z3_ast -> IO ())
    -> IO ())
-> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl
-> CUInt -> Ptr (Ptr Z3_ast) -> Ptr Z3_ast -> IO ()
f ->
    FuncDecl -> (Ptr Z3_func_decl -> IO ()) -> IO ()
forall r. FuncDecl -> (Ptr Z3_func_decl -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c FuncDecl
decl ((Ptr Z3_func_decl -> IO ()) -> IO ())
-> (Ptr Z3_func_decl -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl
declPtr ->
    [AST] -> (CUInt -> Ptr (Ptr Z3_ast) -> IO ()) -> IO ()
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
args ((CUInt -> Ptr (Ptr Z3_ast) -> IO ()) -> IO ())
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr ->
    AST -> (Ptr Z3_ast -> IO ()) -> IO ()
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
body ((Ptr Z3_ast -> IO ()) -> IO ()) -> (Ptr Z3_ast -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
bodyPtr ->
      Ptr Z3_func_decl
-> CUInt -> Ptr (Ptr Z3_ast) -> Ptr Z3_ast -> IO ()
f Ptr Z3_func_decl
declPtr CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr Ptr Z3_ast
bodyPtr

-------------------------------------------------
-- ** Helpers

-- | Declare and create a variable (aka /constant/).
--
-- An alias for 'mkConst'.
mkVar :: Context -> Symbol -> Sort -> IO AST
mkVar :: Context -> Symbol -> Sort -> IO AST
mkVar = Context -> Symbol -> Sort -> IO AST
mkConst

-- | Declarate and create a variable of sort /bool/.
--
-- See 'mkVar'.
mkBoolVar :: Context -> Symbol -> IO AST
mkBoolVar :: Context -> Symbol -> IO AST
mkBoolVar Context
ctx Symbol
sym = Context -> Symbol -> Sort -> IO AST
mkVar Context
ctx Symbol
sym (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> IO Sort
mkBoolSort Context
ctx

-- | Declarate and create a variable of sort /real/.
--
-- See 'mkVar'.
mkRealVar :: Context -> Symbol -> IO AST
mkRealVar :: Context -> Symbol -> IO AST
mkRealVar Context
ctx Symbol
sym = Context -> Symbol -> Sort -> IO AST
mkVar Context
ctx Symbol
sym (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> IO Sort
mkRealSort Context
ctx

-- | Declarate and create a variable of sort /int/.
--
-- See 'mkVar'.
mkIntVar :: Context -> Symbol -> IO AST
mkIntVar :: Context -> Symbol -> IO AST
mkIntVar Context
ctx Symbol
sym = Context -> Symbol -> Sort -> IO AST
mkVar Context
ctx Symbol
sym (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> IO Sort
mkIntSort Context
ctx

-- | Declarate and create a variable of sort /bit-vector/.
--
-- See 'mkVar'.
mkBvVar :: Context -> Symbol
                   -> Int     -- ^ bit-width
                   -> IO AST
mkBvVar :: Context -> Symbol -> Int -> IO AST
mkBvVar Context
ctx Symbol
sym Int
sz = Context -> Symbol -> Sort -> IO AST
mkVar Context
ctx Symbol
sym (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> Int -> IO Sort
forall int. Integral int => Context -> int -> IO Sort
mkBvSort Context
ctx Int
sz

-- | Declare and create a /fresh/ variable (aka /constant/).
--
-- An alias for 'mkFreshConst'.
mkFreshVar :: Context -> String -> Sort -> IO AST
mkFreshVar :: Context -> String -> Sort -> IO AST
mkFreshVar = Context -> String -> Sort -> IO AST
mkFreshConst

-- | Declarate and create a /fresh/ variable of sort /bool/.
--
-- See 'mkFreshVar'.
mkFreshBoolVar :: Context -> String -> IO AST
mkFreshBoolVar :: Context -> String -> IO AST
mkFreshBoolVar Context
ctx String
str = Context -> String -> Sort -> IO AST
mkFreshVar Context
ctx String
str (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> IO Sort
mkBoolSort Context
ctx

-- | Declarate and create a /fresh/ variable of sort /real/.
--
-- See 'mkFreshVar'.
mkFreshRealVar :: Context -> String -> IO AST
mkFreshRealVar :: Context -> String -> IO AST
mkFreshRealVar Context
ctx String
str = Context -> String -> Sort -> IO AST
mkFreshVar Context
ctx String
str (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> IO Sort
mkRealSort Context
ctx

-- | Declarate and create a /fresh/ variable of sort /int/.
--
-- See 'mkFreshVar'.
mkFreshIntVar :: Context -> String -> IO AST
mkFreshIntVar :: Context -> String -> IO AST
mkFreshIntVar Context
ctx String
str = Context -> String -> Sort -> IO AST
mkFreshVar Context
ctx String
str (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> IO Sort
mkIntSort Context
ctx

-- | Declarate and create a /fresh/ variable of sort /bit-vector/.
--
-- See 'mkFreshVar'.
mkFreshBvVar :: Context -> String
                        -> Int     -- ^ bit-width
                        -> IO AST
mkFreshBvVar :: Context -> String -> Int -> IO AST
mkFreshBvVar Context
ctx String
str Int
sz = Context -> String -> Sort -> IO AST
mkFreshVar Context
ctx String
str (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> Int -> IO Sort
forall int. Integral int => Context -> int -> IO Sort
mkBvSort Context
ctx Int
sz

---------------------------------------------------------------------
-- Propositional Logic and Equality

-- | Create an AST node representing /true/.
mkTrue :: Context -> IO AST
mkTrue :: Context -> IO AST
mkTrue = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_true

-- | Create an AST node representing /false/.
mkFalse :: Context -> IO AST
mkFalse :: Context -> IO AST
mkFalse = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_false

-- | Create an AST node representing /l = r/.
mkEq :: Context -> AST -> AST -> IO AST
mkEq :: Context -> AST -> AST -> IO AST
mkEq = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_eq

-- | The distinct construct is used for declaring the arguments pairwise
-- distinct.
--
-- That is, @and [ args!!i /= args!!j | i <- [0..length(args)-1], j <- [i+1..length(args)-1] ]@
--
-- Requires a non-empty list.
mkDistinct :: Context -> [AST] -> IO AST
mkDistinct :: Context -> [AST] -> IO AST
mkDistinct =
  String
-> (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> [AST]
-> IO AST
liftAstN_err String
"Z3.Base.mkDistinct: empty list of expressions" Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_distinct

-- | Same as 'mkDistinct' but type-safe.
mkDistinct1 :: Context -> NonEmpty AST -> IO AST
mkDistinct1 :: Context -> NonEmpty AST -> IO AST
mkDistinct1 = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context -> NonEmpty AST -> IO AST
liftAstN1 Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_distinct

-- | Create an AST node representing /not(a)/.
mkNot :: Context -> AST -> IO AST
mkNot :: Context -> AST -> IO AST
mkNot = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_not

-- | Create an AST node representing an if-then-else: /ite(t1, t2, t3)/.
mkIte :: Context -> AST -> AST -> AST -> IO AST
mkIte :: Context -> AST -> AST -> AST -> IO AST
mkIte = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_ite

-- | Create an AST node representing /t1 iff t2/.
mkIff :: Context -> AST -> AST -> IO AST
mkIff :: Context -> AST -> AST -> IO AST
mkIff = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_iff

-- | Create an AST node representing /t1 implies t2/.
mkImplies :: Context -> AST -> AST -> IO AST
mkImplies :: Context -> AST -> AST -> IO AST
mkImplies = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_implies

-- | Create an AST node representing /t1 xor t2/.
mkXor :: Context -> AST -> AST -> IO AST
mkXor :: Context -> AST -> AST -> IO AST
mkXor = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_xor

-- | Create an AST node representing args[0] and ... and args[num_args-1].
mkAnd :: Context -> [AST] -> IO AST
mkAnd :: Context -> [AST] -> IO AST
mkAnd = (Ptr Z3_context -> IO (Ptr Z3_ast))
-> (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> [AST]
-> IO AST
liftAstN Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_true Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_and

-- | Create an AST node representing args[0] or ... or args[num_args-1].
mkOr :: Context -> [AST] -> IO AST
mkOr :: Context -> [AST] -> IO AST
mkOr = (Ptr Z3_context -> IO (Ptr Z3_ast))
-> (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> [AST]
-> IO AST
liftAstN Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_false Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_or

-------------------------------------------------
-- ** Helpers

-- | Create an AST node representing the given boolean.
mkBool :: Context -> Bool -> IO AST
mkBool :: Context -> Bool -> IO AST
mkBool Context
ctx Bool
False = Context -> IO AST
mkFalse Context
ctx
mkBool Context
ctx Bool
True  = Context -> IO AST
mkTrue  Context
ctx

---------------------------------------------------------------------
-- Arithmetic: Integers and Reals

-- | Create an AST node representing args[0] + ... + args[num_args-1].
mkAdd :: Context -> [AST] -> IO AST
mkAdd :: Context -> [AST] -> IO AST
mkAdd Context
ctx = IO AST
-> (NonEmpty AST -> IO AST) -> Maybe (NonEmpty AST) -> IO AST
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Context -> Integer -> IO AST
mkInteger Context
ctx Integer
0) ((Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context -> NonEmpty AST -> IO AST
liftAstN1 Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_add Context
ctx) (Maybe (NonEmpty AST) -> IO AST)
-> ([AST] -> Maybe (NonEmpty AST)) -> [AST] -> IO AST
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [AST] -> Maybe (NonEmpty AST)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty

-- | Create an AST node representing args[0] * ... * args[num_args-1].
mkMul :: Context -> [AST] -> IO AST
mkMul :: Context -> [AST] -> IO AST
mkMul Context
ctx = IO AST
-> (NonEmpty AST -> IO AST) -> Maybe (NonEmpty AST) -> IO AST
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Context -> Integer -> IO AST
mkInteger Context
ctx Integer
1) ((Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context -> NonEmpty AST -> IO AST
liftAstN1 Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_mul Context
ctx) (Maybe (NonEmpty AST) -> IO AST)
-> ([AST] -> Maybe (NonEmpty AST)) -> [AST] -> IO AST
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [AST] -> Maybe (NonEmpty AST)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty

-- | Create an AST node representing args[0] - ... - args[num_args - 1].
--
-- Requires a non-empty list.
mkSub :: Context -> [AST] -> IO AST
mkSub :: Context -> [AST] -> IO AST
mkSub = String
-> (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> [AST]
-> IO AST
liftAstN_err String
"Z3.Base.mkSub: empty list of expressions" Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_sub

-- | Same as 'mkSub' but type-safe.
mkSub1 :: Context -> NonEmpty AST -> IO AST
mkSub1 :: Context -> NonEmpty AST -> IO AST
mkSub1 = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context -> NonEmpty AST -> IO AST
liftAstN1 Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_sub

-- | Create an AST node representing -arg.
mkUnaryMinus :: Context -> AST -> IO AST
mkUnaryMinus :: Context -> AST -> IO AST
mkUnaryMinus = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_unary_minus

-- | Create an AST node representing arg1 div arg2.
mkDiv :: Context -> AST -> AST -> IO AST
mkDiv :: Context -> AST -> AST -> IO AST
mkDiv = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_div

-- | Create an AST node representing arg1 mod arg2.
mkMod :: Context -> AST -> AST -> IO AST
mkMod :: Context -> AST -> AST -> IO AST
mkMod = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_mod

-- | Create an AST node representing arg1 rem arg2.
mkRem :: Context -> AST -> AST -> IO AST
mkRem :: Context -> AST -> AST -> IO AST
mkRem = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_rem

-- | Create an AST node representing arg1 ^ arg2.
mkPower :: Context -> AST -> AST -> IO AST
mkPower :: Context -> AST -> AST -> IO AST
mkPower = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_power

-- | Create less than.
mkLt :: Context -> AST -> AST -> IO AST
mkLt :: Context -> AST -> AST -> IO AST
mkLt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_lt

-- | Create less than or equal to.
mkLe :: Context -> AST -> AST -> IO AST
mkLe :: Context -> AST -> AST -> IO AST
mkLe = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_le

-- | Create greater than.
mkGt :: Context -> AST -> AST -> IO AST
mkGt :: Context -> AST -> AST -> IO AST
mkGt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_gt

-- | Create greater than or equal to.
mkGe :: Context -> AST -> AST -> IO AST
mkGe :: Context -> AST -> AST -> IO AST
mkGe = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_ge

-- | Coerce an integer to a real.
mkInt2Real :: Context -> AST -> IO AST
mkInt2Real :: Context -> AST -> IO AST
mkInt2Real = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_int2real

-- | Coerce a real to an integer.
mkReal2Int :: Context -> AST -> IO AST
mkReal2Int :: Context -> AST -> IO AST
mkReal2Int = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_real2int

-- | Check if a real number is an integer.
mkIsInt :: Context -> AST -> IO AST
mkIsInt :: Context -> AST -> IO AST
mkIsInt = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_is_int

---------------------------------------------------------------------
-- Bit-vectors

-- | Bitwise negation.
mkBvnot :: Context -> AST -> IO AST
mkBvnot :: Context -> AST -> IO AST
mkBvnot = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvnot

-- | Take conjunction of bits in vector, return vector of length 1.
mkBvredand :: Context -> AST -> IO AST
mkBvredand :: Context -> AST -> IO AST
mkBvredand = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvredand

-- | Take disjunction of bits in vector, return vector of length 1.
mkBvredor :: Context -> AST -> IO AST
mkBvredor :: Context -> AST -> IO AST
mkBvredor = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvredor

-- | Bitwise and.
mkBvand :: Context -> AST -> AST -> IO AST
mkBvand :: Context -> AST -> AST -> IO AST
mkBvand = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvand

-- | Bitwise or.
mkBvor :: Context -> AST -> AST -> IO AST
mkBvor :: Context -> AST -> AST -> IO AST
mkBvor = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvor

-- | Bitwise exclusive-or.
mkBvxor :: Context -> AST -> AST -> IO AST
mkBvxor :: Context -> AST -> AST -> IO AST
mkBvxor = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvxor

-- | Bitwise nand.
mkBvnand :: Context -> AST -> AST -> IO AST
mkBvnand :: Context -> AST -> AST -> IO AST
mkBvnand = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvnand

-- | Bitwise nor.
mkBvnor :: Context -> AST -> AST -> IO AST
mkBvnor :: Context -> AST -> AST -> IO AST
mkBvnor = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvnor

-- | Bitwise xnor.
mkBvxnor :: Context -> AST -> AST -> IO AST
mkBvxnor :: Context -> AST -> AST -> IO AST
mkBvxnor = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvxnor

-- | Standard two's complement unary minus.
mkBvneg :: Context -> AST -> IO AST
mkBvneg :: Context -> AST -> IO AST
mkBvneg = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvneg

-- | Standard two's complement addition.
mkBvadd :: Context -> AST -> AST -> IO AST
mkBvadd :: Context -> AST -> AST -> IO AST
mkBvadd = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvadd

-- | Standard two's complement subtraction.
mkBvsub :: Context -> AST -> AST -> IO AST
mkBvsub :: Context -> AST -> AST -> IO AST
mkBvsub = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsub

-- | Standard two's complement multiplication.
mkBvmul :: Context -> AST -> AST -> IO AST
mkBvmul :: Context -> AST -> AST -> IO AST
mkBvmul = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvmul

-- | Unsigned division.
mkBvudiv :: Context -> AST -> AST -> IO AST
mkBvudiv :: Context -> AST -> AST -> IO AST
mkBvudiv = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvudiv

-- | Two's complement signed division.
mkBvsdiv :: Context -> AST -> AST -> IO AST
mkBvsdiv :: Context -> AST -> AST -> IO AST
mkBvsdiv = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsdiv

-- | Unsigned remainder.
mkBvurem :: Context -> AST -> AST -> IO AST
mkBvurem :: Context -> AST -> AST -> IO AST
mkBvurem = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvurem

-- | Two's complement signed remainder (sign follows dividend).
mkBvsrem :: Context -> AST -> AST -> IO AST
mkBvsrem :: Context -> AST -> AST -> IO AST
mkBvsrem = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsrem

-- | Two's complement signed remainder (sign follows divisor).
mkBvsmod :: Context -> AST -> AST -> IO AST
mkBvsmod :: Context -> AST -> AST -> IO AST
mkBvsmod = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsmod

-- | Unsigned less than.
mkBvult :: Context -> AST -> AST -> IO AST
mkBvult :: Context -> AST -> AST -> IO AST
mkBvult = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvult

-- | Two's complement signed less than.
mkBvslt :: Context -> AST -> AST -> IO AST
mkBvslt :: Context -> AST -> AST -> IO AST
mkBvslt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvslt

-- | Unsigned less than or equal to.
mkBvule :: Context -> AST -> AST -> IO AST
mkBvule :: Context -> AST -> AST -> IO AST
mkBvule = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvule

-- | Two's complement signed less than or equal to.
mkBvsle :: Context -> AST -> AST -> IO AST
mkBvsle :: Context -> AST -> AST -> IO AST
mkBvsle = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsle

-- | Unsigned greater than or equal to.
mkBvuge :: Context -> AST -> AST -> IO AST
mkBvuge :: Context -> AST -> AST -> IO AST
mkBvuge = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvuge

-- | Two's complement signed greater than or equal to.
mkBvsge :: Context -> AST -> AST -> IO AST
mkBvsge :: Context -> AST -> AST -> IO AST
mkBvsge = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsge

-- | Unsigned greater than.
mkBvugt :: Context -> AST -> AST -> IO AST
mkBvugt :: Context -> AST -> AST -> IO AST
mkBvugt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvugt

-- | Two's complement signed greater than.
mkBvsgt :: Context -> AST -> AST -> IO AST
mkBvsgt :: Context -> AST -> AST -> IO AST
mkBvsgt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsgt

-- | Concatenate the given bit-vectors.
mkConcat :: Context -> AST -> AST -> IO AST
mkConcat :: Context -> AST -> AST -> IO AST
mkConcat = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_concat

-- | Extract the bits high down to low from a bitvector of size m to yield a new
-- bitvector of size /n/, where /n = high - low + 1/.
mkExtract :: Context -> Int -> Int -> AST -> IO AST
mkExtract :: Context -> Int -> Int -> AST -> IO AST
mkExtract = (Ptr Z3_context -> CUInt -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> Int -> Int -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context -> CUInt -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_extract

-- | Sign-extend of the given bit-vector to the (signed) equivalent bitvector
-- of size /m+i/, where /m/ is the size of the given bit-vector.
mkSignExt :: Context -> Int -> AST -> IO AST
mkSignExt :: Context -> Int -> AST -> IO AST
mkSignExt = (Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> Int -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_sign_ext

-- | Extend the given bit-vector with zeros to the (unsigned) equivalent
-- bitvector of size /m+i/, where /m/ is the size of the given bit-vector.
mkZeroExt :: Context -> Int -> AST -> IO AST
mkZeroExt :: Context -> Int -> AST -> IO AST
mkZeroExt = (Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> Int -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_zero_ext

-- | Repeat the given bit-vector up length /i/.
mkRepeat :: Context -> Int -> AST -> IO AST
mkRepeat :: Context -> Int -> AST -> IO AST
mkRepeat = (Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> Int -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_repeat

-- | Shift left.
mkBvshl :: Context -> AST -> AST -> IO AST
mkBvshl :: Context -> AST -> AST -> IO AST
mkBvshl = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvshl

-- | Logical shift right.
mkBvlshr :: Context -> AST -> AST -> IO AST
mkBvlshr :: Context -> AST -> AST -> IO AST
mkBvlshr = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvlshr

-- | Arithmetic shift right.
mkBvashr :: Context -> AST -> AST -> IO AST
mkBvashr :: Context -> AST -> AST -> IO AST
mkBvashr = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvashr

-- | Rotate bits of /t1/ to the left /i/ times.
mkRotateLeft :: Context -> Int -> AST -> IO AST
mkRotateLeft :: Context -> Int -> AST -> IO AST
mkRotateLeft = (Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> Int -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_rotate_left

-- | Rotate bits of /t1/ to the right /i/ times.
mkRotateRight :: Context -> Int -> AST -> IO AST
mkRotateRight :: Context -> Int -> AST -> IO AST
mkRotateRight = (Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> Int -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_rotate_right

-- | Rotate bits of /t1/ to the left /t2/ times.
mkExtRotateLeft :: Context -> AST -> AST -> IO AST
mkExtRotateLeft :: Context -> AST -> AST -> IO AST
mkExtRotateLeft = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_ext_rotate_left

-- | Rotate bits of /t1/ to the right /t2/ times.
mkExtRotateRight :: Context -> AST -> AST -> IO AST
mkExtRotateRight :: Context -> AST -> AST -> IO AST
mkExtRotateRight = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_ext_rotate_right

-- | Create an /n/ bit bit-vector from the integer argument /t1/.
mkInt2bv :: Context -> Int -> AST -> IO AST
mkInt2bv :: Context -> Int -> AST -> IO AST
mkInt2bv = (Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> Int -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_int2bv

-- | Create an integer from the bit-vector argument /t1/.
--
-- If /is_signed/ is false, then the bit-vector /t1/ is treated as unsigned.
-- So the result is non-negative and in the range [0..2^/N/-1],
-- where /N/ are the number of bits in /t1/.
-- If /is_signed/ is true, /t1/ is treated as a signed bit-vector.
mkBv2int :: Context -> AST -> Bool -> IO AST
mkBv2int :: Context -> AST -> Bool -> IO AST
mkBv2int = (Ptr Z3_context -> Ptr Z3_ast -> Z3_bool -> IO (Ptr Z3_ast))
-> Context -> AST -> Bool -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Z3_bool -> IO (Ptr Z3_ast)
z3_mk_bv2int

-- | Create a predicate that checks that the bit-wise addition of /t1/ and /t2/
-- does not overflow.
mkBvaddNoOverflow :: Context -> AST -> AST -> Bool -> IO AST
mkBvaddNoOverflow :: Context -> AST -> AST -> Bool -> IO AST
mkBvaddNoOverflow = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Z3_bool -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> Bool -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Z3_bool -> IO (Ptr Z3_ast)
z3_mk_bvadd_no_overflow

-- | Create a predicate that checks that the bit-wise signed addition of /t1/
-- and /t2/ does not underflow.
mkBvaddNoUnderflow :: Context -> AST -> AST -> IO AST
mkBvaddNoUnderflow :: Context -> AST -> AST -> IO AST
mkBvaddNoUnderflow = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvadd_no_underflow

-- | Create a predicate that checks that the bit-wise signed subtraction of /t1/
-- and /t2/ does not overflow.
mkBvsubNoOverflow :: Context -> AST -> AST -> IO AST
mkBvsubNoOverflow :: Context -> AST -> AST -> IO AST
mkBvsubNoOverflow = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsub_no_overflow

-- | Create a predicate that checks that the bit-wise subtraction of /t1/ and
-- /t2/ does not underflow.
mkBvsubNoUnderflow :: Context -> AST -> AST -> IO AST
mkBvsubNoUnderflow :: Context -> AST -> AST -> IO AST
mkBvsubNoUnderflow = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsub_no_underflow

-- | Create a predicate that checks that the bit-wise signed division of /t1/
-- and /t2/ does not overflow.
mkBvsdivNoOverflow :: Context -> AST -> AST -> IO AST
mkBvsdivNoOverflow :: Context -> AST -> AST -> IO AST
mkBvsdivNoOverflow = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvsdiv_no_overflow

-- | Check that bit-wise negation does not overflow when /t1/ is interpreted as
-- a signed bit-vector.
mkBvnegNoOverflow :: Context -> AST -> IO AST
mkBvnegNoOverflow :: Context -> AST -> IO AST
mkBvnegNoOverflow = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvneg_no_overflow

-- | Create a predicate that checks that the bit-wise multiplication of /t1/ and
-- /t2/ does not overflow.
mkBvmulNoOverflow :: Context -> AST -> AST -> Bool -> IO AST
mkBvmulNoOverflow :: Context -> AST -> AST -> Bool -> IO AST
mkBvmulNoOverflow = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Z3_bool -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> Bool -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Z3_bool -> IO (Ptr Z3_ast)
z3_mk_bvmul_no_overflow

-- | Create a predicate that checks that the bit-wise signed multiplication of
-- /t1/ and /t2/ does not underflow.
mkBvmulNoUnderflow :: Context -> AST -> AST -> IO AST
mkBvmulNoUnderflow :: Context -> AST -> AST -> IO AST
mkBvmulNoUnderflow = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_bvmul_no_underflow

---------------------------------------------------------------------
-- Arrays

-- | Array read. The argument a is the array and i is the index of the array
-- that gets read.
mkSelect :: Context
            -> AST      -- ^ Array.
            -> AST      -- ^ Index of the array to read.
            -> IO AST
mkSelect :: Context -> AST -> AST -> IO AST
mkSelect = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_select

-- | Array update.
--
-- The result of this function is an array that is equal to the input array
-- (with respect to select) on all indices except for i, where it maps to v.
--
-- The semantics of this function is given by the theory of arrays described
-- in the SMT-LIB standard. See <http://smtlib.org> for more details.
mkStore :: Context
          -> AST      -- ^ Array.
          -> AST      -- ^ Index /i/ of the array.
          -> AST      -- ^ New value for /i/.
          -> IO AST
mkStore :: Context -> AST -> AST -> AST -> IO AST
mkStore = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_store

-- | Create the constant array.
--
-- The resulting term is an array, such that a select on an arbitrary index
-- produces the value /v/.
mkConstArray :: Context
            -> Sort   -- ^ Domain sort of the array.
            -> AST    -- ^ Value /v/ that the array maps to.
            -> IO AST
mkConstArray :: Context -> Sort -> AST -> IO AST
mkConstArray = (Ptr Z3_context -> Ptr Z3_sort -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> Sort -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_sort -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_const_array

-- | Map a function /f/ on the the argument arrays.
--
-- The /n/ nodes args must be of array sorts [domain -> range_i].
-- The function declaration /f/ must have type range_1 .. range_n -> range.
-- The sort of the result is [domain -> range].
mkMap :: Context
        -> FuncDecl   -- ^ Function /f/.
        -> [AST]      -- ^ List of arrays.
        -> IO AST
mkMap :: Context -> FuncDecl -> [AST] -> IO AST
mkMap Context
ctx FuncDecl
fun [AST]
args = (Ptr Z3_context
 -> Ptr Z3_func_decl
 -> CUInt
 -> Ptr (Ptr Z3_ast)
 -> IO (Ptr Z3_ast))
-> Context
-> ((Ptr Z3_func_decl
     -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_func_decl -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_map Context
ctx (((Ptr Z3_func_decl
   -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((Ptr Z3_func_decl
     -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f ->
  FuncDecl
-> (Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. FuncDecl -> (Ptr Z3_func_decl -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c FuncDecl
fun ((Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl
funPtr ->
  [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
args ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr ->
    Ptr Z3_func_decl -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Ptr Z3_func_decl
funPtr CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr

-- | Access the array default value.
--
-- Produces the default range value, for arrays that can be represented as
-- finite maps with a default range value.
mkArrayDefault :: Context
                -> AST      -- ^ Array.
                -> IO AST
mkArrayDefault :: Context -> AST -> IO AST
mkArrayDefault = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_array_default

---------------------------------------------------------------------
-- Sets

-- | Create the empty set.
mkEmptySet :: Context
            -> Sort   -- ^ Domain sort of the set.
            -> IO AST
mkEmptySet :: Context -> Sort -> IO AST
mkEmptySet = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Sort -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_empty_set

-- | Create the full set.
mkFullSet :: Context
            -> Sort   -- ^ Domain sort of the set.
            -> IO AST
mkFullSet :: Context -> Sort -> IO AST
mkFullSet = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Sort -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_full_set

-- | Add an element to a set.
mkSetAdd :: Context
          -> AST      -- ^ Set.
          -> AST      -- ^ Element.
          -> IO AST
mkSetAdd :: Context -> AST -> AST -> IO AST
mkSetAdd = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_set_add

-- | Remove an element from a set.
mkSetDel :: Context
          -> AST      -- ^ Set.
          -> AST      -- ^ Element.
          -> IO AST
mkSetDel :: Context -> AST -> AST -> IO AST
mkSetDel = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_set_del

-- | Take the union of a list of sets.
mkSetUnion :: Context -> [AST] -> IO AST
mkSetUnion :: Context -> [AST] -> IO AST
mkSetUnion Context
ctx [AST]
args = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_set_union Context
ctx (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f ->
  [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
args ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr ->
    CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr

-- | Take the intersection of a list of sets.
mkSetIntersect :: Context -> [AST] -> IO AST
mkSetIntersect :: Context -> [AST] -> IO AST
mkSetIntersect Context
ctx [AST]
args = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_set_intersect Context
ctx (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f ->
  [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
args ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr ->
    CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f CUInt
argsNum Ptr (Ptr Z3_ast)
argsArr

-- | Take the set difference between two sets.
mkSetDifference :: Context
          -> AST      -- ^ First set.
          -> AST      -- ^ Second set.
          -> IO AST
mkSetDifference :: Context -> AST -> AST -> IO AST
mkSetDifference = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_set_difference

-- | Take the complement of a set.
mkSetComplement :: Context
          -> AST      -- ^ Set.
          -> IO AST
mkSetComplement :: Context -> AST -> IO AST
mkSetComplement = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_set_complement

-- | Check for set membership.
mkSetMember :: Context
          -> AST      -- ^ Element.
          -> AST      -- ^ Set.
          -> IO AST
mkSetMember :: Context -> AST -> AST -> IO AST
mkSetMember = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_set_member

-- | Check if the first set is a subset of the second set.
mkSetSubset :: Context
          -> AST      -- ^ First set.
          -> AST      -- ^ Second set.
          -> IO AST
mkSetSubset :: Context -> AST -> AST -> IO AST
mkSetSubset = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_set_subset

---------------------------------------------------------------------
-- * Numerals

-- | Create a numeral of a given sort.
mkNumeral :: Context -> String -> Sort -> IO AST
mkNumeral :: Context -> String -> Sort -> IO AST
mkNumeral = (Ptr Z3_context -> Z3_string -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> String -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Z3_string -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_numeral

-- | Create a real from a fraction.
mkReal :: Context -> Int   -- ^ numerator
                  -> Int   -- ^ denominator (/= 0)
                  -> IO AST
mkReal :: Context -> Int -> Int -> IO AST
mkReal Context
ctx Int
num Int
den
  | Int
den Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0  = (Ptr Z3_context
 -> Z3_error_code -> Z3_error_code -> IO (Ptr Z3_ast))
-> Context -> Int -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Z3_error_code -> Z3_error_code -> IO (Ptr Z3_ast)
z3_mk_real Context
ctx Int
num Int
den
  | Bool
otherwise = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReal: zero denominator"

-- | Create a numeral of an int, bit-vector, or finite-domain sort.
--
-- This function can be use to create numerals that fit in a
-- /machine integer/.
-- It is slightly faster than 'mkNumeral' since it is not necessary
-- to parse a string.
mkInt :: Context -> Int -> Sort -> IO AST
mkInt :: Context -> Int -> Sort -> IO AST
mkInt = (Ptr Z3_context -> Z3_error_code -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Int -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Z3_error_code -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_int

-- | Create a numeral of an int, bit-vector, or finite-domain sort.
--
-- This function can be use to create numerals that fit in a
-- /machine unsigned integer/.
-- It is slightly faster than 'mkNumeral' since it is not necessary
-- to parse a string.
mkUnsignedInt :: Context -> Word -> Sort -> IO AST
mkUnsignedInt :: Context -> Word -> Sort -> IO AST
mkUnsignedInt = (Ptr Z3_context -> CUInt -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Word -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_unsigned_int

-- | Create a numeral of an int, bit-vector, or finite-domain sort.
--
-- This function can be use to create numerals that fit in a
-- /machine 64-bit integer/.
-- It is slightly faster than 'mkNumeral' since it is not necessary
-- to parse a string.
mkInt64 :: Context -> Int64 -> Sort -> IO AST
mkInt64 :: Context -> Int64 -> Sort -> IO AST
mkInt64 = (Ptr Z3_context -> CLLong -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Int64 -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CLLong -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_int64

-- | Create a numeral of an int, bit-vector, or finite-domain sort.
--
-- This function can be use to create numerals that fit in a
-- /machine unsigned 64-bit integer/.
-- It is slightly faster than 'mkNumeral' since it is not necessary
-- to parse a string.
mkUnsignedInt64 :: Context -> Word64 -> Sort -> IO AST
mkUnsignedInt64 :: Context -> Word64 -> Sort -> IO AST
mkUnsignedInt64 = (Ptr Z3_context -> CULLong -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Word64 -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CULLong -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_unsigned_int64

-------------------------------------------------
-- ** Helpers

-- | Create a numeral of an int, bit-vector, or finite-domain sort.
mkIntegral :: Integral a => Context -> a -> Sort -> IO AST
mkIntegral :: forall a. Integral a => Context -> a -> Sort -> IO AST
mkIntegral Context
c a
n Sort
s = Context -> String -> Sort -> IO AST
mkNumeral Context
c String
n_str Sort
s
  where n_str :: String
n_str = Integer -> String
forall a. Show a => a -> String
show (Integer -> String) -> Integer -> String
forall a b. (a -> b) -> a -> b
$ a -> Integer
forall a. Integral a => a -> Integer
toInteger a
n

-- | Create a numeral of sort /real/ from a 'Rational'.
mkRational :: Context -> Rational -> IO AST
mkRational :: Context -> Rational -> IO AST
mkRational = Context -> Rational -> IO AST
forall r. Real r => Context -> r -> IO AST
mkRealNum

-- | Create a numeral of sort /real/ from a 'Fixed'.
mkFixed :: HasResolution a => Context -> Fixed a -> IO AST
mkFixed :: forall a. HasResolution a => Context -> Fixed a -> IO AST
mkFixed Context
ctx = Context -> Rational -> IO AST
mkRational Context
ctx (Rational -> IO AST) -> (Fixed a -> Rational) -> Fixed a -> IO AST
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed a -> Rational
forall a. Real a => a -> Rational
toRational

-- | Create a numeral of sort /real/ from a 'Real'.
mkRealNum :: Real r => Context -> r -> IO AST
mkRealNum :: forall r. Real r => Context -> r -> IO AST
mkRealNum Context
c r
n = Context -> String -> Sort -> IO AST
mkNumeral Context
c String
n_str (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> IO Sort
mkRealSort Context
c
  where r :: Rational
r     = r -> Rational
forall a. Real a => a -> Rational
toRational r
n
        r_n :: Integer
r_n   = Integer -> Integer
forall a. Integral a => a -> Integer
toInteger (Integer -> Integer) -> Integer -> Integer
forall a b. (a -> b) -> a -> b
$ Rational -> Integer
forall a. Ratio a -> a
numerator Rational
r
        r_d :: Integer
r_d   = Integer -> Integer
forall a. Integral a => a -> Integer
toInteger (Integer -> Integer) -> Integer -> Integer
forall a b. (a -> b) -> a -> b
$ Rational -> Integer
forall a. Ratio a -> a
denominator Rational
r
        n_str :: String
n_str = Integer -> String
forall a. Show a => a -> String
show Integer
r_n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" / " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
r_d

-- | Create a numeral of sort /int/ from an 'Integer'.
mkInteger :: Context -> Integer -> IO AST
mkInteger :: Context -> Integer -> IO AST
mkInteger = Context -> Integer -> IO AST
forall a. Integral a => Context -> a -> IO AST
mkIntNum

-- | Create a numeral of sort /int/ from an 'Integral'.
mkIntNum :: Integral a => Context -> a -> IO AST
mkIntNum :: forall a. Integral a => Context -> a -> IO AST
mkIntNum Context
ctx a
n = Context -> a -> Sort -> IO AST
forall a. Integral a => Context -> a -> Sort -> IO AST
mkIntegral Context
ctx a
n (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> IO Sort
mkIntSort Context
ctx

-- | Create a numeral of sort /Bit-vector/ from an 'Integer'.
mkBitvector :: Context -> Int      -- ^ bit-width
                       -> Integer  -- ^ integer value
                       -> IO AST
mkBitvector :: Context -> Int -> Integer -> IO AST
mkBitvector = Context -> Int -> Integer -> IO AST
forall i. Integral i => Context -> Int -> i -> IO AST
mkBvNum

-- | Create a numeral of sort /Bit-vector/ from an 'Integral'.
mkBvNum :: Integral i => Context -> Int    -- ^ bit-width
                                 -> i      -- ^ integer value
                                 -> IO AST
mkBvNum :: forall i. Integral i => Context -> Int -> i -> IO AST
mkBvNum Context
ctx Int
s i
n = Context -> i -> Sort -> IO AST
forall a. Integral a => Context -> a -> Sort -> IO AST
mkIntegral Context
ctx i
n (Sort -> IO AST) -> IO Sort -> IO AST
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context -> Int -> IO Sort
forall int. Integral int => Context -> int -> IO Sort
mkBvSort Context
ctx Int
s

---------------------------------------------------------------------
-- Sequences and regular expressions

-- | Create a sequence sort out of the sort for the elements.
mkSeqSort :: Context -> Sort -> IO Sort
mkSeqSort :: Context -> Sort -> IO Sort
mkSeqSort = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort))
-> Context -> Sort -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort)
z3_mk_seq_sort

-- | Check if s is a sequence sort.
isSeqSort :: Context -> Sort -> IO Bool
isSeqSort :: Context -> Sort -> IO Bool
isSeqSort = (Ptr Z3_context -> Ptr Z3_sort -> IO Z3_bool)
-> Context -> Sort -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO Z3_bool
z3_is_seq_sort

-- | Create a regular expression sort out of a sequence sort.
mkReSort :: Context -> Sort -> IO Sort
mkReSort :: Context -> Sort -> IO Sort
mkReSort = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort))
-> Context -> Sort -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort)
z3_mk_re_sort

-- | Check if s is a regular expression sort.
isReSort :: Context -> Sort -> IO Bool
isReSort :: Context -> Sort -> IO Bool
isReSort = (Ptr Z3_context -> Ptr Z3_sort -> IO Z3_bool)
-> Context -> Sort -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO Z3_bool
z3_is_re_sort

-- | Create a sort for 8 bit strings. This function creates a sort for ASCII
-- strings. Each character is 8 bits.
mkStringSort :: Context -> IO Sort
mkStringSort :: Context -> IO Sort
mkStringSort = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_string_sort

-- | Check if s is a string sort.
isStringSort :: Context -> Sort -> IO Bool
isStringSort :: Context -> Sort -> IO Bool
isStringSort = (Ptr Z3_context -> Ptr Z3_sort -> IO Z3_bool)
-> Context -> Sort -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO Z3_bool
z3_is_string_sort

-- | Create a string constant out of the string that is passed in.
mkString :: Context -> String -> IO AST
mkString :: Context -> String -> IO AST
mkString = (Ptr Z3_context -> Z3_string -> IO (Ptr Z3_ast))
-> Context -> String -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Z3_string -> IO (Ptr Z3_ast)
z3_mk_string

-- | Determine if s is a string constant.
isString :: Context -> AST -> IO Bool
isString :: Context -> AST -> IO Bool
isString = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_is_string

-- | Retrieve the string constant stored in s.
getString :: Context -> AST -> IO String
getString :: Context -> AST -> IO String
getString = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_string)
-> Context -> AST -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_string
z3_get_string

-- | Create an empty sequence of the sequence sort seq.
mkSeqEmpty :: Context -> Sort -> IO AST
mkSeqEmpty :: Context -> Sort -> IO AST
mkSeqEmpty = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Sort -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_seq_empty

-- | Create a unit sequence of a.
mkSeqUnit :: Context -> AST -> IO AST
mkSeqUnit :: Context -> AST -> IO AST
mkSeqUnit = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_unit

-- | Concatenate sequences.
mkSeqConcat :: Context -> [AST] -> IO AST
mkSeqConcat :: Context -> [AST] -> IO AST
mkSeqConcat Context
c [AST]
as
  | [AST] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [AST]
as = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkSeqConcet: empty list of expressions"
  | Bool
otherwise         = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_seq_concat Context
c (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
as

-- | Check if prefix is a prefix of s.
mkSeqPrefix :: Context
            -> AST -- ^ prefix
            -> AST -- ^ s
            -> IO AST
mkSeqPrefix :: Context -> AST -> AST -> IO AST
mkSeqPrefix = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_prefix

-- | Check if suffix is a suffix of s.
mkSeqSuffix :: Context
            -> AST -- ^ suffix
            -> AST -- ^ s
            -> IO AST
mkSeqSuffix :: Context -> AST -> AST -> IO AST
mkSeqSuffix = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_suffix

-- | Check if container contains containee.
mkSeqContains :: Context
              -> AST -- ^ container
              -> AST -- ^ containee
              -> IO AST
mkSeqContains :: Context -> AST -> AST -> IO AST
mkSeqContains = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_contains

-- | Check if s1 is equal or lexicographically strictly less than s2.
mkStrLt :: Context
        -> AST -- ^ s1
        -> AST -- ^ s2
        -> IO AST
mkStrLt :: Context -> AST -> AST -> IO AST
mkStrLt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_str_lt

-- | Check if s1 is lexicographically strictly less than s2.
mkStrLe :: Context
        -> AST -- ^ s1
        -> AST -- ^ s2
        -> IO AST
mkStrLe :: Context -> AST -> AST -> IO AST
mkStrLe = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_str_le

-- | Extract subsequence starting at offset of length.
mkSeqExtract :: Context
             -> AST -- ^ s
             -> AST -- ^ offset
             -> AST -- ^ length
             -> IO AST
mkSeqExtract :: Context -> AST -> AST -> AST -> IO AST
mkSeqExtract = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_extract

-- | Replace the first occurrence of src with dst in s.
mkSeqReplace :: Context
             -> AST -- ^ s
             -> AST -- ^ src
             -> AST -- ^ dst
             -> IO AST
mkSeqReplace :: Context -> AST -> AST -> AST -> IO AST
mkSeqReplace = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_replace

-- | Retrieve from s the unit sequence positioned at position index.
mkSeqAt :: Context
        -> AST -- ^ s
        -> AST -- ^ index
        -> IO AST
mkSeqAt :: Context -> AST -> AST -> IO AST
mkSeqAt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_at

-- | Return the length of the sequence s.
mkSeqLength :: Context
            -> AST -- ^ s
            -> IO AST
mkSeqLength :: Context -> AST -> IO AST
mkSeqLength = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_length

-- | Return index of first occurrence of substr in s starting from offset
-- offset. If s does not contain substr, then the value is -1, if offset is the
-- length of s, then the value is -1 as well. The function is under-specified if
-- offset is negative or larger than the length of s.
mkSeqIndex :: Context
           -> AST -- ^ s
           -> AST -- ^ substr
           -> AST -- ^ offset
           -> IO AST
mkSeqIndex :: Context -> AST -> AST -> AST -> IO AST
mkSeqIndex = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_index

-- | Convert string to integer.
mkStrToInt :: Context -> AST -> IO AST
mkStrToInt :: Context -> AST -> IO AST
mkStrToInt = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_str_to_int

-- | Integer to string conversion.
mkIntToStr :: Context -> AST -> IO AST
mkIntToStr :: Context -> AST -> IO AST
mkIntToStr = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_int_to_str

-- | Create a regular expression that accepts the sequence.
mkSeqToRe :: Context -> AST -> IO AST
mkSeqToRe :: Context -> AST -> IO AST
mkSeqToRe = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_to_re

-- | Check if seq is in the language generated by the regular expression re.
mkSeqInRe :: Context
          -> AST -- ^ seq
          -> AST -- ^ re
          -> IO AST
mkSeqInRe :: Context -> AST -> AST -> IO AST
mkSeqInRe = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_seq_in_re

-- | Create the regular language re+.
mkRePlus :: Context -> AST -> IO AST
mkRePlus :: Context -> AST -> IO AST
mkRePlus = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_re_plus

-- | Create the regular language re*.
mkReStar :: Context -> AST -> IO AST
mkReStar :: Context -> AST -> IO AST
mkReStar = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_re_star

-- | Create the regular language [re].
mkReOption :: Context -> AST -> IO AST
mkReOption :: Context -> AST -> IO AST
mkReOption = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_re_option

-- | Create the union of the regular languages.
mkReUnion :: (Integral int) => Context -> int -> [AST] -> IO AST
mkReUnion :: forall int. Integral int => Context -> int -> [AST] -> IO AST
mkReUnion Context
c int
i [AST]
as
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
<  int
0            = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReUnion: negative size"
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
>= int
0 Bool -> Bool -> Bool
&& [AST] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [AST]
as = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReUnion: empty list of expressions"
  | Bool
otherwise         = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_re_union Context
c (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
as

-- | Create the concatenation of the regular languages.
mkReConcat :: (Integral int) => Context -> int -> [AST] -> IO AST
mkReConcat :: forall int. Integral int => Context -> int -> [AST] -> IO AST
mkReConcat Context
c int
i [AST]
as
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
<  int
0            = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReConcat: negative size"
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
>= int
0 Bool -> Bool -> Bool
&& [AST] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [AST]
as = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReConcat: empty list of expressions"
  | Bool
otherwise         = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_re_concat Context
c (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
as

-- | Create the range regular expression over two sequences of length 1.
mkReRange :: Context
          -> AST -- ^ lo
          -> AST -- ^ hi
          -> IO AST
mkReRange :: Context -> AST -> AST -> IO AST
mkReRange = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_re_range

-- | Create a regular expression loop. The supplied regular expression r is
-- repeated between lo and hi times. The lo should be below hi with one
-- exception: when supplying the value hi as 0, the meaning is to repeat the
-- argument r at least lo number of times, and with an unbounded upper bound.
mkReLoop :: (Integral int)
         => Context
         -> AST -- ^ r
         -> int -- ^ lo
         -> int -- ^ hi
         -> IO AST
mkReLoop :: forall int. Integral int => Context -> AST -> int -> int -> IO AST
mkReLoop Context
c AST
a int
i int
j
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
< int
0     = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReLoop: negative size"
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
< int
0     = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReLoop: empty list of expressions"
  | Bool
otherwise = (Ptr Z3_context -> Ptr Z3_ast -> CUInt -> CUInt -> IO (Ptr Z3_ast))
-> Context -> AST -> int -> int -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context -> Ptr Z3_ast -> CUInt -> CUInt -> IO (Ptr Z3_ast)
z3_mk_re_loop Context
c AST
a int
i int
j

-- | Create the intersection of the regular languages.
mkReIntersect :: (Integral int) => Context -> int -> [AST] -> IO AST
mkReIntersect :: forall int. Integral int => Context -> int -> [AST] -> IO AST
mkReIntersect Context
c int
i [AST]
as
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
<  int
0            = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReIntersect: negative size"
  | int
i int -> int -> Bool
forall a. Ord a => a -> a -> Bool
>= int
0 Bool -> Bool -> Bool
&& [AST] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [AST]
as = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkReIntersect: empty list of expressions"
  | Bool
otherwise         = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_mk_re_intersect Context
c (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
as

-- | Create the complement of the regular language.
mkReComplement :: Context -> AST -> IO AST
mkReComplement :: Context -> AST -> IO AST
mkReComplement = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_re_complement

-- | Create an empty regular expression of sort re.
mkReEmpty :: Context -> Sort -> IO AST
mkReEmpty :: Context -> Sort -> IO AST
mkReEmpty = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Sort -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_re_empty

-- | Create an universal regular expression of sort re.
mkReFull :: Context -> Sort -> IO AST
mkReFull :: Context -> Sort -> IO AST
mkReFull = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Sort -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_re_full

 ---------------------------------------------------------------------
-- Quantifiers

-- | Create a pattern for quantifier instantiation.
--
-- Z3 uses pattern matching to instantiate quantifiers.
-- If a pattern is not provided for a quantifier, then Z3 will automatically
-- compute a set of patterns for it. However, for optimal performance,
-- the user should provide the patterns.
--
-- Patterns comprise a list of terms.
-- The list should be non-empty.
-- If the list comprises of more than one term, it is a called a multi-pattern.
--
-- In general, one can pass in a list of (multi-)patterns in the quantifier
-- constructor.
mkPattern :: Context
              -> [AST]        -- ^ Terms.
              -> IO Pattern
mkPattern :: Context -> [AST] -> IO Pattern
mkPattern Context
_ [] = String -> IO Pattern
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkPattern: empty list of expressions"
mkPattern Context
c [AST]
es = (Ptr Z3_context
 -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_pattern))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_pattern))
    -> IO (Ptr Z3_pattern))
-> IO Pattern
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_pattern)
z3_mk_pattern Context
c (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_pattern))
  -> IO (Ptr Z3_pattern))
 -> IO Pattern)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_pattern))
    -> IO (Ptr Z3_pattern))
-> IO Pattern
forall a b. (a -> b) -> a -> b
$ [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_pattern))
-> IO (Ptr Z3_pattern)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
es

-- | Create a bound variable.
--
-- Bound variables are indexed by de-Bruijn indices.
--
-- See <http://z3prover.github.io/api/html/group__capi.html#ga1d4da8849fca699b345322f8ee1fa31e>
mkBound :: Context
            -> Int    -- ^ de-Bruijn index.
            -> Sort
            -> IO AST
mkBound :: Context -> Int -> Sort -> IO AST
mkBound Context
c Int
i Sort
s
  | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0    = (Ptr Z3_context -> CUInt -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Int -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_bound Context
c Int
i Sort
s
  | Bool
otherwise = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkBound: negative de-Bruijn index"

type MkZ3Quantifier = Ptr Z3_context -> CUInt
                      -> CUInt -> Ptr (Ptr Z3_pattern)
                      -> CUInt -> Ptr (Ptr Z3_sort) -> Ptr (Ptr Z3_symbol)
                      -> Ptr Z3_ast
                      -> IO (Ptr Z3_ast)

marshalMkQ :: MkZ3Quantifier
          -> Context
          -> Int
          -> [Pattern]
          -> [Symbol]
          -> [Sort]
          -> AST
          -> IO AST
marshalMkQ :: MkZ3Quantifier
-> Context
-> Int
-> [Pattern]
-> [Symbol]
-> [Sort]
-> AST
-> IO AST
marshalMkQ MkZ3Quantifier
z3_mk_Q Context
ctx Int
weight [Pattern]
pats [Symbol]
x [Sort]
s AST
body = MkZ3Quantifier
-> Context
-> ((CUInt
     -> CUInt
     -> Ptr (Ptr Z3_pattern)
     -> CUInt
     -> Ptr (Ptr Z3_sort)
     -> Ptr (Ptr Z3_symbol)
     -> Ptr Z3_ast
     -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal MkZ3Quantifier
z3_mk_Q Context
ctx (((CUInt
   -> CUInt
   -> Ptr (Ptr Z3_pattern)
   -> CUInt
   -> Ptr (Ptr Z3_sort)
   -> Ptr (Ptr Z3_symbol)
   -> Ptr Z3_ast
   -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt
     -> CUInt
     -> Ptr (Ptr Z3_pattern)
     -> CUInt
     -> Ptr (Ptr Z3_sort)
     -> Ptr (Ptr Z3_symbol)
     -> Ptr Z3_ast
     -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \CUInt
-> CUInt
-> Ptr (Ptr Z3_pattern)
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr (Ptr Z3_symbol)
-> Ptr Z3_ast
-> IO (Ptr Z3_ast)
f ->
  [Pattern]
-> (CUInt -> Ptr (Ptr Z3_pattern) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Pattern]
pats ((CUInt -> Ptr (Ptr Z3_pattern) -> IO (Ptr Z3_ast))
 -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_pattern) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
n Ptr (Ptr Z3_pattern)
patsArr ->
  [Symbol]
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [Symbol]
x ((Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_symbol)
xArr ->
  [Sort] -> (Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [Sort]
s ((Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_sort)
sArr ->
  Int -> (CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. Int -> (CUInt -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Int
weight ((CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
weightC ->
  AST -> (Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
body ((Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
bodyPtr ->
    CUInt
-> CUInt
-> Ptr (Ptr Z3_pattern)
-> CUInt
-> Ptr (Ptr Z3_sort)
-> Ptr (Ptr Z3_symbol)
-> Ptr Z3_ast
-> IO (Ptr Z3_ast)
f CUInt
weightC CUInt
n Ptr (Ptr Z3_pattern)
patsArr CUInt
len Ptr (Ptr Z3_sort)
sArr Ptr (Ptr Z3_symbol)
xArr Ptr Z3_ast
bodyPtr
  where len :: CUInt
len
          | Int
l Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0        = String -> CUInt
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkQuantifier:\
              \ quantifier with 0 bound variables"
          | Int
l Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= [Symbol] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Symbol]
x = String -> CUInt
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkQuantifier:\
              \ different number of symbols and sorts"
          | Bool
otherwise     = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
l
          where l :: Int
l = [Sort] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Sort]
s
-- | 'mkForall' with weight 0 (the default).
mkForall :: Context
          -> [Pattern]  -- ^ Instantiation patterns (see 'mkPattern').
          -> [Symbol]   -- ^ Bound (quantified) variables /xs/.
          -> [Sort]     -- ^ Sorts of the bound variables.
          -> AST        -- ^ Body of the quantifier.
          -> IO AST
mkForall :: Context -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST
mkForall = (Context
 -> Int -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST)
-> Int
-> Context
-> [Pattern]
-> [Symbol]
-> [Sort]
-> AST
-> IO AST
forall a b c. (a -> b -> c) -> b -> a -> c
flip Context -> Int -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST
mkForallW Int
0

-- | Create a forall formula.
--
-- The bound variables are de-Bruijn indices created using 'mkBound'.
--
-- Z3 applies the convention that the last element in /xs/ refers to the
-- variable with index 0, the second to last element of /xs/ refers to the
-- variable with index 1, etc.
mkForallW :: Context
          -> Int        -- ^ quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.
          -> [Pattern]  -- ^ Instantiation patterns (see 'mkPattern').
          -> [Symbol]   -- ^ Bound (quantified) variables /xs/.
          -> [Sort]     -- ^ Sorts of the bound variables.
          -> AST        -- ^ Body of the quantifier.
          -> IO AST
mkForallW :: Context -> Int -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST
mkForallW = MkZ3Quantifier
-> Context
-> Int
-> [Pattern]
-> [Symbol]
-> [Sort]
-> AST
-> IO AST
marshalMkQ MkZ3Quantifier
z3_mk_forall


-- | Create an exists formula.
--
-- Similar to 'mkForallW'.
mkExistsW :: Context -> Int -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST
mkExistsW :: Context -> Int -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST
mkExistsW = MkZ3Quantifier
-> Context
-> Int
-> [Pattern]
-> [Symbol]
-> [Sort]
-> AST
-> IO AST
marshalMkQ MkZ3Quantifier
z3_mk_exists

-- | `mkExistsW` with weight 0 (the default).
mkExists :: Context -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST
mkExists :: Context -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST
mkExists = (Context
 -> Int -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST)
-> Int
-> Context
-> [Pattern]
-> [Symbol]
-> [Sort]
-> AST
-> IO AST
forall a b c. (a -> b -> c) -> b -> a -> c
flip Context -> Int -> [Pattern] -> [Symbol] -> [Sort] -> AST -> IO AST
mkExistsW Int
0

-- TODO: Z3_mk_quantifier
-- TODO: Z3_mk_quantifier_ex

type MkZ3QuantifierConst = Ptr Z3_context
                           -> CUInt
                           -> CUInt
                           -> Ptr (Ptr Z3_app)
                           -> CUInt
                           -> Ptr (Ptr Z3_pattern)
                           -> Ptr Z3_ast
                           -> IO (Ptr Z3_ast)

marshalMkQConst :: MkZ3QuantifierConst
                  -> Context
                  -> Int
                  -> [Pattern]
                  -> [App]
                  -> AST
                -> IO AST
marshalMkQConst :: MkZ3QuantifierConst
-> Context -> Int -> [Pattern] -> [App] -> AST -> IO AST
marshalMkQConst MkZ3QuantifierConst
z3_mk_Q_const Context
ctx Int
weight [Pattern]
pats [App]
apps AST
body =
  MkZ3QuantifierConst
-> Context
-> ((CUInt
     -> CUInt
     -> Ptr (Ptr Z3_app)
     -> CUInt
     -> Ptr (Ptr Z3_pattern)
     -> Ptr Z3_ast
     -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal MkZ3QuantifierConst
z3_mk_Q_const Context
ctx (((CUInt
   -> CUInt
   -> Ptr (Ptr Z3_app)
   -> CUInt
   -> Ptr (Ptr Z3_pattern)
   -> Ptr Z3_ast
   -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt
     -> CUInt
     -> Ptr (Ptr Z3_app)
     -> CUInt
     -> Ptr (Ptr Z3_pattern)
     -> Ptr Z3_ast
     -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \CUInt
-> CUInt
-> Ptr (Ptr Z3_app)
-> CUInt
-> Ptr (Ptr Z3_pattern)
-> Ptr Z3_ast
-> IO (Ptr Z3_ast)
f ->
    [Pattern]
-> (CUInt -> Ptr (Ptr Z3_pattern) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Pattern]
pats ((CUInt -> Ptr (Ptr Z3_pattern) -> IO (Ptr Z3_ast))
 -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_pattern) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
patsNum Ptr (Ptr Z3_pattern)
patsArr ->
    [App] -> (Ptr (Ptr Z3_app) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray    [App]
apps ((Ptr (Ptr Z3_app) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr (Ptr Z3_app) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_app)
appsArr ->
    Int -> (CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. Int -> (CUInt -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Int
weight ((CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
weightC ->
    AST -> (Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
body ((Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
bodyPtr ->
      CUInt
-> CUInt
-> Ptr (Ptr Z3_app)
-> CUInt
-> Ptr (Ptr Z3_pattern)
-> Ptr Z3_ast
-> IO (Ptr Z3_ast)
f CUInt
weightC CUInt
len Ptr (Ptr Z3_app)
appsArr CUInt
patsNum Ptr (Ptr Z3_pattern)
patsArr Ptr Z3_ast
bodyPtr
  where len :: CUInt
len
          | Int
l Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0        = String -> CUInt
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkQuantifierConst:\
              \ quantifier with 0 bound variables"
          | Bool
otherwise     = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
l
          where l :: Int
l = [App] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [App]
apps

-- | Create a universal quantifier using a list of constants that will form the
-- set of bound variables.
mkForallWConst :: Context
              -> Int       -- ^ quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.

              -> [Pattern] -- ^ Instantiation patterns (see 'mkPattern').
              -> [App]     -- ^ Constants to be abstracted into bound variables.
              -> AST       -- ^ Quantifier body.
              -> IO AST
mkForallWConst :: Context -> Int -> [Pattern] -> [App] -> AST -> IO AST
mkForallWConst = MkZ3QuantifierConst
-> Context -> Int -> [Pattern] -> [App] -> AST -> IO AST
marshalMkQConst MkZ3QuantifierConst
z3_mk_forall_const


-- | 'mkForallWConst' with weight set to 0 (the default).
mkForallConst :: Context -> [Pattern] -> [App] -> AST -> IO AST
mkForallConst :: Context -> [Pattern] -> [App] -> AST -> IO AST
mkForallConst = (Context -> Int -> [Pattern] -> [App] -> AST -> IO AST)
-> Int -> Context -> [Pattern] -> [App] -> AST -> IO AST
forall a b c. (a -> b -> c) -> b -> a -> c
flip Context -> Int -> [Pattern] -> [App] -> AST -> IO AST
mkForallWConst Int
0

-- | Create a existential quantifier using a list of constants that will form
-- the set of bound variables.
mkExistsWConst :: Context
              -> Int       -- ^ quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.
              -> [Pattern] -- ^ Instantiation patterns (see 'mkPattern').
              -> [App]     -- ^ Constants to be abstracted into bound variables.
              -> AST       -- ^ Quantifier body.
              -> IO AST
mkExistsWConst :: Context -> Int -> [Pattern] -> [App] -> AST -> IO AST
mkExistsWConst = MkZ3QuantifierConst
-> Context -> Int -> [Pattern] -> [App] -> AST -> IO AST
marshalMkQConst MkZ3QuantifierConst
z3_mk_exists_const

-- | 'mkForallWConst' with weight set to 0 (the default).
mkExistsConst :: Context -> [Pattern] -> [App] -> AST -> IO AST
mkExistsConst :: Context -> [Pattern] -> [App] -> AST -> IO AST
mkExistsConst = (Context -> Int -> [Pattern] -> [App] -> AST -> IO AST)
-> Int -> Context -> [Pattern] -> [App] -> AST -> IO AST
forall a b c. (a -> b -> c) -> b -> a -> c
flip Context -> Int -> [Pattern] -> [App] -> AST -> IO AST
mkExistsWConst Int
0

-- TODO: Z3_mk_quantifier_const
-- TODO: Z3_mk_quantifier_const_ex

---------------------------------------------------------------------
-- Accessors

-- TODO: Z3_get_symbol_kind

-- TODO: Z3_get_symbol_int

-- | Return the symbol name.
getSymbolString :: Context -> Symbol -> IO String
getSymbolString :: Context -> Symbol -> IO String
getSymbolString = (Ptr Z3_context -> Ptr Z3_symbol -> IO Z3_string)
-> Context -> Symbol -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_symbol -> IO Z3_string
z3_get_symbol_string

-- | Return the sort name as a symbol.
getSortName :: Context -> Sort -> IO Symbol
getSortName :: Context -> Sort -> IO Symbol
getSortName = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_symbol))
-> Context -> Sort -> IO Symbol
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_symbol)
z3_get_sort_name

-- | Convert a Z3_sort into Z3_ast. This is just type casting.
sortToAst :: Context -> Sort -> IO AST
sortToAst :: Context -> Sort -> IO AST
sortToAst = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Sort -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_sort_to_ast

-- | Return a unique identifier for s.
getSortId :: Context -> Sort -> IO Int
getSortId :: Context -> Sort -> IO Int
getSortId = (Ptr Z3_context -> Ptr Z3_sort -> IO CUInt)
-> Context -> Sort -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO CUInt
z3_get_sort_id

-- | Compare sorts.
isEqSort :: Context -> Sort -> Sort -> IO Bool
isEqSort :: Context -> Sort -> Sort -> IO Bool
isEqSort = (Ptr Z3_context -> Ptr Z3_sort -> Ptr Z3_sort -> IO Z3_bool)
-> Context -> Sort -> Sort -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_sort -> Ptr Z3_sort -> IO Z3_bool
z3_is_eq_sort

-- | Return the sort kind of the given sort.
getSortKind :: Context -> Sort -> IO SortKind
getSortKind :: Context -> Sort -> IO SortKind
getSortKind Context
ctx Sort
sort = Z3_error_code -> SortKind
toSortKind (Z3_error_code -> SortKind) -> IO Z3_error_code -> IO SortKind
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr Z3_context -> Ptr Z3_sort -> IO Z3_error_code)
-> Context -> Sort -> IO Z3_error_code
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO Z3_error_code
z3_get_sort_kind Context
ctx Sort
sort
  where toSortKind :: Z3_sort_kind -> SortKind
        toSortKind :: Z3_error_code -> SortKind
toSortKind Z3_error_code
k
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_uninterpreted_sort      = SortKind
Z3_UNINTERPRETED_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_bool_sort               = SortKind
Z3_BOOL_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_int_sort                = SortKind
Z3_INT_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_real_sort               = SortKind
Z3_REAL_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_bv_sort                 = SortKind
Z3_BV_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_array_sort              = SortKind
Z3_ARRAY_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_datatype_sort           = SortKind
Z3_DATATYPE_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_relation_sort           = SortKind
Z3_RELATION_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_finite_domain_sort      = SortKind
Z3_FINITE_DOMAIN_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_floating_point_sort     = SortKind
Z3_FLOATING_POINT_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_rounding_mode_sort      = SortKind
Z3_ROUNDING_MODE_SORT
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_unknown_sort            = SortKind
Z3_UNKNOWN_SORT
          | Bool
otherwise                 =
              String -> SortKind
forall a. HasCallStack => String -> a
error String
"Z3.Base.getSortKind: unknown `Z3_sort_kind'"

-- | Return the size of the given bit-vector sort.
getBvSortSize :: Context -> Sort -> IO Int
getBvSortSize :: Context -> Sort -> IO Int
getBvSortSize = (Ptr Z3_context -> Ptr Z3_sort -> IO CUInt)
-> Context -> Sort -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO CUInt
z3_get_bv_sort_size

getFiniteDomainSortSize :: Context -> Sort -> IO (Maybe Word64)
getFiniteDomainSortSize :: Context -> Sort -> IO (Maybe Word64)
getFiniteDomainSortSize Context
ctx Sort
sort = (Ptr CULLong -> IO (Maybe Word64)) -> IO (Maybe Word64)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CULLong -> IO (Maybe Word64)) -> IO (Maybe Word64))
-> (Ptr CULLong -> IO (Maybe Word64)) -> IO (Maybe Word64)
forall a b. (a -> b) -> a -> b
$ \Ptr CULLong
sizePtr ->
  Context
-> (Ptr Z3_context -> IO (Maybe Word64)) -> IO (Maybe Word64)
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContext Context
ctx ((Ptr Z3_context -> IO (Maybe Word64)) -> IO (Maybe Word64))
-> (Ptr Z3_context -> IO (Maybe Word64)) -> IO (Maybe Word64)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
ctxPtr ->
    Sort -> (Ptr Z3_sort -> IO (Maybe Word64)) -> IO (Maybe Word64)
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
sort ((Ptr Z3_sort -> IO (Maybe Word64)) -> IO (Maybe Word64))
-> (Ptr Z3_sort -> IO (Maybe Word64)) -> IO (Maybe Word64)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
sortPtr ->
      do Bool
success <- Z3_bool -> Bool
toBool (Z3_bool -> Bool) -> IO Z3_bool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr Z3_context -> Ptr Z3_sort -> Ptr CULLong -> IO Z3_bool
z3_get_finite_domain_sort_size Ptr Z3_context
ctxPtr Ptr Z3_sort
sortPtr Ptr CULLong
sizePtr)
         Bool -> IO Word64 -> IO (Maybe Word64)
forall (m :: * -> *) a. Monad m => Bool -> m a -> m (Maybe a)
returnValueToMaybe Bool
success (IO Word64 -> IO (Maybe Word64)) -> IO Word64 -> IO (Maybe Word64)
forall a b. (a -> b) -> a -> b
$ (CULLong -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULLong -> Word64) -> IO CULLong -> IO Word64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CULLong -> IO CULLong
forall a. Storable a => Ptr a -> IO a
peek Ptr CULLong
sizePtr)


-- TODO: Z3_get_array_sort_size

getArraySortDomain :: Context -> Sort -> IO Sort
getArraySortDomain :: Context -> Sort -> IO Sort
getArraySortDomain = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort))
-> Context -> Sort -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort)
z3_get_array_sort_domain

getArraySortRange :: Context -> Sort -> IO Sort
getArraySortRange :: Context -> Sort -> IO Sort
getArraySortRange = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort))
-> Context -> Sort -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_sort)
z3_get_array_sort_range

getTupleSortMkDecl :: Context -> Sort -> IO FuncDecl
getTupleSortMkDecl :: Context -> Sort -> IO FuncDecl
getTupleSortMkDecl = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_func_decl))
-> Context -> Sort -> IO FuncDecl
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_func_decl)
z3_get_tuple_sort_mk_decl

getTupleSortNumFields :: Context -> Sort -> IO Int
getTupleSortNumFields :: Context -> Sort -> IO Int
getTupleSortNumFields = (Ptr Z3_context -> Ptr Z3_sort -> IO CUInt)
-> Context -> Sort -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO CUInt
z3_get_tuple_sort_num_fields

getTupleSortFieldDecl :: Context -> Sort -> Int -> IO FuncDecl
getTupleSortFieldDecl :: Context -> Sort -> Int -> IO FuncDecl
getTupleSortFieldDecl = (Ptr Z3_context -> Ptr Z3_sort -> CUInt -> IO (Ptr Z3_func_decl))
-> Context -> Sort -> Int -> IO FuncDecl
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_sort -> CUInt -> IO (Ptr Z3_func_decl)
z3_get_tuple_sort_field_decl

-- | Get list of constructors for datatype.
getDatatypeSortConstructors :: Context
                            -> Sort           -- ^ Datatype sort.
                            -> IO [FuncDecl]  -- ^ Constructor declarations.
getDatatypeSortConstructors :: Context -> Sort -> IO [FuncDecl]
getDatatypeSortConstructors Context
c Sort
dtSort =
  Context -> (Ptr Z3_context -> IO [FuncDecl]) -> IO [FuncDecl]
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c ((Ptr Z3_context -> IO [FuncDecl]) -> IO [FuncDecl])
-> (Ptr Z3_context -> IO [FuncDecl]) -> IO [FuncDecl]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr ->
  Sort -> (Ptr Z3_sort -> IO [FuncDecl]) -> IO [FuncDecl]
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
dtSort ((Ptr Z3_sort -> IO [FuncDecl]) -> IO [FuncDecl])
-> (Ptr Z3_sort -> IO [FuncDecl]) -> IO [FuncDecl]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
dtSortPtr -> do
    CUInt
numCons <- Ptr Z3_context -> IO CUInt -> IO CUInt
forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
cPtr (IO CUInt -> IO CUInt) -> IO CUInt -> IO CUInt
forall a b. (a -> b) -> a -> b
$ Ptr Z3_context -> Ptr Z3_sort -> IO CUInt
z3_get_datatype_sort_num_constructors Ptr Z3_context
cPtr Ptr Z3_sort
dtSortPtr
    (CUInt -> IO FuncDecl) -> [CUInt] -> IO [FuncDecl]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
T.mapM (Ptr Z3_sort -> CUInt -> IO FuncDecl
forall {h}.
Marshal h (Ptr Z3_func_decl) =>
Ptr Z3_sort -> CUInt -> IO h
getConstructor Ptr Z3_sort
dtSortPtr) [CUInt
0..(CUInt
numConsCUInt -> CUInt -> CUInt
forall a. Num a => a -> a -> a
-CUInt
1)]
  where
    getConstructor :: Ptr Z3_sort -> CUInt -> IO h
getConstructor Ptr Z3_sort
dtSortPtr CUInt
idx =
      Context -> (Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h)
-> (Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> Ptr Z3_sort -> CUInt -> IO (Ptr Z3_func_decl)
z3_get_datatype_sort_constructor Ptr Z3_context
cPtr Ptr Z3_sort
dtSortPtr CUInt
idx

-- | Get list of recognizers for datatype.
getDatatypeSortRecognizers :: Context
                           -> Sort           -- ^ Datatype sort.
                           -> IO [FuncDecl]  -- ^ Constructor recognizers.
getDatatypeSortRecognizers :: Context -> Sort -> IO [FuncDecl]
getDatatypeSortRecognizers Context
c Sort
dtSort =
  Context -> (Ptr Z3_context -> IO [FuncDecl]) -> IO [FuncDecl]
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c ((Ptr Z3_context -> IO [FuncDecl]) -> IO [FuncDecl])
-> (Ptr Z3_context -> IO [FuncDecl]) -> IO [FuncDecl]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr ->
  Sort -> (Ptr Z3_sort -> IO [FuncDecl]) -> IO [FuncDecl]
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
dtSort ((Ptr Z3_sort -> IO [FuncDecl]) -> IO [FuncDecl])
-> (Ptr Z3_sort -> IO [FuncDecl]) -> IO [FuncDecl]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
dtSortPtr -> do
    CUInt
numCons <- Ptr Z3_context -> IO CUInt -> IO CUInt
forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
cPtr (IO CUInt -> IO CUInt) -> IO CUInt -> IO CUInt
forall a b. (a -> b) -> a -> b
$ Ptr Z3_context -> Ptr Z3_sort -> IO CUInt
z3_get_datatype_sort_num_constructors Ptr Z3_context
cPtr Ptr Z3_sort
dtSortPtr
    (CUInt -> IO FuncDecl) -> [CUInt] -> IO [FuncDecl]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
T.mapM (Ptr Z3_sort -> CUInt -> IO FuncDecl
forall {h}.
Marshal h (Ptr Z3_func_decl) =>
Ptr Z3_sort -> CUInt -> IO h
getRecognizer Ptr Z3_sort
dtSortPtr) [CUInt
0..(CUInt
numConsCUInt -> CUInt -> CUInt
forall a. Num a => a -> a -> a
-CUInt
1)]
  where
    getRecognizer :: Ptr Z3_sort -> CUInt -> IO h
getRecognizer Ptr Z3_sort
dtSortPtr CUInt
idx =
      Context -> (Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h)
-> (Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> Ptr Z3_sort -> CUInt -> IO (Ptr Z3_func_decl)
z3_get_datatype_sort_recognizer Ptr Z3_context
cPtr Ptr Z3_sort
dtSortPtr CUInt
idx

-- | Get list of accessors for the datatype constructor.
getDatatypeSortConstructorAccessors :: Context
                                    -> Sort             -- ^ Datatype sort.
                                    -> IO [[FuncDecl]]  -- ^ Constructor accessors.
getDatatypeSortConstructorAccessors :: Context -> Sort -> IO [[FuncDecl]]
getDatatypeSortConstructorAccessors Context
c Sort
dtSort =
  Context -> (Ptr Z3_context -> IO [[FuncDecl]]) -> IO [[FuncDecl]]
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c ((Ptr Z3_context -> IO [[FuncDecl]]) -> IO [[FuncDecl]])
-> (Ptr Z3_context -> IO [[FuncDecl]]) -> IO [[FuncDecl]]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr ->
  Sort -> (Ptr Z3_sort -> IO [[FuncDecl]]) -> IO [[FuncDecl]]
forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Sort
dtSort ((Ptr Z3_sort -> IO [[FuncDecl]]) -> IO [[FuncDecl]])
-> (Ptr Z3_sort -> IO [[FuncDecl]]) -> IO [[FuncDecl]]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_sort
dtSortPtr -> do
    CUInt
numCons <- Ptr Z3_context -> IO CUInt -> IO CUInt
forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
cPtr (IO CUInt -> IO CUInt) -> IO CUInt -> IO CUInt
forall a b. (a -> b) -> a -> b
$ Ptr Z3_context -> Ptr Z3_sort -> IO CUInt
z3_get_datatype_sort_num_constructors Ptr Z3_context
cPtr Ptr Z3_sort
dtSortPtr
    (CUInt -> IO [FuncDecl]) -> [CUInt] -> IO [[FuncDecl]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
T.mapM (Ptr Z3_sort -> CUInt -> IO [FuncDecl]
forall {b}.
Marshal b (Ptr Z3_func_decl) =>
Ptr Z3_sort -> CUInt -> IO [b]
getAccessors Ptr Z3_sort
dtSortPtr) [CUInt
0..(CUInt
numConsCUInt -> CUInt -> CUInt
forall a. Num a => a -> a -> a
-CUInt
1)]
  where
    getConstructor :: Ptr Z3_sort -> CUInt -> IO (Ptr Z3_func_decl)
getConstructor Ptr Z3_sort
dtSortPtr CUInt
idx_c =
      Context
-> (Ptr Z3_context -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContext Context
c ((Ptr Z3_context -> IO (Ptr Z3_func_decl))
 -> IO (Ptr Z3_func_decl))
-> (Ptr Z3_context -> IO (Ptr Z3_func_decl))
-> IO (Ptr Z3_func_decl)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> Ptr Z3_sort -> CUInt -> IO (Ptr Z3_func_decl)
z3_get_datatype_sort_constructor Ptr Z3_context
cPtr Ptr Z3_sort
dtSortPtr CUInt
idx_c

    getAccessors :: Ptr Z3_sort -> CUInt -> IO [b]
getAccessors Ptr Z3_sort
dtSortPtr CUInt
idx_c = do
      Ptr Z3_func_decl
consPtr <- Ptr Z3_sort -> CUInt -> IO (Ptr Z3_func_decl)
getConstructor Ptr Z3_sort
dtSortPtr CUInt
idx_c
      CUInt
numAs <- Context -> (Ptr Z3_context -> IO CUInt) -> IO CUInt
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO CUInt) -> IO CUInt)
-> (Ptr Z3_context -> IO CUInt) -> IO CUInt
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> Ptr Z3_func_decl -> IO CUInt
z3_get_arity Ptr Z3_context
cPtr Ptr Z3_func_decl
consPtr
      if CUInt
numAs CUInt -> CUInt -> Bool
forall a. Ord a => a -> a -> Bool
> CUInt
0  -- NB: (0::CUInt) - 1 == 0
        then (CUInt -> IO b) -> [CUInt] -> IO [b]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
T.mapM (\CUInt
idx_a -> Ptr Z3_sort -> CUInt -> CUInt -> IO b
forall {h}.
Marshal h (Ptr Z3_func_decl) =>
Ptr Z3_sort -> CUInt -> CUInt -> IO h
getAccessors' Ptr Z3_sort
dtSortPtr CUInt
idx_c CUInt
idx_a) [CUInt
0..(CUInt
numAs CUInt -> CUInt -> CUInt
forall a. Num a => a -> a -> a
- CUInt
1)]
        else [b] -> IO [b]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []

    getAccessors' :: Ptr Z3_sort -> CUInt -> CUInt -> IO h
getAccessors' Ptr Z3_sort
dtSortPtr CUInt
idx_c CUInt
idx_a =
      Context -> (Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h)
-> (Ptr Z3_context -> IO (Ptr Z3_func_decl)) -> IO h
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context
-> Ptr Z3_sort -> CUInt -> CUInt -> IO (Ptr Z3_func_decl)
z3_get_datatype_sort_constructor_accessor Ptr Z3_context
cPtr Ptr Z3_sort
dtSortPtr CUInt
idx_c CUInt
idx_a

-- TODO: Z3_get_relation_arity

-- TODO: Z3_get_relation_column

mkAtMost :: Context -> [AST] -> Int -> IO AST
mkAtMost :: Context -> [AST] -> Int -> IO AST
mkAtMost Context
_ctx [] Int
_n = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkAtMost: empty list of expressions"
mkAtMost  Context
ctx [AST]
es  Int
n =
  (Ptr Z3_context
 -> CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast)
z3_mk_atmost Context
ctx (((CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast)
f ->
  [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
es ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
esLen Ptr (Ptr Z3_ast)
esArr ->
  Int -> (CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. Int -> (CUInt -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Int
n ((CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
n' ->
  CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast)
f CUInt
esLen Ptr (Ptr Z3_ast)
esArr CUInt
n'

mkAtLeast :: Context -> [AST] -> Int -> IO AST
mkAtLeast :: Context -> [AST] -> Int -> IO AST
mkAtLeast Context
_ctx [] Int
_n = String -> IO AST
forall a. HasCallStack => String -> a
error String
"Z3.Base.mkAtLeast: empty list of expressions"
mkAtLeast  Context
ctx [AST]
es  Int
n =
  (Ptr Z3_context
 -> CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast)
z3_mk_atleast Context
ctx (((CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast)
f ->
  [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
es ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
esLen Ptr (Ptr Z3_ast)
esArr ->
  Int -> (CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. Int -> (CUInt -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Int
n ((CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
n' ->
  CUInt -> Ptr (Ptr Z3_ast) -> CUInt -> IO (Ptr Z3_ast)
f CUInt
esLen Ptr (Ptr Z3_ast)
esArr CUInt
n'

-- TODO: Z3_mk_pble

-- TODO: Z3_mk_pbge

-- TODO: Z3_mk_pbeq

-- TODO: Z3_func_decl_to_ast

-- TODO: Z3_is_eq_func_decl

-- TODO: Z3_get_func_decl_id

-- | Return the constant declaration name as a symbol.
getDeclName :: Context -> FuncDecl -> IO Symbol
getDeclName :: Context -> FuncDecl -> IO Symbol
getDeclName Context
c FuncDecl
decl = FuncDecl -> (Ptr Z3_func_decl -> IO Symbol) -> IO Symbol
forall r. FuncDecl -> (Ptr Z3_func_decl -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c FuncDecl
decl ((Ptr Z3_func_decl -> IO Symbol) -> IO Symbol)
-> (Ptr Z3_func_decl -> IO Symbol) -> IO Symbol
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl
declPtr ->
  Ptr Z3_symbol -> Symbol
Symbol (Ptr Z3_symbol -> Symbol) -> IO (Ptr Z3_symbol) -> IO Symbol
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context
-> (Ptr Z3_context -> IO (Ptr Z3_symbol)) -> IO (Ptr Z3_symbol)
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c (\Ptr Z3_context
cPtr -> Ptr Z3_context -> Ptr Z3_func_decl -> IO (Ptr Z3_symbol)
z3_get_decl_name Ptr Z3_context
cPtr Ptr Z3_func_decl
declPtr)

-- TODO: Z3_get_decl_kind

-- TODO: Z3_get_domain_size

-- | Returns the number of parameters of the given declaration
getArity :: Context -> FuncDecl -> IO Int
getArity :: Context -> FuncDecl -> IO Int
getArity = (Ptr Z3_context -> Ptr Z3_func_decl -> IO CUInt)
-> Context -> FuncDecl -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_decl -> IO CUInt
z3_get_arity

-- | Returns the sort of the i-th parameter of the given function declaration
getDomain :: Context
             -> FuncDecl         -- ^ A function declaration
             -> Int              -- ^ i
             -> IO Sort
getDomain :: Context -> FuncDecl -> Int -> IO Sort
getDomain = (Ptr Z3_context -> Ptr Z3_func_decl -> CUInt -> IO (Ptr Z3_sort))
-> Context -> FuncDecl -> Int -> IO Sort
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_func_decl -> CUInt -> IO (Ptr Z3_sort)
z3_get_domain

-- | Returns the range of the given declaration.
getRange :: Context -> FuncDecl -> IO Sort
getRange :: Context -> FuncDecl -> IO Sort
getRange = (Ptr Z3_context -> Ptr Z3_func_decl -> IO (Ptr Z3_sort))
-> Context -> FuncDecl -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_decl -> IO (Ptr Z3_sort)
z3_get_range

getDeclNumParameters :: Context -> FuncDecl -> IO Int
getDeclNumParameters :: Context -> FuncDecl -> IO Int
getDeclNumParameters = (Ptr Z3_context -> Ptr Z3_func_decl -> IO CUInt)
-> Context -> FuncDecl -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_decl -> IO CUInt
z3_get_decl_num_parameters

-- TODO: Z3_get_decl_parameter_kind

-- TODO: Z3_get_decl_int_parameter

-- TODO: Z3_get_decl_double_parameter

-- TODO: Z3_get_decl_symbol_parameter

-- TODO: Z3_get_decl_sort_parameter

-- TODO: Z3_get_decl_ast_parameter

-- TODO: Z3_get_decl_func_decl_parameter

-- TODO: Z3_get_decl_rational_parameter

-- | Convert an app into AST. This is just type casting.
appToAst :: Context -> App -> IO AST
appToAst :: Context -> App -> IO AST
appToAst = (Ptr Z3_context -> Ptr Z3_app -> IO (Ptr Z3_ast))
-> Context -> App -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_app -> IO (Ptr Z3_ast)
z3_app_to_ast

-- | Return the declaration of a constant or function application.
getAppDecl :: Context -> App -> IO FuncDecl
getAppDecl :: Context -> App -> IO FuncDecl
getAppDecl = (Ptr Z3_context -> Ptr Z3_app -> IO (Ptr Z3_func_decl))
-> Context -> App -> IO FuncDecl
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_app -> IO (Ptr Z3_func_decl)
z3_get_app_decl

-- | Return the number of argument of an application. If t is an constant, then the number of arguments is 0.
getAppNumArgs :: Context -> App -> IO Int
getAppNumArgs :: Context -> App -> IO Int
getAppNumArgs = (Ptr Z3_context -> Ptr Z3_app -> IO CUInt)
-> Context -> App -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_app -> IO CUInt
z3_get_app_num_args

-- | Return the i-th argument of the given application.
getAppArg :: Context -> App -> Int -> IO AST
getAppArg :: Context -> App -> Int -> IO AST
getAppArg = (Ptr Z3_context -> Ptr Z3_app -> CUInt -> IO (Ptr Z3_ast))
-> Context -> App -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_app -> CUInt -> IO (Ptr Z3_ast)
z3_get_app_arg

-- | Return a list of all the arguments of the given application.
getAppArgs :: Context -> App -> IO [AST]
getAppArgs :: Context -> App -> IO [AST]
getAppArgs Context
ctx App
a = do
  Int
n <- Context -> App -> IO Int
getAppNumArgs Context
ctx App
a
  [Int] -> (Int -> IO AST) -> IO [AST]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
T.forM [Int
0..Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] (Context -> App -> Int -> IO AST
getAppArg Context
ctx App
a)

-- TODO: Z3_is_eq_ast

-- TODO: Z3_get_ast_id

-- TODO: Z3_get_ast_hash

-- | Return the sort of an AST node.
getSort :: Context -> AST -> IO Sort
getSort :: Context -> AST -> IO Sort
getSort = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_sort))
-> Context -> AST -> IO Sort
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_sort)
z3_get_sort

isWellSorted :: Context -> AST -> IO Bool
isWellSorted :: Context -> AST -> IO Bool
isWellSorted = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_is_well_sorted

-- TODO: fix doc
-- | Return Z3_L_TRUE if a is true, Z3_L_FALSE if it is false, and Z3_L_UNDEF
-- otherwise.
getBoolValue :: Context -> AST -> IO (Maybe Bool)
getBoolValue :: Context -> AST -> IO (Maybe Bool)
getBoolValue Context
c AST
a = AST -> (Ptr Z3_ast -> IO (Maybe Bool)) -> IO (Maybe Bool)
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
a ((Ptr Z3_ast -> IO (Maybe Bool)) -> IO (Maybe Bool))
-> (Ptr Z3_ast -> IO (Maybe Bool)) -> IO (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
astPtr ->
  Z3_lbool -> Maybe Bool
castLBool (Z3_lbool -> Maybe Bool) -> IO Z3_lbool -> IO (Maybe Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context -> (Ptr Z3_context -> IO Z3_lbool) -> IO Z3_lbool
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c (\Ptr Z3_context
cPtr -> Ptr Z3_context -> Ptr Z3_ast -> IO Z3_lbool
z3_get_bool_value Ptr Z3_context
cPtr Ptr Z3_ast
astPtr)
  where castLBool :: Z3_lbool -> Maybe Bool
        castLBool :: Z3_lbool -> Maybe Bool
castLBool Z3_lbool
lb
          | Z3_lbool
lb Z3_lbool -> Z3_lbool -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_lbool
z3_l_true  = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
          | Z3_lbool
lb Z3_lbool -> Z3_lbool -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_lbool
z3_l_false = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
          | Z3_lbool
lb Z3_lbool -> Z3_lbool -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_lbool
z3_l_undef = Maybe Bool
forall a. Maybe a
Nothing
          | Bool
otherwise        =
              String -> Maybe Bool
forall a. HasCallStack => String -> a
error String
"Z3.Base.castLBool: illegal `Z3_lbool' value"

-- | Return the kind of the given AST.
getAstKind :: Context -> AST -> IO ASTKind
getAstKind :: Context -> AST -> IO ASTKind
getAstKind Context
ctx AST
ast = Z3_error_code -> ASTKind
toAstKind (Z3_error_code -> ASTKind) -> IO Z3_error_code -> IO ASTKind
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_error_code)
-> Context -> AST -> IO Z3_error_code
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_error_code
z3_get_ast_kind Context
ctx AST
ast
  where toAstKind :: Z3_ast_kind -> ASTKind
        toAstKind :: Z3_error_code -> ASTKind
toAstKind Z3_error_code
k
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_numeral_ast       = ASTKind
Z3_NUMERAL_AST
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_app_ast           = ASTKind
Z3_APP_AST
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_var_ast           = ASTKind
Z3_VAR_AST
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_quantifier_ast    = ASTKind
Z3_QUANTIFIER_AST
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_sort_ast          = ASTKind
Z3_SORT_AST
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_func_decl_ast     = ASTKind
Z3_FUNC_DECL_AST
          | Z3_error_code
k Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_unknown_ast       = ASTKind
Z3_UNKNOWN_AST
          | Bool
otherwise                 =
              String -> ASTKind
forall a. HasCallStack => String -> a
error String
"Z3.Base.getAstKind: unknown `Z3_ast_kind'"

-- | Return True if an ast is APP_AST, False otherwise.
isApp :: Context -> AST -> IO Bool
isApp :: Context -> AST -> IO Bool
isApp = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_is_app

-- TODO: Z3_is_numeral_ast

-- TODO: Z3_is_algebraic_number

-- | Convert an ast into an APP_AST. This is just type casting.
toApp :: Context -> AST -> IO App
toApp :: Context -> AST -> IO App
toApp = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_app))
-> Context -> AST -> IO App
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_app)
z3_to_app

-- TODO: Z3_to_func_decl

-- | Return numeral value, as a string of a numeric constant term.
getNumeralString :: Context -> AST -> IO String
getNumeralString :: Context -> AST -> IO String
getNumeralString = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_string)
-> Context -> AST -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_string
z3_get_numeral_string

-- TODO: Z3_get_numeral_decimal_string

-- | Return the numerator (as a numeral AST) of a numeral AST of sort Real.
--
-- Reference: <https://z3prover.github.io/api/html/group__capi.html#ga2d37084eb47ea0ab19638a3407ce610b>
getNumerator :: Context -> AST -> IO AST
getNumerator :: Context -> AST -> IO AST
getNumerator = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_get_numerator

-- | Return the denominator (as a numeral AST) of a numeral AST of sort Real.
--
-- Reference: <https://z3prover.github.io/api/html/group__capi.html#ga07549939888e8fdfc8e0fde1776c31a7>
getDenominator :: Context -> AST -> IO AST
getDenominator :: Context -> AST -> IO AST
getDenominator = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_get_denominator

-- TODO: Z3_get_numeral_small

-- TODO: Z3_get_numeral_int

-- TODO: Z3_get_numeral_int

-- TODO: Z3_get_numeral_uint

-- TODO: Z3_get_numeral_uint64

-- TODO: Z3_get_numeral_int64

-- TODO: Z3_get_numeral_rational_int64

-- TODO: Z3_get_algebraic_number_lower

-- TODO: Z3_get_algebraic_number_upper

-- TODO: Z3_pattern_to_ast

-- TODO: Z3_get_pattern_num_terms

-- TODO: Z3_get_pattern

getIndexValue :: Context -> AST -> IO Int
getIndexValue :: Context -> AST -> IO Int
getIndexValue = (Ptr Z3_context -> Ptr Z3_ast -> IO CUInt)
-> Context -> AST -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO CUInt
z3_get_index_value

isQuantifierForall :: Context -> AST -> IO Bool
isQuantifierForall :: Context -> AST -> IO Bool
isQuantifierForall = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_is_quantifier_forall

isQuantifierExists :: Context -> AST -> IO Bool
isQuantifierExists :: Context -> AST -> IO Bool
isQuantifierExists Context
ctx = (Bool -> Bool) -> IO Bool -> IO Bool
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Bool
not (IO Bool -> IO Bool) -> (AST -> IO Bool) -> AST -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context -> AST -> IO Bool
isQuantifierForall Context
ctx

getQuantifierWeight :: Context -> AST -> IO Int
getQuantifierWeight :: Context -> AST -> IO Int
getQuantifierWeight = (Ptr Z3_context -> Ptr Z3_ast -> IO CUInt)
-> Context -> AST -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO CUInt
z3_get_quantifier_weight

getQuantifierNumPatterns :: Context -> AST -> IO Int
getQuantifierNumPatterns :: Context -> AST -> IO Int
getQuantifierNumPatterns = (Ptr Z3_context -> Ptr Z3_ast -> IO CUInt)
-> Context -> AST -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO CUInt
z3_get_quantifier_num_patterns

getQuantifierPatternAST :: Context -> AST -> Int -> IO AST
getQuantifierPatternAST :: Context -> AST -> Int -> IO AST
getQuantifierPatternAST = (Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast))
-> Context -> AST -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast)
z3_get_quantifier_pattern_ast

getQuantifierPatterns :: Context -> AST -> IO [AST]
getQuantifierPatterns :: Context -> AST -> IO [AST]
getQuantifierPatterns Context
ctx AST
a = do
  Int
n <- Context -> AST -> IO Int
getQuantifierNumPatterns Context
ctx AST
a
  [Int] -> (Int -> IO AST) -> IO [AST]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
T.forM [Int
0..Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] (Context -> AST -> Int -> IO AST
getQuantifierPatternAST Context
ctx AST
a)

getQuantifierNumNoPatterns :: Context -> AST -> IO Int
getQuantifierNumNoPatterns :: Context -> AST -> IO Int
getQuantifierNumNoPatterns = (Ptr Z3_context -> Ptr Z3_ast -> IO CUInt)
-> Context -> AST -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO CUInt
z3_get_quantifier_num_no_patterns

getQuantifierNoPatternAST :: Context -> AST -> Int -> IO AST
getQuantifierNoPatternAST :: Context -> AST -> Int -> IO AST
getQuantifierNoPatternAST = (Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast))
-> Context -> AST -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast)
z3_get_quantifier_no_pattern_ast

getQuantifierNoPatterns :: Context -> AST -> IO [AST]
getQuantifierNoPatterns :: Context -> AST -> IO [AST]
getQuantifierNoPatterns Context
ctx AST
a = do
  Int
n <- Context -> AST -> IO Int
getQuantifierNumNoPatterns Context
ctx AST
a
  [Int] -> (Int -> IO AST) -> IO [AST]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
T.forM [Int
0..Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] (Context -> AST -> Int -> IO AST
getQuantifierNoPatternAST Context
ctx AST
a)

getQuantifierNumBound :: Context -> AST -> IO Int
getQuantifierNumBound :: Context -> AST -> IO Int
getQuantifierNumBound = (Ptr Z3_context -> Ptr Z3_ast -> IO CUInt)
-> Context -> AST -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO CUInt
z3_get_quantifier_num_bound

getQuantifierBoundName :: Context -> AST -> Int -> IO Symbol
getQuantifierBoundName :: Context -> AST -> Int -> IO Symbol
getQuantifierBoundName = (Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_symbol))
-> Context -> AST -> Int -> IO Symbol
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_symbol)
z3_get_quantifier_bound_name

getQuantifierBoundSort :: Context -> AST -> Int -> IO Sort
getQuantifierBoundSort :: Context -> AST -> Int -> IO Sort
getQuantifierBoundSort = (Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_sort))
-> Context -> AST -> Int -> IO Sort
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_sort)
z3_get_quantifier_bound_sort

getQuantifierBoundVars :: Context -> AST -> IO [AST]
getQuantifierBoundVars :: Context -> AST -> IO [AST]
getQuantifierBoundVars Context
ctx AST
a = do
  Int
n <- Context -> AST -> IO Int
getQuantifierNumBound Context
ctx AST
a
  [Int] -> (Int -> IO AST) -> IO [AST]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
T.forM [Int
0..Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] ((Int -> IO AST) -> IO [AST]) -> (Int -> IO AST) -> IO [AST]
forall a b. (a -> b) -> a -> b
$ \Int
i -> do
    Symbol
b <- Context -> AST -> Int -> IO Symbol
getQuantifierBoundName Context
ctx AST
a Int
i
    Sort
s <- Context -> AST -> Int -> IO Sort
getQuantifierBoundSort Context
ctx AST
a Int
i
    Context -> Symbol -> Sort -> IO AST
mkVar Context
ctx Symbol
b Sort
s

getQuantifierBody :: Context -> AST -> IO AST
getQuantifierBody :: Context -> AST -> IO AST
getQuantifierBody = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_get_quantifier_body

simplify :: Context -> AST -> IO AST
simplify :: Context -> AST -> IO AST
simplify = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_simplify

simplifyEx :: Context -> AST -> Params -> IO AST
simplifyEx :: Context -> AST -> Params -> IO AST
simplifyEx = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_params -> IO (Ptr Z3_ast))
-> Context -> AST -> Params -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_params -> IO (Ptr Z3_ast)
z3_simplify_ex

-- TODO: Z3_simplify_get_help

-- TODO: Z3_simplify_get_param_descrs

-------------------------------------------------
-- ** Helpers

-- | Read a 'Bool' value from an 'AST'
getBool :: Context -> AST -> IO Bool
getBool :: Context -> AST -> IO Bool
getBool Context
c AST
a = Maybe Bool -> Bool
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Bool -> Bool) -> IO (Maybe Bool) -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context -> AST -> IO (Maybe Bool)
getBoolValue Context
c AST
a
  -- TODO: throw an custom error if Nothing?
  -- TODO: Refactor castLBool?

-- | Read an 'Integer' value from an 'AST'
getInt :: Context -> AST -> IO Integer
getInt :: Context -> AST -> IO Integer
getInt Context
c AST
a = String -> Integer
forall a. Read a => String -> a
read (String -> Integer) -> IO String -> IO Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context -> AST -> IO String
getNumeralString Context
c AST
a

-- | Read a 'Rational' value from an 'AST'
getReal :: Context -> AST -> IO Rational
getReal :: Context -> AST -> IO Rational
getReal Context
c AST
a = String -> Rational
parse (String -> Rational) -> IO String -> IO Rational
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context -> AST -> IO String
getNumeralString Context
c AST
a
  where parse :: String -> Rational
        parse :: String -> Rational
parse String
s
          | [(Integer
i, String
sj)] <- ReadS Integer
forall a. Read a => ReadS a
reads String
s = Integer
i Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% String -> Integer
parseDen ((Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ') String
sj)
          | Bool
otherwise            = String -> Rational
forall a. HasCallStack => String -> a
error String
"Z3.Base.getReal: no parse"

        parseDen :: String -> Integer
        parseDen :: String -> Integer
parseDen String
""       = Integer
1
        parseDen (Char
'/':String
sj) = String -> Integer
forall a. Read a => String -> a
read String
sj
        parseDen String
_        = String -> Integer
forall a. HasCallStack => String -> a
error String
"Z3.Base.getReal: no parse"

---------------------------------------------------------------------
-- Modifiers

-- TODO Z3_update_term

substituteVars :: Context -> AST -> [AST] -> IO AST
substituteVars :: Context -> AST -> [AST] -> IO AST
substituteVars Context
ctx AST
a [AST]
vars =
  (Ptr Z3_context
 -> Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
z3_substitute_vars Context
ctx (((Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f ->
    AST -> (Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
a ((Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
aPtr ->
    [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
vars ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
varsNum Ptr (Ptr Z3_ast)
varsArr ->
      Ptr Z3_ast -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Ptr Z3_ast
aPtr CUInt
varsNum Ptr (Ptr Z3_ast)
varsArr

substitute :: Context -> AST -> [(AST, AST)] -> IO AST
substitute :: Context -> AST -> [(AST, AST)] -> IO AST
substitute Context
ctx AST
a [(AST, AST)]
substs =
  let froms :: [AST]
froms = ((AST, AST) -> AST) -> [(AST, AST)] -> [AST]
forall a b. (a -> b) -> [a] -> [b]
map (AST, AST) -> AST
forall a b. (a, b) -> a
fst [(AST, AST)]
substs
      tos :: [AST]
tos   = ((AST, AST) -> AST) -> [(AST, AST)] -> [AST]
forall a b. (a -> b) -> [a] -> [b]
map (AST, AST) -> AST
forall a b. (a, b) -> b
snd [(AST, AST)]
substs
  in (Ptr Z3_context
 -> Ptr Z3_ast
 -> CUInt
 -> Ptr (Ptr Z3_ast)
 -> Ptr (Ptr Z3_ast)
 -> IO (Ptr Z3_ast))
-> Context
-> ((Ptr Z3_ast
     -> CUInt
     -> Ptr (Ptr Z3_ast)
     -> Ptr (Ptr Z3_ast)
     -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_ast
-> CUInt
-> Ptr (Ptr Z3_ast)
-> Ptr (Ptr Z3_ast)
-> IO (Ptr Z3_ast)
z3_substitute Context
ctx (((Ptr Z3_ast
   -> CUInt
   -> Ptr (Ptr Z3_ast)
   -> Ptr (Ptr Z3_ast)
   -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((Ptr Z3_ast
     -> CUInt
     -> Ptr (Ptr Z3_ast)
     -> Ptr (Ptr Z3_ast)
     -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
-> CUInt -> Ptr (Ptr Z3_ast) -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f ->
    AST -> (Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
a ((Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr Z3_ast -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
aPtr ->
    [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
froms ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \CUInt
fromsLen Ptr (Ptr Z3_ast)
fromsArr ->
    [AST] -> (Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray    [AST]
tos   ((Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \         Ptr (Ptr Z3_ast)
tosArr   ->
      Ptr Z3_ast
-> CUInt -> Ptr (Ptr Z3_ast) -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Ptr Z3_ast
aPtr CUInt
fromsLen Ptr (Ptr Z3_ast)
fromsArr Ptr (Ptr Z3_ast)
tosArr

-- TODO Z3_translate

---------------------------------------------------------------------
-- Models

-- | Evaluate an AST node in the given model.
--
-- The evaluation may fail for the following reasons:
--
--     * /t/ contains a quantifier.
--     * the model /m/ is partial.
--     * /t/ is type incorrect.
modelEval :: Context
            -> Model  -- ^ Model /m/.
            -> AST    -- ^ Expression to evaluate /t/.
            -> Bool   -- ^ Model completion?
            -> IO (Maybe AST)
modelEval :: Context -> Model -> AST -> Bool -> IO (Maybe AST)
modelEval Context
ctx Model
m AST
a Bool
b =
  Context -> (Ptr Z3_context -> IO (Maybe AST)) -> IO (Maybe AST)
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContext Context
ctx ((Ptr Z3_context -> IO (Maybe AST)) -> IO (Maybe AST))
-> (Ptr Z3_context -> IO (Maybe AST)) -> IO (Maybe AST)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
ctxPtr ->
  (Ptr (Ptr Z3_ast) -> IO (Maybe AST)) -> IO (Maybe AST)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr Z3_ast) -> IO (Maybe AST)) -> IO (Maybe AST))
-> (Ptr (Ptr Z3_ast) -> IO (Maybe AST)) -> IO (Maybe AST)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_ast)
aptr2 ->
    AST -> (Ptr Z3_ast -> IO (Maybe AST)) -> IO (Maybe AST)
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
a ((Ptr Z3_ast -> IO (Maybe AST)) -> IO (Maybe AST))
-> (Ptr Z3_ast -> IO (Maybe AST)) -> IO (Maybe AST)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
astPtr ->
    Model -> (Ptr Z3_model -> IO (Maybe AST)) -> IO (Maybe AST)
forall r. Model -> (Ptr Z3_model -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Model
m ((Ptr Z3_model -> IO (Maybe AST)) -> IO (Maybe AST))
-> (Ptr Z3_model -> IO (Maybe AST)) -> IO (Maybe AST)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_model
mPtr ->
    Bool -> (Z3_bool -> IO (Maybe AST)) -> IO (Maybe AST)
forall r. Bool -> (Z3_bool -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Bool
b ((Z3_bool -> IO (Maybe AST)) -> IO (Maybe AST))
-> (Z3_bool -> IO (Maybe AST)) -> IO (Maybe AST)
forall a b. (a -> b) -> a -> b
$ \Z3_bool
b' ->
    Ptr Z3_context -> IO Z3_bool -> IO Z3_bool
forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
ctxPtr
      (Ptr Z3_context
-> Ptr Z3_model
-> Ptr Z3_ast
-> Z3_bool
-> Ptr (Ptr Z3_ast)
-> IO Z3_bool
z3_model_eval Ptr Z3_context
ctxPtr Ptr Z3_model
mPtr Ptr Z3_ast
astPtr Z3_bool
b' Ptr (Ptr Z3_ast)
aptr2) IO Z3_bool -> (Z3_bool -> IO (Maybe AST)) -> IO (Maybe AST)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr (Ptr Z3_ast) -> Bool -> IO (Maybe AST)
peekAST Ptr (Ptr Z3_ast)
aptr2 (Bool -> IO (Maybe AST))
-> (Z3_bool -> Bool) -> Z3_bool -> IO (Maybe AST)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z3_bool -> Bool
toBool
  where peekAST :: Ptr (Ptr Z3_ast) -> Bool -> IO (Maybe AST)
        peekAST :: Ptr (Ptr Z3_ast) -> Bool -> IO (Maybe AST)
peekAST Ptr (Ptr Z3_ast)
_p Bool
False = Maybe AST -> IO (Maybe AST)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe AST
forall a. Maybe a
Nothing
        peekAST  Ptr (Ptr Z3_ast)
p Bool
True  = (AST -> Maybe AST) -> IO AST -> IO (Maybe AST)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AST -> Maybe AST
forall a. a -> Maybe a
Just (IO AST -> IO (Maybe AST))
-> (Ptr Z3_ast -> IO AST) -> Ptr Z3_ast -> IO (Maybe AST)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context -> Ptr Z3_ast -> IO AST
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx (Ptr Z3_ast -> IO (Maybe AST)) -> IO (Ptr Z3_ast) -> IO (Maybe AST)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Z3_ast)
p

getConstInterp :: Context -> Model -> FuncDecl -> IO (Maybe AST)
getConstInterp :: Context -> Model -> FuncDecl -> IO (Maybe AST)
getConstInterp Context
ctx Model
m FuncDecl
fd = (Ptr Z3_context
 -> Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_ast))
-> Context
-> ((Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO (Maybe AST)
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_ast)
z3_model_get_const_interp Context
ctx (((Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO (Maybe AST))
-> ((Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO (Maybe AST)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_ast)
f ->
  Model -> (Ptr Z3_model -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. Model -> (Ptr Z3_model -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Model
m ((Ptr Z3_model -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr Z3_model -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_model
mPtr ->
  FuncDecl
-> (Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall r. FuncDecl -> (Ptr Z3_func_decl -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c FuncDecl
fd ((Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast))
-> (Ptr Z3_func_decl -> IO (Ptr Z3_ast)) -> IO (Ptr Z3_ast)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl
fdPtr ->
    Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_ast)
f Ptr Z3_model
mPtr Ptr Z3_func_decl
fdPtr

modelTranslate :: Context -> Model -> Context -> IO Model
modelTranslate :: Context -> Model -> Context -> IO Model
modelTranslate = (Ptr Z3_context
 -> Ptr Z3_model -> Ptr Z3_context -> IO (Ptr Z3_model))
-> Context -> Model -> Context -> IO Model
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context
-> Ptr Z3_model -> Ptr Z3_context -> IO (Ptr Z3_model)
z3_model_translate

hasInterp :: Context -> Model -> FuncDecl -> IO Bool
hasInterp :: Context -> Model -> FuncDecl -> IO Bool
hasInterp = (Ptr Z3_context -> Ptr Z3_model -> Ptr Z3_func_decl -> IO Z3_bool)
-> Context -> Model -> FuncDecl -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_model -> Ptr Z3_func_decl -> IO Z3_bool
z3_model_has_interp

numConsts :: Context -> Model -> IO Word
numConsts :: Context -> Model -> IO Word
numConsts = (Ptr Z3_context -> Ptr Z3_model -> IO CUInt)
-> Context -> Model -> IO Word
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_model -> IO CUInt
z3_model_get_num_consts

numFuncs :: Context -> Model -> IO Word
numFuncs :: Context -> Model -> IO Word
numFuncs = (Ptr Z3_context -> Ptr Z3_model -> IO CUInt)
-> Context -> Model -> IO Word
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_model -> IO CUInt
z3_model_get_num_funcs

getConstDecl :: Context -> Model -> Word -> IO FuncDecl
getConstDecl :: Context -> Model -> Word -> IO FuncDecl
getConstDecl = (Ptr Z3_context -> Ptr Z3_model -> CUInt -> IO (Ptr Z3_func_decl))
-> Context -> Model -> Word -> IO FuncDecl
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_model -> CUInt -> IO (Ptr Z3_func_decl)
z3_model_get_const_decl

getFuncDecl :: Context -> Model -> Word -> IO FuncDecl
getFuncDecl :: Context -> Model -> Word -> IO FuncDecl
getFuncDecl = (Ptr Z3_context -> Ptr Z3_model -> CUInt -> IO (Ptr Z3_func_decl))
-> Context -> Model -> Word -> IO FuncDecl
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_model -> CUInt -> IO (Ptr Z3_func_decl)
z3_model_get_func_decl

getConsts :: Context -> Model -> IO [FuncDecl]
getConsts :: Context -> Model -> IO [FuncDecl]
getConsts Context
ctx Model
m = do
  Word
n <- Context -> Model -> IO Word
numConsts Context
ctx Model
m
  [Word] -> (Word -> IO FuncDecl) -> IO [FuncDecl]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Word
0..Word
nWord -> Word -> Word
forall a. Num a => a -> a -> a
-Word
1] ((Word -> IO FuncDecl) -> IO [FuncDecl])
-> (Word -> IO FuncDecl) -> IO [FuncDecl]
forall a b. (a -> b) -> a -> b
$ \Word
i -> Context -> Model -> Word -> IO FuncDecl
getConstDecl Context
ctx Model
m Word
i

getFuncs :: Context -> Model -> IO [FuncDecl]
getFuncs :: Context -> Model -> IO [FuncDecl]
getFuncs Context
ctx Model
m = do
  Word
n <- Context -> Model -> IO Word
numFuncs Context
ctx Model
m
  [Word] -> (Word -> IO FuncDecl) -> IO [FuncDecl]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Word
0..Word
nWord -> Word -> Word
forall a. Num a => a -> a -> a
-Word
1] ((Word -> IO FuncDecl) -> IO [FuncDecl])
-> (Word -> IO FuncDecl) -> IO [FuncDecl]
forall a b. (a -> b) -> a -> b
$ \Word
i -> Context -> Model -> Word -> IO FuncDecl
getFuncDecl Context
ctx Model
m Word
i

-- | Evaluate an array as a function, if possible.
evalArray :: Context -> Model -> AST -> IO (Maybe FuncModel)
evalArray :: Context -> Model -> AST -> IO (Maybe FuncModel)
evalArray Context
ctx Model
model AST
array =
    do -- The array must first be evaluated normally, to get it into
       -- 'as-array' form, which is required to acquire the FuncDecl.
       Maybe AST
evaldArrayMb <- Context -> EvalAst AST
eval Context
ctx Model
model AST
array
       case Maybe AST
evaldArrayMb of
         Maybe AST
Nothing -> Maybe FuncModel -> IO (Maybe FuncModel)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe FuncModel
forall a. Maybe a
Nothing
         Just AST
evaldArray ->
             do Bool
canConvert <- Context -> AST -> IO Bool
isAsArray Context
ctx AST
evaldArray
                if Bool
canConvert
                  then
                    do FuncDecl
arrayDecl <- Context -> AST -> IO FuncDecl
getAsArrayFuncDecl Context
ctx AST
evaldArray
                       Context -> Model -> FuncDecl -> IO (Maybe FuncModel)
evalFunc Context
ctx Model
model FuncDecl
arrayDecl
                  else Maybe FuncModel -> IO (Maybe FuncModel)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe FuncModel
forall a. Maybe a
Nothing


-- | Return the function declaration f associated with a (_ as_array f) node.
getAsArrayFuncDecl :: Context -> AST -> IO FuncDecl
getAsArrayFuncDecl :: Context -> AST -> IO FuncDecl
getAsArrayFuncDecl = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_func_decl))
-> Context -> AST -> IO FuncDecl
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_func_decl)
z3_get_as_array_func_decl

-- | The (_ as-array f) AST node is a construct for assigning interpretations
-- for arrays in Z3. It is the array such that forall indices i we have that
-- (select (_ as-array f) i) is equal to (f i). This procedure returns Z3_TRUE
-- if the a is an as-array AST node.
isAsArray :: Context -> AST -> IO Bool
isAsArray :: Context -> AST -> IO Bool
isAsArray = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_is_as_array

isEqAST :: Context -> AST -> AST -> IO Bool
isEqAST :: Context -> AST -> AST -> IO Bool
isEqAST = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> AST -> IO Bool
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO Z3_bool
z3_is_eq_ast

addFuncInterp :: Context -> Model -> FuncDecl -> AST -> IO FuncInterp
addFuncInterp :: Context -> Model -> FuncDecl -> AST -> IO FuncInterp
addFuncInterp = (Ptr Z3_context
 -> Ptr Z3_model
 -> Ptr Z3_func_decl
 -> Ptr Z3_ast
 -> IO (Ptr Z3_func_interp))
-> Context -> Model -> FuncDecl -> AST -> IO FuncInterp
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_model
-> Ptr Z3_func_decl
-> Ptr Z3_ast
-> IO (Ptr Z3_func_interp)
z3_add_func_interp

addConstInterp :: Context -> Model -> FuncDecl -> AST -> IO ()
addConstInterp :: Context -> Model -> FuncDecl -> AST -> IO ()
addConstInterp = (Ptr Z3_context
 -> Ptr Z3_model -> Ptr Z3_func_decl -> Ptr Z3_ast -> IO ())
-> Context -> Model -> FuncDecl -> AST -> IO ()
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_model -> Ptr Z3_func_decl -> Ptr Z3_ast -> IO ()
z3_add_const_interp


getMapFromInterp :: Context -> FuncInterp -> IO [([AST], AST)]
getMapFromInterp :: Context -> FuncInterp -> IO [([AST], AST)]
getMapFromInterp Context
ctx FuncInterp
interp =
    do Int
n <- Context -> FuncInterp -> IO Int
funcInterpGetNumEntries Context
ctx FuncInterp
interp
       [FuncEntry]
entries <- (Int -> IO FuncEntry) -> [Int] -> IO [FuncEntry]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Context -> FuncInterp -> Int -> IO FuncEntry
funcInterpGetEntry Context
ctx FuncInterp
interp) [Int
0..Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1]
       (FuncEntry -> IO ([AST], AST)) -> [FuncEntry] -> IO [([AST], AST)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Context -> FuncEntry -> IO ([AST], AST)
getEntry Context
ctx) [FuncEntry]
entries

getEntry :: Context -> FuncEntry -> IO ([AST], AST)
getEntry :: Context -> FuncEntry -> IO ([AST], AST)
getEntry Context
ctx FuncEntry
entry =
    do AST
val <- Context -> FuncEntry -> IO AST
funcEntryGetValue Context
ctx FuncEntry
entry
       [AST]
args <- Context -> FuncEntry -> IO [AST]
getEntryArgs Context
ctx FuncEntry
entry
       ([AST], AST) -> IO ([AST], AST)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([AST]
args, AST
val)

getEntryArgs :: Context -> FuncEntry -> IO [AST]
getEntryArgs :: Context -> FuncEntry -> IO [AST]
getEntryArgs Context
ctx FuncEntry
entry =
    do Int
n <- Context -> FuncEntry -> IO Int
funcEntryGetNumArgs Context
ctx FuncEntry
entry
       (Int -> IO AST) -> [Int] -> IO [AST]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Context -> FuncEntry -> Int -> IO AST
funcEntryGetArg Context
ctx FuncEntry
entry) [Int
0..Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1]

-- | Return the interpretation of the function f in the model m.
-- Return NULL, if the model does not assign an interpretation for f.
-- That should be interpreted as: the f does not matter.
getFuncInterp :: Context -> Model -> FuncDecl -> IO (Maybe FuncInterp)
getFuncInterp :: Context -> Model -> FuncDecl -> IO (Maybe FuncInterp)
getFuncInterp Context
ctx Model
m FuncDecl
fd = (Ptr Z3_context
 -> Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_func_interp))
-> Context
-> ((Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_func_interp))
    -> IO (Ptr Z3_func_interp))
-> IO (Maybe FuncInterp)
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_func_interp)
z3_model_get_func_interp Context
ctx (((Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_func_interp))
  -> IO (Ptr Z3_func_interp))
 -> IO (Maybe FuncInterp))
-> ((Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_func_interp))
    -> IO (Ptr Z3_func_interp))
-> IO (Maybe FuncInterp)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_func_interp)
f ->
  Model
-> (Ptr Z3_model -> IO (Ptr Z3_func_interp))
-> IO (Ptr Z3_func_interp)
forall r. Model -> (Ptr Z3_model -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Model
m ((Ptr Z3_model -> IO (Ptr Z3_func_interp))
 -> IO (Ptr Z3_func_interp))
-> (Ptr Z3_model -> IO (Ptr Z3_func_interp))
-> IO (Ptr Z3_func_interp)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_model
mPtr ->
  FuncDecl
-> (Ptr Z3_func_decl -> IO (Ptr Z3_func_interp))
-> IO (Ptr Z3_func_interp)
forall r. FuncDecl -> (Ptr Z3_func_decl -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c FuncDecl
fd ((Ptr Z3_func_decl -> IO (Ptr Z3_func_interp))
 -> IO (Ptr Z3_func_interp))
-> (Ptr Z3_func_decl -> IO (Ptr Z3_func_interp))
-> IO (Ptr Z3_func_interp)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_func_decl
fdPtr ->
    Ptr Z3_model -> Ptr Z3_func_decl -> IO (Ptr Z3_func_interp)
f Ptr Z3_model
mPtr Ptr Z3_func_decl
fdPtr

-- | Return the number of entries in the given function interpretation.
funcInterpGetNumEntries :: Context -> FuncInterp -> IO Int
funcInterpGetNumEntries :: Context -> FuncInterp -> IO Int
funcInterpGetNumEntries = (Ptr Z3_context -> Ptr Z3_func_interp -> IO CUInt)
-> Context -> FuncInterp -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_interp -> IO CUInt
z3_func_interp_get_num_entries

-- | Return a _point_ of the given function intepretation.
-- It represents the value of f in a particular point.
funcInterpGetEntry :: Context -> FuncInterp -> Int -> IO FuncEntry
funcInterpGetEntry :: Context -> FuncInterp -> Int -> IO FuncEntry
funcInterpGetEntry = (Ptr Z3_context
 -> Ptr Z3_func_interp -> CUInt -> IO (Ptr Z3_func_entry))
-> Context -> FuncInterp -> Int -> IO FuncEntry
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context
-> Ptr Z3_func_interp -> CUInt -> IO (Ptr Z3_func_entry)
z3_func_interp_get_entry

-- | Return the 'else' value of the given function interpretation.
funcInterpGetElse :: Context -> FuncInterp -> IO AST
funcInterpGetElse :: Context -> FuncInterp -> IO AST
funcInterpGetElse = (Ptr Z3_context -> Ptr Z3_func_interp -> IO (Ptr Z3_ast))
-> Context -> FuncInterp -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_interp -> IO (Ptr Z3_ast)
z3_func_interp_get_else

-- | Return the arity (number of arguments) of the given function
-- interpretation.
funcInterpGetArity :: Context -> FuncInterp -> IO Int
funcInterpGetArity :: Context -> FuncInterp -> IO Int
funcInterpGetArity = (Ptr Z3_context -> Ptr Z3_func_interp -> IO CUInt)
-> Context -> FuncInterp -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_interp -> IO CUInt
z3_func_interp_get_arity

-- | Return the value of this point.
funcEntryGetValue :: Context -> FuncEntry -> IO AST
funcEntryGetValue :: Context -> FuncEntry -> IO AST
funcEntryGetValue = (Ptr Z3_context -> Ptr Z3_func_entry -> IO (Ptr Z3_ast))
-> Context -> FuncEntry -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_entry -> IO (Ptr Z3_ast)
z3_func_entry_get_value

-- | Return the number of arguments in a Z3_func_entry object.
funcEntryGetNumArgs :: Context -> FuncEntry -> IO Int
funcEntryGetNumArgs :: Context -> FuncEntry -> IO Int
funcEntryGetNumArgs = (Ptr Z3_context -> Ptr Z3_func_entry -> IO CUInt)
-> Context -> FuncEntry -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_entry -> IO CUInt
z3_func_entry_get_num_args

-- | Return an argument of a Z3_func_entry object.
funcEntryGetArg :: Context -> FuncEntry -> Int -> IO AST
funcEntryGetArg :: Context -> FuncEntry -> Int -> IO AST
funcEntryGetArg = (Ptr Z3_context -> Ptr Z3_func_entry -> CUInt -> IO (Ptr Z3_ast))
-> Context -> FuncEntry -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_func_entry -> CUInt -> IO (Ptr Z3_ast)
z3_func_entry_get_arg

-- | Convert the given model into a string.
modelToString :: Context -> Model -> IO String
modelToString :: Context -> Model -> IO String
modelToString = (Ptr Z3_context -> Ptr Z3_model -> IO Z3_string)
-> Context -> Model -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_model -> IO Z3_string
z3_model_to_string

-- | Alias for 'modelToString'.
showModel :: Context -> Model -> IO String
showModel :: Context -> Model -> IO String
showModel = Context -> Model -> IO String
modelToString
{-# DEPRECATED showModel "Use modelToString instead." #-}

-------------------------------------------------
-- ** Helpers

-- | Type of an evaluation function for 'AST'.
--
-- Evaluation may fail (i.e. return 'Nothing') for a few
-- reasons, see 'modelEval'.
type EvalAst a = Model -> AST -> IO (Maybe a)

-- | An alias for 'modelEval' with model completion enabled.
eval :: Context -> EvalAst AST
eval :: Context -> EvalAst AST
eval Context
ctx Model
m AST
a = Context -> Model -> AST -> Bool -> IO (Maybe AST)
modelEval Context
ctx Model
m AST
a Bool
True

-- | Evaluate an AST node of sort /bool/ in the given model.
--
-- See 'modelEval' and 'getBool'.
evalBool :: Context -> EvalAst Bool
evalBool :: Context -> EvalAst Bool
evalBool Context
ctx Model
m AST
ast = Context -> EvalAst AST
eval Context
ctx Model
m AST
ast IO (Maybe AST) -> (Maybe AST -> IO (Maybe Bool)) -> IO (Maybe Bool)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (AST -> IO Bool) -> Maybe AST -> IO (Maybe Bool)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
T.traverse (Context -> AST -> IO Bool
getBool Context
ctx)

-- | Evaluate an AST node of sort /int/ in the given model.
--
-- See 'modelEval' and 'getInt'.
evalInt :: Context -> EvalAst Integer
evalInt :: Context -> EvalAst Integer
evalInt Context
ctx Model
m AST
ast = Context -> EvalAst AST
eval Context
ctx Model
m AST
ast IO (Maybe AST)
-> (Maybe AST -> IO (Maybe Integer)) -> IO (Maybe Integer)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (AST -> IO Integer) -> Maybe AST -> IO (Maybe Integer)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
T.traverse (Context -> AST -> IO Integer
getInt Context
ctx)

-- | Evaluate an AST node of sort /real/ in the given model.
--
-- See 'modelEval' and 'getReal'.
evalReal :: Context -> EvalAst Rational
evalReal :: Context -> EvalAst Rational
evalReal Context
ctx Model
m AST
ast = Context -> EvalAst AST
eval Context
ctx Model
m AST
ast IO (Maybe AST)
-> (Maybe AST -> IO (Maybe Rational)) -> IO (Maybe Rational)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (AST -> IO Rational) -> Maybe AST -> IO (Maybe Rational)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
T.traverse (Context -> AST -> IO Rational
getReal Context
ctx)

-- | Evaluate an AST node of sort /bit-vector/ in the given model.
--
-- The flag /signed/ decides whether the bit-vector value is
-- interpreted as a signed or unsigned integer.
--
-- See 'modelEval' and 'mkBv2int'.
evalBv :: Context -> Bool -- ^ signed?
                  -> EvalAst Integer
evalBv :: Context -> Bool -> EvalAst Integer
evalBv Context
ctx Bool
signed Model
m AST
ast =
  Context -> AST -> Bool -> IO AST
mkBv2int Context
ctx AST
ast Bool
signed IO AST -> (AST -> IO (Maybe AST)) -> IO (Maybe AST)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Context -> EvalAst AST
eval Context
ctx Model
m IO (Maybe AST)
-> (Maybe AST -> IO (Maybe Integer)) -> IO (Maybe Integer)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (AST -> IO Integer) -> Maybe AST -> IO (Maybe Integer)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
T.traverse (\AST
a -> Context -> AST -> IO Integer
getInt Context
ctx AST
a)

-- | Evaluate a /collection/ of AST nodes in the given model.
evalT :: Traversable t => Context -> Model -> t AST -> IO (Maybe (t AST))
evalT :: forall (t :: * -> *).
Traversable t =>
Context -> Model -> t AST -> IO (Maybe (t AST))
evalT Context
c = EvalAst AST -> Model -> t AST -> IO (Maybe (t AST))
forall (t :: * -> *) a.
Traversable t =>
EvalAst a -> Model -> t AST -> IO (Maybe (t a))
mapEval (Context -> EvalAst AST
eval Context
c)

-- | Run a evaluation function on a 'Traversable' data structure of 'AST's
-- (e.g. @[AST]@, @Vector AST@, @Maybe AST@, etc).
--
-- This a generic version of 'evalT' which can be used in combination with
-- other helpers. For instance, @mapEval (evalInt c)@ can be used to obtain
-- the 'Integer' interpretation of a list of 'AST' of sort /int/.
mapEval :: Traversable t => EvalAst a -> Model -> t AST -> IO (Maybe (t a))
mapEval :: forall (t :: * -> *) a.
Traversable t =>
EvalAst a -> Model -> t AST -> IO (Maybe (t a))
mapEval EvalAst a
f Model
m = (t (Maybe a) -> Maybe (t a))
-> IO (t (Maybe a)) -> IO (Maybe (t a))
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap t (Maybe a) -> Maybe (t a)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => t (m a) -> m (t a)
T.sequence (IO (t (Maybe a)) -> IO (Maybe (t a)))
-> (t AST -> IO (t (Maybe a))) -> t AST -> IO (Maybe (t a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AST -> IO (Maybe a)) -> t AST -> IO (t (Maybe a))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> t a -> m (t b)
T.mapM (EvalAst a
f Model
m)

{- TODO: Parameterize FuncModel

data FuncModel a b = FuncModel [([a], b)] b

type FuncModelAST = FuncModel AST AST

evalFuncWith :: Context -> Model -> EvalAst a -> EvalAst b -> FuncDecl -> IO (Maybe (FuncModel a b))

-}

-- | The interpretation of a function.
data FuncModel = FuncModel
    { FuncModel -> [([AST], AST)]
interpMap :: [([AST], AST)]
      -- ^ Mapping from arguments to values.
    , FuncModel -> AST
interpElse :: AST
      -- ^ Default value.
    }

-- | Evaluate a function declaration to a list of argument/value pairs.
evalFunc :: Context -> Model -> FuncDecl -> IO (Maybe FuncModel)
evalFunc :: Context -> Model -> FuncDecl -> IO (Maybe FuncModel)
evalFunc Context
ctx Model
m FuncDecl
fDecl =
    do Maybe FuncInterp
interpMb <- Context -> Model -> FuncDecl -> IO (Maybe FuncInterp)
getFuncInterp Context
ctx Model
m FuncDecl
fDecl
       case Maybe FuncInterp
interpMb of
         Maybe FuncInterp
Nothing -> Maybe FuncModel -> IO (Maybe FuncModel)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe FuncModel
forall a. Maybe a
Nothing
         Just FuncInterp
interp ->
             do [([AST], AST)]
funcMap  <- Context -> FuncInterp -> IO [([AST], AST)]
getMapFromInterp Context
ctx FuncInterp
interp
                AST
elsePart <- Context -> FuncInterp -> IO AST
funcInterpGetElse Context
ctx FuncInterp
interp
                Maybe FuncModel -> IO (Maybe FuncModel)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (FuncModel -> Maybe FuncModel
forall a. a -> Maybe a
Just (FuncModel -> Maybe FuncModel) -> FuncModel -> Maybe FuncModel
forall a b. (a -> b) -> a -> b
$ [([AST], AST)] -> AST -> FuncModel
FuncModel [([AST], AST)]
funcMap AST
elsePart)

---------------------------------------------------------------------
-- Interaction logging

-- TODO

---------------------------------------------------------------------
-- String Conversion

-- | Pretty-printing mode for converting ASTs to strings.  The mode
-- can be one of the following:
--
-- * Z3_PRINT_SMTLIB_FULL: Print AST nodes in SMTLIB verbose format.
--
-- * Z3_PRINT_LOW_LEVEL: Print AST nodes using a low-level format.
--
-- * Z3_PRINT_SMTLIB_COMPLIANT: Print AST nodes in SMTLIB 1.x
-- compliant format.
--
-- * Z3_PRINT_SMTLIB2_COMPLIANT: Print AST nodes in SMTLIB 2.x
-- compliant format.
data ASTPrintMode
  = Z3_PRINT_SMTLIB_FULL
  | Z3_PRINT_LOW_LEVEL
  | Z3_PRINT_SMTLIB2_COMPLIANT

-- | Set the pretty-printing mode for converting ASTs to strings.
setASTPrintMode :: Context -> ASTPrintMode -> IO ()
setASTPrintMode :: Context -> ASTPrintMode -> IO ()
setASTPrintMode Context
ctx ASTPrintMode
mode = Context -> (Ptr Z3_context -> IO ()) -> IO ()
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
ctx ((Ptr Z3_context -> IO ()) -> IO ())
-> (Ptr Z3_context -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
ctxPtr ->
  case ASTPrintMode
mode of
       ASTPrintMode
Z3_PRINT_SMTLIB_FULL ->
         Z3_error_handler
z3_set_ast_print_mode Ptr Z3_context
ctxPtr Z3_error_code
z3_print_smtlib_full
       ASTPrintMode
Z3_PRINT_LOW_LEVEL ->
         Z3_error_handler
z3_set_ast_print_mode Ptr Z3_context
ctxPtr Z3_error_code
z3_print_low_level
       ASTPrintMode
Z3_PRINT_SMTLIB2_COMPLIANT ->
         Z3_error_handler
z3_set_ast_print_mode Ptr Z3_context
ctxPtr Z3_error_code
z3_print_smtlib2_compliant

-- | Convert an AST to a string.
astToString :: Context -> AST -> IO String
astToString :: Context -> AST -> IO String
astToString = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_string)
-> Context -> AST -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_string
z3_ast_to_string

-- | Convert a pattern to a string.
patternToString :: Context -> Pattern -> IO String
patternToString :: Context -> Pattern -> IO String
patternToString = (Ptr Z3_context -> Ptr Z3_pattern -> IO Z3_string)
-> Context -> Pattern -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_pattern -> IO Z3_string
z3_pattern_to_string

-- | Convert a sort to a string.
sortToString :: Context -> Sort -> IO String
sortToString :: Context -> Sort -> IO String
sortToString = (Ptr Z3_context -> Ptr Z3_sort -> IO Z3_string)
-> Context -> Sort -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO Z3_string
z3_sort_to_string

-- | Convert a FuncDecl to a string.
funcDeclToString :: Context -> FuncDecl -> IO String
funcDeclToString :: Context -> FuncDecl -> IO String
funcDeclToString = (Ptr Z3_context -> Ptr Z3_func_decl -> IO Z3_string)
-> Context -> FuncDecl -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_func_decl -> IO Z3_string
z3_func_decl_to_string

-- | Convert the given benchmark into SMT-LIB formatted string.
--
-- The output format can be configured via 'setASTPrintMode'.
benchmarkToSMTLibString :: Context
                            -> String   -- ^ name
                            -> String   -- ^ logic
                            -> String   -- ^ status
                            -> String   -- ^ attributes
                            -> [AST]    -- ^ assumptions
                            -> AST      -- ^ formula
                            -> IO String
benchmarkToSMTLibString :: Context
-> String
-> String
-> String
-> String
-> [AST]
-> AST
-> IO String
benchmarkToSMTLibString Context
ctx String
name String
logic String
status String
attr [AST]
assump AST
form =
  (Ptr Z3_context
 -> Z3_string
 -> Z3_string
 -> Z3_string
 -> Z3_string
 -> CUInt
 -> Ptr (Ptr Z3_ast)
 -> Ptr Z3_ast
 -> IO Z3_string)
-> Context
-> ((Z3_string
     -> Z3_string
     -> Z3_string
     -> Z3_string
     -> CUInt
     -> Ptr (Ptr Z3_ast)
     -> Ptr Z3_ast
     -> IO Z3_string)
    -> IO Z3_string)
-> IO String
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Z3_string
-> Z3_string
-> Z3_string
-> Z3_string
-> CUInt
-> Ptr (Ptr Z3_ast)
-> Ptr Z3_ast
-> IO Z3_string
z3_benchmark_to_smtlib_string Context
ctx (((Z3_string
   -> Z3_string
   -> Z3_string
   -> Z3_string
   -> CUInt
   -> Ptr (Ptr Z3_ast)
   -> Ptr Z3_ast
   -> IO Z3_string)
  -> IO Z3_string)
 -> IO String)
-> ((Z3_string
     -> Z3_string
     -> Z3_string
     -> Z3_string
     -> CUInt
     -> Ptr (Ptr Z3_ast)
     -> Ptr Z3_ast
     -> IO Z3_string)
    -> IO Z3_string)
-> IO String
forall a b. (a -> b) -> a -> b
$ \Z3_string
-> Z3_string
-> Z3_string
-> Z3_string
-> CUInt
-> Ptr (Ptr Z3_ast)
-> Ptr Z3_ast
-> IO Z3_string
f ->
    String -> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
name ((Z3_string -> IO Z3_string) -> IO Z3_string)
-> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a b. (a -> b) -> a -> b
$ \Z3_string
namePtr ->
    String -> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
logic ((Z3_string -> IO Z3_string) -> IO Z3_string)
-> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a b. (a -> b) -> a -> b
$ \Z3_string
logicPtr ->
    String -> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
status ((Z3_string -> IO Z3_string) -> IO Z3_string)
-> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a b. (a -> b) -> a -> b
$ \Z3_string
statusPtr ->
    String -> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
attr ((Z3_string -> IO Z3_string) -> IO Z3_string)
-> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a b. (a -> b) -> a -> b
$ \Z3_string
attrPtr ->
    [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_string) -> IO Z3_string
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
assump ((CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_string) -> IO Z3_string)
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_string) -> IO Z3_string
forall a b. (a -> b) -> a -> b
$ \CUInt
assumpNum Ptr (Ptr Z3_ast)
assumpArr ->
    AST -> (Ptr Z3_ast -> IO Z3_string) -> IO Z3_string
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
form ((Ptr Z3_ast -> IO Z3_string) -> IO Z3_string)
-> (Ptr Z3_ast -> IO Z3_string) -> IO Z3_string
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
formPtr ->
      Z3_string
-> Z3_string
-> Z3_string
-> Z3_string
-> CUInt
-> Ptr (Ptr Z3_ast)
-> Ptr Z3_ast
-> IO Z3_string
f Z3_string
namePtr Z3_string
logicPtr Z3_string
statusPtr Z3_string
attrPtr CUInt
assumpNum Ptr (Ptr Z3_ast)
assumpArr Ptr Z3_ast
formPtr

---------------------------------------------------------------------
-- Tactics

mkTactic :: Context -> String -> IO Tactic
mkTactic :: Context -> String -> IO Tactic
mkTactic = (Ptr Z3_context -> Z3_string -> IO (Ptr Z3_tactic))
-> Context -> String -> IO Tactic
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Z3_string -> IO (Ptr Z3_tactic)
z3_mk_tactic

andThenTactic :: Context -> Tactic -> Tactic -> IO Tactic
andThenTactic :: Context -> Tactic -> Tactic -> IO Tactic
andThenTactic = (Ptr Z3_context
 -> Ptr Z3_tactic -> Ptr Z3_tactic -> IO (Ptr Z3_tactic))
-> Context -> Tactic -> Tactic -> IO Tactic
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context
-> Ptr Z3_tactic -> Ptr Z3_tactic -> IO (Ptr Z3_tactic)
z3_tactic_and_then

orElseTactic :: Context -> Tactic -> Tactic -> IO Tactic
orElseTactic :: Context -> Tactic -> Tactic -> IO Tactic
orElseTactic = (Ptr Z3_context
 -> Ptr Z3_tactic -> Ptr Z3_tactic -> IO (Ptr Z3_tactic))
-> Context -> Tactic -> Tactic -> IO Tactic
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context
-> Ptr Z3_tactic -> Ptr Z3_tactic -> IO (Ptr Z3_tactic)
z3_tactic_or_else

skipTactic :: Context -> IO Tactic
skipTactic :: Context -> IO Tactic
skipTactic = (Ptr Z3_context -> IO (Ptr Z3_tactic)) -> Context -> IO Tactic
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_tactic)
z3_tactic_skip

tryForTactic :: Context -> Tactic -> Int -> IO Tactic
tryForTactic :: Context -> Tactic -> Int -> IO Tactic
tryForTactic = (Ptr Z3_context -> Ptr Z3_tactic -> CUInt -> IO (Ptr Z3_tactic))
-> Context -> Tactic -> Int -> IO Tactic
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_tactic -> CUInt -> IO (Ptr Z3_tactic)
z3_tactic_try_for

tacticUsingParams :: Context -> Tactic -> Params -> IO Tactic
tacticUsingParams :: Context -> Tactic -> Params -> IO Tactic
tacticUsingParams = (Ptr Z3_context
 -> Ptr Z3_tactic -> Ptr Z3_params -> IO (Ptr Z3_tactic))
-> Context -> Tactic -> Params -> IO Tactic
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context
-> Ptr Z3_tactic -> Ptr Z3_params -> IO (Ptr Z3_tactic)
z3_tactic_using_params

repeatTactic :: Context -> Tactic -> Int -> IO Tactic
repeatTactic :: Context -> Tactic -> Int -> IO Tactic
repeatTactic = (Ptr Z3_context -> Ptr Z3_tactic -> CUInt -> IO (Ptr Z3_tactic))
-> Context -> Tactic -> Int -> IO Tactic
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_tactic -> CUInt -> IO (Ptr Z3_tactic)
z3_tactic_repeat

mkQuantifierEliminationTactic :: Context -> IO Tactic
mkQuantifierEliminationTactic :: Context -> IO Tactic
mkQuantifierEliminationTactic Context
ctx = Context -> String -> IO Tactic
mkTactic Context
ctx String
"qe"

mkAndInverterGraphTactic :: Context -> IO Tactic
mkAndInverterGraphTactic :: Context -> IO Tactic
mkAndInverterGraphTactic Context
ctx = Context -> String -> IO Tactic
mkTactic Context
ctx String
"aig"

applyTactic :: Context -> Tactic -> Goal -> IO ApplyResult
applyTactic :: Context -> Tactic -> Goal -> IO ApplyResult
applyTactic = (Ptr Z3_context
 -> Ptr Z3_tactic -> Ptr Z3_goal -> IO (Ptr Z3_apply_result))
-> Context -> Tactic -> Goal -> IO ApplyResult
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context
-> Ptr Z3_tactic -> Ptr Z3_goal -> IO (Ptr Z3_apply_result)
z3_tactic_apply

applyResultToString :: Context -> ApplyResult -> IO String
applyResultToString :: Context -> ApplyResult -> IO String
applyResultToString = (Ptr Z3_context -> Ptr Z3_apply_result -> IO Z3_string)
-> Context -> ApplyResult -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_apply_result -> IO Z3_string
z3_apply_result_to_string

getApplyResultNumSubgoals :: Context -> ApplyResult -> IO Int
getApplyResultNumSubgoals :: Context -> ApplyResult -> IO Int
getApplyResultNumSubgoals = (Ptr Z3_context -> Ptr Z3_apply_result -> IO CUInt)
-> Context -> ApplyResult -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_apply_result -> IO CUInt
z3_apply_result_get_num_subgoals

getApplyResultSubgoal :: Context -> ApplyResult -> Int -> IO Goal
getApplyResultSubgoal :: Context -> ApplyResult -> Int -> IO Goal
getApplyResultSubgoal = (Ptr Z3_context
 -> Ptr Z3_apply_result -> CUInt -> IO (Ptr Z3_goal))
-> Context -> ApplyResult -> Int -> IO Goal
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_apply_result -> CUInt -> IO (Ptr Z3_goal)
z3_apply_result_get_subgoal

getApplyResultSubgoals :: Context -> ApplyResult -> IO [Goal]
getApplyResultSubgoals :: Context -> ApplyResult -> IO [Goal]
getApplyResultSubgoals Context
ctx ApplyResult
a = do
  Int
n <- Context -> ApplyResult -> IO Int
getApplyResultNumSubgoals Context
ctx ApplyResult
a
  [Int] -> (Int -> IO Goal) -> IO [Goal]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
T.forM [Int
0..Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] (Context -> ApplyResult -> Int -> IO Goal
getApplyResultSubgoal Context
ctx ApplyResult
a)

mkGoal :: Context -> Bool -> Bool -> Bool -> IO Goal
mkGoal :: Context -> Bool -> Bool -> Bool -> IO Goal
mkGoal = (Ptr Z3_context
 -> Z3_bool -> Z3_bool -> Z3_bool -> IO (Ptr Z3_goal))
-> Context -> Bool -> Bool -> Bool -> IO Goal
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context -> Z3_bool -> Z3_bool -> Z3_bool -> IO (Ptr Z3_goal)
z3_mk_goal

goalAssert :: Context -> Goal -> AST -> IO ()
goalAssert :: Context -> Goal -> AST -> IO ()
goalAssert = (Ptr Z3_context -> Ptr Z3_goal -> Ptr Z3_ast -> IO ())
-> Context -> Goal -> AST -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_goal -> Ptr Z3_ast -> IO ()
z3_goal_assert

getGoalSize :: Context -> Goal -> IO Int
getGoalSize :: Context -> Goal -> IO Int
getGoalSize = (Ptr Z3_context -> Ptr Z3_goal -> IO CUInt)
-> Context -> Goal -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_goal -> IO CUInt
z3_goal_size

getGoalFormula :: Context -> Goal -> Int -> IO AST
getGoalFormula :: Context -> Goal -> Int -> IO AST
getGoalFormula = (Ptr Z3_context -> Ptr Z3_goal -> CUInt -> IO (Ptr Z3_ast))
-> Context -> Goal -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_goal -> CUInt -> IO (Ptr Z3_ast)
z3_goal_formula

getGoalFormulas :: Context -> Goal -> IO [AST]
getGoalFormulas :: Context -> Goal -> IO [AST]
getGoalFormulas Context
ctx Goal
g = do
  Int
n <- Context -> Goal -> IO Int
getGoalSize Context
ctx Goal
g
  [Int] -> (Int -> IO AST) -> IO [AST]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
T.forM [Int
0..Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] (Context -> Goal -> Int -> IO AST
getGoalFormula Context
ctx Goal
g)

goalToString :: Context -> Goal -> IO String
goalToString :: Context -> Goal -> IO String
goalToString = (Ptr Z3_context -> Ptr Z3_goal -> IO Z3_string)
-> Context -> Goal -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_goal -> IO Z3_string
z3_goal_to_string

convertModel :: Context -> Goal -> Model -> IO Model
convertModel :: Context -> Goal -> Model -> IO Model
convertModel = (Ptr Z3_context
 -> Ptr Z3_goal -> Ptr Z3_model -> IO (Ptr Z3_model))
-> Context -> Goal -> Model -> IO Model
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_goal -> Ptr Z3_model -> IO (Ptr Z3_model)
z3_goal_convert_model

---------------------------------------------------------------------
-- Parser interface

parseSMTLib2String :: Context
                   -> String     -- ^ string to parse
                   -> [Symbol]   -- ^ sort names
                   -> [Sort]     -- ^ sorts
                   -> [Symbol]   -- ^ declaration names
                   -> [FuncDecl] -- ^ declarations
                   -> IO [AST]
parseSMTLib2String :: Context
-> String
-> [Symbol]
-> [Sort]
-> [Symbol]
-> [FuncDecl]
-> IO [AST]
parseSMTLib2String Context
ctx String
str [Symbol]
sortNames [Sort]
sorts [Symbol]
declNames [FuncDecl]
decls =
  (Ptr Z3_context
 -> Z3_string
 -> CUInt
 -> Ptr (Ptr Z3_symbol)
 -> Ptr (Ptr Z3_sort)
 -> CUInt
 -> Ptr (Ptr Z3_symbol)
 -> Ptr (Ptr Z3_func_decl)
 -> IO (Ptr Z3_ast_vector))
-> Context
-> ((Z3_string
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_sort)
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_func_decl)
     -> IO (Ptr Z3_ast_vector))
    -> IO (Ptr Z3_ast_vector))
-> IO [AST]
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Z3_string
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_ast_vector)
z3_parse_smtlib2_string Context
ctx (((Z3_string
   -> CUInt
   -> Ptr (Ptr Z3_symbol)
   -> Ptr (Ptr Z3_sort)
   -> CUInt
   -> Ptr (Ptr Z3_symbol)
   -> Ptr (Ptr Z3_func_decl)
   -> IO (Ptr Z3_ast_vector))
  -> IO (Ptr Z3_ast_vector))
 -> IO [AST])
-> ((Z3_string
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_sort)
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_func_decl)
     -> IO (Ptr Z3_ast_vector))
    -> IO (Ptr Z3_ast_vector))
-> IO [AST]
forall a b. (a -> b) -> a -> b
$ \Z3_string
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_ast_vector)
f ->
    String
-> (Z3_string -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector)
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
str ((Z3_string -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector))
-> (Z3_string -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \Z3_string
cstr ->
    [Sort]
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Sort]
sorts ((CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \CUInt
sortNum Ptr (Ptr Z3_sort)
sortArr ->
    [Symbol]
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [Symbol]
sortNames ((Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_symbol)
sortNameArr ->
    [FuncDecl]
-> (CUInt -> Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [FuncDecl]
decls ((CUInt -> Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (CUInt -> Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \CUInt
declNum Ptr (Ptr Z3_func_decl)
declArr ->
    [Symbol]
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [Symbol]
declNames ((Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_symbol)
declNameArr ->
      Z3_string
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_ast_vector)
f Z3_string
cstr CUInt
sortNum Ptr (Ptr Z3_symbol)
sortNameArr Ptr (Ptr Z3_sort)
sortArr CUInt
declNum Ptr (Ptr Z3_symbol)
declNameArr Ptr (Ptr Z3_func_decl)
declArr

parseSMTLib2File :: Context
                 -> String     -- ^ file name
                 -> [Symbol]   -- ^ sort names
                 -> [Sort]     -- ^ sorts
                 -> [Symbol]   -- ^ declaration names
                 -> [FuncDecl] -- ^ declarations
                 -> IO [AST]
parseSMTLib2File :: Context
-> String
-> [Symbol]
-> [Sort]
-> [Symbol]
-> [FuncDecl]
-> IO [AST]
parseSMTLib2File Context
ctx String
file [Symbol]
sortNames [Sort]
sorts [Symbol]
declNames [FuncDecl]
decls =
  (Ptr Z3_context
 -> Z3_string
 -> CUInt
 -> Ptr (Ptr Z3_symbol)
 -> Ptr (Ptr Z3_sort)
 -> CUInt
 -> Ptr (Ptr Z3_symbol)
 -> Ptr (Ptr Z3_func_decl)
 -> IO (Ptr Z3_ast_vector))
-> Context
-> ((Z3_string
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_sort)
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_func_decl)
     -> IO (Ptr Z3_ast_vector))
    -> IO (Ptr Z3_ast_vector))
-> IO [AST]
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Z3_string
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_ast_vector)
z3_parse_smtlib2_file Context
ctx (((Z3_string
   -> CUInt
   -> Ptr (Ptr Z3_symbol)
   -> Ptr (Ptr Z3_sort)
   -> CUInt
   -> Ptr (Ptr Z3_symbol)
   -> Ptr (Ptr Z3_func_decl)
   -> IO (Ptr Z3_ast_vector))
  -> IO (Ptr Z3_ast_vector))
 -> IO [AST])
-> ((Z3_string
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_sort)
     -> CUInt
     -> Ptr (Ptr Z3_symbol)
     -> Ptr (Ptr Z3_func_decl)
     -> IO (Ptr Z3_ast_vector))
    -> IO (Ptr Z3_ast_vector))
-> IO [AST]
forall a b. (a -> b) -> a -> b
$ \Z3_string
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_ast_vector)
f ->
    String
-> (Z3_string -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector)
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
file ((Z3_string -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector))
-> (Z3_string -> IO (Ptr Z3_ast_vector)) -> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \Z3_string
fileName ->
    [Sort]
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [Sort]
sorts ((CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (CUInt -> Ptr (Ptr Z3_sort) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \CUInt
sortNum Ptr (Ptr Z3_sort)
sortArr ->
    [Symbol]
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [Symbol]
sortNames ((Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_symbol)
sortNameArr ->
    [FuncDecl]
-> (CUInt -> Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [FuncDecl]
decls ((CUInt -> Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (CUInt -> Ptr (Ptr Z3_func_decl) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \CUInt
declNum Ptr (Ptr Z3_func_decl)
declArr ->
    [Symbol]
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [Symbol]
declNames ((Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
 -> IO (Ptr Z3_ast_vector))
-> (Ptr (Ptr Z3_symbol) -> IO (Ptr Z3_ast_vector))
-> IO (Ptr Z3_ast_vector)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr Z3_symbol)
declNameArr ->
      Z3_string
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_sort)
-> CUInt
-> Ptr (Ptr Z3_symbol)
-> Ptr (Ptr Z3_func_decl)
-> IO (Ptr Z3_ast_vector)
f Z3_string
fileName CUInt
sortNum Ptr (Ptr Z3_symbol)
sortNameArr Ptr (Ptr Z3_sort)
sortArr CUInt
declNum Ptr (Ptr Z3_symbol)
declNameArr Ptr (Ptr Z3_func_decl)
declArr

evalSMTLib2String :: Context
                  -> String    -- ^ string to parse
                  -> IO String
evalSMTLib2String :: Context -> String -> IO String
evalSMTLib2String Context
ctx String
cmd =
  (Ptr Z3_context -> Z3_string -> IO Z3_string)
-> Context
-> ((Z3_string -> IO Z3_string) -> IO Z3_string)
-> IO String
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> Z3_string -> IO Z3_string
z3_eval_smtlib2_string Context
ctx (((Z3_string -> IO Z3_string) -> IO Z3_string) -> IO String)
-> ((Z3_string -> IO Z3_string) -> IO Z3_string) -> IO String
forall a b. (a -> b) -> a -> b
$ \Z3_string -> IO Z3_string
f ->
    String -> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
cmd ((Z3_string -> IO Z3_string) -> IO Z3_string)
-> (Z3_string -> IO Z3_string) -> IO Z3_string
forall a b. (a -> b) -> a -> b
$ \Z3_string
command ->
      Z3_string -> IO Z3_string
f Z3_string
command

---------------------------------------------------------------------
-- Error handling

-- | Z3 exceptions.
--
-- Z3 errors are re-thrown as Haskell 'Z3Error' exceptions,
-- see 'Control.Exception'.
data Z3Error = Z3Error
    { Z3Error -> Z3ErrorCode
errCode :: Z3ErrorCode
    , Z3Error -> String
errMsg  :: String
    }
  deriving Typeable

instance Show Z3Error where
  show :: Z3Error -> String
show (Z3Error Z3ErrorCode
_ String
s) = String
"Z3 error: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s

-- | Z3 error codes.
data Z3ErrorCode = SortError | IOB | InvalidArg | ParserError | NoParser
  | InvalidPattern | MemoutFail  | FileAccessError | InternalFatal
  | InvalidUsage   | DecRefError | Z3Exception
  deriving (Int -> Z3ErrorCode -> ShowS
[Z3ErrorCode] -> ShowS
Z3ErrorCode -> String
(Int -> Z3ErrorCode -> ShowS)
-> (Z3ErrorCode -> String)
-> ([Z3ErrorCode] -> ShowS)
-> Show Z3ErrorCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Z3ErrorCode -> ShowS
showsPrec :: Int -> Z3ErrorCode -> ShowS
$cshow :: Z3ErrorCode -> String
show :: Z3ErrorCode -> String
$cshowList :: [Z3ErrorCode] -> ShowS
showList :: [Z3ErrorCode] -> ShowS
Show, Typeable)

toZ3Error :: Z3_error_code -> Z3ErrorCode
toZ3Error :: Z3_error_code -> Z3ErrorCode
toZ3Error Z3_error_code
e
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_sort_error        = Z3ErrorCode
SortError
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_iob               = Z3ErrorCode
IOB
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_invalid_arg       = Z3ErrorCode
InvalidArg
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_parser_error      = Z3ErrorCode
ParserError
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_no_parser         = Z3ErrorCode
NoParser
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_invalid_pattern   = Z3ErrorCode
InvalidPattern
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_memout_fail       = Z3ErrorCode
MemoutFail
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_file_access_error = Z3ErrorCode
FileAccessError
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_internal_fatal    = Z3ErrorCode
InternalFatal
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_invalid_usage     = Z3ErrorCode
InvalidUsage
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_dec_ref_error     = Z3ErrorCode
DecRefError
  | Z3_error_code
e Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_error_code
z3_exception         = Z3ErrorCode
Z3Exception
  | Bool
otherwise                 = String -> Z3ErrorCode
forall a. HasCallStack => String -> a
error String
"Z3.Base.toZ3Error: illegal `Z3_error_code' value"

instance Exception Z3Error

-- | Throws a z3 error
z3Error :: Z3ErrorCode -> String -> IO ()
z3Error :: Z3ErrorCode -> String -> IO ()
z3Error Z3ErrorCode
cd = Z3Error -> IO ()
forall a e. Exception e => e -> a
throw (Z3Error -> IO ()) -> (String -> Z3Error) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z3ErrorCode -> String -> Z3Error
Z3Error Z3ErrorCode
cd

-- | Throw an exception if a Z3 error happened
checkError :: Ptr Z3_context -> IO a -> IO a
checkError :: forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
cPtr IO a
m = do
  IO a
m IO a -> IO () -> IO a
forall a b. IO a -> IO b -> IO a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (Ptr Z3_context -> IO Z3_error_code
z3_get_error_code Ptr Z3_context
cPtr IO Z3_error_code -> (Z3_error_code -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Z3_error_code -> IO ()
throwZ3Exn)
  where getErrStr :: Z3_error_code -> IO String
getErrStr Z3_error_code
i  = Z3_string -> IO String
peekCString (Z3_string -> IO String) -> IO Z3_string -> IO String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Z3_context -> Z3_error_code -> IO Z3_string
z3_get_error_msg Ptr Z3_context
cPtr Z3_error_code
i
        throwZ3Exn :: Z3_error_code -> IO ()
throwZ3Exn Z3_error_code
i = Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Z3_error_code
i Z3_error_code -> Z3_error_code -> Bool
forall a. Eq a => a -> a -> Bool
/= Z3_error_code
z3_ok) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Z3_error_code -> IO String
getErrStr Z3_error_code
i IO String -> (String -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Z3ErrorCode -> String -> IO ()
z3Error (Z3_error_code -> Z3ErrorCode
toZ3Error Z3_error_code
i)

---------------------------------------------------------------------
-- Miscellaneous

data Version
  = Version {
      Version -> Int
z3Major    :: !Int
    , Version -> Int
z3Minor    :: !Int
    , Version -> Int
z3Build    :: !Int
    , Version -> Int
z3Revision :: !Int
    }
  deriving (Version -> Version -> Bool
(Version -> Version -> Bool)
-> (Version -> Version -> Bool) -> Eq Version
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Version -> Version -> Bool
== :: Version -> Version -> Bool
$c/= :: Version -> Version -> Bool
/= :: Version -> Version -> Bool
Eq,Eq Version
Eq Version
-> (Version -> Version -> Ordering)
-> (Version -> Version -> Bool)
-> (Version -> Version -> Bool)
-> (Version -> Version -> Bool)
-> (Version -> Version -> Bool)
-> (Version -> Version -> Version)
-> (Version -> Version -> Version)
-> Ord Version
Version -> Version -> Bool
Version -> Version -> Ordering
Version -> Version -> Version
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 :: Version -> Version -> Ordering
compare :: Version -> Version -> Ordering
$c< :: Version -> Version -> Bool
< :: Version -> Version -> Bool
$c<= :: Version -> Version -> Bool
<= :: Version -> Version -> Bool
$c> :: Version -> Version -> Bool
> :: Version -> Version -> Bool
$c>= :: Version -> Version -> Bool
>= :: Version -> Version -> Bool
$cmax :: Version -> Version -> Version
max :: Version -> Version -> Version
$cmin :: Version -> Version -> Version
min :: Version -> Version -> Version
Ord)

instance Show Version where
  show :: Version -> String
show (Version Int
major Int
minor Int
build Int
_) =
    Int -> String
forall a. Show a => a -> String
show Int
major String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
minor String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
build

-- | Return Z3 version number information.
getVersion :: IO Version
getVersion :: IO Version
getVersion =
  (Ptr CUInt -> IO Version) -> IO Version
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CUInt -> IO Version) -> IO Version)
-> (Ptr CUInt -> IO Version) -> IO Version
forall a b. (a -> b) -> a -> b
$ \Ptr CUInt
ptrMinor ->
  (Ptr CUInt -> IO Version) -> IO Version
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CUInt -> IO Version) -> IO Version)
-> (Ptr CUInt -> IO Version) -> IO Version
forall a b. (a -> b) -> a -> b
$ \Ptr CUInt
ptrMajor ->
  (Ptr CUInt -> IO Version) -> IO Version
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CUInt -> IO Version) -> IO Version)
-> (Ptr CUInt -> IO Version) -> IO Version
forall a b. (a -> b) -> a -> b
$ \Ptr CUInt
ptrBuild ->
  (Ptr CUInt -> IO Version) -> IO Version
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CUInt -> IO Version) -> IO Version)
-> (Ptr CUInt -> IO Version) -> IO Version
forall a b. (a -> b) -> a -> b
$ \Ptr CUInt
ptrRevision -> do
    Ptr CUInt -> Ptr CUInt -> Ptr CUInt -> Ptr CUInt -> IO ()
z3_get_version Ptr CUInt
ptrMinor Ptr CUInt
ptrMajor Ptr CUInt
ptrBuild Ptr CUInt
ptrRevision
    Int
minor    <- CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CUInt -> Int) -> IO CUInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CUInt -> IO CUInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CUInt
ptrMinor
    Int
major    <- CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CUInt -> Int) -> IO CUInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CUInt -> IO CUInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CUInt
ptrMajor
    Int
build    <- CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CUInt -> Int) -> IO CUInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CUInt -> IO CUInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CUInt
ptrBuild
    Int
revision <- CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CUInt -> Int) -> IO CUInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CUInt -> IO CUInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CUInt
ptrRevision
    Version -> IO Version
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Version -> IO Version) -> Version -> IO Version
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> Int -> Version
Version Int
minor Int
major Int
build Int
revision

---------------------------------------------------------------------
-- Externalm Theory Plugins

-- TODO

---------------------------------------------------------------------
-- Fixedpoint facilities

newtype Fixedpoint = Fixedpoint { Fixedpoint -> ForeignPtr Z3_fixedpoint
unFixedpoint :: ForeignPtr Z3_fixedpoint }
    deriving Fixedpoint -> Fixedpoint -> Bool
(Fixedpoint -> Fixedpoint -> Bool)
-> (Fixedpoint -> Fixedpoint -> Bool) -> Eq Fixedpoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Fixedpoint -> Fixedpoint -> Bool
== :: Fixedpoint -> Fixedpoint -> Bool
$c/= :: Fixedpoint -> Fixedpoint -> Bool
/= :: Fixedpoint -> Fixedpoint -> Bool
Eq

instance Marshal Fixedpoint (Ptr Z3_fixedpoint) where
  c2h :: Context -> Ptr Z3_fixedpoint -> IO Fixedpoint
c2h = (ForeignPtr Z3_fixedpoint -> Fixedpoint)
-> Z3IncRefFun Z3_fixedpoint
-> Z3IncRefFun Z3_fixedpoint
-> Context
-> Ptr Z3_fixedpoint
-> IO Fixedpoint
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_fixedpoint -> Fixedpoint
Fixedpoint Z3IncRefFun Z3_fixedpoint
z3_fixedpoint_inc_ref Z3IncRefFun Z3_fixedpoint
z3_fixedpoint_dec_ref
  h2c :: forall r. Fixedpoint -> (Ptr Z3_fixedpoint -> IO r) -> IO r
h2c Fixedpoint
fp = ForeignPtr Z3_fixedpoint -> (Ptr Z3_fixedpoint -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Fixedpoint -> ForeignPtr Z3_fixedpoint
unFixedpoint Fixedpoint
fp)

mkFixedpoint :: Context -> IO Fixedpoint
mkFixedpoint :: Context -> IO Fixedpoint
mkFixedpoint = (Ptr Z3_context -> IO (Ptr Z3_fixedpoint))
-> Context -> IO Fixedpoint
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_fixedpoint)
z3_mk_fixedpoint

fixedpointAddRule :: Context -> Fixedpoint -> AST -> Symbol -> IO ()
fixedpointAddRule :: Context -> Fixedpoint -> AST -> Symbol -> IO ()
fixedpointAddRule = (Ptr Z3_context
 -> Ptr Z3_fixedpoint -> Ptr Z3_ast -> Ptr Z3_symbol -> IO ())
-> Context -> Fixedpoint -> AST -> Symbol -> IO ()
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_fixedpoint -> Ptr Z3_ast -> Ptr Z3_symbol -> IO ()
z3_fixedpoint_add_rule

fixedpointSetParams :: Context -> Fixedpoint -> Params -> IO ()
fixedpointSetParams :: Context -> Fixedpoint -> Params -> IO ()
fixedpointSetParams = (Ptr Z3_context -> Ptr Z3_fixedpoint -> Ptr Z3_params -> IO ())
-> Context -> Fixedpoint -> Params -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_fixedpoint -> Ptr Z3_params -> IO ()
z3_fixedpoint_set_params

fixedpointRegisterRelation :: Context -> Fixedpoint -> FuncDecl -> IO ()
fixedpointRegisterRelation :: Context -> Fixedpoint -> FuncDecl -> IO ()
fixedpointRegisterRelation = (Ptr Z3_context -> Ptr Z3_fixedpoint -> Ptr Z3_func_decl -> IO ())
-> Context -> Fixedpoint -> FuncDecl -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_fixedpoint -> Ptr Z3_func_decl -> IO ()
z3_fixedpoint_register_relation

fixedpointQueryRelations :: Context -> Fixedpoint -> [FuncDecl] -> IO Result
fixedpointQueryRelations :: Context -> Fixedpoint -> [FuncDecl] -> IO Result
fixedpointQueryRelations Context
ctx Fixedpoint
fixedpoint [FuncDecl]
fds =
  (Ptr Z3_context
 -> Ptr Z3_fixedpoint
 -> CUInt
 -> Ptr (Ptr Z3_func_decl)
 -> IO Z3_lbool)
-> Context
-> ((Ptr Z3_fixedpoint
     -> CUInt -> Ptr (Ptr Z3_func_decl) -> IO Z3_lbool)
    -> IO Z3_lbool)
-> IO Result
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_fixedpoint
-> CUInt
-> Ptr (Ptr Z3_func_decl)
-> IO Z3_lbool
z3_fixedpoint_query_relations Context
ctx (((Ptr Z3_fixedpoint
   -> CUInt -> Ptr (Ptr Z3_func_decl) -> IO Z3_lbool)
  -> IO Z3_lbool)
 -> IO Result)
-> ((Ptr Z3_fixedpoint
     -> CUInt -> Ptr (Ptr Z3_func_decl) -> IO Z3_lbool)
    -> IO Z3_lbool)
-> IO Result
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_fixedpoint -> CUInt -> Ptr (Ptr Z3_func_decl) -> IO Z3_lbool
f ->
    Fixedpoint -> (Ptr Z3_fixedpoint -> IO Z3_lbool) -> IO Z3_lbool
forall r. Fixedpoint -> (Ptr Z3_fixedpoint -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Fixedpoint
fixedpoint ((Ptr Z3_fixedpoint -> IO Z3_lbool) -> IO Z3_lbool)
-> (Ptr Z3_fixedpoint -> IO Z3_lbool) -> IO Z3_lbool
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_fixedpoint
fixedpointPtr ->
    [FuncDecl]
-> (CUInt -> Ptr (Ptr Z3_func_decl) -> IO Z3_lbool) -> IO Z3_lbool
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [FuncDecl]
fds ((CUInt -> Ptr (Ptr Z3_func_decl) -> IO Z3_lbool) -> IO Z3_lbool)
-> (CUInt -> Ptr (Ptr Z3_func_decl) -> IO Z3_lbool) -> IO Z3_lbool
forall a b. (a -> b) -> a -> b
$ \CUInt
fdsNum Ptr (Ptr Z3_func_decl)
fdsArr ->
      Ptr Z3_fixedpoint -> CUInt -> Ptr (Ptr Z3_func_decl) -> IO Z3_lbool
f Ptr Z3_fixedpoint
fixedpointPtr CUInt
fdsNum Ptr (Ptr Z3_func_decl)
fdsArr

fixedpointGetAnswer :: Context -> Fixedpoint -> IO AST
fixedpointGetAnswer :: Context -> Fixedpoint -> IO AST
fixedpointGetAnswer = (Ptr Z3_context -> Ptr Z3_fixedpoint -> IO (Ptr Z3_ast))
-> Context -> Fixedpoint -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_fixedpoint -> IO (Ptr Z3_ast)
z3_fixedpoint_get_answer

fixedpointGetAssertions :: Context -> Fixedpoint -> IO [AST]
fixedpointGetAssertions :: Context -> Fixedpoint -> IO [AST]
fixedpointGetAssertions = (Ptr Z3_context -> Ptr Z3_fixedpoint -> IO (Ptr Z3_ast_vector))
-> Context -> Fixedpoint -> IO [AST]
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_fixedpoint -> IO (Ptr Z3_ast_vector)
z3_fixedpoint_get_assertions

---------------------------------------------------------------------
-- Floating-Point Arithmetic

-- | Create the RoundingMode sort.
mkFpaRoundingModeSort :: Context -> IO Sort
mkFpaRoundingModeSort :: Context -> IO Sort
mkFpaRoundingModeSort = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_rounding_mode_sort

-- | Create a numeral of RoundingMode sort which represents the
-- NearestTiesToEven rounding mode.
mkFpaRoundNearestTiesToEven :: Context -> IO AST
mkFpaRoundNearestTiesToEven :: Context -> IO AST
mkFpaRoundNearestTiesToEven = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_round_nearest_ties_to_even

-- | Create a numeral of RoundingMode sort which represents the
-- NearestTiesToEven rounding mode.
mkFpaRne :: Context -> IO AST
mkFpaRne :: Context -> IO AST
mkFpaRne = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_rne

-- | Create a numeral of RoundingMode sort which represents the
-- NearestTiesToAway rounding mode.
mkFpaRoundNearestTiesToAway :: Context -> IO AST
mkFpaRoundNearestTiesToAway :: Context -> IO AST
mkFpaRoundNearestTiesToAway = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_round_nearest_ties_to_away

-- | Create a numeral of RoundingMode sort which represents the
-- NearestTiesToAway rounding mode.
mkFpaRna :: Context -> IO AST
mkFpaRna :: Context -> IO AST
mkFpaRna = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_rna

-- | Create a numeral of RoundingMode sort which represents the
-- TowardPositive rounding mode.
mkFpaRoundTowardPositive :: Context -> IO AST
mkFpaRoundTowardPositive :: Context -> IO AST
mkFpaRoundTowardPositive = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_round_toward_positive

-- | Create a numeral of RoundingMode sort which represents the
-- TowardPositive rounding mode.
mkFpaRtp :: Context -> IO AST
mkFpaRtp :: Context -> IO AST
mkFpaRtp = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_rtp

-- | Create a numeral of RoundingMode sort which represents the
-- TowardNegative rounding mode.
mkFpaRoundTowardNegative :: Context -> IO AST
mkFpaRoundTowardNegative :: Context -> IO AST
mkFpaRoundTowardNegative = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_round_toward_negative

-- | Create a numeral of RoundingMode sort which represents the
-- TowardNegative rounding mode.
mkFpaRtn :: Context -> IO AST
mkFpaRtn :: Context -> IO AST
mkFpaRtn = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_rtn

-- | Create a numeral of RoundingMode sort which represents the
-- TowardZero rounding mode.
mkFpaRoundTowardZero :: Context -> IO AST
mkFpaRoundTowardZero :: Context -> IO AST
mkFpaRoundTowardZero = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_round_toward_zero

-- | Create a numeral of RoundingMode sort which represents the
-- TowardZero rounding mode.
mkFpaRtz :: Context -> IO AST
mkFpaRtz :: Context -> IO AST
mkFpaRtz = (Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
z3_mk_fpa_rtz

-- | Create a FloatingPoint sort.
mkFpaSort :: Integral int
          => Context -- ^ Context
          -> int -- ^ Number of exponent bits
          -> int -- ^ Number of significand bits
          -> IO Sort
mkFpaSort :: forall int. Integral int => Context -> int -> int -> IO Sort
mkFpaSort = (Ptr Z3_context -> CUInt -> CUInt -> IO (Ptr Z3_sort))
-> Context -> int -> int -> IO Sort
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CUInt -> CUInt -> IO (Ptr Z3_sort)
z3_mk_fpa_sort

-- | Create the half-precision (16-bit) FloatingPoint sort.
mkFpaSortHalf :: Context -> IO Sort
mkFpaSortHalf :: Context -> IO Sort
mkFpaSortHalf = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_sort_half

-- | Create the half-precision (16-bit) FloatingPoint sort.
mkFpaSort16 :: Context -> IO Sort
mkFpaSort16 :: Context -> IO Sort
mkFpaSort16 = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_sort_16

-- | Create the single-precision (32-bit) FloatingPoint sort.
mkFpaSortSingle :: Context -> IO Sort
mkFpaSortSingle :: Context -> IO Sort
mkFpaSortSingle = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_sort_single

-- | Create the single-precision (32-bit) FloatingPoint sort.
mkFpaSort32 :: Context -> IO Sort
mkFpaSort32 :: Context -> IO Sort
mkFpaSort32 = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_sort_32

-- | Create the double-precision (64-bit) FloatingPoint sort.
mkFpaSortDouble :: Context -> IO Sort
mkFpaSortDouble :: Context -> IO Sort
mkFpaSortDouble = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_sort_double

-- | Create the double-precision (64-bit) FloatingPoint sort.
mkFpaSort64 :: Context -> IO Sort
mkFpaSort64 :: Context -> IO Sort
mkFpaSort64 = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_sort_64

-- | Create the quadruple-precision (128-bit) FloatingPoint sort.
mkFpaSortQuadruple :: Context -> IO Sort
mkFpaSortQuadruple :: Context -> IO Sort
mkFpaSortQuadruple = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_sort_quadruple

-- | Create the quadruple-precision (128-bit) FloatingPoint sort.
mkFpaSort128 :: Context -> IO Sort
mkFpaSort128 :: Context -> IO Sort
mkFpaSort128 = (Ptr Z3_context -> IO (Ptr Z3_sort)) -> Context -> IO Sort
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_sort)
z3_mk_fpa_sort_128

-- | Create a floating-point NaN of sort @s@.
mkFpaNaN :: Context -> Sort -> IO AST
mkFpaNaN :: Context -> Sort -> IO AST
mkFpaNaN = (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Sort -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_nan

-- | Create a floating-point infinity of sort @s@.
mkFpaInf :: Context -- ^ Context
         -> Sort    -- ^ Target sort
         -> Bool    -- ^ Indicates whether the result should be negative
         -> IO AST
mkFpaInf :: Context -> Sort -> Bool -> IO AST
mkFpaInf = (Ptr Z3_context -> Ptr Z3_sort -> Z3_bool -> IO (Ptr Z3_ast))
-> Context -> Sort -> Bool -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_sort -> Z3_bool -> IO (Ptr Z3_ast)
z3_mk_fpa_inf

-- | Create a floating-point zero of sort @s@.
mkFpaZero :: Context -- ^ Context
          -> Sort    -- ^ Target sort
          -> Bool    -- ^ Indicates whether the result should be negative
          -> IO AST
mkFpaZero :: Context -> Sort -> Bool -> IO AST
mkFpaZero = (Ptr Z3_context -> Ptr Z3_sort -> Z3_bool -> IO (Ptr Z3_ast))
-> Context -> Sort -> Bool -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_sort -> Z3_bool -> IO (Ptr Z3_ast)
z3_mk_fpa_zero

-- | Create an expression of FloatingPoint sort from three bit-vector
-- expressions.
--
-- This is the operator named `fp' in the SMT FP theory definition.
-- Note that @sgn@ is required to be a bit-vector of size 1.
-- Significand and exponent are required to be longer than 1 and 2
-- respectively. The FloatingPoint sort of the resulting expression
-- is automatically determined from the bit-vector sizes of the
-- arguments. The exponent is assumed to be in IEEE-754 biased
-- representation.
mkFpaFp :: Context -- ^ Context
        -> AST     -- ^ Sign
        -> AST     -- ^ Exponent
        -> AST     -- ^ Significand
        -> IO AST
mkFpaFp :: Context -> AST -> AST -> AST -> IO AST
mkFpaFp = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_fp

-- | Create a numeral of FloatingPoint sort from a float.
mkFpaNumeralFloat :: Context -> Float -> Sort -> IO AST
mkFpaNumeralFloat :: Context -> Float -> Sort -> IO AST
mkFpaNumeralFloat = (Ptr Z3_context -> CFloat -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Float -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CFloat -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_numeral_float

-- | Create a numeral of FloatingPoint sort from a double.
mkFpaNumeralDouble :: Context -> Double -> Sort -> IO AST
mkFpaNumeralDouble :: Context -> Double -> Sort -> IO AST
mkFpaNumeralDouble = (Ptr Z3_context -> CDouble -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Double -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> CDouble -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_numeral_double

-- | Create a numeral of FloatingPoint sort from a signed integer.
mkFpaNumeralInt :: Integral int => Context -> int -> Sort -> IO AST
mkFpaNumeralInt :: forall a. Integral a => Context -> a -> Sort -> IO AST
mkFpaNumeralInt = (Ptr Z3_context -> Z3_error_code -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> int -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Z3_error_code -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_numeral_int

-- | Create a numeral of FLoatingPoint sort from a sign bit and
-- two integers.
mkFpaNumeralIntUInt :: Integral int
                    => Context -- ^ Context
                    -> Bool    -- ^ Sign bit (true == negative)
                    -> int     -- ^ Significand
                    -> int     -- ^ Exponent
                    -> Sort    -- ^ Result sort
                    -> IO AST
mkFpaNumeralIntUInt :: forall int.
Integral int =>
Context -> Bool -> int -> int -> Sort -> IO AST
mkFpaNumeralIntUInt = (Ptr Z3_context
 -> Z3_bool
 -> Z3_error_code
 -> CUInt
 -> Ptr Z3_sort
 -> IO (Ptr Z3_ast))
-> Context -> Bool -> int -> int -> Sort -> IO AST
forall ah ac bh bc ch cc dh dc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal dh dc,
 Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> dc -> IO rc)
-> Context -> ah -> bh -> ch -> dh -> IO rh
liftFun4 Ptr Z3_context
-> Z3_bool
-> Z3_error_code
-> CUInt
-> Ptr Z3_sort
-> IO (Ptr Z3_ast)
z3_mk_fpa_numeral_int_uint

-- | Create a numeral of FloatingPoint sort from a sign bit and
-- two 64-bit integers.
mkFpaNumeralInt64UInt64 :: Integral int
                        => Context -- ^ Context
                        -> Bool    -- ^ Sign bit (true == negative)
                        -> int     -- ^ Significand
                        -> int     -- ^ Exponent
                        -> Sort    -- ^ Result sort
                        -> IO AST
mkFpaNumeralInt64UInt64 :: forall int.
Integral int =>
Context -> Bool -> int -> int -> Sort -> IO AST
mkFpaNumeralInt64UInt64 = (Ptr Z3_context
 -> Z3_bool -> CLong -> CULong -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> Bool -> int -> int -> Sort -> IO AST
forall ah ac bh bc ch cc dh dc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal dh dc,
 Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> dc -> IO rc)
-> Context -> ah -> bh -> ch -> dh -> IO rh
liftFun4 Ptr Z3_context
-> Z3_bool -> CLong -> CULong -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_numeral_int64_uint64

-- | Floating-point absolute value.
mkFpaAbs :: Context -> AST -> IO AST
mkFpaAbs :: Context -> AST -> IO AST
mkFpaAbs = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_abs

-- | Floating-point negation.
mkFpaNeg :: Context -> AST -> IO AST
mkFpaNeg :: Context -> AST -> IO AST
mkFpaNeg = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_neg

-- | Floating-point addition.
mkFpaAdd :: Context -- ^ Context
         -> AST     -- ^ Rounding Mode
         -> AST     -- ^ FloatingPoint sort term
         -> AST     -- ^ FloatingPoint sort term
         -> IO AST
mkFpaAdd :: Context -> AST -> AST -> AST -> IO AST
mkFpaAdd = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_add

-- | Floating-point subtraction.
mkFpaSub :: Context -- ^ Context
         -> AST     -- ^ Rounding Mode
         -> AST     -- ^ FloatingPoint sort term
         -> AST     -- ^ FloatingPoint sort term
         -> IO AST
mkFpaSub :: Context -> AST -> AST -> AST -> IO AST
mkFpaSub = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_sub

-- | Floating-point multiplication.
mkFpaMul :: Context -- ^ Context
         -> AST     -- ^ Rounding Mode
         -> AST     -- ^ FloatingPoint sort term
         -> AST     -- ^ FloatingPoint sort term
         -> IO AST
mkFpaMul :: Context -> AST -> AST -> AST -> IO AST
mkFpaMul = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_mul

-- | Floating-point division.
mkFpaDiv :: Context -- ^ Context
         -> AST     -- ^ Rounding Mode
         -> AST     -- ^ FloatingPoint sort term
         -> AST     -- ^ FloatingPoint sort term
         -> IO AST
mkFpaDiv :: Context -> AST -> AST -> AST -> IO AST
mkFpaDiv = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_div

-- | Floating-point fused multiply-add.
--
-- The result is @round((t1 * t2) + t3)@.
mkFpaFma :: Context -> AST -> AST -> AST -> AST -> IO AST
mkFpaFma :: Context -> AST -> AST -> AST -> AST -> IO AST
mkFpaFma = (Ptr Z3_context
 -> Ptr Z3_ast
 -> Ptr Z3_ast
 -> Ptr Z3_ast
 -> Ptr Z3_ast
 -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> AST -> IO AST
forall ah ac bh bc ch cc dh dc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal dh dc,
 Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> dc -> IO rc)
-> Context -> ah -> bh -> ch -> dh -> IO rh
liftFun4 Ptr Z3_context
-> Ptr Z3_ast
-> Ptr Z3_ast
-> Ptr Z3_ast
-> Ptr Z3_ast
-> IO (Ptr Z3_ast)
z3_mk_fpa_fma

-- | Floating-point square root.
mkFpaSqrt :: Context -> AST -> AST -> IO AST
mkFpaSqrt :: Context -> AST -> AST -> IO AST
mkFpaSqrt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_sqrt

-- | Floating-point remainder.
mkFpaRem :: Context -> AST -> AST -> IO AST
mkFpaRem :: Context -> AST -> AST -> IO AST
mkFpaRem = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_rem

-- | Floating-point roundToIntegral. Rounds a floating-point number
-- to the closest integer, again represented as a floating-point
-- number.
mkFpaRoundToIntegral :: Context -> AST -> AST -> IO AST
mkFpaRoundToIntegral :: Context -> AST -> AST -> IO AST
mkFpaRoundToIntegral = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_round_to_integral

-- | Minimum of floating-point numbers.
mkFpaMin :: Context -> AST -> AST -> IO AST
mkFpaMin :: Context -> AST -> AST -> IO AST
mkFpaMin = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_min

-- | Maximum of floating-point numbers.
mkFpaMax :: Context -> AST -> AST -> IO AST
mkFpaMax :: Context -> AST -> AST -> IO AST
mkFpaMax = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_max

-- | Floating-point less than or equal.
mkFpaLeq :: Context -> AST -> AST -> IO AST
mkFpaLeq :: Context -> AST -> AST -> IO AST
mkFpaLeq = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_leq

-- | Floating-point less than.
mkFpaLt :: Context -> AST -> AST -> IO AST
mkFpaLt :: Context -> AST -> AST -> IO AST
mkFpaLt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_lt

-- | Floating-point greater than or equal.
mkFpaGeq :: Context -> AST -> AST -> IO AST
mkFpaGeq :: Context -> AST -> AST -> IO AST
mkFpaGeq = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_geq

-- | Floating-point greater than.
mkFpaGt :: Context -> AST -> AST -> IO AST
mkFpaGt :: Context -> AST -> AST -> IO AST
mkFpaGt = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_gt

-- | Floating-point equality.
mkFpaEq :: Context -> AST -> AST -> IO AST
mkFpaEq :: Context -> AST -> AST -> IO AST
mkFpaEq = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_eq

-- | Predicate indicating whether @t@ is a normal floating-point
-- number.
mkFpaIsNormal :: Context -> AST -> IO AST
mkFpaIsNormal :: Context -> AST -> IO AST
mkFpaIsNormal = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_is_normal

-- | Predicate indicating whether @t@ is a subnormal floating-point
-- number.
mkFpaIsSubnormal :: Context -> AST -> IO AST
mkFpaIsSubnormal :: Context -> AST -> IO AST
mkFpaIsSubnormal = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_is_subnormal

-- | Predicate indicating whether @t@ is a floating-point number
-- with zero value, i.e., +zero or -zero.
mkFpaIsZero :: Context -> AST -> IO AST
mkFpaIsZero :: Context -> AST -> IO AST
mkFpaIsZero = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_is_zero

-- | Predicate indicating whether @t@ is a floating-point number
-- representing infinity, i.e., +oo or -oo.
mkFpaIsInfinite :: Context -> AST -> IO AST
mkFpaIsInfinite :: Context -> AST -> IO AST
mkFpaIsInfinite = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_is_infinite

-- | Predicate indicating whether @t@ is NaN.
mkFpaIsNaN :: Context -> AST -> IO AST
mkFpaIsNaN :: Context -> AST -> IO AST
mkFpaIsNaN = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_is_nan

-- | Predicate indicating whether @t@ is a negative floating-point
-- number.
mkFpaIsNegative :: Context -> AST -> IO AST
mkFpaIsNegative :: Context -> AST -> IO AST
mkFpaIsNegative = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_is_negative

-- | Predicate indicating whether @t@ is a positive floating-point
-- number.
mkFpaIsPositive :: Context -> AST -> IO AST
mkFpaIsPositive :: Context -> AST -> IO AST
mkFpaIsPositive = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_is_positive

-- | Conversion of a single IEEE 754-2008 bit-vector into a
-- floating-point number.
mkFpaToFpBv :: Context -> AST -> Sort -> IO AST
mkFpaToFpBv :: Context -> AST -> Sort -> IO AST
mkFpaToFpBv = (Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> AST -> Sort -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_to_fp_bv

-- | Conversion of a FloatingPoint term into another term of
-- different FloatingPoint sort.
mkFpaToFpFloat :: Context -> AST -> AST -> Sort -> IO AST
mkFpaToFpFloat :: Context -> AST -> AST -> Sort -> IO AST
mkFpaToFpFloat = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> Sort -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_to_fp_float

-- | Conversion of a term of real sort into a term of
-- FloatingPoint sort.
mkFpaToFpReal :: Context -> AST -> AST -> Sort -> IO AST
mkFpaToFpReal :: Context -> AST -> AST -> Sort -> IO AST
mkFpaToFpReal = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> Sort -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_to_fp_real

-- | Conversion of a 2's complement signed bit-vector term into
-- a term of FloatingPoint sort.
mkFpaToFpSigned :: Context -> AST -> AST -> Sort -> IO AST
mkFpaToFpSigned :: Context -> AST -> AST -> Sort -> IO AST
mkFpaToFpSigned = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> Sort -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_to_fp_signed

-- | Conversion of a 2's complement unsigned bit-vector term into
-- a term of FloatingPoint sort.
mkFpaToFpUnsigned :: Context -> AST -> AST -> Sort -> IO AST
mkFpaToFpUnsigned :: Context -> AST -> AST -> Sort -> IO AST
mkFpaToFpUnsigned = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> Sort -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_mk_fpa_to_fp_unsigned

-- | Conversion of a floating-point term into an unsigned bit-vector.
mkFpaToUbv :: Integral int => Context -> AST -> AST -> int -> IO AST
mkFpaToUbv :: forall int. Integral int => Context -> AST -> AST -> int -> IO AST
mkFpaToUbv = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> int -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast)
z3_mk_fpa_to_ubv

-- | Conversion of a floating-point term into a signed bit-vector.
mkFpaToSbv :: Integral int => Context -> AST -> AST -> int -> IO AST
mkFpaToSbv :: forall int. Integral int => Context -> AST -> AST -> int -> IO AST
mkFpaToSbv = (Ptr Z3_context
 -> Ptr Z3_ast -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> int -> IO AST
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_ast -> Ptr Z3_ast -> CUInt -> IO (Ptr Z3_ast)
z3_mk_fpa_to_sbv

-- | Conversion of a floating-point term into an real-numbered
-- term.
mkFpaToReal :: Context -> AST -> IO AST
mkFpaToReal :: Context -> AST -> IO AST
mkFpaToReal = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_to_real

---------------------------------------------------------------------
-- Z3-specific floating-point extensions

-- | Retrieves the number of bits reserved for the exponent in a
-- FloatingPoint sort.
fpaGetEbits :: Integral int => Context -> Sort -> IO int
fpaGetEbits :: forall int. Integral int => Context -> Sort -> IO int
fpaGetEbits = (Ptr Z3_context -> Ptr Z3_sort -> IO CUInt)
-> Context -> Sort -> IO int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO CUInt
z3_fpa_get_ebits

-- | Retrieves the number of bits reserved for the significand in
-- a FloatingPoint sort.
fpaGetSbits :: Integral int => Context -> Sort -> IO int
fpaGetSbits :: forall int. Integral int => Context -> Sort -> IO int
fpaGetSbits = (Ptr Z3_context -> Ptr Z3_sort -> IO CUInt)
-> Context -> Sort -> IO int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_sort -> IO CUInt
z3_fpa_get_sbits

-- | Checks whether a given floating-point numeral is a NaN.
fpaIsNumeralNaN :: Context -> AST -> IO Bool
fpaIsNumeralNaN :: Context -> AST -> IO Bool
fpaIsNumeralNaN = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_fpa_is_numeral_nan

-- | Checks whether a given floating-point numeral is a +oo or -oo.
fpaIsNumeralInf :: Context -> AST -> IO Bool
fpaIsNumeralInf :: Context -> AST -> IO Bool
fpaIsNumeralInf = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_fpa_is_numeral_inf

-- | Checks whether a given floating-point numeral is a +zero or
-- -zero.
fpaIsNumeralZero :: Context -> AST -> IO Bool
fpaIsNumeralZero :: Context -> AST -> IO Bool
fpaIsNumeralZero = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_fpa_is_numeral_zero

-- | Checks whether a given floating-point numeral is normal.
fpaIsNumeralNormal :: Context -> AST -> IO Bool
fpaIsNumeralNormal :: Context -> AST -> IO Bool
fpaIsNumeralNormal = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_fpa_is_numeral_normal

-- | Checks whether a given floating-point numeral is subnormal.
fpaIsNumeralSubnormal :: Context -> AST -> IO Bool
fpaIsNumeralSubnormal :: Context -> AST -> IO Bool
fpaIsNumeralSubnormal = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_fpa_is_numeral_subnormal

-- | Checks whether a given floating-point numeral is positive.
fpaIsNumeralPositive :: Context -> AST -> IO Bool
fpaIsNumeralPositive :: Context -> AST -> IO Bool
fpaIsNumeralPositive = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_fpa_is_numeral_positive

-- | Checks whether a given floating-point numeral is negative.
fpaIsNumeralNegative :: Context -> AST -> IO Bool
fpaIsNumeralNegative :: Context -> AST -> IO Bool
fpaIsNumeralNegative = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool)
-> Context -> AST -> IO Bool
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_bool
z3_fpa_is_numeral_negative

-- | Retrieves the sign of a floating-point literal as a bit-vector
-- expression.
fpaGetNumeralSignBv :: Context -> AST -> IO AST
fpaGetNumeralSignBv :: Context -> AST -> IO AST
fpaGetNumeralSignBv = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_fpa_get_numeral_sign_bv

-- | Retrieves the significand of a floating-point literal as a
-- bit-vector expression.
fpaGetNumeralSignificandBv :: Context -> AST -> IO AST
fpaGetNumeralSignificandBv :: Context -> AST -> IO AST
fpaGetNumeralSignificandBv = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_fpa_get_numeral_significand_bv

-- | Return the significand value of a floating-point numeral as a
-- string.
fpaGetNumeralSignificandString :: Context -> AST -> IO String
fpaGetNumeralSignificandString :: Context -> AST -> IO String
fpaGetNumeralSignificandString = (Ptr Z3_context -> Ptr Z3_ast -> IO Z3_string)
-> Context -> AST -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO Z3_string
z3_fpa_get_numeral_significand_string

-- | Return the exponent value of a floating-point numeral as a
-- string.
fpaGetNumeralExponentString :: Context -> AST -> Bool -> IO String
fpaGetNumeralExponentString :: Context -> AST -> Bool -> IO String
fpaGetNumeralExponentString = (Ptr Z3_context -> Ptr Z3_ast -> Z3_bool -> IO Z3_string)
-> Context -> AST -> Bool -> IO String
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Z3_bool -> IO Z3_string
z3_fpa_get_numeral_exponent_string

-- | Retrieves the exponent of a floating-point literal as a
-- bit-vector expression.
fpaGetNumeralExponentBv :: Context -> AST -> Bool -> IO AST
fpaGetNumeralExponentBv :: Context -> AST -> Bool -> IO AST
fpaGetNumeralExponentBv = (Ptr Z3_context -> Ptr Z3_ast -> Z3_bool -> IO (Ptr Z3_ast))
-> Context -> AST -> Bool -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_ast -> Z3_bool -> IO (Ptr Z3_ast)
z3_fpa_get_numeral_exponent_bv

-- | Conversion of a floating-point term into a bit-vector term
-- in IEEE 754-2008 format.
mkFpaToIEEEBv :: Context -> AST -> IO AST
mkFpaToIEEEBv :: Context -> AST -> IO AST
mkFpaToIEEEBv = (Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast))
-> Context -> AST -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_ast -> IO (Ptr Z3_ast)
z3_mk_fpa_to_ieee_bv

-- | Conversion of a real-sorted significand and an integer-sorted
-- exponent into a term of FloatingPoint sort.
mkFpaToFpIntReal :: Context -> AST -> AST -> AST -> Sort -> IO AST
mkFpaToFpIntReal :: Context -> AST -> AST -> AST -> Sort -> IO AST
mkFpaToFpIntReal = (Ptr Z3_context
 -> Ptr Z3_ast
 -> Ptr Z3_ast
 -> Ptr Z3_ast
 -> Ptr Z3_sort
 -> IO (Ptr Z3_ast))
-> Context -> AST -> AST -> AST -> Sort -> IO AST
forall ah ac bh bc ch cc dh dc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal dh dc,
 Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> dc -> IO rc)
-> Context -> ah -> bh -> ch -> dh -> IO rh
liftFun4 Ptr Z3_context
-> Ptr Z3_ast
-> Ptr Z3_ast
-> Ptr Z3_ast
-> Ptr Z3_sort
-> IO (Ptr Z3_ast)
z3_mk_fpa_to_fp_int_real

---------------------------------------------------------------------
-- Optimization facilities

newtype Optimize = Optimize { Optimize -> ForeignPtr Z3_optimize
unOptimize :: ForeignPtr Z3_optimize }
    deriving Optimize -> Optimize -> Bool
(Optimize -> Optimize -> Bool)
-> (Optimize -> Optimize -> Bool) -> Eq Optimize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Optimize -> Optimize -> Bool
== :: Optimize -> Optimize -> Bool
$c/= :: Optimize -> Optimize -> Bool
/= :: Optimize -> Optimize -> Bool
Eq

instance Marshal Optimize (Ptr Z3_optimize) where
  c2h :: Context -> Ptr Z3_optimize -> IO Optimize
c2h = (ForeignPtr Z3_optimize -> Optimize)
-> Z3IncRefFun Z3_optimize
-> Z3IncRefFun Z3_optimize
-> Context
-> Ptr Z3_optimize
-> IO Optimize
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_optimize -> Optimize
Optimize Z3IncRefFun Z3_optimize
z3_optimize_inc_ref Z3IncRefFun Z3_optimize
z3_optimize_dec_ref
  h2c :: forall r. Optimize -> (Ptr Z3_optimize -> IO r) -> IO r
h2c Optimize
fp = ForeignPtr Z3_optimize -> (Ptr Z3_optimize -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Optimize -> ForeignPtr Z3_optimize
unOptimize Optimize
fp)

mkOptimize :: Context -> IO Optimize
mkOptimize :: Context -> IO Optimize
mkOptimize = (Ptr Z3_context -> IO (Ptr Z3_optimize)) -> Context -> IO Optimize
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_optimize)
z3_mk_optimize

optimizeAssert :: Context -> Optimize -> AST -> IO ()
optimizeAssert :: Context -> Optimize -> AST -> IO ()
optimizeAssert = (Ptr Z3_context -> Ptr Z3_optimize -> Ptr Z3_ast -> IO ())
-> Context -> Optimize -> AST -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_optimize -> Ptr Z3_ast -> IO ()
z3_optimize_assert

optimizeAssertAndTrack :: Context -> Optimize -> AST -> AST -> IO ()
optimizeAssertAndTrack :: Context -> Optimize -> AST -> AST -> IO ()
optimizeAssertAndTrack = (Ptr Z3_context
 -> Ptr Z3_optimize -> Ptr Z3_ast -> Ptr Z3_ast -> IO ())
-> Context -> Optimize -> AST -> AST -> IO ()
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_optimize -> Ptr Z3_ast -> Ptr Z3_ast -> IO ()
z3_optimize_assert_and_track

optimizeAssertSoft :: Context -> Optimize -> AST -> String -> Symbol -> IO Int
optimizeAssertSoft :: Context -> Optimize -> AST -> String -> Symbol -> IO Int
optimizeAssertSoft Context
ctx Optimize
opt AST
ast String
str Symbol
sym =
  (Ptr Z3_context
 -> Ptr Z3_optimize
 -> Ptr Z3_ast
 -> Z3_string
 -> Ptr Z3_symbol
 -> IO CUInt)
-> Context
-> ((Ptr Z3_optimize
     -> Ptr Z3_ast -> Z3_string -> Ptr Z3_symbol -> IO CUInt)
    -> IO CUInt)
-> IO Int
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_optimize
-> Ptr Z3_ast
-> Z3_string
-> Ptr Z3_symbol
-> IO CUInt
z3_optimize_assert_soft Context
ctx (((Ptr Z3_optimize
   -> Ptr Z3_ast -> Z3_string -> Ptr Z3_symbol -> IO CUInt)
  -> IO CUInt)
 -> IO Int)
-> ((Ptr Z3_optimize
     -> Ptr Z3_ast -> Z3_string -> Ptr Z3_symbol -> IO CUInt)
    -> IO CUInt)
-> IO Int
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_optimize
-> Ptr Z3_ast -> Z3_string -> Ptr Z3_symbol -> IO CUInt
f ->
    Optimize -> (Ptr Z3_optimize -> IO CUInt) -> IO CUInt
forall r. Optimize -> (Ptr Z3_optimize -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Optimize
opt ((Ptr Z3_optimize -> IO CUInt) -> IO CUInt)
-> (Ptr Z3_optimize -> IO CUInt) -> IO CUInt
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_optimize
optPtr ->
    AST -> (Ptr Z3_ast -> IO CUInt) -> IO CUInt
forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c AST
ast ((Ptr Z3_ast -> IO CUInt) -> IO CUInt)
-> (Ptr Z3_ast -> IO CUInt) -> IO CUInt
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_ast
astPtr ->
    String -> (Z3_string -> IO CUInt) -> IO CUInt
forall a. String -> (Z3_string -> IO a) -> IO a
withCString String
str ((Z3_string -> IO CUInt) -> IO CUInt)
-> (Z3_string -> IO CUInt) -> IO CUInt
forall a b. (a -> b) -> a -> b
$ \Z3_string
strPtr ->
    Symbol -> (Ptr Z3_symbol -> IO CUInt) -> IO CUInt
forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Symbol
sym ((Ptr Z3_symbol -> IO CUInt) -> IO CUInt)
-> (Ptr Z3_symbol -> IO CUInt) -> IO CUInt
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_symbol
symPtr ->
      Ptr Z3_optimize
-> Ptr Z3_ast -> Z3_string -> Ptr Z3_symbol -> IO CUInt
f Ptr Z3_optimize
optPtr Ptr Z3_ast
astPtr Z3_string
strPtr Ptr Z3_symbol
symPtr

optimizeMaximize :: Context -> Optimize -> AST -> IO Int
optimizeMaximize :: Context -> Optimize -> AST -> IO Int
optimizeMaximize = (Ptr Z3_context -> Ptr Z3_optimize -> Ptr Z3_ast -> IO CUInt)
-> Context -> Optimize -> AST -> IO Int
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_optimize -> Ptr Z3_ast -> IO CUInt
z3_optimize_maximize

optimizeMinimize :: Context -> Optimize -> AST -> IO Int
optimizeMinimize :: Context -> Optimize -> AST -> IO Int
optimizeMinimize = (Ptr Z3_context -> Ptr Z3_optimize -> Ptr Z3_ast -> IO CUInt)
-> Context -> Optimize -> AST -> IO Int
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_optimize -> Ptr Z3_ast -> IO CUInt
z3_optimize_minimize

optimizePush :: Context -> Optimize -> IO ()
optimizePush :: Context -> Optimize -> IO ()
optimizePush = Z3IncRefFun Z3_optimize -> Context -> Optimize -> IO ()
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Z3IncRefFun Z3_optimize
z3_optimize_push

optimizePop :: Context -> Optimize -> IO ()
optimizePop :: Context -> Optimize -> IO ()
optimizePop = Z3IncRefFun Z3_optimize -> Context -> Optimize -> IO ()
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Z3IncRefFun Z3_optimize
z3_optimize_pop

optimizeCheck :: Context -> Optimize -> [AST] -> IO Result
optimizeCheck :: Context -> Optimize -> [AST] -> IO Result
optimizeCheck Context
ctx Optimize
opt [AST]
ss = (Ptr Z3_context
 -> Ptr Z3_optimize -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool)
-> Context
-> ((Ptr Z3_optimize -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool)
    -> IO Z3_lbool)
-> IO Result
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_optimize -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool
z3_optimize_check Context
ctx (((Ptr Z3_optimize -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool)
  -> IO Z3_lbool)
 -> IO Result)
-> ((Ptr Z3_optimize -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool)
    -> IO Z3_lbool)
-> IO Result
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_optimize -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool
f ->
  Optimize -> (Ptr Z3_optimize -> IO Z3_lbool) -> IO Z3_lbool
forall r. Optimize -> (Ptr Z3_optimize -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Optimize
opt ((Ptr Z3_optimize -> IO Z3_lbool) -> IO Z3_lbool)
-> (Ptr Z3_optimize -> IO Z3_lbool) -> IO Z3_lbool
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_optimize
optPtr ->
  [AST] -> (CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool) -> IO Z3_lbool
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
ss ((CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool) -> IO Z3_lbool)
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool) -> IO Z3_lbool
forall a b. (a -> b) -> a -> b
$ \CUInt
ssNum Ptr (Ptr Z3_ast)
ssPtr ->
    Ptr Z3_optimize -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool
f Ptr Z3_optimize
optPtr CUInt
ssNum Ptr (Ptr Z3_ast)
ssPtr

optimizeGetReasonUnknown :: Context -> Optimize -> IO String
optimizeGetReasonUnknown :: Context -> Optimize -> IO String
optimizeGetReasonUnknown = (Ptr Z3_context -> Ptr Z3_optimize -> IO Z3_string)
-> Context -> Optimize -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_optimize -> IO Z3_string
z3_optimize_get_reason_unknown

optimizeGetModel :: Context -> Optimize -> IO Model
optimizeGetModel :: Context -> Optimize -> IO Model
optimizeGetModel = (Ptr Z3_context -> Ptr Z3_optimize -> IO (Ptr Z3_model))
-> Context -> Optimize -> IO Model
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_optimize -> IO (Ptr Z3_model)
z3_optimize_get_model

optimizeGetUnsatCore :: Context -> Optimize -> IO [AST]
optimizeGetUnsatCore :: Context -> Optimize -> IO [AST]
optimizeGetUnsatCore = (Ptr Z3_context -> Ptr Z3_optimize -> IO (Ptr Z3_ast_vector))
-> Context -> Optimize -> IO [AST]
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_optimize -> IO (Ptr Z3_ast_vector)
z3_optimize_get_unsat_core

optimizeSetParams :: Context -> Optimize -> Params -> IO ()
optimizeSetParams :: Context -> Optimize -> Params -> IO ()
optimizeSetParams = (Ptr Z3_context -> Ptr Z3_optimize -> Ptr Z3_params -> IO ())
-> Context -> Optimize -> Params -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_optimize -> Ptr Z3_params -> IO ()
z3_optimize_set_params

optimizeGetLower :: Context -> Optimize -> Int -> IO AST
optimizeGetLower :: Context -> Optimize -> Int -> IO AST
optimizeGetLower = (Ptr Z3_context -> Ptr Z3_optimize -> CUInt -> IO (Ptr Z3_ast))
-> Context -> Optimize -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_optimize -> CUInt -> IO (Ptr Z3_ast)
z3_optimize_get_lower

optimizeGetUpper :: Context -> Optimize -> Int -> IO AST
optimizeGetUpper :: Context -> Optimize -> Int -> IO AST
optimizeGetUpper = (Ptr Z3_context -> Ptr Z3_optimize -> CUInt -> IO (Ptr Z3_ast))
-> Context -> Optimize -> Int -> IO AST
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_optimize -> CUInt -> IO (Ptr Z3_ast)
z3_optimize_get_upper

optimizeGetUpperAsVector :: Context -> Optimize -> Int -> IO [AST]
optimizeGetUpperAsVector :: Context -> Optimize -> Int -> IO [AST]
optimizeGetUpperAsVector = (Ptr Z3_context
 -> Ptr Z3_optimize -> CUInt -> IO (Ptr Z3_ast_vector))
-> Context -> Optimize -> Int -> IO [AST]
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context
-> Ptr Z3_optimize -> CUInt -> IO (Ptr Z3_ast_vector)
z3_optimize_get_upper_as_vector

optimizeGetLowerAsVector :: Context -> Optimize -> Int -> IO [AST]
optimizeGetLowerAsVector :: Context -> Optimize -> Int -> IO [AST]
optimizeGetLowerAsVector = (Ptr Z3_context
 -> Ptr Z3_optimize -> CUInt -> IO (Ptr Z3_ast_vector))
-> Context -> Optimize -> Int -> IO [AST]
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context
-> Ptr Z3_optimize -> CUInt -> IO (Ptr Z3_ast_vector)
z3_optimize_get_lower_as_vector

optimizeToString :: Context -> Optimize -> IO String
optimizeToString :: Context -> Optimize -> IO String
optimizeToString = (Ptr Z3_context -> Ptr Z3_optimize -> IO Z3_string)
-> Context -> Optimize -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_optimize -> IO Z3_string
z3_optimize_to_string

optimizeFromString :: Context -> Optimize -> String -> IO ()
optimizeFromString :: Context -> Optimize -> String -> IO ()
optimizeFromString = (Ptr Z3_context -> Ptr Z3_optimize -> Z3_string -> IO ())
-> Context -> Optimize -> String -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_optimize -> Z3_string -> IO ()
z3_optimize_from_string

optimizeFromFile :: Context -> Optimize -> String -> IO ()
optimizeFromFile :: Context -> Optimize -> String -> IO ()
optimizeFromFile = (Ptr Z3_context -> Ptr Z3_optimize -> Z3_string -> IO ())
-> Context -> Optimize -> String -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_optimize -> Z3_string -> IO ()
z3_optimize_from_file

optimizeGetHelp :: Context -> Optimize -> IO String
optimizeGetHelp :: Context -> Optimize -> IO String
optimizeGetHelp = (Ptr Z3_context -> Ptr Z3_optimize -> IO Z3_string)
-> Context -> Optimize -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_optimize -> IO Z3_string
z3_optimize_get_help

optimizeGetAssertions :: Context -> Optimize -> IO [AST]
optimizeGetAssertions :: Context -> Optimize -> IO [AST]
optimizeGetAssertions = (Ptr Z3_context -> Ptr Z3_optimize -> IO (Ptr Z3_ast_vector))
-> Context -> Optimize -> IO [AST]
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_optimize -> IO (Ptr Z3_ast_vector)
z3_optimize_get_assertions

optimizeGetObjectives :: Context -> Optimize -> IO [AST]
optimizeGetObjectives :: Context -> Optimize -> IO [AST]
optimizeGetObjectives = (Ptr Z3_context -> Ptr Z3_optimize -> IO (Ptr Z3_ast_vector))
-> Context -> Optimize -> IO [AST]
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_optimize -> IO (Ptr Z3_ast_vector)
z3_optimize_get_objectives

-- AST vectors ?

-- AST maps ?

---------------------------------------------------------------------
-- Goals

-- TODO

---------------------------------------------------------------------
-- Tactics and Probes

-- TODO

---------------------------------------------------------------------
-- Solvers

-- | Solvers available in Z3.
--
-- These are described at <http://smtlib.cs.uiowa.edu/logics.html>
data Logic
  = AUFLIA
    -- ^ Closed formulas over the theory of linear integer arithmetic
    -- and arrays extended with free sort and function symbols but
    -- restricted to arrays with integer indices and values.

  | AUFLIRA
    -- ^ Closed linear formulas with free sort and function symbols over
    -- one- and two-dimentional arrays of integer index and real
    -- value.

  | AUFNIRA
    -- ^ Closed formulas with free function and predicate symbols over a
    -- theory of arrays of arrays of integer index and real value.

  | LRA
    -- ^ Closed linear formulas in linear real arithmetic.

  | QF_ABV
    -- ^ Closed quantifier-free formulas over the theory of bitvectors
    -- and bitvector arrays.

  | QF_AUFBV
    -- ^ Closed quantifier-free formulas over the theory of bitvectors
    -- and bitvector arrays extended with free sort and function
    -- symbols.

  | QF_AUFLIA
    -- ^ Closed quantifier-free linear formulas over the theory of
    -- integer arrays extended with free sort and function symbols.

  | QF_AX
    -- ^ Closed quantifier-free formulas over the theory of arrays with
    -- extensionality.

  | QF_BV
    -- ^ Closed quantifier-free formulas over the theory of fixed-size
    -- bitvectors.

  | QF_IDL
    -- ^ Difference Logic over the integers. In essence, Boolean
    -- combinations of inequations of the form x - y < b where x and y
    -- are integer variables and b is an integer constant.

  | QF_LIA
    -- ^ Unquantified linear integer arithmetic. In essence, Boolean
    -- combinations of inequations between linear polynomials over
    -- integer variables.

  | QF_LRA
    -- ^ Unquantified linear real arithmetic. In essence, Boolean
    -- combinations of inequations between linear polynomials over
    -- real variables.

  | QF_NIA
    -- ^ Quantifier-free integer arithmetic.

  | QF_NRA
    -- ^ Quantifier-free real arithmetic.

  | QF_RDL
    -- ^ Difference Logic over the reals. In essence, Boolean
    -- combinations of inequations of the form x - y < b where x and y
    -- are real variables and b is a rational constant.

  | QF_UF
    -- ^ Unquantified formulas built over a signature of uninterpreted
    -- (i.e., free) sort and function symbols.

  | QF_UFBV
    -- ^ Unquantified formulas over bitvectors with uninterpreted sort
    -- function and symbols.

  | QF_UFIDL
    -- ^ Difference Logic over the integers (in essence) but with
    -- uninterpreted sort and function symbols.

  | QF_UFLIA
    -- ^ Unquantified linear integer arithmetic with uninterpreted sort
    -- and function symbols.

  | QF_UFLRA
    -- ^ Unquantified linear real arithmetic with uninterpreted sort and
    -- function symbols.

  | QF_UFNRA
    -- ^ Unquantified non-linear real arithmetic with uninterpreted sort
    -- and function symbols.

  | UFLRA
    -- ^ Linear real arithmetic with uninterpreted sort and function
    -- symbols.

  | UFNIA
    -- ^ Non-linear integer arithmetic with uninterpreted sort and
    -- function symbols.

instance Show Logic where
  show :: Logic -> String
show Logic
AUFLIA    = String
"AUFLIA"
  show Logic
AUFLIRA   = String
"AUFLIRA"
  show Logic
AUFNIRA   = String
"AUFNIRA"
  show Logic
LRA       = String
"LRA"
  show Logic
QF_ABV    = String
"QF_ABV"
  show Logic
QF_AUFBV  = String
"QF_AUFBV"
  show Logic
QF_AUFLIA = String
"QF_AUFLIA"
  show Logic
QF_AX     = String
"QF_AX"
  show Logic
QF_BV     = String
"QF_BV"
  show Logic
QF_IDL    = String
"QF_IDL"
  show Logic
QF_LIA    = String
"QF_LIA"
  show Logic
QF_LRA    = String
"QF_LRA"
  show Logic
QF_NIA    = String
"QF_NIA"
  show Logic
QF_NRA    = String
"QF_NRA"
  show Logic
QF_RDL    = String
"QF_RDL"
  show Logic
QF_UF     = String
"QF_UF"
  show Logic
QF_UFBV   = String
"QF_UFBV"
  show Logic
QF_UFIDL  = String
"QF_UFIDL"
  show Logic
QF_UFLIA  = String
"QF_UFLIA"
  show Logic
QF_UFLRA  = String
"QF_UFLRA"
  show Logic
QF_UFNRA  = String
"QF_UFNRA"
  show Logic
UFLRA     = String
"UFLRA"
  show Logic
UFNIA     = String
"UFNIA"

mkSolver :: Context -> IO Solver
mkSolver :: Context -> IO Solver
mkSolver = (Ptr Z3_context -> IO (Ptr Z3_solver)) -> Context -> IO Solver
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_solver)
z3_mk_solver

mkSimpleSolver :: Context -> IO Solver
mkSimpleSolver :: Context -> IO Solver
mkSimpleSolver = (Ptr Z3_context -> IO (Ptr Z3_solver)) -> Context -> IO Solver
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_solver)
z3_mk_simple_solver

mkSolverForLogic :: Context -> Logic -> IO Solver
mkSolverForLogic :: Context -> Logic -> IO Solver
mkSolverForLogic Context
c Logic
logic = Context -> String -> IO Symbol
mkStringSymbol Context
c (Logic -> String
forall a. Show a => a -> String
show Logic
logic) IO Symbol -> (Symbol -> IO Solver) -> IO Solver
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Symbol
sym ->
  Context -> (Ptr Z3_context -> IO (Ptr Z3_solver)) -> IO Solver
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO (Ptr Z3_solver)) -> IO Solver)
-> (Ptr Z3_context -> IO (Ptr Z3_solver)) -> IO Solver
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> Ptr Z3_symbol -> IO (Ptr Z3_solver)
z3_mk_solver_for_logic Ptr Z3_context
cPtr (Ptr Z3_symbol -> IO (Ptr Z3_solver))
-> Ptr Z3_symbol -> IO (Ptr Z3_solver)
forall a b. (a -> b) -> a -> b
$ Symbol -> Ptr Z3_symbol
unSymbol Symbol
sym

-- | Return a string describing all solver available parameters.
solverGetHelp :: Context -> Solver -> IO String
solverGetHelp :: Context -> Solver -> IO String
solverGetHelp = (Ptr Z3_context -> Ptr Z3_solver -> IO Z3_string)
-> Context -> Solver -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO Z3_string
z3_solver_get_help

-- | Set the given solver using the given parameters.
solverSetParams :: Context -> Solver -> Params -> IO ()
solverSetParams :: Context -> Solver -> Params -> IO ()
solverSetParams = (Ptr Z3_context -> Ptr Z3_solver -> Ptr Z3_params -> IO ())
-> Context -> Solver -> Params -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_solver -> Ptr Z3_params -> IO ()
z3_solver_set_params

solverPush :: Context -> Solver -> IO ()
solverPush :: Context -> Solver -> IO ()
solverPush = (Ptr Z3_context -> Ptr Z3_solver -> IO ())
-> Context -> Solver -> IO ()
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO ()
z3_solver_push

solverPop :: Context -> Solver -> Int -> IO ()
solverPop :: Context -> Solver -> Int -> IO ()
solverPop = (Ptr Z3_context -> Ptr Z3_solver -> CUInt -> IO ())
-> Context -> Solver -> Int -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_solver -> CUInt -> IO ()
z3_solver_pop

solverReset :: Context -> Solver -> IO ()
solverReset :: Context -> Solver -> IO ()
solverReset = (Ptr Z3_context -> Ptr Z3_solver -> IO ())
-> Context -> Solver -> IO ()
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO ()
z3_solver_reset

-- | Number of backtracking points.
solverGetNumScopes :: Context -> Solver -> IO Int
solverGetNumScopes :: Context -> Solver -> IO Int
solverGetNumScopes = (Ptr Z3_context -> Ptr Z3_solver -> IO CUInt)
-> Context -> Solver -> IO Int
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO CUInt
z3_solver_get_num_scopes

solverAssertCnstr :: Context -> Solver -> AST -> IO ()
solverAssertCnstr :: Context -> Solver -> AST -> IO ()
solverAssertCnstr = (Ptr Z3_context -> Ptr Z3_solver -> Ptr Z3_ast -> IO ())
-> Context -> Solver -> AST -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_solver -> Ptr Z3_ast -> IO ()
z3_solver_assert

solverAssertAndTrack :: Context -> Solver -> AST -> AST -> IO ()
solverAssertAndTrack :: Context -> Solver -> AST -> AST -> IO ()
solverAssertAndTrack = (Ptr Z3_context
 -> Ptr Z3_solver -> Ptr Z3_ast -> Ptr Z3_ast -> IO ())
-> Context -> Solver -> AST -> AST -> IO ()
forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context
-> Ptr Z3_solver -> Ptr Z3_ast -> Ptr Z3_ast -> IO ()
z3_solver_assert_and_track

solverFromFile :: Context -> Solver -> String -> IO ()
solverFromFile :: Context -> Solver -> String -> IO ()
solverFromFile = (Ptr Z3_context -> Ptr Z3_solver -> Z3_string -> IO ())
-> Context -> Solver -> String -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_solver -> Z3_string -> IO ()
z3_solver_from_file

solverFromString :: Context -> Solver -> String -> IO ()
solverFromString :: Context -> Solver -> String -> IO ()
solverFromString = (Ptr Z3_context -> Ptr Z3_solver -> Z3_string -> IO ())
-> Context -> Solver -> String -> IO ()
forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> Ptr Z3_solver -> Z3_string -> IO ()
z3_solver_from_string

solverGetAssertions :: Context -> Solver -> IO [AST]
solverGetAssertions :: Context -> Solver -> IO [AST]
solverGetAssertions = (Ptr Z3_context -> Ptr Z3_solver -> IO (Ptr Z3_ast_vector))
-> Context -> Solver -> IO [AST]
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO (Ptr Z3_ast_vector)
z3_solver_get_assertions

-- | Check whether the assertions in a given solver are consistent or not.
solverCheck :: Context -> Solver -> IO Result
solverCheck :: Context -> Solver -> IO Result
solverCheck Context
ctx Solver
solver = (Ptr Z3_context -> Ptr Z3_solver -> IO Z3_lbool)
-> Context
-> ((Ptr Z3_solver -> IO Z3_lbool) -> IO Z3_lbool)
-> IO Result
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> Ptr Z3_solver -> IO Z3_lbool
z3_solver_check Context
ctx (((Ptr Z3_solver -> IO Z3_lbool) -> IO Z3_lbool) -> IO Result)
-> ((Ptr Z3_solver -> IO Z3_lbool) -> IO Z3_lbool) -> IO Result
forall a b. (a -> b) -> a -> b
$ Solver -> (Ptr Z3_solver -> IO Z3_lbool) -> IO Z3_lbool
forall r. Solver -> (Ptr Z3_solver -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Solver
solver

-- | Check whether the assertions in the given solver and optional assumptions are consistent or not.
solverCheckAssumptions :: Context -> Solver -> [AST] -> IO Result
solverCheckAssumptions :: Context -> Solver -> [AST] -> IO Result
solverCheckAssumptions Context
ctx Solver
solver [AST]
assump =
  (Ptr Z3_context
 -> Ptr Z3_solver -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool)
-> Context
-> ((Ptr Z3_solver -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool)
    -> IO Z3_lbool)
-> IO Result
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context
-> Ptr Z3_solver -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool
z3_solver_check_assumptions Context
ctx (((Ptr Z3_solver -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool)
  -> IO Z3_lbool)
 -> IO Result)
-> ((Ptr Z3_solver -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool)
    -> IO Z3_lbool)
-> IO Result
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_solver -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool
f ->
    Solver -> (Ptr Z3_solver -> IO Z3_lbool) -> IO Z3_lbool
forall r. Solver -> (Ptr Z3_solver -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Solver
solver ((Ptr Z3_solver -> IO Z3_lbool) -> IO Z3_lbool)
-> (Ptr Z3_solver -> IO Z3_lbool) -> IO Z3_lbool
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_solver
solverPtr ->
    [AST] -> (CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool) -> IO Z3_lbool
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
assump ((CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool) -> IO Z3_lbool)
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool) -> IO Z3_lbool
forall a b. (a -> b) -> a -> b
$ \CUInt
assumpNum Ptr (Ptr Z3_ast)
assumpArr ->
      Ptr Z3_solver -> CUInt -> Ptr (Ptr Z3_ast) -> IO Z3_lbool
f Ptr Z3_solver
solverPtr CUInt
assumpNum Ptr (Ptr Z3_ast)
assumpArr

-- | Retrieve the model for the last 'solverCheck'.
--
-- The error handler is invoked if a model is not available because
-- the commands above were not invoked for the given solver,
-- or if the result was 'Unsat'.
solverGetModel :: Context -> Solver -> IO Model
solverGetModel :: Context -> Solver -> IO Model
solverGetModel Context
ctx Solver
solver = (Ptr Z3_context -> Ptr Z3_solver -> IO (Ptr Z3_model))
-> Context
-> ((Ptr Z3_solver -> IO (Ptr Z3_model)) -> IO (Ptr Z3_model))
-> IO Model
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> Ptr Z3_solver -> IO (Ptr Z3_model)
z3_solver_get_model Context
ctx (((Ptr Z3_solver -> IO (Ptr Z3_model)) -> IO (Ptr Z3_model))
 -> IO Model)
-> ((Ptr Z3_solver -> IO (Ptr Z3_model)) -> IO (Ptr Z3_model))
-> IO Model
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_solver -> IO (Ptr Z3_model)
f ->
  Solver -> (Ptr Z3_solver -> IO (Ptr Z3_model)) -> IO (Ptr Z3_model)
forall r. Solver -> (Ptr Z3_solver -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c Solver
solver ((Ptr Z3_solver -> IO (Ptr Z3_model)) -> IO (Ptr Z3_model))
-> (Ptr Z3_solver -> IO (Ptr Z3_model)) -> IO (Ptr Z3_model)
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_solver
solverPtr ->
    Ptr Z3_solver -> IO (Ptr Z3_model)
f Ptr Z3_solver
solverPtr

-- | Retrieve the proof for the last 'solverCheck' or 'solverCheckAssumptions'.
--
-- The error handler is invoked if a proof is not available because
-- the commands above were not invoked for the given solver,
-- or if the result was different from 'Unsat' (so 'Sat' does not have a proof).
solverGetProof :: Context -> Solver -> IO AST
solverGetProof :: Context -> Solver -> IO AST
solverGetProof = (Ptr Z3_context -> Ptr Z3_solver -> IO (Ptr Z3_ast))
-> Context -> Solver -> IO AST
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO (Ptr Z3_ast)
z3_solver_get_proof

-- | Retrieve the unsat core for the last 'solverCheckAssumptions'; the unsat core is a subset of the assumptions
solverGetUnsatCore :: Context -> Solver -> IO [AST]
solverGetUnsatCore :: Context -> Solver -> IO [AST]
solverGetUnsatCore = (Ptr Z3_context -> Ptr Z3_solver -> IO (Ptr Z3_ast_vector))
-> Context -> Solver -> IO [AST]
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO (Ptr Z3_ast_vector)
z3_solver_get_unsat_core

-- | Return a brief justification for an 'Unknown' result for the commands 'solverCheck' and 'solverCheckAssumptions'.
solverGetReasonUnknown :: Context -> Solver -> IO String
solverGetReasonUnknown :: Context -> Solver -> IO String
solverGetReasonUnknown = (Ptr Z3_context -> Ptr Z3_solver -> IO Z3_string)
-> Context -> Solver -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO Z3_string
z3_solver_get_reason_unknown

-- | Convert the given solver into a string.
solverToString :: Context -> Solver -> IO String
solverToString :: Context -> Solver -> IO String
solverToString = (Ptr Z3_context -> Ptr Z3_solver -> IO Z3_string)
-> Context -> Solver -> IO String
forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> Ptr Z3_solver -> IO Z3_string
z3_solver_to_string

-------------------------------------------------
-- ** Helpers

-- | Call 'solverCheck' and based on the result also call 'solverGetModel'.
solverCheckAndGetModel :: Context -> Solver -> IO (Result, Maybe Model)
solverCheckAndGetModel :: Context -> Solver -> IO (Result, Maybe Model)
solverCheckAndGetModel Context
ctx Solver
solver =
  do Result
res <- Context -> Solver -> IO Result
solverCheck Context
ctx Solver
solver
     Maybe Model
mbModel <- case Result
res of
                  Result
Unsat -> Maybe Model -> IO (Maybe Model)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Model
forall a. Maybe a
Nothing
                  Result
_     -> Model -> Maybe Model
forall a. a -> Maybe a
Just (Model -> Maybe Model) -> IO Model -> IO (Maybe Model)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context -> Solver -> IO Model
solverGetModel Context
ctx Solver
solver
     (Result, Maybe Model) -> IO (Result, Maybe Model)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result
res, Maybe Model
mbModel)

---------------------------------------------------------------------
-- Marshalling

{- MARSHALLING HELPERS

We try to get rid of most of the marshalling boilerplate which, by the way,
is going to be essential for transitioning to Z3 4 API.

Most API functions can be lifted using 'liftFun'{0-3} helpers. Otherwise try
using 'marshal'. Worst case scenario, write the marshalling code yourself.

-}

-- withIntegral :: (Integral a, Integral b) => a -> (b -> r) -> r
-- withIntegral x f = f (fromIntegral x)

withContext :: Context -> (Ptr Z3_context -> IO r) -> IO r
withContext :: forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContext Context
c Ptr Z3_context -> IO r
f = RLock -> IO r -> IO r
forall a. RLock -> IO a -> IO a
Z3.RLock.with (Context -> RLock
lock Context
c) (IO r -> IO r) -> IO r -> IO r
forall a b. (a -> b) -> a -> b
$ ForeignPtr Z3_context -> (Ptr Z3_context -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Context -> ForeignPtr Z3_context
unContext Context
c) Ptr Z3_context -> IO r
f

withContextError :: Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError :: forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContextError Context
c Ptr Z3_context -> IO r
f = Context -> (Ptr Z3_context -> IO r) -> IO r
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContext Context
c ((Ptr Z3_context -> IO r) -> IO r)
-> (Ptr Z3_context -> IO r) -> IO r
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> IO r -> IO r
forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
cPtr (Ptr Z3_context -> IO r
f Ptr Z3_context
cPtr)

marshalArray :: (Marshal h c, Storable c) => [h] -> (Ptr c -> IO a) -> IO a
marshalArray :: forall h c a.
(Marshal h c, Storable c) =>
[h] -> (Ptr c -> IO a) -> IO a
marshalArray [h]
hs Ptr c -> IO a
f = [h] -> ([c] -> IO a) -> IO a
forall h c r. Marshal h c => [h] -> ([c] -> IO r) -> IO r
hs2cs [h]
hs (([c] -> IO a) -> IO a) -> ([c] -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \[c]
cs -> [c] -> (Ptr c -> IO a) -> IO a
forall a b. Storable a => [a] -> (Ptr a -> IO b) -> IO b
withArray [c]
cs Ptr c -> IO a
f

marshalArrayLen :: (Marshal h c, Storable c, Integral i) =>
    [h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen :: forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [h]
hs i -> Ptr c -> IO a
f =
  [h] -> ([c] -> IO a) -> IO a
forall h c r. Marshal h c => [h] -> ([c] -> IO r) -> IO r
hs2cs [h]
hs (([c] -> IO a) -> IO a) -> ([c] -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \[c]
cs -> [c] -> (Int -> Ptr c -> IO a) -> IO a
forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
withArrayLen [c]
cs ((Int -> Ptr c -> IO a) -> IO a) -> (Int -> Ptr c -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \Int
n -> i -> Ptr c -> IO a
f (Int -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)

-- marshalMaybeArray :: (Marshal h c, Storable c) => Maybe [h] -> (Ptr c -> IO a) -> IO a
-- marshalMaybeArray Nothing   f = f nullPtr
-- marshalMaybeArray (Just hs) f = marshalArray hs f

liftAstN_err :: String
            -> (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
            -> Context -> [AST] -> IO AST
liftAstN_err :: String
-> (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> [AST]
-> IO AST
liftAstN_err String
s Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
_ Context
_ [] = String -> IO AST
forall a. HasCallStack => String -> a
error String
s
liftAstN_err String
_ Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Context
c [AST]
es = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Context
c (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall a b. (a -> b) -> a -> b
$ [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen [AST]
es
{-# INLINE liftAstN_err #-}

liftAstN :: (Ptr Z3_context -> IO (Ptr Z3_ast))
         -> (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
         -> Context -> [AST] -> IO AST
liftAstN :: (Ptr Z3_context -> IO (Ptr Z3_ast))
-> (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> [AST]
-> IO AST
liftAstN Ptr Z3_context -> IO (Ptr Z3_ast)
s Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Context
c = IO AST
-> (NonEmpty AST -> IO AST) -> Maybe (NonEmpty AST) -> IO AST
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((Ptr Z3_context -> IO (Ptr Z3_ast)) -> Context -> IO AST
forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 Ptr Z3_context -> IO (Ptr Z3_ast)
s Context
c) ((Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context -> NonEmpty AST -> IO AST
liftAstN1 Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Context
c) (Maybe (NonEmpty AST) -> IO AST)
-> ([AST] -> Maybe (NonEmpty AST)) -> [AST] -> IO AST
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [AST] -> Maybe (NonEmpty AST)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty
{-# INLINE liftAstN #-}

liftAstN1 :: (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
          -> Context -> NonEmpty AST -> IO AST
liftAstN1 :: (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context -> NonEmpty AST -> IO AST
liftAstN1 Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Context
c = (Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> Context
-> ((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> IO AST
forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast)
f Context
c (((CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
  -> IO (Ptr Z3_ast))
 -> IO AST)
-> (NonEmpty AST
    -> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
    -> IO (Ptr Z3_ast))
-> NonEmpty AST
-> IO AST
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [AST]
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall h c i a.
(Marshal h c, Storable c, Integral i) =>
[h] -> (i -> Ptr c -> IO a) -> IO a
marshalArrayLen ([AST]
 -> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
 -> IO (Ptr Z3_ast))
-> (NonEmpty AST -> [AST])
-> NonEmpty AST
-> (CUInt -> Ptr (Ptr Z3_ast) -> IO (Ptr Z3_ast))
-> IO (Ptr Z3_ast)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty AST -> [AST]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
{-# INLINE liftAstN1 #-}

class Marshal h c where
  c2h :: Context -> c -> IO h
  h2c :: h -> (c -> IO r) -> IO r

hs2cs :: Marshal h c => [h] -> ([c] -> IO r) -> IO r
hs2cs :: forall h c r. Marshal h c => [h] -> ([c] -> IO r) -> IO r
hs2cs []     [c] -> IO r
f = [c] -> IO r
f []
hs2cs (h
h:[h]
hs) [c] -> IO r
f =
  h -> (c -> IO r) -> IO r
forall r. h -> (c -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c h
h ((c -> IO r) -> IO r) -> (c -> IO r) -> IO r
forall a b. (a -> b) -> a -> b
$ \c
c ->
  [h] -> ([c] -> IO r) -> IO r
forall h c r. Marshal h c => [h] -> ([c] -> IO r) -> IO r
hs2cs [h]
hs (([c] -> IO r) -> IO r) -> ([c] -> IO r) -> IO r
forall a b. (a -> b) -> a -> b
$ \[c]
cs -> [c] -> IO r
f (c
cc -> [c] -> [c]
forall a. a -> [a] -> [a]
:[c]
cs)

cs2hs :: Marshal h c => Context -> [c] -> IO [h]
cs2hs :: forall h c. Marshal h c => Context -> [c] -> IO [h]
cs2hs Context
ctx = (c -> IO h) -> [c] -> IO [h]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Context -> c -> IO h
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx)

-- peekToHs :: (Marshal h c, Storable c) => Context -> Ptr c -> IO h
-- peekToHs c ptr = c2h c =<< peek ptr

-- peekToMaybeHs :: (Marshal h (Ptr c), Storable c) => Context -> Ptr (Ptr c) -> IO (Maybe h)
-- peekToMaybeHs c = peek >=> (c2h c `T.traverse`) . ptrToMaybe

peekArrayToHs :: (Marshal h c, Storable c) => Context -> Int -> Ptr c -> IO [h]
peekArrayToHs :: forall h c.
(Marshal h c, Storable c) =>
Context -> Int -> Ptr c -> IO [h]
peekArrayToHs Context
c Int
n Ptr c
dPtr =
  Context -> [c] -> IO [h]
forall h c. Marshal h c => Context -> [c] -> IO [h]
cs2hs Context
c ([c] -> IO [h]) -> IO [c] -> IO [h]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int -> Ptr c -> IO [c]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
n Ptr c
dPtr

-- peekPtrArrayToHs :: (Marshal h c, Storable c) => Context -> Int -> Ptr (Ptr c) -> IO [h]
-- peekPtrArrayToHs c n = peekArray n >=> mapM (peekToHs c)

toHsCheckError :: Marshal h c => Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError :: forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c Ptr Z3_context -> IO c
f = Context -> (Ptr Z3_context -> IO h) -> IO h
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContext Context
c ((Ptr Z3_context -> IO h) -> IO h)
-> (Ptr Z3_context -> IO h) -> IO h
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr ->
  Context -> c -> IO h
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
c (c -> IO h) -> IO c -> IO h
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Z3_context -> IO c -> IO c
forall a. Ptr Z3_context -> IO a -> IO a
checkError Ptr Z3_context
cPtr (Ptr Z3_context -> IO c
f Ptr Z3_context
cPtr)

type Z3SetRefCount c = Ptr Z3_context -> Ptr c -> IO ()
type Z3IncRefFun c = Z3SetRefCount c
type Z3DecRefFun c = Z3SetRefCount c

mkC2hRefCount :: (ForeignPtr c -> h)
                   -> Z3IncRefFun c
                   -> Z3DecRefFun c
                   -> Context -> Ptr c -> IO h
mkC2hRefCount :: forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr c -> h
mk Z3IncRefFun c
incRef Z3IncRefFun c
decRef Context
ctx Ptr c
xPtr =
  Context -> (Ptr Z3_context -> IO h) -> IO h
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContext Context
ctx ((Ptr Z3_context -> IO h) -> IO h)
-> (Ptr Z3_context -> IO h) -> IO h
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
ctxPtr -> do
    Z3IncRefFun c
incRef Ptr Z3_context
ctxPtr Ptr c
xPtr
    Context -> IO ()
contextIncRef Context
ctx
    let xFinalizer :: IO ()
xFinalizer = RLock -> IO () -> IO ()
forall a. RLock -> IO a -> IO a
Z3.RLock.with (Context -> RLock
lock Context
ctx) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ (do Z3IncRefFun c
decRef Ptr Z3_context
ctxPtr Ptr c
xPtr
                                                    Ptr Z3_context -> IORef Word -> IO ()
contextDecRef Ptr Z3_context
ctxPtr (Context -> IORef Word
refCount Context
ctx))
    ForeignPtr c -> h
mk (ForeignPtr c -> h) -> IO (ForeignPtr c) -> IO h
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr c -> IO () -> IO (ForeignPtr c)
forall a. Ptr a -> IO () -> IO (ForeignPtr a)
newForeignPtr Ptr c
xPtr IO ()
xFinalizer

dummy_inc_ref :: Z3IncRefFun c
dummy_inc_ref :: forall c. Z3IncRefFun c
dummy_inc_ref Ptr Z3_context
_ Ptr c
_ = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

on_ast_ptr :: Z3SetRefCount Z3_ast
            -> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast))
            -> Z3SetRefCount a
Z3SetRefCount Z3_ast
f on_ast_ptr :: forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)
t = \Ptr Z3_context
ctxPtr Ptr a
ptr -> Z3SetRefCount Z3_ast
f Ptr Z3_context
ctxPtr (Ptr Z3_ast -> IO ()) -> IO (Ptr Z3_ast) -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)
t Ptr Z3_context
ctxPtr Ptr a
ptr

instance Marshal h (Ptr x) => Marshal (Maybe h) (Ptr x) where
  c2h :: Context -> Ptr x -> IO (Maybe h)
c2h Context
c = (Ptr x -> IO h) -> Maybe (Ptr x) -> IO (Maybe h)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Maybe a -> m (Maybe b)
T.mapM (Context -> Ptr x -> IO h
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
c) (Maybe (Ptr x) -> IO (Maybe h))
-> (Ptr x -> Maybe (Ptr x)) -> Ptr x -> IO (Maybe h)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr x -> Maybe (Ptr x)
forall a. Ptr a -> Maybe (Ptr a)
ptrToMaybe
  h2c :: forall r. Maybe h -> (Ptr x -> IO r) -> IO r
h2c Maybe h
Nothing  Ptr x -> IO r
f = Ptr x -> IO r
f Ptr x
forall a. Ptr a
nullPtr
  h2c (Just h
x) Ptr x -> IO r
f = h -> (Ptr x -> IO r) -> IO r
forall r. h -> (Ptr x -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c h
x Ptr x -> IO r
f

instance Marshal () () where
  c2h :: Context -> () -> IO ()
c2h Context
_ = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
  h2c :: forall r. () -> (() -> IO r) -> IO r
h2c ()
x () -> IO r
f = () -> IO r
f ()
x

instance Marshal Bool Z3_bool where
  c2h :: Context -> Z3_bool -> IO Bool
c2h Context
_ = Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IO Bool) -> (Z3_bool -> Bool) -> Z3_bool -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z3_bool -> Bool
toBool
  h2c :: forall r. Bool -> (Z3_bool -> IO r) -> IO r
h2c Bool
b Z3_bool -> IO r
f = Z3_bool -> IO r
f (Bool -> Z3_bool
unBool Bool
b)

instance Marshal Result Z3_lbool where
  c2h :: Context -> Z3_lbool -> IO Result
c2h Context
_ = Result -> IO Result
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result -> IO Result)
-> (Z3_lbool -> Result) -> Z3_lbool -> IO Result
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z3_lbool -> Result
toResult
  h2c :: forall r. Result -> (Z3_lbool -> IO r) -> IO r
h2c = String -> Result -> (Z3_lbool -> IO r) -> IO r
forall a. HasCallStack => String -> a
error String
"Marshal Result Z3_lbool => h2c not implemented"

instance Integral h => Marshal h CInt where
  c2h :: Context -> Z3_error_code -> IO h
c2h Context
_ = h -> IO h
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (h -> IO h) -> (Z3_error_code -> h) -> Z3_error_code -> IO h
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z3_error_code -> h
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  h2c :: forall r. h -> (Z3_error_code -> IO r) -> IO r
h2c h
i Z3_error_code -> IO r
f = Z3_error_code -> IO r
f (h -> Z3_error_code
forall a b. (Integral a, Num b) => a -> b
fromIntegral h
i)

instance Integral h => Marshal h CUInt where
  c2h :: Context -> CUInt -> IO h
c2h Context
_ = h -> IO h
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (h -> IO h) -> (CUInt -> h) -> CUInt -> IO h
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> h
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  h2c :: forall r. h -> (CUInt -> IO r) -> IO r
h2c h
i CUInt -> IO r
f = CUInt -> IO r
f (h -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral h
i)

instance Integral h => Marshal h CLong where
  c2h :: Context -> CLong -> IO h
c2h Context
_ = h -> IO h
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (h -> IO h) -> (CLong -> h) -> CLong -> IO h
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CLong -> h
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  h2c :: forall r. h -> (CLong -> IO r) -> IO r
h2c h
i CLong -> IO r
f = CLong -> IO r
f (h -> CLong
forall a b. (Integral a, Num b) => a -> b
fromIntegral h
i)

instance Integral h => Marshal h CULong where
  c2h :: Context -> CULong -> IO h
c2h Context
_ = h -> IO h
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (h -> IO h) -> (CULong -> h) -> CULong -> IO h
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CULong -> h
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  h2c :: forall r. h -> (CULong -> IO r) -> IO r
h2c h
i CULong -> IO r
f = CULong -> IO r
f (h -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral h
i)

instance Integral h => Marshal h CLLong where
  c2h :: Context -> CLLong -> IO h
c2h Context
_ = h -> IO h
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (h -> IO h) -> (CLLong -> h) -> CLLong -> IO h
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CLLong -> h
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  h2c :: forall r. h -> (CLLong -> IO r) -> IO r
h2c h
i CLLong -> IO r
f = CLLong -> IO r
f (h -> CLLong
forall a b. (Integral a, Num b) => a -> b
fromIntegral h
i)

instance Integral h => Marshal h CULLong where
  c2h :: Context -> CULLong -> IO h
c2h Context
_ = h -> IO h
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (h -> IO h) -> (CULLong -> h) -> CULLong -> IO h
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CULLong -> h
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  h2c :: forall r. h -> (CULLong -> IO r) -> IO r
h2c h
i CULLong -> IO r
f = CULLong -> IO r
f (h -> CULLong
forall a b. (Integral a, Num b) => a -> b
fromIntegral h
i)

instance Marshal Float CFloat where
  c2h :: Context -> CFloat -> IO Float
c2h Context
_ = Float -> IO Float
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Float -> IO Float) -> (CFloat -> Float) -> CFloat -> IO Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CFloat -> Float
forall a b. (Real a, Fractional b) => a -> b
realToFrac
  h2c :: forall r. Float -> (CFloat -> IO r) -> IO r
h2c Float
d CFloat -> IO r
f = CFloat -> IO r
f (Float -> CFloat
forall a b. (Real a, Fractional b) => a -> b
realToFrac Float
d)

instance Marshal Double CDouble where
  c2h :: Context -> CDouble -> IO Double
c2h Context
_ = Double -> IO Double
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> IO Double)
-> (CDouble -> Double) -> CDouble -> IO Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac
  h2c :: forall r. Double -> (CDouble -> IO r) -> IO r
h2c Double
d CDouble -> IO r
f = CDouble -> IO r
f (Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
d)

instance Marshal String CString where
  c2h :: Context -> Z3_string -> IO String
c2h Context
_ = Z3_string -> IO String
peekCString
  h2c :: forall a. String -> (Z3_string -> IO a) -> IO a
h2c   = String -> (Z3_string -> IO r) -> IO r
forall a. String -> (Z3_string -> IO a) -> IO a
withCString

instance Marshal Context (Ptr Z3_context) where
  c2h :: Context -> Ptr Z3_context -> IO Context
c2h Context
_ Ptr Z3_context
ctx = (Config -> IO Context) -> IO Context
forall a. (Config -> IO a) -> IO a
withConfig ((Config -> IO Context) -> IO Context)
-> (Config -> IO Context) -> IO Context
forall a b. (a -> b) -> a -> b
$ (Ptr Z3_config -> IO (Ptr Z3_context)) -> Config -> IO Context
mkContextWith (IO (Ptr Z3_context) -> Ptr Z3_config -> IO (Ptr Z3_context)
forall a b. a -> b -> a
const (Ptr Z3_context -> IO (Ptr Z3_context)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Z3_context
ctx))
  h2c :: forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
h2c Context
ctx = ForeignPtr Z3_context -> (Ptr Z3_context -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Context -> ForeignPtr Z3_context
unContext Context
ctx)

instance Marshal App (Ptr Z3_app) where
  c2h :: Context -> Ptr Z3_app -> IO App
c2h = (ForeignPtr Z3_app -> App)
-> Z3IncRefFun Z3_app
-> Z3IncRefFun Z3_app
-> Context
-> Ptr Z3_app
-> IO App
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_app -> App
App
            (Z3SetRefCount Z3_ast
z3_inc_ref Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr Z3_app -> IO (Ptr Z3_ast))
-> Z3IncRefFun Z3_app
forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr Z3_app -> IO (Ptr Z3_ast)
z3_app_to_ast)
            (Z3SetRefCount Z3_ast
z3_dec_ref Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr Z3_app -> IO (Ptr Z3_ast))
-> Z3IncRefFun Z3_app
forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr Z3_app -> IO (Ptr Z3_ast)
z3_app_to_ast)
  h2c :: forall r. App -> (Ptr Z3_app -> IO r) -> IO r
h2c App
app = ForeignPtr Z3_app -> (Ptr Z3_app -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (App -> ForeignPtr Z3_app
unApp App
app)

instance Marshal Params (Ptr Z3_params) where
  c2h :: Context -> Ptr Z3_params -> IO Params
c2h = (ForeignPtr Z3_params -> Params)
-> Z3IncRefFun Z3_params
-> Z3IncRefFun Z3_params
-> Context
-> Ptr Z3_params
-> IO Params
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_params -> Params
Params Z3IncRefFun Z3_params
z3_params_inc_ref Z3IncRefFun Z3_params
z3_params_dec_ref
  h2c :: forall r. Params -> (Ptr Z3_params -> IO r) -> IO r
h2c Params
prm = ForeignPtr Z3_params -> (Ptr Z3_params -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Params -> ForeignPtr Z3_params
unParams Params
prm)

instance Marshal Symbol (Ptr Z3_symbol) where
  c2h :: Context -> Ptr Z3_symbol -> IO Symbol
c2h Context
_ = Symbol -> IO Symbol
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Symbol -> IO Symbol)
-> (Ptr Z3_symbol -> Symbol) -> Ptr Z3_symbol -> IO Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr Z3_symbol -> Symbol
Symbol
  h2c :: forall r. Symbol -> (Ptr Z3_symbol -> IO r) -> IO r
h2c Symbol
s Ptr Z3_symbol -> IO r
f = Ptr Z3_symbol -> IO r
f (Symbol -> Ptr Z3_symbol
unSymbol Symbol
s)

instance Marshal AST (Ptr Z3_ast) where
  c2h :: Context -> Ptr Z3_ast -> IO AST
c2h = (ForeignPtr Z3_ast -> AST)
-> Z3SetRefCount Z3_ast
-> Z3SetRefCount Z3_ast
-> Context
-> Ptr Z3_ast
-> IO AST
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_ast -> AST
AST Z3SetRefCount Z3_ast
z3_inc_ref Z3SetRefCount Z3_ast
z3_dec_ref
  h2c :: forall r. AST -> (Ptr Z3_ast -> IO r) -> IO r
h2c AST
a Ptr Z3_ast -> IO r
f = ForeignPtr Z3_ast -> (Ptr Z3_ast -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (AST -> ForeignPtr Z3_ast
unAST AST
a) Ptr Z3_ast -> IO r
f

instance Marshal [AST] (Ptr Z3_ast_vector) where
  c2h :: Context -> Ptr Z3_ast_vector -> IO [AST]
c2h Context
ctx Ptr Z3_ast_vector
vecPtr = Context -> (Ptr Z3_context -> IO [AST]) -> IO [AST]
forall r. Context -> (Ptr Z3_context -> IO r) -> IO r
withContext Context
ctx ((Ptr Z3_context -> IO [AST]) -> IO [AST])
-> (Ptr Z3_context -> IO [AST]) -> IO [AST]
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
ctxPtr -> do
    Ptr Z3_context -> Ptr Z3_ast_vector -> IO ()
z3_ast_vector_inc_ref Ptr Z3_context
ctxPtr Ptr Z3_ast_vector
vecPtr
    CUInt
n <- Ptr Z3_context -> Ptr Z3_ast_vector -> IO CUInt
z3_ast_vector_size Ptr Z3_context
ctxPtr Ptr Z3_ast_vector
vecPtr
    [AST]
res <- if CUInt
n CUInt -> CUInt -> Bool
forall a. Eq a => a -> a -> Bool
== CUInt
0 -- Need an explicit check, since n is unsigned so n - 1 might overflow
              then [AST] -> IO [AST]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
              else (CUInt -> IO AST) -> [CUInt] -> IO [AST]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\CUInt
i -> Ptr Z3_context -> Ptr Z3_ast_vector -> CUInt -> IO (Ptr Z3_ast)
z3_ast_vector_get Ptr Z3_context
ctxPtr Ptr Z3_ast_vector
vecPtr CUInt
i IO (Ptr Z3_ast) -> (Ptr Z3_ast -> IO AST) -> IO AST
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Context -> Ptr Z3_ast -> IO AST
forall h c. Marshal h c => Context -> c -> IO h
c2h Context
ctx) [CUInt
0 .. (CUInt
n CUInt -> CUInt -> CUInt
forall a. Num a => a -> a -> a
- CUInt
1)]
    Ptr Z3_context -> Ptr Z3_ast_vector -> IO ()
z3_ast_vector_dec_ref Ptr Z3_context
ctxPtr Ptr Z3_ast_vector
vecPtr
    [AST] -> IO [AST]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return [AST]
res
  h2c :: forall r. [AST] -> (Ptr Z3_ast_vector -> IO r) -> IO r
h2c [AST]
_ Ptr Z3_ast_vector -> IO r
_ = String -> IO r
forall a. HasCallStack => String -> a
error String
"Marshal [AST] (Ptr Z3_ast_vector) => h2c not implemented"

instance Marshal Sort (Ptr Z3_sort) where
  c2h :: Context -> Ptr Z3_sort -> IO Sort
c2h = (ForeignPtr Z3_sort -> Sort)
-> Z3IncRefFun Z3_sort
-> Z3IncRefFun Z3_sort
-> Context
-> Ptr Z3_sort
-> IO Sort
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_sort -> Sort
Sort
            (Z3SetRefCount Z3_ast
z3_inc_ref Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Z3IncRefFun Z3_sort
forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_sort_to_ast)
            (Z3SetRefCount Z3_ast
z3_dec_ref Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast))
-> Z3IncRefFun Z3_sort
forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr Z3_sort -> IO (Ptr Z3_ast)
z3_sort_to_ast)
  h2c :: forall r. Sort -> (Ptr Z3_sort -> IO r) -> IO r
h2c Sort
srt = ForeignPtr Z3_sort -> (Ptr Z3_sort -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Sort -> ForeignPtr Z3_sort
unSort Sort
srt)

instance Marshal FuncDecl (Ptr Z3_func_decl) where
  c2h :: Context -> Ptr Z3_func_decl -> IO FuncDecl
c2h = (ForeignPtr Z3_func_decl -> FuncDecl)
-> Z3IncRefFun Z3_func_decl
-> Z3IncRefFun Z3_func_decl
-> Context
-> Ptr Z3_func_decl
-> IO FuncDecl
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_func_decl -> FuncDecl
FuncDecl
            (Z3SetRefCount Z3_ast
z3_inc_ref Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr Z3_func_decl -> IO (Ptr Z3_ast))
-> Z3IncRefFun Z3_func_decl
forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr Z3_func_decl -> IO (Ptr Z3_ast)
z3_func_decl_to_ast)
            (Z3SetRefCount Z3_ast
z3_dec_ref Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr Z3_func_decl -> IO (Ptr Z3_ast))
-> Z3IncRefFun Z3_func_decl
forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr Z3_func_decl -> IO (Ptr Z3_ast)
z3_func_decl_to_ast)
  h2c :: forall r. FuncDecl -> (Ptr Z3_func_decl -> IO r) -> IO r
h2c FuncDecl
fnd = ForeignPtr Z3_func_decl -> (Ptr Z3_func_decl -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (FuncDecl -> ForeignPtr Z3_func_decl
unFuncDecl FuncDecl
fnd)

instance Marshal FuncEntry (Ptr Z3_func_entry) where
  c2h :: Context -> Ptr Z3_func_entry -> IO FuncEntry
c2h = (ForeignPtr Z3_func_entry -> FuncEntry)
-> Z3IncRefFun Z3_func_entry
-> Z3IncRefFun Z3_func_entry
-> Context
-> Ptr Z3_func_entry
-> IO FuncEntry
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_func_entry -> FuncEntry
FuncEntry Z3IncRefFun Z3_func_entry
z3_func_entry_inc_ref
                                Z3IncRefFun Z3_func_entry
z3_func_entry_dec_ref
  h2c :: forall r. FuncEntry -> (Ptr Z3_func_entry -> IO r) -> IO r
h2c FuncEntry
fne = ForeignPtr Z3_func_entry -> (Ptr Z3_func_entry -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (FuncEntry -> ForeignPtr Z3_func_entry
unFuncEntry FuncEntry
fne)

instance Marshal FuncInterp (Ptr Z3_func_interp) where
  c2h :: Context -> Ptr Z3_func_interp -> IO FuncInterp
c2h = (ForeignPtr Z3_func_interp -> FuncInterp)
-> Z3IncRefFun Z3_func_interp
-> Z3IncRefFun Z3_func_interp
-> Context
-> Ptr Z3_func_interp
-> IO FuncInterp
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_func_interp -> FuncInterp
FuncInterp Z3IncRefFun Z3_func_interp
z3_func_interp_inc_ref
                                 Z3IncRefFun Z3_func_interp
z3_func_interp_dec_ref
  h2c :: forall r. FuncInterp -> (Ptr Z3_func_interp -> IO r) -> IO r
h2c FuncInterp
fni = ForeignPtr Z3_func_interp -> (Ptr Z3_func_interp -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (FuncInterp -> ForeignPtr Z3_func_interp
unFuncInterp FuncInterp
fni)

instance Marshal Model (Ptr Z3_model) where
  c2h :: Context -> Ptr Z3_model -> IO Model
c2h = (ForeignPtr Z3_model -> Model)
-> Z3IncRefFun Z3_model
-> Z3IncRefFun Z3_model
-> Context
-> Ptr Z3_model
-> IO Model
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_model -> Model
Model Z3IncRefFun Z3_model
z3_model_inc_ref Z3IncRefFun Z3_model
z3_model_dec_ref
  h2c :: forall r. Model -> (Ptr Z3_model -> IO r) -> IO r
h2c Model
m = ForeignPtr Z3_model -> (Ptr Z3_model -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Model -> ForeignPtr Z3_model
unModel Model
m)

instance Marshal Pattern (Ptr Z3_pattern) where
  c2h :: Context -> Ptr Z3_pattern -> IO Pattern
c2h = (ForeignPtr Z3_pattern -> Pattern)
-> Z3IncRefFun Z3_pattern
-> Z3IncRefFun Z3_pattern
-> Context
-> Ptr Z3_pattern
-> IO Pattern
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_pattern -> Pattern
Pattern
            (Z3SetRefCount Z3_ast
z3_inc_ref Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr Z3_pattern -> IO (Ptr Z3_ast))
-> Z3IncRefFun Z3_pattern
forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr Z3_pattern -> IO (Ptr Z3_ast)
z3_pattern_to_ast)
            (Z3SetRefCount Z3_ast
z3_dec_ref Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr Z3_pattern -> IO (Ptr Z3_ast))
-> Z3IncRefFun Z3_pattern
forall a.
Z3SetRefCount Z3_ast
-> (Ptr Z3_context -> Ptr a -> IO (Ptr Z3_ast)) -> Z3SetRefCount a
`on_ast_ptr` Ptr Z3_context -> Ptr Z3_pattern -> IO (Ptr Z3_ast)
z3_pattern_to_ast)
  h2c :: forall r. Pattern -> (Ptr Z3_pattern -> IO r) -> IO r
h2c Pattern
pat = ForeignPtr Z3_pattern -> (Ptr Z3_pattern -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Pattern -> ForeignPtr Z3_pattern
unPattern Pattern
pat)

instance Marshal Constructor (Ptr Z3_constructor) where
  c2h :: Context -> Ptr Z3_constructor -> IO Constructor
c2h = (ForeignPtr Z3_constructor -> Constructor)
-> Z3IncRefFun Z3_constructor
-> Z3IncRefFun Z3_constructor
-> Context
-> Ptr Z3_constructor
-> IO Constructor
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_constructor -> Constructor
Constructor Z3IncRefFun Z3_constructor
forall c. Z3IncRefFun c
dummy_inc_ref Z3IncRefFun Z3_constructor
z3_del_constructor
  h2c :: forall r. Constructor -> (Ptr Z3_constructor -> IO r) -> IO r
h2c Constructor
cns = ForeignPtr Z3_constructor -> (Ptr Z3_constructor -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Constructor -> ForeignPtr Z3_constructor
unConstructor Constructor
cns)

instance Marshal ConstructorList (Ptr Z3_constructor_list) where
  c2h :: Context -> Ptr Z3_constructor_list -> IO ConstructorList
c2h = (ForeignPtr Z3_constructor_list -> ConstructorList)
-> Z3IncRefFun Z3_constructor_list
-> Z3IncRefFun Z3_constructor_list
-> Context
-> Ptr Z3_constructor_list
-> IO ConstructorList
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_constructor_list -> ConstructorList
ConstructorList Z3IncRefFun Z3_constructor_list
forall c. Z3IncRefFun c
dummy_inc_ref Z3IncRefFun Z3_constructor_list
z3_del_constructor_list
  h2c :: forall r.
ConstructorList -> (Ptr Z3_constructor_list -> IO r) -> IO r
h2c ConstructorList
cl = ForeignPtr Z3_constructor_list
-> (Ptr Z3_constructor_list -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (ConstructorList -> ForeignPtr Z3_constructor_list
unConstructorList ConstructorList
cl)

instance Marshal Solver (Ptr Z3_solver) where
  c2h :: Context -> Ptr Z3_solver -> IO Solver
c2h = (ForeignPtr Z3_solver -> Solver)
-> (Ptr Z3_context -> Ptr Z3_solver -> IO ())
-> (Ptr Z3_context -> Ptr Z3_solver -> IO ())
-> Context
-> Ptr Z3_solver
-> IO Solver
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_solver -> Solver
Solver Ptr Z3_context -> Ptr Z3_solver -> IO ()
z3_solver_inc_ref Ptr Z3_context -> Ptr Z3_solver -> IO ()
z3_solver_dec_ref
  h2c :: forall r. Solver -> (Ptr Z3_solver -> IO r) -> IO r
h2c Solver
slv = ForeignPtr Z3_solver -> (Ptr Z3_solver -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Solver -> ForeignPtr Z3_solver
unSolver Solver
slv)

instance Marshal Tactic (Ptr Z3_tactic) where
  c2h :: Context -> Ptr Z3_tactic -> IO Tactic
c2h = (ForeignPtr Z3_tactic -> Tactic)
-> Z3IncRefFun Z3_tactic
-> Z3IncRefFun Z3_tactic
-> Context
-> Ptr Z3_tactic
-> IO Tactic
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_tactic -> Tactic
Tactic Z3IncRefFun Z3_tactic
z3_tactic_inc_ref Z3IncRefFun Z3_tactic
z3_tactic_dec_ref
  h2c :: forall r. Tactic -> (Ptr Z3_tactic -> IO r) -> IO r
h2c Tactic
tac = ForeignPtr Z3_tactic -> (Ptr Z3_tactic -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Tactic -> ForeignPtr Z3_tactic
unTactic Tactic
tac)

instance Marshal ApplyResult (Ptr Z3_apply_result) where
  c2h :: Context -> Ptr Z3_apply_result -> IO ApplyResult
c2h = (ForeignPtr Z3_apply_result -> ApplyResult)
-> Z3IncRefFun Z3_apply_result
-> Z3IncRefFun Z3_apply_result
-> Context
-> Ptr Z3_apply_result
-> IO ApplyResult
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_apply_result -> ApplyResult
ApplyResult Z3IncRefFun Z3_apply_result
z3_apply_result_inc_ref Z3IncRefFun Z3_apply_result
z3_apply_result_dec_ref
  h2c :: forall r. ApplyResult -> (Ptr Z3_apply_result -> IO r) -> IO r
h2c ApplyResult
apl = ForeignPtr Z3_apply_result -> (Ptr Z3_apply_result -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (ApplyResult -> ForeignPtr Z3_apply_result
unApplyResult ApplyResult
apl)

instance Marshal Goal (Ptr Z3_goal) where
  c2h :: Context -> Ptr Z3_goal -> IO Goal
c2h = (ForeignPtr Z3_goal -> Goal)
-> Z3IncRefFun Z3_goal
-> Z3IncRefFun Z3_goal
-> Context
-> Ptr Z3_goal
-> IO Goal
forall c h.
(ForeignPtr c -> h)
-> Z3IncRefFun c -> Z3IncRefFun c -> Context -> Ptr c -> IO h
mkC2hRefCount ForeignPtr Z3_goal -> Goal
Goal Z3IncRefFun Z3_goal
z3_goal_inc_ref Z3IncRefFun Z3_goal
z3_goal_dec_ref
  h2c :: forall r. Goal -> (Ptr Z3_goal -> IO r) -> IO r
h2c Goal
goa = ForeignPtr Z3_goal -> (Ptr Z3_goal -> IO r) -> IO r
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr (Goal -> ForeignPtr Z3_goal
unGoal Goal
goa)

marshal :: Marshal rh rc => (Ptr Z3_context -> t) ->
              Context -> (t -> IO rc) -> IO rh
marshal :: forall rh rc t.
Marshal rh rc =>
(Ptr Z3_context -> t) -> Context -> (t -> IO rc) -> IO rh
marshal Ptr Z3_context -> t
f Context
c t -> IO rc
cont = Context -> (Ptr Z3_context -> IO rc) -> IO rh
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO rc) -> IO rh)
-> (Ptr Z3_context -> IO rc) -> IO rh
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> t -> IO rc
cont (t -> IO rc) -> t -> IO rc
forall a b. (a -> b) -> a -> b
$ Ptr Z3_context -> t
f Ptr Z3_context
cPtr

liftFun0 :: Marshal rh rc => (Ptr Z3_context -> IO rc) ->
              Context -> IO rh
liftFun0 :: forall rh rc.
Marshal rh rc =>
(Ptr Z3_context -> IO rc) -> Context -> IO rh
liftFun0 = (Context -> (Ptr Z3_context -> IO rc) -> IO rh)
-> (Ptr Z3_context -> IO rc) -> Context -> IO rh
forall a b c. (a -> b -> c) -> b -> a -> c
flip Context -> (Ptr Z3_context -> IO rc) -> IO rh
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError
{-# INLINE liftFun0 #-}

liftFun1 :: (Marshal ah ac, Marshal rh rc) =>
              (Ptr Z3_context -> ac -> IO rc) ->
              Context -> ah -> IO rh
liftFun1 :: forall ah ac rh rc.
(Marshal ah ac, Marshal rh rc) =>
(Ptr Z3_context -> ac -> IO rc) -> Context -> ah -> IO rh
liftFun1 Ptr Z3_context -> ac -> IO rc
f Context
c ah
x = ah -> (ac -> IO rh) -> IO rh
forall r. ah -> (ac -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c ah
x ((ac -> IO rh) -> IO rh) -> (ac -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \ac
a ->
  Context -> (Ptr Z3_context -> IO rc) -> IO rh
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO rc) -> IO rh)
-> (Ptr Z3_context -> IO rc) -> IO rh
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> ac -> IO rc
f Ptr Z3_context
cPtr ac
a
{-# INLINE liftFun1 #-}

liftFun2 :: (Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
              (Ptr Z3_context -> ac -> bc -> IO rc) ->
              Context -> ah -> bh -> IO rh
liftFun2 :: forall ah ac bh bc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> IO rc)
-> Context -> ah -> bh -> IO rh
liftFun2 Ptr Z3_context -> ac -> bc -> IO rc
f Context
c ah
x bh
y = ah -> (ac -> IO rh) -> IO rh
forall r. ah -> (ac -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c ah
x ((ac -> IO rh) -> IO rh) -> (ac -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \ac
a -> bh -> (bc -> IO rh) -> IO rh
forall r. bh -> (bc -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c bh
y ((bc -> IO rh) -> IO rh) -> (bc -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \bc
b ->
  Context -> (Ptr Z3_context -> IO rc) -> IO rh
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO rc) -> IO rh)
-> (Ptr Z3_context -> IO rc) -> IO rh
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> ac -> bc -> IO rc
f Ptr Z3_context
cPtr ac
a bc
b
{-# INLINE liftFun2 #-}

liftFun3 :: (Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
              (Ptr Z3_context -> ac -> bc -> cc -> IO rc) ->
              Context -> ah -> bh -> ch -> IO rh
liftFun3 :: forall ah ac bh bc ch cc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> IO rc)
-> Context -> ah -> bh -> ch -> IO rh
liftFun3 Ptr Z3_context -> ac -> bc -> cc -> IO rc
f Context
c ah
x bh
y ch
z = ah -> (ac -> IO rh) -> IO rh
forall r. ah -> (ac -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c ah
x ((ac -> IO rh) -> IO rh) -> (ac -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \ac
x1 -> bh -> (bc -> IO rh) -> IO rh
forall r. bh -> (bc -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c bh
y ((bc -> IO rh) -> IO rh) -> (bc -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \bc
y1 -> ch -> (cc -> IO rh) -> IO rh
forall r. ch -> (cc -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c ch
z ((cc -> IO rh) -> IO rh) -> (cc -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \cc
z1 ->
  Context -> (Ptr Z3_context -> IO rc) -> IO rh
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO rc) -> IO rh)
-> (Ptr Z3_context -> IO rc) -> IO rh
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> ac -> bc -> cc -> IO rc
f Ptr Z3_context
cPtr ac
x1 bc
y1 cc
z1
{-# INLINE liftFun3 #-}

liftFun4 :: (Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal dh dc,
            Marshal rh rc) => (Ptr Z3_context -> ac -> bc -> cc -> dc ->
                               IO rc) ->
            Context -> ah -> bh -> ch -> dh -> IO rh
liftFun4 :: forall ah ac bh bc ch cc dh dc rh rc.
(Marshal ah ac, Marshal bh bc, Marshal ch cc, Marshal dh dc,
 Marshal rh rc) =>
(Ptr Z3_context -> ac -> bc -> cc -> dc -> IO rc)
-> Context -> ah -> bh -> ch -> dh -> IO rh
liftFun4 Ptr Z3_context -> ac -> bc -> cc -> dc -> IO rc
f Context
c ah
x bh
y ch
z dh
zz = ah -> (ac -> IO rh) -> IO rh
forall r. ah -> (ac -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c ah
x ((ac -> IO rh) -> IO rh) -> (ac -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \ac
x1 -> bh -> (bc -> IO rh) -> IO rh
forall r. bh -> (bc -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c bh
y ((bc -> IO rh) -> IO rh) -> (bc -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \bc
y1 -> ch -> (cc -> IO rh) -> IO rh
forall r. ch -> (cc -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c ch
z ((cc -> IO rh) -> IO rh) -> (cc -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \cc
z1 ->
  dh -> (dc -> IO rh) -> IO rh
forall r. dh -> (dc -> IO r) -> IO r
forall h c r. Marshal h c => h -> (c -> IO r) -> IO r
h2c dh
zz ((dc -> IO rh) -> IO rh) -> (dc -> IO rh) -> IO rh
forall a b. (a -> b) -> a -> b
$ \dc
zz1 -> Context -> (Ptr Z3_context -> IO rc) -> IO rh
forall h c.
Marshal h c =>
Context -> (Ptr Z3_context -> IO c) -> IO h
toHsCheckError Context
c ((Ptr Z3_context -> IO rc) -> IO rh)
-> (Ptr Z3_context -> IO rc) -> IO rh
forall a b. (a -> b) -> a -> b
$ \Ptr Z3_context
cPtr -> Ptr Z3_context -> ac -> bc -> cc -> dc -> IO rc
f Ptr Z3_context
cPtr ac
x1 bc
y1 cc
z1 dc
zz1
{-# INLINE liftFun4 #-}

---------------------------------------------------------------------
-- Utils

-- | Convert 'Z3_lbool' from Z3.Base.C to 'Result'
toResult :: Z3_lbool -> Result
toResult :: Z3_lbool -> Result
toResult Z3_lbool
lb
    | Z3_lbool
lb Z3_lbool -> Z3_lbool -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_lbool
z3_l_true  = Result
Sat
    | Z3_lbool
lb Z3_lbool -> Z3_lbool -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_lbool
z3_l_false = Result
Unsat
    | Z3_lbool
lb Z3_lbool -> Z3_lbool -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_lbool
z3_l_undef = Result
Undef
    | Bool
otherwise        = String -> Result
forall a. HasCallStack => String -> a
error String
"Z3.Base.toResult: illegal `Z3_lbool' value"

-- | Convert 'Z3_bool' to 'Bool'.
--
-- 'Foreign.toBool' should be OK but this is more convenient.
toBool :: Z3_bool -> Bool
toBool :: Z3_bool -> Bool
toBool Z3_bool
b
    | Z3_bool
b Z3_bool -> Z3_bool -> Bool
forall a. Eq a => a -> a -> Bool
== Z3_bool
z3_false = Bool
False
    -- As of March 2019, OS X has an issue where z3 uses other
    -- values than 'z3_true' as truthy. Our work around is to be permissive.
    | Bool
otherwise = Bool
True

-- | Convert 'Bool' to 'Z3_bool'.
unBool :: Bool -> Z3_bool
unBool :: Bool -> Z3_bool
unBool Bool
True  = Z3_bool
z3_true
unBool Bool
False = Z3_bool
z3_false

-- | Wraps a non-null pointer with 'Just', or else returns 'Nothing'.
ptrToMaybe :: Ptr a -> Maybe (Ptr a)
ptrToMaybe :: forall a. Ptr a -> Maybe (Ptr a)
ptrToMaybe Ptr a
ptr | Ptr a
ptr Ptr a -> Ptr a -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr a
forall a. Ptr a
nullPtr = Maybe (Ptr a)
forall a. Maybe a
Nothing
               | Bool
otherwise      = Ptr a -> Maybe (Ptr a)
forall a. a -> Maybe a
Just Ptr a
ptr