Skip to content

Commit

Permalink
model checking implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
hk619 committed Jun 27, 2020
1 parent 207edaf commit 28a8118
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
5 changes: 1 addition & 4 deletions DPLL.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{-# OPTIONS_GHC -Wall -fwarn-tabs #-}
{-# OPTIONS_GHC -Wall -Wno-name-shadowing -fwarn-tabs #-}
module DPLL where

import Data.List
import Data.Maybe

import Formula

--------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion Formula.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-# OPTIONS_GHC -Wall -fwarn-tabs #-}
{-# OPTIONS_GHC -Wall -Wno-name-shadowing -fwarn-tabs #-}
module Formula where

import Data.Maybe
import Data.List

type Id = String

Expand Down
41 changes: 41 additions & 0 deletions Logic.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{-# OPTIONS_GHC -Wall -Wno-name-shadowing -fwarn-tabs #-}
module Logic where

import Formula
import DPLL

p, q, r :: Formula
p = Var "P"
q = Var "Q"
r = Var "R"

modelCheck :: Formula -> Formula -> Bool
modelCheck knowledge query
= all modelCheck' (sequence allModels)
where
symbols = vars (And knowledge query)
allModels = [[(symbol, b) | b <- [True, False]] | symbol <- symbols]
modelCheck' :: [(Id, Bool)] -> Bool
modelCheck' model
| evaluate model knowledge = evaluate model query
| otherwise = True

knowledge :: Formula
knowledge
= ands [
(p `And` Not q) `Impl` r,
p,
Not q
]

query :: Formula
query
= r

main :: IO ()
main
= do
putStrLn ("Knowledge is " ++ show knowledge)
putStrLn ("Query is " ++ show query)
let result = modelCheck knowledge query
putStrLn ("Does the model entail? (using modelCheck): " ++ show result)

0 comments on commit 28a8118

Please sign in to comment.