CS510 Software Engineering



Similar documents
Logic in general. Inference rules and theorem proving

Correspondence analysis for strong three-valued logic

Handout #1: Mathematical Reasoning

Satisfiability Checking

CHAPTER 7 GENERAL PROOF SYSTEMS

Likewise, we have contradictions: formulas that can only be false, e.g. (p p).

Introduction to Logic in Computer Science: Autumn 2006

Predicate logic Proofs Artificial intelligence. Predicate logic. SET07106 Mathematics for Software Engineering

2. The Language of First-order Logic

Mathematical Induction

Optimizing Description Logic Subsumption

Ensuring Consistency in Long Running Transactions

Foundational Proof Certificates

Propositional Logic. A proposition is a declarative sentence (a sentence that declares a fact) that is either true or false, but not both.

Computational Methods for Database Repair by Signed Formulae

Rigorous Software Development CSCI-GA

Automated Theorem Proving - summary of lecture 1

(LMCS, p. 317) V.1. First Order Logic. This is the most powerful, most expressive logic that we will examine.

Beyond Propositional Logic Lukasiewicz s System

DEDUCTIVE & INDUCTIVE REASONING

Predicate Logic Review

Lecture 7: NP-Complete Problems

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

Resolution. Informatics 1 School of Informatics, University of Edinburgh

Fixed-Point Logics and Computation

A Theorem Prover for Boolean BI

npsolver A SAT Based Solver for Optimization Problems

How To Trace

Summary Last Lecture. Automated Reasoning. Outline of the Lecture. Definition sequent calculus. Theorem (Normalisation and Strong Normalisation)

def: An axiom is a statement that is assumed to be true, or in the case of a mathematical system, is used to specify the system.

Logical Agents. Explorations in Artificial Intelligence. Knowledge-based Agents. Knowledge-base Agents. Outline. Knowledge bases

Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

We would like to state the following system of natural deduction rules preserving falsity:

Computational Logic and Cognitive Science: An Overview

The Classes P and NP

Software Modeling and Verification

Boolean Algebra Part 1

Generating models of a matched formula with a polynomial delay

Schedule. Logic (master program) Literature & Online Material. gic. Time and Place. Literature. Exercises & Exam. Online Material

Certamen 1 de Representación del Conocimiento

Examination paper for MA0301 Elementær diskret matematikk

Formal Verification Coverage: Computing the Coverage Gap between Temporal Specifications

[Refer Slide Time: 05:10]

Introduction to Logic: Argumentation and Interpretation. Vysoká škola mezinárodních a veřejných vztahů PhDr. Peter Jan Kosmály, Ph.D

InvGen: An Efficient Invariant Generator

OHJ-2306 Introduction to Theoretical Computer Science, Fall

Algorithmic Software Verification

Which Semantics for Neighbourhood Semantics?

Relations: their uses in programming and computational specifications

NP-Completeness and Cook s Theorem

Degrees of Truth: the formal logic of classical and quantum probabilities as well as fuzzy sets.

2 Temporal Logic Model Checking

Lecture 13 of 41. More Propositional and Predicate Logic

A Semantical Perspective on Verification of Knowledge

ON FUNCTIONAL SYMBOL-FREE LOGIC PROGRAMS

Development of a computer system to support knowledge acquisition of basic logical forms using fairy tale "Alice in Wonderland"

Introduction to formal semantics -

Discuss the size of the instance for the minimum spanning tree problem.

Mathematical Induction. Lecture 10-11

Why? A central concept in Computer Science. Algorithms are ubiquitous.

COMPUTER SCIENCE TRIPOS

WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT?

WOLLONGONG COLLEGE AUSTRALIA. Diploma in Information Technology

Lecture Notes in Discrete Mathematics. Marcel B. Finan Arkansas Tech University c All Rights Reserved

Chapter 1. NP Completeness I Introduction. By Sariel Har-Peled, December 30, Version: 1.05

Chapter II. Controlling Cars on a Bridge

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Lecture 8: Resolution theorem-proving

A Few Basics of Probability

CSE 459/598: Logic for Computer Scientists (Spring 2012)

University of Ostrava. Reasoning in Description Logic with Semantic Tableau Binary Trees

Page 1. CSCE 310J Data Structures & Algorithms. CSCE 310J Data Structures & Algorithms. P, NP, and NP-Complete. Polynomial-Time Algorithms

Chapter. NP-Completeness. Contents

Bounded Treewidth in Knowledge Representation and Reasoning 1

Predicate Logic. Example: All men are mortal. Socrates is a man. Socrates is mortal.

On the Modeling and Verification of Security-Aware and Process-Aware Information Systems

6.852: Distributed Algorithms Fall, Class 2

Jedd: A BDD-based Relational Extension of Java

Trust but Verify: Authorization for Web Services. The University of Vermont

ML for the Working Programmer

MPBO A Distributed Pseudo-Boolean Optimization Solver

How To Understand The Theory Of Hyperreals

General Information and Communication Technology. Second module of this course: Boolean logic. Some elements of computational complexity

DISCRETE MATH: LECTURE 3

CSC 373: Algorithm Design and Analysis Lecture 16

Monitoring Metric First-order Temporal Properties

Predicate logic. Logic in computer science. Logic in Computer Science (lecture) PART II. first order logic

CSL105: Discrete Mathematical Structures. Ragesh Jaiswal, CSE, IIT Delhi

Lecture 19: Introduction to NP-Completeness Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

Static Program Transformations for Efficient Software Model Checking

Updating Action Domain Descriptions

Logic in Computer Science: Logic Gates

Introducing Formal Methods. Software Engineering and Formal Methods

Introduction. The Quine-McCluskey Method Handout 5 January 21, CSEE E6861y Prof. Steven Nowick

Rules of Inference Friday, January 18, 2013 Chittu Tripathy Lecture 05

Model Checking: An Introduction

Solutions Q1, Q3, Q4.(a), Q5, Q6 to INTLOGS16 Test 1

Regression Verification: Status Report

Solutions to Homework 6 Mathematics 503 Foundations of Mathematics Spring 2014

Transcription:

CS510 Software Engineering Propositional Logic Asst. Prof. Mathias Payer Department of Computer Science Purdue University TA: Scott A. Carr Slides inspired by Xiangyu Zhang http://nebelwelt.net/teaching/15-cs510-se Spring 2015 Additional slides credit: Michael Reniers, Julia Lawall, and Neil Jones.

Motivation Many static analysis techniques rely on proofing that some set of conditions hold. We need to come up with a way to express these conditions and reason about them. SAT solving allows to test the satisfiablity of propositional formulas in the domain of Boolean values. SAT solving is used for, e.g., formal equivalence checking, model checking, formal verification, automatic test pattern generation, scheduling problems, and symbolic execution. We need to understand propositional logic and SAT solving to follow the techniques listed above. Mathias Payer (Purdue University) CS510 Software Engineering 2015 2 / 60

History of Logic Philosophical Logic (500BC to 19th century) Symbolic Logic (mid to late 19th century) Mathematical Logic (late 19th century to mid 20th century) Logic in Computer Science (now) Mathias Payer (Purdue University) CS510 Software Engineering 2015 3 / 60

Syntax of propositional logic Table of Contents 1 Syntax of propositional logic 2 Semantics of propositional logic 3 Semantic entailment Natural deduction of proof system Soundness and completeness 4 Validity and Satisfiability Conjunctive normal forms 5 SAT Solver Mathias Payer (Purdue University) CS510 Software Engineering 2015 4 / 60

Syntax Syntax of propositional logic F :== (P) ( F ) (F F ) (F F ) (F F ) P :== p q r... Propositional atoms (p, q, r,...) are used to describe declarative sentences like 1037 is a prime number, Every even number > 2 is the sum of two prime numbers, or All Martians like pepperoni on their pizza (i.e., they can be evaluated to true or false). Connective Symbol Alternative Symbols negation (not) disjunction (or) conjunction (and) & mplication (implies),, Mathias Payer (Purdue University) CS510 Software Engineering 2015 5 / 60

Syntax of propositional logic Syntax for propositional logic Binding priorities:,,,, (These help reduce the amount of brackets needed. Also, outermost brackets are often omitted.) Mathias Payer (Purdue University) CS510 Software Engineering 2015 6 / 60

Semantics of propositional logic Table of Contents 1 Syntax of propositional logic 2 Semantics of propositional logic 3 Semantic entailment Natural deduction of proof system Soundness and completeness 4 Validity and Satisfiability Conjunctive normal forms 5 SAT Solver Mathias Payer (Purdue University) CS510 Software Engineering 2015 7 / 60

Semantics of propositional logic Semantics for Propositional Logic The meaning of a formula depends on: The meaning of the propositional atoms (occurring in the formula) The meaning of the connectives (occurring in the formula) Mathias Payer (Purdue University) CS510 Software Engineering 2015 8 / 60

Semantics of propositional logic Semantics: Propositional Atoms The meaning of the propositional atoms (occurring in the formula): A declarative sentence is either true or false Captured as an assignment of truth values (B = {T, F }) to the propositional atoms a valuation v : P B Mathias Payer (Purdue University) CS510 Software Engineering 2015 9 / 60

Semantics of propositional logic Semantics: Connectives The meaning of an n-ary connective is captured by a function f : B n B Usually, such functions are specified by a truth table. A B A A B A B A B T T F T T T T F F F T F F T T F T T F F T F F T Mathias Payer (Purdue University) CS510 Software Engineering 2015 10 / 60

Semantics of propositional logic Example: Formula Evaluation Evaluate the following formula: (p q) (q r) (p r) p q r p q q r...... p r A B C T T T T T T T T T T F T F F F T T F T F T F T T T F F F T F F T F T T T T T T T F T F T F F T T F F T T T T T T F F F T T T T T Mathias Payer (Purdue University) CS510 Software Engineering 2015 11 / 60

Semantic entailment Table of Contents 1 Syntax of propositional logic 2 Semantics of propositional logic 3 Semantic entailment Natural deduction of proof system Soundness and completeness 4 Validity and Satisfiability Conjunctive normal forms 5 SAT Solver Mathias Payer (Purdue University) CS510 Software Engineering 2015 12 / 60

Semantic entailment Areas of Interest Semantic entailment. Many logical arguments are of the form: from the assumptions φ 1, φ 2,... φ n we know ψ. This is formalised by the semantic entailment relation =. E.g., M = A describes that a situation M satisfies a formula A. Formally, φ 1, φ 2,... φ n = ψ iff for all valuations v such that φ i (v) = T for all 1 i n we have ψ (v) = T Validity: a formula φ is valid if = φ holds. Satisfiability: a formula φ is sat if there exists a valuation v so that φ (v) = T. Mathias Payer (Purdue University) CS510 Software Engineering 2015 13 / 60

Semantic entailment Semantic Entailment How do we establish semantic entailment φ 1, φ 2,... φ n = ψ? Option 1: Construct a truth table. If formulas contain m propositional atoms, the truth table contains 2 m lines! Option 2: Give a proof. Suppose that (p q) (q r). Suppose that p. Then, as p q follows from (p q) (q r), we have q. Finally, as q r follows from (p q) (q r), we have r. Thus the formula holds (i.e., there is no contradiction). Mathias Payer (Purdue University) CS510 Software Engineering 2015 14 / 60

Semantic entailment Semantic Entailment Proof rules for inferring a conclusion ψ from a list of premises φ 1, φ 2,... φ n (x y means that y is provable from x): φ 1, φ 2,... φ n ψ(sequent) What is a proof of a sequent φ 1, φ 2,... φ n ψ? Proof rules may be instantiated: consistent replacement of variables with formulas. Constructing the proof is filling the gap between the premises and the conclusion by applying a suitable sequence of proof rules. Mathias Payer (Purdue University) CS510 Software Engineering 2015 15 / 60

Semantic entailment Natural Deduction: Conjunction Natural deduction of proof system Proof rules for conjunction: proofs of ψ φ are a concatenation of proofs for ψ and proofs of φ. introduction: ψ φ ψ φ i elimination: ψ φ ψ e 1 ψ φ φ e 2 Mathias Payer (Purdue University) CS510 Software Engineering 2015 16 / 60

Semantic entailment Conjunction: Exercise Natural deduction of proof system Prove (p q) r, s t q s. Given that we have (p q) r and s t we can prove q s. Linear representation: 1 (p q) r premise 2 s t premise 3 p q e 1 1 4 q e 2 3 5 s e 1 2 6 q s i 4,5 Mathias Payer (Purdue University) CS510 Software Engineering 2015 17 / 60

Semantic entailment Conjunction: Exercise (2) Natural deduction of proof system Prove (p q) r, s t q s. Given that we have (p q) r and s t we can prove q s. Tree representation: (p q) r p q q e 1 e 2 q s s t s e 1 i Mathias Payer (Purdue University) CS510 Software Engineering 2015 18 / 60

Semantic entailment Natural Deduction: Disjunction Natural deduction of proof system Proof rules for disjunction: introduction: ψ ψ φ i 1 φ ψ φ i 2 elminiation: φ ψ φ. χ χ ψ. χ e Mathias Payer (Purdue University) CS510 Software Engineering 2015 19 / 60

Semantic entailment Disjunction: Exercise Natural deduction of proof system Prove (p q) (p r) p (q r): 1 (p q) (p r) premise 2 p q assumption (1) 3 p e 1 2 4 q e 2 2 5 q r i 1 4 6 p (q r) i 3, 5 7 p r assumption (2) 8 p e 1 7 9 r e 2 7 10 q r i 2 9 11 p (q r) i 8,10 12 p (q r) e 1, 2-6, 7-11 Mathias Payer (Purdue University) CS510 Software Engineering 2015 20 / 60

Semantic entailment Natural Deduction: Implication Natural deduction of proof system Proof rules for implication: introduction elminiation φ φ. ψ φ ψ i φ ψ ψ e Mathias Payer (Purdue University) CS510 Software Engineering 2015 21 / 60

Semantic entailment Implication: Exercise Natural deduction of proof system Prove p q, q r p r: 1 p q premise 2 q r premise 3 p assumption 4 q e 1, 3 5 r e 2, 4 6 p r i 3-5 Mathias Payer (Purdue University) CS510 Software Engineering 2015 22 / 60

Semantic entailment Natural Deduction: Negation Natural deduction of proof system Proof rules for negation: introduction elimination: φ. φ i φ φ q Mathias Payer (Purdue University) CS510 Software Engineering 2015 23 / 60

Negation: Exercise Semantic entailment Natural deduction of proof system Prove p q, p q p: 1 p q premise 2 p q premise 3 p assumption 4 q e 1,3 5 q e 2,3 6 e 4, 5 7 p i 3-6 Mathias Payer (Purdue University) CS510 Software Engineering 2015 24 / 60

Semantic entailment Negation: Exercise (2) Natural deduction of proof system Prove p q p q: 1 p q premise 2 p assumption ( e 1 ) 3 p assumption (contradiction) 4 e 3, 2 5 q e 4 6 p q i 3-5 7 q assumption ( e 2 ) 8 p assumption 9 q copy 7 10 p q i 8, 9 11 p q e 1, 2-6, 7-10 Mathias Payer (Purdue University) CS510 Software Engineering 2015 25 / 60

Semantic entailment Natural Deduction: Falsum Natural deduction of proof system Proof rules for falsum: introduction: there are no proof rules for the introduction of elimination: φ e Mathias Payer (Purdue University) CS510 Software Engineering 2015 26 / 60

Semantic entailment Natural deduction of proof system Natural Deduction: Double Negation Proof rules for double negation: introduction: elimination: φ φ i φ φ e Mathias Payer (Purdue University) CS510 Software Engineering 2015 27 / 60

Semantic entailment Natural deduction of proof system Natural Deduction: Derived Rules Modus Tollens: φ ψ ψ MT φ Reduction Ad Absurdum: φ. φ RAA Tertium Non Datur: φ φ TND TND can also be called Law of the Excluded Middle. Mathias Payer (Purdue University) CS510 Software Engineering 2015 28 / 60

Semantic entailment Soundness and completeness Natural Deduction is Sound and Complete Natural deduction is sound: if φ 1, φ n ψ, then φ 1, φ n = ψ Natural deduction is complete: if φ 1, φ n = ψ, then φ 1, φ n ψ Mathias Payer (Purdue University) CS510 Software Engineering 2015 29 / 60

Validity and Satisfiability Table of Contents 1 Syntax of propositional logic 2 Semantics of propositional logic 3 Semantic entailment Natural deduction of proof system Soundness and completeness 4 Validity and Satisfiability Conjunctive normal forms 5 SAT Solver Mathias Payer (Purdue University) CS510 Software Engineering 2015 30 / 60

Validity and Satisfiability Validity and Satisfiability of Propositional Formulas A formula φ is valid if for any valuations v, φ (v) = A formula φ is satisfiable if there exists a valuation v such that φ (v) = Mathias Payer (Purdue University) CS510 Software Engineering 2015 31 / 60

Validity and Satisfiability Validity and Satisfiability: Example p q satisfiable p (q p) valid(and satisfiable) p p unsatisfiable Mathias Payer (Purdue University) CS510 Software Engineering 2015 32 / 60

Validity and Satisfiability Deciding Validity What are the means to decide whether or not a given formula φ is valid? Use techniques for semantic entailment (e.g., natural deduction) Use a calculus for semantical equivalence to prove that φ. Transform φ into some normal form that is semantically equivalent and then apply dedicated (syntactic) techniques. (φ and ψ are semantically equivalent (not φ ψ) iff φ = ψ and ψ = φ. Mathias Payer (Purdue University) CS510 Software Engineering 2015 33 / 60

Validity and Satisfiability Deciding Validity (2) Lemma 1.41 A decision procedure for validity can be used for semantic entailment. φ 1, φ n = ψ iff = φ 1 (φ 2 (φ n ψ)) Mathias Payer (Purdue University) CS510 Software Engineering 2015 34 / 60

Validity and Satisfiability Deciding Validity (3) If I m wealthy, then I m happy. I am happy.therefore, I m wealthy. If John drinks beer, he is at least 21 years old. John does not drink beer.therefore, John is not yet 21 years old. If I study, then I will not fail basket weaving 101. If I do not play cards too often, then I will study. I failed basket weaving 101.Therefore, I played cards too often. Mathias Payer (Purdue University) CS510 Software Engineering 2015 35 / 60

Validity and Satisfiability Conjunctive Normal Form Conjunctive normal forms A literal is either an atom p or the negation of an atom p. A formula φ is in conjunctive normal form (CNF) if it is a conjunction of a number of disjunctions and literals only. L ::= P P C ::= L C C CNF ::= C CNF CNF literal clause CNF Mathias Payer (Purdue University) CS510 Software Engineering 2015 36 / 60

CNF Examples Validity and Satisfiability Conjunctive normal forms p, p CNF p not CNF p p CNF (p r) ( r s) q CNF (p q) q not CNF Mathias Payer (Purdue University) CS510 Software Engineering 2015 37 / 60

Validity in CNF Validity and Satisfiability Conjunctive normal forms Remember a formula is valid iff any of its equivalent formulas is valid. Reduce the problem of determining whether any φ is valid to the problem of computing an equivalent ψ φ such that ψ is in CNF and then checking ψ. Deciding validity in CNF (C 1 C 2 C n ) is incremental: each clause C i must be valid individually. Each clause C i consists of a disjunction of literals L 1 L 2 L m. A disjunction of literals is valid iff there are 1 i, j m such that L i is L j. Mathias Payer (Purdue University) CS510 Software Engineering 2015 38 / 60

Validity and Satisfiability Validity in CNF (2) Conjunctive normal forms We now have a simple way to check the validity of = φ as long as φ is in CNF: inspect all conjuncts ψ k of φ and search for atoms in ψ k so that ψ k also contains their negation. If a match is found for all conjuncts we have = φ. Otherwise (i.e., some conjunct contains no pair L i and L j ), φ is not valid. Mathias Payer (Purdue University) CS510 Software Engineering 2015 39 / 60

Validity and Satisfiability Transformation into CNF Conjunctive normal forms 1 IF: Remove all occurrences of : translate ψ η to ψ η (in: formula, out: formula without ). 2 NNF: Obtain a negation normal form (NNF) where only atoms are negated (in: formula without, out: formula in NNF): N ::= P P (N N) (N N) P ::= p q r 3 CNF: Apply distribution laws (in: formula in NNF, out: formula in CNF): replace (φ 1 φ 2 ) ψ by (φ 1 ψ) (φ 2 ψ) replace φ (ψ 1 ψ 2 ) by (φ ψ 1 ) (φ ψ 2 ) Therefore, CNF (NNF (IF (φ))) is in CNF and semantically equivalent with φ. Mathias Payer (Purdue University) CS510 Software Engineering 2015 40 / 60

Validity and Satisfiability Conjunctive normal forms Transformation into CNF: IF algorithm Remove implications from the formula by applying the following replacement until you reach a fix-point: ψ η to ψ η Inductive definition of IMPL FREE: IF (p) = p IF ( φ) = IF (φ) IF (φ 1 φ 2 ) = IF (φ 1 ) IF (φ 2 ) IF (φ 1 φ 2 ) = IF (φ 1 ) IF (φ 2 ) IF (φ 1 φ 2 ) = IF (φ 1 ) IF (φ 2 ) Properties of IF : it is (i) well-defined (terminates for any input), (ii) IF (ψ) ψ (output of both formulas are semantically equivalent),and (iii) IF (ψ) is an implication-free formula for any formula ψ. Mathias Payer (Purdue University) CS510 Software Engineering 2015 41 / 60

Validity and Satisfiability Conjunctive normal forms Transformation into CNF: NNF algorithm Simplify formula into negation normal form by repeatedly applying pattern rewriting rules: φ replace by φ (φ ψ) replace by φ ψ (φ ψ) replace by φ ψ Inductive definition of NFF: NNF (p) = p NNF ( p) = p NNF ( φ) = NNF (φ) NNF ( (φ ψ)) = NNF ( φ) NNF ( ψ) NNF ( (φ ψ)) = NNF ( φ) NNF ( ψ) NNF (φ ψ) = NNF (φ) NNF (ψ) NNF (φ ψ) = NNF (φ) NNF (ψ) Mathias Payer (Purdue University) CS510 Software Engineering 2015 42 / 60

Validity and Satisfiability Conjunctive normal forms Transformation into CNF: NNF algorithm (2) Properties of NNF : it is (i) well-defined (terminates for any input), (ii) NNF (ψ) ψ (output of both formulas are semantically equivalent),and (iii) NNF (ψ) is a negation-free formula for any formula ψ. Mathias Payer (Purdue University) CS510 Software Engineering 2015 43 / 60

Validity and Satisfiability Conjunctive normal forms Transformation into CNF: CNF algorithm Simplify formula into conjunctive normal form (CNF) by repeatedly applying pattern rewriting rules: (φ 1 φ 2 ) ψ replace by (φ 1 ψ) (φ 2 ψ) φ (ψ 1 ψ 2 ) replace by (φ ψ 1 ) (φ ψ 2 ) Mathias Payer (Purdue University) CS510 Software Engineering 2015 44 / 60

Validity and Satisfiability Conjunctive normal forms Transformation into CNF: CNF algorithm (2) Inductive definition of CNF: CNF (p) = p CNF ( p) = p CNF (φ 1 φ 2 ) = CNF (φ 1 ) CNF (φ 2 ) CNF (φ 1 φ 2 ) = D(CNF (φ 1 ), CNF (φ 2 )) D(φ 11, φ 2 ) D(φ 12, φ 2 ) φ 1 = φ 11 φ 12 D(φ 1, φ 2 ) = D(φ 1, φ 21 ) D(φ 1, φ 22 ) φ 2 = φ 21 φ 22 φ 1 φ 2 otherwise Properties of CNF and D: CNF and D are (i) well-defined (terminate for any input), (ii) D(φ, ψ) φ ψ and CNF (φ) φ (output of both formulas are semantically equivalent),and (iii) CNF (φ) is in CNF for any formula φ in NNF and D(φ, ψ) is in CNF for any formulas φ and ψ in CNF. Mathias Payer (Purdue University) CS510 Software Engineering 2015 45 / 60

CNF: Example Validity and Satisfiability Conjunctive normal forms Find a CNF for p q r: p q r premise (p q) r apply IMPL FREE ( p q) r apply NNF ( p q) r apply NNF ( p r) (q r) apply CNF Mathias Payer (Purdue University) CS510 Software Engineering 2015 46 / 60

Table of Contents SAT Solver 1 Syntax of propositional logic 2 Semantics of propositional logic 3 Semantic entailment Natural deduction of proof system Soundness and completeness 4 Validity and Satisfiability Conjunctive normal forms 5 SAT Solver Mathias Payer (Purdue University) CS510 Software Engineering 2015 47 / 60

SAT Solver SAT Solver Find satisfying valuations to a propositional formula. Develop a systematic approach to test all possible valuations to find a satisfiable valuation. SAT solving is NP-complete, so the worst-case complexity will always be exponential.but good heuristics exist. Mathias Payer (Purdue University) CS510 Software Engineering 2015 48 / 60

SAT Solver Forcing Laws: Negation φ φ T F F T o T F o F T Mathias Payer (Purdue University) CS510 Software Engineering 2015 49 / 60

SAT Solver Forcing Laws: Conjunction φ ψ φ ψ T T T T F F F T F F F F φ, ψ φ, ψ T = T, T T, T = T?, F = F F,? = F, φ ψ, ψ φ F, T = F F, T = F Mathias Payer (Purdue University) CS510 Software Engineering 2015 50 / 60

SAT Solver Forcing Laws: Completeness Is this enough?we now have and. We can convert any propositional formula (without loss of generality) to a formula that only contains and. Simplify formula into, T (p) T ( φ) T (φ ψ) T (φ ψ) T (φ ψ) = p = T (φ) = T (φ) T (ψ) = ( T (φ) T (ψ)) = (T (φ) T (ψ)) This translation results in a linear growth in the formula size. Mathias Payer (Purdue University) CS510 Software Engineering 2015 51 / 60

SAT Solving SAT Solver 1 Convert formula to and 2 Translate the formula to a DAG, sharing common subterms. 3 Set the root to T and apply the forcing rules. The formula is satisfiable iff all nodes are consistently annotated. Mathias Payer (Purdue University) CS510 Software Engineering 2015 52 / 60

SAT Solver Example: Satisfiability Formula: p (q p) p ( q p): 1T 2T 3F 4T 5T 5T 6F 2T p q 6F Is the formula satisfiable? Yes: p = T, q = F is a witness. Mathias Payer (Purdue University) CS510 Software Engineering 2015 53 / 60

Example: Validity SAT Solver Show the validity of (p (p q)) p. This formula is valid if ((p (p q)) p) is not satisfiable.translated formula: ( p (p q)) p. 1T 2T 2T 3F 4F 5T 3F p q Contradiction! Mathias Payer (Purdue University) CS510 Software Engineering 2015 54 / 60

SAT Solver Example: Satisfiability Formula: (p (p q)) p ((p (p q)) p) 1T 2F p q We have an unsatisfiable formula. Now what? Mathias Payer (Purdue University) CS510 Software Engineering 2015 55 / 60

SAT Solver Limitation of the SAT solver algorithm Fails for all formulas of the form (φ 1 φ 2 ). Yet, some are valid and thus satisfiable: p p (p p) Some are not valid and thus not satisfiable: ( ) (p p p p) ( (p p) (p p)) Mathias Payer (Purdue University) CS510 Software Engineering 2015 56 / 60

SAT Solver Extended Algorithm SAT Checking 1 Pick an unmarked node and add temporary T and F marks. 2 Use the forcing rules to propagate both marks. 3 If both marks lead to a contradiction, report a contradiction. 4 If both marks lead to some node having the same value, permanently assign the node that value. 5 Erase the remaining temporary marks and continue. Complexity: O(n 3 ): (i) testing each unmarked node O(n), (ii) testing a given unmarked node O(n), (iii) repeating the process when a new node is marked O(n). Mathias Payer (Purdue University) CS510 Software Engineering 2015 57 / 60

SAT Solver Extended Algorithm: Example Formula: (q r) ( (q r) ( q r)): 3F 2T 8T q 6T 7T r 6T 4T 1T 2T 4F 5F 3F 5T 5F 6T 8T q 6T 7T r 6T 7T 7T r 6T 8T q 6T r is true in both cases. Fix r to T. Mathias Payer (Purdue University) CS510 Software Engineering 2015 58 / 60

SAT Solver Extended Algorithm: Example (2) 1T 2T 2T 3F 3F 5F q r 4T 7T 8F 6F 7T 5F q r 4T 6T r 4T 5F q Satisfiable! Mathias Payer (Purdue University) CS510 Software Engineering 2015 59 / 60

Questions? SAT Solver? Mathias Payer (Purdue University) CS510 Software Engineering 2015 60 / 60