IASCAR: Incremental Answer Set Counting by Anytime Refinement

Answer set programming (ASP) is a popular declarative programming paradigm with various applications. Programs can easily have many answer sets that cannot be enumerated in practice, but counting still allows quantifying solution spaces. If one counts under assumptions on literals, one obtains a tool to comprehend parts of the solution space, so-called answer set navigation. However, navigating through parts of the solution space requires counting many times, which is expensive in theory. Knowledge compilation compiles instances into representations on which counting works in polynomial time. However, these techniques exist only for CNF formulas, and compiling ASP programs into CNF formulas can introduce an exponential overhead. This paper introduces a technique to iteratively count answer sets under assumptions on knowledge compilations of CNFs that encode supported models. Our anytime technique uses the inclusion-exclusion principle to improve bounds by over- and undercounting systematically. In a preliminary empirical analysis, we demonstrate promising results. After compiling the input (offline phase), our approach quickly (re)counts.


Introduction
Answer set programming (ASP) (Marek and Truszczyński, 1999;Niemelä, 1999;Brewka et al., 2011) is a widely used declarative problem modeling and solving paradigm with many applications in artificial intelligence such as knowledge representation, planning, and many more (Baral, 2003;Pontelli et al., 2012).It is widely used to solve difficult search problems while allowing compact modeling (Gebser et al., 2012).In ASP, a problem is represented as a set of rules, called logic program, over atoms.Models of a program under the stable semantics (Gelfond and Lifschitz, 1988;Gelfond and Lifschitz, 1991) form its solutions, so-called answer sets.Beyond the Related Works.Previous work (Bogaerts and den Broeck, 2015) considered knowledge compilation for logic programs.There an eager incremental approximation technique incrementally computes the result whereas our approach can be seen as an incremental lazy approach on the counting graph.Moreover, the technique by Bogarts and Broeck focuses on well-founded models and stratified negation, which does not work for normal programs in general without translating ASP programs into CNFs directly.Note that common reasoning problems on answer set programs without negation can be solved in polynomial time (Truszczyński, 2011).Model counting can significantly benefit from preprocessing techniques (Lagniez et al., 2016;Lagniez and Marquis, 2014), which eliminate variables.Widely used propositional knowledge compilers are c2d (Darwiche, 2004) and d4.Very recent works consider enumerating answer sets (Alviano et al., 2023), which can be beneficial for counting if the number of answer sets is sufficiently low.More advanced enumeration techniques have also recently been studied for propositional satisfiability (Masina et al., 2023;Spallitta et al., 2023).
Prior Work.This paper extends the conference publication (Fichte et al., 2022a).The paper contains more elaborate examples and proofs that have been omitted in the preliminary version.We now provide an empirical evaluation on relevant instances and instances that have been used for counting in previous works.We formulate detailed questions and hypotheses for our algorithm's implementation and evaluation.Now, our evaluation incorporates two instance sets containing a large number of instances, and we compare our approach to state-of-the-art model counters.

Preliminaries
We assume familiarity with propositional satisfiability (Kleine Büning and Lettmann, 1999), graph theory (Bondy and Murty, 2008), and propositional ASP (Gebser et al., 2012).Recall that a cycle C on a (di)graph G is a (directed) walk of G where the first and the last vertex coincide.For cycle C, we let V C be its vertices and cycles(G) := {V C | C is a cycle of G}.We consider propositional variables and mean by formula a propositional formula.By ⊤ and ⊥ we refer to the variables that are always evaluated to 1 or 0 (constants).A literal is an atom a or its negation ¬a, and vars(ϕ) denotes the set of variables that occur in formula ϕ.The set of models of a formula ϕ is given by M(ϕ).Below, we introduce the necessary background and notation used in the paper for ASP, and knowledge compilation.
Answer Set Programming.Let us recall basic notions of ASP, for further details we refer to standard texts (Gebser et al., 2012).In the context of ASP, we usually say atom instead of variable.A (propositional logic) program Π is a finite set of rules r of the form a 0 ← a 1 , . . ., a m , ¬a m+1 , . . ., ¬a n where 0 ≤ m ≤ n and a 0 , . . ., a n are atoms and usually omit ⊤ and ⊥.For a rule r, we define H(r) := {a 0 } called head of r.The body consists of B + (r) := {a 1 , . . ., a m } and B − (r) := {a m+1 , . . ., a n }.The set at(r) of atoms of r consists of H(r) ∪ B + (r) ∪ B − (r).Let Π be a program.Then, we let the set at(Π) := r∈Π at(r) of Π contain its atoms.Its positive dependency digraph DP(Π) = (V, E) is defined by V := at(Π) and E := {(a 1 , a 0 ) | a 1 ∈ B + (r), a 0 ∈ H(r), r ∈ Π}.The cycles of Π are given by cycles(Π) := cycles(DP(Π)).Π is tight, if DP(Π) is acyclic.An interpretation of Π is a set I ⊆ at(Π) of atoms.I satisfies a rule r ∈ Π if H(r) ∩ I = / 0 whenever B + (r) ⊆ I and B − (r) ∩ I = / 0. I satisfies Π, if I satisfies each rule r ∈ Π.The GL-reduct Π I is defined by Π I := {H(r) ← B + (r) | I ∩ B − (r) = / 0, r ∈ Π}.I is an answer set, sometimes also called stable model, if I satisfies Π I and I is subset-minimal.The completion (Clark, 1978) of Π is the propositional formula comp(Π) := a∈at(Π) a ↔ r∈Π,H(r)=a BF(r) where where, as usual, the conjunction for an empty set is understood as ⊤ and the empty disjunction as ⊥.An interpretation I is a supported model (Apt et al., 1988) of Π, if it is a model of the formula comp(Π).Let S(Π) be the set of all supported models of Π.It holds that AS(Π) ⊆ S(Π) (Marek and Subrahmanian, 1992), but not vice-versa.If Π is tight, then AS(Π) = S(Π) (Fages, 1994).In practice, we use the completion in CNF, thereby introducing auxiliary variables and still preserving the number of supported models.

Example 2
Consider program Π 1 from Example 1, with AS(Π 1 ) = {{a, b}}.For L 1 ⊆ {a, b, ¬c}, we obtain the same answer sets, i.e., AS(Π 1 ) = AS(Π 1 [L 1 ]).However, for any L 2 ⊆ {a, b, ¬c} we obtain Knowledge Compilation and Counting on Formulas in sd-DNNF.Let ϕ be a formula, ϕ is in NNF (negation normal form) if negations (¬) occur only directly in front of variables and the only other operators are conjunction (∧) and disjunction (∨) (Robinson and Voronkov, 2001).NNFs can be represented in terms of rooted directed acyclic graphs (DAGs) where each leaf node is labeled with a literal, and each internal node is labeled with either a conjunction (∧-node) or a disjunction (∨-node).
We use an NNF and its DAG interchangeably.The size of an NNF ϕ, denoted by |ϕ|, is given by the number of edges in its DAG.Formula ϕ is in DNNF, if it is in NNF and it satisfies the decomposability property, that is, for any distinct subformulas ψ i , ψ j in a conjunction ψ = ψ 1 ∧ • • • ∧ ψ n with i = j, we have vars(ψ i ) ∩ vars(ψ j ) = / 0 (Darwiche, 2004).Formula ϕ is in d-DNNF, if it is in DNNF and it satisfies the decision property, that is, disjunctions are of the form ψ = (x ∧ ψ 1 ) ∨ (¬x ∧ ψ 2 ).Note that x does not occur in ψ 1 and ψ 2 because of decomposability.ψ 1 and ψ 2 may be conjunctions.Formula ϕ is in sd-DNNF, if all disjunctions in ψ are smooth, meaning for ψ = ψ 1 ∨ ψ 2 we have vars(ψ 1 ) = vars(ψ 2 ).
Determinism and smoothness permit traversal operations on sd-DNNFs to count models of ϕ in linear time in |ϕ| (Darwiche, 2001).The traversal takes place on the so-called counting graph of an sd-DNNF.The counting graph G(ϕ) is the DAG of ϕ where each node N is additionally labeled by val(N) := 1, if N consists of a literal; labeled by val(N) By val(G(ϕ)) we refer to val(N) for the root N of G(ϕ).Function val can be constructed by traversing G(ϕ) in post-order in polynomial time.
It is well-known that val(G(ϕ)) equals the model count of ϕ.For a set L of literals, counting of ϕ L := ϕ ∧ ℓ∈L ℓ can be carried out by conditioning of ϕ on L (Darwiche, 1999).Therefore, the function val on the counting graph is modified by setting val(N) = 0, if N consists of ℓ and ¬ℓ ∈ L. This corresponds to replacing each literal ℓ of the NNF ϕ by constant ⊥ or ⊤, respectively.From now on, we denote by Φ Π[L] an equivalent sd-DNNF of comp(Π[L]) and its counting graph by

Counting Supported Models
In our applications mentioned in the introduction, we are interested in counting multiple times under assumptions.In other words, we count the total number of answer sets and the number of answer sets under various changing assumptions.Therefore, we extend known techniques from knowledge compilation (Darwiche and Marquis, 2002).
The general outline for a given program Π is as follows: (i) we construct the formula comp(Π) that can (ii) be compiled in a computationally expensive step into a formula Φ comp(Π) in a normal form, so-called sd-DNNF by existing knowledge compilers.Then, (iii) on the sd-DNNF Φ comp(Π) counting can be done in polynomial time in the size of Φ comp(Π) .We can even count under a set L of propositional assumptions by the technique known as conditioning.
However, this approach yields only the number of supported models under assumptions and we overcount compared to the number of answer sets.To this end, in Section 4, (iv) we present a technique to incrementally reduce the overcount.
In the following, we recall how knowledge compilation can be used to count formulas under assumptions by assuming that a formula is in sd-DNNF and constructing a counting graph.
be removed from G(ϕ 1 ) and we obtain ϕ 1 ∧ ¬c = (( From Figure 1, we observe that the model count val(G(ϕ ∧ ¬c)) of formula ϕ ∧ ¬c is 1. △ Using the techniques as described above, we can compile the formula comp(Π) into an sd-DNNF Φ comp(Π) and count the number |S(Π)| of supported models.We illustrate this in the following example.

Counting Supported Models under Assumptions
Since assumptions of formulas and programs behave slightly differently due to the GL reduct, it is not immediately clear that we can use conditioning to obtain the number of supported models of a program under given assumptions.In the following we will show that supported models of Π under assumptions L coincide with models of Φ Π [L] .
Observation 1 Let Π be a program and L assumptions.Then, For any program Π the conditioning (Φ Π ) L on assumptions L allows us to identify supported models of a program Π[L].
Immediately, we obtain that we can count the number of supported models by first compiling the completion into an sd-DNNF and then applying conditioning.For tight programs, this already yields the number of answer sets.

Corollary 1
Let Π be a program and L be assumptions.Then, Example 5 Consider program Π 1 from Example 1, which has two supported models {a, b} and {a, b, c}.Without setting val(c) to 0 in Figure 1, we would obtain 2, which corresponds to these two models.By assumption ¬c, we set val(c) to 0, which results in a total count of 1 as the ∧-node gives only one count in the subgraph.△

Compressing Counting Graphs
When computing the counting graph of the completion of a program Π, in practice, we usually construct a CNF of the completion by introducing so-called nogoods (Gebser et al., 2012) similar 1: initialize array t and traverse nodes N ∈ Φ Π bottom-up such that 2: if N contains a literal ℓ ∈ L(Π) then label N with val(N) else check the number of children of N that are not marked as ignored 5: if N has no remaining children then mark N as ignored 6: else if N has one remaining child C then N ← C and mark N as ignored add N to t 9: remove all nodes marked with ignored from t 10: return t to Tseitin's transformation (Tseytin, 1983).It is well-known that there is a one-to-one correspondence, however, auxiliary variables are introduced, see, e.g., (Kuiter et al., 2023).For counting, the one-to-one correspondence immediately allows to establish a bijection between the models of the CNF and the supported models making it practicable on CNFs.
However, from Corollary 1, we know that the runtime counting models on (G Π ) L depends on the size of Φ Π .In consequence, introducing auxiliary variables affects the runtime of our approach.To this end, we introduce a compressing technique in Algorithm 1 that takes a counting graph G Π and produces a compressed counting graph (CCG) τ(G Π ), thereby removing auxiliary variables that have been introduced by the Tseitin transformation.The algorithm takes as input an sd-DNNF Φ Π , and literals L(Π); and returns the compressed counting graph τ(G Π ).In Line 3, we check whether the literal node consists of an auxiliary variable, and if so, it will be ignored.The case distinction in Lines 5-7 distinguishes how many not ignored children a non-literal node still has.Remember that each non-literal node is either an ∧-node or an ∨-node.In Line 5, the node can be removed, as it has no child.In Line 6, the node needs to be absorbed, as it has only one child meaning that the node ultimately becomes its child.In all other cases (Line 7), the node needs to be evaluated on the CCG t such that the ignored nodes are treated as neutral element of the respective sum or product.Ignored nodes are then removed from t.It remains to show that compressing G Π leaves val unchanged, which is the topic of the following statement and subsequent proof.

Lemma 3.2
Let Π be a program, Φ Π an sd-DNNF of comp(Π) after a transformation that preserves the number of models, but introduces auxiliary variables, and

Proof
Let G Π be the counting graph of an sd-DNNF that is equivalent to the CNF that has been constructed from comp(Π) using a transformation that preserves the number of models, which usually is the Tseitin transformation.We show that the value val(N) of each node N of G Π , which is not removed in τ(G Π ), does not change, since for N and its respective children children(N) in Algorithm 1 we modify only literals that occur in the program Π.By N τ ∈ τ(G Π ) we denote the modified version of N, and by children τ (N) we denote the children of N in τ(G Π ).We distinguish the cases: (a) Assume |children τ (N)| = 0.Then, in Algorithm 1, N will be ignored and thus not belong to τ(G Π ).(b) Assume |children τ (N)| = 1.Then, in Algorithm 1, N will be absorbed by its only child.
Thus, N does not belong to τ(G Π ).(c) Assume |children τ (N)| ≥ 2. Then in Algorithm 1, N will be evaluated on children τ (N), which means N τ will be contained in τ(G Π ).We now need to show that val(N) on children(N) corresponds to val(N) on children τ (N), i.e., val(N) = val(N τ ).By assumption (number of models is preserved), we have a bijection between M(Φ Π ) and S(Π) which ignores auxiliary variables.Therefore, we can simply set the values of children children(N) that have been removed or absorbed due to Cases 2a, 2b, or 2c -as a consequence of removing auxiliary variables -to the corresponding neutral element of the value of N.
i Assume N is an ∧-node.Accordingly, in Algorithm 1, N will be evaluated on children τ (N) such that in the product corresponding to val(N), the value of each removed branch (removed child), due to removing auxiliary variables, corresponds to the neutral element of multiplication, i.e., 1.Therefore, we conclude that val(N) = val(N τ ).ii Assume N is an ∨-node.Again, accordingly, in Algorithm 1, N will be evaluated on children τ (N) such that in the sum corresponding to val(N), the value of each removed branch (removed child), due to removing auxiliary variables, corresponds to the neutral element of addition, i.e., 0. Therefore, val(N) = val(N τ ), which concludes the proof.
Inspecting Algorithm 1, we see that we require two traversals of the original counting graph, one from Lines 3-8 and another one in Line 9 where we remove the nodes that do not belong to the CCG.Runtime follows from the fact that we need to traverse Φ Π twice.

Incremental Counting by Inclusion-Exclusion
In the previous section, we illustrated how counting on tight programs works and introduced a technique to speed up practical counting.To count answer sets of a non-tight program, we need to distinguish supported models from answer sets on τ(G Π ), which can become quite tedious.Therefore, we use the positive dependency graph DP(Π) of Π.A set X ⊆ at(Π) of atoms is an answer set, whenever it can be derived from Π in a finite number of steps.In particular, the mismatch between answer sets and supported models is caused by atoms C ∈ cycles(Π) involved in cycles in DP(Π) that are not supported by atoms from outside the cycle.We call those supporting atoms of C the external support of C. Note that external supports are sets of atoms.However, we can simulate such a set by introducing an auxiliary atom; hence one atom, as in this definition, is sufficient (Gebser et al., 2012).To approach the answer set count of a non-tight program under assumptions, we employ the well-known inclusion-exclusion principle, which is a counting technique to determine the number of elements in a finite union of finite sets X 1 , . . ., X n .Therefore, first the cardinalities of the singletons are summed up.Then, to compensate for potential overcounting, the cardinalities of all intersections of two sets are subtracted.Next, the number of elements that appear in at least three sets are added back, i.e., the cardinality of the intersection of all three sets -to compensate for potential undercounting -and so on.As an example, for three sets X 1 , X 2 , X 3 the procedure can be expressed as This principle can be used to count answer sets via supported model counting.
Next we define a notion that is useful to identify or prune supported models that are not stable.
The unsupported constraints as defined here, (i) are inspired by loop formulas (Lin and Zhao, 2004;Ferraris et al., 2006); and (ii) contain the whole set C, which is slightly weaker than constraints (nogoods) defined in related work (Gebser et al., 2012), but sufficient for characterizing answer sets.
)| by a L d , using the combinatorial principle of inclusion-exclusion as follows: we subtract the number of supported models that are not answer sets under assumptions L with respect to each cycle C ∈ cycles(Π).However, we need to take into account the interaction of cycles and their respective external supports under assumptions L. Thus we enter the first alternation step, where we proceed by adding back , which means that we add back the number of supported models that were mistakenly subtracted from |S(Π[L])| in the previous step, and so on, until we went through all Λ i where 0 ≤ i ≤ d.Note that therefore in total we have d alternations.In general, we show that a L n = |AS(Π[L])| as follows.Theorem 1 Let Π be a program, cycles(Π) = {C 1 , . . .,C n }, and further U := {λ (C 1 ), . . . ,λ (C n )} be the set of all unsupported constraints of Π.Then, for assumptions L, However, this formula then subtracts supported models satisfying both constraints {λ (C ′ ), λ (C ′′ )} with one of the cycles λ (C ′′ ) ∈ U m twice, which require to be added back.Thus, we proceed by adding back supported models satisfying unsupported constraints of C ′ with two other cycles, which again have to be subtracted in the next step.In turn, the application of the inclusion-exclusion principle ensures that Finally, one can count answer sets correctly.

Corollary 3
Let Π be a program, L assumptions, and n = |cycles(Π)|.Then, a L n = |AS(Π[L])|.In fact, we can characterize a L n with respect to alternation depths.If there is no change from one alternation to another, the point is reached where the number of answer sets is obtained, as the following lemma states.
for every 1 ≤ j ≤ i 6: Let Π be a program and L be assumptions.If a L i = a L i+1 for some integer i ≥ 0, then We can observe that therefore no further combination of unsupported constraints with set L of assumptions where we combine unsupported constraints of cycles that occur in subsets of cycles(Π) with cardinality j > i+1 points to any supported model.In other words, we have for all j > i that ∑ Γ∈Λ j (Π) |S(Π[L]) \ S(Π[L ∪ B(Γ)])| = 0, which concludes the proof.
Using our approach on computing a L n , we end up with 2 n (supported model) counting operations where n := |cycles(Π)| on the respective compressed counting graph τ(G Π ), which, since counting is linear in k := |τ(G(Π))|, gives us that incremental answer set counting under assumptions is by 2 n • k exponential in time.However, we can restrict the alternation depth to d such that 0 ≤ d < n in order to stop after Λ d (Π).Then we need to count n times for each cycle and its respective unsupported constraints and another n i times for 1 < i ≤ d, that is, for each number of subsets of cycles and their respective unsupported constraints with cardinality i.These considerations yield the following result.Note that if we choose an even d, we will stop on adding back, potentially overcounting, and otherwise we will stop on subtracting, potentially undercounting.Algorithm 2 ensures that we end on an add-operation to avoid undercounting in Line 2. Furthermore, it uses Lemma 4.2 as a termination criterion in Line 4.
We see that restricting the alternation depth to 1, leads to undercounting.However, not restricting the depth leads to the exact count as:

△
Preprocessing Cycles.When computing the incremental count a L i , we can implement a simple preprocessing step.Recall that an unsatisfiable propositional formula remains unsatisfiable when adding additional clauses (Kleine Büning and Lettmann, 1999).Hence, if the conjunction of an unsupported constraint and assumption leads to an unsatisfiable formula, we can immediately obtain the resulting supported model count.

Empirical Evaluation
To demonstrate the capability of our approach, we implement the functionality into a tool that we call iascar (incremental answer set counter with anytime refinement and counting graph compressor).Our prototypical system is publicly available.1 Below, we outline implementation details and illustrate the results of a series of practical experiments, which aim at evaluating the feasibility of our approach and its limitations.We explain the design of experiments, our expectations, and examine our expectations within a set of instances originating in an AI problem, a prototypical ASP problem, standard combinatorial puzzles, and graph problems.2 Design of Experiments.We design an empirical evaluation to study the questions: 1. Can we obtain sd-DNNFs for supported model counting by modern knowledge compilers?2. Are these resulting sd-DNNFs feasible for our incremental answer set counting? 3. How does incremental counting on sd-DNNFs compare to translating ASP instances into CNFs and run state-of-the-art model counters?4. Since our technique aims at improving counting multiple times and under varying assumptions, do we benefit from the potentially expensive construction of sd-DNNFs when counting multiple times? 5. What are the qualitative effects of the inclusion-exclusion-based approach to reduce the over-counting that initially occurs when only supported models are constructed but reduced gradually?
Implementation Details.Our system iascar is written in Rust and builds upon well-established tools, namely, gringo for constructing ground instances (Gebser et al., 2011), the Aalto ASP Tools for converting extended rules (Bomanson et al., 2016) and constructing Clark's completion (Gebser et al., 2011), and c2d to compile CNFs into a DNNF (Darwiche, 2004;Darwiche, 1999).In more detail, we implement Algorithms 1 and 2, which first construct a CCG and then count based on the inclusion-exclusion technique.We assume the input program to be ground, if not we use gringo to construct a propositional instance (Gebser et al., 2011).To obtain a CCG from a propositional program, we first convert extended rules of the ground input program into normal rules using the tool lp2normal (Bomanson et al., 2016).Then, we construct a positive dependency graph from the propositional program and encode simple cycles, i.e., only the first and last vertex repeat, as unsupported constraints.According to Corollary 3, we need to take all cycles into account to obtain the exact number of answer sets of an instance.Separately, we store the completion of the resulting program as a CNF using lp2sat (Janhunen, 2006).Afterward, we compile the resulting CNF into an (sd-D)NNF by employing c2d (Darwiche, 2004;Darwiche, 1999).
Model Counters for Comparison.Later, we compare our system to existing tools for counting.
Natural approaches for counting are: (a) We employ answer set counters.(b) We enumerate answer sets by a recent answer set solver.(c) Alternatively, we translate the propositional input program into a propositional formula and run state-of-the-art preprocessors and model counters on the resulting formula.We require a one-to-one correspondence between the answer sets and the satisfying assignments for the translation.Unfortunately, existing answer set counters focus on extended functionality like probabilistic reasoning (Fichte et al., 2022c), algebraic semirings (Eiter et al., 2021), or are tailored towards approximate counting (Kabir et al., 2022) or certain structural restrictions of the instance (Fichte et al., 2017).Therefore, we omit tools listed in (a) from an evaluation.For (b), we use the answer set solver clingo (Gebser et al., 2009) to enumerate answer sets.To speed up solving, we do not output the answer sets.Since there have been recent advances on enumerating answer sets (Alviano et al., 2023), we also include the solver wasp, where we state only the number of answer sets and report only one configuration, since we observe no notable difference.For repeated counting with clingo, one could store the enumerated answer sets and implement fast data structures to test whether an element belongs to a set (Bloom, 1970;Weaver et al., 2012) or count (Meel et al., 2018).To our knowledge, there is no implementation that follows this direction and we did not implement it ourselves.For (c), we turn the input program into a propositional program using gringo, convert extended rules (Bomanson et al., 2016) into normal rules (lp2normal), construct Clark's completion (Gebser et al., 2011) (lp2sat), and add level mappings (lp2atomic).Then, we apply bipartition and elimination as a preprocessing step using b+e (Lagniez and Marquis, 2017b) and evaluate leading solvers of the model counting competition (Fichte and Hecher, 2023;Fichte et al., 2021a) using different conceptual techniques.Therefore, we take c2d (Darwiche, 2004), d4 (Lagniez and Marquis, 2017a), and sharpsat-td (Korhonen and Järvisalo, 2021).Each solver counts satisfying assignments on propositional formulas given as CNF.We consider approximate counting (Chakraborty et al., 2014), which is interesting for projected counting or settings where we cannot expect a solution from exact model counters.Since we observe no notable performance gain in this setting, we omit it below.
Platform, Measure, and Restrictions.We evaluated our system on two platforms (a) laptop for a user-tailored evaluation on instances with more detailed interest and (b) a systematic evaluation on a larger set of benchmark instances.For (a), we ran the experiments on an 8-core intel I7-10510U CPU 1.8 GHz with 16 GB of RAM, runnning Manjaro Linux 21.1.1(Kernel 5.10.59-1-MANJARO).For (b), we used a high-performance cluster consisting of 12 nodes.Each node of the cluster is equipped with two Intel Xeon E5-2680v3 CPUs, where each of these 12 physical cores runs at 2.5 GHz clock speed and has access to 64 GB shared RAM.Results are gathered on Linux RHEL 7 powered on kernel 3.10.0-1127.19.1.el7with hyperthreading disabled.Transparent huge pages are set to system default (Fichte et al., 2020).We follow standard guidelines for empirical evaluations (van der Kouwe et al., 2018;Fichte et al., 2021b) and measure runtime using perf and enforce limits using runsolver (Roussel, 2011).We mainly compare wall clock time.Run times larger than 900 seconds count as timeout and main memory (RAM) was restricted to 8 GB.We chose a small timeout due to the interest in fast counting and fast counting multiple times as outlined in the design of experiments.We ran jobs exclusively on one machine, where solvers were executed sequentially with exclusive access and at most four other runs were executed on the same node.
Instances.For our experiment, we select instances that result in varying NNF sizes, CCG sizes, and the number of simple cycles, answer sets, and supported models.We expect prototypical problems for counting multiple times to be found in probabilistic settings.However, this area is entirely unexplored for ASP.Gradually investigating the search space of an ASP instance, so-called navigation is an application for counting multiple times on the same instance under assumptions.Nevertheless, there are no standard ASP benchmark sets and ASP competitions (Gebser et al., 2017;Dodaro et al., 2019) are either tailored for modeling problems or solving decision or optimization problems.Therefore, we consider different types of instances.Set (S1) contains 242 instances that solve a problem in artificial intelligence.Set (S2) consists of 936 instances of a prototypical ASP problem.Set (S3) includes a very small set of instances of combinatorial problems.The instances in sets (S1) and (S2) have been used in previous works on ASP and counting (Eiter et al., 2021;Besin et al., 2021;Hecher, 2022).Set (S1) encodes finding extensions of an argumentation framework (Fichte et al., 2022b;Dvořák et al., 2020;Gaggl et al., 2020).While there have been various iterations of the argumentation competition ICCMA, we focused on instances from 2017 (Gaggl et al., 2020), and encode conflict-free sets of abstract argumentation instances.These instances have a relatively high number of answer sets and are cycle-free.In contrast, the 2019 instances are easy to enumerate (Bistarelli et al., 2020).The 2021 instances have only a relatively small number of solutions (Mailly et al., 2021).The ASP encoding for conflict-free sets originates in the abstract argumentation system ASPARTIX (Dvořák et al., 2020).More insights on counting and abstract argumentation frameworks and their varying semantics are available in the literature (Dewoprabowo et al., 2022).Set (S2) consists of instances that encode a prototypical ASP domain with reachability and use of transitive closure containing cycles.While the previous set can be done by encoding ASP instances into SAT without the use of level mappings, this set provides us with a domain to distinguish the effect of cycles.Reachability on these instances is considered on quite large real-world graphs of public transport networks from all over the world, (Dell et al., 2017).We select graphs that either incorporate no particular means of public transport or all of them.Further, we omit unsatisfiable instances thereof.Set (S3) contains the well-known n-queens problem for n ∈ {8, 10, 12}; a sudoku sub-grid (3x3 grid) that has to be filled uniquely with numbers from 1 to 9; the 3-coloring problem on a graph (3 coloring) and an encoding that ensures arbitrary 2-coloring for the same graph (arb 2 coloring).These instances admit no simple cycles.
Setup.Since instances from the sets (S1) and (S2) contain many instances, we evaluate these on a cluster and summarize the details in Table 1.In addition, we report on interesting instances in more detail in Table 2. There, we omit (S1) due to absence of cycles.For counting under assumptions, we select from the given instance uniform at random three atoms and set them randomly to true or false.By setting few assumptions, we ensure that only few solutions are cut.For considered solvers, we count answer sets and supported models and repeat two times counting under up to three random assumptions.For iascar we run varying alternation depth until we reach a fixed-point as by Lemma 4.2.
Expectations.Before we state the results, we formulate expectations from the design of experiment and our theoretical understanding.), counting answer sets on a translation to SAT (c2d,d4), using incremental answer-set counting (iascar), or using incremental answer-set counting (iascar-d2) of depth two.iascar* and iascar-d2* refer to runs where, regardless of the timeout, a bound (anytime count) was obtained.We omit iascar-d2 due to relevance for (S1) and ( S3).Observations and Results.We summarize our results in Table 1 and Table 2.We exclude (S1) from Table 2 due to absence of cycles.Experimental data and instances are publicly available (Fichte et al., 2023).
(O1): In Table 1 and Table 2, we see that iascar can compute the answer sets fast if the number of cycles is small or only few cycles are present.When taking a look onto Table 2, we see that instances such as 3 coloring or arb 2 coloring can be solved fast despite the high number of solutions.This confirms our Expectation (E1.1).(O2): We observe in Table 1 that while the ASP solver clingo suffers as soon as the number of instances is high, dedicated model counters can compute the number of answer sets quite fast on the considered instances.In fact, the overall time is faster than the overall time for iascar, which confirms our Expectation (E1.2).When inspecting the number of cycles as well, it confirms our Expectation (E2.3).(O3): In Table 1, we can see that iascar spends a notable time during the phase of constructing sd-DNNFs of a CNF if the instance has few or no cycles.Interestingly, in our experiments we have seen that constructing an sd-DNNF of a CNF can vary notably ranging from 0.1s to 472.0s for (S1) and ranges within a few seconds for (S2).
When we encode answer sets instead of supported models into a CNF, we obtain significantly higher runtimes for compiling the CNF into sd-DNNF.In contrast, iascar might allow fast compilation, but can result in extremly high runtimes when applying the inclusion-exclusion principle.This only partially confirms our Expectation (E1.3).Table 2 provides a more detailed observation for selected instances.We see that on smaller instances such as 8 queens, 3x3 grid, or arb 2 coloring, we can compile and count answer sets in reasonable time.Whereas on instances such as nrp hanoi or nrp berkshire we observe a high runtime; in particular, there we see that sd-DNNFs can become quite large.(O4): In Table 2 column T[s], we can see that there are instances where compressing the counting graph can significantly reduce its size.On many instances, we see a reduction by one order, for example, 10 queens by factor 17.1 and 12 queens by 19.3.Still, for 3x3 grid, we see a reduction by 3.7.This confirms Expectation (E2.1), but there we cannot necessarily expect an improvement, which is not unsurprising due to the nature of this simplification step.In fact, compressing instances with a large number of cycles, such as nrp berkshire, is less effective than on those with a small number of cycles, such as nrp kyoto and 12 queens.(O5): By correlating Observation (O3) with column #SC in  2, we can see that the runtime on the illustrated instances depends on both parameters.A medium number of simple cycles and depth effects the runtime; similar to high number of simple cycles and small depth.Still, with a high number of simple cycles and a small depth, we can obtain the count under assumption sufficiently fast.This partially confirms our Expectation (E2.2).Interestingly, the size of the CCG itself has a much less impact than anticipated, see instance 12 queens.(O7): Consider Table 2.The runtime, as stated in column A[s], indicates that we can still obtain a reasonable count for instances, which ran with restricted depth, marked by *; see for example nrp hanoi, nrp aircoach, or nrp berkshire.(O8): Finally, note that in Table 2 there is one instance, namely, nrp autorit, for which we overcounted by 3 when restricting to simple cycles, which confirms Expectation (E3).However, on all other instances, we obtained the exact count.
Summary.The evaluation indicates that our approach clearly pays off on instances containing reasonably many cycles.In particular, we see promising results when counting under assumptions, clearly benefiting from knowledge compilation.Compression of the counting graph works reasonably fast and can significantly reduce its size.Overall, the drawn experiments allowed us to confirm our expectations we stated before running the experiments.However, we see that our approach shows only benefits if the number of cycles is sufficiently small and whenever we are interested in counting multiple times.We expect that additional preprocessing pays off, if we can either exclude cases where there are no answer sets possible or where we can reduce the instance size notably, as with preprocessing of propositional formulas.Further, since knowledge compilation might consume larger parts of our overall runtime, we immediately expect better performance with the availability of improved and optimized knowledge compilers.

Conclusion
We establish a novel technique for counting answer sets under assumptions combining ideas from knowledge compilation and combinatorial solving.Knowledge compilation and known transformations of ASP programs into CNF formulas already provide a basic toolbox for counting answer sets.However, compilations suffer from overhead when constructing CNFs.Our approach is sim-ilar to propagation-based solving when searching for one solution.We construct compilations that allow reasoning for supported models and apply a combinatorial principle to count answer sets.Our approach gradually reduces the over-counting we obtain when considering supported models.Further, we introduce domain-specific simplification techniques for counting graphs.We expect our technique to be useful for navigating answer sets or answering probabilistic questions on ASP programs, requiring repeated counting questions under assumptions.Thereby, we see particular potential of our quantitative technique in the study and analysis of existing solving approaches and heuristics, especially through the lense of answer set navigation, where we expect synergies.For instance, feasible repeated counting might yield useful counting-based metrics in the context of searching diverse answer sets (Böhl et al., 2023;Böhl and Gaggl, 2022).Another interesting application could be to augment visual representations of answer sets (Dachselt et al., 2022;Hahn et al., 2022) with designated quantitative characteristics, such as relative frequencies obtained by repeated counting under assumptions.
For future work, we plan to investigate techniques to reduce the size of compilations for supported models, which can, in fact, already be a bottleneck due to the added clauses modeling the support of an atom.There, domain-specific preprocessing or an alternative compilation could be promising.Furthermore, fast identification of unsatisfiable cases by incremental SAT solving could be interesting to evaluate.From the practical side, it is seems also be interesting whether we can speed up counting by GPUs (Fichte et al., 2021c) or database technology (Fichte et al., 2022e) in the ASP navigation setting.From the theoretical side, questions on the effectiveness of knowledge compilations in ASP might be interesting and similar to considerations for formulas (Darwiche and Marquis, 2002).Finally, we believe that verifiable results would also be interesting when exact bounds are required, similar to techniques that have recently been developed in propositional counting (Fichte et al., 2022d;Beyersdorff et al., 2023;Bryant et al., 2023).
val(N) w.r.t.t and remaining children of N and label N with v 8:

Example 7
Let a ← b, b ← a, and b ← c, ¬d be rules.Then the external support of atoms {a, b}, which are involved in cycles, is {c}.If instead of b ← c, ¬d we use two alternative rules b r ← c, ¬d and b ← b r , we have ES({a, b}) = {b r }. △

Algorithm 2
Incremental Counting by Anytime Refinement In: Program Π; assumptions L; compressed counting graph τ(G Π ); alternation depth d Out: Incremental count a L d 1 Theorem 2 Let Π be a program, L be assumptions, and 0 ≤ d ≤ n with n := |cycles(Π)|.We can compute a L d in time O(m • |τ(G(Π))|) where m = ∑ i≤d n i .
(S1) consists of 242 instances, (S2) of 936 instances, and (S3) of 6 instances.# refers to the number of solved instances within the timeout of 900s.The average time of the compilation phase for solved instances comprises both sd-DNNF[s] (average time for translating into CNF and sd-DNNF compilation) and ccg[s] (average time for counting graph compression and encoding unsupported constraints).a[s] refers to the average runtime of the counting step.#AS contains the count in log 10 notation, which equals the number of answer sets for all solvers except iascar-d2, iascar* and iascar-d2*.(E1.1):When counting multiple times, iascar outperforms existing systems.(E1.2):When counting once, iascar is notably slower due to the overhead caused by compilation and compression.(E1.3):Compiling sd-DNNFs from formulas that encode answer sets takes much longer than when compiling supported models.Most of the time is spend on the compilation for iascar if the number of cycles is small.(E2.1):Compressing the counting graph can significantly reduce its size and works fast.(E2.2):The runtime of iascar depends on the number of cycles and size of the CCG due to the structural parameter of the underlying algorithm.(E2.3):If the instance has few cycles, counting works fast.Otherwise, depth restriction makes our approach utilizable.(E3): There are instances on which simple cycles are not sufficient for counting answer sets.

Table 1 :
Comparing runtimes of different solvers when directly counting answer sets by enumeration (clingo, wasp

Table 2 :
For selected interesting instances from the considered sets, we compare runtimes of iascar for compiling the input program to an NNF when directly counting answer sets (cnf), counting supported models (sup), converging to the answer set count (A) under assumptions with specified alternation depth (d) of several instances with varying numbers of simple cycles (#SC), compressing counting graphs (T), and supported models (#S), sd-DNNF sizes (sd-DNNF size) and CCG sizes (CCG size).Depths marked with * indicate restricting alternation depths to the corresponding value.
Table2, we can see that instances, which can be solved fast, have no simple cycles.This pattern still holds, if we take a look on Table1for more instances.When considering only a few cycles as in iascar-d2, which considers only depth two, we can see that instances for (S2) result in significantly more solved instances, but a high over-count.This matches with our expectation (E2.2) and the knowledge on how CNFs are generated from a program as cycles are a primary source of hardness in ASP.Unsurprisingly, compiling CNFs without level mappings/loop formulas, as stated in column sup[s], works much faster.This is particularly visible for instances nrp hanoi, nrp berkshire, nrp bart, or nrp aircoach.(O6): From columns #SC, depth, and A[s] in Table