Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Algorithm where
  2.  
  3.     import System.Random
  4.     import Data.Maybe
  5.     import Data.List
  6.  
  7.     type Atom = String
  8.     type Literal = (Bool,Atom)
  9.     type Clause = [Literal]
  10.     type Formula = [Clause]
  11.     type Model = [(Atom, Bool)]
  12.     type Node = (Formula, ([Atom], Model))
  13.  
  14.     -- This function  takess a Clause and return the set of Atoms of that Clause.
  15.     atomsClause :: Clause -> [Atom]
  16.    
  17.  
  18.     -- This function  takes a Formula returns the set of Atoms of a Formula
  19.     atoms :: Formula -> [Atom]
  20.    
  21.  
  22.     -- This function returns True if the given Literal can be found within
  23.     -- the Clause.
  24.     isLiteral :: Literal -> Clause -> Bool
  25.    
  26.  
  27.     -- this function takes a Model and an Atom and flip the truthvalue of
  28.     -- the atom in the model
  29.     flipSymbol :: Model -> Atom -> Model -- is this ok?
  30.  
  31.     Additional functions :
  32.     remove :: (Eq a) )a ->[a] ->[a]
  33.     -This function removes an item from a list.
  34.      
  35.      neg :: Literal->Literal
  36.     -This function flips a literal (ie. from P to :P and from :P to P).
  37.     falseClause :: Model -> Clause -> Bool
  38.     -This function takes a Model and a Clause and returns True
  39.     if the clause is unsatisfied by the model or False otherwise.
  40.     falseClauses :: Formula -> Model -> [Clause]
  41.     -This function takes a Formula and a Model and returns the list of clauses of the  formula that are not satisfied.
  42.      assignModel :: Model -> Formula -> Formula
  43.      -This function applies the assign function for all the assignments of a given model.
  44.      checkFormula :: Formula -> Maybe Bool This function checks whether a formula can be  decided to be satisfiable or unsatisfiable based on the effects of the assign function.
  45.      satisfies :: Model -> Formula -. Bool This function checks whether a model satisfies a formula. This is done with the combination of the assignModel and checkFormula functions.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement