A Compositional Atlas for Algebraic Circuits

Authors: benjie  wang
denis  deratani mauá
guy  van den broeck
yoojung  choi
Venue: NeurIPS_cc_2024_Conference
Published: 2024-05-15 21:05:56

Abstract: Circuits based on sum-product structure have become a ubiquitous representation to compactly encode knowledge, from Boolean functions to probability distributions. By imposing constraints on the structure of such circuits, certain inference queries become tractable, such as model counting and most probable configuration. Recent works have explored analyzing probabilistic and causal inference queries as compositions of basic operations to derive tractability conditions. In this paper, we take an algebraic perspective for compositional inference, and show that a large class of queries---including marginal MAP, probabilistic answer set programming inference, and causal backdoor adjustment---correspond to a combination of basic operations over semirings: aggregation, product, and elementwise mapping. Using this framework, we uncover simple and general sufficient conditions for tractable composition of these operations, in terms of circuit properties (e.g., marginal determinism, compatibility) and conditions on the elementwise mappings. Applying our analysis, we derive novel tractability conditions for many such compositional queries. Our results unify tractability conditions for existing problems on circuits, while providing a blueprint for analysing novel compositional inference queries.

Main paper: 
 introduction: 
 Circuit-based representations, such as Boolean circuits, decision diagrams, and arithmetic circuits, are of central importance in many areas of AI and machine learning. For example, a primary means of performing inference in many models, from Bayesian networks [16, 9] to probabilistic programs [20, 24, 26, 43] , is to convert them into equivalent circuits; this is commonly known as knowledge compilation. Inference via knowledge compilation has also been used for many applications in neuro-symbolic AI, such as constrained generation [2, 54] and neural logic programming [34, 28] . Circuits can also be learned as probabilistic generative models directly from data [25, 41, 40, 32] , in which context they are known as probabilistic circuits [11] . Compared with neural generative models, probabilistic circuits enjoy tractable evaluation of inference queries such as marginal probabilities, which has been used for tasks such as fair machine learning [12] and causal reasoning [53, 50, 49] .The key feature of circuits is that they enable one to precisely characterize tractability conditions under which a given inference query can be computed exactly and efficiently, in terms of structural properties of the circuit. One can then enforce these circuit properties when compiling or learning a model to enable tractable inference. For many basic inference queries, such as computing a marginal probability, tractability conditions are well understood [48, 8] . However, for more complex queries, the situation is less clear, and the exercise of deriving tractability conditions for a given query has usually been carried out in an instance-specific manner requiring significant effort. In Figure 1 , we illustrate two such queries. The marginal MAP (MMAP) [13] query takes a probabilistic circuit p and some evidence e and asks for the most likely assignment of a subset of variables. The success probability inference in probabilistic logic programming [6, 45] takes a circuit representation ϕ of a logic program, a weight function ω and some query q, and computes the probability of the query under the program's semantics (MaxEnt, in the example). At first glance, these seem like very different queries, involving different types of input circuits (logical and probabilistic), and different types of computations. However, they share similar algebraic structure: logical and probabilistic circuits can be interpreted as circuits defined over different semirings, while maximization and summation can be viewed as aggregation over different semirings. In this paper, inspired by the compositional atlas for probabilistic circuits [48] , we take a compositional approach to algebraic inference problems, breaking them down into a series of basic operators: aggregation, product, and elementwise mapping. For example, the MMAP and probabilistic logic programming queries involve multiple interleaved aggregations and products, along with one elementwise mapping each. Given a circuit algorithm (and associated tractability condition) for each basic operator, we can reuse these algorithms to construct algorithms for arbitrary compositions. The key challenge is then to check if each intermediate circuit satisfies the requisite tractability conditions.max X Y ∼e p(X, Y ) p(X, Y ) [[Y ∼ e]] ⊗ ⊕ Y τ id ⊕ X X ω(X) Y ∼q ϕ(X,Y ) Y ϕ(X,Y ) ϕ(X, Y ) [[Y ∼ q]] [[•]] ⊕ Y τ -1 ⊗ ⊗ ⊕ Y ω(X) ⊗ ⊕ XOur contributions can be summarized as follows. We introduce a compositional inference framework for algebraic circuits (Section 3) over arbitrary semirings, generalizing existing results on logical [18] and probabilistic [48] circuits. In particular, we provide a language for specifying inference queries involving different semirings as a composition of basic operators (Section 3.1). We then prove sufficient conditions for the tractability of each basic operator (Section 3.2) and novel conditions for composing such operators (Section 3.3). We apply our compositional framework to a number of inference problems (Section 4), showing how our compositional approach leads to more systematic derivation of tractability conditions and algorithms, and in some cases improved complexity analysis.In particular, we discover a tractability hierarchy for inference queries captured under the 2AMC framework [29] , and reduce the complexity of causal backdoor/frontdoor adjustment on probabilistic circuits [38, 49] from quadratic/cubic to linear/quadratic respectively. 
preliminaries: 
 Notation We use capital letters (e.g., X, Y ) to denote variables and lowercase for assignments (values) of those variables (e.g., x, y). We use boldface to denote sets of variables/assignments (e.g., X, y) and write Assign(V ) for the set of all assignments to V . Given a variable assignment v of V , and a subset of variables W ⊆ V , we write v W to denote the assignment of W corresponding to v.Semirings In this paper, we consider inference problems over commutative semirings. Semirings are sets closed w.r.t. operators of addition (⊕) and multiplication (⊗) that satisfy certain properties:Definition 1 (Commutative Semiring). A commutative semiring S is a tuple (S, ⊕, ⊗, 0 S , 1 S ), where ⊕ and ⊗ are associative and commutative binary operators on a set S (called the domain) such that ⊗ distributes over ⊕ (i.e., a ⊗ (b ⊕ c) = (a ⊗ b) ⊕ (a ⊗ c) for all a, b, c ∈ S); 0 S ∈ S is the additive identity (i.e., 0 S ⊕ a = a for all a ∈ S) and annihilates S through multiplication (i.e., 0 S ⊗ a = 0 for all a ∈ S); and 1 S ∈ S is the multiplicative identity (i.e., 1 S ⊗ a = a for all a ∈ S).For example, the probability semiring P = (R ≥0 , +, •, 0, 1) employs standard addition and multiplication (⊕ = + and ⊗ = •) over the non-negative reals, the (max, •) semiring M = (R ≥0 , max, •, 0, 1) replaces addition with maximization, while the Boolean semiring B = ({⊥, ⊤}, ∨, ∧, ⊥, ⊤) employs disjunction and conjunction operators (⊕ = ∨ and ⊗ = ∧) over truth values.Algebraic Circuits We now define the concept of an algebraic circuit, which are computational graph-based representations of functions taking values in an arbitrary semiring. Definition 2 (Algebraic Circuit). Given a semiring S = (S, ⊕, ⊗, 0 S , 1 S ), an algebraic circuit C over variables V is a rooted directed acyclic graph (DAG), whose nodes α have the following syntax:α ::= l | + k i=1 α i | × k i=1 α i, where α i ∈ C are circuit nodes, k ∈ N >0 and l : Assign(W ) → S is a function over a (possibly empty) subset W ⊆ V of variables, called its scope. That is, each circuit node may be an input (l), sum (+), or a product (×). The scope of any internal node is defined to be vars(α) := ∪ k i=1 vars(α i ). Each node α represents a function p α taking values in S, defined recursively by: p α (w) ::= l(w) if α = l, p α (w) ::= ⊕ k i=1 p αi (w) if α = + k i=1 α i , and p α (w) ::= ⊗ k i=1 p αi (w) if × k i=1 α i , where W is the scope of α. The function p C represented by the circuit is defined to be the function of the root node. The size |C| of a circuit is defined to be the number of edges in the DAG.For simplicity, we will restrict to circuits with binary products (i.e. k = 2 for products); this can be enforced with at most a linear increase in size. Prominent examples of algebraic circuits include negation normal forms (NNF) and binary decision diagrams [4] -which are over the Boolean semiring and represent Boolean functions-and probabilistic circuits [11] -which are over the probabilistic semiring and represent probability distributions. 1 By imposing simple restrictions on the circuit, which we call circuit properties, various inference queries that are computationally hard in general become tractable. In particular, smoothness and decomposability ensure tractable marginal inference: Definition 3 (Smoothness, Decomposability). A circuit is smooth if for every sum node α = + i α i , its children have the same scope: ∀i, j, vars(α i ) = vars(α j ). A circuit is decomposable if for every product node α = α 1 × α 2 , its children have disjoint scopes: vars(α 1 ) ∩ vars(α 2 ) = ∅.Aside from the scopes of circuit nodes, we can also specify properties relating to their supports [11] : Definition 4 (X-Support). Given a partition (X, Y ) of variables V and a node α in circuit C, the X-support of α is the projection of its support on X:supp X (α) = {x ∈ Assign(X ∩ vars(α)) : ∃y ∈ Assign(vars(α) \ X) s.t. p α (x, y) ̸ = 0 S }.Definition 5 (X-Determinism). Given a circuit C and a partition (X, Y ) of V , we say that C is X-deterministic if for all sum nodes α = + k i=1 α i , either:(i) vars(α) ∩ X = ∅; or (ii) supp X (α i ) ∩ supp X (α j ) = ∅ for all i ̸ = j.X-determinism refers to a family of properties indexed by sets X. In particular V -determinism is usually referred to simply as determinism. Note that, as defined, scope and support, and thus these circuit properties, apply to any semiring: the scope only depends on the variable decomposition of the circuit, while the support only refers to scope and the semiring additive identity 0 S . Figure 2a shows a simple example of a smooth, decomposable, and deterministic circuit that is not X-deterministic, while Figure 2b shows a smooth, decomposable, and {X 1 , X 2 }-deterministic circuit. 
compositional inference: a unifying approach: 
 Many inference problems can be written as compositions of basic operators, which take as input one or more functions and output another function. For example, the marginal MAP query on probability distributions max x y p(x, y) is a composition of the and max operators. Similarly, for Boolean functions ϕ, ψ, the query x ∃y. ϕ(x, y) ∧ ψ(x, y) composes the , ∃ and ∧ operators. Although these queries appear to involve four different operators, three of them ( , max, ∃) can viewed as an aggregation operation over different semirings. Thus, we begin this section by consolidating to a simple set of three operators applicable to functions taking values in some semiring: namely, aggregation, product, and elementwise mapping (Section 3.1).(a) A Boolean circuit that is smooth, decomposable, deterministic, but not X-deterministic.× + + × × × × 1 X1=1 1 Y1=1 1 X1=0 1 Y1=0 1 X2=1 1 Y2=1 1 X2=0 1 Y2=0(b) A probabilistic circuit that is smooth, decomposable, and X-deterministic. Equipped with this language for specifiying compositional inference queries, we then move on to analyzing their tractability when the input functions are given as circuits. The thesis of this paper is that algebraic structure is often the right level of abstraction to derive useful sufficient (and sometimes necessary) conditions for tractability. We firstly show tractability conditions of each of the basic operators (Section 3.2), before deriving composability conditions that show how circuit properties are maintained through operators (Section 3.3). This enables us to systematically derive conditions for the input circuits that enable efficient computation of a compositional inference query. Algorithms and detailed proofs of all theorems can be found in Appendix A.Aggregation Given a function f :Assign(V ) → S, aggregating f over W ⊆ V returns the function f ′ : Assign(Z) → S for Z = V \ W defined by f ′ (z) := w f (z, w).For example, aggregation corresponds to forgetting variables W in the Boolean semiring, marginalizing out W in the probability semiring, and maximizing over assignments in the (max, •) semiring. Next, some queries, such as divergence measures between probability distributions, take two functions as inputs, and many others involve combining two or more intermediate results, as is the case in probabilistic answer set programming inference and causal backdoor/frontdoor queries. We define the product operator to encapsulate such "combination" of functions in general.Product Given two functions f : Assign(W ) → S and f ′ : Assign(W ′ ) → S, the product of f andf ′ is a function f ′′ : Assign(V ) → S, where V = W ∪W ′ , defined by f ′′ (v) := f (v W )⊗f ′ (v W ′ ).For example, a product corresponds to the conjoin operator ∧ in the Boolean semiring, and standard multiplication • in the probability semiring. Lastly, we introduce the elementwise mapping operator, defined by a mapping τ from a semiring to a (possibly different) semiring. When applied to a function f , it returns the function composition τ • f . This is the key piece that distinguishes our framework from prior analysis of sum-of-product queries over specific semirings, allowing us to express queries such as causal inference and probabilistic logic programming inference under the same framework.Elementwise Mapping Given a function f : Assign(V ) → S and a mapping τ : S → S ′ from semiring S to S ′ satisfying τ (0 S ) = 0 S ′ , an elementwise mapping of f by τ results in a functionf ′ : Assign(V ) → S ′ defined by f ′ (v) := τ (f (v)). 2In practice, we use elementwise mappings as an abstraction predominantly for two purposes. The first is for switching between semirings, while the second is to map between elements of the same semiring. For the former, one of the most important elementwise mappings we will consider is the support mapping, which maps between any two semirings as follows.Definition 6 (Support Mapping). Given a source semiring S and a target semiring S ′ , the support mapping• S→S ′ is defined as: a S→S ′ = 0 S ′ if a = 0 S ; a S→S ′ = 1 S ′ otherwise.In particular we will often use the source semiring S = B, in which case the support mapping maps ⊥ to the 0 S ′ and ⊤ to the 1 S ′ in the target semiring. This is useful for encoding a logical function for inference in another semiring, e.g. probabilistic inference in the probabilistic semiring.Example 1 (Marginal MAP). Suppose that we are given a Boolean formula ϕ(X, Y ) and a weight function w : Assign(X ∪ Y ) → R ≥0 . The marginal MAP query for variables X is defined byMMAP(ϕ, ω) = max x y ϕ(x, y) • ω(x, y) ,where we interpret ⊤ as 1 and ⊥ as 0. We can break this down into a compositional query as follows:x τ id,P→M y ϕ(x, y) B→P ⊗ ω(x, y) .The support mapping ensures ϕ and ω are both functions over the probabilistic semiring, so that we can apply the product operation. Notice also the inclusion of an identity mapping τ id,P→M from the probability to the (max, •) semiring defined by τ id,P→M (x) = x for all x ∈ R ≥0 . While differentiating between semirings over the same domain may seem superfluous, the explicit identity operator will become important when we analyze the tractability of these compositions on circuits.We now consider the tractability of applying each basic operation to circuits: that is, computing a circuit whose function corresponds to the result of applying the operation to the functions given by the input circuit(s). First, it is well known that forgetting and marginalization of any subset of variables can be performed in polynomial time if the input circuits in the respective semirings (NNF and PC) are smooth and decomposable [18, 11] . This can be generalized to arbitrary semirings: Theorem 1 (Tractable Aggregation). Let C be a smooth and decomposable circuit representing a function p : Assign(V ) → S. Then for any W ⊆ V , it is possible to compute the aggregate as a smooth and decomposable circuit C ′ (i.e., p C ′ (Z) = w p C (Z, w)) in O(|C|) time and space.Next, let us consider the product operator. In the Boolean circuits literature, it is well known that the conjoin operator can be applied tractably if the circuits both follow a common structure known as a vtree [17] . In [48] a more general property known as compatibility was introduced that directly specifies conditions with respect to two (probabilistic) circuits, without reference to a vtree. We now define a generalization of this property (X-compatibility) and also identify a new condition (X-support-compatibility) that enables tractable products. Definition 7 (X-Compatibility). Given two smooth and decomposable circuits C, C ′ over variables V , V ′ respectively, and a variable set X ⊆ V ∩ V ′ , we say that C, C ′ are X-compatible if for everyproduct node α = α 1 × α 2 ∈ C and α ′ = α ′ 1 × α ′ 2 ∈ C ′ such that vars(α) ∩ X = vars(α ′) ∩ X, the scope is partitioned in the same way, i.e. vars(α 1 ) ∩ X = vars(α ′ 1 ) ∩ X and vars(α 2 ) ∩ X = vars(α ′2 ) ∩ X. We say that C, C ′ are compatible if they are (V ∩ V ′ )-compatible.Intuitively, compatibility states that the scopes of the circuits decompose in the same way at product nodes. Compatibility of two circuits suffices to be able to tractably compute their product: Theorem 2 (Tractable Product -Compatibility). Let C, C ′ be compatible circuits over variables V , V ′ , respectively, and the same semiring. Then it is possible to compute their product as a circuit C compatible with them (i.e., pC ′′ (V ∪ V ′ ) = p C (V ) ⊗ p C ′ (V ′ )) in O(|C||C ′ |) time and space.We remark that if we are given a fully factorized function f (V ) = Vi∈V f i (V i ), this can be arranged as a circuit (series of binary products) compatible with any other decomposable circuit; thus, we say this type of function is omni-compatible. We also say that a circuit is structured decomposable if it is compatible with itself. Now, our more general definition of X-compatibility states that the scopes of the circuits restricted to X decompose in the same way at product nodes. This will be important when we consider composing products with other operators, such as aggregation. The following result shows that compatibility w.r.t. a subset is a weaker condition: Proposition 1 (Properties of X-Compatibility). If two circuits C, C ′ are X-compatible, then they are X ′ -compatible for any subset X ′ ⊆ X.Compatibility is a sufficient but not necessary condition for tractable products; it is also known that some circuits can be multiplied with themselves in linear time, even when they are not structured decomposable [48, 27] . We formalize this idea with a new property which we call support-compatibility. Definition 8 (X-Support Compatibility). Given two smooth and decomposable circuits C, C ′ over variables V , V ′ respectively, and a set of variables X ⊆ V ∩ V ′ , let C[X], C ′ [X] be the DAGs obtained by restricting to nodes with scope overlapping with X. We say that C, C ′ are X-supportcompatible if there is an isomorphism ι between C[X], C ′ [X] such that: (i) for any node α ∈ C[X], vars(α) ∩ X = vars(ι(α)) ∩ X; (ii) for any sum node α ∈ C[X], supp X (α i ) ∩ supp X (ι(α j )) = ∅ whenever i ̸ = j. We say that C, C ′ are support-compatible if they are (V ∩ V ′ )-support-compatible.To unpack this definition, we note that any smooth, decomposable, and X-deterministic circuit is X-support-compatible with itself, with the obvious isomorphism. However, this property is more general in that it allows for circuits over different sets of variables and does not require that the nodes represent exactly the same function; merely that the sum nodes have "compatible" support decompositions. As we will later see, the significance of this property is that it can be often maintained through applications of operators, making it useful for compositions. Theorem 3 (Tractable Product -Support Compatibility). Let C, C ′ be support-compatible circuits over variables V , V ′ , respectively, and the same semiring. Then, given the isomorphism ι, it is possible to compute their product as a smooth and decomposable circuit C ′′ support-compatible with them (i.e., pC ′′ (V ∪ V ′ ) = p C (V ) ⊗ p C ′ (V ′ )) in O(max(|C|, |C ′ |)) time and space.We now examine the tractability of general elementwise mappings τ : S → S ′ on a circuit C. It is tempting here to simply construct a new circuit C ′ over the semiring S ′ with the same structure as C, and replace each input function l in the circuit with τ (l). However, the resulting circuit p C ′ (V ) is not guaranteed to correctly compute τ (p C (V )) in general. For example, consider the support mapping• B→S -which maps ⊥ to 0 S and ⊤ to 1 S -for the probability semiring S = (R ≥0 , +, •, 0, 1). Then the transformation of the smooth and decomposable circuit C = X ∨X produces C ′ = 1 X=1 +1 X=1 , which evaluates to p C ′ (X = 1) = 2 whereas τ (p C (X = 1)) = 1. In order for this simple algorithm to be correct, we need to impose certain conditions on the elementwise mapping τ and/or the circuit C it is being applied to.Theorem 4 (Tractable Mapping). Let C be a smooth and decomposable circuit over semiring S, and τ : S → S ′ a mapping such that τ (0 S ) = 0 S ′ . Then it is possible to compute the mapping of C by τ as a smooth and decomposable circuit C ′ (i.e., p C ′ (V ) = τ (p C (V ))) in O(|C|) time and space if τ distributes over sums and over products. τ distributes over products if: either (Multiplicative) τ is an multiplicative homomorphism, i.e. τ (a⊗b) = τ (a)⊗τ (b); or (Prod 0/1) τ (1 S ) = 1 S ′ , and for all product nodes α = α 1 ×α 2 ∈ C, and for every value v ∈ Assign(vars(α)), either p α1 (v vars(α1) ) ∈ {0 S , 1 S } or p α2 (v vars(α2) ) ∈ {0 S , 1 S }.We can apply Theorem 4 to immediately derive the following property of support mappings: Corollary 1 (Support Mapping). Given a circuit C over a semiring S and any target semiring S ′ , a circuit representing p C S→S ′ can be computed tractably if(i) S satisfies a ⊕ b = 0 S =⇒ a = b = 0 S and S ′ is idempotent (i.e., 1 S ′ ⊕ 1 S ′ = 1 S ′ ), or (ii) C is deterministic.Proof. First note that • S→S ′ satisfies (Multiplicative), and thus distributes over products.If (i) holds, consider a ⊕ b S→S ′ . If a = b = 0 S , then this is equal to 0 S S→S ′ = a S→S ′ + b S→S ′ = 0 S ′ ; otherwise a, b, a ⊕ b ̸ = 0 S and a ⊕ b S→S ′ = a S→S ′ ⊕ b S→S ′ = 1 S ′ (by idempotence of S ′ ).Thus • S→S ′ satisfies (Additive). Alternatively, if (ii) holds, then (Det) holds. In either case • S→S ′ distributes over sums in the circuit.The following examples illustrate the generality of elementwise mappings and Theorem 4: Example 2 (Partition Function and MPE). Given a probability distribution p(V ), consider the task of computing the partition function v p(v) and MPE max v p(v). These can be viewed as aggregations over the probability and (max, •) semirings respectively.p is often either a probabilistic circuit C prob , or a combination of a Boolean circuit C bool and weights w (in weighted model counting). In the former case, the partition function is tractable because the circuit is already over the probability semiring, while in the latter case, MPE is tractable because the S ′ = (max, •) semiring is idempotent so C bool B→S ′ is tractable. On the other hand, the partition Table 1 : Tractability Conditions for Operations on Algebraic Circuits. Sm: Smoothness, Dec: Decomposability; X-Det(erminism), X-Cmp: X-Compatibility, X-SCmp: X-Support-Compatibility.If the Input Circuit(s) are ... Conditions X-Det X-Cmp w/ C other X-SCmp w/ C other Complexity Then the Output Circuit is ... (A.4) Aggr. (W ) Sm, Dec X-Det if W ∩X = ∅ X-Cmp w/ C other if W ∩X = ∅ X-SCmp w/ C other if W ∩X = ∅ O(|C|) (A.1) Product Cmp X-Det X-Cmp w/ C other N/A O(|C||C ′ |) (A.2.1) SCmp X-Det X-Cmp w/ C other X-SCmp w/ C other O(max(|C|, |C ′ |)) (A.2.2Sm, Dec, (Add/Det), (Mult/Prod01)X-Det X-Cmp w/ C other X-SCmp w/ C other O(|C|) (A.3)function for Boolean circuits and MPE for PCs require determinism for the conditions of Theorem 4 to hold; in fact, these problems are known to be NP-hard without determinism [18, 39] .Example 3 (Power Function in Probability Semiring). For the probability semiringS = S ′ = (R ≥0 , +, •, 0, 1), consider the power function τ β (a) := a β if a ̸ = 0 0 if a = 0for some β ∈ R. This mapping satisfies (Multiplicative), and is tractable if we enforce (Det) on the circuit.It is worth noting that semiring homomorphisms (i.e. additive and multiplicative) are always tractable.In the case when S = S ′ = P, it was shown in [48] that the only such mapping is the identity function. However this is not the case for other semirings: the power function τ β is an example in the (max, •) semiring. To summarize, we have shown sufficient tractability conditions for aggeregation, products, and elementwise mappings. Notice that the conditions for aggregation and products only depend on variable scopes and supports, and as such apply to any semiring; in contrast, for elementwise mappings, we take advantage of specific properties of the semiring(s) in question.We now analyze compositions of these basic operators. As such, we need to consider not only circuit properties that enable tractability, but how these properties are maintained through each operator, so that the output circuit can be used as input to another operator. We call these composability conditions. In all cases, the output circuit is smooth and decomposable. Thus, we focus on the properties of X-determinism, X-compatibility, and X-support-compatibility. We emphasize that these are not singular properties, but rather families of properties indexed by a variable set X. We present the intuitive ideas behind our results below, while deferring full proofs to the Appendix. Theorem 5 (Composability Conditions). The results in Table 1 hold.X-determinism Intuitively, X-determinism is maintained through products because the resulting sum nodes partition the X-support in a "finer" way to the original circuits, and through elementwise mappings since they do not expand the support of any node (since τ (0 S ) = 0 S ′ ). For aggregation, the X-support is maintained if aggregation does not occur over any of the variables in X.X-compatibility Here, we are interested in the following question: if the input circuit(s) to some operator are X-compatible with some other circuit C other for any fixed X, is the same true of the output of the operator? X-compatibility with C other is maintained through aggregation because it weakens the condition (by Proposition 1) and through elementwise mapping as it does not change variable scopes. As for taking the product of circuits, the output circuit will maintain similar variable partitionings at products, such that it remains X-compatible with C other . Notably, this result does not hold for compatibility where the scope X may be different for each pair of circuits under consideration; we show a counterexample in Example 4 in the Appendix.X-support-compatibility X-support-compatibility is maintained through elementwise mappings and aggregation (except on X) for similar reasons to X-determinism. For products, the result retains a similar X-support structure, so X-support compatibility is maintained.We conclude by remarking that, once we determine that a compositional query is tractable, then one immediately obtains a correct algorithm for computing the query by application of the generic 2AMCPASP (Max-Credal) * Sm, Dec, X-Det O(|C|) (B.1.2) PASP (MaxEnt) * , MMAP Sm, Dec, Det, X-Det O(|C|) (B.1.1) SDP * Sm, Dec, Det, X-Det, X-First O(|C|) (B.1.3) Causal Inference Backdoor * Sm, Dec, SD, (X ∪ Z)-Det O(|C| 2 ) (B.2.1) Sm, Dec, Z-Det, (X ∪ Z)-Det O(|C|) (B.2.1) Frontdoor * Sm, Dec, SD, X-Det, (X ∪ Z)-Det O(|C| 2 ) (B.2.2) Other MFE * Sm, Dec, H-Det, I --Det, (H ∪ I -)-Det O(|C|) (B.3.1) Reverse-MAP Sm, Dec, X-Det O(|C|) (B.3.2)algorithms for aggregation, product, and elementwise mapping (see Appendix A). An upper bound on the complexity (attained by the algorithm) is also given by considering the complexities of each individual operator; in particular, the algorithm is polytime for a bounded number of operators. 
case studies: 
 In this section, we apply our compositional framework to analyze the tractability of several different problems involving circuits found in the literature (Table 2 ). Some of the results are known, but can now be cast in a general framework (with often simpler proofs). We also present new results, deriving tractability conditions that are less restrictive than reported in existing literature. Theorem 6 (Tractability of Compositional Queries). The results in Table 2 hold.In algebraic model counting [30] (a generalization of weighted model counting), one is given a Boolean function ϕ(V ), and a fully-factorized labeling function ω(V ) = Vi∈V ω i (V i ) in some semiring S, and the goal is to aggregate these labels for all satisfying assignments of ϕ. This can be easily cast in our framework as v (ϕ(v)) B→S ⊗ ω(v) . Here, the support mapping • B→S transfers the Boolean function to the semiring S over which aggregation occurs. Assuming that ϕ(V ) is given as a smooth and decomposable Boolean circuit (DNNF), then by Corollary 1 AMC is tractable if S is idempotent or if the circuit is additionally deterministic (note that ω(V ) is omni-compatible, so the product is tractable); this matches the results of [30] .2AMC A recent generalization of algebraic model counting is the 2AMC (second-level algebraic model counting) problem [29] , which encompasses a number of important bilevel inference problems such as marginal MAP and inference in probabilistic answer set programs. Given a partition of the variables V = (X, Y ), a Boolean function ϕ(X, Y ), outer and inner semirings S X , S Y , labelingfunctions ω Y (Y ) = Yi∈Y ω Y ,i (Y i ) over S Y and ω X (X) = Xi∈X ω X,i (X i ) over S X, and an elementwise mapping τ S Y →S X : S Y → S X , the 2AMC problem is given by:EQUATIONTo tackle this type of bilevel inference problem, [29] identified a circuit property called X-firstness. Definition 9 (X-Firstness). Suppose C is a circuit over variables V and (X, Y ) a partition of V . We say that a node α ∈ C is X-only if vars(α) ⊆ X, Y -only if vars(α) ⊆ Y , and mixed otherwise. Then we say that C is X-first if for all product nodes α = α 1 × α 2 , we have that either: (i) each α i is X-only or Y -only; (ii) or exactly one α i is mixed, and the other is X-only.It was stated in [29] that smoothness, decomposability, determinism, and X-firstness suffice to ensure tractable computation of 2AMC problems, by simply evaluating the circuit in the given semirings (caching values if necessary). We now show that this is neither sufficient nor necessary in general. To build intuition, consider the simple NNF circuit ϕ(X, Y ) = (X ∧ Y ) ∨ (X ∧ ¬Y ). Note that ϕ trivially satisfies X-firstness and is smooth, decomposable, and deterministic. Let S be the probability semiring, S ′ be the (max, •)-semiring, labeling functions be ω(y) = ω(¬y) = 1, ∨ ∧ ∧ X Y ¬Y (a) Boolean circuit ϕ(X, Y ) + × × X 1 1 (b) Inner semiring evaluation max × × 1 1 1(c) Outer semiring evaluation Figure 3 : Failure case of 2AMC algorithm on smooth, decomposable, X-first circuit.ω ′ (x) = ω ′ (¬x) = 1, and the mapping function be the identity τ (a) = a. Then, noting that the labels are the multiplicative identity 1, the 2AMC value ismax X τ ( Y ϕ(X, Y ) B→S ) = max τ ( ϕ(x, y) B→S + ϕ(x, ¬y) B→S ), τ ( ϕ(¬x, y) B→S + ϕ(¬x, ¬y) B→S ) = max τ (1 + 1), τ (0) = 2.On the other hand, the algorithm of [29] returns the value 2AMC = 1, as shown in Figure 3 . This is not just a flaw in the specific evaluation algorithm, but rather a provable intractability of the problem given these properties: Theorem 7 (Hardness of 2AMC with X-firstness). 2AMC is #P-hard, even for circuits that are smooth, decomposable, deterministic, and X-first, and a constant-time elementwise mapping.Analyzing using our compositional framework, the issue is that the tractability conditions for τ do not hold; whilst the Boolean circuit is deterministic, this is not true once Y is aggregated. In fact, we show that also enforcing X-determinism suffices to tractably compute arbitrary 2AMC instances. Theorem 8 (Tractability Conditions for 2AMC). Every 2AMC instance is tractable in O(|C|) time for Boolean circuits that are smooth, decomposable, deterministic, X-first, and X-deterministic.Proof sketch. The key point to notice is that the elementwise mapping relative to the transformation of inner to outer semiring operates over an aggregation of an X-first and X-deterministic circuit, obtained by the product of a Boolean function (mapped to the inner semiring by a support mapping) and a weight function of Y . Hence, it satisfies (Det) and (Prod 0/1): all of the X-only children of a product node are 0/1 valued (in the inner semiring).For specific instances of 2AMC, depending on the semirings S, S ′ and mapping function τ , we also find that it is possible to remove the requirement of X-firstness or determinism, as we summarize in Table 2 . One might thus wonder if there is a difference in terms of compactness between requiring X-determinism and X-firstness, as opposed to X-determinism alone. For example, for sentential decision diagrams (SDD) [17] , a popular knowledge compilation target, these notions coincide: a SDD is X-deterministic iff it is X-first (in which context this property is known as X-constrainedness [37, 22] ). However, as shown in Figure 2b , there exist X-deterministic but not X-first circuits. We now show that X-deterministic circuits can be exponentially more succinct than X-deterministic circuits that are additionally X-first, as the size of X grows. 3Theorem 9 (Exponential Separation). Given sets of variables X = {X 1 , ..., X n }, Y = {Y 1 , ..., Y n }, there exists a smooth, decomposable and X-deterministic circuit C of size poly(n) such that the smallest smooth, decomposable, andX-first circuit C ′ such that p C ≡ p C ′ has size 2 Ω(n) .Thus, to summarize, some instances of 2AMC can be solved efficiently when ϕ is smooth, decomposable and X-deterministic. A larger number of instances can be solved when additionally, ϕ is deterministic; and all 2AMC problems are tractable if we also impose X-firstness.In causal inference, one is often interested in computing interventional distributions, denoted using the do(•) operator, as a function of the observed distribution p. This function depends on the causal graph linking the variables, and can be derived using the do-calculus [38] . For example, the well-known backdoor and frontdoor graphs induce the following formulae:EQUATIONEQUATIONAssuming that the observed joint distribution p(X, Y , Z) is given as a probabilistic circuit C, we consider the problem of obtaining a probabilistic circuit C ′ over variables X ∪ Y representing p(Y |do(X)). Tractability conditions for the backdoor/frontdoor cases were derived by [49] , with quadratic/cubic complexity respectively. However, we observe that in some cases we can avoid the requirement of structured decomposability and/or obtain reduced complexity relative to their findings.In the backdoor case, it is known that structured decomposability and (X ∪ Z)-determinism suffices for a quadratic time algorithm. This can be seen by decomposing into a compositional query:EQUATIONwhere V = (X, Y , Z), andτ -1 (a) = a -1 if a ̸ = 0 0 if a = 0. Assuming (X ∪ Z)-determinism and structured decomposability, then τ -1 y p(V ) is tractable by (Det) and (Multiplicative), the product p(V ) ⊗ τ -1 y p(V ) by support-compatibility, and the final product by compatibility. However, if we additionally have Z-determinism, then the final product becomes tractable by support compatibility. This has linear rather than quadratic complexity, and does not require the circuit to be structured decomposable. In the frontdoor case, [49] showed that X-determinism, (X ∪ Z)determinism, and structured decomposability suffices for cubic complexity. However, we note that under such conditions, the inner product p(X ′ ) ⊗ p(Y |X ′ , Z) is tractable by support-compatibility. As such, the complexity of this query is actually quadratic rather than cubic as previously shown. We summarize our findings in Table 2 and refer the reader to the Appendix for full proofs. 
related work: 
 Our work builds upon the observation that many inference problems can be characterized as a composition of basic operators. Prior works have considered compositional inference for circuits in the Boolean [18] and probabilistic semirings [48, 49] , deriving tractability conditions for operators specific to these semirings. Aside from generalizing to arbitrary semirings, we also introduce extended composability conditions that enable interleaving of aggregation, products, and mappings. Meanwhile, algebraic model counting [30] deals (implicitly) with mappings from the Boolean semiring to an arbitrary semiring, but does not consider compositional queries. Closest to our work, [29] consider a generalization of algebraic model counting that allows for an additional semiring translation; however, this still assumes input Boolean circuits and has incomplete tractability characterizations. Our framework resolves these limitations, permitting arbitrary compositional queries over semirings.Many works have considered (unbounded) sums-of-products queries on arbitrary semirings [21, 5, 1, 23] , encompassing many important problems such as constraint satisfaction problems [7] , graphical model inference [55] , and database queries [52] , which are often computationally hard in the worstcase. Algorithms for such queries often utilize compact intermediate representations and/or assume compact input representations, such as circuits [35, 17, 36, 3] . Our framework focuses on queries where the number of operators is bounded, and characterizes conditions under which inference is tractable in polynomial time. It also includes elementwise mappings as a key additional abstraction that can be used to express queries involving more than sums and products. 
conclusion: 
 In summary, we have introduced a framework for analysing compositional inference problems on circuits, based on algebraic structure. In doing so, we were able to derive new tractability conditions and simplified algorithms for a number of existing problems, including 2AMC and causal inference. Our framework focuses on simple and composable sufficient tractability conditions for aggregations, products and elementwise mappings operators; a limitation of this generality is these conditions may not be necessary for specific queries on specific semirings. Our work motivates the development of knowledge compilation and learning algorithms that target the requisite circuit properties, such as X-determinism. Finally, while we focus on exact inference, for many problems (e.g. marginal MAP) approximate algorithms exist and are of significant interest; an interesting direction for future work is to investigate if these can be also be generalized using the compositional approach. ) if α is product else NEWNODE(⊕ k i=1 p AGG(αi;W ) ) else if α is product or sum node and W ⊂ vars(α) then return × k i=1 AGG(α i ; W ∩ vars(α i )) if α is product else + k i=1 AGG(α i ; W ) Algorithm 2: PROD-CMP Input: Compatible algebraic circuits C(V ), C ′ (V ′ ); nodes α ∈ C, α ′ ∈ C ′ s.t. vars(α) ∩ (V ∩ V ′ ) = vars(α ′ ) ∩ (V ∩ V ′ ) Output: Node encoding p C (V ) ⊗ p C ′ (V ′ ) if vars(α) ∩ vars(α ′ ) = ∅ then return α × α ′ else if α is a product or input node and α ′ = + k ′ j=1 is a sum node then return + k ′ j=1 PROD-CMP(α, α ′ j ) else if α, α ′ are input nodes then return PROD-INPUT(α, α ′ ) else if α = α 1 × α 2 , α ′ = α ′ 1 × α ′ 2 are product nodes then return PROD-CMP(α 1 , α ′ 1 ) × PROD-CMP(α 2 , α ′ 2 ) else if α = + k i=1 α i , α ′ = + k ′ j=1 α ′ j are sum nodes then return + k i=1 + k ′ j=1 PROD-CMP(α i , α ′ j ) 
experiments compute resources: 
 Question: For each experiment, does the paper provide sufficient information on the computer resources (type of compute workers, memory, time of execution) needed to reproduce the experiments?Answer: [NA] Justification: This paper does not contain experiments.Guidelines:• The answer NA means that the paper does not include experiments.• The paper should indicate the type of compute workers CPU or GPU, internal cluster, or cloud provider, including relevant memory and storage. • The paper should provide the amount of compute required for each of the individual experimental runs as well as estimate the total compute. • The paper should disclose whether the full research project required more compute than the experiments reported in the paper (e.g., preliminary or failed experiments that didn't make it into the paper). Guidelines:• The answer NA means that the authors have not reviewed the NeurIPS Code of Ethics.• If the authors answer No, they should explain the special circumstances that require a deviation from the Code of Ethics. • The authors should make sure to preserve anonymity (e.g., if there is a special consideration due to laws or regulations in their jurisdiction). 
broader impacts: 
 Question: Does the paper discuss both potential positive societal impacts and negative societal impacts of the work performed?Answer: [No] Justification: This paper presents foundational research that is not tied to any particular application/deployment; there are no particular societal impacts that we feel need to be highlighted.Guidelines:• The answer NA means that there is no societal impact of the work performed.• If the authors answer NA or No, they should explain why their work has no societal impact or why the paper does not address societal impact. • Examples of negative societal impacts include potential malicious or unintended uses (e.g., disinformation, generating fake profiles, surveillance), fairness considerations (e.g., deployment of technologies that could make decisions that unfairly impact specific groups), privacy considerations, and security considerations.• The conference expects that many papers will be foundational research and not tied to particular applications, let alone deployments. However, if there is a direct path to any negative applications, the authors should point it out. For example, it is legitimate to point out that an improvement in the quality of generative models could be used to generate deepfakes for disinformation. On the other hand, it is not needed to point out that a generic algorithm for optimizing neural networks could enable people to train models that generate Deepfakes faster. • The authors should consider possible harms that could arise when the technology is being used as intended and functioning correctly, harms that could arise when the technology is being used as intended but gives incorrect results, and harms following from (intentional or unintentional) misuse of the technology. • If there are negative societal impacts, the authors could also discuss possible mitigation strategies (e.g., gated release of models, providing defenses in addition to attacks, mechanisms for monitoring misuse, mechanisms to monitor how a system learns from feedback over time, improving the efficiency and accessibility of ML). 
safeguards: 
 Question: Does the paper describe safeguards that have been put in place for responsible release of data or models that have a high risk for misuse (e.g., pretrained language models, image generators, or scraped datasets)?Answer: [NA]Justification: The paper does not propose to release any data or models that would pose such a risk.Guidelines:• The answer NA means that the paper poses no such risks.• Released models that have a high risk for misuse or dual-use should be released with necessary safeguards to allow for controlled use of the model, for example by requiring that users adhere to usage guidelines or restrictions to access the model or implementing safety filters. • Datasets that have been scraped from the Internet could pose safety risks. The authors should describe how they avoided releasing unsafe images. • We recognize that providing effective safeguards is challenging, and many papers do not require this, but we encourage authors to take this into account and make a best faith effort.12. Licenses for existing assets Question: Are the creators or original owners of assets (e.g., code, data, models), used in the paper, properly credited and are the license and terms of use explicitly mentioned and properly respected?Answer: [NA] Justification: This paper does not use existing assets.Guidelines:• The answer NA means that the paper does not use existing assets.• The authors should cite the original paper that produced the code package or dataset.• The authors should state which version of the asset is used and, if possible, include a URL. • The name of the license (e.g., CC-BY 4.0) should be included for each asset.• For scraped data from a particular source (e.g., website), the copyright and terms of service of that source should be provided. • If assets are released, the license, copyright information, and terms of use in the package should be provided. For popular datasets, paperswithcode.com/datasets has curated licenses for some datasets. Their licensing guide can help determine the license of a dataset. • For existing datasets that are re-packaged, both the original license and the license of the derived asset (if it has changed) should be provided. 
 
 Appendix: In Algorithms 1-4 we present algorithms for the aggregation, product (with compatibility), product (with support-compatiblity), and elementwise mapping operators respectively (the initial call is to the root of the circuit(s)). In the following, we present proofs that the algorithms soundly compute smooth and decomposable output circuits for the respective operators.Theorem 1 (Tractable Aggregation). Let C be a smooth and decomposable circuit representing a function p : Assign(V ) → S. Then for any W ⊆ V , it is possible to compute the aggregate as a smooth and decomposable circuit C ′ (i.e., p C ′ (Z) = w p C (Z, w)) in O(|C|) time and space.Proof. We prove this inductively, starting from the input nodes of the circuit. Our claim is that for each node α ∈ C, AGG(α; W ) (Algorithm 1) returns a node α ′ with scope vars(α ′ ) = vars(α) \ W such that p α ′ (vars(α ′ )) = w p α (vars(α)), and is decomposable (if product) and smooth (if sum).If α is an input node (Lines 1-2), then this is possible by assumption; we denote this with AGG-INPUT in the algorithm. Note that if vars(α) = W , then this is just a scalar/constant (i.e. input node with empty scope).Algorithm 3: PROD-SCMP Input: Support-compatible algebraic circuits C(V ), C ′ (V ′ ); nodes α ∈ C, α ′ ∈ C ′ s.t. ι(α) = α ′ Output: Circuit encoding p C (V ) ⊗ p C ′ (V ′ ) if vars(α) ∩ vars(α ′ ) = ∅ then return α × α ′ else if α, α ′ are input nodes then return PROD-INPUT(α, α ′ ) else if α = α 1 × α 2 , α ′ = α ′ 1 × α ′ 2 are product nodes then return PROD-SCMP(α 1 , α ′ 1 ) × PROD-SCMP(α 2 , α ′ 2 ) else if α = + k i=1 α i , α ′ = + k i=1 α ′ i are sum nodes then return + k i=1 PROD-SCMP(α i , α ′ i )Algorithm 4: MAPPING Input: Smooth and decomposable algebraic circuit C(V ) over semiring S; Node α ∈ C; Mapping function τ : S → S ′ Output: Node encoding τ (p C (V )) if α is input node then return MAPPING-INPUT(α; τ ) else if α is product or sum node then return ⊗ k i=1 MAPPING(α i ; τ ) if α is product else ⊕ k i=1 MAPPING(α i ; τ ) If α is a product node α 1 × α 2 ,p α2 (vars(α 2 ))   = p AGG(α1;W ∩vars(α1)) (vars(α 1 ) \ W ) ⊗ p AGG(α2;W ∩vars(α2)) (vars(α 2 ) \ W )The second equality follows by the partition (and associativity of the addition and multiplication), while the third follows by distributivity of multiplication over addition. In the case where vars(α) = W (Lines 3-4), then p AGG(αi;W ∩vars(αi)) (vars(α i )) is just a scalar for each i, so we can directly perform this computation, returning a new scalar node α ′ . Otherwise (Lines 5-6), we construct a new product nodeα ′ = α ′ 1 × α ′ 2 = AGG(α 1 ; W ∩ vars(α 1 )) × AGG(α 2 ; W ∩ vars(α 2 )). By the inductive hypothesis, α ′ i has scope vars(α ′ i ) = vars(α i ) \ W , so α ′ is clearly decomposable and has scope vars(α ′ ) = (vars(α 1 ) \ W ) ∪ (vars(α 2 ) \ W ) = vars(α) \ W . If α = + ki=1 α i is a sum node, then we note that by smoothness, vars(α i ) = vars(α) for all i. Thus we have that:w p α (vars(α)) = w k i=1 p αi (vars(α)) = k i=1 w p αi (vars(α)) = k i=1 w p αi (vars(α i )) = k i=1 p AGG(αi;W ) (vars(α i ))In the case where vars(α) = W (Lines 3-4), then p AGG(αi;W ) (vars(α i )) is just a scalar, so we can directly perform this computation, returning a new scalar node α ′ . Otherwise (Lines 5-6), we construct a new sum nodeα ′ = + k i=1 α ′ i = + k i=1 AGG(α i ; W ). By the inductive hypothesis, each α ′ i has scope vars(α i ) \ W = vars(α) \ W , so α ′ is smooth and also has scope vars(α) \ W .Theorem 2 (Tractable Product -Compatibility). Let C, C ′ be compatible circuits over variables V , V ′ , respectively, and the same semiring. Then it is possible to compute their product as a circuit C compatible with them (i.e., pC ′′ (V ∪ V ′ ) = p C (V ) ⊗ p C ′ (V ′ )) in O(|C||C ′ |) time and space.Proof. We prove this inductively bottom up, for nodes If α is an input or product node and α ′ = + k ′ j=1 α ′ j is a sum node, then the algorithm constructs a new sum node α ′′ = + k ′ j=1 PROD-CMP(α, α ′ j ). This computes the correct function asEQUATIONp α ′′ = ⊕ k ′ j=1 p α ⊗ p α ′ j = p α ⊗ ⊕ k ′ j=1 p α ′ j = p α ⊗ p α ′ . Each child has scope vars(α) ∪ vars(α ′ j ) = vars(α) ∪ vars(α ′ ), so smoothness is retained. If α = α 1 ×α 2 , α ′ = α ′ 1 ×α ′ 2 are product nodes such that vars(α)∩(V ∩V ′ ) = vars(α ′ )∩(V ∩V ′) is non-empty, then writing X := V ∩ V ′ , by compatibility we also have vars(α 1 ) ∩ X = vars(α ′ 1 ) ∩ X and vars(α 2 ) ∩ X = vars(α ′ 2 ) ∩ X, so we can apply the inductive hypothesis for PROD-CMP(α 1 , α ′ 1 ) and PROD-CMP(α 2 , α ′ 2 ). Algorithm 2 constructs a new product nodeα ′′ = PROD-CMP(α 1 , α ′ 1 ) × PROD-CMP(α 2 , α ′2 ). To show that this is decomposable, we need the following lemma: Lemma 1 (Decomposability of Product). Suppose α ∈ C, α ′ ∈ C ′ are decomposable product nodes which decompose in the same way over X, i.e. vars(α 1 ) ∩ X = vars(α ′ 1 ) ∩ X and vars(α2 ) ∩ X = vars(α ′ 2 ) ∩ X. Then (vars(α 1 ) ∪ vars(α ′ 1 )) ∩ (vars(α 2 ) ∪ vars(α ′ 2 )) = ∅.Proof. We have that:(vars(α 1 ) ∪ vars(α ′ 1 )) ∩ (vars(α 2 ) ∪ vars(α ′ 2 )) = (vars(α 1 ) ∩ vars(α 2 )) ∪ (vars(α ′ 1 ) ∩ vars(α ′ 2 )) ∪ (vars(α 1 ) ∩ vars(α ′ 2 )) ∪ (vars(α 2 ) ∩ vars(α ′ 1 )) can also verify that p α ′′ = p PROD-SCMP(α1,α ′ 1 ) ⊗ p PROD-SCMP(α2,α ′ 2 ) = p α1 ⊗ p α ′ 1 ⊗ p α2 ⊗ p α ′ 2 = p α ⊗ p α ′by the inductive hypothesis, and associativity of ⊗.If α = + k i=1 α i , α ′ = + k ′ i=1 α ′i are sum nodes and ι(α) = α ′ , then by smoothness, all of the children of α have the same support and all the children of α ′ have the same support; thus all the children are in C[X], C ′ [X] respectively, k = k ′ , and ι(α i ) = α ′ i . By support compatibility, we also that (i) vars(α i ) ∩ X = vars(α ′ j ) ∩ X for all i, j; and (ii) that supp X (α i ) ∩ supp X (α ′ j ) for i ̸ = j. We claim that p αi ⊗ p α ′ j ≡ 0 S whenever i ̸ = j. To see this, recall the definition of X-support: we have that:supp X (α i ) = {x ∈ Assign(X ∩ vars(α i )) : ∃y ∈ Assign(vars(α i ) \ X) s.t. p αi (x, y) ̸ = 0 S } supp X (α ′ j ) = {x ∈ Assign(X ∩ vars(α ′ j )) : ∃y ∈ Assign(vars(α ′ j ) \ X) s.t. p α ′ j (x, y) ̸ = 0 S } Since X ∩ vars(α i ) = X ∩ vars(α ′ j )and is nonempty, by (ii) we know that there is no assignment of X ∩ vars(α i ) such that p αi and p α ′ j can be simultaneously not equal to 0 S . Thus there is no assignment of X ∩ vars(α i ) such that p αi ⊗ p α ′ j is not 0 S , since 0 S is the multiplicative annihilator. Thus, the product function is given by:p α ⊗ p α ′ = k i=1 k j=1 (p αi ⊗ p α ′ j ) = k i=1 (p αi ⊗ p α ′ i ) = k i=1 PROD-SCMP(α i , α ′ i )The second equality follows by the Lemma and the fact that 0 S is the additive identity, and the third equality by the inductive hypothesis. Thus α ′′ = + k i=1 PROD-SCMP(α i , α ′ i ) computes the correct function (Lines 7-8). We conclude by noting that vars(α′′ ) = k i=1 (vars(α i ) ∪ vars(α i )) = k i=1 vars(α i ) ∪ k i=1 vars(α i ) = vars(α) ∪ vars(α ′ ).The complexity of this procedure applied to the root nodes is O(max(|C|, |C ′ |), as we only perform recursive calls for (i) α ∈ C[X] and its corresponding node α ′ = ι(α) and (ii) nodes with nonoverlapping scope, upon which the recursion ends; so the overall number of recursive calls is linear in the size of the circuits.Theorem 4 (Tractable Mapping). Let C be a smooth and decomposable circuit over semiring S, and τ : S → S ′ a mapping such that τ (0 S ) = 0 S ′ . Then it is possible to compute the mapping of C by τ as a smooth and decomposable circuit C ′ (i.e., p C ′ (V ) = τ (p C (V ))) in O(|C|) time and space if τ distributes over sums and over products. If (Additive) holds, then we immediately have that τ k i=1 p αi (vars(α)) ≡ k i=1 τ (p αi (vars(α))) by associativity of ⊕. Alternatively, if (Det) holds, then given any v ∈ Assign((vars(α))), there is at most one child, say α j , such that p αj (v) ̸ = 0 S . Then we have thatτ ⊕ k i=1 p αi (v) = τ p αj (v) ⊕ k i=1,i̸ =j p αi (v) = τ p αj (v) ⊕ k i=1,i̸ =j 0 S = τ p αj (v) = τ p αj (v) ⊕ k i=1,i̸ =j 0 S ′ = τ p αj (v) ⊕ k i=1,i̸ =j τ (0 S ) = τ p αj (v) ⊕ k i=1,i̸ =j τ (p αi (v)) = k i=1 τ (p αi (v))and so again τk i=1 p αi (v) ≡ k i=1 τ (p αi (v)).Second, let us consider product nodes. If (Multiplicative) holds, then we immediately have that τk i=1 p αi (vars(α)) ≡ k i=1 τ (p αi (vars(α))) by associativity of ⊗. Otherwise, if (Prod 0/1) holds, then given any v ∈ Assign(vars(α)), there is at most one child, say α j , such that p αj (v) ̸ ∈ {0 S , 1 S }. Thus, we have that:τ k i=1 p αi (v) = τ p αj (v) ⊗ k i=1,i̸ =j p αi (v) = τ p αj (v) ⊗ τ k i=1,i̸ =j p αi (v) = τ p αj (v) ⊗ k i=1,i̸ =j τ (p αi (v) = k i=1 τ (p αi (v))The second equality follows because k i=1,i̸ =j p αi (v) ∈ {0 S , 1 S }, and we have that τ (a ⊗ 0 S ) = 0 S ′ = τ (a) ⊗ τ (0 S ) and τ (a ⊗ 1 S ) = 1 S ′ = τ (a) ⊗ τ (1 S ) for any a ∈ S. The third equality follows as both τ k i=1,i̸ =j p αi (v) and k i=1,i̸ =j τ (p αi (v)) are equal to 1 S ′ iff no p αi (v) is 0 S . Thus, we have that τk i=1 p αi (v) ≡ k i=1 τ (p αi (v)).By applying these identities recursively to sum and product nodes, and assuming that τ can be applied tractably to input nodes, we obtain a circuit C ′ such that p C ′ (V ) ≡ τ (p C (V )).Table 3 : Tractability Conditions for Operations on Algebraic Circuits. Sm: Smoothness, Dec: Decomposability; X-Det(erminism), X-Cmp: X-Compatibility, X-SCmp: X-Support-Compatibility.Proof. We look at each property in turn, and show that they are maintained under the aggregation, product, and mapping operators as stated in the Table . For convenience, we reproduce the table in Table 3 , with each result highlighted with a number that is referenced in the proof below.X-determinism Suppose that circuit C is X-deterministic; that is, for any sum node α = + k i=1 α i ∈ C, either (i) vars(α) ∩ X = ∅, or else (ii) supp X (α i ) ∩ supp X (α j ) = ∅ for all i ̸ = j.(5.1) Consider aggregating with respect to a set of variables W such that W ∩ X = ∅. According to Algorithm 1 and the proof of Theorem 1, this produces an output circuit where each node α ′ corresponds to some node α in the original circuit, such that p α ′ = w∩vars(α) p α and with scope vars(α) \ W . In particular, for sum nodes α = + k i=1 α i ∈ C, either vars(α) ⊆ W , in which case α ′ is an input node (and X-determinism is not applicable), or elseα ′ = + k i=1 α ′ i is also a sum node, where each α ′ i corresponds to α i . If (i) vars(α) ∩ X = ∅, then vars(α ′ ) ∩ X = ∅ also. If (ii) supp X (α i ) ∩ supp X (α j ) = ∅ for all i ̸ = j, we claim that supp X (α ′ i ) ⊆ supp X (α i) for all i. To see this, first note that by smoothness, vars(α′ i ) = vars(α ′ j ) = vars(α ′ ). Suppose that x i ∈ Assign(X ∩ vars(α ′ )) satisfies x ∈ supp X (α ′ i ).Then there exists y i ∈ Assign(vars(α ′ ) \ X) such that p α ′ i (x i , y i ) ̸ = 0 S . Since α ′ i corresponds to α i in the original circuit, we have:w∈Assign(W )∩vars(α) p αi (x i , y i , w i ) = p α ′ i (x, y) ̸ = 0 SThis means that there must be some w i ∈ Assign(W ) ∩ vars(α) such that p αi (x, y i , w i ) ̸ = 0 S (since 0 S is the additive identity); thus x ∈ supp X (α i ). To finish the proof, note that supp X (α ′ i ) ⊆ supp X (α i ) and supp X (α ′ l ) ⊆ supp X (α l ) are disjoint unless i = l (by X-determinism of α, i.e. supp X (α i ) ∩ supp X (α l ) = ∅ unless i = l). Thus (ii) holds for α ′ . In either case, we have shown that α ′ is also X-deterministic.(5.2) Consider taking the product of two compatible circuits C, C ′ over variables V , V ′ , outputting a circuit C ′′ . According to Algorithm 2 and the proof of Theorem 2, every sum node α ′′ ∈ C ′′ corresponds to either the product of (a) an input or product node α ∈ C and a sum nodeα ′ = + k ′ j=1 α ′ j ∈ C ′ , such that α ′′ = + k ′ j=1 α ′′ j or (b) two sum nodes α = + k i=1 α i ∈ C and α ′ = + k ′ j=1 α ′ j ∈ C ′ , such that α ′′ = + k i=1 + k ′ j=1 α ′′ ij .Further, α and α ′ have the same scope over the common variablesV ∩ V ′ , i.e. vars(α) ∩ (V ∩ V ′ ) = vars(α ′ ) ∩ (V ∩ V ′ ).Assume that C and C ′ are both X-deterministic; then X ⊆ V ∩ V ′ . We note that since α, α ′ have the same scope over the common variables, they also have the same scope over X, i.e. vars(α)∩X = vars(α ′ ) ∩ X.In case (a), X-determinism of α ′ means that either (i) vars(α′ ) ∩ X = ∅ or (ii) supp X (α ′ i ) ∩ supp X (α ′ j ) = ∅ for all i ̸ = j. If (i), then vars(α ′′ ) ∩ X = (vars(α) ∪ vars(α ′ )) ∩ X = ∅ also. If (ii), note that supp X (α ′′ j ) ⊆ supp X (α ′ j )for all j as a ⊗ 0 S = 0 S for any semiring S and a ∈ S. Thus supp X (α ′′ i ) ∩ supp X (α ′′ j ) = ∅ for all i ̸ = j. Thus α ′′ is X-deterministic. In case (b), since α, α ′ have the same scope over X, either (i) holds for both α, α ′ , or (ii) holds for both. If (i), then vars(α ′′ ) ∩ X = (vars(α) ∪ vars(α ′ )) ∩ X = ∅ also. If (ii), then for any i, j, consider the restricted support supp X (α ′′ ij ). Noting that vars(α i )∩X = vars(α ′ j )∩X = vars(α ′′ ij )∩ vars(α ′ ) ∩ (V ∩ V ′ ) (and similarly for their children). Thus by (V ∪ V ′ )-compatibility of C, C ′ , α and α ′ decompose the same way over (V ∪V ′ ), i.e. vars(α1 )∩(V ∪V ′ ) = vars(α ′ 1 )∩(V ∪V ′ ) and vars(α 2 ) ∩ (V ∪ V ′ ) = vars(α ′ 2 ) ∩ (V ∪ V ′ ). Since X ⊆ V ∩ V ′ (by definition of compatibility), this also holds over X, i.e. vars(α 1 ) ∩ X = vars(α ′ 1 ) ∩ X and vars(α 2 ) ∩ X = vars(α ′ 2 ) ∩ X. Now, since vars(α ′′ 1 ) = vars(α 1 ) ∪ vars(α ′ 1 ) and vars(α ′′ 2 ) = vars(α 2 ) ∪ vars(α ′ 2 ), we have that:vars(α ′′ ) ∩ X = (vars(α) ∩ X) ∪ (vars(α ′ ) ∩ X) = vars(α) ∩ X vars(α ′′ 1 ) ∩ X = (vars(α 1 ) ∩ X) ∪ (vars(α ′ 1 ) ∩ X) = vars(α 1 ) ∩ X vars(α ′′ 2 ) ∩ X = (vars(α 2 ) ∩ X) ∪ (vars(α ′ 2 ) ∩ X) = vars(α 2 ) ∩ XBy compatibility of C, C other , we have that vars(α other1 )∩X = vars(α 1 )∩X and vars(α other2 )∩X = vars(α 2 ) ∩ X. Thus vars(α other1 ) ∩ X = vars(α ′′ 1 ) ∩ X and vars(α other2 ) ∩ X = vars(α ′′ 2 ) ∩ X. This shows X-compatibility of C ′′ , C other .Example 4 (Counterexample to (5.6) for Compatibility). While X-compatibility is maintained through multiplying compatible circuits, the same is not true for compatibility, due to the different variable overlaps between the circuits. For example, suppose that C over variable sets A, B, C has product nodes with scope decomposing as α = α 1 (A) × α 2 (B ∪ C), and C ′ over variable sets A, B, D has product nodes with scope decomposing asα ′ = α ′ 1 (A) × α ′ 2 (B ∪ D).Then these circuits are compatible (i.e. A ∪ B-compatible), and their product is a circuit with product nodes with scope decomposing asα ′′ = α ′ 1 (A) × α ′ 2 (B ∪ C ∪ D). Now consider C other with product nodes with scope decomposing as α other = α other (C) × α other (D). This is compatible with α and α ′ , but not with α ′′ .(5.7) This holds by the same argument as (5.6).(5.8) The circuit C ′ obtained by applying an elementwise mapping to C does not change the scopes of any node. Thus, if C is compatible with C other , then C ′ is also compatible with C other .X-support-compatibility Recall that two smooth and decomposable circuits C, C other over variables V , V other are X-support-compatible for X ⊆ V ∩ V other if there is an isomorphism ι between the nodes C[X] and C other [X], such that:• For any node α ∈ C[X], vars(α) ∩ X = vars(ι(α)) ∩ X; • For all sum nodes α = + k i=1 α i ∈ C[X], we have that supp X (α i ) ∩ supp X (ι(α j )) = ∅ whenever i ̸ = j.(5.9) Suppose that C, C other are X-support-compatible; and let ι Cother,C be the isomorphism from C other [X] to C[X]. We wish to show that C other , C ′ are X-support-compatible where C ′ is the output circuit from Algorithm 1 that aggregates C over W , where W ∩ X = ∅.We define the isomorphism as follows. Consider the set of nodes C ′ [X]. Since W ∩ X = ∅, these nodes are not scalars and so are not propagated away by Lines 3-4. Moreover, since the algorithm retains the node types and connectivity of the circuit, there is an isomorphism ιC,C ′ between C[X] and C ′ [X]. There is thus an isomorphism ι Cother,C ′ := ι C,C ′ • ι Cother,C between C other [X] and C ′ [X].It remains to show the two conditions. Given a node α other ∈ C other , let us write α := ι Cother,C (α other ) and α ′ := ι C,C ′ (α). By Xsupport compatibility of C other , C, we have that vars(α other ) ∩ X = vars(α) ∩ X. By the proof of Theorem 1, we know that vars(α ′ ) = vars(α) \ W . Since W ∩ X = ∅, this implies that vars(α other ) ∩ X = vars(α ′ ) ∩ X as required. For the second part, suppose that these are sum nodes, i.e. α other = + k i=1 α other,i , α = + k i=1 α i and α ′ = + k i=1 α ′ i . We know by X-support-compatibility that supp X (α other,i ) ∩ supp X (α j ) = ∅ whenever i ̸ = j. By the same argument as in (5.1), we have that supp X (α ′ i ) ⊆ supp X (α i ) for all i. Thus we can conclude that supp X (α other,i ) ∩ supp X (α ′ j ) = ∅ whenever i ̸ = j. So C other , C ′ are X-support-compatible.(5.10) Suppose that C over V and C ′ over V ′ are both X-support-compatible with C other ; write ι Cother,C for the isomorphism from C other [X] to C, and ι Cother,C ′ for the isomorphism from C other [X] to C ′ . We wish to show that C other , C ′′ are X-support-compatible where C ′′ is the output circuit from Algorithm 3 that computes the product of the two support-compatible (i.e.(V ∪ V ′ )-support- compatible) circuits C, C ′ .We define the isomorphism as follows. Consider the set of nodes C ′′ [X]. The algorithm for multiplying C, C ′ makes use of the isomorphism ιC,C ′ between C[V ∩ V ′ ] and C ′ [V ∩ V ′ ], with C ′′ [V ∩ V ′ ]retaining the same connectivity and node types; thus there is an isomorphism ι By X-support-compatibility of C other , C, we have that vars(α other ) ∩ X = vars(α) ∩ X. By support-compatibility of C, C ′ , we have that vars(α) ∩ (V ∩ V ′ ) = vars(α ′ ) ∩ (V ∩ V ′ ) and so vars(α)∩X = vars(α ′ )∩X, and both are equal to vars(α ′′ )∩X since vars(α ′′ ) = vars(α)∪vars(α ′ ) (as in Theorem 3). Thus vars(α other ) ∩ X = vars(α ′′ ) ∩ X as required. For the second part, suppose that these are sum nodes, i.e.C,C ′′ from C[V ∩ V ′ ] to C ′′ [V ∩ V ′ ], also. Since X ⊆ (V ∩ V ′ ),α other = + k i=1 α other,i , α = + k i=1 α i , α ′ = + k i=1 α ′ i and α ′ = + k i=1 α ′′ i .We know by X-support-compatibility that supp X (α other,i ) ∩ supp X (α j ) = ∅ whenever i ̸ = j. By the same argument as in (5.3), we have that suppX (α ′′ ) ⊆ supp X (α) ∩ supp X (α ′ ). Thus we can conclude that supp X (α other,i ) ∩ supp X (α ′′ ) = ∅. So C other , C ′′ are X-support-compatible.(5.11) Suppose that C, C other are X-support-compatible; and let ι Cother,C be the isomorphism fromC other [X] to C[X].We wish to show that C other , C ′ are X-support-compatible where C ′ is the output circuit from Algorithm 4 that applies an elementwise mapping τ to C. Algorithm 4 maps each node α ∈ C to another node α ′ ∈ C, keeping the node type and connectivity; this defines an isomorphismι C,C ′ from C[X] to C ′ [X]. Thus we have an isomorphism ι Cother,C ′ := ι C,C ′ • ι Cother,C . It remains to show the two conditions.Given a node α other ∈ C other , let us write α := ι C0,C (α other ) and α ′ := ι C,C ′ (α). By Xsupport-compatibility of C other , C, we have that vars(α other ) ∩ X = vars(α) ∩ X. The mapping algorithm does not change the scope of the nodes, i.e. vars(α ′ ) = vars(α), so we have that vars(α other ) ∩ X = vars(α ′ ) ∩ X as required. For the second part, suppose that these are sum nodes, i.e. α other = + k i=1 α other,i , α = + k i=1 α i and α ′ = + k i=1 α ′ i . We know by X-support-compatibility that supp X (α other,i ) ∩ supp X (α j ) = ∅ whenever i ̸ = j. We know by the same argument as in (5.4) that supp X (α ′ i ) ⊆ supp X (α i ) for all i. Thus we can conclude that supp X (α other,i ) ∩ supp X (α ′ j ) = ∅ whenever i ̸ = j. So C other , C ′ are X-support-compatible.Theorem 7 (Hardness of 2AMC with X-firstness). 2AMC is #P-hard, even for circuits that are smooth, decomposable, deterministic, and X-first, and a constant-time elementwise mapping.Proof. Take a DNF ϕ with terms ϕ 1 , . . . , ϕ m over variables X 1 , . . . , X n . Let l = ⌈log m⌉ + 1. Let us construct another DNF ϕ ′ with terms ϕ ′ 1 , . . . , ϕ ′ m over variables X 1 . . . , X n and Y 1 , . . . , Y l+1 such that each ϕ ′ i is the conjunction of ϕ i , Y l+1 and a term over Y 1 , . . . , Y l encoding a binary representation of i. For example:ϕ ′ 5 = ϕ 5 ∧ Y 1 ∧ ¬Y 2 ∧ Y 3 ∧ ¬Y 4 ∧ • • • ∧ ¬Y l ∧ Y l+1. Now, efficiently manipulate ϕ ′ to make it smooth [15] . The circuit ϕ ′ is thus smooth, decomposable, deterministic and trivially satisfies X-firstness (since the children to every ∧-gate are literals). Take the probability semiring as S X , and S Y = (N 2 , + 2 , × 2 , (0, 0), (1, 1)) and τ ((n1, n2)) = n1/n2 (define 0/0 = 0). Also, define ω(x) = 1, and ω ′ (Y l+1 = 0) = (0, 1) and ω ′ (y) = 1 for all other literals. Then 2AMC counts the models of ϕ, which is #P-hard [46] :2AM C = x y:y l+1 =1 ϕ ′ (x, y) y ϕ ′ (x, y) = x ϕ(x),where we assume 0/0 = 0. The last equality follows because the circuit is deterministic (hence y ϕ ′ (x, y) = max y ϕ(x, y) ≤ 1) and logically equivalent to ϕ (i.e., ∀x : ϕ(x) = 1 ⇔ ∃y : ϕ ′ (x, y) = 1).Theorem 8 (Tractability Conditions for 2AMC). Every 2AMC instance is tractable in O(|C|) time for Boolean circuits that are smooth, decomposable, deterministic, X-first, and X-deterministic.EQUATION... ... EQUATIONS X ) C S Y (X, Y ) ← MAPPING(C(X, Y ); • B→S Y ) C S Y ,ω Y (X, Y ) ← PROD-CMP(C S Y (X, Y ), ω Y ) C S Y ,ω Y (X) ← AGG(C S Y ,ω Y (X, Y ); Y ) C S X ,ω Y (X) ← MAPPING(C S Y ,ω Y (X); τ S Y →S X ) C S X ,ω Y ,ω X (X) ← PROD-CMP(C S X (X), ω X ) Result: AGG(C S X ,ω Y ,ω X (X); X)Proof. In Algorithm 5, we show the algorithm for 2AMC, which is simply a composition of aggregations, products, and elementwise mappings. To show tractability of 2AMC, we simply need to show that the input circuits to each of these operators satisfy the requisite tractability conditions.We start with a smooth, decomposable, deterministic, X-deterministic, and X-first circuit C(X, Y ).• In line 1, we use the support mapping (Definition 6) from the Boolean to S Y semiring; this is tractable by Corollary 1 due to determinism, and the output C S Y (X, Y ) retains all the properties by Table 3 .• In line 2, we take the product of C S Y (X, Y ) and ω X (X). ω X is omni-compatible, so we can apply PROD-CMP. This results in a circuit C S Y ,ω Y (X, Y ) that is smooth, decomposable and X-first. ω X (X) is both deterministic and X-deterministic as it has no sum nodes, so this output circuit is also deterministic and X-deterministic by (5.2).• In line 3, we aggregateC S Y ,ω Y (X, Y ) over Y . The output circuit C S Y ,ω Y (X) is smooth and decomposable. It is also X-deterministic by (5.1), as Y ∩ X = ∅.Since C S Y ,ω Y (X, Y ) satisfied X-firstness, each product node α = α 1 × α 2 in that circuit had at most one child (say α 1 ) with scope overlapping with Y . Then, in the product in the previous step, α 2 must have been produced through Lines 1-2 (otherwise it would contain some variable in Y ); thus it was produced by applying • B→S Y to some node in C. Thus, for any value v ∈ Assign(α 2 ), p α2 ∈ {0 S Y , 1 S Y }. So (Prod 0/1) is satisfied.• In line 4, we apply the mapping τ S Y →S X to C S Y ,ω Y (X). This circuit is over X and is X-deterministic, i.e. deterministic and satisfies (Additive). As shown in the previous step, it also satisfies (Prod 0/1). Thus the mapping algorithm produces the correct result, producing a smooth, decomposable and determinsitic circuit C S X ,ω Y (X) as output.• In line 5, we take the product of C S X ,ω Y (X) with ω X (X). ω X is omni-compatible so we can apply PROD-CMP, producing a circuit C S X ,ω Y ,ω X that is smooth and decomposable (and also deterministic).• Finally, we aggregate C S X ,ω Y ,ω X (X) over X, producing a scalar.Theorem 9 (Exponential Separation). Given sets of variables X = {X 1 , ..., X n }, Y = {Y 1 , ..., Y n }, there exists a smooth, decomposable and X-deterministic circuit C of size poly(n) such that the smallest smooth, decomposable, andX-first circuit C ′ such that p C ≡ p C ′ has size 2 Ω(n) .Proof. Consider representing the distribution given by a hidden Markov model (HMM) over (hidden) variables X ≤n = {X 1 , ..., X n } and (observed) variables Y ≤n = {Y 1 , ..., Y n }, as depicted in Figure 4a . Figure 4b shows a structured decomposable circuit that computes the hidden Markov model distribution, where the components C i (j) have scope {X i , Y i }. The corresponding vtree/scopedecomposition (with nodes notated using their scopes) is shown in Figure 4c . It can easily be checked that the circuit is X ≤n -deterministic, and that the circuit size is linear in n.It remains to show that the smallest X ≤n -first and X ≤n -deterministic circuit computing the HMM distribution is exponential in size. Explicitly, we will choose a HMM such that the emission distribution is given by p(Y i |X i ) = 1 Yi=Xi . Then we have that p C ′ (x ≤n , Y ≤n ) = p C ′ (x ≤n )p C ′ (Y ≤n |x ≤n ) = p C ′ (x ≤n )1 Y ≤n =x ≤n , for any circuit C ′ that expresses the distribution of the HMM.Consider any such circuit C ′ . Then, let α = {α 1 , ..., α K } be the set of nodes with scope Y ≤n in the circuit. We will need the following lemma:Lemma 2. For any value x ≤n of X ≤n , there exists constants c 1 , .., c K ∈ R ≥0 such that:EQUATIONIn other words, the output of the circuit is a linear function of the nodes with scope Y ≤n .Proof. We show this proof by bottom-up induction (child before parent), for the set of nodes whose scope contains Y ≤n :• Leaf node: If the scope is Y ≤n , then it must be some node α k ∈ α; then we take c k = 1 and c k ′ = 0 for all k ′ ̸ = k.• Sum node: By smoothness, all the children must have the same scope (containing Y ≤n ). The sum node is then just a linear combination of its children, so the result holds by the inductive hypothesis.• Product node P : Let P 1 , P 2 be the children of P . By X ≤n -firstness, either both children are pure (have scope entirely contained in X ≤n or Y ≤n ), or one of them is pure, and the scope of the other one (say P 1 ) contains Y ≤n .In the first case, if there is exactly one node (say P 1 ), with scope contained in Y ≤n , then it must have scope exactly Y ≤n . Then we have that:p P (x ≤n , Y ≤n ) = p P1 (Y ≤n )p P2 (x ≤n ∩ vars(P 2 ))p P2 (x ≤n ∩ vars(P 2 )) here is a constant, so by the inductive hypothesis we are done. If both nodes have scope contained in Y ≤n , then P is in α, say P = α k . Then we set c k = 1 and c k ′ = 0 for k ′ ̸ = k.In the second case, we have that:p P (x ≤n , Y ≤n ) = p P1 (x ≤n ∩ vars(P 1 ), Y ≤n )p P2 (x ≤n ∩ vars(P 2 ))Here p P2 (x ≤n ∩ vars(P 2 )) is a constant, so by the inductive hypothesis we are done.Note that X ≤n -firstness was crucial to avoid the case where a product has two mixed nodes (containing variables in X ≤n and Y ≤n ) as children.For any k = 1, .., K, define v k ∈ R 2 n ≥0 to be the vector with entries v k,i = α k (i) (where we interpret i as a value of Y ≤n ). Then we have the following Corollary: Corollary 2. The set of vectors {v 1 , ..., v K } forms a spanning set for R 2 n .Proof. By the Lemma and the fact that C ′ expresses the HMM distribution, we have that for any x ≤n ∈ {0, 1} n , there exists c 1 , .., c k ∈ R ≥0 such that:p C ′ (x ≤n )1 Y ≤n =x ≤n ≡ K k=1 c k p α k (Y ≤n )Rearranging, and writing in vector form, we have:e x ≤n = K k=1 c k p C ′ (x ≤n ) v kwhere e x ≤n ∈ R 2 n ≥0 is the standard basis vector corresponding to the value x ≤n . Thus {v 1 , ..., v K } is a spanning set.Any spanning set for R 2 n must contain at least 2 n elements. Thus, K ≥ 2 n , and the circuit C ′ must be exponentially sized.One might attempt to remedy the situation by replacing X-firstness with X-determinism. For the general case, that however is insufficient: Theorem 10 (Hardness of 2AMC with X-determinism). 2AMC is #P-hard even for decomposable, smooth, deterministic and X-deterministic circuits, and a constant-time elementwise transformation function.Proof. By reduction from the counting version of number partitioning: Given positive integers k 1 , . . . , k n , count the number of index sets S ⊆ {1, . . . , n} such that i∈S k i = i̸ ∈S k i = c. That problem is known to be #P-hard [47] . Define ϕ = n i=1 (X i ⇔ Y i ). Then ϕ is a deterministic, X-deterministic, decomposable and smooth circuit. 4 Let the inner labeling function be ω ′ (y i ) = k i /c and ω ′ (¬y i ) = 1. Then for a fixed configuration x of the variables X = {X 1 , . . . , X n }, we have exactly one model for ϕ, whose value is ⊗ i:xi=1 k i /c. If we select the inner semiring so that ⊗ is addition (e.g., the max tropical semiring or log semiring), then the inner AMC problem returns i:xi=1 k i /c, which equals 1 iff S = {i : x i = 1} is a solution to the number partitioning instance. Now, define the outer labeling function to be ω = 1, and let the transformation function be τ (s) = 1 if s = 1 and τ (s) = 0 otherwise. Then the 2AMC problem with the probability semiring as outer semiring counts the number of solutions of the number partitioning instance. In this section, we provide more details about the compositional inference problems in Table 2 (reproduced in Table 4 ) for convenience, and prove the tractability conditions for each (Theorem 6). For all of them, we assume that we are given a Boolean formula represented as a circuit. That would usually come from knowledge compilation from some source language such as Bayesian Networks [9] or probabilistic logic programs [24] ; our results thus show what properties the compiled circuit must have in order a query of interest to be tractable. Note that the problems are generally computationally hard [19, 10] on the source language, which means there do not exist compact circuits satsifying the properties in the worst-case.Theorem 6 (Tractability of Compositional Queries). The results in Table 2 hold.Firstly, we consider instances of 2AMC queries. Recall the general form of a 2AMC query. Given a partition of the variables V = (X, Y ), a Boolean function ϕ(X, Y ), outer and inner semirings S X , S Y , labeling functions ω Y (Y ) = Yi∈Y ω Y ,i (Y i ) over S and ω X (X) = Xi∈X ω X,i (X i ) over S ′ , and an elementwise mapping τ S Y →S X : S Y → S X , the 2AMC problem is given by:x τ S Y →S X y ϕ(x, y) B→S Y ⊗ ω(y) ⊗ ω ′ (x) (1, revisited)By Theorem 8, any 2AMC problem is tractable if ϕ is given as a smooth, decomposable, deterministic, X-deterministic, and X-first circuit C. However, in some instances, we can relax these conditions, as we show shortly.In the Marginal Maximum A Posteriori inference (MMAP), we are given a Boolean function ϕ(V ), a (unnormalized) fully factorized distribution p(V ) = i p i (V i ), a partition X ∪ Y = V and some evidence e on E ⊂ V . The goal is to compute the probability of the maximum probability assignment of X consistent with e:max x p(X = x, E = e) = max x y|=ϕ(x,Y )∧e i p i (v i ).To cast it as a 2AMC problem, take the inner semiring S Y to be the probability semiring and define the inner labelling function to assign ω Y (Y i ) = 0 if Y i ∈ E and Y i is inconsistent with e and ω Y (Y i ) = p i (Y i ) otherwise. The outer semiring is the (max, •) semiring with labeling function ω X (X i ) = 1. The elementwise mapping function τ S Y →S X (a) = a is the identity function.The proof of the tractability conditions follows Theorem 8, except that we note that the mapping function τ S Y →S X from the outer to inner semiring satisifies (Multiplicative). As such, we do not need the (Prod 0/1) circuit property, which was the reason we needed the X-firstness condition.The Probabilistic Answer Set Programming Inference (PASP) query takes a Boolean formula ϕ(V ), a partition X ∪ Y = V , a (unnormalized) fully factorized distribution p(X) = i p(X i ), and query variable and value {Q = q}, for some Q ∈ V . The goal is to compute:p(Q = q) = x i p(X i ) y|=ϕ(x,Y )∧q p * (y|x).The function p * (Y |X) depends on the semantics adopted. Let mod(Y |X) := {y : ϕ(X, y)} be the set of assignments of Y such that ϕ(X, •) is true. In the Maximum Entropy Semantics (MaxEnt) [6, 51, 45] , one distributes the probability mass p(X) uniformly over the models of ϕ consistent with X, i.e. p * (y|X) = 1 |mod(Y |X)| . On the other hand, in the Credal Semantics [33, 14] (Max-Credal), one places all probability mass p(X) on some assignment y of Y consistent with X and q. To obtain an upper bound on the query probability regardless of which y is chosen, one sets p * (y|X) := 1 for all y if there exists an assignment Y |= ϕ(X, Y ) ∧ q, and p * (Y |X) = 0 otherwise. The 2AMC formulation of the problem uses the probability semiring as outer semiring S X , with labeling function ω X (X i ) = p(X i ) for X i ∈ X. (Q) = ⊤ if Q = q ⊥ otherwise , and sets ω Y (Y i ) = ⊤ for all other variables Y i ∈ Y . The mapping function is defined by τ S Y →S X (a) = a S Y →S X .As with marginal MAP, we can see that in both cases, the mapping function τ S Y →S X satisfies (Multiplicative), so X-firstness of the circuit is not required. In particular, for (MaxEnt) we haveτ S Y →S X ((a, b)⊗(c, d)) = τ S Y →S X ((a•c, b•d)) = a•c b•d = a b • c d = τ S Y →S X (a, b)•τ S Y →S X (c, d) = τ S Y →S X (a, b) ⊗ τ S Y →S X (c, d) (this holds also if (a, b) = (0, 0) and/or (c, d) = (0, 0)). Meanwhile, for (Max-Credal) we have τ S Y →S X (a ⊗ b) = τ S Y →S X (a ∧ b) = a ∧ b S Y →S X = a S Y →S X • b S Y →S X = τ S Y →S X (a) • τ S Y →S X (b) = τ S Y →S X (a) ⊗ τ S Y →S X (b).For the (Max-Credal) semantics, we note additionally since S Y is just the Boolean semiring, we do not need determinism in Line 1 of Algorithm 5. So the only conditions required are smoothness, decomposability, and X-determinism.In the Same Decision Probability (SDP) query [37] , we are given a Boolean formula ϕ(V ), a fully factorized distribution p(V ) = i p(V i ), a partition X, {Y } of V , a query {Y = y}, some evidence e on a subset E ⊆ X of variables and a threshold value T ∈ (0, 1]. The goal is to compute a confidence measure on some threshold-based classification made with the underlying probabilistic model: X (X i ) = 1 Xi|=e if X i ∈ E, and ω X (X i ) = p(X i ) otherwise.Unlike marginal MAP and PASP inference, there is no special structure in SDP that allows us to relax the general tractability conditions for 2AMC. However, it is still a 2AMC instance, and we have the tractability conditions from Theorem 8. In particular this justifies the use of X-constrained sentential decision diagrams for this problem.Now, consider the frontdoor case. In this case, we have the following compositional query:EQUATIONAssume that p(V ) is given as a smooth, structured decomposable, X-deterministic, and (X ∪ Z)deterministic circuit (over the probabilistic semiring). We continue the analysis from the backdoor case:• p(X) C 7 (X) := AGG(C, Y ∪ Z) is tractable by smoothness and decomposability. By (5.1) in Table 3 , since 5.11) . Thus this product is tractable in linear time.EQUATION• x p(x)p(Y |x, Z) C 10 (Y , Z). This is just like C 6 , but with variables X and Z swapped. Thus it is tractable for a smooth, X-deterministic and (X ∪ Z)-deterministic circuit in linear time.• p(Z|X) x ′ p(x ′ )p(Y |x ′ , Z) C 11 (X, Y , Z) := PROD-CMP(C 9 , C 10 ).We can chain applications of (5.5), (5.7) and (5.8) in a similar way to the other steps to show that C 9 , C 10 are Z-compatible (i.e. compatible), so this product is tractable in quadratic time.• z p(z|X) x ′ p(x ′ )p(Y |x ′ , z) C 12 (X, Y ) := AGG(C 11 ; Z). This is tractable by smoothness and decomposability. Thus, this algorithm has complexity O(|C| 2 ), as opposed to the O(|C| 3 ) complexity algorithm in [49] . The key difference is that we exploit support compatibility for a linear time product when constructing C 10 .In [31] , the most frugal explanation (MFE) query was introduced. Given a partition of variables V into (H, I + , I -, E), some evidence e ∈ Assign(E), and a probability distribution p(V ), the MFE query asks for the following:EQUATIONIn words, we want the explanation (assignment to H) that is the most probable for the most number of assignments to I -, when I + is marginalized out. We can rewrite as follows:EQUATIONThis can be written as a compositional query as follows.EQUATIONwhere S is the probability semiring, S ′ is the (max, •)-semiring, S ′′ is ([0, 1], +, •, 0, 1) (i.e. the probability semiring with domain [0, 1]), and S ′′′ is the counting semiring (N, +, •, 0, 1), and the mapping functions are defined as follows:• τ S→S ′ (a) = a • τ S ′ →S ′′ (a) = a • τ -1 (a) = a -1 if a ̸ = 0 0 if a = 0 • τ S ′′ →S ′′′ (a) = 1 a=1 • τ S ′′′ →S ′ (a) = aSuppose we are given a probabilistic circuit representing p(H, I -, e). While this query appears extremely intimidating at first glance, we note that the only operators we need to consider are the mappings and single product. Note that all of these mappings satisfy (Multiplicative) (τ S ′′ →S ′′′ because the domain ofS ′′ is [0, 1] so τ S ′′ →S ′′′ (a • b) = 1 iff a = b = 1); thus the mappings are tractable if the input circuits are deterministic. By checking the scopes of the inputs to each mapping, we can see that (H ∪ I -)-determinism, I --determinism, and H-determinism suffices. This also enables tractability of the product in linear time by support compatibility.No tractability conditions for exact inference for this query were previously known. While the motivation behind the MFE query is as a means of approximating marginal MAP, and so this exact algorithm is not practically useful in this case, this example illustrates the power of the compositional framework to tackle even very complex queries.Recently, in [27] , the reverse-MAP query was introduced, defined by:EQUATIONwhere the variables are partitioned as V = (E 1 , E 2 , X, H). In our compositional framework, this can be written as: Here, the mapping τ -1 is tractable if the circuit for p is X-deterministic. Since p is X-deterministic, it is X-support-compatible with itself; chaining this with (5.9) and (5.11) in Table 3 , the inputs to the product are X-compatible; since they have scope X, this means the product is tractable by support-compatibility. The resulting circuit remains X-deterministic (i.e. deterministic as the scope is X), which means that the mapping τ P→M from the probability to (max, •) semiring is tractable. Thus, this query is tractable for smooth, decomposable and X-deterministic circuits in linear time (same as derived by the authors).• It is OK to report 1-sigma error bars, but one should state it. The authors should preferably report a 2-sigma error bar than state that they have a 96% CI, if the hypothesis of Normality of errors is not verified. • For asymmetric distributions, the authors should be careful not to show in tables or figures symmetric error bars that would yield results that are out of range (e.g. negative error rates). • If error bars are reported in tables or plots, The authors should explain in the text how they were calculated and reference the corresponding figures or tables in the text.Probabilistic circuits are sometimes written with weights on the edges; this can easily be translated to our formalism by replacing the child of a weighted edge with a product of itself and an input function with empty scope corrresponding to the weight[44,42].In a slight abuse of notation, we will write τ : S → S ′ to indicate that τ maps between the respective sets.If the size of X is fixed, a circuit can always be rearranged to be X-first with at most a 2 |X| blowup.While this circuit is not X-first, it does satisfy a property known as X-firstness modulo definability[29]; thus that property is insufficient for 2AMC even together with X-determinism. 


Decision: The paper provides a unifying framework for algebraic circuits using compositional operation and claims to show new tractable classes for various probabilistic queries.  This is done by extending circuits to semi-rings.
 
The reviewers comments say that the strength is in the technical work. Yet the weakness is that it is not clear what the practical contribution is. It is not clear if the tractability conditions can be satisfied by any real circuits. Also, there are complaints that there is no clear separation between earlier and new contributions. There was a discussion with the authors and reviewers seemed to accept the clarifications provided.

There is a very large literature missing here on semiring, by Bistareli et. al: in the area of constraint and probabilistic reasoning by 

Semiring-based constraint satisfaction and optimization
Authors: Stefano Bistarelli, Ugo Montanari, Francesca Rossi 
Journal of the ACM (JACM), Volume 44, Issue 2
Pages 201 - 236
https://doi.org/10.1145/256303.256306

Reviews: review: paper_summary: paper_summary: They investigate algebraic circuits on semi-rings (with sums and products).
They give criterions that allow efficient combinations of circuits and aggregation of the variables of one circuit (e.g. the sum over all inputs of the circuit).
They give algorithms and hardness results for Algebraic Model Counting.
strength_weakness: strength_weakness: a lot of technical definitions

the conditions under which the algorithms are efficiently applicable seem rather restrictive
questions: questions: what is an "atlas"? the word is never used in the text


the classic circuit classes have an uniformity constraint, on the complexity of an algorithm that computes the circuit for a certain input length.
do these algebraic circuits not need uniformity ?


>Theorem 2 
why not just add one new product node as root node, and then make both C and C' children of this new node.
it is a much simpler construction and would also compute the product.
limitations: limitations: yes
paper_summary: paper_summary: The paper presents sufficient conditions under which certain problems (e.g. 2AMC are tractable when performed on circuits.
strength_weakness: strength_weakness: 1) My main problem with the paper is that it only discusses sufficient conditions (also acknowledged by the authors). This is constrast to teh probabilistic circuit atlas [1]. This in itself is not a problem, however, the paper does not discuss the problem of eighted model integratio, which has also been formulated as an AMC problem with integration as an extra operation [2]. In general WMI is intractable, however, it has been shown that there exist tractable fragments [3]. If I understand the paper correctly, the tractable fragment of WMI does not fall within the proposed framework. This is quite limiting as the framework does not even cover all tractable problems that can be formulated as 2AMC.

2) Tractable algebraic circuits seem to be highly related to performing tractable inference on first-order circuits. [4] This relationship is not discussed at all.


[1] Vergari, Antonio, et al. "A compositional atlas of tractable circuit operations for probabilistic inference." Advances in Neural Information Processing Systems 34 (2021): 13189-13201.

[2] Dos Martires, Pedro Zuidberg, Anton Dries, and Luc De Raedt. "Exact and approximate weighted model integration with probability density functions using knowledge compilation." Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 33. No. 01. 2019.

[3] Zeng, Zhe, et al. "Probabilistic inference with algebraic constraints: Theoretical limits and practical approximations." Advances in Neural Information Processing Systems 33 (2020): 11564-11575.

[4] Van den Broeck, Guy, et al. "Lifted probabilistic inference by first-order knowledge compilation." IJCAI. 2011.
questions: questions: Could the authors comment on the two points I raised under "weaknesses".
limitations: limitations: covered.
paper_summary: paper_summary: The paper mainly focuses on the problem of deriving tractability conditions for compositional operations over circuits as to solve a number of queries. By fixing the language of circuits over semirings, the paper generalizes known results and introduce novel ones regarding the tractability of queries solved via algebraic circuits. In addition, it analyzes scenarios where milder structural conditions might be required, when compared to previous results.
strength_weakness: strength_weakness: I think that some results requiring particular semirings and homomorphisms require so many properties that make me wonder their actual contribution.
Tractable mapping (Theorem 4) requires the following combination of properties to be both true:
1. $\tau$ is additive OR $C$ is deterministic
2. $\tau$ is multiplicative OR ($\tau$ maps the multiplicative identity AND for each product $\alpha$, one of its input must output zero or one as a constant).
I think that the authors should have stressed the limitations of the given properties on $\tau$. E.g., if $C$ is not deterministic and there are no product units satisfying the above, then which functions $\tau$ are we restricted to in practice? See the question 1 below for more on this.

Theorem 3 claims that one can compute the product of support compatible circuits linearly in the maximum circuit size for both time and memory. However, I think the authors should state that this complexity assumes that (i) we already know the isomorphism between nodes, and (ii) we already know how to "match" the supports of sum nodes in the algorithm. I think that without (ii) one would definitely need linear space and quadratic time instead.

In line L298-L300, the authors claim that for particular semirings and mappings, one could relax the determinism property from the circuit for tractable 2AMC. However, this does not seem to be reflected in table 2, where X-Det is present in all 2AMC queries. I think the authors should either make a milder claim or explicitly show in table 2 a case of such a query.

Looking at Algorithm 2 and 3, I think there are corner cases that are not covered neither by them nor by the proofs. For example, the case of multiplying a sum node and a product node is missing. The case of multiplying input nodes and sum/product nodes is also missing. In fact, these algorithms are way too small when compared to the algorithm of the product showed in [35] (Algorithm 3 in the appendix). I believe the cases must be covered for completeness.

I believe a minor weakness of the presentation of this paper is that it mixes two kinds of theoretical results. It contains some results that leverage algebraic circuits and specific properties regarding semirings and morphisms (e.g., Theorem 4). However, it seems the majority of the other results do not actually need any specific property of the semiring being chosen, and could have been part of a work following the compositional atlas paper on circuits [35]. When reading the paper, I often found myself asking whether the theorems and proof I was looking at were the result of a property of semirings I was missing. This is because of the title and the definition of algebraic circuits is the first definition appearing, and I was expected the rest of the paper being very dependent on it. Instead, it seems many theorems can stand on their own with the usual circuit definition given in [35]. Although minor, I think it would be beneficial if the authors stressed at the beginning that the chosen semiring is not really important for many of the results being shown.
questions: questions: 1. If we restrict  $\tau$ to be both additive and multiplicative homomorphisms, then does this imply it can only be identity function? It looks like it can only be identity function as for Lemma 3.8 in the appendix of [35]. Do the authors agree on this? If yes, then I think it is necessary to refine the conditions required by Theorem 4 as to include these results about the satisfaction of Cauchy functional equations.
2. Following Question 1, are there examples of both additive and multiplicative homomorphisms for some particular choices of source and destination semirings?
3. It seems the support-compatibility definition does not consider how scopes of products are factorized. What is the relationship between support compatibility between circuits and compatibility + determinism? Is structured decomposability PLUS determinism in a circuit more restrictive than support-compatibility with itself?
limitations: limitations: I have discussed the presence of limitations in the weaknesses section.
paper_summary: paper_summary: This paper unifies two lines of work:
1) a compositional approach to tractability of queries over logical [12], probabilistic [35] and causal circuits [36] and
2) a (commutative) semiring-based perspective over different computational tasks ([12] among many others).

The benefit is the characterization of certain probabilistic and causal tasks in terms of combinations of simple operations on algebraic circuits. Concretely, this approach is used to derive new complexity results in second-level algebraic model counting (including highlighting a wrong claim in [20]) and causal inference, among others.

**update after rebuttal**

The response clarified a bit the scope of the contribution. I think that this is solid work overall and that adding parts of their response to the main text would make the paper more accessible. I raised my score accordingly.
strength_weakness: strength_weakness: - Novel and existing notions/definitions are mixed together, making it hard to give proper credit where it is due.
- The high-level contributions are not very clear from the text (in particular in the first sections). [35] clearly listed their contributions at the end of their introduction, in contrast, I found lines 39-42 more vague in this sense, giving the (wrong) idea that the compositional approach is a novelty.
- I think that the practical impact of this contribution is not be very clear to a general AI/ML audience.
questions: questions: 1. Could you clearly outline what are the novel notions that enable this generalized compositional framework?
2. Could you similarly outline what are the key ideas / existing work this work builds upon?
3. Could you provide examples (for the general NeurIPS audience rather than experts in AMC and AC) of the practical impact of this contribution?


## Minors

Multiple typos on Def. 1
limitations: limitations: The limitations of this work are adequately addressed in the conclusion.

Comments: title: Response to the authors
comment: Thank you for the discussion.

**On WMI and AMC** It is true that standard message-passing on discrete graphical models can be easily translated to circuits. However, the algorithm of Zeng et al. for WMI is different; for instance, integration is not even efficient if the diameter of the tree is large. 

As far as we are aware, a circuit interpretation of their algorithm does not currently exist, and would involve novel research. In particular, in Zuidberg et al., the *logical* (Boolean) part of the WMI problem is compiled to a circuit (which, as an AMC problem, is captured in our atlas), and has the standard exponential-in-treewidth complexity; while the *integration* uses an external symbolic integration engine (PSI-Solver). 

**On first-order circuits** We think the reviewer may be confusing propositional variables, of which we have many, with logical variables, of which we have none. Logical variables, when instantiated as arguments to predicates, give rise to propositional variables in the form of atoms in the work of Van den Broeck et al. Our work has no predicates and no logical variables, and is therefore only tangentially related. Our semiring operations, such as max, are over propositional variables, not logical variables.

In weighted first-order model counting as defined in Van den Broeck et al., one sums a *product of weights* over *grounded predicates satisfying the first-order formula*. In contrast, in algebraic circuits, we sum/aggregate a *function* over *assignments of the propositional variables*.
**On WMI and AMC**
Indeed the method by Zeng et al. solves WMI via a message passing scheme. As it is well-known that message passing is essentially performs a series of sum product evaluations this can be cast as an AMC problem, which was done by Zuidberg et al. Given these two works it should hence be possible to cast WMI as an inference problem in the AMC atlas. 

**On first order circuits**
You state that "you work focuses on propositoinal formulas". However, if you had pure propositional formulas you would not have any variables to perform the extra operation over. I.e. the max in a marginal map problem. In this regard you are not dealing with propositional formulas but with (a fragment of) weighted first-order logic.

**In conclusion**

I still believe the connections to WMI circuits and FO logic circuits should be studied more carefully if one were to claim an atlas of algebraic circuits.
Thank you for clarifying some aspects of your contribution, I don't have further questions at the present time.
Thank you for the very good responses to all my questions.
I have decided to raise my overall score to full acceptance.