Representations for Automated Reasoning Ruben Martins http://www.cs.cmu.edu/~mheule/15816-f19/ Automated Reasoning and Satisfiability, September 10, 2019 1/33
AtLeastOne Given a set of Boolean variables x 1 , . . . , x n , how to encode AtLeastOne ( x 1 , . . . , x n ) into SAT? Hint: This is easy... 2/33
AtLeastOne Given a set of Boolean variables x 1 , . . . , x n , how to encode AtLeastOne ( x 1 , . . . , x n ) into SAT? Hint: This is easy... ( x 1 ∨ x 2 ∨ · · · ∨ x n ) 2/33
Exclusive OR (1) Given a set of Boolean variables x 1 , . . . , x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? x y XOR ( x , y ) 0 0 0 0 1 1 1 0 1 1 1 0 3/33
Exclusive OR (1) Given a set of Boolean variables x 1 , . . . , x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? x y XOR ( x , y ) 0 0 0 0 1 1 1 0 1 1 1 0 XOR ( x 1 , . . . , x n ) is true when an odd number of x i is assigned to true . 3/33
Exclusive OR (2) Given a set of Boolean variables x 1 , . . . , x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? The direct encoding requires 2 n − 1 clauses of length n : � (¯ x 1 ∨ ¯ x 2 ∨ · · · ∨ ¯ x n ) even # ¬ 4/33
Exclusive OR (2) Given a set of Boolean variables x 1 , . . . , x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? The direct encoding requires 2 n − 1 clauses of length n : � (¯ x 1 ∨ ¯ x 2 ∨ · · · ∨ ¯ x n ) even # ¬ XOR ( x , y , z ) =( x ∨ y ∨ z ) ∧ (¯ x ∨ ¯ y ∨ z ) ∧ (¯ x ∨ y ∨ ¯ z ) ∧ ( x ∨ ¯ y ∨ ¯ z ) 4/33
Exclusive OR (2) Given a set of Boolean variables x 1 , . . . , x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? The direct encoding requires 2 n − 1 clauses of length n : � (¯ x 1 ∨ ¯ x 2 ∨ · · · ∨ ¯ x n ) even # ¬ XOR ( x , y , z ) =( x ∨ y ∨ z ) ∧ (¯ x ∨ ¯ y ∨ z ) ∧ (¯ x ∨ y ∨ ¯ z ) ∧ ( x ∨ ¯ y ∨ ¯ z ) Question: How many solutions does this formula have? 4/33
Exclusive OR (2) Given a set of Boolean variables x 1 , . . . , x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? The direct encoding requires 2 n − 1 clauses of length n : � (¯ x 1 ∨ ¯ x 2 ∨ · · · ∨ ¯ x n ) even # ¬ XOR ( x , y , z ) =( x ∨ y ∨ z ) ∧ (¯ x ∨ ¯ y ∨ z ) ∧ (¯ x ∨ y ∨ ¯ z ) ∧ ( x ∨ ¯ y ∨ ¯ z ) Question: How many solutions does this formula have? 4 4/33
Exclusive OR (2) Given a set of Boolean variables x 1 , . . . , x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? The direct encoding requires 2 n − 1 clauses of length n : � (¯ x 1 ∨ ¯ x 2 ∨ · · · ∨ ¯ x n ) even # ¬ Can we encode large XORs with less clauses? 4/33
Exclusive OR (2) Given a set of Boolean variables x 1 , . . . , x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? The direct encoding requires 2 n − 1 clauses of length n : � (¯ x 1 ∨ ¯ x 2 ∨ · · · ∨ ¯ x n ) even # ¬ Can we encode large XORs with less clauses? Make it compact: XOR ( x 1 , x 2 , y ) ∧ XOR (¯ y , x 3 , . . . , x n ) Tradeoff: increase the number of variables but decreases the number of clauses! 4/33
AtMostOne (1) Given a set of Boolean variables x 1 , . . . , x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT? 5/33
AtMostOne (1) Given a set of Boolean variables x 1 , . . . , x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT? The direct encoding requires n ( n − 1) / 2 binary clauses: � ( x i ∨ x j ) 1 ≤ i < j ≤ n 5/33
AtMostOne (1) Given a set of Boolean variables x 1 , . . . , x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT? The direct encoding requires n ( n − 1) / 2 binary clauses: � ( x i ∨ x j ) 1 ≤ i < j ≤ n Is it possible to use fewer clauses? 5/33
AtMostOne (2) Given a set of Boolean variables x 1 , . . . , x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT using a linear number of binary clauses? 6/33
AtMostOne (2) Given a set of Boolean variables x 1 , . . . , x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT using a linear number of binary clauses? By splitting the constraint using additional variables. Apply the direct encoding if n ≤ 4 otherwise replace AtMostOne ( x 1 , . . . , x n ) by AtMostOne ( x 1 , x 2 , x 3 , y ) ∧ AtMostOne ( y , x 4 , . . . , x n ) resulting in 3 n − 6 clauses and ( n − 3) / 2 new variables 6/33
AtMostOne (3) How to show that two encodings of AtMostOne ( x 1 , x 2 ) are equivalent? If we have a circuit representation of each encoding then we can use a miter circuit to show that for the same inputs, the output variables are equivalent: 7/33
AtMostOne (3) Are these two formulas that encode AtMostOne ( x 1 , x 2 ) equivalent? ϕ 1 (direct encoding) ϕ 2 (split encoding) ¯ x 1 ∨ ¯ ¯ x 1 ∨ ¯ x 2 y y ∨ ¯ x 2 Question: Is ϕ 1 equivalent to ϕ 2 ? Note: ϕ 1 ↔ ϕ 2 is valid if ¬ ϕ 1 ∧ ϕ 2 and ϕ 1 ∧ ¬ ϕ 2 are unsatisfiable. 7/33
AtMostOne (3) Are these two formulas that encode AtMostOne ( x 1 , x 2 ) equivalent? ϕ 1 (direct encoding) ϕ 2 (split encoding) ¯ x 1 ∨ ¯ x 2 ¯ x 1 ∨ ¯ y y ∨ ¯ x 2 Is ¬ ϕ 1 ∧ ϕ 2 unsatisfiable? Note: ¬ ϕ 1 ≡ x 1 ∧ x 2 7/33
AtMostOne (3) Are these two formulas that encode AtMostOne ( x 1 , x 2 ) equivalent? ϕ 1 (direct encoding) ϕ 2 (split encoding) ¯ x 1 ∨ ¯ x 2 ¯ x 1 ∨ ¯ y y ∨ ¯ x 2 Is ¬ ϕ 1 ∧ ϕ 2 unsatisfiable? yes! Note: ¬ ϕ 1 ≡ x 1 ∧ x 2 7/33
AtMostOne (3) Are these two formulas that encode AtMostOne ( x 1 , x 2 ) equivalent? ϕ 1 (direct encoding) ϕ 2 (split encoding) ¯ x 1 ∨ ¯ x 2 ¯ x 1 ∨ ¯ y y ∨ ¯ x 2 Is ϕ 1 ∧ ¬ ϕ 2 unsatisfiable? Note: ¬ ϕ 2 ≡ ( x 1 ∨ y ) ∧ ( x 1 ∨ x 2 ) ∧ ( ¬ y ∨ x 2 ) 7/33
AtMostOne (3) Are these two formulas that encode AtMostOne ( x 1 , x 2 ) equivalent? ϕ 1 (direct encoding) ϕ 2 (split encoding) ¯ x 1 ∨ ¯ x 2 ¯ x 1 ∨ ¯ y y ∨ ¯ x 2 Is ¬ ϕ 1 ∧ ϕ 2 unsatisfiable? no! Note: ¬ ϕ 2 ≡ ( x 1 ∨ y ) ∧ ( x 1 ∨ x 2 ) ∧ ( ¬ y ∨ x 2 ) 7/33
AtMostOne (3) Are these two formulas that encode AtMostOne ( x 1 , x 2 ) equivalent? ϕ 1 (direct encoding) ϕ 2 (split encoding) ¯ x 1 ∨ ¯ ¯ x 1 ∨ ¯ x 2 y y ∨ ¯ x 2 ϕ 1 and ϕ 2 are equisatisfiable: ◮ ϕ 1 is satisfiable iff ϕ 2 is satisfiable. Note: Equisatisfiability is weaker than equivalence but useful if all we want we want to do is determine satisfiability. 7/33
How to encode a problem into SAT? c famous problem (in CNF) p cnf 6 9 1 4 0 2 5 0 3 6 0 -1 -2 0 -1 -3 0 -2 -3 0 -4 -5 0 -4 -6 0 -5 -6 0 8/33
How to encode a problem into SAT? c pigeon hole problem p cnf 6 9 1 4 0 # pigeon[1]@hole[1] ∨ pigeon[1]@hole[2] 2 5 0 # pigeon[2]@hole[1] ∨ pigeon[2]@hole[2] 3 6 0 # pigeon[3]@hole[1] ∨ pigeon[3]@hole[2] -1 -2 0 # ¬ pigeon[1]@hole[1] ∨ ¬ pigeon[2]@hole[1] -1 -3 0 # ¬ pigeon[1]@hole[1] ∨ ¬ pigeon[3]@hole[1] -2 -3 0 # ¬ pigeon[2]@hole[1] ∨ ¬ pigeon[3]@hole[1] -4 -5 0 # ¬ pigeon[1]@hole[2] ∨ ¬ pigeon[2]@hole[2] -4 -6 0 # ¬ pigeon[1]@hole[2] ∨ ¬ pigeon[3]@hole[2] -5 -6 0 # ¬ pigeon[2]@hole[2] ∨ ¬ pigeon[3]@hole[2] 8/33
Tseitin Transformation (1) ◮ SAT solvers take as input a formula in CNF ◮ What is the complexity of transformation any formula ϕ in CNF? 9/33
Tseitin Transformation (1) ◮ SAT solvers take as input a formula in CNF ◮ What is the complexity of transformation any formula ϕ in CNF? In some cases, converting a formula to CNF can have an exponential explosion on the size of the formula. If we convert ( x 1 ∧ y 1 ) ∨ ( x 2 ∧ y 2 ) ∨ . . . ∨ ( x n ∧ y n ) using De Morgan’s laws and distributive law to CNF: ( x 1 ∨ x 2 ∨ . . . ∨ x n ) ∧ ( y 1 ∨ x 2 . . . ∨ x n ) ∧ . . . ∧ ( y 1 ∨ y 2 ∨ . . . ∨ y n ) ◮ How can we avoid the exponential blowup? In this case, the equivalent formula would have 2 n clauses! 9/33
Tseitin Transformation (1) ◮ SAT solvers take as input a formula in CNF ◮ What is the complexity of transformation any formula ϕ in CNF? ◮ Tseitin’s transformation converts a formula ϕ into an equisatisfiable CNF formula that is linear in the size of ϕ ! ◮ Key idea: introduce auxiliary variables to represent the output of subformulas, and constrain those variables using CNF clauses! 9/33
Tseitin Transformation (2) P → ( Q ∧ R ) 10/33
Tseitin Transformation (2) P → ( Q ∧ R ) 1. Introduce a fresh variable for every non-atomic subformula 10/33
Tseitin Transformation (2) P → ( Q ∧ R ) 1. Introduce a fresh variable for every non-atomic ↔ P → T 2 T 1 subformula 10/33
Tseitin Transformation (2) P → ( Q ∧ R ) 1. Introduce a fresh variable for every non-atomic ↔ P → T 2 T 1 subformula ↔ Q ∧ R T 2 10/33
Tseitin Transformation (2) P → ( Q ∧ R ) 1. Introduce a fresh variable for every non-atomic ↔ P → T 2 T 1 subformula ↔ Q ∧ R T 2 2. Convert each equivalence into CNF 10/33
Tseitin Transformation (2) P → ( Q ∧ R ) 1. Introduce a fresh variable for every non-atomic ↔ P → T 2 T 1 subformula ↔ Q ∧ R T 2 2. Convert each equivalence into ( T 1 ∨ P ) ∧ ( T 1 ∨ ¬ T 2 ) ∧ ( ¬ T 1 ∨ ¬ P ∨ T 2 ) CNF 10/33
Recommend
More recommend