In this section, we’ll address the question of how to compute the number of quasi- models of an inconsistent set. We can represent all possible quasi-models ofΓ using the following scheme:
F = _ A∈M(Γ) ^ C∈A C = (C11∧. . .∧C1r)∨. . .∨(C|1M(Γ)|∧. . .∧C|sM(Γ|) (5.11) where each Cxy is a reduced clause and|M(Γ)| is the number of maximal consistent subsets ofΓ. It is easy to see that the number of assignments verifyingFis precisely |U(Γ)| since an assignmentv is model of F iff it is a quasi-model ofΓ. Thus we can compute the number of quasi-models forΓ by counting the number of assignments verifyingF. To do this however we need to observe the following:
Proposition 5.5.1
1. IfΓis a set of clauses innvariables, then any maximal consistent subset ofΓhas exactlynvariables.
2. There are exactlyndistinct variables in each disjunct ofF.
3. The number of models forFis exactly the sum of the number of models for each disjunct ofF.
Proof:
(1) Since each A ∈ M(Γ) is a subset ofΓ, the number of variables occurring in any
A ∈M(Γ)cannot be greater thenn. Suppose to the contrary that someA ∈M(Γ)has less thannvariables. Letlibe a literal whose variable does not occur inAbut occurs in Γ. Then eitherli ∈ Γ or li occurs as a disjunct of a clause C ∈ Γ. In both cases, we can find an assignment that satisfiesA ∪{li}andA ∪{C}, but this contradicts the maximal consistency ofA.
(2) Since each disjunct of F is a conjunction of all formulae of a maximal consistent subset ofΓ, it follows from (1) that there must bendistinct variables occurring in each disjunct ofF.
(3) This follows from the fact that the disjuncts ofFare pairwise inconsistent and that each disjunct ofFis consistent.
From (3) of the above proposition, it suffices to calculate the number of models for each disjunct ofFand then sum them. Now consider thek-th disjunct ofF. Suppose it is of the form,
Dk =Ck1 ∧. . .∧Ckm
We can calculate the number of assignments which verifyDkby counting the number of assignments which verify¬Dk. From (2) of the above proposition, there must ben variables inDk(respectively¬Dk). So there must be2ndistinct assignments overDk (respectively¬Dk). Where|Cki|is the number of distinct variables in thei-th clause of Dk, the number distinct assignments which verify¬Cki is then given by the equation
|{v|v|=¬Cki}|=2n−|Cki| (5.12)
the Inclusion-Exclusion formula ([40; 121]): | m [ h=1 Sh| = X 1≤h≤m |Sh| − X 1≤h<i≤m |Sh∩Si| + X 1≤h<i<j≤m |Sh∩Si∩Sj| −· · · +(−1)m|S1∩. . .∩Sm| (5.13)
So on the basis of (5.13), the total number of assignments which verify¬Dkis |{v|v|=¬Dk}| = X 1≤i≤m |{v|v|=¬Cki}| − X 1≤i<j≤m |{v|v|=¬Cki ∧ ¬Ckj}| +· · · +(−1)m|{v|v|=¬Ck1∧. . .∧ ¬Ckm}| (5.14)
So the number of assignments which verifyDkis |{v|v|=Dk}| = 2n−|{v|v|=¬Dk}| = 2n− X 1≤i≤m |{v|v|=¬Cki}| − X 1≤i<j≤m |{v|v|=¬Cki ∧ ¬Ckj}| +· · · +(−1)m|{v|v|=¬Ck1∧. . .∧ ¬Ckm}| (5.15)
The number of assignments which verifyFis simply the sum of assignments which verify some disjunct ofF,
|{v|v|=F}| = 2n−|{v|v|=¬D1}| +· · ·+ 2n−|{v|v|=¬D|M(Γ)|}| = |M(Γ)|·2n− X 1≤i≤|M(Γ)| |{v|v|=¬Di}| (5.16)
We note that in equation (5.14), ifCki andCkj are clauses which contain complemen- tary literalspand¬p, then¬Cki∧¬Ckj is unsatisfiable and thus|{v|v|=¬Cki∧¬Ckj}|=0. Moreover any conjunctive extension of¬Cki∧¬Ckj would clearly also be unsatisfiable. Thus one or more terms of theRHS of (5.14) may turn out to be zero. On the other hand ifCk1. . . Ckmare pairwise free from complementary literals, then¬Ck1∧. . .∧¬Ckm
is clearly satisfiable. As usual if we represent a clauseCas a set of literals, the number of models for¬Ck1 ∧. . .∧ ¬Ckmcan be given by
|{v|v|=(¬Ck1 ∧. . .∧ ¬Ckm)}| = 2n−(|Ck1∪...∪C k
m|) (5.17)
These observations provide the basis of an algorithm developed by Lozinskii in [121] for computing the number of models of aCNFformula.
Algorithm 5.5.1Lozinskii’s algorithm Require: inputCNF(E) Ensure: outputµCNF(E) =|{v|v|=CNF(E)}| 1: s:=1; 2: G1 :={{C}|C∈CNF(E)}; 3: t1:= P {Ci∈G1}2 n−|Ci|; 4: acc:=t1; 5: whileGs6=∅do 6: s:=s+1; 7: Gs:=∅; 8: ts:=0; 9: for allgs−1 ∈Gs−1do
10: for allC∈CNF(E)andC6∈gs−1do 11: gs:=gs−1∪{C};
12: ifgsis pairwise free from complementary literalsthen 13: Gs:=Gs∪{gs}; 14: ts:=ts+2n−|∪gs|; 15: end if 16: end for 17: acc:=acc+ (−1)s−1ts; 18: end for 19: end while 20: µCNF(E) :=2n−acc
The basic idea of algorithm (5.5.1) is to incrementally sum the terms of equa- tion (5.14) from left to right. At the end of line (4), algorithm (5.5.1) computes the first term of equation (5.14), giving the value for P1≤i≤m|{v| v |= ¬Cki}|. The outer loop at line (5) is then executed (at mostmtimes). Each run of the loop adds the value of the next term of the equation. The first execution of the outer loop computes the value of the second termP1≤i<j≤m|{v|v|=¬Cki∧¬Ckj}|. If this value is non-zero, then accis updated to provide the sum of the first two terms of (5.14). The loop is executed repeatedly until either control reaches the last term of (5.14) or when every possible way to extend every gs−1 at line (11) results in complementary literals appearing in
some pair of clauses in the extension. At the first inner loop at line (9),Gs−1 is the set of all subsets ofCNF(E)that are of size(s−1)i.e. eachgs−1 ∈Gs−1 contains exactly s−1clauses ofCNF(E). At line (10) the second inner loop extendsgs−1with a single clause fromCNF(E)and the resulting extension is tested for complementary literals. If the extension is pairwise free from complementary literals, thenGsis extended to includegsandtsis recalculated to reflect the change. Once all possible ways to extend a givengs−1 have been examined, control exits from the inner most loop andaccis updated to reflect the new value. Control then returns to the top of the loop at line (9) and selects another member ofGs−1and continues the process of the inner-most loop. For a set of clausesΓwith a known number of maximal consistent subsetsk, count- ing quasi-models ofΓ can be done by calling Lozinskii’s algorithmktimes. But other propositional model counting algorithms can also be deployed to achieve the task. Indeed, experimental and theoretical results show that Lozinskii’s algorithm is super- seded by the Counting Davis-Putnum algorithm (CDP) of Birnbaum and Lozinskii [40] and by the Decomposing Davis-Putnum algorithm (DDP) of Bayardo and Pe- houshek [18]. But we should point out that the general problem of counting proposi- tional models (#SAT) is #P-complete. So according to the present state-of-the-art, the problem is computationally intractable in the worst case. Counting quasi-models is no easier.