module PrintableBdd
(
Bdd
, bdd
, str
, tex
, Assignment
, VarLabeller
, varl
, var
, top
, bot
, neg
, con
, dis
, imp
, equ
, xor
, conSet
, disSet
, xorSet
, foralll
, forall
, existsl
, exists
, forallSetl
, forallSet
, existsSetl
, existsSet
, substitl
, substit
, allVarsOf
, evaluate
, evaluateFun
) where
import qualified Data.HasCacBDD as B
import Data.Bifunctor ( Bifunctor(second) )
import Data.List ( intercalate )
import Data.Set (Set)
data Bdd = Bdd
{
Bdd -> String
str :: String
, Bdd -> String
tex :: String
, Bdd -> Bdd
bdd :: B.Bdd
} deriving ( Bdd -> Bdd -> Bool
(Bdd -> Bdd -> Bool) -> (Bdd -> Bdd -> Bool) -> Eq Bdd
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Bdd -> Bdd -> Bool
$c/= :: Bdd -> Bdd -> Bool
== :: Bdd -> Bdd -> Bool
$c== :: Bdd -> Bdd -> Bool
Eq, ReadPrec [Bdd]
ReadPrec Bdd
Int -> ReadS Bdd
ReadS [Bdd]
(Int -> ReadS Bdd)
-> ReadS [Bdd] -> ReadPrec Bdd -> ReadPrec [Bdd] -> Read Bdd
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Bdd]
$creadListPrec :: ReadPrec [Bdd]
readPrec :: ReadPrec Bdd
$creadPrec :: ReadPrec Bdd
readList :: ReadS [Bdd]
$creadList :: ReadS [Bdd]
readsPrec :: Int -> ReadS Bdd
$creadsPrec :: Int -> ReadS Bdd
Read )
instance Show Bdd where
show :: Bdd -> String
show = Bdd -> String
str
type Assignment = [(Int, Bool)]
type VarLabeller = (Int -> String)
directly :: (B.Bdd -> a) -> (Bdd -> a)
directly :: (Bdd -> a) -> Bdd -> a
directly = ((Bdd -> a) -> (Bdd -> Bdd) -> Bdd -> a)
-> (Bdd -> Bdd) -> (Bdd -> a) -> Bdd -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Bdd -> a) -> (Bdd -> Bdd) -> Bdd -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) Bdd -> Bdd
bdd
nullary :: String -> String -> B.Bdd -> Bdd
nullary :: String -> String -> Bdd -> Bdd
nullary = String -> String -> Bdd -> Bdd
Bdd
unary :: String -> String -> (B.Bdd -> B.Bdd) -> (Bdd -> Bdd)
unary :: String -> String -> (Bdd -> Bdd) -> Bdd -> Bdd
unary String
s String
t Bdd -> Bdd
f Bdd
b = String -> String -> Bdd -> Bdd
Bdd (String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ Bdd -> String
str Bdd
b) (String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Bdd -> String
tex Bdd
b) (Bdd -> Bdd
f (Bdd -> Bdd) -> Bdd -> Bdd
forall a b. (a -> b) -> a -> b
$ Bdd -> Bdd
bdd Bdd
b)
binary :: String -> String -> (B.Bdd -> B.Bdd -> B.Bdd) -> (Bdd -> Bdd -> Bdd)
binary :: String -> String -> (Bdd -> Bdd -> Bdd) -> Bdd -> Bdd -> Bdd
binary String
s String
t Bdd -> Bdd -> Bdd
f Bdd
b1 Bdd
b2 = String -> String -> Bdd -> Bdd
Bdd
([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"(", Bdd -> String
str Bdd
b1, String
" ", String
s, String
" ", Bdd -> String
str Bdd
b2, String
")"])
([String] -> String
unwords [String
"(", Bdd -> String
tex Bdd
b1, String
t, Bdd -> String
tex Bdd
b2, String
")"])
(Bdd -> Bdd -> Bdd
f (Bdd -> Bdd
bdd Bdd
b1) (Bdd -> Bdd
bdd Bdd
b2))
nary :: String -> String -> ([B.Bdd] -> B.Bdd) -> ([Bdd] -> Bdd)
nary :: String -> String -> ([Bdd] -> Bdd) -> [Bdd] -> Bdd
nary String
s String
t [Bdd] -> Bdd
f [Bdd]
list = String -> String -> Bdd -> Bdd
Bdd
(String
"(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate (String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" ") ((Bdd -> String) -> [Bdd] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Bdd -> String
str [Bdd]
list) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")")
(String
" (" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate (String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" ") ((Bdd -> String) -> [Bdd] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Bdd -> String
tex [Bdd]
list) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
") ")
([Bdd] -> Bdd
f ([Bdd] -> Bdd) -> [Bdd] -> Bdd
forall a b. (a -> b) -> a -> b
$ (Bdd -> Bdd) -> [Bdd] -> [Bdd]
forall a b. (a -> b) -> [a] -> [b]
map Bdd -> Bdd
bdd [Bdd]
list)
quant :: VarLabeller -> VarLabeller -> String -> String -> (Int -> B.Bdd -> B.Bdd) -> (Int -> Bdd -> Bdd)
quant :: VarLabeller
-> VarLabeller
-> String
-> String
-> (Int -> Bdd -> Bdd)
-> Int
-> Bdd
-> Bdd
quant VarLabeller
ls VarLabeller
lt String
s String
t Int -> Bdd -> Bdd
f Int
v Bdd
b = String -> String -> Bdd -> Bdd
Bdd
([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
s, VarLabeller
ls Int
v, String
"(", Bdd -> String
str Bdd
b, String
")"])
([String] -> String
unwords [String
t, VarLabeller
lt Int
v, String
"\\left( ", Bdd -> String
tex Bdd
b, String
"\\right)"])
(Int -> Bdd -> Bdd
f Int
v (Bdd -> Bdd
bdd Bdd
b))
quantSet :: VarLabeller -> VarLabeller -> String -> String -> ([Int] -> B.Bdd -> B.Bdd) -> ([Int] -> Bdd -> Bdd)
quantSet :: VarLabeller
-> VarLabeller
-> String
-> String
-> ([Int] -> Bdd -> Bdd)
-> [Int]
-> Bdd
-> Bdd
quantSet VarLabeller
ls VarLabeller
lt String
s String
t [Int] -> Bdd -> Bdd
f [Int]
v Bdd
b = String -> String -> Bdd -> Bdd
Bdd
([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
s, String
"{", String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
", " (VarLabeller -> [Int] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map VarLabeller
ls [Int]
v), String
"}", String
"(", Bdd -> String
str Bdd
b, String
")"])
([String] -> String
unwords [String
t, String
"\\left{", String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
" , " (VarLabeller -> [Int] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map VarLabeller
lt [Int]
v), String
"\\right}", String
"(", Bdd -> String
str Bdd
b, String
")"])
([Int] -> Bdd -> Bdd
f [Int]
v (Bdd -> Bdd
bdd Bdd
b))
varl :: VarLabeller -> VarLabeller -> Int -> Bdd
varl :: VarLabeller -> VarLabeller -> Int -> Bdd
varl VarLabeller
ls VarLabeller
lt Int
i = String -> String -> Bdd -> Bdd
nullary (VarLabeller
ls Int
i) (VarLabeller
lt Int
i) (Int -> Bdd
B.var Int
i)
var :: Int -> Bdd
var :: Int -> Bdd
var = VarLabeller -> VarLabeller -> Int -> Bdd
varl VarLabeller
forall a. Show a => a -> String
show VarLabeller
forall a. Show a => a -> String
show
top :: Bdd
top :: Bdd
top = String -> String -> Bdd -> Bdd
nullary String
"⊤" String
"\\top " Bdd
B.top
bot :: Bdd
bot :: Bdd
bot = String -> String -> Bdd -> Bdd
nullary String
"⊥" String
"\\bot " Bdd
B.bot
neg :: Bdd -> Bdd
neg :: Bdd -> Bdd
neg = String -> String -> (Bdd -> Bdd) -> Bdd -> Bdd
unary String
"¬" String
"\\neg" Bdd -> Bdd
B.neg
con :: Bdd -> Bdd -> Bdd
con :: Bdd -> Bdd -> Bdd
con = String -> String -> (Bdd -> Bdd -> Bdd) -> Bdd -> Bdd -> Bdd
binary String
"∧" String
"\\wedge" Bdd -> Bdd -> Bdd
B.con
dis :: Bdd -> Bdd -> Bdd
dis :: Bdd -> Bdd -> Bdd
dis = String -> String -> (Bdd -> Bdd -> Bdd) -> Bdd -> Bdd -> Bdd
binary String
"∨" String
"\\vee" Bdd -> Bdd -> Bdd
B.dis
imp :: Bdd -> Bdd -> Bdd
imp :: Bdd -> Bdd -> Bdd
imp = String -> String -> (Bdd -> Bdd -> Bdd) -> Bdd -> Bdd -> Bdd
binary String
"⟶" String
"\\rightarrow" Bdd -> Bdd -> Bdd
B.imp
equ :: Bdd -> Bdd -> Bdd
equ :: Bdd -> Bdd -> Bdd
equ = String -> String -> (Bdd -> Bdd -> Bdd) -> Bdd -> Bdd -> Bdd
binary String
"⟷" String
"\\leftrightarrow" Bdd -> Bdd -> Bdd
B.equ
xor :: Bdd -> Bdd -> Bdd
xor :: Bdd -> Bdd -> Bdd
xor = String -> String -> (Bdd -> Bdd -> Bdd) -> Bdd -> Bdd -> Bdd
binary String
"⊻" String
"\\oplus" Bdd -> Bdd -> Bdd
B.xor
foralll :: VarLabeller -> VarLabeller -> Int -> Bdd -> Bdd
foralll :: VarLabeller -> VarLabeller -> Int -> Bdd -> Bdd
foralll VarLabeller
ls VarLabeller
lt = VarLabeller
-> VarLabeller
-> String
-> String
-> (Int -> Bdd -> Bdd)
-> Int
-> Bdd
-> Bdd
quant VarLabeller
ls VarLabeller
lt String
"∀" String
"\\forall" Int -> Bdd -> Bdd
B.forall
forall :: Int -> Bdd -> Bdd
forall :: Int -> Bdd -> Bdd
forall = VarLabeller -> VarLabeller -> Int -> Bdd -> Bdd
foralll VarLabeller
forall a. Show a => a -> String
show VarLabeller
forall a. Show a => a -> String
show
existsl :: VarLabeller -> VarLabeller -> Int -> Bdd -> Bdd
existsl :: VarLabeller -> VarLabeller -> Int -> Bdd -> Bdd
existsl VarLabeller
ls VarLabeller
lt = VarLabeller
-> VarLabeller
-> String
-> String
-> (Int -> Bdd -> Bdd)
-> Int
-> Bdd
-> Bdd
quant VarLabeller
ls VarLabeller
lt String
"∃" String
"\\exists" Int -> Bdd -> Bdd
B.exists
exists :: Int -> Bdd -> Bdd
exists :: Int -> Bdd -> Bdd
exists = VarLabeller -> VarLabeller -> Int -> Bdd -> Bdd
existsl VarLabeller
forall a. Show a => a -> String
show VarLabeller
forall a. Show a => a -> String
show
forallSetl :: VarLabeller -> VarLabeller -> [Int] -> Bdd -> Bdd
forallSetl :: VarLabeller -> VarLabeller -> [Int] -> Bdd -> Bdd
forallSetl VarLabeller
ls VarLabeller
lt = VarLabeller
-> VarLabeller
-> String
-> String
-> ([Int] -> Bdd -> Bdd)
-> [Int]
-> Bdd
-> Bdd
quantSet VarLabeller
ls VarLabeller
lt String
"∀" String
"\\forall" [Int] -> Bdd -> Bdd
B.forallSet
forallSet :: [Int] -> Bdd -> Bdd
forallSet :: [Int] -> Bdd -> Bdd
forallSet = VarLabeller -> VarLabeller -> [Int] -> Bdd -> Bdd
forallSetl VarLabeller
forall a. Show a => a -> String
show VarLabeller
forall a. Show a => a -> String
show
existsSetl :: VarLabeller -> VarLabeller -> [Int] -> Bdd -> Bdd
existsSetl :: VarLabeller -> VarLabeller -> [Int] -> Bdd -> Bdd
existsSetl VarLabeller
ls VarLabeller
lt = VarLabeller
-> VarLabeller
-> String
-> String
-> ([Int] -> Bdd -> Bdd)
-> [Int]
-> Bdd
-> Bdd
quantSet VarLabeller
ls VarLabeller
lt String
"∃" String
"\\exists" [Int] -> Bdd -> Bdd
B.existsSet
existsSet :: [Int] -> Bdd -> Bdd
existsSet :: [Int] -> Bdd -> Bdd
existsSet = VarLabeller -> VarLabeller -> [Int] -> Bdd -> Bdd
existsSetl VarLabeller
forall a. Show a => a -> String
show VarLabeller
forall a. Show a => a -> String
show
conSet :: [Bdd] -> Bdd
conSet :: [Bdd] -> Bdd
conSet = String -> String -> ([Bdd] -> Bdd) -> [Bdd] -> Bdd
nary String
"∧" String
"\\wedge" [Bdd] -> Bdd
B.conSet
disSet :: [Bdd] -> Bdd
disSet :: [Bdd] -> Bdd
disSet = String -> String -> ([Bdd] -> Bdd) -> [Bdd] -> Bdd
nary String
"∨" String
"\\vee" [Bdd] -> Bdd
B.disSet
xorSet :: [Bdd] -> Bdd
xorSet :: [Bdd] -> Bdd
xorSet = String -> String -> ([Bdd] -> Bdd) -> [Bdd] -> Bdd
nary String
"⊻" String
"\\oplus" [Bdd] -> Bdd
B.xorSet
substitl :: VarLabeller -> Int -> Bdd -> Bdd -> Bdd
substitl :: VarLabeller -> Int -> Bdd -> Bdd -> Bdd
substitl VarLabeller
l Int
i Bdd
s Bdd
f = String -> String -> Bdd -> Bdd
Bdd
([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"[", VarLabeller
l Int
i, String
"\\", Bdd -> String
str Bdd
s, String
"](", Bdd -> String
str Bdd
f, String
")"])
([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"\\left[ ", VarLabeller
l Int
i, String
" \\setminus ", Bdd -> String
tex Bdd
s, String
"\\right]\\left( ", Bdd -> String
tex Bdd
f, String
" )"])
(Int -> Bdd -> Bdd -> Bdd
B.substit Int
i (Bdd -> Bdd
bdd Bdd
s) (Bdd -> Bdd
bdd Bdd
f))
substit :: Int -> Bdd -> Bdd -> Bdd
substit :: Int -> Bdd -> Bdd -> Bdd
substit = VarLabeller -> Int -> Bdd -> Bdd -> Bdd
substitl VarLabeller
forall a. Show a => a -> String
show
allVarsOf :: Bdd -> [Int]
allVarsOf :: Bdd -> [Int]
allVarsOf = (Bdd -> [Int]) -> Bdd -> [Int]
forall a. (Bdd -> a) -> Bdd -> a
directly Bdd -> [Int]
B.allVarsOf
evaluate :: Bdd -> Assignment -> Maybe Bool
evaluate :: Bdd -> Assignment -> Maybe Bool
evaluate = (Bdd -> Assignment -> Maybe Bool)
-> Bdd -> Assignment -> Maybe Bool
forall a. (Bdd -> a) -> Bdd -> a
directly Bdd -> Assignment -> Maybe Bool
B.evaluate
evaluateFun :: Bdd -> (Int -> Bool) -> Bool
evaluateFun :: Bdd -> (Int -> Bool) -> Bool
evaluateFun = (Bdd -> (Int -> Bool) -> Bool) -> Bdd -> (Int -> Bool) -> Bool
forall a. (Bdd -> a) -> Bdd -> a
directly Bdd -> (Int -> Bool) -> Bool
B.evaluateFun