Copyright | (c) Artem Mavrin 2021 |
---|---|
License | BSD3 |
Maintainer | artemvmavrin@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
Satisfiability algorithms.
Synopsis
- class TruthAssignment t a where
- evalVar :: t -> a -> Bool
- evalFormula :: t -> Formula a -> Bool
- (|=) :: TruthAssignment t a => t -> Formula a -> Bool
- satSimple :: Eq a => Formula a -> Bool
- satDPLL :: Ord a => Formula a -> Bool
- satAssignmentSimple :: Ord a => Formula a -> Maybe (Map a Bool)
- satAssignmentDPLL :: Ord a => Formula a -> Maybe (Map a Bool)
Truth assignments
class TruthAssignment t a where Source #
Class representing truth assignments for evalutating propositional logic formulas.
evalVar :: t -> a -> Bool Source #
Evaluate the truth value of a variable under a given truth assignment.
evalFormula :: t -> Formula a -> Bool Source #
Evaluate the truth value of a formula under a given truth assignment.
Instances
TruthAssignment () a Source # | Assigns all propositional variables the truth value Examples
|
Ord a => TruthAssignment (Map a Bool) a Source # | Truth assignments where a missing key in the map is interpreted as Examples
|
(|=) :: TruthAssignment t a => t -> Formula a -> Bool infix 5 Source #
Semantic entailment relation. This is an infix alias of evalFormula
.
Examples
>>>
t = Map.fromList $ [("a", True), ("b", False)]
>>>
t |= And (Var "a") (Not (Var "b"))
True
Satisfiability algorithms
Check satisfiability
satSimple :: Eq a => Formula a -> Bool Source #
A simple baseline satisfiability algorithm.
This algorithm is based on the observation that if \(a\) is a propositional formula and \(x\) is a propositional variable, then \(a\) is satisfiable if and only if either \(a[\top/x]\) is satisfiable or \(a[\bot/x]\) is satisfiable.
Examples
>>>
satSimple $ Var "a"
True
>>>
satSimple $ And (Var "a") (Not (Var "a"))
False
satDPLL :: Ord a => Formula a -> Bool Source #
DPLL satisfiability algorithm.
Examples
>>>
import AutoProof.Internal.Formula
>>>
satDPLL $ Var "a"
True
>>>
satDPLL $ And (Var "a") (Not (Var "a"))
False
Satisfying assignment search
satAssignmentSimple :: Ord a => Formula a -> Maybe (Map a Bool) Source #
A simple baseline satisfiability algorithm, returning a satisfying truth assignment if there is one.
This algorithm is based on the observation that if \(a\) is a propositional formula and \(x\) is a propositional variable, then \(a\) is satisfiable if and only if either \(a[\top/x]\) is satisfiable or \(a[\bot/x]\) is satisfiable.
Examples
>>>
a = And (Not (Var "a")) (Or (Var "b") (Var "c")) -- satisfiable
>>>
Just t = satAssignmentSimple a
>>>
t
fromList [("a",False),("b",True),("c",True)]>>>
t |= a
True
>>>
satAssignmentSimple $ And (Var "a") (Not (Var "a")) -- unsatisfiable
Nothing
satAssignmentDPLL :: Ord a => Formula a -> Maybe (Map a Bool) Source #
DPLL satisfiability algorithm, returning a satisfying truth assihnment, if there is one.
Examples
>>>
a = And (Not (Var "a")) (Or (Var "b") (Var "c")) -- satisfiable
>>>
Just t = satAssignmentDPLL a
>>>
t
fromList [("a",False),("c",True)]>>>
t |= a
True
Note: The variable "b"
is missing in the map above, which means that it's
implictly assigned the value False
.
>>>
satAssignmentDPLL $ And (Var "a") (Not (Var "a")) -- unsatisfiable
Nothing