CS228 Logic for Computer Science 2020 Lecture 7: Conjunctive

CS228 Logic for Computer Science 2020 Lecture 7: Conjunctive

CS228 Logic for Computer Science 2020 Lecture 7: Conjunctive Normal Form Instructor: Ashutosh Gupta IITB, India Compile date: 2020-02-01 cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 1 Removing ⊕, ), and ,. We have seen equivalences that remove ⊕, ), and , from a formula. I (p ) q) ≡ (:p _ q) I (p ⊕ q) ≡ (p _ q) ^ (:p _:q) I (p , q) ≡ :(p ⊕ q) In the lecture, we will assume you can remove them at will. Commentary: Note that removal of ⊕ and , blows up the formula size. Their straight up removal is not desirable. cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 2 Topic 7.1 Negation normal form cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 3 Negation normal form(NNF) Definition 7.1 A formula is in NNF if : appears only in front of the propositional variables. Theorem 7.1 For every formula F , there is a formula F 0 in NNF such that F ≡ F 0. Proof. Due to the equivalences, we can always push : under the connectives I Often we assume that the formulas are in NNF. I However, there are negations hidden inside ⊕, ), and ,. Sometimes, the symbols are also expected to be removed while producing NNF Exercise 7.1 Write an efficient algorithm to convert a propositional formula to NNF? Commentary: In our context, we will not ask one to remove e ⊕, ), and , during conversion to NNF. cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 4 Example :NNF Example 7.1 Consider :(q ) ((p _:s) ⊕ r)) ≡ q ^ :((p _:s) ⊕ r) ≡ q ^ (:(p _:s) ⊕ r) ≡ q ^ ((:p ^ ::s) ⊕ r) ≡ q ^ ((:p ^ s) ⊕ r) Exercise 7.2 Convert the following formulas into NNF I :(p ) q) I :(:((s ):(p , q))) ⊕ (:q _ r)) Exercise 7.3 Remove ), ,, and ⊕ before turning the above into NNF. Exercise 7.4 Are there any added difficulties if the formula is given as a DAG not as a tree? cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 5 Formal derivation for NNF Theorem 7.2 Let F 0 be the NNF of F . If we have Σ ` F , then we can derive Σ ` F 0. Proof. We combine the following pieces of proofs for each step of the transformation. I Derivations for Substitutions. I Derivations for pushing negations inside connectives. Therefore, we have the derivations. cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 6 Topic 7.2 Conjunctive normal form cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 7 Some terminology I Propositional variables are also referred as atoms I A literal is either an atom or its negation I A clause is a disjunction of literals. Since _ is associative, commutative and absorbs multiple occurrences, a clause may be referred as a set of literals Example 7.2 I p is an atom but :p is not. I :p and p both are literals. I p _:p _ p _ q is a clause. I fp; :p; qg is the same clause. cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 8 Conjunctive normal form(CNF) Definition 7.2 A formula is in CNF if it is a conjunction of clauses. Since ^ is associative, commutative and absorbs multiple occurrences, a CNF formula may be referred as a set of clauses Example 7.3 I :p and p both are in CNF. I (p _:q) ^ (r _:q) ^ :r in CNF. I f(p _:q); (r _:q); :rg is the same CNF formula. I ffp; :qg; fr; :qg; f:rgg is the same CNF formula. Exercise 7.5 Write a formal grammar for CNF cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 9 Attendance quiz Which of the following formulas are in CNF? p, :p, p _:p, p _ q , p ^ q , :p ^ q,(p _ q) ^ p,(p _ q) ^ (:p ^ q), (p _ q) ^ (:p _ q), (p ^ q) ^ (:p ^ q)(p _ q) _ (:p _ q), :(p _ q), p ⊕ q, p ) q, p , q,(p ^ q) _ r,(p ^ q) _ (:p _ q), (p _ q) _ (:p ^ r), (p ^ q) _ (:p ^ r), :(p ^ q), cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 10 CNF conversion Theorem 7.3 For every formula F there is another formula F 0in CNF s.t. F ≡ F 0. Proof. Let us suppose we have I removed ⊕, ), , using the standard equivalences, I converted the formula in NNF with removal of ), ,, and ⊕, and I flattened ^ and _. Now the formulas have the following form with literals at leaves. _ After the push formula :: ^ size grows! Why should :: _ :: :: :: the procedure terminate? Since _ distributes over ^, we can always push _ inside ^. Are we done? Eventually, we will obtain a formula that is CNF. Commentary: The above is a good example of an algorithm that has intuitively clear, but formally non-trivial termination argument. cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 11 CNF conversion terminates Theorem 7.4 The procedure of converting a formula in CNF terminates. Proof. For a formula F , let ν(F ) , the maximum height of _ to ^ alternations in F . Consider a formula F (G) such that m ni _ ^ G = Gij : i=0 j=0 After the push we obtain F (G 0), where n1 nm m 0 ^ ^ _ G = ::: Giji j1=0 jm=0 i=0 | {z } ν()<ν(G) Observations I G 0 is either the top formula or the parent connective(s) are ^ I Gij is either a literal or an _ formula 0 We need to apply flattening to keep F (G ) in the form(of the previous slide). ... cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 12 CNF conversion terminates (contd.) (contd.) Due to K¨oinglemma, the procedure terminates.(why?) Exercise 7.6 Consider a set of balls that are labelled with positive numbers. We can replace a k labelled ball with any number of balls with labels less than k. Using K¨oinglemma, show that the process always terminates. Hint: in the above exercise, the bag is the subformulas of F (G). cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 13 CNF examples Example 7.4 Consider (p ) (:q ^ r)) ^ (p ):q) ≡ (:p _ (:q ^ r)) ^ (:p _:q) ≡ ((:p _:q) ^ (:p _ r)) ^ (:p _:q) ≡ (:p _:q) ^ (:p _ r) ^ (:p _:q) Exercise 7.7 Convert the following formulas into CNF 1. :((p ) q) ) ((q ) r) ) (p ) r))) 2.( p ) (:q ) r)) ^ (p ):q) ) (p ) r) cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 14 Formal derivation for CNF Theorem 7.5 Let F 0 be the CNF of F . If we have Σ ` F , then we can derive Σ ` F 0. Proof. We combine the following pieces of proofs for each step of the transformations. I Derivations for NNF I Derivations for substitutions that removes ), ⊕, and , I Derivations for substitutions that flattens ^ and _ I Derivations for substitutions that applies distributivity Therefore, we have the derivations. cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 15 Conjunctive normal form(CNF) more notation I A unit clause contains only one literal. I A binary clause contains two literals. I A ternary clause contains three literals. I We naturally extend definition of the clauses to the empty set of literals. We refer to ? as empty clause. Example 7.5 I (p ^ q ^ :r) has three unit clauses I (p _:q _:s) ^ (p _ q) ^ :r has a ternary, a binary and a unit clause Exercise 7.8 a. Show F 0 obtained from the procedure may be exponentially larger than F b. Give a linear time algorithm to prove validity of a CNF formula c. What is the interpretation of empty set of clauses? cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 16 CNF is desirable I Fewer connectives I Simple structure I Many problems naturally encode into CNF. We will see this in couple of lectures. cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 17 How do we get to CNF? I The transformation using distributivity explodes the formula I Is there a way to avoid the explosion? I Yes! there is a way. Tseitin's encoding But, with a cost. cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 18 Tseitin's encoding (Plaisted-Greenbaum optimization included) We can translate every formula into CNF without exponential explosion using Tseitin's encoding by introducing fresh variables. 1. Assume input formula F is NNF without ⊕, ), and ,. 2. Find a G1 ^ · · · ^ Gn that is just below a _ in F (G1 ^ · · · ^ Gn) 3. Replace F (G1 ^ :: ^ Gn) by F (p) ^ (:p _ G1) ^ :: ^ (:p _ Gn), where p is a fresh variable 4. goto 2 Exercise 7.9 Modify the encoding such that it works without the assumptions at step 1 Commentary: Hint: Download sat solver $wget http://fmv.jku.at/limboole/limboole1.1.tar.gz look for function tseitin in file limboole.c cbna CS228 Logic for Computer Science 2020 Instructor: Ashutosh Gupta IITB, India 19 Example: linear cost of Tseitin's encoding Example 7.6 Consider formula (p1 ^ · · · ^ pn) _ (q1 ^ · · · ^ qm) Using distributivity, we obtain the following CNF containing mn clauses. ^ (pi _ qj ) i21::n;j21::m Using Tseitin's encoding, we obtain the following CNF containing m + n + 1 clauses, where x and y are the fresh Boolean variables.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    37 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us