Logica (I&E) najaar 2018 - - PowerPoint PPT Presentation

logica i e
SMART_READER_LITE
LIVE PREVIEW

Logica (I&E) najaar 2018 - - PowerPoint PPT Presentation

Logica (I&E) najaar 2018 http://liacs.leidenuniv.nl/~vlietrvan1/logica/ Rudy van Vliet kamer 140 Snellius, tel. 071-527 2876 rvvliet(at)liacs(dot)nl college 7, maandag 15 oktober 2018 1.5. Normal forms De punten moeten daar op de i gezet


slide-1
SLIDE 1

Logica (I&E)

najaar 2018 http://liacs.leidenuniv.nl/~vlietrvan1/logica/ Rudy van Vliet kamer 140 Snellius, tel. 071-527 2876 rvvliet(at)liacs(dot)nl college 7, maandag 15 oktober 2018 1.5. Normal forms De punten moeten daar op de i gezet worden, waar ze horen.

1

slide-2
SLIDE 2

1.5. Normal forms

Alternatives for deciding φ1, φ2, . . . , φn ψ

2

slide-3
SLIDE 3

1.5.1. Semantic equivalence, satisfiability and validity

Definition 1.40. Let φ and ψ be formulas of propositional logic. We say that φ and ψ are semantically equivalent iff φ ψ and ψ φ hold. In that case we write φ ≡ ψ. Further, we call φ valid if φ holds, i.e., if φ is a tautology.

3

slide-4
SLIDE 4

A slide from lecture 4:

1.2.4 Provable equivalence

Definition 1.25. Let φ and ψ be formulas of propositional logic. We say that φ and ψ are provably equivalent, if and only if the sequents φ ⊢ ψ and ψ ⊢ φ are valid; Notation: φ ⊣⊢ ψ

4

slide-5
SLIDE 5

Example. p → q ≡ ¬q → ¬p p → q ≡ ¬p ∨ q p ∧ q → p ≡ r ∨ ¬r p ∧ q → r ≡ p → (q → r)

5

slide-6
SLIDE 6

Lemma 1.41. Given formules φ1, φ2, . . . , φn and ψ of proposi- tional logic, φ1, φ2, . . . , φn ψ holds iff φ1 → (φ2 → (φ3 → (. . . (φn → ψ) . . .)))

  • Proof. . .

6

slide-7
SLIDE 7

A slide from lecture 5:

Step 1:

If φ1, φ2, . . . , φn ψ is valid, then Step 1: φ1 → (φ2 → (φ3 → (. . . (φn → ψ) . . .))) Step 2: ⊢ φ1 → (φ2 → (φ3 → (. . . (φn → ψ) . . .))) Step 3: φ1, φ2, . . . , φn ⊢ ψ

7

slide-8
SLIDE 8

Conjunctive Normal Form

Example. (¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q (p ∨ r) ∧ (¬p ∨ r) ∧ (p ∨ ¬r)

8

slide-9
SLIDE 9

Example. (¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q (p ∨ r) ∧ (¬p ∨ r) ∧ (p ∨ ¬r) Definition 1.42. A literal L is either an atom p or the negation of an atom: ¬p. A formula C is in conjunctive normal form (CNF) if it is a conjunction of clauses, where each clause D is a disjunction of literals.

9

slide-10
SLIDE 10

Definition 1.42. A literal L is either an atom p or the negation of an atom: ¬p. A formula C is in conjunctive normal form (CNF) if it is a conjunction of clauses, where each clause D is a disjunction of literals. C ::= D | D ∧ C D ::= L | L ∨ D L ::= p | ¬p

10

slide-11
SLIDE 11

Is (¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q valid?

11

slide-12
SLIDE 12

Is (¬q ∨ p ∨ r) valid?

12

slide-13
SLIDE 13

Lemma 1.43. A disjunction of literals L1 ∨ L2 ∨ · · · ∨ Lm is valid, iff there are 1 ≤ i, j ≤ m such that Li is ¬Lj.

  • Proof. . .

13

slide-14
SLIDE 14

Lemma 1.43. A disjunction of literals L1 ∨ L2 ∨ · · · ∨ Lm is valid, iff there are 1 ≤ i, j ≤ m such that Li is ¬Lj. Hence, a formula φ in CNF is valid, iff . . .

14

slide-15
SLIDE 15

Definition 1.44. Given a formula φ in propositional logic, we say that φ is satisfi- able if it has a valuation in which it evaluates to T.

15

slide-16
SLIDE 16

A slide from lecture 6a:

3.3. Consistentie

Semantisch consistent Definitie 3.2. Een formuleverzameling Σ = {φ1, . . . , φn} is (semantisch) consistent als Σ (minstens) een model heeft. We zeggen ook dat Σ vervulbaar is. Inconsistent

16

slide-17
SLIDE 17

Definition 1.44. Given a formula φ in propositional logic, we say that φ is satisfi- able if it has a valuation in which it evaluates to T. Proposition 1.45. Let φ be a formula of propositional logic. Then φ is satisfiable, iff ¬φ is not valid.

  • Proof. . .

17

slide-18
SLIDE 18

Constructing CNF from truth table

Example. p q r φ T T T T T T F F T F T T T F F T F T T F F T F F F F T F F F F T

18

slide-19
SLIDE 19

1.5.2. Conjunctive normal forms and va- lidity

Transform φ into an equivalent formula ψ in CNF For each input φ, deterministic algorithm CNF (1) terminates, (2) outputs equivalent formula ψ (3) which is in CNF

19

slide-20
SLIDE 20

Step 1: Eliminate implications

Use ψ → η ≡ ¬ψ ∨ η (recursively) IMPL FREE( r → (s → (t ∧ s → r)) )

20

slide-21
SLIDE 21

Step 2: Negation normal form

Use De Morgan: ¬(φ1 ∧ φ2) ≡ ¬φ1∨ φ2 ¬(φ1 ∨ φ2) ≡ ¬φ1∧ φ2 (recursively) NNF( ¬r ∨ (¬s ∨ (¬(t ∧ s) ∨ r)) )

21

slide-22
SLIDE 22

Function NNF

function NNF(φ) /* precondition: φ is implication free */ /* postcondition: NNF(φ) computes a NNF for φ */ begin function case φ is a literal: return φ φ is ¬¬φ1: return NNF(φ1) φ is φ1 ∧ φ2: return NNF(φ1) ∧ NNF(φ2) φ is φ1 ∨ φ2: return NNF(φ1) ∨ NNF(φ2) φ is ¬(φ1 ∧ φ2): return NNF(¬φ1) ∨ NNF(¬φ2) φ is ¬(φ1 ∨ φ2): return NNF(¬φ1) ∧ NNF(¬φ2) end case end function

22

slide-23
SLIDE 23

Step 2: Negation normal form

Use De Morgan: ¬(φ1 ∧ φ2) ≡ ¬φ1∨ φ2 ¬(φ1 ∨ φ2) ≡ ¬φ1∧ φ2 (recursively) Example. NNF( ¬(¬p ∧ q) ∨ (p ∧ (¬r ∨ q)) )

23

slide-24
SLIDE 24

Step 3: CNF

CNF(p) = . . . CNF(¬p) = . . . CNF(φ1 ∧ φ2) = . . . CNF(φ1 ∨ φ2) = . . .

24

slide-25
SLIDE 25

Step 3: CNF

CNF(p) = p CNF(¬p) = ¬p CNF(φ1 ∧ φ2) = CNF(φ1) ∧ CNF(φ2) CNF(φ1 ∨ φ2) = . . . Example. CNF(φ1) = (p ∨ q ∨ r) ∧ (¬p ∨ p ∨ q) CNF(φ2) = (r ∨ ¬q) ∧ (¬q ∨ ¬r ∨ ¬p)

25

slide-26
SLIDE 26

Step 3: CNF

CNF(p) = p CNF(¬p) = ¬p CNF(φ1 ∧ φ2) = CNF(φ1) ∧ CNF(φ2) CNF(φ1 ∨ φ2) = DISTR(CNF(φ1), CNF(φ2))

26

slide-27
SLIDE 27

Step 3: CNF

Use distributivity: (η11 ∧ η12) ∨ η2 ≡ (η11 ∨ η2) ∧ (η12 ∨ η2) η1 ∨ (η21 ∧ η22) ≡ (η1 ∨ η21) ∧ (η1 ∨ η22) (recursively)

27

slide-28
SLIDE 28

Use distributivity: (η11 ∧ η12) ∨ η2 ≡ (η11 ∨ η2) ∧ (η12 ∨ η2) η1 ∨ (η21 ∧ η22) ≡ (η1 ∨ η21) ∧ (η1 ∨ η22) (recursively) function DISTR(η1, η2) /* precondition: η1 and η2 are in CNF */ /* postcondition: DISTR(η1, η2) computes a CNF for η1 ∨ η2 */ begin function case η1 is η11 ∧ η12: return DISTR(η11, η2) ∧ DISTR(η12, η2) η2 is η21 ∧ η22: return DISTR(η1, η21) ∧ DISTR(η1, η22)

  • therwise (= no conjunctions): return η1 ∨ η2

end case end function

28

slide-29
SLIDE 29

function CNF(φ) /* precondition: φ implication free and in NNF */ /* postcondition: CNF(φ) computes an equivalent CNF for φ */ begin function case φ is a literal: return φ φ is φ1 ∧ φ2: return CNF(φ1) ∧ CNF(φ2) φ is φ1 ∨ φ2: return DISTR(CNF(φ1), CNF(φ2)) end case end function Example. CNF( (p ∨ ¬q) ∨ (p ∧ (¬r ∨ q)) )

29

slide-30
SLIDE 30

1.5.3. Horn clauses and satisfiability

Example. (p ∧ q ∧ s → p) ∧ (q ∧ r → p) ∧ (p ∧ s → s)

30

slide-31
SLIDE 31

1.5.3. Horn clauses and satisfiability

Example. (p ∧ q ∧ s → p) ∧ (q ∧ r → p) ∧ (p ∧ s → s) (p2 ∧ p3 ∧ p5 → p13) ∧ (⊤ → p5) ∧ (p5 ∧ p11 → ⊥)

31

slide-32
SLIDE 32

Not Horn formulas

(p ∧ q ∧ s → ¬p) ∧ (q ∧ r → p) ∧ (p ∧ s → s) (p2 ∧ p3 ∧ p5 → p13 ∧ p27) ∧ (⊤ → p5) ∧ (p5 ∧ p11 ∨ ⊥)

32

slide-33
SLIDE 33

From CNF to Horn formula

(¬r ∨ ¬p) ∧ (¬p ∨ q ∨ r)

33

slide-34
SLIDE 34

From CNF to Horn formula

(¬r ∨ ¬p) ∧ (¬p ∨ q ∨ r) ∧ r

34

slide-35
SLIDE 35

Definition 1.46. A Horn formula is a formula φ of propositional logic that can be generated from H in this grammar: H ::= C | C ∧ H C ::= A → P A ::= P | P ∧ A P ::= p | ⊥ | ⊤

35

slide-36
SLIDE 36

Deciding satisfiability for Horn formulas

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 all Pj are marked but P ′ is not do mark P ′ end while if ⊥ is marked then return ‘unsatisfiable’ else return ‘satisfiable’ end function

36

slide-37
SLIDE 37

Exercise 1.5: 15. Apply algorithm HORN to each of these Horn formulas: (a) (p∧q∧w → ⊥)∧(t → ⊥)∧(r → p)∧(⊤ → r)∧(⊤ → q)∧(u → s)∧(⊤ → u)

37