Now that you have finished these two tasks, you have a working resolution algorithm and you can use the unsatisfiable function to test the satisfiability of your formulas.However, often we would like to use the resolution technique to prove not just the satisfiability or unsatisfiability of a single propositional formula, but logical consequence relationships between two propositional formulas.Your final task for this section of the worksheet is to implement an additional function inside Main.hs to do just that. This function should be pretty simple, and should make use of the existing unsatisfiable function. For this to work, you'll need to copy over your solutions from the previous problems once again.Write a function entails which takes two Formulas f and g and returns True if and only if formula g is a logical consequence of f (in which case, we would say that f entails g). Don't forget a type signature!For example:Main> entails [[Pos 'Q', Neg 'P'], [Pos 'P']] [[Pos 'Q']]TrueMain> entails [[Pos 'Q', Neg 'P']] [[Pos 'P', Neg 'Q']]False
Question
Now that you have finished these two tasks, you have a working resolution algorithm and you can use the unsatisfiable function to test the satisfiability of your formulas.However, often we would like to use the resolution technique to prove not just the satisfiability or unsatisfiability of a single propositional formula, but logical consequence relationships between two propositional formulas.Your final task for this section of the worksheet is to implement an additional function inside Main.hs to do just that. This function should be pretty simple, and should make use of the existing unsatisfiable function. For this to work, you'll need to copy over your solutions from the previous problems once again.Write a function entails which takes two Formulas f and g and returns True if and only if formula g is a logical consequence of f (in which case, we would say that f entails g). Don't forget a type signature!For example:Main> entails [[Pos 'Q', Neg 'P'], [Pos 'P']] [[Pos 'Q']]TrueMain> entails [[Pos 'Q', Neg 'P']] [[Pos 'P', Neg 'Q']]False
Solution
To implement the entails function, you can follow these steps:
- Define the function
entailsthat takes two formulasfandgas input and returnsTrueif and only if formulagis a logical consequence off.
entails :: Formula -> Formula -> Bool
entails f g = undefined
- To check if
gis a logical consequence off, you can use theunsatisfiablefunction on the formulafand the negation ofg. If the result isTrue, thengis a logical consequence off.
entails f g = unsatisfiable (f ++ map negateFormula g)
Here, negateFormula is a function that negates a formula (e.g., it returns Neg 'A' for Pos 'A' and vice versa).
Here's the complete code:
import Data.List
type Literal = Char
type Clause = [Literal]
type Formula = [Clause]
complementaryLiteral :: Literal -> Literal
complementaryLiteral lit = if lit == 'Pos' then 'Neg' else 'Pos'
negateFormula :: Clause -> Clause
negateFormula = map complementaryLiteral
unsatisfiable :: Formula -> Bool
unsatisfiable f = not (null latest)
where
f' = reduce (remove_tautologies (map reduce f))
(older, latest) = until finished evolve ([], f')
finished (old, young) = null young || [] `elem` young
entails :: Formula -> Formula -> Bool
entails f g = unsatisfiable (f ++ map negateFormula g)
You can now use the entails function to check if a formula g is a logical consequence of another formula f.
Similar Questions
Which are needed to compute the logical inference algorithm?ans.All of the mentionedLogical equivalenceValiditySatisfiability Previous Marked for Review Next
Construct a truth table for the formula .
2. Use a tree to test whether the following two propositions are equivalent. (Present the tree, and say whether they’re equivalent or not.) If they’re not equivalent, read off from your tree a model on which the propositions have different truth values (and indicate the path from which you are reading it off). ∀x(Ax → Gx) ∃x(Ax → Gx)
Exercise b) Recall that a formula ϕ is a tautology if and only if ¬ϕ is not satisfiable, cf. Exercise 1.2.61in Rosen that we have covered in class, that is, to check whether ϕ is a tautology, you can check whether¬ϕ is satisfiable, and reverse the answer. Note also, that since the tableau rules only deal with negation andconjunction, you have to rewrite ϕ such that it only contains these two connectives. Now, make tableaus, asthey are presented in Priest’s book, Section 1.4, showing that the formulas p → (p ∨ q) and ¬p → (p → q)are tautologies, cf. exercises 1.2.11b and 1.2.11c in Rosen’s book
A _________ is used to demonstrate, on a purely syntactic basis, that one formula is a logical consequence of another formula
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.