CS 512, Spring 2017: Take-Home End-of-Term Examination Out: Tuesday, 9 May 2017, 12:00 noon Due: Wednesday, 10 May 2017, by 11:59 am Turn in your solutions electronically, as a single PDF file, by placing it in the subfolder End-of-Term Exam of the Dropbox folder CS512-Assignments-2017. The solution scribe and grader for the End-of-Term Exam is: Assaf Kfoury (kfoury@bu.edu). The parts shaded in light blue are the questions you have to solve. Problem 1 In this problem, every WFF ϕ is a propositional WFF in CNF: ϕ C 1 C n where n 1 and every clause C i is a disjunction of finitely many literals. All literals are propositional variables or negated propositional variables in the set X {x 1,..., x p } for some p 1. We assume that every clause C i contains at least one literal. Relative to a propositional WFF ϕ as defined above, two optimization versions of the SAT problem are: 1 MaxSAT: Determine a truth assignment σ that maximizes the size of a subset C {C 1,..., C n } such that σ simultaneously satisfies C and falsifies {C 1,..., C n } C. MinSAT: Determine a truth assignment σ that minimizes the size of a subset C {C 1,..., C n } such that σ simultaneously satisfies C and falsifies {C 1,..., C n } C. These two problems are often restricted by the size k 1 of the clauses in ϕ: The restrictions k-maxsat and k-minsat result from requiring that each clause C i has at most k literals. Example. The following α is a propositional WFF in CNF, over the variables {x 1, x 2, x 3 }, with 5 clauses: α ( x 1 ) ( x }{{} 1 x 2 ) ( x }{{} 2 ) (x }{{} 3 ) (x }{{} 1 ) }{{} C 1 C 2 C 3 C 4 Because the clauses in α have each at most 2 literals, α can be an input instance for 2-MaxSAT and 2-MinSAT. Below is a list of all possible solutions for the two problems: Only one possible solution for 2-MaxSAT: false if x = x 1, σ 1 (x) false if x = x 2, true if x = x 3, which simultaneously satisfies the clauses {C 1, C 2, C 3, C 4 } and falsifies {C 5 }. It is not possible to simultaneously satisfy all of the 5 clauses. 1 We give here the simplest formulations of these two problems. In the literature, you will find formulations that are more involved, which qualify these problems as partial and/or weighted. C 5 1
Three possible solutions for 2-MinSAT: true if x = x 1, σ 2,1 (x) false if x = x 2, false if x = x 3, false if x = x 1, σ 2,2 (x) true if x = x 2, false if x = x 3. true if x = x 1, σ 2,3 (x) true if x = x 2, false if x = x 3. σ 2,1 simultaneously satisfies {C 3, C 5 } and falsifies {C 1, C 2, C 4 }; σ 2,2 simultaneously satisfies {C 1, C 2 } and falsifies {C 3, C 4, C 5 }; and σ 2,3 simultaneously satisfies {C 2, C 5 } and falsifies {C 1, C 3, C 4 }. There is no truth assignment σ which satisfies less than two clauses in {C 1, C 2, C 3, C 4, C 5 } and falsifies the remaining clauses. For another example, try on your own α C 1 C 2 C 3 C 4 C 5 where C 5 = x 1 (i.e., C 5 is the same as C 1 ). For α, you should find that it is possible to simultaneously satisfy all the clauses in {C 1, C 2, C 3, C 4, C 5 } and falsify none, for a solution of 2-MaxSAT; and you should find that it is possible to simultaneously satisfy exactly one clause in {C 1, C 2, C 3, C 4, C 5 } and falsify the remaining four, for a solution of 2-MinSAT In all parts below you can assume that, together with a propositional WFF ϕ, the input includes two numbers: n (the number of clauses in ϕ) and p (the number of variables in ϕ). Keep in mind that SAT is a decision problem, whereas MaxSAT and MinSAT are optimization problems. In parts (a) and (b), the requested algorithms must be efficient in the sense that they produce an optimal solution by scanning an input ϕ only once (from left to right). (a) Define precisely (in plain English) the steps of an efficient algorithm for 1-MaxSAT. Hint: Compare the number of occurrencs of the literal x i and the number of occurrences of the literal x i in ϕ. (b) Define precisely (in plain English) the steps of an efficient algorithm for 1-MinSAT. Hint: Do part (a) before part (b). (c) Suppose you are given an efficient algorithm A MaxSAT for the MaxSAT problem. Define precisely (in plain English) the steps of an efficient algorithm for SAT that uses A MaxSAT. 2 For part (d) we need a few preliminary notions. Every truth assignment σ : X {true, false} induces a two-block partition of the clauses {C 1,..., C n } of a propositional WFF ϕ C 1 C n in CNF: the block of true clauses w.r.t. σ, which is defined by block(ϕ, σ, true) { C i σ(c i ) = true }, the block of false clauses w.r.t. σ, which is defined by block(ϕ, σ, false) { C j σ(c j ) = false }. 2 If you took a course on algorithms or computational complexity, part (c) asserts that: SAT is reducible to MaxSAT. 2
We write block(ϕ, σ, true) and block(ϕ, σ, false) to denote the number of clauses in block(ϕ, σ, true) and block(ϕ, σ, false), respectively. The two-block partition of {C 1,..., C n } w.r.t. σ is defined by: partition(ϕ, σ) ( block(ϕ, σ, true), block(ϕ, σ, false) ) and its index is a pair of natural numbers defined by: ( index partition(ϕ, σ) ) ( ) block(ϕ, σ, true), block(ϕ, σ, false) We allow one of the two blocks in partition(ϕ, σ) to be the empty set. Given two pairs of natural numbers (a 1, b 1 ) and (a 2, b 2 ), we write (a 1, b 1 ) (a 2, b 2 ) iff: a 1 < a 2 or (a 1 = a 2 and b 1 b 2 ) which is the usual lexicographic ordering of pairs of numbers. Below we define an algorithm call it A 2-MinSAT to solve 2-MinSAT when the input ϕ C 1 C n satisfies three restrictions: (i) Every variable in X {x 1,..., x p } appears in ϕ. (ii) There are no pure literals in ϕ, i.e., for every variable x j X, it must be that both the literal x j and the literal x j appear in ϕ. (iii) If a clause C i is a disjunction of two literals, say C i (l i l i ), then there is no x j X such that {l i, l i } = {x j, x j }. In the example above, α satisfies (i) and (iii) but not (ii), because variable x 3 appears as a pure literal in α. Algorithm A 2-MinSAT is defined as follows: A 2-MinSAT 1. input: ϕ C 1 C n over variables X {x 1,..., x p } satisfying {(i), (ii), (iii)}. 2. Enumerate all the truth assignments σ : X {true, false} in some fixed order. There are 2 p such assignments, which we denote σ 1,..., σ 2 p. 3. Compute (q, r) := min { index ( partition(ϕ, σ i ) ) 1 i 2 p }. 4. σ := the first assignment σ i in the list σ 1,..., σ 2 p such that index ( partition(ϕ, σ i ) ) = (q, r). 5. output: σ. (d) Assume that A 2-MinSAT is correct (you are not asked to prove its correctness, though it is useful that you understand why A 2-MinSAT is correct before you answer this question). (e) 1. If the input ϕ does not satisfy (ii) or (iii) or both, does A 2-MinSAT still return a correct output? If yes, give a reason. If no, give a counter-example. 2. Propose adjustments in A 2-MinSAT so that the resulting algorithm A 2-MinSAT is more efficient. Hint: Your proposed adjustments need not be more than two or three new instructions in A 2-MinSAT. 3 Identify two real-world applications of formal modeling, one for MaxSAT and one for MinSAT. Hint: You can identify your own real-world applications, if you want, but it is much easier to search the Web and give a good answer for part (e) in at most 3-5 lines. You need to give the URL of an appropriate website and/or a reference to an appropriate article for each of your two applications. 3 As now written, A 2-MinSAT runs in time exponential in the size of the input ϕ in the worst case. 2-MinSAT is known to be an NP-hard problem. Hence, there is not much hope in reducing this time complexity of A 2-MinSAT down to polynomial time. Nevertheless, there are adjustments that will make it more efficient. 3
Problem 2 This is a problem about first-order modeling. Let ϕ be an arbitrary first-order sentence over some signature Σ. If M is a Σ-structure with a single domain/universe M, then we write M to denote the cardinality of M. The spectrum(ϕ) is the set of cardinalities of finite Σ-structures satisfying ϕ: spectrum(ϕ) { n N n = M for some Σ-structure M s.t. M = ϕ } Important note: spectrum(ϕ) excludes the cardinalities of infinite Σ-structures satisfying ϕ. (a) (b) Write a first-order sentence ϕ even such that spectrum(ϕ even ) is the set of all even positive integers. Hint: You can choose the signature of ϕ even in any way that will simplify your task. Write a first-order sentence ϕ odd such that spectrum(ϕ odd ) is the set of all odd positive integers. Hint: You will find it easier to start with part (a) before attempting this part (b). In the rest of this problem, we assume the signature Σ contains only binary relation symbols. You can use. an additional binary relation symbol =, which is implicitly in Σ and always interpreted as equality. If Σ contains only one binary relation symbol R, then Σ is the signature of structures that are graphs G = (V, E). In such a graph G, V is the domain (its vertices) and E V V is the binary predicate describing its edges. (c) Let ϕ be a first-order sentence over signature Σ = {R}, the signature of graphs. Is there an algorithm to decide whether an arbitrary n N is in spectrum(ϕ)? If yes, define precisely (in plain English) the steps of the requested algorithm. If no, define precisely (in plain English) a counter-example showing that there cannot be any such algorithm. (d) Let ϕ 1 and ϕ 2 be two first-order sentences over signature Σ = {R}, and let S 1 = spectrum(ϕ 1 ) and S 2 = spectrum(ϕ 2 ). If A, B N, we define A + B as the set { m + n m A and n B }. 1. Show there is a first-order sentence ψ 1 such that S 1 S 2 = spectrum(ψ 1 ). 2. Show there is a first-order sentence ψ 2 such that S 1 S 2 = spectrum(ψ 2 ). 3. Show there is a first-order sentence ψ 3 such that S 1 + S 2 = spectrum(ψ 3 ). Hint: The signature of the sentences ψ i may contain other binary relation symbols besides R (and, implicitly,. =). If G = (V, E) is an undirected graph, then (a, b) E iff (b, a) E for all distinct vertices a and b, and, by convention, (a, a) E (there are no self-loops). (e) Look up the definition of bipartite undirected graph from the Web (or any textbook on graphs). Write an infinite set Γ bipartite of first-order sentences such that, for every undirected graph G, it holds that G = Γ bipartite iff G is bipartite. Hint: G is bipartite iff every cycle in G (possibly with repeated vertices) has even length. 4
Problem 3 This problem is based on Handout 34 entitled, Program Schemes and First-Order Logic. Both the program P (on page 4 of Handout 34) and the corresponding program scheme S (on page 5) mention a precondition. In P, the precondition is x > 0 and y > 0 (not in the syntax of first-order logic, although precisely stated) which becomes, in S, the precondition R (x, c ) R (y, c ) (in the syntax of first-order logic). (a) What is missing from the specification of P and S are postconditions. An appropriate postcondition for program P is: n is the greatest common divisor of x and y. Write the corresponding postcondition for program scheme S over signature Σ = {R, lo, hi, f, c } with n, x, and y as free variables. The postcondition for S is a first-order WFF, possibly involving quantifiers, which is interpreted in the Σ-structure (N, <, min, max, mod, 0) with <, min, max, mod, and 0, being the interpretations of R, lo, hi, f, and c, respectively. Although. = is not explicitly mentioned in Σ, you can include it as a binary predicate symbol (in infix position) always interpreted as equality. (b) Do the exercise on page 18 of Handout 34. Hint: Read and understand pages 12-18 in the handout before attempting this exercise. The following is a variation on the definition of what it means for a set Φ of first-order WFF s to enforce totality of a program scheme (page 15 in Handout 34). Let S be a program scheme over the signature Σ and whose input variables are X = {x 1,..., x m }. Let C be a class of Σ-structures. Let Φ {ϕ 1, ϕ 2,...} be a set (possibly infinite) of first-order WFF s over signature Σ with FV(ϕ i ) {x 1,..., x m } for every i 1. We say that Φ enforces quasi-totality of program scheme S in the class C iff: there is finite set of k 1 execution paths {π 1,..., π k } in S such that, for every M C and every m-tuple a (a 1,..., a m ) from the domains of M, if (M, a) = Φ and S M ( a) converges, then execution of S M ( a) follows a path in {π 1,..., π k }. Intuitively, even though Paths(S) is an infinite set (if S is not trivial and therefore contains loops), all inputs (M, a) satisfying the conditions expressed by Φ will use only a finite number k of execution paths. What it means for a program scheme S to unwind in the class C is defined in Handout 34 (page 19). (c) Let S and Φ as in the preceding paragraph, and let C { M M = Φ }. Prove the assertion: Φ enforces quasi-totality of S in the class C iff S unwinds in the class C. Hint 1: This assertion is a double implication, which is therefore a stronger assertion than the single implication in Theorem 3 in Handout 34. Hint 2: Please do not fudge! Skip this part if you do not see your way through clearly. You can earn enough points from all other parts in this exam to do well. 5