Improved Algorithms for Weighted #2-SAT & #3-SAT
Improved Algorithms for Weighted #2-SAT & #3-SAT
Abstract
arXiv:2507.14504v1 [[Link]] 19 Jul 2025
The #2-SAT and #3-SAT problems involve counting the number of satisfying assignments (also
called models) for instances of 2-SAT and 3-SAT, respectively. In 2010, Zhou et al. proposed an
O∗ (1.1892m )-time algorithm for #2-SAT and an efficient approach for #3-SAT, where m denotes
the number of clauses. In this paper, we show that the weighted versions of #2-SAT and #3-SAT
can be solved in O∗ (1.1082m ) and O∗ (1.4423m ) time, respectively. These results directly apply
to the unweighted cases and achieve substantial improvements over the previous results. These ad-
vancements are enabled by the introduction of novel reduction rules, a refined analysis of branching
operations, and the application of path decompositions on the primal and dual graphs of the formula.
1 Introduction
The B OOLEAN S ATISFIABILITY problem (SAT), the first problem to be proven NP-complete [6], is
a cornerstone of computational complexity theory. Its counting variant, the P ROPOSITIONAL M ODEL
C OUNTING problem (#SAT), introduced and shown to be #P-complete by Valiant [30], holds compara-
ble significance.
Given a CNF formula, SAT seeks to determine whether the formula is satisfiable, while #SAT aims
to count the number of satisfying assignments (also known as models). Both SAT and #SAT, along with
their variants, are among the most influential problems in computational theory due to their broad ap-
plications in computer science, artificial intelligence, and numerous other domains, both theoretical and
practical. As such, these problems have garnered substantial attention and have been extensively stud-
ied across various fields, including computational complexity and algorithm design. For comprehensive
surveys, For comprehensive surveys, we refer to [3, 14].
This paper focuses on #SAT and its weighted extension, W EIGHTED M ODEL C OUNTING (WMC,
or weighted #SAT). In WMC, each literal (a variable or its negation) in the formula is assigned a weight.
The task is to compute the sum of the weights of all satisfying assignments, where the weight of an
assignment is the product of the weights of the true literals in the assignment. Notably, WMC reduces to
#SAT when all literals have identical weights. Efficient algorithms for (weighted) #SAT have a profound
impact on various application areas [19], such as probabilistic inference [27, 1, 29, 4], network reliability
estimation [11], and explainable AI [26]. This significance is highlighted by the annual Model Counting
Competition1 , which bridges theoretical advancements and practical implementations in model counting.
A fundamental question is: how fast (weighted) #SAT can be solved in the worst case? The naı̈ve
algorithm, which enumerates all assignments, runs in O∗ (2n ) time2 , where n is the number of variables
in the formula. Under the Strong Exponential Time Hypothesis (SETH) [21], SAT (and thus #SAT)
cannot be solved in O∗ ((2 − ϵ)n ) time for any constant ϵ > 0. Another key parameter, the number of
clauses m in the formula, has also been extensively studied. It is well-known that #SAT can be solved
in O∗ (2m ) time using the Inclusion-Exclusion principle [22, 25], which also applies to the weighted
* Corresponding Author
1
[Link]
2
The O∗ notation suppresses polynomial factors in the input size.
1
variant. However, no algorithm with a runtime of O∗ (cm ) for c < 2 was discovered. In 2016, Cygan
et al. [7] proved that such an algorithm does not exist unless SETH fails.
The barriers 2n and 2m can be broken for restricted versions of (weighted) #SAT. One notable exam-
ple is the (weighted) #k-SAT problem, where each clause contains at most k literals in the input formula.
There is a rich history of developing faster algorithms for #2-SAT and #3-SAT [9, 33, 8, 24, 31, 34].
The current fastest algorithms for weighted #2-SAT and #3-SAT achieve runtimes of O∗ (1.2377n ) [31]
and O∗ (1.6423n ) [24], respectively. For the parameter m, Zhou et al. introduced an O∗ (1.1740m )-time
algorithm for #2-SAT and suggested a simple approach for #3-SAT. However, the analysis of the #3-SAT
algorithm in [34] does not yield a valid runtime bound (more details can be found in Appendix A).
Our Contribution. We propose two novel algorithms, Alg2CNF and Alg3CNF, for weighted #2-SAT
and weighted #3-SAT, achieving runtime bounds of O∗ (1.1082m ) and O∗ (1.4423m ), respectively. The
algorithms and complexity bounds directly apply to the unweighted case, significantly improving upon
previous results. To this end, we bring new techniques for (weighted) #2-SAT and #3-SAT.
Our Approach. Most existing algorithms, including ours, are classical branch-and-search algorithms
(also called DPLL-style algorithms) that first apply reduction (preprocessing) rules and then recursively
solve the problem via branching (e.g., selecting a variable and assigning it values). Typically, variables
are processed in descending order of their degree, where the degree of a variable is the number of its
occurrences in the formula. However, such algorithms often perform poorly when encountering low-
degree variables. To address this, previous work has employed tailored branching strategies with intricate
analyses to mitigate this bottleneck.
Our approach departs from these complexities. Instead of elaborate branching, we apply path de-
compositions on the primal and dual graphs of the formula to efficiently handle low-degree cases. The
primal and dual graphs represent structural relationships between variables and clauses, and path decom-
positions allow us to transform these structures into a path-like form. Although our algorithms rely on
simple branching, we demonstrate through sophisticated analyses that this approach, combined with our
reduction rules, achieves substantial efficiency. These ideas may hold potential for broader applications
in the future.
Other Related Works. There is extensive research on fast algorithms for SAT and its related problems
parameterized by m. We list the current best results for some of these problems, achieved after a series
of improvements. Chu et al. [5] showed that SAT can be solved in O∗ (1.2226m ) time. Beigel and
Eppstein [2] introduced an O∗ (1.3645m )-time algorithm for 3-SAT. We also mention the M AXIMUM
S ATISFIABILITY problem (MaxSAT), an optimization version of SAT, where the objective is to satisfy
the maximum number of clauses in a given formula. Currently, MaxSAT and Max-2-SAT can be solved
in time O∗ (1.2886m ) [32] and O∗ (1.1159m ) [18], respectively.
2 Preliminaries
2.1 Notations
A Boolean variable (or simply variable) can be assigned value 1 (TRUE) or 0 (FALSE). A variable x
has two corresponding literals: the positive literal x and the negative literal x̄. We use x̄ to denote the
negation of literal x, and thus x̄ ¯ = x. Let V be a set of variables. A clause on V is a set of literals on
V . Note that a clause might be empty. A CNF formula (or simply formula) over V is a set of clauses on
V . We denote by var(F ) the variable set of F . For a literal ℓ, var(ℓ) denotes its corresponding variable.
For a clause C, var(C) denotes the set of variables such that either x ∈ C or x̄ ∈ C. We denote by n(F )
and m(F ) the number of variables and clauses in formula F , respectively.
An assignment for variable set V is a mapping σ : V → {0, 1}. Given an assignment σ, a clause is
satisfied by σ if at least one literal in it gets value 1 under σ. An assignment for var(F ) is called a model
of F if σ satisfies all clauses in F . We write σ |= F to indicate that σ is a model of F .
2
S
Definition 1 (Weighted Model Count). Let F be a formula, ltr(F ) := x∈var(F ) {x, x̄} be the set of
literals of variables in F , w : ltr(F ) → Z+ be a weight function that assigns a (positive integer) weight
value to each literal, and A(F ) be the set of all possible assignments to var(F ). The weighted model
count WMC(F, w) of formula F is defined as
X Y Y
WMC(F, w) := w(x) · w(ȳ) .
σ∈A(F ) x∈var(F ) y∈var(F )
σ|=F σ(x)=1 σ(y)=0
In the Weighted Model Counting problem (WMC), given a formula F and a weight function w, the
goal is to compute the weighted model count WMC(F, w) of formula F . We use weighted #2-SAT
and weighted #3-SAT to denote the restricted versions of WMC where the inputs are 2-CNF and 3-CNF
formulas, respectively (the definition of 2-CNF and 3-CNF can be found below).
A clause containing a single literal ℓ may be simply written as (ℓ). We use C1 C2 to denote the clause
obtained by concatenating clauses C1 and C2 . For a formula F , we denote F [ℓ = 1] as the resulting
formula obtained from F by removing all clauses containing literal ℓ and removing all literals ℓ̄ from all
clauses in F .
The degree of a variable x in formula F , denoted by deg(x), is the total number of occurrences of
literals x and x̄ in F . A d-variable (resp., d+ -variable) is a variable with degree exactly d (resp., at least
d). The degree of a formula F , denoted by deg(F ), is the maximum degree of all variables in F . The
length of a clause C is the number of literals in C. A clause is a k-clause (resp., k − -clause) if its length
is exactly k (resp., at most k). A formula F is called k-CNF formula if each clause in F has length at
most k.
We say a clause C contains a variable x if x ∈ var(C). Two variables x and y are adjacent (and
neighbors of each other) if they appear together in some clause. We denote by N (x, F ) (resp., Ni (x, F ))
the set of neighbors (resp., the set of i-degree neighbors) of variable x in formula F . When F is clear
from the context, we may simply write N (x) (resp., Ni (x)).
Definition 2 (Primal graphs). The primal graph G(F ) of a formula F is a graph where each vertex
corresponds to a variable in the formula. Two vertices x and y are adjacent if and only if x, y ∈ var(C)
for some clause C ∈ F .
Definition 3 (Dual graphs). The dual graph Gd (F ) of a formula F is the graph where each vertex
corresponds to a clause in the formula. Two vertices C1 and C2 are adjacent if and only if var(C1 ) ∩
var(C2 ) ̸= ∅ for C1 , C2 ∈ F .
We also use the concepts of path decompositions, which offer a way to decompose a graph into a
path structure.
The width of a path decomposition (X1 , . . . , Xr ) is defined as max1≤i≤r {|Xi |} − 1. The pathwidth
of a graph G, denoted by pw(G), is the minimum possible width of any path decomposition of G. The
primal pathwidth and dual pathwidth of a formula are the pathwidths of its primal graph and dual graph,
respectively.
The following is a known bound in terms of the pathwidth.
3
Theorem 1 ([17]). For any ϵ > 0, there exists an integer nϵ such that for every graph G with n > nϵ
vertices,
pw(G) ≤ n3 /6 + n4 /3 + n≥5 + ϵn,
where ni (i ∈ {3, 4}) is the number of vertices of degree i in G and n≥5 is the number of vertices of
degree at least 5. Moreover, a path decomposition of the corresponding width can be constructed in
polynomial time.
Samer and Szeider [28] introduced fast algorithms for #SAT parameterized by primal pathwidth and
dual pathwidth. With minor modifications, these algorithms can be adapted to solve the weighted version,
specifically WMC, without increasing the time complexity.
Theorem 2 ([28]). Given an instance (F, w) of WMC and a path decomposition P of G(F ), there is an
algorithm (denoted by AlgPrimalPw(F, w, P )) that solves WMC in time O∗ (2p ), where p is the width
of P .
Theorem 3 ([28]). Given an instance (F, w) of WMC and a path decomposition P of Gd (F ), there is
an algorithm (denoted by AlgDualPw(F, w, P )) that solves WMC in time O∗ (2p ), where p is the width
of P .
T (µ) ≤ T (µ − a1 ) + · · · + T (µ − al ),
or simply by a branching vector (a1 , . . . , al ). The branching Pfactor of the recurrence, denoted by
−a
τ (a1 , . . . , al ), is the largest root of the function f (x) = 1 − 1≤i≤l x . If the maximum branch-
i
ing factor for all branching operations in the algorithm is at most γ, then T (µ) = O(γ µ ). More details
about analyzing branching algorithms can be found in [16]. We say that one branching vector is not worse
than the other if its corresponding branching factor is not greater than that of the latter. The following
useful property about branching vectors can be obtained from Lemma 2.2 and Lemma 2.3 in [16].
Lemma 1. A branching vector (a1 , a2 ) is not worse than (p − q, q) (or (q, p − q)) if a1 + a2 ≥ p and
a1 , a2 ≥ q > 0.
3 Framework of Algorithms
An instance of WMC is denoted as I = (F, w). For the sake of describing recursive algorithms, we use
I = (F, w, W ) to denote an instance, where W is a positive integer and the solution to this instance is
W · WMC(F, w). Initially, it holds that W = 1, which corresponds to the original WMC.
Our algorithms for weighted #2-SAT and weighted #3-SAT adopt the same framework, which con-
tains three major phases. The first phase is to apply some reduction rules to simplify the instance. The
reduction rules we use in the algorithm will be introduced in the next subsection.
The second phase is to branch on some variable by assigning either 1 or 0 to it. This phase will create
branching vectors and exponentially increase the running time of the algorithm. Specifically, branching
on variable x in an algorithm Alg means doing the following:
• Wt ← Alg(F [x = 1], w, W );
• Wf ← Alg(F [x = 0], w, W );
4
• Return w(x) · Wt + w(x̄) · Wf .
In our algorithms, we may only branch on variables of (relatively) high degree. When all variables
have a low degree, the corresponding primal or dual graphs usually have a small pathwidth. In this
case, we will apply Theorem 1 to obtain a path decomposition with small width, and then invoke the
algorithms in Theorem 2 and Theorem 3 to solve the problem. This is the third phase of our algorithms.
Before introducing our algorithms for weighted #2-SAT and weighted #3-SAT, we first introduce our
reduction rules for general WMC. Since our reduction rules are applicable for general WMC, they can
also be applied to both weighted #2-SAT and weighted #3-SAT.
R-Rule 1 (Elimination of duplicated literals). If a clause C contains duplicated literals ℓ, remove all but
one ℓ in C.
R-Rule 2 (Elimination of tautology). If a clause C contains two complementary literals ℓ and ℓ̄, remove
clause C.
R-Rule 3 (Elimination of subsumptions). If there are two clauses C and D such that C ⊆ D, remove
clause D.
R-Rule 4 (Elimination of 1-clauses). If there is a 1-clause (ℓ), then W ← W · w(ℓ), and F ← F [ℓ = 1].
In the algorithms, we may also generate 0-variables that are unassigned yet. The following rule can
eliminate them.
R-Rule 6. If there are two clauses ℓa ℓb and ℓa ℓ¯b C in F , then remove literal ℓ¯b from clause ℓa ℓ¯b C.
R-Rule 7. If there are two clauses ℓa ℓb and ℓ¯a ℓ¯b in F , do the following:
We use Brute(F, w) to denote the brute-force algorithm that solves WMC by enumerating all pos-
sible assignments. Clearly, Brute(F, w) runs in O∗ (2n(F ) ) time and it uses constant time if the formula
has only a constant number of variables. The following two rules are based on a divide-and-conquer
idea. However, we only apply them to the cases where one part is of constant size.
R-Rule 8. If formula F can be partitioned into two non-empty sub-formulas F1 and F2 with var(F1 ) ∩
var(F2 ) = ∅ and n(F1 ) ≤ 10, do the following:
1. W ′ ← Brute(F1 , w);
2. W ← W · W ′ , and F ← F2 .
5
R-Rule 9. If there is a variable x such that formula F can be partitioned into two non-empty sub-
formulas F1 and F2 , with var(F1 ) ∩ var(F2 ) = {x} and n(F1 ) ≤ 10, do the following:
1. Wt ← Brute(F1 [x = 1], w);
4. F ← F2 .
Lemma 2. All of the above nine reduction rules are correct.
Proof. For convenience, we extend an assignment σ from variables to literals by setting σ(x̄) = 1−σ(x)
for any variable x. According to our definition of correctness, we need to prove that for each instance
I = (F, w, W ), the instance I ′ = (F ′ , w′ , W ′ ) output by each R-Rule satisfies WMC(F, w) · W =
WMC(F ′ , w′ ) · W ′ . The correctness of the first six rules is relatively straightforward, and we only
provide brief explanations here. We will give detailed proofs for the last three rules. Note that during the
execution of R-Rule 1, R-Rule 2, R-Rule 3, and R-Rule 6, both w and W remain unchanged. For these
rules, we only need to show that an assignment satisfies the original formula if and only if it satisfies the
new formula.
R-Rule 1: A literal and its duplicates in a clause C are assigned the same value by any assignment
σ. Thus, removing the duplicates does not change the satisfiability of C under σ. The set of satisfying
assignments for F remains unchanged.
R-Rule 2: Any assignment σ over var(F ) satisfies a clause C that contains a literal and its negation.
Thus, removing C does not affect the set of satisfying assignments for the formula.
R-Rule 3: If C ⊆ D, any assignment σ that satisfies C must also satisfy D. Therefore, clause D is
redundant if clause C must be satisfied. Removing D does not change the set of satisfying assignments
for the formula.
R-Rule 4: Any satisfying assignment for F must assign the literal ℓ to 1. The total weight of
satisfying assignments for F is the sum of weights of assignments that satisfy both ℓ = 1 and the
resulting formula F [ℓ = 1]. This can be expressed as WMC(F, w) = w(ℓ) · WMC(F [ℓ = 1], w).
The rule sets F ′ = F [ℓ = 1] and W ′ = W · w(ℓ), while w′ = w. Thus, WMC(F, w) · W =
(w(ℓ) · WMC(F ′ , w′ )) · W = WMC(F ′ , w′ ) · W ′ .
R-Rule 5: A variable x with deg(x) = 0 does not appear in any clause. Thus, its value does
not affect the satisfiability of F . The total weighted model count can be factored as WMC(F, w) =
(w(x) + w(x̄)) · WMC(F ′ , w), where F ′ is the resulting formula after removing variable x from the
variable set of formula F . The rule sets W ′ = W · (w(x) + w(x̄)) and F ′ as described. Thus, the
correctness of this rule holds.
R-Rule 6: Let the two clauses be C1 = (ℓa ∨ ℓb ) and C2 = (ℓa ∨ ℓ¯b ∨ C). The rule transforms C2
into C2′ = (ℓa ∨ C). We show that for any assignment σ, it holds that σ |= (C1 ∧ C2 ) if and only if
σ |= (C1 ∧ C2′ ) by considering the following two cases.
• If σ(ℓa ) = 1, both C1 , C2 , C2′ are satisfied. The equivalence holds.
• If σ(ℓa ) = 0, for σ to satisfy (C1 ∧ C2 ), it must satisfy (ℓb ) and (ℓ¯b ∨ C), which implies σ(ℓb ) = 1
and σ |= C. For σ to satisfy (C1 ∧ C2′ ), it must satisfy (ℓb ) and (C), which also implies σ(ℓb ) = 1
and σ |= C. The equivalence holds.
Since for any assignment, it satisfies the original formula if and only if it satisfies the new formula, the
rule is correct.
R-Rule 7: The presence of clauses (ℓa ∨ ℓb ) and (ℓ¯a ∨ ℓ¯b ) implies that any satisfying assignment σ
for F must have σ(ℓa ) ̸= σ(ℓb ), which is equivalent to σ(ℓa ) = σ(ℓ¯b ). We establish a bijection between
the satisfying assignments of F and F ′ . For any satisfying assignment σ of F , we define an assignment
σ ′ for F ′ by setting σ ′ (y) = σ(y) for all y ∈ var(F ′ ). Since var(ℓa ) is removed and all its occurrences
are replaced, σ ′ is well-defined. The weight of a satisfying assignment σ for F can be factored based on
the value of ℓa .
6
• If σ(ℓa ) = 1, then σ(ℓb ) = 0. The weight contribution from these two variables is w(ℓa ) · w(ℓ¯b ).
In F ′ , ℓa is replaced by ℓ¯b . The corresponding assignment σ ′ has σ ′ (ℓ¯b ) = 1. The new weight is
w′ (ℓ¯b ) = w(ℓa ) · w(ℓ¯b ), matching the contribution.
• If σ(ℓa ) = 0, then σ(ℓb ) = 1. The weight contribution is w(ℓ¯a ) · w(ℓb ). In F ′ , ℓ¯a is replaced by
ℓb . The corresponding assignment σ ′ has σ ′ (ℓb ) = 1. The new weight is w′ (ℓb ) = w(ℓ¯a ) · w(ℓb ),
matching the contribution.
This establishes a weight-preserving bijection between the satisfying assignments of F and F ′ . Thus,
WMC(F, w) = WMC(F ′ , w′ ), and the rule is correct.
R-Rule 8: Since var(F1 ) ∩ var(F2 ) = ∅, the set of satisfying assignments of F is the Cartesian
product of the satisfying assignments of F1 and F2 . Due to the multiplicative nature of weights, the
WMC of F is the product of the WMCs of its components:
The rule computes W ′ = WMC(F1 , w) (in constant time as n(F1 ) ≤ 10), sets F ′ = F2 , and updates
the global multiplier to Wnew = Wold · W ′ . We have Wold · WMC(F, w) = Wold · (WMC(F1 , w) ·
WMC(F2 , w)) = (Wold · W ′ ) · WMC(F2 , w) = Wnew · WMC(F ′ , w′ ). Thus, the rule is correct.
R-Rule 9: The total WMC of F can be computed by conditioning on the value of the variable x:
Since var(F1 ) ∩ var(F2 ) = {x}, we have WMC(F [x = 1], w) = WMC(F1 [x = 1], w) · WMC(F2 [x =
1], w) and WMC(F [x = 0], w) = WMC(F1 [x = 0], w)·WMC(F2 [x = 0], w). Let Wt = WMC(F1 [x =
1], w) and Wf = WMC(F1 [x = 0], w), which are computed in constant time. Then,
The rule sets F ′ = F2 and defines a new weight function w′ where w′ (x) = w(x) · Wt , w′ (x̄) =
w(x̄) · Wf , and w′ (y) = w(y) for other literals y. The WMC of the new instance is:
Definition 5 (Reduced formulas). A formula F is called reduced if none of the above reduction rules
is applicable. We use R(F ) to denote the reduced formula obtained by exhaustively applying the above
reduction rules on F .
Lemma 3. For any formula F , applying any reduction rule on F will not increase the number of clauses
or the length of any clause. Moreover, it takes polynomial time to transform F into a reduced formula
R(F ) where no reduction rules can be applied.
Proof. First, we verify that no reduction rule increases the number of variables n(F ), the number of
clauses m(F ), or the total length of all clauses L(F ). It can be verified that none of the nine rules
introduce new variables. R-Rule 1, R-Rule 6, and R-Rule 7 only remove or replace literals; thus, they
do not increase m(F ) or L(F ). The other rules (R-Rule 2, R-Rule 3, R-Rule 4, R-Rule 5, R-Rule 8,
and R-Rule 9) simply remove clauses or variables; so they do not increase these parameters either. Thus,
applying any reduction rule does not increase the number of clauses or the length of any clause.
To prove that the reduction process terminates in polynomial time, we define a potential function
Φ(F ) = n(F ) + m(F ) + L(F ). The initial value of Φ(F ) is polynomial in the input size. We show that
each application of any rule decreases Φ(F ) by at least 1.
Previous analysis shows that the application of any rule would not increase n(F ), m(F ), or L(F ).
Thus, it is sufficient to show that each application strictly decreases at least one of n(F ), m(F ), and
7
L(F ): each application of Rule 1 and R-Rule 6 removes at least one literal, which decreases L(F ) by at
least 1; applying one of R-Rule 2, R-Rule 3, and R-Rule 4 removes at least one clause, which decreases
m(F ) by at least 1; each application of R-Rule 5 and R-Rule 7 removes at least one variable, which
decreases n(F ) by at least 1; R-Rule 8 and R-Rule 9 remove a non-empty sub-formula, which involves
removing at least one variable and one clause and decreases both n(F ) and m(F ) by at least 1.
Since each application of a reduction rule decreases Φ(F ) by at least 1 and Φ(F ) ≥ 0, the reduction
process must terminate. The total number of applications of reduction rules is bounded by the initial
value of Φ(F ), which is polynomial in the input size. Furthermore, each rule can be checked and applied
in polynomial time. Therefore, transforming F into R(F ) can be done in polynomial time.
Lemma 4. In a reduced formula F , it holds that (1) all clauses are 2+ -clauses; (2) all 2-clauses only
contains 2+ -variables.
Proof. By R-Rule 4, there is no 1-clause in F , and so (1) holds. By R-Rule 5, there is no 0-variable in
F . Let C be a 2-clause in F . We partition formula F into F1 = C and F2 = F \ F1 . If C contains two
1-variables, then R-Rule 8 can be applied since var(F1 )∩var(F2 ) = ∅. If C contains only one 1-variable
(assume that x the 2-variable in C), then R-Rule 9 is applicable since var(F1 ) ∩ var(F2 ) = {x}. Thus,
C would not contain 1-variables. This completes the proof.
Proof. Suppose, for the sake of contradiction, that there is a 2-clause ℓa ℓb and there exists a clause C
which contradicts what the lemma says. We consider case by case. (1) If C contains ℓa ℓb , R-Rule 2
is applicable. (2) If C contains ℓ¯a ℓb (or ℓa ℓ¯b ), R-Rule 6 can be applied. (3) If C = ℓ¯a ℓ¯b , R-Rule 7 is
applicable. In conclusion, we can apply reduction rules in any case, a contradiction. Thus, the lemma
holds.
Algorithm 1 Alg2CNF(F, w, W )
Input: 2-CNF formula F , weight function w, and integer W .
Output: The weighted model count W · WMC(F, w).
1: Apply reduction rules exhaustively to reduce F and update w and W accordingly.
2: if F is empty then return W .
3: if F contains empty clause then return 0.
4: if deg(F ) ≥ 5 then
5: Select a variable x with deg(x) = deg(F );
6: Branch on x.
7: else if ∃ x such that deg(x) = 4 and |N4 (x)| ≥ 3 then
8: Branch on x.
9: else
10: P ← path decomposition of G(F ) via Theorem 1.
11: Wpw ← AlgPrimalPw(F, w, P );
12: return W · Wpw .
8
4.1 The Analysis
Although the algorithm itself is simple, its running time analysis is technically involved. We first prove
some properties of a reduced 2-CNF, which will be used in our analysis.
Lemma 6. In a reduced 2-CNF formula F , it holds that (1) all clauses are 2-clauses; (2) all variables
are 2+ -variables; (3) n(F ) ≤ m(F ).
Proof. Since F is a 2-CNF formula, (1) and (2) immediately follow from Lemma 4. Let L(F ) be the
sum of the lengths of clauses in F . Since all clauses are 2-clauses, we have L(F ) = 2m(F ). On the
other hand, since all variables are 2+ -variables, we have L(F ) ≥ 2n(F ). Thus, m(F ) ≥ n(F ) holds.
This completes the proof.
Lemma 7. In a reduced 2-CNF formula F , for a variable x, any clause contains at most one variable in
N2 (x).
Proof. Suppose for contradiction that there is a 2-clause Cyz which contains two variables y and z in
N2 (x) for some variable x. Let Dxy (resp.,Dxz ) be the 2-clause containing variables x and y (resp.,
variables x and z). Since both y and z are 2-variables, formula F can be partitioned into F1 and F2 ,
where F1 = Cxy ∧ Cxz ∧ Cyz and F2 = F \ F1 , such that var(F1 ) ∩ var(F2 ) = {x} and n(F1 ) = 3.
Thus, R-Rule 9 is applicable, which contradicts that F is reduced.
Lemma 8. Let F be a reduced 2-CNF formula and x be a variable in F . All clauses containing x would
not appear in R(F [x = 0]) and R(F [x = 1]).
Proof. By Lemma 6, all clauses in F are 2-clauses. Consider the case that we assign x = 1, and the
case for x = 0 is analogous. All clauses that contain literal x are satisfied and removed. Furthermore,
all clauses that contain literal x̄ become 1-clauses, and thus R-Rule 4 would be applied to remove them.
Thus, all clauses containing x would not appear in R(F [x = 0]) and R(F [x = 1]).
To analyze the running time bound, we focus on phase two and phase three since phase one will
not exponentially increase the running time. For phase two, we mainly use Lemma 1 to get the worst
branching vector. Thus, we need to analyze lower bounds for the decrease of m(F ) in a branching
operation, which is formally presented in Lemma 9 below.
Lemma 9. Let F be a reduced 2-CNF formula of degree d and x be a d-variable in F . Let ∆t =
m(F ) − m(R(F [x = 1])) and ∆f = m(F ) − m(R(F [x = 0])). It holds that
1. ∆t , ∆f ≥ d + |N2 (x)|;
l P m
1
2. ∆t + ∆f ≥ 2d + |N2 (x)| + 2 2≤i≤d (i − 1)|Ni (x)| + 1 if d ≤ 7.
• S1 : the set of clauses that contain variable(s) in N2 (x) but not contain variable x.
• S2 : the set of clauses that contain variable(s) in Ni (x), where i ≥ 3, but not contain any variable
in N2 (x) ∪ {x}.
By definition, S0 , S1 , S2 are pairwise disjoint. The primal graph of F shown in Figure 1 provides a
useful perspective for understanding these notations and the subsequent proofs.
We plan to analyze the bounds for ∆t , ∆f , and ∆t + ∆f by considering whether a clause in S0 ∪
S1 ∪ S2 would be removed after we assign a value to variable x (i.e., whether a clause would appear in
R(F [x = 0]) or R(F [x = 0])).
By Lemma 8, all clauses in S0 would not appear in both R(F [x = 0]) and R(F [x = 1]).
We claim that all clauses in S1 would not appear in both R(F [x = 0]) and R(F [x = 1]). Let C be
a clause containing variable x and a variable y ∈ N2 (x). After we assign a value to x, if clause C is
9
𝑥
𝑁 𝑥 𝑁 𝑥 ⋃ 𝑁 𝑥
𝑦 𝑦 𝑦 𝑧 𝑧 𝑧
𝑡 𝑡
Other variables in the formula
satisfied, then it is removed and y becomes a 1-variable. Then, since y (as a 1-variable) is contained in a
2-clause, R-Rule 9 can be applied to remove the other clause containing y. Otherwise, if clause C is not
satisfied, the literal of x is removed from C and so C becomes a 1-clause. In this case, applying R-Rule 4
would assign a value to variable y. By Lemma 8, all clauses containing y would be removed. Thus, all
clauses that contain some variable in N2 (x) (which includes S1 ) would not appear in both R(F [x = 0])
and R(F [x = 1]).
Since all clauses in S0 and S1 would not appear in both R(F [x = 0]) and R(F [x = 1]), we have
∆t ≥ |S0 |+|S1 | and ∆f ≥ |S0 |+|S1 |. Since |S0 | = d (by definition) and |S1 | = |N2 (x)| (by Lemma 7),
it holds that ∆t , ∆f ≥ d + |N2 (x)|.
Next, we consider the clauses in S2 . Let D be a clause that contains variable x and a variable
z ∈ Ni (x) where i ≥ 3. Assigning either x = 0 or x = 1 would make D become a 1-clause that only
contains variable z. When clause D becomes such 1-clause, R-Rule 4 would be applied to assign a value
to z, and then remove all clauses containing z according to Lemma 8. Thus, for a clause in S2 , it would
not appear in at least one of R(F [x = 0]) and R(F [x = 1]). Together with previous analyses on S0 and
S1 , we have
∆t + ∆f ≥ 2 |S0 | + 2 |S1 | + |S2 | = 2d + 2 |N2 (x)| + |S2 | . (1)
To accurately characterize S2 (and |S2 |), we need some additional notations. For a variable y ∈
N (x), we define P (y) := N (y) ∩ N (x) and Q(y) := N (y) \ (N (x) ∪ {x}). For example, in the
example
P shown in Figure 1, we haveP P (z5 ) = {y2 , z4 , z6 } and Q(z5 ) = {t2 }. For each i ≥ 2, we define
pi := y∈Ni (x) |P (y)| and qi := y∈Ni (x) |Q(y)|.
Since all clauses are 2-clauses, |N (y)| = deg(y) holds from Lemma 5. With this, we have the
following that would come in handy later:
X
pi + qi = |P (y)| + |Q(y)|
y∈Ni (x)
X
= |N (y) \ {x}| by N (y) = {x} ⊔ P (y) ⊔ Q(y)
y∈Ni (x)
X
= (deg(y) − 1) by |N (y)| = deg(y)
y∈Ni (x)
X
= (i − 1) = (i − 1)|Ni (x)|.
y∈Ni (x)
P P
We write p≥3 := i≥3 pi and q≥3 := i≥3 qi for brevity. We claim that
1
|S2 | = (p≥3 − p2 ) + q≥3 and (p≥3 − p2 ) mod 2 = 0. (2)
2
S
The reason is as follows. By definition, |S2 | is the number of clauses that contain variable(s)
S in i≥3 Ni (x),
but not contain any variable in N2 (x) ∪ {x}. We may simply write N≥3 (x) := i≥3 Ni (x). Consider
10
the primal graph shown in Figure 1. |S2 | is the number of “green edges” in FigureS 1. We further partition
S3 into S3in ⊔ S3out , where S3in is the set of clauses that contain two variables in i≥3 Ni (x) (e.g., z4 z5
and z5 z6 in the figure) and S3out is the set of clauses that contain a variable in N≥3 (x) (e.g., z5 t2 and
z6 t2 in the figure). We have q≥3 = S3out by definition. Since p2 is the number of clauses that contain
a variable in N2 (x) and a variable in N≥3 (x) (i.e., number of red edges between N2 (x) and N≥3 (x)),
We have p≥3 = 2 S3in + p2 . This gives us S3in = 21 (p≥3 − p2 ) and (p≥3 − p2 ) mod 2 = 0. With
q≥3 = S3out , we have |S2 | = S3in + S3out = 21 (p≥3 − p2 ) + q≥3 .
By putting (2) into (1) and writing β := (p≥3 − p2 ) + 2(p2 + q2 ) + 2q≥3 for convenience, we have
1
∆t + ∆f ≥ 2d + 2(p2 + q2 ) + (p≥3 − p2 ) + q≥3
2 (3)
1 1
= 2d + (p2 + q2 ) + β = 2d + |N2 (x)| + β.
2 2
Next, we claim that
1 1 X
β≥ (i − 1)|Ni (x)|
+ 1. (4)
2 2
2≤i≤d
Note that with Eq. (3), the lemma directly follows from Eq. (4). Next, we only need to prove Eq. (4).
By pi + qi = (i − 1)|Ni (x)|, we have
We need some discussions on the value of q≥3 + q2 . First, we claim that q≥3 + q2 ≥ 2 if F
is reduced. The reason is as follows. Let F1 = S0 ∪ S1 ∪ S2 and F2 = F \ F1 . Recall that by
definition, N (x) ∪ {x}S⊆ var(F1 ), and for y ∈ N (x), Q(y) := N (y)P \ (N (x) ∪ {x}). Thus, we have
var(F1 ) ∩ var(F2 ) = y∈N (x) Q(y), and so |var(F1 ) ∩ var(F2 )| ≤ y∈N (x) |Q(y)| = q2 + q≥3 . Since
|var(F1 )| = 1 + d ≤ 8, R-Rule 8 can be applied if q≥3 + q2 = 0, and R-Rule 9 can be applied if
q≥3 + q2 = 1. Next, we consider the following two cases.
Case 1: q≥3 +q2 = 2. Recall that by (2), we have (p≥3 −p2 ) mod 2 =P0. Since β = p≥3 −p2 +2(p2 +
q2 )+2q≥3 , we have β mod 2 = 0. On the other hand, we also have β P = 2≤i≤d (i−1)|Ni (x)|+q≥3 +q2
by (5). Since (q≥3 + q2 ) mod 2 = 0 in this case, we can know that 2≤i≤d (i − 1)|Ni (x)| mod 2 = 0
holds. Thus, it holds that
1 1 X 1 X
β= (i − 1)|Ni (x)| + 2 = (i − 1)|Ni (x)|
+ 1.
2 2 2
2≤i≤d 2≤i≤d
With Lemma 9 in hand, we proceed to determine the branching vectors of our branching operations.
Lemma 10. In Alg2CNF, the branching operation in Line 6 generates a branching vector not worse
than (5, 11).
11
Proof. In this branching operation, we branch on a d-variable with d ≥ 5. By Lemma 9, we have
∆t , ∆f ≥ d + |N2 (x)| ≥ d. If d ≥ 8, this gives a branching vector not worse than (8, 8). Otherwise if
5 ≤ d ≤ 7, by Lemma 9, we further have
1 X
∆t + ∆f ≥ 2d + |N2 (x)| + 2 (i − 1)|Ni (x)|+1
2≤i≤d
1 X
≥ 2d + 2 |N2 (x)| + (i − 1)|Ni (x)| + 1
2
2≤i≤d
1 X
≥ 2d + 2|Ni (x)| + 1
2
2≤i≤d
X
≥ 2d + |Ni (x)| + 1
2≤i≤d
= 3d + 1 ≥ 16.
With ∆t , ∆f ≥ d ≥ 5, by Lemma 1, the branching vector not worse than (5, 11). Since τ (8, 8) <
1.0905 < τ (5, 11) < 1.0956, the lemma holds.
Lemma 11. In Alg2CNF, the branching operation in Line 8 generates a branching vector not worse
than (4, 11).
Proof. In this branching operation, we branch on a 4-variable x with |N4 (x)| ≥ 3. Note that in this step
we have deg(F ) = 4. By Lemma 9 with d = 4, we have ∆t , ∆f ≥ d = 4 and
1 X
∆t + ∆f ≥ 2d + |N2 (x)| + 2 (i − 1)|Ni (x)|
+1
2≤i≤d
d
& !'
1 X
≥ 2d + 2 |N2 (x)| + (i − 1)|Ni (x)| +1
2
i=3
1 X
≥ 2d + 2 |N4 (x)| + 2|Ni (x)|+1
2≤i≤d
1
≥ 2d + (3 + 2d) + 1 = 15.
2
By Lemma 1, the branching vector generated by this step is not worse than (4, 11).
12
1 PLet V4 be the set of 4-variables in the formula. The number of clauses that contain two 4-variables
P is
2 x∈V4 |N 4 (x)|, and the number of clauses that contain at most one 4-variable is at least x∈V4 (4 −
|N4 (x)|). Thus, we have
1 X X X 1 X
m≥ |N4 (x)| + (4 − |N4 (x)|) ≥ (4 − |N4 (x)|) ≥ (4 − 1) = 3n4 ,
2 2
x∈V4 x∈V4 x∈V4 x∈V4
pw(G(F )) ≤ n3 /6 + n4 /3 + n≥5 + ϵn
= (n3 + 2n4 )/6 + ϵn
≤ (4/27 + ϵ) m by (7).
Moreover, by Theorem 1, a path decomposition of G(F ) with width at most (4/27 + ϵ) m can be con-
structed in polynomial time. Then, we can apply Theorem 2 to solve the problem in time
O∗ (2(4/27+ϵ)m ) ⊆ O∗ (1.1082m ).
Now we are ready to conclude a running-time bound of Algorithm Alg2CNF. By Lemma 10 and
Lemma 11, branching operations in Line 6 and Line 8 generate a branching vector not worse than (5, 11)
and (4, 11), respectively. By Lemma 12, phase three (Lines 10 and 11) takes O∗ (1.1082m ) time. Since
τ (5, 11) < 1.0956 and τ (4, 11) < 1.1058, we have the following result.
Theorem 4. Alg2CNF (Algorithm 1) solves WMC on 2-CNF formulas in O∗ (1.1082m ) time, where m
is the number of clauses in the input formula.
Algorithm 2 Alg3CNF(F, w, W )
Input: 3-CNF formula F , weight function w, and integer W .
Output: The weighted model count W · WMC(F, w).
1: Apply reduction rules exhaustively to reduce F and update w and W accordingly.
2: if F is empty then return W .
3: if F contains empty clause then return 0.
4: if there is a d-variable x in F with d ≥ 3 then
5: Branch on x.
6: else
7: P ← path decomposition of Gd (F ) via Theorem 1.
8: Wpw ← AlgDualPw(F, w, P );
9: return W · Wpw
13
5.1 The Measure
The analysis of the algorithm is different from that of the algorithm for #2-SAT. In this algorithm, it may
not be effective to use m(F ) as the measure in the analysis since we can not guarantee this measure
always decreases in all our steps. For example, a variable x may only appear as a positive literal in some
3-clauses. After assigning x = 0, it is possible that no reduction rule is applicable and no clause is
removed (i.e., m(F ) = m(R(F [x = 0]))). One of our strategies is to use the following combinatorial
measure to analyze the algorithm
µ(F ) := m3 (F ) + α · m2 (F ),
where mi (F )(i ∈ {2, 3}) is the number of i-clauses in formula F and 0 < α < 1 is a tunable parameter.
Note that m(F ) = m3 (F ) + m2 (F ) since there is no 1-clause in a reduced formula by Lemma 4 (we
can simply assume that the initial input formula is reduced). Thus, µ(F ) ≤ m(F ). It can be verified that
all the reduction rules would not increase µ(F ) for any 0 < α < 1. If we can get a running time bound
of O∗ (cµ(F ) ), with a real number c > 1, we immediately get a running time bound of O∗ (cm(F ) ). We
will first analyze the algorithm and obtain the branching vectors related to α, and then set the value of α
to minimize the largest factor.
Lemma 13. Let F be a reduced 3-CNF formula, x be a variable in F , and ck (k ∈ {2, 3}) be the number
of k-clauses containing variable x. Let ∆t := µ(F ) − µ(R(F [x = 1])) and ∆f := µ(F ) − µ(R(F [x =
0])). It holds that
1. ∆t , ∆f ≥ c2 · α + c3 · (1 − α);
2. ∆t + ∆f ≥ c2 · 2α + c3 · (2 − α).
Proof. Let Skℓ , where k ∈ {2, 3} and ℓ ∈ {x, x̄}, be the set of k-clauses that contain literal ℓ. By
definition, we have ck = |Skx | + |Skx̄ | for k ∈ {2, 3}.
Consider what happens after we assign x = 1. First, all clauses containing literal x (i.e., clauses
in S3x and S2x ) are satisfied (and so removed). This decreases ∆t by at least |S3x | + |S2x | · α. Second,
all 3-clauses that contain literal x̄ (i.e., clauses in S3x̄ ) become 2-clauses. This decreses ∆t by at least
|S3x̄ | · (1 − α). Third, all 2-clauses that contain literal x̄ (i.e., clauses in S2x̄ ) become 1-clauses, and then
R-Rule 4 would be applied to remove these clauses. This decreases ∆t by at least |S2x̄ | · α. In summary,
we have
∆t + ∆f ≥ 2 · c2 · α + 2 · c3 · (1 − α) + S3x̄ · α + |S3x | · α
= c2 · 2α + c3 · 2(1 − α) + c3 · α
= c2 · 2α + c3 · (2 − α).
Armed with Lemma 13, we can derive the branching vectors generated by phase two (Line 5) in
Algorithm 2.
14
Lemma 14. In Alg3CNF, the branching operation in Line 5 generates a branching vector not worse
than the worst one of the following branching vectors:
Next, we analyze the time complexity of phase three (Lines 7 and 8) in Algorithm 2.
µ(F )
Lemma 15. Phase three (Lines 7-8) of Alg3CNF can be executed in O∗ (1.1225 α ) time.
Proof. When the algorithm reaches Line 7, the branching operation is not applicable. Thus, at this point,
the formula F is a reduced 3-CNF formula with deg(F ) ≤ 2.
Let m := m(F ) and µ := µ(F ). Consider the dual graph Gd (F ) of formula F . The number of
vertices in Gd (F ) is m.
Let C ∈ F be a clause in formula F . We have |C| ≤ 3. Since each variable in C has a degree of at
most two, the number of clauses that share a common variable with C is at most |C| ≤ 3. That is, for
any C ∈ F , we have |{D ∈ F | D ̸= C and var(C) ∩ var(D) ̸= ∅}| ≤ 3.
This means that in Gd (F ), each vertex has a degree of at most three. Let ni (i ∈ Z) be the number
of vertices with degree i in Gd (F ). We have ni = 0 for i ≥ 4 and n3 ≤ m. Let ϵ be a small const (say
10−9 ) and mϵ be the corresponding integer (which is also a constant) in Theorem 1. If m ≤ mϵ , we
invoke brute-force algorithm Brute to solve the problem in constant time. Otherwise, if m > mϵ , we
can apply Theorem 1 and get
pw(Gd (F )) ≤ n3 /6 + n4 /3 + n≥5 + ϵm
µ
≤ (1/6 + ϵ) m ≤ (1/6 + ϵ) .
α
Here, the last inequality follows from m ≤ α1 µ, which can be derived by the definition of m and µ.
In addition, by Theorem 1, a path decomposition of Gd (F ) with width at most (1/6 + ϵ) αµ can be
constructed in polynomial time. Then, we can apply Theorem 3 to solve the problem in time
(1/6+ϵ)µ µ
O∗ (2 α ) ⊆ O∗ (1.1225 α ).
We are now poised to analyze the overall running time of Alg3CNF. The time complexity of phase
two (by Lemma 14) and phase three (by Lemma 15) are summarized in Table 1.
Factors / Base
Phases Branching vectors
α = 0.6309297
(3, 3 − 3α) 1.4423
(2 + α, 2 − α) 1.4324
Phase two
(1 + 2α, 1 + α) 1.4325
(3α, 3α) 1.4423
1
Phase three - 1.1225 α = 1.2011
Table 1: The branching vectors and corresponding factors generated by phase two of Alg3CNF, and the base of
the time complexity in terms of µ(F ) of phase three, all under α = 0.6309297.
15
By setting α = 0.6309297, the largest factor in phase two is minimized to 1.4423, corresponding to
µ(F )
the branching vectors (3, 3−3α) and (3α, 3α). The time complexity of phase three is O∗ (1.1225 α ) ⊆
O∗ (1.2011µ(F ) ). With µ(F ) ≤ m(F ), we arrive at the following result.
Theorem 5. Alg3CNF (Algorithm 2) solves WMC on 3-CNF formulas in O∗ (1.4423m ) time, where m
is the number of clauses in the input formula.
Acknowledgements
The work is supported by the National Natural Science Foundation of China, under the grants 62372095,
62172077, and 62350710215.
References
[1] Fahiem Bacchus, Shannon Dalmao, and Toniann Pitassi. Algorithms and complexity results for #sat
and bayesian inference. In 44th Symposium on Foundations of Computer Science (FOCS 2003),
11-14 October 2003, Cambridge, MA, USA, Proceedings, pages 340–351. IEEE Computer Society,
2003. doi: 10.1109/SFCS.2003.1238208. URL [Link]
[2] Richard Beigel and David Eppstein. 3-coloring in time o(1.3289n ). J. Algorithms, 54(2):168–204,
2005. doi: 10.1016/[Link].2004.06.008. URL [Link]
[3] Armin Biere, Marijn Heule, Hans van Maaren, and Toby Walsh, editors. Handbook of Satisfiability
- Second Edition, volume 336 of Frontiers in Artificial Intelligence and Applications. IOS Press,
2021. doi: 10.3233/FAIA336. URL [Link]
[4] Mark Chavira and Adnan Darwiche. On probabilistic inference by weighted model counting. Artif.
Intell., 172(6-7):772–799, 2008. doi: 10.1016/[Link].2007.11.002. URL [Link]
1016/[Link].2007.11.002.
[5] Huairui Chu, Mingyu Xiao, and Zhe Zhang. An improved upper bound for SAT. In Thirty-Fifth
AAAI Conference on Artificial Intelligence, AAAI 2021, Thirty-Third Conference on Innovative Ap-
plications of Artificial Intelligence, IAAI 2021, The Eleventh Symposium on Educational Advances
in Artificial Intelligence, EAAI 2021, Virtual Event, February 2-9, 2021, pages 3707–3714. AAAI
Press, 2021. doi: 10.1609/AAAI.V35I5.16487. URL [Link]
[6] Stephen A. Cook. The complexity of theorem-proving procedures. In Michael A. Harrison,
Ranan B. Banerji, and Jeffrey D. Ullman, editors, Proceedings of the 3rd Annual ACM Sympo-
sium on Theory of Computing, May 3-5, 1971, Shaker Heights, Ohio, USA, pages 151–158. ACM,
1971. doi: 10.1145/800157.805047.
16
[7] Marek Cygan, Holger Dell, Daniel Lokshtanov, Dániel Marx, Jesper Nederlof, Yoshio Okamoto,
Ramamohan Paturi, Saket Saurabh, and Magnus Wahlström. On problems as hard as CNF-SAT.
ACM Trans. Algorithms, 12(3):41:1–41:24, 2016. doi: 10.1145/2925416. URL [Link]
1145/2925416.
[8] Vilhelm Dahllöf, Peter Jonsson, and Magnus Wahlström. Counting models for 2sat and 3sat for-
mulae. Theor. Comput. Sci., 332(1-3):265–291, 2005. doi: 10.1016/[Link].2004.10.037. URL
[Link]
[9] Olivier Dubois. Counting the number of solutions for instances of satisfiability. Theor. Com-
put. Sci., 81(1):49–64, 1991. doi: 10.1016/0304-3975(91)90315-S. URL [Link]
0304-3975(91)90315-S.
[10] Jeffrey M. Dudek, Vu H. N. Phan, and Moshe Y. Vardi. DPMC: weighted model counting by
dynamic programming on project-join trees. In Helmut Simonis, editor, Principles and Practice of
Constraint Programming - 26th International Conference, CP 2020, Louvain-la-Neuve, Belgium,
September 7-11, 2020, Proceedings, volume 12333 of Lecture Notes in Computer Science, pages
211–230. Springer, 2020. doi: 10.1007/978-3-030-58475-7\ 13. URL [Link]
978-3-030-58475-7 13.
[11] Leonardo Dueñas-Osorio, Kuldeep S. Meel, Roger Paredes, and Moshe Y. Vardi. Counting-based
reliability estimation for power-transmission grids. In Satinder Singh and Shaul Markovitch, ed-
itors, Proceedings of the Thirty-First AAAI Conference on Artificial Intelligence, February 4-9,
2017, San Francisco, California, USA, pages 4488–4494. AAAI Press, 2017. doi: 10.1609/AAAI.
V31I1.11178. URL [Link]
[12] Johannes Klaus Fichte, Markus Hecher, and Markus Zisser. An improved gpu-based SAT model
counter. In Thomas Schiex and Simon de Givry, editors, Principles and Practice of Constraint
Programming - 25th International Conference, CP 2019, Stamford, CT, USA, September 30 -
October 4, 2019, Proceedings, volume 11802 of Lecture Notes in Computer Science, pages
491–509. Springer, 2019. doi: 10.1007/978-3-030-30048-7\ 29. URL [Link]
978-3-030-30048-7 29.
[13] Johannes Klaus Fichte, Markus Hecher, Patrick Thier, and Stefan Woltran. Exploiting database
management systems and treewidth for counting. Theory Pract. Log. Program., 22(1):128–157,
2022. doi: 10.1017/S147106842100003X. URL [Link]
[14] Johannes Klaus Fichte, Daniel Le Berre, Markus Hecher, and Stefan Szeider. The silent (r)evolution
of SAT. Commun. ACM, 66(6):64–72, 2023. doi: 10.1145/3560469. URL [Link]
3560469.
[15] Johannes Klaus Fichte, Markus Hecher, Michael Morak, Patrick Thier, and Stefan Woltran. Solving
projected model counting by utilizing treewidth and its limits. Artif. Intell., 314:103810, 2023. doi:
10.1016/[Link].2022.103810. URL [Link]
[16] Fedor V. Fomin and Dieter Kratsch. Exact Exponential Algorithms. Texts in Theoretical Com-
puter Science. An EATCS Series. Springer, 2010. ISBN 978-3-642-16532-0. doi: 10.1007/
978-3-642-16533-7. URL [Link]
[17] Fedor V. Fomin, Serge Gaspers, Saket Saurabh, and Alexey A. Stepanov. On two techniques
of combining branching and treewidth. Algorithmica, 54(2):181–207, 2009. doi: 10.1007/
S00453-007-9133-3. URL [Link]
[18] Serge Gaspers and Gregory B. Sorkin. A universally fastest algorithm for max 2-sat, max 2-csp,
and everything in between. In Claire Mathieu, editor, Proceedings of the Twentieth Annual ACM-
SIAM Symposium on Discrete Algorithms, SODA 2009, New York, NY, USA, January 4-6, 2009,
pages 606–615. SIAM, 2009. doi: 10.1137/1.9781611973068.67. URL [Link]
9781611973068.67.
17
[19] Carla P. Gomes, Ashish Sabharwal, and Bart Selman. Model counting. In Armin Biere, Marijn
Heule, Hans van Maaren, and Toby Walsh, editors, Handbook of Satisfiability - Second Edition,
volume 336 of Frontiers in Artificial Intelligence and Applications, pages 993–1014. IOS Press,
2021. doi: 10.3233/FAIA201009. URL [Link]
[20] Markus Hecher, Patrick Thier, and Stefan Woltran. Taming high treewidth with abstraction, nested
dynamic programming, and database technology. In Luca Pulina and Martina Seidl, editors, Theory
and Applications of Satisfiability Testing - SAT 2020 - 23rd International Conference, Alghero,
Italy, July 3-10, 2020, Proceedings, volume 12178 of Lecture Notes in Computer Science, pages
343–360. Springer, 2020. doi: 10.1007/978-3-030-51825-7\ 25. URL [Link]
978-3-030-51825-7 25.
[21] Russell Impagliazzo and Ramamohan Paturi. On the complexity of k-SAT. J. Comput. Syst. Sci.,
62(2):367–375, 2001. doi: 10.1006/jcss.2000.1727.
[22] Kazuo Iwama. CNF satisfiability test by counting and polynomial average time. SIAM J. Comput.,
18(2):385–391, 1989. doi: 10.1137/0218026. URL [Link]
[23] Tuukka Korhonen and Matti Järvisalo. Integrating tree decompositions into decision heuris-
tics of propositional model counters (short paper). In Laurent D. Michel, editor, 27th Interna-
tional Conference on Principles and Practice of Constraint Programming, CP 2021, Montpel-
lier, France (Virtual Conference), October 25-29, 2021, volume 210 of LIPIcs, pages 8:1–8:11.
Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2021. doi: 10.4230/[Link].2021.8. URL
[Link]
[24] Konstantin Kutzkov. New upper bound for the #3-sat problem. Inf. Process. Lett., 105(1):1–5,
2007. doi: 10.1016/[Link].2007.06.017. URL [Link]
[25] Eliezer L. Lozinskii. Counting propositional models. Inf. Process. Lett., 41(6):327–332, 1992. doi:
10.1016/0020-0190(92)90160-W. URL [Link]
[26] Nina Narodytska, Aditya A. Shrotri, Kuldeep S. Meel, Alexey Ignatiev, and João Marques-Silva.
Assessing heuristic machine learning explanations with model counting. In Mikolás Janota and Inês
Lynce, editors, Theory and Applications of Satisfiability Testing - SAT 2019 - 22nd International
Conference, SAT 2019, Lisbon, Portugal, July 9-12, 2019, Proceedings, volume 11628 of Lecture
Notes in Computer Science, pages 267–278. Springer, 2019. doi: 10.1007/978-3-030-24258-9\ 19.
URL [Link] 19.
[27] Dan Roth. On the hardness of approximate reasoning. Artif. Intell., 82(1-2):273–302, 1996. doi:
10.1016/0004-3702(94)00092-1. URL [Link]
[28] Marko Samer and Stefan Szeider. Algorithms for propositional model counting. J. Discrete Al-
gorithms, 8(1):50–64, 2010. doi: 10.1016/[Link].2009.06.002. URL [Link]
2009.06.002.
[29] Tian Sang, Paul Beame, and Henry A. Kautz. Performing bayesian inference by weighted model
counting. In Manuela M. Veloso and Subbarao Kambhampati, editors, Proceedings, The Twentieth
National Conference on Artificial Intelligence and the Seventeenth Innovative Applications of Ar-
tificial Intelligence Conference, July 9-13, 2005, Pittsburgh, Pennsylvania, USA, pages 475–482.
AAAI Press / The MIT Press, 2005. URL [Link]
php.
[30] Leslie G. Valiant. The complexity of computing the permanent. Theor. Comput. Sci., 8:189–201,
1979. doi: 10.1016/0304-3975(79)90044-6. URL [Link]
[31] Magnus Wahlström. A tighter bound for counting max-weight solutions to 2sat instances. In Martin
Grohe and Rolf Niedermeier, editors, Parameterized and Exact Computation, Third International
18
Workshop, IWPEC 2008, Victoria, Canada, May 14-16, 2008. Proceedings, volume 5018 of Lecture
Notes in Computer Science, pages 202–213. Springer, 2008. doi: 10.1007/978-3-540-79723-4\ 19.
URL [Link] 19.
[32] Mingyu Xiao. An exact maxsat algorithm: Further observations and further improvements. In
Luc De Raedt, editor, Proceedings of the Thirty-First International Joint Conference on Artificial
Intelligence, IJCAI 2022, Vienna, Austria, 23-29 July 2022, pages 1887–1893. [Link], 2022. doi:
10.24963/IJCAI.2022/262. URL [Link]
[33] Wenhui Zhang. Number of models and satisfiability of sets of clauses. Theor. Comput. Sci., 155(1):
277–288, 1996. doi: 10.1016/0304-3975(95)00144-1. URL [Link]
00144-1.
[34] Junping Zhou, Minghao Yin, and Chunguang Zhou. New worst-case upper bound for #2-sat and #3-
sat with the number of clauses as the parameter. In Maria Fox and David Poole, editors, Proceedings
of the Twenty-Fourth AAAI Conference on Artificial Intelligence, AAAI 2010, Atlanta, Georgia,
USA, July 11-15, 2010, pages 217–222. AAAI Press, 2010. doi: 10.1609/AAAI.V24I1.7537. URL
[Link]
19
A The Issue in the Analysis of the Previous Algorithm
We give a note on the issue in the analysis of the algorithm for #3-SAT suggested in [34]. Their algorithm
is presented in Algorithm 3 (denoted by Alg3CNF-prev) below. We note that Alg3CNF-prev was
proposed only for the unweighted version, and some of the terminology they used differs from ours.
Here, we restated the algorithm within the framework used in this paper.
Algorithm 3 Alg3CNF-prev(F, w, W )
Input: 3-CNF formula F , weight function w, integer W .
Output: Integer W , which is the weighted model count of F .
1: Apply reduction rules exhaustively to reduce F and update w and W accordingly.
2: if F is empty then return W .
3: if F contains empty clause then return 0.
4: if there is 3-clause in F then
5: Select a variable x with the maximum degree in all 3-clauses;
6: Branch on x.
7: else
8: return Alg2CNF(F, w, W ).
Their algorithm employs only simple reduction rules, which are a subset of those used in this paper.
Our primary focus is on the part of analysis of the branching operation. The idea of the algorithm is to
branch on a variable with maximum degree among all variables in 3-clauses (if it exists). When there
is no 3-clause, the formula is a 2-CNF and so the problem can be solved directly by an algorithm for
#2-SAT (e.g., our Alg2CNF).
The analysis in [34] is as follows. First, the degree of the variable selected in Line 5 is at least 2.
Otherwise, all variables in 3-clauses are 1-variables, and some reduction rules are applicable. This is
true.
The issue arises in the subsequent argumentation: Second, when x is fixed to a value, every clause
containing x (or x̄) is either removed or simplified as 2-clauses. Since the degree of x is at least 2, at
least two clauses are removed when we give a fixed value to x. Therefore, we have a branching vector of
(2, 2), whose corresponding factor is 1.4142.
However, the above argument may not always be valid. It is not guaranteed that “at least two clauses
are removed when we assign a value to x”. For example, a variable x may only appear as a positive
literal in some 3-clauses. After assigning x = 0, it is possible that no reduction rule is applicable and no
clause is removed (i.e., m(F ) = m(R(F [x = 0]))). Thus, we may only be able to get a branching vector
of (2, 0). Since the parameter m does not decrease in the sub-branch x = 0, such an analysis might not
yield a valid running time bound. This is the reason why we adopt a different measure in our analysis of
the algorithm Alg3CNF.
20
According to Lemmas 4 and 6, in a reduced 2-CNF formula, all clauses are 2-clauses, and all variables are 2+-variables, ensuring that there are no 1-clauses and no variables appear in fewer than 2 clauses. These properties are significant as they simplify the structure, making it feasible to apply reduction rules and guaranteeing the correctness and efficiency of the algorithm .
In reduced 2-CNF formulas, reduction rules ensure all clauses are 2-clauses with 2+-variables, eliminating trivial clauses and variables to streamline the formula . For 3-CNF, the lack of 1-clauses and optimally reduced k-clauses aligned with the measure µ(F), fosters a structure conducive to algorithmic solvers by reducing complexity and improving manageability for further dynamic processing . These simplifications facilitate efficient branching and dynamic programming, enhancing solver performance across various stages of computation.
Algorithm 1 applies different branching strategies based on the degrees of variables. It branches on 5+-variables and some special 4-variables when the degree of the formula is at least 5 or when some variable’s n4 is at least 3. These strategic selections effectively reduce the formula complexity by lowering the variable degrees, which facilitates the creation of a primal graph with a small pathwidth after phase two, thus allowing dynamic programming solutions to operate more efficiently .
Alg3CNF efficiently solves WMC on 3-CNF formulas by first employing branch-and-search to eliminate high-degree variables, followed by dynamic programming strategies on a reduced structure with a favorable dual pathwidth. The algorithm achieves a running time of O*(1.4423^m), a significant enhancement compared to the previous O*(2^m) barrier. This improvement leverages combinatorial measures and optimization techniques that substantially reduce computational overhead .
Tree decomposition strategies in model counting can significantly influence artificial intelligence by enabling more sophisticated algorithms tailored to specific structural properties of problems, potentially leading to performance breakthroughs in areas such as reasoning, Bayesian inference, and optimization. By allowing efficient handling of highly connected variables and reducing problem complexity, these methods lay the groundwork for more dynamic, adaptable AI systems capable of tackling diverse and complex real-world challenges effectively. This influence is poised to drive inventive approaches and cross-disciplinary collaborations, probing deeply into the core of AI problem-solving strategies .
Each application of a reduction rule decreases the potential function Φ(F) by at least 1 while maintaining Φ(F) ≥ 0, guaranteeing termination. Since each rule is polynomially checkable and applicable, the process is computationally feasible. Additionally, the total number of applications is bounded by the initial Φ(F), ensuring that transforming F into R(F) can be achieved in polynomial time .
µ(F) is more effective than m(F) for Algorithm 2 because it accounts for the impact of both 2-clauses and 3-clauses with a weight factor α (<1), which allows for more precise tracking of formula reductions when branching occurs. The measure does not always decrease with m(F) since certain assignments might not trigger clause removals. By ensuring that all the reduction rules do not increase µ(F), the analysis becomes more reliable for deriving branching vectors and achieving computational efficiency .
The branching and dynamic programming approach used in weighted model counting demonstrates potential for practical applications in solving other computational problems as it highlights the effectiveness of combining structural decomposition with efficient enumeration strategies. The approach suggests new opportunities for optimization in problems amenable to similar structural transformations and encourages further exploration into the applicability of these strategies across domains, such as probabilistic inference and constraint satisfaction problems .
In a reduced 2-CNF formula, deleting clauses containing x when extending the solution to R(F[x=0]) and R(F[x=1]) poses challenges because the satisfaction of clauses with literal x affects the remaining structure. When x=1, all clauses with literal x are satisfied and removed, and those containing ¯x are reduced to 1-clauses. R-Rule 4 removes these, ensuring that x's presence does not influence other clauses in subsequent reductions; this requirement imposes additional structural constraints on the transformation process .
The time complexity of phase three in Algorithm 2 depends on minimizing the largest factor in branching vectors because this directly influences the exponential growth term of the algorithm’s runtime with respect to µ(F). By tuning α to 0.6309297, the branching vectors (3, 3−3α) and (3α, 3α) are optimized to produce the smallest possible growth factor, reducing time complexity and enhancing efficiency. This careful parameter adjustment aligns the branching dynamics with the structural constraints, ensuring effective branching .