A Polynomial-Time Heuristic for Circuit-SAT
Total Page:16
File Type:pdf, Size:1020Kb
A polynomial-time heuristic for Circuit-SAT Francesco Capasso [email protected] Abstract. In this paper is presented an heuristic that, in polynomial time and space in the input dimension, determines if a circuit describes a tautology or a contradiction. If the circuit is neither a tautology nor a contradiction, then the heuristic finds an assignment to the circuit inputs such that the circuit is satis- fied. 1. Introduction Circuit - SAT: given a circuit C and x1, …, xn inputs find a value 0 or 1 for each input such that circuit’s output equals 1. Circuit-SAT is one of the main NP-complete problems [1], however most solvers proposed are based on the reduction from Circuit-SAT to SAT, which is another NP- complete problem. Many attempts have been made so far in order to efficiently solve SAT, but no satisfying solution has been found yet. The approach adopted to solve Circuit-SAT follows the ideas already outlined in “Solving SAT with Bilateral Computing” [2] and consists in a reverse circuit execu- tion. Beginning from the output, that has a value 1 or 0, we go back through the cir- cuit gates up to its inputs. In so doing we get those input values such that the output equals the value fixed in the beginning. The present heuristic finds, in polynomial time and space in the input dimension, an assignment, if exists, to the inputs of a circuit C such that the output equals 1. In what follows is introduced a list of logic gates features (2) and two data struc- tures (3). Subsequently is presented the heuristic (4) and its proof of correctness (5) for some particular circuit classes. Then is introduced a recursive function (6) to up- date data structures, after that is given the correctness of heuristic for each circuit class (7) and then is calculated its computational complexity (8). 2 Francesco Capasso 2. Properties of logic gates Given a circuit C we assign a label xi to each input (0≤i≤n), a label Gj to each logic gate and a label yj to each logic gate output (0≤j≤m). In this way the circuit in figure 1 can be represented by formula 1. Figure 1. Sample circuit. (y1 = x1 ∧ x4 ) ∧ (y2 = ¬x4 ) ∧ (y3 = ¬x5 ) ∧ (y4 = y1 ∨ x2 ) ∧ (y5 = ¬x2 ) ∧ ∧ (y6 = x3 ∧ y2 ) ∧ (y7 = y5 ∨ y6 ) ∧ (y8 = y4 ∧ y7 ) ∧ (1) ∧ (y9 = y7 ∧ y3 ) ∧ (y10 = y8 ∧ y9 ) A polynomial-time heuristic for Circuit-SAT 3 We notice that each yj is associated to the output of a gate Gj whose truth table is known (table 1). AND OR NOT x y out x y out x out 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 1 1 1 Table 1. Truth table for AND, OR and NOT gates. Definition With the term degree of freedom we define the maximum number of possible com- binations of values that can be assigned to a logic gate according to the values given to its inputs and output. Classification of the degrees of freedom: • Degree 4: o AND and OR gate without any specific value mapped on inputs or output; • Degree 3: o AND gate with output 0; OR gate with output 1; 0 1 0 0 1 1 0 1 1 0 0 1 0 1 • Degree 2: o AND gate with output 0 and an input 0; AND gate with an input 0; 0 0 0/1 4 Francesco Capasso o OR gate with output 1 and an input 1; OR gate with an input 1; 1 1 0/1 • Degree 1: o AND gate with output 0 and input 1; AND gate with output 1; 1 1 0 1 0 1 o OR gate with output 1 and an input 0; OR gate with output 0; 0 0 1 0 1 0 o NOT gate with output 0 or 1, or input 0 or 1; 0 1 1 0 • Degree 0 (contradiction): o AND gate with output 1 and an input 0; 0 1 ? o OR gate with output 0 and input 1; 1 0 ? A polynomial-time heuristic for Circuit-SAT 5 o NOT gate with output and input both 0 or 1; 1 1 0 0 3. Data structures We represent a circuit C using following data structures: 1. a circuit truth table (CTT) with n+m columns (labelled by xi and yj): for each gate we report the corresponding truth table (setting to “null” the fields not assigned to 0 or 1); to each value we assign the label of the gate it belongs. 2. a degree table (DT) with m columns (labelled by Gj): for each gate we report the index of circuit’s truth table rows in which are defined truth value for the gate itself. Figure 2. Sample circuit. The circuit featured in figure 2 can be represented by the following formula: (y1 = x1 ∨ x2 ) ∧ (y2 = ¬x3 ) ∧ (y3 = y1 ∧ y2 ) (2) 6 Francesco Capasso X1 X2 X3 Y1 Y2 Y3 1 0/G1 0/G1 0/G1 2 0/G1 1/G1 1/G1 3 1/G1 0/G1 1/G1 4 1/G1 1/G1 1/G1 5 0/G2 1/G2 6 1/G2 0/G2 7 0/G3 0/G3 0/G3 8 0/G3 1/G3 0/G3 9 1/G3 0/G3 0/G3 10 1/G3 1/G3 1/G3 Table 2. Circuit truth table of circuit in figure 2. G1 G2 G3 1 5 7 2 6 8 3 9 4 10 Table 3. Degree table of circuit in figure 2. We observe that in circuit truth table the maximum number of rows we introduce for each gate is 4, consequently the table has in the worst case dimension (n+m)·(4m) that is O(nm+m²). Similarly we observe that in degree table the maximum number of rows introduced is 4 and the resulting dimension is therefore 4·m that is O(m). A polynomial-time heuristic for Circuit-SAT 7 4. Heuristic Given 0≤j≤m and supposing that each Gj is correlated with a yj: 1. assign a value to the output, ym=1; 2. delete from the circuit truth table all rows in which ym= 0; delete from degree table the values related to the index of previous deleted rows in circuit truth table; 3. until unassigned xi exist: 3.1. assign missing value to the inputs or output of all gates with degree of freedom 1; update circuit truth table and degree table (as shown in step 2); 3.2. if there are no more gates with degree of freedom 1, assign the value 0 or 1 to an input of a gate with degree of freedom 2 or 3; then update the circuit truth table and degree table (as shown in step 3.2); Applying the heuristic to the circuit showed in figure 2 we obtain: • [step 1]: set y3=1; • [step 2]: − delete from CTT all rows where y3 = 0 (rows 7, 8 and 9); − delete from DT, field G3, the values 7, 8 and 9; • [step 3.1]: − degree(G1)=4; degree(G2)=2; degree(G3)=1 y2=1 and y1= 1 (row 10); − delete from CTT all rows where y1 = 0 (row 1) ed y2 = 0 (row 6); − delete from DT, field G1 value 1, and in field G2 value 6; − degree(G1)=3, degree(G2)=1 x3 = 0 (row 5); • [step 3.2]: − degree(G1)=3; − determine a value for one of the inputs in G1, for instance x1 = 1; − delete from CTT all rows where x1 = 0 (row 2); − delete from DT, field G1, the value 2; − degree(G1)=2; 8 Francesco Capasso − set a value for x2, for instance x2 = 0; − delete from CTT all rows where x2=1 (row 4); − delete from DT, field G1, the value 4; The solution is given by the remaining rows in the circuit truth table (3, 5 e 10). These rows contain the assignment sought for x1, x2 and x3. 5. Correctness The correctness of steps 1 and 2 is obvious. To demonstrate the correctness of steps 3.1 and 3.2 we observe circuit in figure 3. This circuit describes neither a con- tradiction nor a tautology therefore exists an assignment to its inputs that satisfy the circuit. In the first case (a) applying step 3.1 and then 3.2 we obtain a solution, while in the second case applying step 3.2 before step 3.1 we obtain a contradiction. In other words applying step 3.1 we strongly bind the inputs and output assignment. (a) (b) Figure 3. Solution (a); Contradiction (b). The execution of step 3.1 brings to 3 different configurations: • a chain of consistent assignments for every logic gate and input (for instance, that is the case of a circuit with AND gates only); • a chain of consistent assignments that ends with an inconsistent assignment (that is the case of a circuit which represents a contradiction, figure 4); A polynomial-time heuristic for Circuit-SAT 9 • a chain of consistent assignments for some logic gates and inputs with degree of freedom 1, where the other gates have degree of freedom 2 or 3 (figure 5); Figure 4. Circuit that represent a contradiction. In the first case the heuristic ends with a solution, whereas in the second case it tells us that a solution does not exist. The third case is more articulated and introduces us to the correctness’s proof of step 3.2.