Reverse Counting Algorithm To Solve 3sat
Reverse Counting Algorithm To Solve 3sat
VINAY CHATURVEDI
The 3SAT problem is a well known problem whose ‘efficient’ solution has not yet been obtained.
The author here tries to present a new and interesting approach to finding the solution to any 3SAT
problem along with the number of satisfiable instances of the Boolean equation represented by the
problem using a recursive algorithm. The approach is based on 'counting' the satisfiable instances
for each additional clause starting from the 1st clause of the 3SAT equation.
Algorithm:
The algorithm takes into account the fact that each additional clause introduced in the equation
changes the satisfiable instances count by a number and if that number is 0 at any point of time,
then, the equation becomes UNSAT, otherwise the algorithm just counts the total number of
satisfiable instances as below:
2) Make a table containing truth values for each clause(7 rows only per clauses as 1 row will be the
truth row nullifying the equation).
3) Remove all the truth values from this list which relate to similar clauses' nullifying truth row. For
example if we have (1 2 3) as 1 clause then its truth values will be:
123
1 2 -3
1 -2 3
-1 2 3
-1 2 -3
-1 -2 3
1 -2 -3
and suppose then we have another clause as (-1 2 3) then its truth values will be:
123
1 2 -3
1 -2 3
-1 -2 -3
-1 2 -3
-1 -2 3
-1 2 3
But, in essence the 2 clauses have 3 variables in common and thus we can remove the negating
value of 2nd clause from the 1st clause's truth rows to simplify the algorithm. After removing the
particular row, we can delete the 2nd clause also. So, we remove (1 -2 -3) from the 1st clause's truth
rows and update the same in the main truth rows for all clauses matrix:
The new truth values for 1st clause will be now:
123
1 2 -3
1 -2 3
-1 2 3
-1 2 -3
-1 -2 3
Do this for all clauses that is check from 1st clause to m-1th clause agaist each of (current clause+1)th
clause to mth clause.
3) Send the matrix of the truth values for all clauses thus obtained to function “getTotalSatCount”.
This function 'getTotalSatCount' is described as below and it is used to obtain the Satisfiability
Count for a specific truth values matrix. (be it for any number of clauses having any number of
rows in the truth values matrix against those clauses).
GetTotalSatCount Explained:
This function gets the total number of satisfiability count for the matrix sent as parameter to it. The
working is as below:
1) Set list containedset[] to be an empty list of integers, this list is to contain obtained variables
from the clauses. Set variable mn=0
2) Add the corresponding variables of the 1st clause to the list containedset[], and add the number of
truth values rows for 1st clause to mn.
3) From clause 2nd to clause m do: //m is the number of clauses in the equation
If none of the variables in current clause are in the set containedset[] do:
mn=mn*len(current clause's truth rows count)
Add all the 3 variables in the current clause to containedset[] list.
Continue For loop of point 3 without going to remaining code below
Else
count the number of new variables in the current clause that are not in the list containedset[]
if count==2
mn=mn*4
else if count==1
mn=mn*2
else if count==0
//do nothing
End If
Let the last clause of the current value matrix be x
Calculate the negation value matrix for clause x as below:
//that is calculate all the possibilities which are not there in the truth values for clause x
for each truth value possible in (000,001,010,100,101,011,110,111)
if (not ( current truth value is in truth value set for clause x) )
add current truth value to negation matrix
Initialize list remlist[] to contain truth value matrix of current function's truth value matrix
parameter from index 1st to (last -1). (That is leave out the last element)
Going as per the algorithm we take the value mn=7 and containedset={1,2,3} on 1st iteration. Next,
since 4 and 5 are new variables and truth values for current system should multiply by 2^2=4,
therefore, new value is 7*4=28. But, the values that should be negated from the system are those
values that make the equation false, which in this case, are the number of truth values of clause 1,
which, when intersected with negating value of clause 2, make the system false. In above case, the
negating value for 2nd clause is -3 -4 -5 and the number of truth rows of clause 1 which do interect
with this value is:
1 2 -3
-1 2 -3
1 -2 -3
that is 3 rows. So, we can easily deduce that the satisfiablity count for (1) is 28-3=25.
In this case 1st we have to tweak the main truth values matrix as (3 4 5) and (-3 4 5) have all 3
variables in common. Thus, final truth matrix is:
[
[
123
1 2 -3
1 -2 3
-1 2 3
-1 2 -3
-1 -2 3
1 -2 -3
]
[
345
3 4 -5
3 -4 5
-3 4 5
-3 4 -5
-3 -4 5
]
[
246
-2 4 6
2 -4 6
2 4 -6
-2 4 -6
2 -4 -6
-2 -4 6
]]
Now going as per the algorithm, mn=7 and containedset=[1,2,3] in 1st iteration and in the 2nd
iteration we add 4 and 5 to containedset list thus making it [1,2,3,4,5] and final satisfiability count
deduced as follows for (2nd iteration that is):
[
123 -3 -4 -5
1 2 -3
1 -2 3
-1 2 3 INTERSECTION
-1 2 -3
-1 -2 3 3 -4 -5
1 -2 -3
]
=
[
[
1 2 3 -4 -5
1 2 -3 -4 -5
1 -2 3 -4 -5
-1 2 3 -4 -5
-1 2 -3 -4 -5
-1 -2 3 -4 -5
1 -2 -3 -4 -5
]
That is, 7 rows. So, 28-7=21 satisfiability count is the required number for 2nd iteration.
Next, we need to find how many truth value rows out of this count above intersects with the
negation of the 4th clause => 2 || 4 || 6 which is (-2 -4 -6). But, 1st since this clause contains a new
variable => 6 thus we need to multiply the main truth count by 2. Thus, main number (mn) is 42.
So, we CHANGE the truth values of all clauses which lie before this clause to signify that they
ARE going to intersect with the negating value(s) of this clause and then send this to the
function getTotalSatCount() again! .......................... (3)
the next truth matrix to send to getTotalSatCount() function is deduced as below (Note: each row
should contain any of -2 -4 -6 or any other variable or its negation but not any of 2,4 and 6)
[
[
1 -2 3
-1 -2 3
1 -2 -3
]
[
3 -4 5
-3 -4 5
]
] .................................. (4)
(3 4 -5): [
1 -2 3
-1 -2 3] => 2
(-3 4 5):[
1 -2 -3]=> 1
(3 -4 -5):[
1 -2 3
-1 -2 3] => 2
-3 4 -5[
1 -2 -3]=> 1
(3 -4 -5):[
1 -2 -3]=> 1
Thus, we have to “SUBTRACT” this negating value from the satisfiability count as obtained in step
1. Thus, main number(mn=12-9=3). Thus, we return 3 from getTotalSatCount() function for this
iteration. This, '3' is the negating value count for the 4th clause of equation (2) as found out by
executing step (3) and we have to subtract this from the number 42 to get the final number as 42-
3=39! This (39) is the exact satisfiability count for the equation (2)!
5) Make a copy of the remlist[] truth values matrix as remlist2 and initialize number variable to 0
4) For each negation row in negation[][] matrix do:
a) remlist=Copy of remlist2
b) Remove 'unwanted' rows from the remlist matrix against the current negating row as
discussed above
c) If any of the truth value column in matrix remlist has 0 rows while deleting above,
continue outer loop.
Else if none of the truth value column in remlist have 0 rows do
if remlist matrix size is 1 do
number = number + number of truth values in 1st column of remlist
else
number=number+getTotalSatCount(remlist)
end if
end if
end For
mn=mn-number //This is important as we need to subtract the total
//unsatisfiable count from satisfiable count mn
end for loop for point 3 ( ends here!)
End Of Algorithm
Electronic Supplements
The link for electronic supplements which includes the source code in python project for this paper
is shared herewith for curious eyes. Please note that the code is not commented properly because of
time limits for the author. For any concerns regarding this paper please contact the author via email.
Link:
https://www.dropbox.com/s/s6fr5qjjbdvhe0y/codePython.py?dl=0
Note: You may download 3 SAT benchmark problem cases from here:
http://www.cs.ubc.ca/~hoos/SATLIB/benchm.html