Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Language.Hasmtlib.Counting
Description
This module provides functions for counting symbolic formulas and creating cardinality-constraints.
Internally this converts each given Expr
BoolSort
into a numerical Expr
using ite
, then sums them up:
count :: forall t f. (Functor f, Foldable f, Num (Expr t)) => f (Expr BoolSort) -> Expr t count = sum . fmap (\b -> ite b 1 0)
Therefore additional information for the temporal summation may need to be provided.
E.g. if your logic is "QF_LIA" you would want count'
@IntSort
$ ...
It is worth noting that some cardinality constraints use optimized encodings for special cases.
Synopsis
- count :: forall t f. (Functor f, Foldable f, Num (Expr t)) => f (Expr BoolSort) -> Expr t
- count' :: forall t f. (Functor f, Foldable f, Num (Expr t)) => Proxy t -> f (Expr BoolSort) -> Expr t
- atLeast :: forall t f. (Functor f, Foldable f, Num (Expr t), Orderable (Expr t)) => Expr t -> f (Expr BoolSort) -> Expr BoolSort
- exactly :: forall t f. (Functor f, Foldable f, Num (Expr t), Orderable (Expr t)) => Expr t -> f (Expr BoolSort) -> Expr BoolSort
- atMost :: forall t f. (Functor f, Foldable f, Num (Expr t), Orderable (Expr t)) => Expr t -> f (Expr BoolSort) -> Expr BoolSort
- amoSqrt :: (Foldable f, Boolean b) => f b -> b
- amoQuad :: Boolean b => [b] -> b
Count
count :: forall t f. (Functor f, Foldable f, Num (Expr t)) => f (Expr BoolSort) -> Expr t Source #
Out of many bool-expressions build a formula which encodes how many of them are true
.
count' :: forall t f. (Functor f, Foldable f, Num (Expr t)) => Proxy t -> f (Expr BoolSort) -> Expr t Source #
At-Least
atLeast :: forall t f. (Functor f, Foldable f, Num (Expr t), Orderable (Expr t)) => Expr t -> f (Expr BoolSort) -> Expr BoolSort Source #
Exactly
exactly :: forall t f. (Functor f, Foldable f, Num (Expr t), Orderable (Expr t)) => Expr t -> f (Expr BoolSort) -> Expr BoolSort Source #
At-Most
atMost :: forall t f. (Functor f, Foldable f, Num (Expr t), Orderable (Expr t)) => Expr t -> f (Expr BoolSort) -> Expr BoolSort Source #
amoSqrt :: (Foldable f, Boolean b) => f b -> b Source #
The squareroot-encoding, also called product-encoding, is a special encoding for atMost 1
.
The original product-encoding provided by Jingchao Chen in A New SAT Encoding of the At-Most-One Constraint (2010) used auxiliary variables and would therefore be monadic. It requires \( 2 \sqrt{n} + \mathcal{O}(\sqrt[4]{n}) \) auxiliary variables and \( 2n + 4\sqrt{n} + \mathcal{O}(\sqrt[4]{n}) \) clauses.
To make this encoding pure, all auxiliary variables are replaced with a disjunction of size \( \mathcal{O}(\sqrt{n}) \). Therefore zero auxiliary variables are required and technically clause-count remains the same, although the clauses get bigger.