formale methoden der informatik introduction and a short ... · types of logics interesting for cs...

59
Formale Methoden der Informatik Introduction and a Short Review of Propositional Logic Uwe Egly Vienna University of Technology Institute of Information Systems Knowledge-Based Systems Group

Upload: others

Post on 23-Jan-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Formale Methoden der InformatikIntroduction and a

Short Review of Propositional Logic

Uwe Egly

Vienna University of TechnologyInstitute of Information Systems

Knowledge-Based Systems Group

Page 2: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Outline

IntroductionMotivationThe Circuit ExampleFormalizing a Logical SystemInductive Definitions Recap

Syntax of PL0Tree Notation of Propositional Formulas

Semantics of PL0NotationsUseful EquivalencesEntailmentChecking Entailment

Satisfiability CheckingTranslation to Normal FormsDLL

Page 3: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Why Logic in CS Studies?

◮ ProgrammingPROLOG, boolean expressions in if-then, assertions, . . .

◮ Languages for and reasoning about specifications,dynamic behavior (temporal logics), consistency, . . .

◮ Knowledge representationWeb ontologies, description logics, reasoning underincomplete/uncertain information, . . .

◮ Hardwarecircuit specification, (automated) verification of circuits, . . .

◮ and much more!!!

Page 4: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Types of Logics Interesting for CS

There is not the logic for CS, but many of them

◮ Besides classical logic, there are non-classical logics◮ minimal and intuitionistic logic (“constructive” logics)◮ modal logics, temporal logics, . . .◮ many-valued logics, fuzzy logics

◮ Many of these logics come in different “levels”◮ Propositional logics (PL0)◮ First-order (PL1): (quantifiers over object variables)◮ Second-order (quantifiers over function/predicate symbols)◮ and even higher-order logics

Page 5: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Example: Correct Implementation of a Circuit

Does the implemented circuit compute specified function

Spec : ((p ∧ q) ∨ r) ∧ (¬(p ∧ q) ∨ s)

&

A1

p

q≥1

O1r

1

N1

≥1

O2s

&

A2

Page 6: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Example: Correct Implementation of a Circuit

Does the implemented circuit compute specified function

Spec : ((p ∧ q) ∨ r) ∧ (¬(p ∧ q) ∨ s)

&

A1

p

q

A1↔ p ∧ q≥1

O1

O1↔ A1 ∨ r

r

1

N1

N1↔ ¬A1≥1

O2s O2↔ N1 ∨ s

&

A2

A2↔ O1 ∧O2

Page 7: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

How to Model and Solve the Problem?

◮ Modeling: Abstract a given problem P into logic PL0 ( P ′)◮ The implemented function Impl is:

Impl = (A1↔ p ∧ q) ∧ (O1↔ A1 ∨ r) ∧ (N1↔ ¬A1) ∧

(O2↔ N1 ∨ s) ∧ (A2↔ O1 ∧O2)→ A2

◮ Is the implementation correct (does Impl comply w. Spec)?◮ P ′ is now a reasoning problem, not a test problem!◮ Proof: Use automatic decision procedures to determine

the solution of P, i.e., compute satisfiability/validity of P ′

◮ SAT Solvers and BDDs◮ Model Checker◮ Theorem Provers

Page 8: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Formalizing a Logical System. . . or the ingredients for an (automated) inference system

◮ Old dream of mankind(at least of some “logicians” like G. W. Leibniz (1646–1716))

◮ What is needed?◮ Syntax (= a formal language for constructing formulas)◮ Semantics (= meaning of formulas)◮ Inference rules (syntacticly derive “correct” statements)◮ Correctness (no false conclusions are drawn)◮ Completeness (all correct conclusions are drawn)

◮ Is this all what we need?

Page 9: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Other Important Questions

◮ Expressive power of the representation language (RL)Are we able to represent our problem in the given RL?

◮ Decidability of the reasoning procedure (on the given RL)Is there a terminating algo providing the correct answer fora given reasoning task?

◮ ComplexityWhat amount of resources (time, space) are required (inthe worst case) to answer the question?

Page 10: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Basic Ideas Underlying Inductive Definitions

◮ Inductive definitions widely used in CS (recursion!!!)◮ Basic idea: given basic set A0 ⊆ B rule f : Bn 7→ B

◮ Incremental construction of sets

Ai+1 = Ai ∪ {f (a1, . . . ,an) |a1, . . . ,an ∈ Ai}

◮ Limes of Ai (when i goes to infinity)

A =⋃

i≥0

Ai

◮ A set A is closed under f , if the following holds:

a1, . . . ,an ∈ A ⇒ f (a1, . . . ,an) ∈ A

Page 11: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Basic Ideas Underlying Inductive Definitions (2)

Schema of the inductive definition

A is the smallest set for which (a) and (b) holds:

(a) A0 ⊆ A

(b) a1, . . . ,an ∈ A ⇒ f (a1, . . . ,an) ∈ A(A is closed under f )

Often simple induction is used:

1. You want to prove ∀n :nat .P(n)(i.e., a property P holds for all natural numbers)

2. You show the base case P(0)

3. In the induction step, you prove ∀n :nat . (P(n)→ P(n + 1))(i.e., if you had a proof of P(n) (induction hypothesis), youcould prove P(n + 1))

Page 12: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Syntax of PL0 (Alternative 1)

◮ Given a countable set, BV, of boolean variables◮ Boolean variables like p,q, r ,p1, . . . represent facts:

e.g., r represents “it is raining”

◮ Use p,q, . . . as metavariables for BVs and φ, ψ, . . . asmetavariables for formulas

◮ Inductive definition of the set of propositional formulas L0

B1: Every p ∈ BV is a formula (called atomic formula or atom)B2: ⊤ (verum) and ⊥ (falsum) are formulasS1: If φ is a formula, then so is (¬φ) (negation)S2: If φ1 and φ2 are formulas, then so are (φ1 ∧ φ2)

(conjunction), (φ1 ∨ φ2) (disjunction), (φ1 → φ2)(implication), (φ1 ↔ φ2) (equivalence) and (φ1 ⊕ φ2)(exclusive-or)

◮ What is A0, f , and A here?

Page 13: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Syntax of PL0 (Alternative 2)

L ::= ⊤ |⊥ |BV | (¬L) | (L∧L) | (L∨L) | (L → L) | (L ↔ L) | (L⊕L)

◮ Read this as: L is the smallest set such that 1. and 2. hold:

1. If p ∈ BV, p is ⊤ or p is ⊥, then p ∈ L2. If φ, ψ ∈ L then

(¬φ), (φ ∧ ψ), (φ ∨ ψ), (φ→ ψ), (φ↔ ψ), (φ⊕ ψ) ∈ L

◮ To save parenthesis, use the following ranking of bindingstrength: ¬, ∧, ∨,→,↔, ⊕ (¬ binds stronger than ∧, etc.)

◮ Example: ¬p ∧ q → r ∨ s means (((¬p) ∧ q)→ (r ∨ s))

Page 14: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Syntax of PL0 Cont’d

◮ A literal is ⊤, ⊥, an atom or the negation thereof◮ A clause is a disjunction of literals◮ Immediate subformula (relation)

◮ φ is an immediate subformula (isf) of ¬φ◮ φ1 and φ2 are isfs of (φ1 ◦ φ2) for ◦ ∈ {∧,∨,→,↔,⊕}

◮ Subformula relation: reflexive-transitive closure of theimmediate subformula relation

◮ Example: all subformulas of ¬p ∧ q → r ∨ s¬p ∧ q → r ∨ s, ¬p ∧ q, r ∨ s, ¬p, q, r , s, p

Page 15: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Syntax of PL0 Cont’d

◮ A literal is ⊤, ⊥, an atom or the negation thereof◮ A clause is a disjunction of literals◮ Immediate subformula (relation)

◮ φ is an immediate subformula (isf) of ¬φ◮ φ1 and φ2 are isfs of (φ1 ◦ φ2) for ◦ ∈ {∧,∨,→,↔,⊕}

◮ Subformula relation: reflexive-transitive closure of theimmediate subformula relation

◮ Example: all subformulas of ¬p ∧ q → r ∨ s¬p ∧ q → r ∨ s, ¬p ∧ q, r ∨ s, ¬p, q, r , s, p

Page 16: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Syntax of PL0 Cont’d

◮ A literal is ⊤, ⊥, an atom or the negation thereof◮ A clause is a disjunction of literals◮ Immediate subformula (relation)

◮ φ is an immediate subformula (isf) of ¬φ◮ φ1 and φ2 are isfs of (φ1 ◦ φ2) for ◦ ∈ {∧,∨,→,↔,⊕}

◮ Subformula relation: reflexive-transitive closure of theimmediate subformula relation

◮ Example: all subformulas of ¬p ∧ q → r ∨ s¬p ∧ q → r ∨ s, ¬p ∧ q, r ∨ s, ¬p, q, r , s, p

Page 17: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Syntax of PL0 Cont’d

◮ A literal is ⊤, ⊥, an atom or the negation thereof◮ A clause is a disjunction of literals◮ Immediate subformula (relation)

◮ φ is an immediate subformula (isf) of ¬φ◮ φ1 and φ2 are isfs of (φ1 ◦ φ2) for ◦ ∈ {∧,∨,→,↔,⊕}

◮ Subformula relation: reflexive-transitive closure of theimmediate subformula relation

◮ Example: all subformulas of ¬p ∧ q → r ∨ s¬p ∧ q → r ∨ s, ¬p ∧ q, r ∨ s, ¬p, q, r , s, p

Page 18: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Syntax of PL0 Cont’d

◮ A literal is ⊤, ⊥, an atom or the negation thereof◮ A clause is a disjunction of literals◮ Immediate subformula (relation)

◮ φ is an immediate subformula (isf) of ¬φ◮ φ1 and φ2 are isfs of (φ1 ◦ φ2) for ◦ ∈ {∧,∨,→,↔,⊕}

◮ Subformula relation: reflexive-transitive closure of theimmediate subformula relation

◮ Example: all subformulas of ¬p ∧ q → r ∨ s¬p ∧ q → r ∨ s, ¬p ∧ q, r ∨ s, ¬p, q, r , s, p

Page 19: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Propositional Formulas as Trees

◮ Formulas can be depicted as formula trees◮ Example: ((p ∧ q)→ r)↔ (p → (q → r))

p q

r

p →

q r

Page 20: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Semantics of PL0

◮ A boolean value (or truth value) is either 0 (false) or 1 (true)

◮ An interpretation function for a set P of boolean variables:

mapping I : P 7→ {0,1}

◮ Interpretation functions are often called truth assignmentse.g., I assigns 1 to p ∈ P, i.e., I(p) = 1

◮ Since we want to “evaluate” formulas under I, we have toextend I to formulas

Page 21: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Extension of I to Formulas

◮ I(⊤) = 1 and I(⊥) = 0◮ I(¬φ) = 1 iff I(φ) = 0◮ I(φ ∧ ψ) = 1 iff I(φ) = I(ψ) = 1◮ I(φ ∨ ψ) = 1 iff I(φ) = 1 or I(ψ) = 1◮ I(φ→ ψ) = 1 iff I(φ) = 0 or I(ψ) = 1◮ I(φ↔ ψ) = 1 iff I(φ) = I(ψ)

◮ I(φ⊕ ψ) = 1 iff I(φ) 6= I(ψ)

Equivalent notations:φ is true under I iff I satisfies φ iff I(φ) = 1 iff I |= φ

φ is false under I iff I does not satisfy φ iff I(φ) = 0 iff I 6|= φ

Page 22: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Truth Tables

◮ Another representation of the extension of I from above◮ One table for each connective (What is the table for ⊕?)

¬

1 00 1

∧ 1 01 1 00 0 0

∨ 1 01 1 10 1 0

→ 1 01 1 00 1 1

↔ 1 01 1 00 0 1

Page 23: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Even More Notations

◮ If I satisfies φ, then we call I a model of φ◮ Mod(ψ) is the set of all models of ψ◮ φ is satisfiable (valid) if φ is true in some (all) interpretations◮ φ is unsatisfiable if φ is false in all interpretations◮ Formulas φ and ψ are equivalent, denoted by φ ≡ ψ, iff

they have exactly the same models, i.e., Mod(φ) = Mod(ψ)

◮ Example: (φ→ ψ) ≡ (¬ψ → ¬φ): Take I ∈ Mod(φ→ ψ)I(φ→ ψ) = 1 iff I(φ) = 0 or I(ψ) = 1

iff I(¬φ) = 1 or I(ψ) = 1iff I(¬φ) = 1 or I(¬ψ) = 0iff I(¬ψ → ¬φ) = 1

Page 24: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Some Useful Equivalences

Commutativity φ ◦ ψ ≡ ψ ◦ φ for ◦ ∈ {∨,∧,↔}Idempotence φ ◦ φ ≡ φ for ◦ ∈ {∨,∧}Tautology φ ∨ ⊤ ≡ ⊤Unsatisfiability φ ∧ ⊥ ≡ ⊥Neutrality φ ∧ ⊤ ≡ φ

φ ∨ ⊥ ≡ φ

Negation φ ∨ ¬φ ≡ ⊤φ ∧ ¬φ ≡ ⊥

Double Negation ¬¬φ ≡ φ

Implication φ→ ψ ≡ ¬φ ∨ ψ

Page 25: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Some Useful Equivalences Cont’d

De Morgan ¬(φ ∨ ψ) ≡ ¬φ ∧ ¬ψ¬(φ ∧ ψ) ≡ ¬φ ∨ ¬ψ

Absorption φ ∨ (φ ∧ ψ) ≡ φ

φ ∧ (φ ∨ ψ) ≡ φ

Distributivity φ ∧ (ψ ∨ χ) ≡ (φ ∧ ψ) ∨ (φ ∧ χ)φ ∨ (ψ ∧ χ) ≡ (φ ∨ ψ) ∧ (φ ∨ χ)

Associativity φ ∨ (ψ ∨ χ) ≡ (φ ∨ ψ) ∨ χφ ∧ (ψ ∧ χ) ≡ (φ ∧ ψ) ∧ χ

Page 26: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Connections Between the Different Notations

◮ Distinguish between◮ tautologies: all interpretations are models◮ satisfiable formulas: some interpretations are models◮ contradictions: no interpretation is a model

◮ A formula φ is valid iff ¬φ is unsatisfiableRecall that this is the basis for a “proof by contradiction”

◮ A formula φ is satisfiable iff ¬φ is not valid◮ Two formulas φ and ψ are equivalent iff φ↔ ψ is valid◮ A formula φ is valid iff φ is equivalent to ⊤◮ A formula φ is unsatisfiable iff φ is equivalent to ⊥

Page 27: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Entailment (or Logical Implication)

◮ So far, |= relates an interpretation and a formula◮ Allow also a set of formulas on the left side◮ Important: a set of formulas coincides with the conjunction

of its elements, i.e., {φ1, . . . , φn} is∧n

i=1 φi

◮ Important: an empty conjunction is 1 in all interpretationsi.e., it is equivalent to ⊤

◮ W entails φ, W |= φ, iff Mod(W ) ⊆ Mod(φ)

◮ W |= φ iff I |= φ for all models I of W (for all I ∈ Mod(W ))

Page 28: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Properties of Entailment

◮ W |= ψ implies W ∪ {φ} |= ψ Monotonicity for PL0◮ W ∪ {φ} |= ψ iff W |= φ→ ψ Deduction Thm◮ W ∪ {φ} |= ¬ψ iff W ∪ {ψ} |= ¬φ Contraposition Thm◮ W ∪ {φ} is unsatisfiable iff W |= ¬φ Contradiction Thm

Page 29: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Important Questions to Answer

Q1 How can we algorithmicly check whether I |= φ holds?➥ Evaluation of a formula φ under a given interpretation I

Q2 When does W |= φ hold?Q2’ When does |= φ hold?

◮ This is a special case of Q2 with empty W !◮ Q2’ asks: when is φ a tautology (1 in all interpretations)?

Q3 Can we define deduction (based on syntactic rules), s.t.the results of deduction and entailment coincide?

◮ Write W ⊢i φ if φ is derived from W by deduction proc. i◮ i is sound: if W ⊢i φ holds, then W |= φ also holds◮ i is complete: if W |= φ holds, then W ⊢i φ also holds

Page 30: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Evaluation of a Formula Under an Interpretation

Evaluate φ : (p → q) ∧ (p ∧ q → r)→ (p → r) underI = {p 7→ 1,q 7→ 0, r 7→ 1} starting with r

formula value1 (p → q) ∧ (p ∧ q → r)→ (p → r) 12 p → r 13 (p → q) ∧ (p ∧ q → r) 04 p ∧ q → r 15 p → q 06 p ∧ q 07 p p p 18 q q 09 r r 1

Try other evaluation orders!

Page 31: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Evaluation of a Formula Under an Interpretation

Evaluate φ : (p → q) ∧ (p ∧ q → r)→ (p → r) underI = {p 7→ 1,q 7→ 0, r 7→ 1} starting with r

formula value1 (p → q) ∧ (p ∧ q → r)→ (p → r) 12 p → r 13 (p → q) ∧ (p ∧ q → r) 04 p ∧ q → r 15 p → q 06 p ∧ q 07 p p p 18 q q 09 r r 1

Try other evaluation orders!

Page 32: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Evaluation of a Formula Under an Interpretation

Evaluate φ : (p → q) ∧ (p ∧ q → r)→ (p → r) underI = {p 7→ 1,q 7→ 0, r 7→ 1} starting with r

formula value1 (p → q) ∧ (p ∧ q → r)→ (p → r) 12 p → r 13 (p → q) ∧ (p ∧ q → r) 04 p ∧ q → r 15 p → q 06 p ∧ q 07 p p p 18 q q 09 r r 1

Try other evaluation orders!

Page 33: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Evaluation of a Formula Under an Interpretation

Evaluate φ : (p → q) ∧ (p ∧ q → r)→ (p → r) underI = {p 7→ 1,q 7→ 0, r 7→ 1} starting with r

formula value1 (p → q) ∧ (p ∧ q → r)→ (p → r) 12 p → r 13 (p → q) ∧ (p ∧ q → r) 04 p ∧ q → r 15 p → q 06 p ∧ q 07 p p p 18 q q 09 r r 1

Try other evaluation orders!

Page 34: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

How to Check Entailments W |= φ and |= φ

How can we use the evaluation procedure to answer Q2’?

◮ Consider formula φ with {p1, . . . ,pn} as prop. variables◮ Generate all 2n I over these n variables one after the other◮ Test each of the generated interpretation I

◮ Evaluate with the above procedure φ under the current I◮ If I(φ) = 0 then STOP and answer “φ is not a tautology”

◮ If I(φ) = 1 for all I then STOP and answer “φ is a tautology”

How is Q2 handled (i.e., W |= φ)?

◮ Assume W is {ψ1, . . . , ψm} and apply the Deduction Thm◮ Obtain, e.g., |= ψ1 → (ψ2 → (· · · (ψm → φ) · · · )

Page 35: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Decision Procedure for PL0

◮ Check proc. is based on enumeration of interpretations◮ For n atoms in the input formula: 2n interpretations possible◮ Worst case: all 2n interpretations have to be generated

◮ Check procedure for validity is a Decision Procedure◮ Possible answer is either yes or no◮ Decides entailment (and validity)◮ Decides satisfiability by reduction approach:φ is satisfiable iff ¬φ is not valid (i.e., ¬φ is not a tautology)

◮ Can we do better/differently?

Page 36: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Reduction to Satisfiability

Reduce validity, entailment, equivalence to satisfiability

1 Validity◮ ¬φ is unsatisfiable iff φ is valid

2 Entailment◮ φ entails ψ (φ |= ψ) iff φ→ ψ is valid (apply Deduction Thm)◮ Hence, φ |= ψ iff φ ∧ ¬ψ (i.e., ¬(φ→ ψ)) is unsatisfiable

3 Equivalence◮ φ is equivalent to ψ (φ ≡ ψ) iff φ↔ ψ is valid◮ Hence, φ ≡ ψ iff φ |= ψ and ψ |= φ hold◮ Consequently, φ ≡ ψ iff φ ∧ ¬ψ and ψ ∧ ¬φ are unsatisfiable

Sound and complete procedure for satisfiability is sufficient!

Page 37: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Table of Synonym Notions

All four statements in each line amount the same

entailment(s) validity satisfiability equivalenceφ |= ψ φ→ ψ valid φ ∧ ¬ψ unsat (φ→ ψ) ≡ ⊤

⊤ |= ψ ψ valid ¬ψ unsat ψ ≡ ⊤

⊤ 6|= ¬ψ ¬ψ not valid ψ sat ¬ψ 6≡ ⊤

φ |= ψ and ψ |= φ φ↔ ψ valid φ↔ ¬ψ unsat φ ≡ ψ

Page 38: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Normal Forms: NNF and CNF

◮ Restricted syntax, but retain the important properties(application-dependent, e.g., provability)

◮ Negation Normal Form (NNF): A formula in NNF has◮ negation signs only in front of atoms and◮ the only connectives are ∧ and ∨

◮ Conjunctive Normal Form (CNF): A formula in CNF◮ consists of a conjuction of clauses (=disjunction of literals)

(often represented as a set of clauses)◮ Clauses sometimes represented as sets of literals

(can cause problems)

◮ Every PL0-formula has an equivalent formula in NNF/CNF!◮ But how do we construct them?

Page 39: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Preparatory Concept: Tree Replacements

◮ Let φ[ψ] denote that ψ occurs in φ◮ This means that ψ occurs as zero, one or more subtree(s)

in the formula tree of φ◮ Possibility to perform subtree replacements◮ Example: φ : ¬(p ∧ q) ∨ r and ψ1 : ¬(p ∧ q)

◮ Then φ[ψ1] indicates occurrence(s) of ψ1 in φ◮ Construct φ[ψ2] with ψ2 : ¬p ∨ ¬q by a tree replacement

¬

p q

r=⇒

¬

p

¬

q

r

Page 40: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Equivalent Replacement

Lemma (Equivalent Replacement Lemma)Let I be an interpretation and I |= ψ1 ↔ ψ2. ThenI |= φ[ψ1]↔ φ[ψ2].

Theorem (Equivalent Replacement Theorem)Let ψ1 ≡ ψ2. Then φ[ψ1] ≡ φ[ψ2].

Page 41: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Basics of the NNF Translation

◮ Replace↔ by→ using (φ↔ ψ) ≡ ((φ→ ψ) ∧ (ψ → φ))

◮ Replace ⊕ using (φ⊕ ψ) ≡ ((φ ∨ ψ) ∧ (¬φ ∨ ¬ψ)) (why?)◮ Replace→ using (φ→ ψ) ≡ (¬φ ∨ ψ)

◮ Replace the left side of the following equivalences by theright side (order does not matter!)

¬(φ ∨ ψ) ≡ ¬φ ∧ ¬ψ ¬(φ ∧ ψ) ≡ ¬φ ∨ ¬ψφ ∨ ⊤ ≡ ⊤ ⊤ ∨ φ ≡ ⊤φ ∧ ⊥ ≡ ⊥ ⊥ ∧ φ ≡ ⊥φ ∧ ⊤ ≡ φ ⊤ ∧ φ ≡ φ

φ ∨ ⊥ ≡ φ ⊥ ∨ φ ≡ φ

¬¬φ ≡ φ

◮ Translation process is terminating with the NNF◮ For any PL0-formulas λ, nnf(λ)↔ λ holds

Page 42: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Basics of the CNF Translation

◮ Based on the application of distributivity laws◮ Start with the formula φ and translate it to NNF◮ Take nnf(φ) and replace the left side of the following

equivalences by the right side (order does not matter!)

1 φ ∨ (ψ ∧ χ) ≡ (φ ∨ ψ) ∧ (φ ∨ χ)2 (ψ ∧ χ) ∨ φ ≡ (ψ ∨ φ) ∧ (χ ∨ φ)

◮ Observe that nnf(φ) ≡ cnf(φ) ≡ φ holds

Page 43: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

Exa: Transform φ : (p ∧ q → r)→ (q → r) to CNF

nnf(φ) : (p ∧ q ∧ ¬r) ∨ (¬q ∨ r) (why?)

Formula Rule(p ∧ q ∧ ¬r) ∨ (¬q ∨ r) 2(p ∨ ¬q ∨ r) ∧ (q ∧ ¬r ∨ (¬q ∨ r)) 2(p ∨ ¬q ∨ r) ∧ (q ∨ ¬q ∨ r) ∧ (¬r ∨ ¬q ∨ r)

Two disadvantages:

1. Disruption of the formula’s structure

2. cnf(φ) can be exponentially longer than φTake a formula in disjunctive NF and translate it to CNF!

Can be avoided: use definitional translation ( circuit exa)

Page 44: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Method of Davis, Logeman and Loveland

◮ M. Davis, G. Logeman, D. Loveland A machine program fortheorem proving, CACM, Vol. 5, No. 7, pp. 394-397, 1962

◮ Basic framework for all modern SAT solvers(require additional features like learning andnon-chronological backtracking to be competitive)

◮ DLL is search-based (rather than resolution-based as DP)◮ Basic Idea: Given a clause set C

◮ Try all (partial) assignments and test whether C is sat◮ Stop enlarging the current partial assignment I when there

is a conflict (i.e., C cannot be satisfied with extensions of I)◮ Stop if I satisfying C is found or all possible I have been tried

Page 45: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ ca ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ da′ ∨ b ∨ c′

a′ ∨ b′ ∨ c

p′ means ¬p

Page 46: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ ca ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ da′ ∨ b ∨ c′

a′ ∨ b′ ∨ c

a

p′ means ¬p

Page 47: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ c ←a ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ da′ ∨ b ∨ c′ ←a′ ∨ b′ ∨ c ←

a0

p′ means ¬p

Page 48: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ c ←a ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ da′ ∨ b ∨ c′ ←a′ ∨ b′ ∨ c ←

a

b0

p′ means ¬p

Page 49: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ c ←a ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ d ←a′ ∨ b ∨ c′ ←a′ ∨ b′ ∨ c ←

a

b0

0

p′ means ¬p

Page 50: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ c ←a ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ d ←a′ ∨ b ∨ c′ ←a′ ∨ b′ ∨ c ←

a

b0

c0

p′ means ¬p

Page 51: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ c ←a ∨ c ∨ d ←a ∨ c ∨ d ′ ←a ∨ c′ ∨ d ←a ∨ c′ ∨ d ′ ←b′ ∨ c′ ∨ d ←a′ ∨ b ∨ c′ ←a′ ∨ b′ ∨ c ←

a

b0

c0

0

Conflict between← clauses wrt d and d ′

p′ means ¬p

Page 52: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ c ←a ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ d ←a ∨ c′ ∨ d ′ ←b′ ∨ c′ ∨ d ←a′ ∨ b ∨ c′ ←a′ ∨ b′ ∨ c ←

a

b0

c0

0

p′ means ¬p

Page 53: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ c ←a ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ d ←a ∨ c′ ∨ d ′ ←b′ ∨ c′ ∨ d ←a′ ∨ b ∨ c′ ←a′ ∨ b′ ∨ c ←

a

b0

c0

0 1

Conflict between← clauses wrt d and d ′

p′ means ¬p

Page 54: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ c ←a ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ d ←a′ ∨ b ∨ c′ ←a′ ∨ b′ ∨ c ←

a

b0

c0

0�

1

p′ means ¬p

Page 55: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ ca ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ da′ ∨ b ∨ c′

a′ ∨ b′ ∨ c

a

b0

c0

0�

1c1

0�

1

b1

0�

1

I(c) = I(d) = 1 forced by I(a) = I(b) = 1 by UNIT

p′ means ¬p

Page 56: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: An Example

a′ ∨ b ∨ ca ∨ c ∨ da ∨ c ∨ d ′

a ∨ c′ ∨ da ∨ c′ ∨ d ′

b′ ∨ c′ ∨ da′ ∨ b ∨ c′

a′ ∨ b′ ∨ c

a

b0

c0

0�

1c1

0�

1

b1

0�

1

Easy to check: I(a) = I(b) = I(c) = I(d) = 1 is a model

p′ means ¬p

Page 57: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure

◮ Inference rules in DLL:◮ UNIT: In an unsatisfied clause C ∈ C (by the current partial

assignment), if there is only one literal unassigned, then Cis unit (Value of unit clause is implied: Make the literal true!)

◮ Boolean Constraint Propagation (BCP)Apply UNIT until no more unit clause is available in C

◮ PURE: (Seldom used in practice)If a variable occurs in one polarity only: Make its literal true

Page 58: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Basic DLL Procedure: The Destructive Version

◮ Sometimes, “destructive” version of DLL is considered(seen in former lecture on theoretical CS)

◮ Apply assignment of variable to formula and simplify◮ Simplification: Use rules below to eliminate truth constants

φ ∨ ⊤ ≡ ⊤ ⊤ ∨ φ ≡ ⊤φ ∧ ⊥ ≡ ⊥ ⊥ ∧ φ ≡ ⊥φ ∧ ⊤ ≡ φ ⊤ ∧ φ ≡ φ

φ ∨ ⊥ ≡ φ ⊥ ∨ φ ≡ φ

◮ Two possible results on clause set C◮ Delete clauses with true literal from C◮ Delete false literal from clauses in C

Page 59: Formale Methoden der Informatik Introduction and a Short ... · Types of Logics Interesting for CS There is not the logic for CS, but many of them Besides classical logic, there are

The Features of the DLL Procedure

◮ Polynomial memory requirement (exponential in DP!)◮ Exponential time requirement remains

(except for restricted inputs like 2-CNF)

◮ Chronological backtrackingOk for random instances, bad for practical problems w. structure

◮ Need extensions to be of practical value◮ Heuristics to select variables to branch next

(including the assignment to consider first)◮ “Intelligent” (non-chronological) backtracking◮ Learning from successful and unsuccessful decisions