Decision Procedures. An Algorithmic Point of View. Decision Procedures for Propositional Logic. D. Kroening O. Strichman.

Similar documents
Finite Model Generation for Isabelle/HOL Using a SAT Solver

SAT Solver. CS 680 Formal Methods Jeremy Johnson

2SAT Andreas Klappenecker

Translating into SAT

NP-Complete Reductions 2

Propositional Calculus: Boolean Algebra and Simplification. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Mixed Integer Linear Programming

Decision Procedures and SMT

P -vs- NP. NP Problems. P = polynomial time. NP = non-deterministic polynomial time

Boolean Functions (Formulas) and Propositional Logic

NP-Completeness. Algorithms

Decision Procedures. An Algorithmic Point of View. Bit-Vectors. D. Kroening O. Strichman. Version 1.0, ETH/Technion

Deductive Methods, Bounded Model Checking

PROPOSITIONAL LOGIC (2)

SAT. ReRiSE 14 Winter School Reasoning for Rigorous System Enineering. Johannes Kepler University Linz, Austria

8.1 Polynomial-Time Reductions

8 NP-complete problem Hard problems: demo

Normal Forms for Boolean Expressions

W4231: Analysis of Algorithms

NP and computational intractability. Kleinberg and Tardos, chapter 8

Systemtheory 2. Formal Systems 2 # SS 2006 Johannes Kepler Universität Linz, Österreich

Decision Procedures in First Order Logic

Implementation of a Sudoku Solver Using Reduction to SAT

Seminar decision procedures: Certification of SAT and unsat proofs

Unit 8: Coping with NP-Completeness. Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems. Y.-W.

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

MajorSat: A SAT Solver to Majority Logic

Chapter 10 Part 1: Reduction

Symbolic Methods. The finite-state case. Martin Fränzle. Carl von Ossietzky Universität FK II, Dpt. Informatik Abt.

NP-Completeness of 3SAT, 1-IN-3SAT and MAX 2SAT

Example of a Demonstration that a Problem is NP-Complete by reduction from CNF-SAT

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

The Satisfiability Problem [HMU06,Chp.10b] Satisfiability (SAT) Problem Cook s Theorem: An NP-Complete Problem Restricted SAT: CSAT, k-sat, 3SAT

Decision Procedures for Equality Logic. Daniel Kroening and Ofer Strichman 1

Satisfiability. Michail G. Lagoudakis. Department of Computer Science Duke University Durham, NC SATISFIABILITY

Best known solution time is Ω(V!) Check every permutation of vertices to see if there is a graph edge between adjacent vertices

Parallel and Distributed Computing

Computability Theory

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

CPSC 320 Notes: What's in a Reduction?

Introduction to Parameterized Complexity

Boolean Representations and Combinatorial Equivalence

Circuit versus CNF Reasoning for Equivalence Checking

Efficient Circuit to CNF Conversion

1 Definition of Reduction

Principles of AI Planning. Principles of AI Planning. 7.1 How to obtain a heuristic. 7.2 Relaxed planning tasks. 7.1 How to obtain a heuristic

Enforcement in Abstract Argumentation via Boolean Optimization

SAT-CNF Is N P-complete

NP-complete Reductions

Some Hardness Proofs

Lecture 14: Lower Bounds for Tree Resolution

SAT Solvers. Ranjit Jhala, UC San Diego. April 9, 2013

Chapter 3 Complexity of Classical Planning

Where Can We Draw The Line?

Reductions. Linear Time Reductions. Desiderata. Reduction. Desiderata. Classify problems according to their computational requirements.

Exercises Computational Complexity

EXTENDING SAT SOLVER WITH PARITY CONSTRAINTS

Chapter 8. NP-complete problems

(p 300) Theorem 7.27 SAT is in P iff P=NP

CS 512, Spring 2017: Take-Home End-of-Term Examination

Homework 1. Due Date: Wednesday 11/26/07 - at the beginning of the lecture

4.1 Review - the DPLL procedure

1.4 Normal Forms. We define conjunctions of formulas as follows: and analogously disjunctions: Literals and Clauses

CSc Parallel Scientific Computing, 2017

CSE Theory of Computing Fall 2017 Project 1-SAT Solving

A New Reduction from 3-SAT to Graph K- Colorability for Frequency Assignment Problem

Linear Time Unit Propagation, Horn-SAT and 2-SAT

P and NP (Millenium problem)

Reductions and Satisfiability

Massively Parallel Seesaw Search for MAX-SAT

ALGORITHMS EXAMINATION Department of Computer Science New York University December 17, 2007

Improving Coq Propositional Reasoning Using a Lazy CNF Conversion

1 Introduction. 1. Prove the problem lies in the class NP. 2. Find an NP-complete problem that reduces to it.

Discrete Optimization. Lecture Notes 2

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

Provably Optimal Test Cube Generation using Quantified Boolean Formula Solving

CSP- and SAT-based Inference Techniques Applied to Gnomine

Exam in Algorithms & Data Structures 3 (1DL481)

Combining forces to solve Combinatorial Problems, a preliminary approach

Chapter 2 PRELIMINARIES

Computer-Aided Program Design

COMP4418 Knowledge Representation and Reasoning

Learning a SAT Solver from Single-

Propositional Calculus. Math Foundations of Computer Science

Lecture 2: Symbolic Model Checking With SAT

Online Appendix: A Stackelberg Game Model for Botnet Data Exfiltration

What's the difference between the entailment symbol with the equals vs the entailment symbol with one line? Single turnstile meaning

Automated Testing and Debugging of SAT and QBF Solvers

DM841 DISCRETE OPTIMIZATION. Part 2 Heuristics. Satisfiability. Marco Chiarandini

P and NP CISC5835, Algorithms for Big Data CIS, Fordham Univ. Instructor: X. Zhang

The Resolution Algorithm

Motivation. CS389L: Automated Logical Reasoning. Lecture 5: Binary Decision Diagrams. Historical Context. Binary Decision Trees

Computational problems. Lecture 2: Combinatorial search and optimisation problems. Computational problems. Examples. Example

Prove, where is known to be NP-complete. The following problems are NP-Complete:

9.1 Cook-Levin Theorem

Fall 2009 CSE Qualifying Exam Core Subjects. September 19, 2009

Minimum Satisfying Assignments for SMT. Işıl Dillig, Tom Dillig Ken McMillan Alex Aiken College of William & Mary Microsoft Research Stanford U.

Polynomial SAT-Solver Algorithm Explanation

Engineering 9867 Advanced Computing Concepts

NP-Hardness. We start by defining types of problem, and then move on to defining the polynomial-time reductions.

Transcription:

Decision Procedures An Algorithmic Point of View Decision Procedures for Propositional Logic D. Kroening O. Strichman ETH/Technion Version 1.0, 2007

Part I Decision Procedures for Propositional Logic

Outline 1 Modeling with Propositional Logic SAT Example: Equivalence Checking if-then-else Chains SAT Example: Circuit Equivalence Checking 2 Formal Definition SAT 3 Conjunctive Normal Form Definition Tseitin Transformation DIMACS CNF D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 3 / 24

D. Kroening, O. Strichman How(ETH/Technion) to check that these Decisiontwo Procedures versions are equivalent? Version 1.0, 2007 4 / 24 SAT Example: Equivalence Checking if-then-else Chains Optimization of if-then-else chains original C code if(!a &&!b) h(); else if(!a) g(); else f(); optimized C code if(a) f(); else if(b) g(); else h(); if(!a) { if(a) f(); if(!b) h(); else { else g(); if(!b) h(); } else f(); else g(); }

SAT Example II 1 Represent procedures as independent Boolean variables original := optimized := if a b then h if a then f else if a then g else if b then g else f else h 2 Compile if-then-else chains into Boolean formulae compile(if x then y else z) (x y) ( x z) 3 Check equivalence of Boolean formulae compile(original) compile(optimized) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 5 / 24

Compilation original if a b then h else if a then g else h ( a b) h ( a b) if a then g else f ( a b) h ( a b) ( a g a f) optimized if a then f else if b then g else h a f a if b then g else h a f a (b g b h) ( a b) h ( a b) ( a g a f) a f a (b g b h) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 6 / 24

How to Check (In)Equivalence? Reformulate it as a satisfiability (SAT) problem: Is there an assignment to a, b, f, g, h, which results in different evaluations of original and optimized? D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 7 / 24

How to Check (In)Equivalence? Reformulate it as a satisfiability (SAT) problem: or equivalently: Is there an assignment to a, b, f, g, h, which results in different evaluations of original and optimized? Is the boolean formula compile(original) compile(optimized) satisfiable? Such an assignment provides an easy to understand counterexample D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 7 / 24

SAT Example: Circuit Equivalence Checking b a c a b c b a c (a b) (b c) equivalent? b a c (a b) (b c) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 8 / 24

SAT SAT (Satisfiability) the classical NP-complete problem: Given a propositional formula f over n propositional variables V = {x, y,...}. Is there are an assignment σ : V {0, 1} with σ(f) = 1? D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 9 / 24

SAT SAT belongs to NP There is a non-deterministic Touring-machine deciding SAT in polynomial time: guess the assignment σ (linear in n), calculate σ(f) (linear in f ) Note: on a real (deterministic) computer this still requires 2 n time SAT is complete for NP (see complexity / theory class) Implications for us: general SAT algorithms are probably exponential in time (unless NP = P) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 10 / 24

Conjunctive Normal Form Definition (Conjunctive Normal Form) A formula in Conjunctive Normal Form (CNF) is a conjunction of clauses C 1 C 2... C n each clause C is a disjunction of literals C = L 1... L m and each literal is either a plain variable x or a negated variable x. D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 11 / 24

Conjunctive Normal Form Definition (Conjunctive Normal Form) A formula in Conjunctive Normal Form (CNF) is a conjunction of clauses C 1 C 2... C n each clause C is a disjunction of literals C = L 1... L m and each literal is either a plain variable x or a negated variable x. Example (a b c) (a b) (a c) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 11 / 24

CNF for Parity Function is Exponential b a 0 1 0 1 0 0 1 1 0 1 0 1 0 1 0 d 1 c no merging in the Karnaugh map all clauses contain all variables CNF for parity with n variables has 2 n 1 clauses a b c d D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 12 / 24

CNF for Parity Function is Exponential b a 0 1 0 1 0 0 1 1 0 1 0 1 0 1 0 d 1 c no merging in the Karnaugh map all clauses contain all variables CNF for parity with n variables has 2 n 1 clauses a b c d Better ideas? D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 12 / 24

Example of Tseitin Transformation: Circuit to CNF y x a u o b c v w w D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 13 / 24

Example of Tseitin Transformation: Circuit to CNF a b c x u v w y w o o (x a c) (y b x) (u a b) (v b c) (w u v) (o y w) o (x a) (x c) (x a c)... o (x a) (x c) (x a c)... D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 13 / 24

Algorithmic Description of Tseitin Transformation Tseitin Transformation 1 For each non input circuit signal s generate a new variable x s 2 For each gate produce complete input / output constraints as clauses 3 Collect all constraints in a big conjunction D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 14 / 24

Algorithmic Description of Tseitin Transformation Tseitin Transformation 1 For each non input circuit signal s generate a new variable x s 2 For each gate produce complete input / output constraints as clauses 3 Collect all constraints in a big conjunction The transformation is satisfiability equivalent: the result is satisfiable iff and only the original formula is satisfiable Not equivalent in the classical sense to original formula: it has new variables D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 14 / 24

Algorithmic Description of Tseitin Transformation Tseitin Transformation 1 For each non input circuit signal s generate a new variable x s 2 For each gate produce complete input / output constraints as clauses 3 Collect all constraints in a big conjunction The transformation is satisfiability equivalent: the result is satisfiable iff and only the original formula is satisfiable Not equivalent in the classical sense to original formula: it has new variables You an get a satisfying assignment for original formula by projecting the satisfying assignment onto the original variables D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 14 / 24

Tseitin Transformation: Input / Output Constraints Negation: x y (x y) (y x) (x y) (y x) Disjunction: x (y z) (y x) (z x) (x (y z)) (y x) (z x) (x y z) Conjunction: x (y z) (x y) (x z) ((y z) x) (x y) (x z) ((y z) x) (x y) (x z) (y z x) Equivalence: x (y z) (x (y z)) ((y z) x) (x ((y z) (z y)) ((y z) x) (x (y z)) (x (z y)) ((y z) x) (x y z) (x z y) ((y z) x) (x y z) (x z y) (((y z) (y z)) x) (x y z) (x z y) ((y z) x) ((y z) x) (x y z) (x z y) (y z x) (y z x) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 15 / 24

Optimizations for the Tseitin Transformation Goal is smaller CNF (less variables, less clauses) Extract multi argument operands (removes variables for intermediate nodes) NNF: half of AND, OR node constraints may be removed due to monotonicity use sharing D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 16 / 24

DIMACS CNF DIMACS CNF format = standard format for CNF Used by most SAT solvers Plain text file with following structure: p cnf <# variables> <# clauses> <clause> 0 <clause> 0... One or more lines per clause D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 17 / 24

DIMACS CNF Every clause is a list of numbers, separated by spaces A clause ends with 0 Every number 1, 2,... corresponds to a variable variable names (e.g., a, b,...) have to be mapped to numbers A negative number corresponds to negation Let a have number 5. Then a is -5. D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 18 / 24

DIMACS CNF: Example 4 variables, 3 clauses CNF file: p cnf 4 3 1 2-3 0 2-1 0 4-2 -1 0 (x 1 x 2 x 3 ) (x 2 x 1 ) (x 4 x 2 x 1 ) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 19 / 24

Example SAT: Circuit Equivalence number assignment: formula: o (x a c) (y b x) (u a b) (v b c) (w u v) (o y w) variable number o 1 a 2 c 3 x 4 b 5 y 6 u 7 v 8 w 9 Simply in order of occurrence. D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 20 / 24

Example SAT: Circuit Equivalence formula clauses DIMACS o o 1 0 x a c a x 2-4 0 c x 3-4 0 a c x -2-3 4 0 y b x x y -4 6 0 b y -5 6 0 x b y 4 5-6 0 u a b a u -2 7 0 b u -5 7 0 a b u 2 5-7 0 v b c b v -5 8 0 c v -3 8 0 b c v 5 3-8 0 w u v u w 7-9 0 v w 8-9 0 u v w -7-8 9 0 o y w y w o -6-9 -1 0 y w o 6 9-1 0 y w o -6 9 1 0 D. Kroening, O. Strichman (ETH/Technion) Decision y wprocedures o 6-9 1 0Version 1.0, 2007 21 / 24

Example SAT: Circuit Equivalence Let s change the circuit! a b c x u v w y w o o (x a c) (y b x) (u a b) (v b c) (w u v) (o y w) Is the CNF satisfiable? D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 22 / 24

Example SAT: Circuit Equivalence Output of the SAT solver: SATISFIABLE 1 2 3 4-5 -6 7 8 9 Values of the variables: variable number value o 1 1 a 2 1 c 3 1 x 4 1 b 5 0 y 6 0 u 7 1 v 8 1 w 9 1 Caveat: there is more than one solution D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 23 / 24

Example SAT: Circuit Equivalence Satisfying assignment mapped to the circuit: a=1 b=0 c=1 x=1 u=1 w v=1 y=0 w=1 o=1 variable value o 1 a 1 c 1 x 1 b 0 y 0 u 1 v 1 w 1 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 24 / 24