epistemic-group-gossip-0.1.0.0
Copyright(c) Jesper Kuiper 2021
Leander van Boven 2021
Ramon Meffert 2021
LicenseBSD3
Safe HaskellNone
LanguageHaskell2010

PrintableBdd

Description

 
Synopsis

BDD type

data Bdd Source #

Printable data wrapper for the Bdd record.

Instances

Instances details
Eq Bdd Source # 
Instance details

Defined in PrintableBdd

Methods

(==) :: Bdd -> Bdd -> Bool #

(/=) :: Bdd -> Bdd -> Bool #

Read Bdd Source # 
Instance details

Defined in PrintableBdd

Show Bdd Source # 
Instance details

Defined in PrintableBdd

Methods

showsPrec :: Int -> Bdd -> ShowS #

show :: Bdd -> String #

showList :: [Bdd] -> ShowS #

BDD fields

bdd :: Bdd -> Bdd Source #

The binary decision diagram, as a Bdd type.

str :: Bdd -> String Source #

The formula represented as a unicode string for direct printing.

tex :: Bdd -> String Source #

The formula represented as a string, formatted in LaTeX.

Other types

type Assignment = [(Int, Bool)] Source #

An assignment is a valuation for a set of variables, i.e. a valuation as to whether a variable is true or false.

type VarLabeller = Int -> String Source #

The printable BDD can label their variables, instead of using integers. A VarLabeller type is a function that encodes a variable integer to its corresponding name.

Creating new BDDs

varl :: VarLabeller -> VarLabeller -> Int -> Bdd Source #

Encode a labelled integer as a BDD variable. Note that the first labeller is for text, the second for LaTeX. The variable is indexed by any integer from 0 to 1.000.000.

>>> slabel n = "var" ++ (show n)
>>> tlabel n = "p_" ++ (show n)
>>> foo = varl slabel tlabel 0
>>> foo
var0
>>> tex foo
p_0

var :: Int -> Bdd Source #

Encode an unlabelled integer as a BDD variable. The variable is indexed by any integer from 0 to 1.000.000.

top :: Bdd Source #

True constant.

>>> top

bot :: Bdd Source #

False constant.

>>> bot

BDD Operators

Unary operator

neg :: Bdd -> Bdd Source #

Negation.

>>> neg foo
¬(foo)

Binary operators

con :: Bdd -> Bdd -> Bdd Source #

Conjunction.

>>> foo `con` bar
(foo ∧ bar)

dis :: Bdd -> Bdd -> Bdd Source #

Disjunction.

>>> foo `dis` bar
(foo ∨ bar)

imp :: Bdd -> Bdd -> Bdd Source #

Logical implication.

>>> foo `imp` bar
(foo ⟶ bar)

equ :: Bdd -> Bdd -> Bdd Source #

Logical bi-implication or equivalence.

>>> foo `equ` bar
(foo ⟷ bar)

xor :: Bdd -> Bdd -> Bdd Source #

Exlusive or.

>>> foo `xor` bar
(foo ⊻ bar)

N-ary operators

conSet :: [Bdd] -> Bdd Source #

Big (setwise) conjunction.

>>> conSet [foo, bar, baz]
(foo ∧ bar ∧ baz)

disSet :: [Bdd] -> Bdd Source #

Big (setwise) disjunction.

>>> disSet [foo, bar, baz]
(foo ∨ bar ∨ baz)

xorSet :: [Bdd] -> Bdd Source #

Big (setwise) exclusive disjunction.

>>> xorSet [foo, bar, baz]
(foo ⊻ bar ⊻ baz)

Quantification

foralll :: VarLabeller -> VarLabeller -> Int -> Bdd -> Bdd Source #

Labelled binary universal quantification. Note that the first VarLabeller works for direct printing and the VarLabeller is for latex.

>>> slabel n = "var" ++ (show n)
>>> tlabel n = "p_" ++ (show n)
>>> foo = foralll slabel tlabel 0 $ varl slabel tlabel 0 `imp` varl slabel tlabel 1
>>> foo
∀var0(var0 ⟶ var1)
>>> tex foo
\\forall p_0 (p_0 \\rightarrow p_1)

forall :: Int -> Bdd -> Bdd Source #

Unlabelled binary universal quantification.

>>> forall 0 foo
∀0(foo)

existsl :: VarLabeller -> VarLabeller -> Int -> Bdd -> Bdd Source #

Labelled binary existential quantification.

>>> slabel n = "var" ++ (show n)
>>> tlabel n = "p_" ++ (show n)
>>> foo = existsl slabel tlabel 0 $ (varl slabel tlabel 0) `imp` (varl slabel tlabel 1)
>>> foo
∃var0(var0 ⟶ var1)
>>> tex foo
\\exists (p_0 \\rightarrow p_1) 

exists :: Int -> Bdd -> Bdd Source #

Unlabelled binary existential quantification

>>> exists 0 foo
∃0(foo)

N-ary quantification

forallSetl :: VarLabeller -> VarLabeller -> [Int] -> Bdd -> Bdd Source #

Labelled big binary universal quanficition.

>>> slabel n = "var" ++ (show n)
>>> tlabel n = "p_" ++ (show n)
>>> foo = forallSetl slabel tlabel [0, 1] $ (varl slabel tlabel 0) `imp` (varl slabel tlabel 1)
>>> foo
∀{var0, var1}(var0 ⟶ var1)
>>> tex foo
\\forall \\left{ p_0, p_1 \\right} (p_0 \\rightarrow p_1)

forallSet :: [Int] -> Bdd -> Bdd Source #

Unlabelled big binary universal quantification.

>>> forallSet [0,1,2] foo
∀{0,1,2}(foo)

existsSetl :: VarLabeller -> VarLabeller -> [Int] -> Bdd -> Bdd Source #

Labelled big binary existential quantification.

>>> slabel n = "var" ++ (show n)
>>> tlabel n = "p_" ++ (show n)
>>> foo = existsSetl slabel tlabel [0, 1] $ (varl slabel tlabel 0) `imp` (varl slabel tlabel 1)
>>> foo
∃{var0, var1}(var0 ⟶ var1)
>>> tex foo
\\exists \\left{ p_0, p_1 \\right} (p_0 \\rightarrow p_1)

existsSet :: [Int] -> Bdd -> Bdd Source #

Unlabelled big binary existential quantification.

>>> existsSet [0,1,2] foo
∃{0,1,2}(foo)

Substitution

substitl :: VarLabeller -> Int -> Bdd -> Bdd -> Bdd Source #

Labelled substitution.

>>> label n = "var" ++ n
>>> subsitl label 0 top foo
[var0\⊤](foo)

substit :: Int -> Bdd -> Bdd -> Bdd Source #

Unlabelled substitution.

>>> substit 0 top foo
[0\⊤]foo

Variable inspection

allVarsOf :: Bdd -> [Int] Source #

Returns all variables (without labels) that occur within the given BDD.

>>> allVarsOf (var 0 `imp` (var 1 `dis` var 2))
[0,1,2]

Evaluation

evaluate :: Bdd -> Assignment -> Maybe Bool Source #

Evaluate a BDD, given an assignment. Returns Nothing if the assignment doesn't contain all variables of the BDD.

>>> evaluate (var 0 `imp` var 1) [(0, True), (1, False)]
Just False 
>>> evaluate (var 0 `imp` var 1) [(0, True)]
Nothing

evaluateFun :: Bdd -> (Int -> Bool) -> Bool Source #

Evaluates a BDD, given a total assignment function.

>>> evaluateFun (var 0 `imp` var 1) (\ x -> if x == 0 then True else False)
False