Satisfiability 6 the Decision Problem 7
Total Page:16
File Type:pdf, Size:1020Kb
Satisfiability Difficult Problems Dealing with SAT Implementation Klaus Sutner Carnegie Mellon University 2020/02/04 Finding Hard Problems 2 Entscheidungsproblem to the Rescue 3 The Entscheidungsproblem is solved when one knows a pro- cedure by which one can decide in a finite number of operations So where would be look for hard problems, something that is eminently whether a given logical expression is generally valid or is satis- decidable but appears to be outside of P? And, we’d like the problem to fiable. The solution of the Entscheidungsproblem is of funda- be practical, not some monster from CRT. mental importance for the theory of all fields, the theorems of which are at all capable of logical development from finitely many The Circuit Value Problem is a good indicator for the right direction: axioms. evaluating Boolean expressions is polynomial time, but relatively difficult D. Hilbert within P. So can we push CVP a little bit to force it outside of P, just a little bit? In a sense, [the Entscheidungsproblem] is the most general Say, up into EXP1? problem of mathematics. J. Herbrand Exploiting Difficulty 4 Scaling Back 5 Herbrand is right, of course. As a research project this sounds like a Taking a clue from CVP, how about asking questions about Boolean fiasco. formulae, rather than first-order? But: we can turn adversity into an asset, and use (some version of) the Probably the most natural question that comes to mind here is Entscheidungsproblem as the epitome of a hard problem. Is ϕ(x1, . , xn) a tautology? The original Entscheidungsproblem would presumable have included arbitrary first-order questions about number theory. This would indeed be where ϕ is a Boolean formula, with variables x , . , x . very difficult, truth in arithmetic requires a monster oracle (ω). 1 n ∅ Close, but no cigar. We need something less ambitious and closer to real algorithms. Satisfiability 6 The Decision Problem 7 For technical reasons, it is better to ask the very similar question Problem: Satisfiability (SAT) Instance: A Boolean formula ϕ(x1, . , xn). Is ϕ(x1, . , xn) satisfiable? Question: Is ϕ satisfiable? Obviously, ϕ is a tautology iff ϕ fails to be satisfiable, so nothing is n lost. ¬ The difficulty here comes from the fact that there are 2 possible truth assignments σ : Var 2 . Even though we can evaluate ϕ[σ] in linear time, any algorithm→ using brute-force search will be exponential, But, as we will see, satisfiability is slightly better behaved than tautology something like 2npoly(n). if one is concerned about resource bounds. This has to do with convenient normal forms: ϕ may be in normal form (such as CNF), but ϕ is not. Of course, that does not mean that there is no better algorithm, ¬ brute-force is just the most obvious line of attack. It would also work for Tautology. Aside: Problem Specification 8 Mighty SAT 9 Since Garey and Johnson published their famous Computers and Intractability in 1979, it has become standard to specify a decision If you think of a Boolean formula as the kind to little thingy you problem like so: encountered in 151, they might seem pretty feeble. E.g., (A B) (B C) (A C) Problem: Problem Name (catchy acronym) ⇒ ⇒ ⇒ ⇒ ⇒ Instance: Description of an instance x. Question: Does x have property such-and-such? is clearly a tautology (the infamous cut rule). It is quite useful as a logcical axiom in a formal system, though. In fact, all the logical axioms in any of the standard systems are obviously tautologies. The description has to be in terms of a finite data structure, ultimately a string x 2?. But there is no need to spell out all the details, we have ∈ But: what if the formula has 10000 variables, and takes a megabyte of reasonable standard conventions (e.g., numbers are written in binary). memory just to write it down? Your intuition will tell you zip about a monster like that. Unfortunately, big formulae are where the action is. The question must have a clear Yes/No answer (no counting, no data structures, . ). Example 1: VC to SAT 10 Coding Covers 11 As a warm-up exercise showing off the expressiveness of SAT, we will The idea is simply that show how to translate the Vertex Cover problem into a satisfiability σ = p x is in the alleged cover problem. | x ⇐⇒ So the truth assignment σ is just a bitvector for the set Problem: Vertex Cover Cσ = x σ = px V . Instance: A ugraph G, a bound k. { | | } ⊆ Question: Does G have a vertex cover of size k? We need to construct a formula ΦG,k that enforces this interpretation. Let’s ignore the cardinality part for the moment. Every edge needs to have at least one endpoint in the alleged cover C : For any translation to SAT, it is critical to interpret the Boolean variables σ the right way. Let’s assume G looks like [n],E . It seems natural to introduce n pu pv h i ∨ Boolean variables (u,v) E ^∈ px 1 x n, ≤ ≤ This conjunction has size O(n2), so we are good. one for each vertex x. Counting 12 Problems with Reductions 13 To establish a reduction from A to B we need to avoid three possible We also need to make sure that C = k. | σ| errors: Write CNTr,s(p1, p2, . , pr) for a formula that is true under σ iff exactly Logical correctness: we must have x A f(x) B. s of the r variables are true. ∈ ⇔ ∈ We could simply add CNTn,k(p1, p2, . , pn) to ΦG and be done. Computational simplicity: f must be easy to compute. Size constraint: f(x) must not be too long. Easy, what could possibly go wrong? In the heat of battle, it’s quite possible to screw up one of these issues. Threshold Functions 14 Expressiveness 15 The standard way to get a counting formula is to use threshold functions. Lots of Boolean functions can be defined in terms of threshold functions. Definition thrn is the constant tt. n 0 A threshold function thrm, 0 m n, is an n-ary Boolean function ≤ ≤ n defined by thr1 is n-ary disjunction. n 1 if #(i xi = 1) m, n thrm(x) = ≥ thrn is n-ary conjunction. (0 otherwise. n n thrk (p) thrk+1(p) is the counting function: CNTn,k(p1, p2, . , pn), “exactly∧k ¬out of n.” n So thrm(x) simply means that at least m of the n variables are true. Dire Warning 16 How Big? 17 For example, CNTn,2(p) looks like A casual observer might say this formula has size around k, but that’s (p p ) (p p p ) totally wrong: we need to expand out the disjunctions and conjunctions: i ∧ j ∧ ¬ i ∧ j ∧ k i<j i<j<k strictly speaking, a Boolean formula must only use operators of arity 2 _ _ (plus negation). What would the formula CNT (x , x , . , x ) look like? r,s 1 2 r n But that means that CNTn,k has size something like k+1 . This is not polynomial in n for variable k. xi xi ∧ ¬ I [r]k i I J [r]k+1 i J ⊆_ ^∈ ⊆_ ^∈ To be sure, it would work for fixed k, but that is not what the VC problem asks. Here [r]k denotes all subsets of [r] of cardinality k. Counting in Style 18 Total Damage 19 To keep the cardinality formula small, we introduce new variables q 0 i n, 0 j k + 1 i,j 2 ≤ ≤ ≤ ≤ We get a formula Φg,k of size O(n ) (at least with uniform size function) with the intent that that clearly can be constructed from G and k in polynomial time. A closer look shows that we can actually get away with just logarithmic q thri (p , . , p ) space: all we need is a few loops over variables. i,j ⇔ j 1 i We can determine the qi,j in a dynamic programming style, very much Moreover, like an instance of CVP. σ = Φ C is a vertex cover of size k | G,k ⇐⇒ σ qi,0 = 1 i = 0, . , n and we have our translation to SAT. q0,j = 0 j = 1, . , k + 1 Done. qi+1,j = qi,j (qi,j 1 pi+1) ∨ − ∧ q q n,k ∧ ¬ n,k+1 Example 2: HC to SAT 20 A Big Formula 21 Here is another translation, from Hamiltonian Cycle problem to Satisfiability. The Idea: the Hamiltonian path we are looking for touches node x at time t iff σ(pt,x) = 1 for a satisfying truth assignment σ. Problem: Hamiltonian Cycle So we need to construct a (large) Boolean formula ΦG that enforces the Instance: A ugraph G. following: Question: Does G have a Hamiltonian cycle? σ = Φ σ codes a Hamiltonian cycle in G | G ⇐⇒ Again, it is critical to interpret the Boolean variables the right way. Then ΦG is satisfiable iff G has a Hamiltonian cycle and we are done. As always, assume G looks like [n],E . We introduce n(n + 1) Boolean variables h i Of course, there is the constraint that ΦG needs to be constructible from G in polynomial time. pt,x 0 t n, 1 x n. ≤ ≤ ≤ ≤ Otherwise we could use Φ = or Φ = ;-) G ⊥ G > Think of t as time, and of x as location. Building ΦG 22 How Bad Can It Be? 23 ΦG is a conjunction with 4 parts as follows: 2 CNTr,1(x1, . , xr) is easily seen to be size Θ(r ).