conjunctive normal form horn clauses
play

Conjunctive Normal Form & Horn Clauses York University CSE 3401 - PowerPoint PPT Presentation

Conjunctive Normal Form & Horn Clauses York University CSE 3401 Vida Movahedi 1 York University CSE 3401 V. Movahedi Overview Overview Definition of literals, clauses, and CNF , , Conversion to CNF Propositional logic


  1. Conjunctive Normal Form & Horn Clauses York University CSE 3401 Vida Movahedi 1 York University ‐ CSE 3401 ‐ V. Movahedi

  2. Overview Overview • Definition of literals, clauses, and CNF , , • Conversion to CNF ‐ Propositional logic • Representation of clauses in logic programming • Representation of clauses in logic programming • Horn clauses and Programs – Facts – Facts – Rules – Queries (goals) • Conversion to CNF ‐ Predicate logic [ref.: Clocksin ‐ Chap. 10 and Nilsson ‐ Chap. 2] 2 York University ‐ CSE 3401 ‐ V. Movahedi

  3. Conjunctive Normal Form Conjunctive Normal Form • A literal is either an atomic formula (called a positive ( p literal) or a negated atomic formula (called a negated literal) – e.g. p, ¬q e.g. p, q • A clause is – A literal, or – Disjunction of two or more literals, or – The empty clause, shown as □ , : ‐ or {} ∨ ¬ ∨ – e.g. p, p q r • A formula α is said to be in Conjunctive Normal Form (CNF) if it is the conjunction of some number of clauses 3 York University ‐ CSE 3401 ‐ V. Movahedi

  4. CNF (example) CNF (example) ∨ ∨ ∧ ∧ ∨ ∨ ¬ ¬ ∨ ∨ ∧ ∧ ¬ ¬ ∨ ∨ ( ( ) ) ( ( ) ) ( ( ) ) p p q q q q s s r r r r t t ˄ ˅ ˅ ˅ p q q ¬s r ¬r t 4 York University ‐ CSE 3401 ‐ V. Movahedi

  5. CNF ‐ Facts CNF Facts • For every formula α of propositional logic, there For every formula α of propositional logic, there exists a formula A in CNF such that α≡ A is a tautology • A polynomial algorithm exists for converting α to A • A polynomial algorithm exists for converting α to A • For practical purposes, we use CNFs in Logic Programming i 5 York University ‐ CSE 3401 ‐ V. Movahedi

  6. Conversion to CNF Conversion to CNF 1. Remove implication and equivalence p q Example: Example: → ⇒ ¬ ∨ ( ) ( ) – Use p q p q ≡ ∧ ( ) p r s ≡ ⇒ → ∧ → ( ) ( ) ( ) p q p q q p ⇒ ⇒ ¬ ∨ ∨ ∧ ∧ ∧ ∧ ⇒ ¬ ∨ ∧ ¬ ∨ ( ( ( ( )) )) p p r r s s ( ( ) ) ( ( ) ) p q q p ¬ ∧ ∨ ( ( ) ) r s p 2. Move negations inwards ⇒ ⇒ ¬ ∨ ∨ ∧ ∧ ( ( ) ) p p r r Use De Morgan’s U D M ’ – ¬ ∧ ⇒ ¬ ∨ ¬ ¬ ∨ ∧ ( ) ( ) p q p q ( ) p s ¬ ¬ ∨ ∨ ⇒ ⇒ ¬ ¬ ∧ ∧ ¬ ¬ ( ( ) ) ( ( ) ) ¬ ∨ ∨ ¬ ∨ ∨ p p q q p p q q ( ( ) ) r s p 3. Distribute OR over AND ∨ ∨ ∧ ∧ ⇒ ⇒ ∨ ∨ ∧ ∧ ∨ ∨ ( ( ) ) ( ( ) ) ( ( ) ) p p q q r r p p q q p p r r 6 York University ‐ CSE 3401 ‐ V. Movahedi

  7. Representing a clause Representing a clause ¬ ∨ ∨ ¬ ∨ • Consider this clause: Consider this clause: p p q q r s ¬ ∧ ∨ ∨ ⇒ ∧ → ∨ • It can be written as: ( ) ( ) ( ) p r q s p r q s • In Logic programming, it is shown as: ∨ ← ← ∧ ( ( ) ) ( ( ) ) q q s s p p r − ; : , . q s p r • Easy way: positive literals on the left, negative literals on the right 7 York University ‐ CSE 3401 ‐ V. Movahedi

  8. Logic Programming Clause Logic Programming Clause • A clause in the form: A clause in the form: − ; ;...; : , ,..., . p p p q q q 1 2 1 2 m n is equivalent to: is equivalent to: ∨ ∨ ∨ ∨ ¬ ∨ ¬ ∨ ∨ ¬ ... ... p p p q q q 1 2 1 2 m n ∧ ∧ ∧ ∧ ∧ ∧ → → ∨ ∨ ∨ ∨ ∨ ∨ or or ... ... q q q q q q p p p p p p 1 2 1 2 n m ∧ ∧ ∧ ∧ ∧ ∧ ... q q q q q q if if is true, then at least one of is true then at least one of 1 2 n , ,..., p p p is true. 1 2 m 8 York University ‐ CSE 3401 ‐ V. Movahedi

  9. Another Example Another Example Write the following expression as Logic Programming Clauses: Write the following expression as Logic Programming Clauses: ( ( ) ) ∧ → ∨ ∧ → ( ) ( ) p s r q r t ( ( ( ( ) ) ) ) 1 Conversion to CNF: 1 ‐ Conversion to CNF: ⇒ ∧ ¬ ∨ ∨ ∧ ¬ ∨ ( ) ( ) p s r q r t ⇒ ∨ ∧ ¬ ∨ ∨ ∧ ¬ ∨ ( ) ( ) ( ) p q s r q r t 2 ‐ Symmetry of ˄ allows for sets notation { } ∨ ¬ ∨ ∨ ¬ ∨ of a CNF ( ), ( ), ( ) p q s r q r t 3 ‐ Symmetry of ˅ 3 S t f ˅ { { } { } { } } ¬ ¬ , , , , , , p q q s r r t allows for set notation of clauses − − − ; : . ; : . : . p q q r s t r 4 ‐ As Logic Prog. 9 York University ‐ CSE 3401 ‐ V. Movahedi

  10. Horn Clause Horn Clause • A Horn clause is a clause with at most one positive A Horn clause is a clause with at most one positive literal: – Rules “head: ‐ body.” e.g. p 1 : ‐ q 1 , q 2 , ..., q n . – Facts “head : ‐ .” e.g. p 2 : ‐ . – Queries (or goals) “: ‐ body.” Queries (or goals) : body. e.g. : ‐ r 1 , r 2 , ..., r m . e.g. : r 1 , r 2 , ..., r m . • Horn clauses simplify the implementation of logic H l i lif h i l i f l i programming languages and are therefore used in Prolog. 10 York University ‐ CSE 3401 ‐ V. Movahedi

  11. A Program A Program • A logic programming program P is defined as a finite A logic programming program P is defined as a finite set of rules and facts. – For example, P={p: ‐ q,r., q: ‐ ., r: ‐ a., a: ‐ .} rule1 fact1 rule2 fact2 • Rules and facts (with exactly one positive literal) are called definite clauses and therefore a program defined called definite clauses and therefore a program defined by them is called a definite program. 11 York University ‐ CSE 3401 ‐ V. Movahedi

  12. Query Query • A computational query (or goal) is the conjunction of some p q y ( g ) j ∧ ∧ ∧ positive literals (called subgoals) , e.g. ... r r r 1 2 n • A query is deductible from P if it can be proven on the basis − ∧ ∧ ∧ | ... P r r r of P: 1 2 n − : , ,..., . r r r • Note this query is written as 1 2 n ¬ ∨ ¬ ∨ ∨ ¬ ¬ ∧ ∧ ∧ which is or ... ( ... ) r r r r r r 1 2 1 2 n n • Why? In logic programming theorem proving is used to answer queries: { } − ∧ ∧ ∧ ¬ ∧ ∧ ∧ iff U is inconsistent | ... ( ... ) P r r r P r r r 1 2 1 2 n n 12 York University ‐ CSE 3401 ‐ V. Movahedi

  13. Example Example • P: { p: ‐ q. , q: ‐ .} P: { p: q. , q: .} • If we want to know about p, we will ask the query: : ‐ p. • Note that the set { p: ‐ q., q: ‐ ., : ‐ p.} is inconsistent. Note that the set { p: q., q: ., : p.} is inconsistent. (Reminder: truth table for above clauses does not have even one row where all the clauses are true) • Therefore p is provable and your theorem proving program (e.g. Prolog) will return true . program (e.g. Prolog) will return true . 13 York University ‐ CSE 3401 ‐ V. Movahedi

  14. Predicate Logic Clauses Predicate Logic Clauses • Same definition for literals, clauses, and CNF except Same definition for literals, clauses, and CNF except now each literal is more complicated since an atomic formula is more complicated in predicate logic • We need to deal with quantifiers and their object d d l i h ifi d h i bj variables when converting to CNF 14 York University ‐ CSE 3401 ‐ V. Movahedi

  15. Conversion to CNF in Predicate Logic Conversion to CNF in Predicate Logic 1. Remove implication and equivalence p q 2. Move negations inwards ¬ ∃ ∃ ≡ ≡ ∀ ∀ ¬ ( ( ) ) ( ( ) ) ( ( ) ) ( ( ) ) Note Note x x p p x x x x p p x x 3. Rename variables so that variables of each quantifier are unique 4. Move all quantifiers to the front (Prenex Normal Form) q ( ) 15 York University ‐ CSE 3401 ‐ V. Movahedi

  16. Conversion to CNF (cont.) Conversion to CNF (cont.) 5. Skolemizing (get rid of existential quantifiers) g (g q ) 5. Skolem constants ∃ ∧ ⇒ ∧ (( ) ( ) ( , )) ( 1 ) ( 1 , ) X female X motherof X eve female g motherof g eve 6 6. Skolem functions Skolem functions ∀ ∃ ¬ ∨ ( )( ) ( ) ( , ) X Y human X motherof X Y ⇒ ∀ ¬ ∨ ( ( ) ) ( ( ) ) ( ( , , 2 ( ( )) )) X human X motherof f X g g X 6. Distribute OR over AND to have conjunctions of disjunctions as the body of the formula j y 7. Remove all universal quantifiers 16 York University ‐ CSE 3401 ‐ V. Movahedi

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend