Week S2.3. Horn Clauses and Logic Programming
Recap: Using CNF
In this week’s content, need to be familiar with CNF and the rewrite rules.
CNF Rewrite Rules
To obtain CNF, we can perform a series of transformations:
Link to original
For example, transform each formula of into CNF:
We will assign the result for further use to:
Horn & definite clauses
Horn clause
A Horn clause is a clause in DNF with at most one positive literal. For example, or .
Link to original
Definite clause
A definite clause is a clause in DNF with exactly one positive literal and as such is also a Horn clause. For example, or .
Link to original
Definite rules
A definite clause in the form can be rewritten in the form .
In a program, a rule without a body is also called a fact because it states something that we are sure of.
Link to original
Consider again, from earlier, we can transform the define clauses into definite rules:
Justification for definite rules (fluff)
We use definite rules as:
- Reasoning over a set of formulae means being able to decide whether a formula is entailed by the formulas in .
- Reasoning over sets of formula is at the base of many application contexts, from simple automatic reasoning to logical abduction.
- Logical consequence can be defined in terms of models or in terms of natural deduction, which is sound and complete.
It is not always easy to find the right sequence of natural deduction steps, so we can use definite clauses and rules. Given a set of definite rules, which is called a program, there is a simple automatic procedure to reason over the rules in and decide whether a conjunction of propositional variables is entailed by them.
Definite clauses are important as they can be directly translated into definite rules, hence into a program which we can reason over.
Resolution in propositional definite clause programs
Propositional definite clause program
A propositional definite clause program is a set of definite rules.
Link to original
Conjunctive Query
A (conjunctive) query (CQ) is a conjunction of propositions (also seen as a set )
Link to original
A CQ is a logical consequence or otherwise logically entailed by the program denoted if all models of are models of .
To resolve, we use a top-down approach to show logical entailment from a propositional definite clause program by starting from the goal (the proposition(s) of the query) and then we want to decide whether it is / are entailed by the program or not.
Resolution algorithm
Resolution algorithm
Let be a definite clause program with rules , where , and let be a conjunctive query over .
- Set
progressto .- Set
currentGoalto .- While the
currentGoalis not empty andprogressis :
- Let be a proposition in the current goal.
- If it exists, choose in a rule with the head .
- Let be a rule in with the head .
- In the current goal, replace for :
- Else, set
progressto .- If
currentGoalis empty andprogressis then the output is true, otherwise the output is false.There are two points of non-determinism:
Link to original
- (3.1) When we choose a proposition in the current goal. The choice here does not matter but we must be consistent, i.e. always leftmost or rightmost.
- (3.2) When we choose a matching rule, this choice does matter. See example 2 for an explanation.
Example 1: resolution (step-by-step)
Consider from earlier, is entailed by ?
Example 2: resolution (step-by-step)
Transform the set of formulas to CNF, then to definite clause program . Is entailed by the program?
Transformed into CNF:
And then into a program:
Let’s try to evaluate the entailment of in the previous program via resolution:
Therefore, the choice of the rule at the step where we pick the matching rule influences the evaluation of entailment. We may answer no when the answer is actually true.