Classical Propositional Logic

Similar documents
The Calculus of Computation: Decision Procedures with Applications to Verification. Part I: FOUNDATIONS. by Aaron Bradley Zohar Manna

CS156: The Calculus of Computation

Part 1: Propositional Logic

CS156: The Calculus of Computation Zohar Manna Autumn 2008

Computational Logic. Davide Martinenghi. Spring Free University of Bozen-Bolzano. Computational Logic Davide Martinenghi (1/30)

Solvers for the Problem of Boolean Satisfiability (SAT) Will Klieber Aug 31, 2011

LOGIC PROPOSITIONAL REASONING

Topics in Model-Based Reasoning

Propositional Logic: Evaluating the Formulas

Part 1: Propositional Logic

Propositional Logic. Methods & Tools for Software Engineering (MTSE) Fall Prof. Arie Gurfinkel

From SAT To SMT: Part 1. Vijay Ganesh MIT

Clause/Term Resolution and Learning in the Evaluation of Quantified Boolean Formulas

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

3 Propositional Logic

Propositional Logic Language

Logic and Inferences

Lecture 2 Propositional Logic & SAT

Automated Reasoning in First-Order Logic

Warm-Up Problem. Is the following true or false? 1/35

Propositional logic. Programming and Modal Logic

Lecture Notes on SAT Solvers & DPLL

CSE507. Introduction. Computer-Aided Reasoning for Software. Emina Torlak courses.cs.washington.edu/courses/cse507/17wi/

COMP219: Artificial Intelligence. Lecture 20: Propositional Reasoning

Deductive Systems. Lecture - 3

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 3: Practical SAT Solving

Formal Verification Methods 1: Propositional Logic

Title: Logical Agents AIMA: Chapter 7 (Sections 7.4 and 7.5)

Comp487/587 - Boolean Formulas

Pythagorean Triples and SAT Solving

Logic in AI Chapter 7. Mausam (Based on slides of Dan Weld, Stuart Russell, Subbarao Kambhampati, Dieter Fox, Henry Kautz )

Logic in AI Chapter 7. Mausam (Based on slides of Dan Weld, Stuart Russell, Dieter Fox, Henry Kautz )

Decision Procedures for Satisfiability and Validity in Propositional Logic

A brief introduction to Logic. (slides from

Propositional Logic: Methods of Proof (Part II)

Solving SAT Modulo Theories

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 2: Propositional Logic

Propositional Logic: Methods of Proof (Part II)

Language of Propositional Logic

7. Propositional Logic. Wolfram Burgard and Bernhard Nebel

Propositional and First Order Reasoning

Satisfiability Modulo Theories

Chapter 7 R&N ICS 271 Fall 2017 Kalev Kask

CS:4420 Artificial Intelligence

Propositional Logic: Models and Proofs

Rewriting for Satisfiability Modulo Theories

Knowledge base (KB) = set of sentences in a formal language Declarative approach to building an agent (or other system):

WHAT IS AN SMT SOLVER? Jaeheon Yi - April 17, 2008

Foundations of Artificial Intelligence

Foundations of Artificial Intelligence

Intelligent Agents. Pınar Yolum Utrecht University

Propositional and Predicate Logic - V

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

CS 380: ARTIFICIAL INTELLIGENCE PREDICATE LOGICS. Santiago Ontañón

Tutorial 1: Modern SMT Solvers and Verification

Logical Agents. Chapter 7

Logical agents. Chapter 7. Chapter 7 1

Propositional logic. Programming and Modal Logic

SAT Solvers: Theory and Practice

Propositional Logic: Methods of Proof. Chapter 7, Part II

Abstract Answer Set Solvers with Backjumping and Learning

Solving SAT and SAT Modulo Theories: From an Abstract Davis Putnam Logemann Loveland Procedure to DPLL(T)

CS 380: ARTIFICIAL INTELLIGENCE

Propositional and Predicate Logic. jean/gbooks/logic.html

Introduction to Artificial Intelligence. Logical Agents

EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS

Propositional Logic. Testing, Quality Assurance, and Maintenance Winter Prof. Arie Gurfinkel

ME(LIA) - Model Evolution With Linear Integer Arithmetic Constraints

Abstract DPLL and Abstract DPLL Modulo Theories

Class Assignment Strategies

Critical Reading of Optimization Methods for Logical Inference [1]

Foundations of Artificial Intelligence

An Introduction to SAT Solving

2.5.2 Basic CNF/DNF Transformation

Learning Goals of CS245 Logic and Computation

02 Propositional Logic

Satisfiability Modulo Theories (SMT)

Foundations of Artificial Intelligence

Propositional Resolution

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw

Introduction to Artificial Intelligence Propositional Logic & SAT Solving. UIUC CS 440 / ECE 448 Professor: Eyal Amir Spring Semester 2010

Mathematical Logic Propositional Logic - Tableaux*

The Calculus of Computation

Propositional Calculus - Soundness & Completeness of H

Propositional Logic: Methods of Proof (Part II)

Kecerdasan Buatan M. Ali Fauzi

Inf2D 06: Logical Agents: Knowledge Bases and the Wumpus World

Artificial Intelligence

AAA615: Formal Methods. Lecture 2 First-Order Logic

Constraint Solving for Finite Model Finding in SMT Solvers

A New 3-CNF Transformation by Parallel-Serial Graphs 1

Chapter 7 Propositional Satisfiability Techniques

Lecture 9: The Splitting Method for SAT

Foundations of Lazy SMT and DPLL(T)

Logical Inference. Artificial Intelligence. Topic 12. Reading: Russell and Norvig, Chapter 7, Section 5

Logical agents. Chapter 7. Chapter 7 1

Foundations of Artificial Intelligence

A Tableau Calculus for Minimal Modal Model Generation

Induction on Failing Derivations

On the Complexity of the Reflected Logic of Proofs

Transcription:

Classical Propositional Logic Peter Baumgartner http://users.cecs.anu.edu.au/~baumgart/ Ph: 02 6218 3717 Data61/CSIRO and ANU July 2017 1 / 71

Classical Logic and Reasoning Problems A 1 : Socrates is a human A 2 : All humans are mortal Translation into first-order logic: A 1 : human(socrates) A 2 : X (human(x ) mortal(x )) Reasoning problems Which of the following statements hold true? ( = means entails ) 1. {A 1, A 2 } = mortal(socrates) 2. {A 1, A 2 } = mortal(apollo) 3. {A 1, A 2 } = mortal(socrates) 4. {A 1, A 2 } = mortal(apollo) 5. {A 1, A 2 } = mortal(socrates) 6. {A 1, A 2 } = mortal(apollo) Topics of these lectures What do these statements exactly mean? Algorithms/procedures for reasoning problems like the above Next: some applications 2 / 71

Application : Mathematical Theorem Proving First-Order Logic Can express (mathematical) structures, e.g. groups x 1 x = x x x 1 = x (N) x x 1 x = 1 x x x 1 = 1 (I) x, y, z (x y) z = x (y z) (A) Reasoning Object level: It follows x (x x) = 1 x, y x y = y x Meta-level: the word problem for groups is decidable Automated Reasoning Computer program to provide the above conclusions automatically 3 / 71

Application: Compiler Validation Problem: prove equivalence of source and target program 1: y := 1 2: if z = x*x*x 3: then y := x*x + y 4: endif 1: y := 1 2: R1 := x*x 3: R2 := R1*x 4: jmpne(z,r2,6) 5: y := R1+1 To prove: (indexes refer to values at line numbers; index 0 = initial values) From y 1 = 1 z 0 = x 0 x 0 x 0 y 3 = x 0 x 0 + y 1 and y 1 = 1 R1 2 = x 0 x 0 R2 3 = R1 2 x 0 z 0 = R2 3 it follows y 3 = y 5 y 5 = R1 2 + 1 x 0 = x 0 y 0 = y 0 z 0 = z 0 4 / 71

Application: Constraint Solving The n-queens problem: Given: An n n chessboard Question: Is it possible to place n queens so that no queen attacks any other? A solution for n = 8 p[1] = 6 p[2] = 3 p[3] = 5 p[4] = 8 p[5] = 1 p[6] = 4 p[7] = 2 p[8] = 7 5 / 71

Application: Constraint Solving Formalization in sorted first-order logic: n : Z (Declaration of n) p : Z Z (Declaration of p) n = 8 i : Z j : Z (1 i i n i + 1 j j < n p(i) p(j) p(i) + i p(j) + j p(i) i p(j) j) (Queens) p(1) = 1 p(1) = 2 p(1) = 8... p(8) = 1 p(8) = 2 p(8) = 8 (p(1) {1,..., n}) (p(n) {1,..., n}) Logic: Integer arithmetic, quantifiers, free symbol p Task: Find a satisfying interpretation I (a model) and evaluate I (p(1)),..., I (p(n)) to read off the answer 6 / 71

Application: System Analysis p[1] = 6 p[2] = 3 p[3] = 5 p[4] = 8 p[5] = 1 p[6] = 4 p[7] = 2 p[8] = 7 The n-queens has variable symmetry: mapping p[i] p[n + 1 i] preserves solutions, for any n Therefore, it is justified to add (to the formalization) a constraint p[1] < p[n], for search space pruning But how can we know that the problem has symmetries? This is a theorem proving task! 7 / 71

Application: System Analysis We need two copies (Queens p) and (Queens q) of the constraint: n : Z (Declaration of n) p, q : Z Z (Declaration of p, q) perm : Z Z i : Z j : Z (1 i i n i + 1 j j < n p(i) p(j) p(i) + i p(j) + j p(i) i p(j) j) i : Z j : Z (1 i i n i + 1 j j < n q(i) q(j) q(i) + i q(j) + j q(i) i q(j) j) (Declaration of perm) (Queens p) (Queens q) i : Z perm(i) = n + 1 i (Def. permutation) Logic: Integer arithmetic, quantifiers, free symbol p Task: Prove logical consequence (Queens p) ( i : Z q(i) = p(perm(i))) (Queens q) 8 / 71

Issues Previous slides gave motivation: logical analysis of systems System can be anything that makes sense and can be described using logic (group theory, computer programs,...) Propositional logic is not very expressive; but it admits complete and terminating (and sound, and fast ) reasoning procedures First-order logic is expressive but not too expressive; it admits complete (and sound, and reasonably fast ) reasoning procedures So, reasoning with it can be automated on computer. BUT How to do it in the first place: suitable calculi? How to do it efficiently: search space control? How to do it optimally: reasoning support for specific theories like equality and arithmetic? The lecture will touch on some of these issues and explain basic approaches to their solution 9 / 71

Contents Lectures 1 5: Propositional logic: syntax, semantics, reasoning algorithms, important properties (Slides in part thanks to Aaron Bradley) Lecture 6 10: First-order logic: syntax, semantics, reasoning procedures, important properties 10 / 71

Propositional Logic(PL) PL Syntax Atom truth symbols ( true ) and ( false ) propositional variables P, Q, R, P 1, Q 1, R 1, Literal atom α or its negation α Formula atom or application of a logical connective to formulae F, F 1, F 2 F not (negation) F 1 F 2 and (conjunction) F 1 F 2 or (disjunction) F 1 F 2 implies (implication) F 1 F 2 if and only if (iff) Speaking formally, formulas are defined inductively 11 / 71

Example: formula F : (P Q) ( Q) atoms: P, Q, literal: Q subformulas: P Q, Q abbreviation (leave parenthesis away) F : P Q Q 12 / 71

PL Semantics (meaning) Formula F + Interpretation I = Interpretation Truth value (true, false) I : {P true, Q false, } Evaluation of F under I : F F 0 1 1 0 where 0 corresponds to value false 1 true F 1 F 2 F 1 F 2 F 1 F 2 F 1 F 2 F 1 F 2 0 0 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 0 1 1 1 1 1 1 13 / 71

Example: F : P Q P Q I : {P true, Q false} P Q Q P Q P Q F 1 0 1 0 1 1 1 = true 0 = false F evaluates to true under I 14 / 71

Inductive Definition of PL s Semantics I = F if F evaluates to true under I ( I satisfies F ) I = F false under I ( I falsifies F ) Base Case: I = I = I = P iff I [P] = true I = P iff I [P] = false Inductive Case: I = F iff I = F I = F 1 F 2 iff I = F 1 and I = F 2 I = F 1 F 2 iff I = F 1 or I = F 2 I = F 1 F 2 iff, if I = F 1 then I = F 2 I = F 1 F 2 iff, I = F 1 and I = F 2, or I = F 1 and I = F 2 Note: I = F 1 F 2 iff I = F 1 and I = F 2 15 / 71

Example: F : P Q P Q I : {P true, Q false} 1. I = P since I [P] = true 2. I = Q since I [Q] = false 3. I = Q by 2 and 4. I = P Q by 2 and 5. I = P Q by 1 and 6. I = F by 4 and Why? Thus, F is true under I. Notation Extend interpretation I to formulas F : { true if I = F I [F ] = false otherwise (I = F ) 16 / 71

Inductive Proofs Induction on the structure of formulas To prove that a property P holds for every formula F it suffices to show the following: Induction start: show that P holds for every base case formula A Induction step: Assume that P holds for arbitrary formulas F 1 and F 2 (induction hypothesis). Show that P follows for every inductive case formula built with F 1 and F 2 Example Lemma 1 Let F be a formula, and I and J be interpretations. If I [P] = J[P] for every propositional variable P occurring in F then I [F ] = J[F ] (equivalently: J = F iff J = F ). 17 / 71

Example Lemma 1 Let F be a formula, and I and J be interpretations. If I [P] = J[P] for every propositional variable P occurring in F then I [F ] = J[F ]. Proof. Assume I [P] = J[P] for every propositional variable P occurring in F. We have to show I [F ] = J[F ] Induction start If F = or F = then trivially I [F ] = J[F ]. Otherwise F = P for some propositional variable P. Trivially P occurs in F and hence by assumption I [F ] = I [P] = J[P] = J[F ]. 18 / 71

Example Lemma 1 Let F be a formula, and I and J be interpretations. If I [P] = J[P] for every propositional variable P occurring in F then I [F ] = J[F ]. Induction step Case 1: F = G for some formula G. If I [F ] = true then I [F ] = true iff I [ G] = true iff (F = G) I [G] = false iff (Semantics of ) J[G] = false iff (Induction hypothesis) J[ G] = true iff (Semantics of ) J[F ] = true If I [F ] = false: analogously (F = G) 19 / 71

Example Lemma 1 Let F be a formula, and I and J be interpretations. If I [P] = J[P] for every propositional variable P occurring in F then I [F ] = J[F ]. Induction step Case 2: F = G H for some formulas G and H. If I [F ] = true then I [F ] = true iff I [G H] = true iff (F = G H) I [G] = true and I [H] = true iff (Semantics of ) J[G] = true and J[H] = true iff (Induction hypothesis 2x) J[G H] = true iff (Semantics of ) J[F ] = true (F = G H) If I [F ] = false: analogously Cases 3, 4 and 5 for, and : analogously 20 / 71

Satisfiability and Validity F satisfiable iff there exists an interpretation I such that I = F. F valid iff for all interpretations I, I = F. Method 1: Truth Tables F is valid iff F is unsatisfiable Example F : P Q P Q P Q P Q Q P Q F 0 0 0 1 1 1 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 1 Thus F is valid. 21 / 71

Example F : P Q P Q P Q P Q P Q F 0 0 0 0 1 satisfying I 0 1 1 0 0 falsifying I 1 0 1 0 0 1 1 1 1 1 Thus F is satisfiable, but invalid. 22 / 71

Examples Which of the following formulas is satisfiable, which is valid? 1. F 1 : P Q satisfiable, not valid 2. F 2 : (P Q) satisfiable, not valid 3. F 3 : P P satisfiable, valid 4. F 4 : (P P) unsatisfiable, not valid 5. F 5 : (P Q) (P Q) Q unsatisfiable, not valid 23 / 71

Method 2: Semantic Argument ( Tableau Calculus ) Proof rules I = F I = F I = F I = F I I I = F G = F = G and I = F G I = F I = G or I = F G I = F I = G I = F G I = F I = G I I I I I I = F G = F = G = F G = F = G I = F G I = F G I = F G I = F G I = F G I = F G I I I = F = F = 24 / 71

Example 1: Prove F : P Q P Q is valid. Let s assume that F is not valid and that I is a falsifying interpretation. 1. I = P Q P Q assumption 2. I = P Q 1 and 3. I = P Q 1 and 4. I = P 2 and 5. I = P 3 and 6. I = 4 and 5 are contradictory Thus F is valid. 25 / 71

Example 2: Prove F : (P Q) (Q R) (P R) is valid. Let s assume that F is not valid. 1. I = F assumption 2. I = (P Q) (Q R) 1 and 3. I = P R 1 and 4. I = P 3 and 5. I = R 3 and 6. I = P Q 2 and of 7. I = Q R 2 and of 26 / 71

Two cases from 6 and 8a. I = P 6 and 9a. I = 4 and 8a are contradictory 8b. I = Q 6 and Two cases from 7 and 9ba. I = Q 7 and 10ba. I = 8b and 9ba are contradictory 9bb. I = R 7 and 10bb. I = 5 and 9bb are contradictory Our assumption is incorrect in all cases F is valid. 27 / 71

Example 3: Is F : P Q P Q valid? Let s assume that F is not valid. 1. I = P Q P Q assumption 2. I = P Q 1 and 3. I = P Q 1 and Two options 4a. I = P 2 or 5a. I = Q 3 4b. I = Q 2 5b. I = P 3 We cannot derive a contradiction. F is not valid. Falsifying interpretation: I 1 : {P true, Q false} I 2 : {Q true, P false} We have to derive a contradiction in both cases for F to be valid. 28 / 71

Equivalence F 1 and F 2 are equivalent (F 1 F 2 ) iff for all interpretations I, I = F 1 F 2 To prove F 1 F 2 show F 1 F 2 is valid. F 1 implies F 2 (F 1 F 2 ) iff for all interpretations I, I = F 1 F 2 F 1 F 2 and F 1 F 2 are not formulae! 29 / 71

Proposition 1 (Substitution Theorem) Assume F 1 F 2. If F is a formula with at least one occurrence of F 1 as a subformula then F F, where F is obtained from F by replacing some occurrence of F 1 in F by F 2. Proof. (Sketch) By induction on the formula structure. For the induction start, if F = F 1 then F = F 2, and F F follows from F 1 F 2. The proof of the induction step is similar to the proof of Lemma 1. Proposition 1 is relevant for conversion of formulas into normal form, which requires replacing subformulas by equivalent ones 30 / 71

Normal Forms 1. Negation Normal Form (NNF) Negations appear only in literals. (only,, ) To transform F to equivalent F in NNF use recursively the following template equivalences (left-to-right): F 1 F 1 } (F 1 F 2 ) F 1 F 2 De Morgan s Law (F 1 F 2 ) F 1 F 2 F 1 F 2 F 1 F 2 F 1 F 2 (F 1 F 2 ) (F 2 F 1 ) Example: Convert F : (P (P Q)) to NNF F : ( P (P Q)) to F : P (P Q) De Morgan s Law F : P P Q F is equivalent to F (F F ) and is in NNF 31 / 71

2. Disjunctive Normal Form (DNF) Disjunction of conjunctions of literals l i,j for literals l i,j i j To convert F into equivalent F in DNF, transform F into NNF and then use the following template equivalences (left-to-right): } (F 1 F 2 ) F 3 (F 1 F 3 ) (F 2 F 3 ) dist F 1 (F 2 F 3 ) (F 1 F 2 ) (F 1 F 3 ) Example: Convert F : (Q 1 Q 2 ) ( R 1 R 2 ) into DNF F : (Q 1 Q 2 ) (R 1 R 2 ) F : (Q 1 (R 1 R 2 )) (Q 2 (R 1 R 2 )) F : (Q 1 R 1 ) (Q 1 R 2 ) (Q 2 R 1 ) (Q 2 R 2 ) in NNF dist dist F is equivalent to F (F F ) and is in DNF 32 / 71

3. Conjunctive Normal Form (CNF) Conjunction of disjunctions of literals l i,j for literals l i,j i j To convert F into equivalent F in CNF, transform F into NNF and then use the following template equivalences (left-to-right): (F 1 F 2 ) F 3 (F 1 F 3 ) (F 2 F 3 ) F 1 (F 2 F 3 ) (F 1 F 2 ) (F 1 F 3 ) Relevance: DPLL and Resolution both work with CNF 33 / 71

Davis-Putnam-Logemann-Loveland (DPLL) Algorithm Decides the satisfiability of PL formulae in CNF, or clause sets Clause A (propositional) clause is a disjunction of literals Convention A formula in CNF is taken as a set of clauses. Example: (A B) (C A) (D C A) ( D B) CNF {A B, C A, D C A, D B} Clause Set Typical Application: Proof by Refutation To prove the validity of Axiom 1 Axiom n Conjecture it suffices to prove that the CNF of Axiom 1 Axiom n Conjecture is unsatisfiable 34 / 71

DPLL Interpretations DPLL works with trees whose nodes are labelled with literals Consistency No branch contains the labels A and A, for no A Every branch in a tree is taken as a (consistent) set of its literals A consistent set of literals S is taken as an interpretation: if A S then (A true) I if A S then (A false) I if A / S and A / S then (A false) I Example {A, B, D} stands for I : {A true, B false, C false, D true} Model A model for a clause set N is an interpretation I such that I = N 35 / 71

DPLL as a Semantic Tree Method (1) A B (2) C A (3) D C A (4) D B empty tree {} = A B {} = C A {} = D C A {} = D B A Branch stands for an interpretation Purpose of splitting: satisfy a clause that is currently falsified Close branch if some clause is plainly falsified by it ( ) 36 / 71

DPLL as a Semantic Tree Method (1) A B (2) C A (3) D C A (4) D B A A {A} = A B {A} = C A {A} = D C A {A} = D B A Branch stands for an interpretation Purpose of splitting: satisfy a clause that is currently falsified Close branch if some clause is plainly falsified by it ( ) 37 / 71

DPLL as a Semantic Tree Method (1) A B (2) C A (3) D C A (4) D B A A {A, C} = A B {A, C} = C A {A, C} = D C A {A, C} = D B C C A Branch stands for an interpretation Purpose of splitting: satisfy a clause that is currently falsified Close branch if some clause is plainly falsified by it ( ) 38 / 71

DPLL as a Semantic Tree Method (1) A B (2) C A (3) D C A (4) D B A A {A, C, D} = A B {A, C, D} = C A {A, C, D} = D C A {A, C, D} = D B C C D D Model {A, C, D} found. A Branch stands for an interpretation Purpose of splitting: satisfy a clause that is currently falsified Close branch if some clause is plainly falsified by it ( ) 39 / 71

DPLL as a Semantic Tree Method (1) A B (2) C A (3) D C A (4) D B A A {B} = A B {B} = C A {B} = D C A {B} = D B C C B B Model {B} found. D D A Branch stands for an interpretation Purpose of splitting: satisfy a clause that is currently falsified Close branch if some clause is plainly falsified by it ( ) 40 / 71

DPLL Pseudocode 1 function DPLL(N) 2 %% N is a set of clauses 3 %% returns true if N satisfiable, false otherwise 4 while N contains a unit clause {L} 5 N := simplify(n, L) 6 if N = {} then return true 7 if N then return false 8 L := choose-literal(n) %% any literal that occurs in N - decision literal 9 if DPLL(simplify(N, L)) 10 then return true 11 else return DPLL(simplify(N, L)); 1 function simplify(n, L) %% also called unit propagation 2 remove all clauses from N that contain L 3 delete L from all remaining clauses %% possibly get empty clause 4 return the resulting clause set 41 / 71

Simplify Examples 1 function simplify(n, L) %% also called unit propagation 2 remove all clauses from N that contain L 3 delete L from all remaining clauses %% possibly get empty clause 4 return the resulting clause set simplify({a B, C A, D C A, D B}, A) = { C, D C, D B} simplify({ C, D C, D B}, C) = { D, D B} simplify({ D, D B}, D) = { B} 42 / 71

Making DPLL Fast Overview Conflict Driven Clause Learning (CDCL) solvers extend DPLL Lemma learning: add new clauses to the clause set as branches get closed ( conflict driven ) Goal: reuse information that is obtained in one branch for subsequent derivation steps. Backtracking: replace chronological backtracking by dependency-directed backtracking, aka backjumping : on backtracking, skip splits that are not necessary to close a branch Randomized restarts: every now and then start over, with learned clauses Variable selection heuristics: what literal to split on. E.g., use literals that occur often Make unit-propagation fast: 2-watched literal technique 43 / 71

Making DPLL Fast 2-watched literal technique A technique to implement unit propagation efficiently In each clause, select two (currently undefined) watched literals. For each variable A, keep a list of all clauses in which A is watched and a list of all clauses in which A is watched. If an undefined variable is set to false (or to true), check all clauses in which A (or A) is watched and watch another literal (that is true or undefined) in this clause if possible. As long as there are two watched literals in a n-literal clause, this clause cannot be used for unit propagation, because n 1 of its literals have to be false to provide a unit conclusion. Important: Watched literal information need not be restored upon backtracking. 44 / 71

2-Watched Literals Example In an n-literal clause, n 1 literals must be assigned false before it can unit-propagate. Defer unit propagation until this is the case. Invariant: if clause is not satisfied, watched literals are undefined. Only clauses violating the invariant can unit-propagate Clause A B C D E (watched literals underlined) 1. Assignments developed in this order C D A 2. Watched literal A is false find another literal to watch Clause A B C D E 3. Extend with decision literal C D A B 4. Imposible to watch two literals now E is unit-propagated 5. Now have C D A B E Maintains invariant Invariant is maintained in case of backtracking to B: Then have C D A B 45 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma... B A (1) D C (2) D B C (3) (1) B A A Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 46 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma... B A (1) D C (2) D B C (3) (1) B A A C C (2) D * (3) Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 47 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma... B A (1) D C (2) D B C (3) (1) B A A C C (2) D * (3) Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 48 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma... B A (1) D C (2) D B C (3) (1) B A A Lemma Candidates by Resolution: D B C C C (2) D * (3) Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 49 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma... B A (1) D C (2) D B C (3) (1) B A A Lemma Candidates by Resolution: D B C B C D C C C (2) D * (3) Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 50 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma... B A (1) D C (2) D B C (3) (1) B A A Lemma Candidates by Resolution: D B C D C B C B A C A C C (2) D * (3) Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 51 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma With Lemma... B A (1) D C (2) D B C (3) (1) B A A Lemma Candidates by Resolution: D B C D C B C B A C A C C (2) D * (3) Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 52 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma With Lemma... B A (1) D C (2) D B C (3) (1) B A A A A Lemma Candidates by Resolution: D B C D C B C B A C A C C (2) D * (3) Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 53 / 71

Lemma Learning Lemma Learning in DPLL "Avoid making the same mistake twice" w/o Lemma With Lemma... B A (1) D C (2) D B C (3) Lemma Candidates by Resolution: D B C D C B C B A C A (1) B A A C C (2) D * (3) A A C ( C A) Baumgartner/Fuchs/Tinelli Lemma Learning in the Model Evolution Calculus 9 54 / 71

Further Information The ideas described so far heve been implemented in the SAT checker zchaff: Lintao Zhang and Sharad Malik. The Quest for Efficient Boolean Satisfiability Solvers, Proc. CADE-18, LNAI 2392, pp. 295 312, Springer, 2002. Other Overviews Robert Nieuwenhuis, Albert Oliveras, Cesare Tinelli. Solvin SAT and SAT Modulo Theories: From an abstract Davis-Putnam-Logemann-Loveland precedure to DPLL(T), pp 937 977, Journal of the ACM, 53(6), 2006. Armin Biere and Marijn Heule and Hans van Maaren and Toby Walsh. Handbook of Satisability, IOS Press, 2009. 55 / 71

The Resolution Calculus DPLL and the refined CDCL algorithm are the practically best methods for PL The resolution calculus (Robinson 1969) has been introduced as a basis for automated theorem proving in first-order logic. We will see it in detail in the first-order logic part of this lecture Refined versions are still the practically best methods for first-order logic The resolution calculus is best introduced first for propositional logic 56 / 71

The Propositional Resolution Calculus Propositional resolution inference rule C A A D C D Terminology: C D: resolvent; A: resolved atom Propositional (positive) factoring inference rule Terminology: C A: factor C A A C A These are schematic inference rules: C and D propositional clauses A propositional atom is considered associative and commutative 57 / 71

Derivations Let N = {C 1,..., C k } be a set of input clauses A derivation (from N) is a sequence of the form C 1,..., C }{{ k, C } k+1,..., C n,... }{{} Input Derived clauses clauses such that for every n k + 1 C n is a resolvent of C i and C j, for some 1 i, j < n, or C n is a factor of C i, for some 1 i < n. The empty disjunction, or empty clause, is written as A refutation (of N) is a derivation from N that contains 58 / 71

Sample Refutation 1. A A B (given) 2. A B (given) 3. C B (given) 4. C (given) 5. A B B (Res. 2. into 1.) 6. A B (Fact. 5.) 7. B B (Res. 2. into 6.) 8. B (Fact. 7.) 9. C (Res. 8. into 3.) 10. (Res. 4. into 9.) 59 / 71

Soundness and Completeness Important properties a calculus may or may not have: Soundness: if there is a refutation of N then N is unsatisfiable Deduction completeness: if N is valid then there is a derivation of N Refutational completeness: if N is unsatisfiable then there is a refutation of N The resolution calculus is sound and refutationally complete, but not deduction complete 60 / 71

Soundness of Propositional Resolution Theorem 2 Propositional resolution is sound Proof. Let I be an interpretation. To be shown: 1. for resolution: I = C A, I = D A I = C D 2. for factoring: I = C A A I = C A Ad (1): Assume premises are valid in I. Two cases need to be considered: (a) A is valid in I, or (b) A is valid in I. a) I = A I = D I = C D b) I = A I = C I = C D Ad (2): even simpler 61 / 71

Completeness of Propositional Resolution Theorem 3 Propositional Resolution is refutationally complete That is, if a propositional clause set is unsatisfiable, then Resolution will derive the empty clause eventually More precisely: If a clause set is unsatisfiable and closed under the application of the Resolution and Factoring inference rules, then it contains the empty clause Perhaps easiest proof: semantic tree proof technique (see whiteboard) This result can be considerably strengthened, some strengthenings come for free from the proof 62 / 71

Semantic Trees (Robinson 1968, Kowalski and Hayes 1969) Semantic trees are a convenient device to represent interpretations for possibly infinitely many atoms Applications To prove the completeness of the propositional resolution calculus Characterizes a specific, refined resolution calculus To prove the compactness theorem of propositional logic. Application: completeness proof of first-order logic Resolution. 63 / 71

Trees A tree is an acyclic, connected, directed graph, where every node has at most one incoming edge A rooted tree has a dedicated node, called root that has no incoming edge A tree is finite iff it has finitely many vertices (and edges) only In a finitely branching tree every node has only finitely many edges A binary tree every node has at most two outgoing edges. It is complete iff every node has either no or two outgoing edges 64 / 71

A path P in a rooted tree is a possibly infinite sequence of nodes P = (N 0, N 1,...), where N 0 is the root, and N i is a direct successor of N i 1, for all i = 1,..., n A path to a node N is a finite path of the form (N 0, N 1,..., N n ) such that N = N n ; the value n is the length of the path The node N n 1 is called the immediate predecessor of N Every node N 0, N 1,..., N n 1 is called a predecessor of N A (node-)labelled tree is a tree together with a labelling function λ that maps each of its nodes to an element in a given set Let L be a literal. The complement of L is the literal L := { A if L is the atom A A if L is the negated atom A. 65 / 71

Semantic Trees A semantic tree B (for a set of atoms D) is a labelled, complete, rooted, binary tree such that 1. the root is labelled by the symbol 2. for every inner node N, one successor of N is labeled with the literal A, and the other successor is labeled with the literal A, for some A D 3. for every node N, there is no literal L such that L I(N ) and L I(N ), where I(N ) = {λ(n i ) N 0, N 1,..., (N n = N ) is a path to N and 1 i n} 66 / 71

Semantic Trees Atom Set For a clause set N let the atom set (of N) be the set of atoms occurring in clauses in N A semantic tree for N is a semantic tree for the atom set of N Path Semantics For a path P = (N 0, N 1,...) let be the set of all literals along P I(P) = {λ(n i ) i 0} Complete Semantic Tree A semantic tree for D is complete iff for every A D and every branch P it holds that A I(P) or A I(P) 67 / 71

Interpretation Induced by a Semantic Tree Every path P in a complete semantic tree for D induces an interpretation I P as follows: I P [A] = { true false if A I P if A I P A complete semantic tree can be seen as an enumeration of all possible interpretations for N (it holds I P I P whenever P P ) 68 / 71

Failure Node If a clause set N is unsatisfiable (not satisfiable) then, by definition, every interpretation I falsifies some clause in N, i.e., I = C for some C N This motivates the following definition: Failure Node A node N in a semantic tree for N is a failure node, if 1. there is a clause C N such that I N = C, and 2. for every predecessor N of N it holds: there is no clause C N such that I N = C 69 / 71

Open, Closed A path P in a semantic tree for N is closed iff P contains a failure node, otherwise it is open A semantic tree B for M is closed iff every path is closed, otherwise B is open Every closed semantic tree can be turned into a finite closed one by removing all subtrees below all failure nodes Remark The construction of a (closed or open) finite semantic tree is the core of the propositional DPLL procedure above. Our main application now, however, is to prove compactness of propositional clause logic 70 / 71

Compactness Theorem 4 A (possibly infinite) clause set N is unsatisfiable iff there is a closed semantic tree for N Proof. See whiteboard Corollary 5 (Compactness) A (possibly infinite) clause set N is unsatisfiable iff some finite subset of N is unsatisfiable Proof. The if-direction is trivial. For the only-if direction, Theorem 4 gives us a finite unsatisfiable subset of N as identified by the finitely many failure nodes in the semantic tree. 71 / 71