cs1502 formal methods in computer science lecture notes 10 resolution and horn sentences
TRANSCRIPT
![Page 1: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/1.jpg)
CS1502 Formal Methods in CS1502 Formal Methods in Computer Science Computer Science
Lecture Notes 10
Resolutionand Horn Sentences
![Page 2: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/2.jpg)
Resolution Theorem ProvingResolution Theorem Proving
Method for searching for proofs automaticallyMethod for searching for proofs automaticallySentences are translated into CNF, and then to Sentences are translated into CNF, and then to sets of clausessets of clausesAt each step, a new clause is derived from two At each step, a new clause is derived from two clauses you already haveclauses you already haveProof steps all use the same ruleProof steps all use the same rule
If reach If reach (_|_), sentences were not satisfiable (_|_), sentences were not satisfiable
Start: premises + negation of goalStart: premises + negation of goal
End: if reach End: if reach , premises |= goal, premises |= goal
![Page 3: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/3.jpg)
Resolution Theorem ProvingResolution Theorem Proving
Method for searching for proofs automaticallyMethod for searching for proofs automaticallySentences are translated into CNF, and then to Sentences are translated into CNF, and then to sets of clausessets of clausesAt each step, a new clause is derived from two At each step, a new clause is derived from two clauses you already haveclauses you already haveProof steps all use the same ruleProof steps all use the same rule
If reach If reach (_|_), sentences were not satisfiable (_|_), sentences were not satisfiable
Start: premises + negation of goalStart: premises + negation of goal
End: if reach End: if reach , premises |= goal, premises |= goal
![Page 4: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/4.jpg)
Conversion to Clausal FormConversion to Clausal Form
UseUse P P Q Q equivequiv ~P v Q ~P v Q to removeto remove UseUse P P Q Q equivequiv ((~P v Q) ^ (~Q v P)) ((~P v Q) ^ (~Q v P)) to removeto remove
New 1st Step! We hadn’t done conditionals yetNew 1st Step! We hadn’t done conditionals yet
Use Use DeMorgan’s lawsDeMorgan’s laws and and ~Elim~Elim to move to move ~~ as far inward as far inward as possible as possible (gives NNF)(gives NNF)
Use the Use the distributive lawsdistributive laws until the sentence is in until the sentence is in CNFCNF
![Page 5: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/5.jpg)
Clausal FormClausal Form
Given a sentence S written in CNFGiven a sentence S written in CNF S = ( ) S = ( ) ( ) ( ) . . . . . . ( ) ( )
Convert each ( ) into a clause - a set Convert each ( ) into a clause - a set consisting of each of the literals in ( ).consisting of each of the literals in ( ).
Example: Example: S=S= (A) (A) ( (B B C C D) D) ( (AA D) D)Clauses are: Clauses are: {A}, {{A}, { B, C, D}, { B, C, D}, { A, D} A, D}
![Page 6: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/6.jpg)
Resolution Theorem ProvingResolution Theorem Proving
Method for searching for proofs automaticallyMethod for searching for proofs automatically
Sentences are translated into CNF, and then to sets of Sentences are translated into CNF, and then to sets of clausesclauses
At each step, a new clause is derived from two clauses At each step, a new clause is derived from two clauses you already haveyou already have
Proof steps all use the same ruleProof steps all use the same rule
If reach If reach (_|_), sentences were not (_|_), sentences were not satisfiablesatisfiableStart: premises + negation of goalStart: premises + negation of goal
End: if reach End: if reach , premises |= goal, premises |= goal
![Page 7: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/7.jpg)
Satisfying a Set of ClausesSatisfying a Set of Clauses
Assigning truth-values to the atomic Assigning truth-values to the atomic sentences so the CNF sentence the set sentences so the CNF sentence the set corresponds to is true.corresponds to is true.
{{A, {{A, C, D}, {C},{C, D}, {C},{A},{A, D}}A},{A, D}} is satisfied by is satisfied by
A = FalseA = False C = True C = True D = True D = True
![Page 8: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/8.jpg)
Empty ClauseEmpty Clause
{} denoted by {} denoted by . �. �The empty clause is not satisfiableThe empty clause is not satisfiableWe want We want {{A}, {{{A}, { A}} A}} to lead to to lead to {}{} ( ( ��))The basic resolution step involves “canceling” The basic resolution step involves “canceling” pos and neg matching literals from two clausespos and neg matching literals from two clauses
So, we derive So, we derive {}{} ( ( ��) from ) from {{A}, {{{A}, { A}} A}}
![Page 9: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/9.jpg)
Example: not satisfiableExample: not satisfiable
P P Q Q PP
{P, Q} {P}
{Q}
{P, Q} {P} {Q}
![Page 10: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/10.jpg)
Resolution Theorem ProvingResolution Theorem Proving
Method for searching for proofs automaticallyMethod for searching for proofs automatically
Sentences are translated into CNF, and then to Sentences are translated into CNF, and then to sets of clausessets of clauses
At each step, a new clause is derived from two At each step, a new clause is derived from two clauses you already haveclauses you already have
Proof steps all use the same ruleProof steps all use the same ruleIf reach If reach (_|_), sentences were not satisfiable (_|_), sentences were not satisfiable
Start: premises + negation of goalStart: premises + negation of goal
End: if reach End: if reach , premises |= goal, premises |= goal
![Page 11: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/11.jpg)
Resolution StepResolution Step
![Page 12: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/12.jpg)
Res. Step with Larger ClausesRes. Step with Larger Clauses
![Page 13: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/13.jpg)
ResolventResolvent
Clause R is a resolvent of clauses CClause R is a resolvent of clauses C11 and and
CC22 if there is a literal in C if there is a literal in C11 whose negation whose negation
is in Cis in C22 and R consists of all the remaining and R consists of all the remaining
literals in either clause.literals in either clause.
Example:Example: {A,{A, C C , , D} D} andand {B, {B, CC} } havehave
resolventresolvent { {A, B, A, B, DD}}
![Page 14: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/14.jpg)
Resolution Theorem ProvingResolution Theorem Proving
Method for searching for proofs automaticallyMethod for searching for proofs automaticallySentences are translated into CNF, and then to Sentences are translated into CNF, and then to sets of clausessets of clausesAt each step, a new clause is derived from two At each step, a new clause is derived from two clauses you already haveclauses you already haveProof steps all use the same ruleProof steps all use the same rule
If reach If reach (_|_), sentences were not (_|_), sentences were not satisfiablesatisfiableStart: premises + negation of goalStart: premises + negation of goalEnd: if reach End: if reach , premises |= goal, premises |= goal
![Page 15: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/15.jpg)
Resolution TheoremResolution Theorem
For any set of clauses that are For any set of clauses that are not not satisfiablesatisfiable, it is possible to arrive at the , it is possible to arrive at the empty clause by using successive empty clause by using successive resolutions.resolutions.
![Page 16: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/16.jpg)
Resolution Theorem ProvingResolution Theorem Proving
Method for searching for proofs automaticallyMethod for searching for proofs automatically
Sentences are translated into CNF, and then to sets of Sentences are translated into CNF, and then to sets of clausesclauses
At each step, a new clause is derived from two clauses At each step, a new clause is derived from two clauses you already haveyou already have
Proof steps all use the same ruleProof steps all use the same rule
If reach If reach (_|_), sentences were not satisfiable (_|_), sentences were not satisfiable
Start: premises + negation of goalStart: premises + negation of goal
End: if reach End: if reach , premises |= goal, premises |= goal
![Page 17: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/17.jpg)
Using Resolution to Determine Validity of Using Resolution to Determine Validity of ArgumentsArguments
QQ is a logical consequence of is a logical consequence of P1, P2, …, P1, P2, …, Pn Pn iff iff P1 ^ P2 ^ … ^ PnP1 ^ P2 ^ … ^ Pn ^ ~Q^ ~Q is not is not satisfiablesatisfiableFor sentences in clausal form: For sentences in clausal form: Q Q is a logical consequence of a set of is a logical consequence of a set of clauses clauses SS iff iff SS { {Q} Q} is not satisfiable.is not satisfiable.
So, convert premises + negation of goal to So, convert premises + negation of goal to clausal form, and do resolution steps, trying to clausal form, and do resolution steps, trying to reach {} (reach {} () �) �
![Page 18: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/18.jpg)
Is this Argument Valid?Is this Argument Valid?
B v C~C v ~DA v D~B v ~DA
![Page 19: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/19.jpg)
ExampleExample
Show Show A A (B (B C) C) ( (C C D) D) (A (A D) D) ( (B B D)D) is not is not satisfiable.satisfiable.
Clauses: Clauses: {{ A}, {B, C}, { A}, {B, C}, {C, C, D}, {A, D}, {D}, {A, D}, {B, B, D}.D}.
{ {AA} {} {AA,D} {B,,D} {B,CC} {} {CC, , D}D}
{ {DD} {} {BB, , D} {D} {BB, , D}D}
{ {DD}}
��
![Page 20: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/20.jpg)
ExampleExample
Modus PonesModus PonesPPQ Q PPQ or {Q or {P,Q}P,Q}
P P {P}{P}
Q negate to get Q negate to get {{Q}Q}
Apply resolution: Apply resolution: {{PP,Q} {,Q} {PP}}
{ {QQ} {} {QQ}}
![Page 21: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/21.jpg)
What is a Horn sentence?What is a Horn sentence?
A A positive literalpositive literal is any literal that is not is any literal that is not preceded with a preceded with a . . For example, Cube(b) For example, Cube(b) and P are positive literals.and P are positive literals.
A sentence S is a A sentence S is a Horn sentenceHorn sentence if and if and only if it is only if it is in CNFin CNF and every conjunct has and every conjunct has at most one positive literal.at most one positive literal.
![Page 22: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/22.jpg)
ExamplesExamples
(A (A B B C) C) ( (A A B)B)
(A (A B B C) C) (D) (D)
(A (A B) B) ( (C C D)D)
Horn sentence
Not Horn sentence
(A C) (B C) (A D) (B D)
Horn sentence
![Page 23: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/23.jpg)
Alternate Form of Horn Alternate Form of Horn ConjunctConjunct
AA11 AA22...... AAnn B B
(A1 A2 ... An) B
(A1 A2 ... An) B Conditional Formof
Horn sentence
B :- A1, A2, …, An. In Prolog:
Rule
B if A1, A2, …, An
![Page 24: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/24.jpg)
Special CasesSpecial Cases
No positive literalNo positive literalAA11 AA22...... AAnn
No negative literalsNo negative literalsBB
(A1 A2 ... An) False
True BIn Prolog, this
is a fact!
In Prolog, thisis a query!
![Page 25: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/25.jpg)
Why are Horn sentences Why are Horn sentences important?important?
Very efficient algorithms exist for determining if a Very efficient algorithms exist for determining if a set of Horn sentences is satisfiableset of Horn sentences is satisfiable
![Page 26: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/26.jpg)
CNF to PROLOGCNF to PROLOG
A A B B C is C is (A(AC) C) B is (A B is (A C) C)B B
B :- A, C.B :- A, C.A.A.C.C.
Query: :- B.Query: :- B.Answer: Yes.Answer: Yes.
![Page 27: CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences](https://reader030.vdocuments.mx/reader030/viewer/2022032705/56649dc95503460f94abf234/html5/thumbnails/27.jpg)
Example Prolog ProgramExample Prolog Program
grandfather(X,Y) :-grandfather(X,Y) :- father(X,Z), father(X,Z), father(Z,Y). father(Z,Y).
grandfather(X,Y) :-grandfather(X,Y) :- father(X,Z), father(X,Z), mother(Z,Y). mother(Z,Y).
mother(ann,bill).mother(ann,bill).father(carl,ed).father(carl,ed).father(nick,ann).father(nick,ann).father(ed,sam).father(ed,sam).