Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Language.Hasmtlib.Type.Relation
Description
This module provides the data-type Relation
for encoding binary relations as SMT-problems.
Example
problem :: MonadSMT s m => StateT s m (Relation Int Int) setLogic "QF_LIA" r <- relation ((2,1), (6,5)) forM_ (image r <$> domain r) (assert . exactly @IntSort 1) forM_ (preimage r <$> codomain r) (assert . exactly @IntSort 1) assertMaybe $ do item <- r^?ix (3,3) return $ item === true return r
Synopsis
- newtype Relation a b = Relation (Array (a, b) (Expr BoolSort))
- relation :: (Ix a, Ix b, MonadSMT s m) => ((a, b), (a, b)) -> m (Relation a b)
- symmetric_relation :: (MonadSMT s m, Ix b) => ((b, b), (b, b)) -> m (Relation b b)
- build :: (Ix a, Ix b) => ((a, b), (a, b)) -> [((a, b), Expr BoolSort)] -> Relation a b
- buildFrom :: (Ix a, Ix b) => ((a, b), (a, b)) -> ((a, b) -> Expr BoolSort) -> Relation a b
- buildFromM :: (Ix a, Ix b, MonadSMT s m) => ((a, b), (a, b)) -> ((a, b) -> m (Expr BoolSort)) -> m (Relation a b)
- identity :: Ix a => ((a, a), (a, a)) -> Relation a a
- (!?) :: (Ix a, Ix b) => Relation a b -> (a, b) -> Maybe (Expr BoolSort)
- (!) :: (Ix a, Ix b) => Relation a b -> (a, b) -> Expr BoolSort
- bounds :: Relation a b -> ((a, b), (a, b))
- indices :: (Ix a, Ix b) => Relation a b -> [(a, b)]
- elems :: Relation a b -> [Expr BoolSort]
- assocs :: (Ix a, Ix b) => Relation a b -> [((a, b), Expr BoolSort)]
- domain :: Ix a => Relation a b -> [a]
- codomain :: Ix b => Relation a b -> [b]
- image :: (Ix a, Ix b) => Relation a b -> a -> [Expr BoolSort]
- preimage :: (Ix a, Ix b) => Relation a b -> b -> [Expr BoolSort]
- table :: (Ix a, Ix b) => Array (a, b) Bool -> String
Type
Relation a b
represents a binary relation \(R \subseteq A \times B \),
where the domain \(A\) is a finite subset of the type a
,
and the codomain \(B\) is a finite subset of the type b
.
A relation is stored internally as Array (a,b) Expr BoolSort
,
so a
and b
have to be instances of Ix
,
and both \(A\) and \(B\) are intervals.
Instances
(Ix a, Ix b) => Codec (Relation a b) Source # | |
(Ix a, Ix b) => Ixed (Relation a b) Source # | |
Defined in Language.Hasmtlib.Type.Relation | |
(Ix a, Ix b, a ~ c, b ~ d) => Each (Relation a b) (Relation c d) (Expr 'BoolSort) (Expr 'BoolSort) Source # | |
type Decoded (Relation a b) Source # | |
Defined in Language.Hasmtlib.Type.Relation | |
type Index (Relation a b) Source # | |
Defined in Language.Hasmtlib.Type.Relation | |
type IxValue (Relation a b) Source # | |
Defined in Language.Hasmtlib.Type.Relation |
Construction
relation :: (Ix a, Ix b, MonadSMT s m) => ((a, b), (a, b)) -> m (Relation a b) Source #
relation ((amin,bmin),(amax,mbax))
constructs an indeterminate relation \(R \subseteq A \times B \)
where \(A\) is {amin .. amax}
and \(B\) is {bmin .. bmax}
.
Arguments
:: (MonadSMT s m, Ix b) | |
=> ((b, b), (b, b)) | Since a symmetric relation must be homogeneous, the domain must equal the codomain.
Therefore, given bounds |
-> m (Relation b b) |
Constructs an indeterminate relation \(R \subseteq B \times B \) that is symmetric, i.e., \(\forall x, y \in B: ((x,y) \in R) \rightarrow ((y,x) \in R) \).
Arguments
:: (Ix a, Ix b) | |
=> ((a, b), (a, b)) | |
-> [((a, b), Expr BoolSort)] | A list of tuples, where the first element represents an element
\((x,y) \in A \times B \) and the second element is a positive |
-> Relation a b |
Constructs a relation \(R \subseteq A \times B \) from a list.
Arguments
:: (Ix a, Ix b) | |
=> ((a, b), (a, b)) | |
-> ((a, b) -> Expr BoolSort) | A function that assigns a |
-> Relation a b |
Constructs a relation \(R \subseteq A \times B \) from a function.
buildFromM :: (Ix a, Ix b, MonadSMT s m) => ((a, b), (a, b)) -> ((a, b) -> m (Expr BoolSort)) -> m (Relation a b) Source #
Constructs an indeterminate relation \(R \subseteq A \times B\) from a function.
Arguments
:: Ix a | |
=> ((a, a), (a, a)) | Since the identity relation is homogeneous, the domain must equal the codomain.
Therefore, given bounds |
-> Relation a a |
Constructs the identity relation \(I = \{ (x,x) ~|~ x \in A \} \subseteq A \times A\).
Accessors
bounds :: Relation a b -> ((a, b), (a, b)) Source #
The bounds of the array that correspond to the matrix representation of the given relation.
indices :: (Ix a, Ix b) => Relation a b -> [(a, b)] Source #
The list of indices, where each index represents an element \((x,y) \in A \times B \) that may be contained in the given relation \(R \subseteq A \times B \).
elems :: Relation a b -> [Expr BoolSort] Source #
The list of elements of the array that correspond to the matrix representation of the given relation.
domain :: Ix a => Relation a b -> [a] Source #
The domain \(A\) of a relation \(R \subseteq A \times B\).
codomain :: Ix b => Relation a b -> [b] Source #
The codomain \(B\) of a relation \(R \subseteq A \times B\).