• Tidak ada hasil yang ditemukan

Horn clauses and satisfiability

Dalam dokumen LOGIC IN COMPUTER SCIENCE (Halaman 81-84)

WWW page

1.5 Normal forms

1.5.3 Horn clauses and satisfiability

1.5 Normal forms 65 NNF(IMPL FREEφ) =NNF(¬r∨(¬s∨ ¬(t∧s)∨r))

= (NNF¬r)NNF(¬s∨ ¬(t∧s)∨r)

=¬r∨NNF(¬s∨ ¬(t∧s)∨r)

=¬r∨(NNF(¬s)NNF(¬(t∧s)∨r))

=¬r∨(¬s∨NNF(¬(t∧s)∨r))

=¬r∨(¬s∨(NNF(¬(t∧s))NNFr))

=¬r∨(¬s∨(NNF(¬t∨ ¬s))NNFr)

=¬r∨(¬s∨((NNF(¬t)NNF(¬s))NNFr))

=¬r∨(¬s∨((¬t∨NNF(¬s))NNFr))

=¬r∨(¬s∨((¬t∨ ¬s)NNFr))

=¬r∨(¬s∨((¬t∨ ¬s)∨r))

where the latter is already in CNF and valid asr has a matching ¬r.

Horn formulas are conjunctions of Horn clauses. A Horn clause is an impli- cation whose assumptionA is a conjunction of propositions of type P and whose conclusion is also of typeP. Examples of Horn formulas are

(p∧q∧s→p)(q∧r→p)(p∧s→s) (p∧q∧s→ ⊥)(q∧r→p)( →s)

(p2∧p3∧p5 →p13)( →p5)(p5∧p11→ ⊥). Examples of formulas which arenot Horn formulas are

(p∧q∧s→ ¬p)(q∧r→p)(p∧s→s) (p∧q∧s→ ⊥)(¬q∧r →p)( →s)

(p2∧p3∧p5 →p13∧p27)( →p5)(p5∧p11→ ⊥) (p2∧p3∧p5 →p13∧p27)( →p5)(p5∧p11∨ ⊥).

The first formula is not a Horn formula since ¬p, the conclusion of the implication of the first conjunct, is not of typeP. The second formula does not qualify since the premise of the implication of the second conjunct,

¬q∧r, is not a conjunction of atoms, , or . The third formula is not a Horn formula since the conclusion of the implication of the first conjunct, p13∧p27, is not of typeP. The fourth formula clearly is not a Horn formula since it is not a conjunction of implications.

The algorithm we propose for deciding the satisfiability of a Horn for- mulaφ maintains a list of all occurrences of type P in φand proceeds like this:

1. It marksif it occurs in that list.

2. If there is a conjunctP1P2∧ · · · ∧Pki Pofφsuch that allPjwith 1j ki are marked, markP as well and go to 2. Otherwise (= there is no conjunct P1P2∧ · · · ∧Pki P such that allPj are marked) go to 3.

3. Ifis marked, print out ‘The Horn formulaφis unsatisfiable.’ and stop. Oth- erwise, go to 4.

4. Print out ‘The Horn formulaφis satisfiable.’ and stop.

In these instructions, the markings of formulas are shared by all other oc- currences of these formulas in the Horn formula. For example, once we mark p2 because of one of the criteria above, then all other occurrences of p2 are marked as well. We use pseudo code to specify this algorithm formally:

1.5 Normal forms 67 function HORN(φ):

/* precondition:φis a Horn formula */

/* postcondition: HORN(φ) decides the satisfiability for φ*/

begin function

mark all occurrences of inφ;

while there is a conjunct P1∧P2∧ · · · ∧Pki →P of φ such that allPj are marked butP isn’tdo mark P

end while

if is marked then return‘unsatisfiable’ else return‘satisfiable’

end function

We need to make sure that this algorithm terminates on all Horn formulas φas input and that its output (= its decision) is always correct.

Theorem 1.47 The algorithmHORN is correct for the satisfiability decision problem of Horn formulas and has no more than n+ 1 cycles in its while- statement if n is the number of atoms in φ. In particular, HORN always terminates on correct input.

Proof: Let us first consider the question of program termination. Notice that entering the body of the while-statement has the effect of marking an unmarked P which is not . Since this marking applies to all occurrences of P inφ, the while-statement can have at most one more cycle than there are atoms in φ.

Since we guaranteed termination, it suffices to show that the answers given by the algorithm HORN are always correct. To that end, it helps to reveal the functional role of those markings. Essentially, marking aP means that thatP has got to be true if the formulaφis ever going to be satisfiable.

We use mathematical induction to show that

‘All marked P are true for all valuations in whichφevaluates to T.’ (1.8) holds after any number of executions of the body of the while-statement above. The base case, zero executions, is when the while-statement has not yet been entered but we already and only marked all occurrences of. Since must be true in all valuations, (1.8) follows.

In the inductive step, we assume that (1.8) holds after k cycles of the while-statement. Then we need to show that same assertion for all marked P after k+ 1 cycles. If we enter the (k+ 1)th cycle, the condition of the while-statement is certainly true. Thus, there exists a conjunct P1∧P2

· · · ∧Pki →P of φ such that all Pj are marked. Let v be any valuation

in which φ is true. By our induction hypothesis, we know that all Pj and thereforeP1∧P2∧ · · · ∧Pki have to be true in vas well. The conjunctP1 P2∧ · · · ∧Pki →P of φhas be to true in v, too, from which we infer that P has to be true inv.

By mathematical induction, we therefore secured that (1.8) holds no mat- ter how many cycles that while-statement went through.

Finally, we need to make sure that the if-statement above always renders correct replies. First, if is marked, then there has to be some conjunct P1∧P2∧ · · · ∧Pki → ⊥ of φ such that all Pi are marked as well. By (1.8) that conjunct of φ evaluates to TF=F whenever φ is true. As this is impossible the reply ‘unsatisfiable’ is correct. Second, ifis not marked, we simply assignT to all marked atoms and Fto all unmarked atoms and use proof by contradiction to show that φ has to be true with respect to that valuation.

If φ is not true under that valuation, it must make one of its principal conjuncts P1∧P2∧ · · · ∧Pki →P false. By the semantics of implication this can only mean that allPj are true andP is false. By the definition of our valuation, we then infer that allPj are marked, so P1∧P2∧ · · · ∧Pki →P is a conjunct of φ that would have been dealt with in one of the cycles of the while-statement and soP is marked, too. Sinceis not marked,P has to beor some atom q. In any event, the conjunct is then true by (1.8), a

contradiction 2

Note that the proof by contradiction employed in the last proof was not really needed. It just made the argument seem more natural to us. The literature is full of such examples where one uses proof by contradiction more out of psychological than proof-theoretical necessity.

Dalam dokumen LOGIC IN COMPUTER SCIENCE (Halaman 81-84)