A Compositional Atlas for Algebraic Circuits
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 operators 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 operators over semirings: aggregation, product, and elementwise mapping. Using this framework, we uncover simple and general sufficient conditions for tractable composition of these operators, 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.
1 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 [darwiche2003differential, Chavira08] to probabilistic programs [problog, problog-inference, holtzen2020scaling, saad2021sppl], 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 [AhmedNeurIPS22, ZhangICML23] and neural logic programming [manhaeve2018deepproblog, huang2021scallop]. Circuits can also be learned as probabilistic generative models directly from data [gens2013learning, rahman2014cutset, peharz2020random, LiuICLR23], in which context they are known as probabilistic circuits [probcirc]. 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 [choi2021group] and causal reasoning [zevcevic2021interventional, wang2022tractable, wang2023compositional].
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 [vergari2021atlas, BroadrickUAI24]. 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) [marginalmap] query takes a probabilistic circuit and some evidence and asks for the most likely assignment of a subset of variables. The success probability inference in probabilistic logic programming [plog, smproblog] takes a circuit representation of a logic program, a weight function and some query , 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 [vergari2021atlas], 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.
Our 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 [darwiche2002knowledge] and probabilistic [vergari2021atlas] 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 LABEL:sec:case_studies), 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 [asp2mc], and reduce the complexity of causal backdoor/frontdoor adjustment on probabilistic circuits [pearl1995do, wang2023compositional] from quadratic/cubic to linear/quadratic respectively.
2 Preliminaries
Notation
We use capital letters (e.g., ) to denote variables and lowercase for assignments (values) of those variables (e.g., ). We use boldface to denote sets of variables/assignments (e.g., ) and write for the set of all assignments to . Given a variable assignment of , and a subset of variables , we write to denote the assignment of corresponding to .
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 is a tuple , where and are associative and commutative binary operators on a set (called the domain) such that distributes over (i.e., for all ); is the additive identity (i.e., for all ) and annihilates through multiplication (i.e., for all ); and is the multiplicative identity (i.e., for all ).
For example, the probability semiring employs standard addition and multiplication ( and ) over the non-negative reals, the semiring replaces addition with maximization, while the Boolean semiring 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 , an algebraic circuit over variables is a rooted directed acyclic graph (DAG), whose nodes have the following syntax:
where are circuit nodes, and is a function over a (possibly empty) subset of variables, called its scope. That is, each circuit node may be an input (), sum (), or a product (). The scope of any internal node is defined to be . Each node represents a function taking values in , defined recursively by: if , if , and if , where is the scope of . The function represented by the circuit is defined to be the function of the root node. The size 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. 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 [amarilli2024circus]—which are over the Boolean semiring and represent Boolean functions—and probabilistic circuits [probcirc]—which are over the probabilistic semiring and represent probability distributions.111Probabilistic 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 [shpilka2010arithmetic, rooshenas2014learning]. 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 , its children have the same scope: . A circuit is decomposable if for every product node , its children have disjoint scopes: .
Aside from the scopes of circuit nodes, we can also specify properties relating to their supports [probcirc]:
Definition 4 (-Support).
Given a partition of variables and a node in circuit , the -support of is the projection of its support on :
Definition 5 (-Determinism).
Given a circuit and a partition of , we say that is -deterministic if for all sum nodes , either: (i) ; or (ii) for all .
-determinism refers to a family of properties indexed by sets . In particular -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 . Figure 2(a) shows a simple example of a smooth, decomposable, and deterministic circuit that is not -deterministic, while Figure 2(b) shows a smooth, decomposable, and -deterministic circuit.
3 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 is a composition of the and operators. Similarly, for Boolean functions , the query composes the , and operators. Although these queries appear to involve four different operators, three of them 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).
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 LABEL:appx:proofs.
3.1 Basic Operators
Aggregation
Given a function , aggregating over returns the function for defined by
For example, aggregation corresponds to forgetting variables in the Boolean semiring, marginalizing out in the probability semiring, and maximizing over assignments in the 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 and , the product of and is a function , where , defined by
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 , it returns the function composition . 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 and a mapping from semiring to satisfying , an elementwise mapping of by results in a function defined by 222In a slight abuse of notation, we will write to indicate that maps between the respective sets.
In 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 and a target semiring , the support mapping is defined as: if ; otherwise.
In particular we will often use the source semiring , in which case the support mapping maps to the and to the 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 and a weight function . The marginal MAP query for variables is defined by
where we interpret as and as 0. We can break this down into a compositional query as follows:
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 from the probability to the semiring defined by for all . 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.
3.2 Tractability Conditions for Basic Operators
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 [darwiche2002knowledge, probcirc]. This can be generalized to arbitrary semirings:
[Tractable Aggregation]theoremthmAggregation Let be a smooth and decomposable circuit representing a function . Then for any , it is possible to compute the aggregate as a smooth and decomposable circuit (i.e., ) in 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 [darwiche2011sdd]. In [vergari2021atlas] 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 (-compatibility) and also identify a new condition (-support-compatibility) that enables tractable products.
Definition 7 (-Compatibility).
Given two smooth and decomposable circuits over variables respectively, and a variable set , we say that are -compatible if for every product node and such that , the scope is partitioned in the same way, i.e. and . We say that are compatible if they are -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:
[Tractable Product - Compatibility]theoremthmCmp Let be compatible circuits over variables , respectively, and the same semiring. Then it is possible to compute their product as a circuit compatible with them (i.e., ) in time and space.
We remark that if we are given a fully factorized function , 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 -compatibility states that the scopes of the circuits restricted to 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 -Compatibility).
If two circuits are -compatible, then they are -compatible for any subset .
Compatibility is a sufficient but not necessary condition for tractable products. Some non-compatible circuits can be efficiently restructured to be compatible [zhang2024restructuring]. Alternatively, it is also known that some circuits can be multiplied with themselves in linear time, even when they are not structured decomposable [vergari2021atlas, huang2024causal]. We formalize this idea with a new property which we call support-compatibility.
Definition 8 (-Support Compatibility).
Given two smooth and decomposable circuits over variables respectively, and a set of variables , let be the DAGs obtained by restricting to nodes with scope overlapping with . We say that are -support-compatible if there is an isomorphism between such that: (i) for any node , ; (ii) for any sum node , whenever . We say that are support-compatible if they are -support-compatible.
To unpack this definition, we note that any smooth, decomposable, and -deterministic circuit is -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.
[Tractable Product - Support Compatibility]theoremthmSComp Let be support-compatible circuits over variables , respectively, and the same semiring. Then, given the isomorphism , it is possible to compute their product as a smooth and decomposable circuit support-compatible with them (i.e., ) in time and space.
We now examine the tractability of general elementwise mappings on a circuit . It is tempting here to simply construct a new circuit over the semiring with the same structure as , and replace each input function in the circuit with . However, the resulting circuit is not guaranteed to correctly compute in general. For example, consider the support mapping —which maps to and to —for the probability semiring . Then the transformation of the smooth and decomposable circuit produces , which evaluates to whereas . In order for this simple algorithm to be correct, we need to impose certain conditions on the elementwise mapping and/or the circuit it is being applied to.
[Tractable Mapping]theoremthmTractMap Let be a smooth and decomposable circuit over semiring , and a mapping such that . Then it is possible to compute the mapping of by as a smooth and decomposable circuit (i.e., ) in time and space if distributes over sums and over products.
distributes over sums if: either (Additive) is an additive homomorphism, i.e. ; or (Det) is deterministic.
distributes over products if: either (Multiplicative) is an multiplicative homomorphism, i.e. ; or (Prod 0/1) , and for all product nodes , and for every value , either or .
We can apply Theorem 8 to immediately derive the following property of support mappings:
Corollary 1 (Support Mapping).
Given a circuit over a semiring and any target semiring , a circuit representing can be computed tractably if (i) satisfies and is idempotent (i.e., ), or (ii) is deterministic.
Proof.
First note that satisfies (Multiplicative), and thus distributes over products. If (i) holds, consider . If , then this is equal to ; otherwise and (by idempotence of ). Thus satisfies (Additive). Alternatively, if (ii) holds, then (Det) holds. In either case distributes over sums in the circuit. ∎
The following examples illustrate the generality of elementwise mappings and Theorem 8:
Example 2 (Partition Function and MPE).
Given a probability distribution , consider the task of computing the partition function and MPE . These can be viewed as aggregations over the probability and semirings respectively.
is often either a probabilistic circuit , or a combination of a Boolean circuit and weights (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 semiring is idempotent so is tractable. On the other hand, the partition function for Boolean circuits and MPE for PCs require determinism for the conditions of Theorem 8 to hold; in fact, these problems are known to be NP-hard without determinism [darwiche2002knowledge, peharz2016latent].
Example 3 (Power Function in Probability Semiring).
For the probability semiring , consider the power function for some . 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 , it was shown in [vergari2021atlas] 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 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.
3.3 Tractable Composition of Operators
If the Input Circuit(s) are … | |||||||||||
Conditions | -Det | -Cmp w/ | -SCmp w/ | Complexity | |||||||
Then the Output Circuit is … (LABEL:appx:comp) | |||||||||||
Aggr. () | Sm, Dec |
|
|
|
(LABEL:appx:aggr) | ||||||
Product | Cmp | -Det | -Cmp w/ | N/A | (LABEL:appx:prod) | ||||||
SCmp | -Det | -Cmp w/ | -SCmp w/ | (LABEL:appx:prod-supp) | |||||||
Elem. Mapping |
|
-Det | -Cmp w/ | -SCmp w/ | (LABEL:appx:elem) |
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 -determinism, -compatibility, and -support-compatibility. We emphasize that these are not singular properties, but rather families of properties indexed by a variable set . We present the intuitive ideas behind our results below, while deferring full proofs to the Appendix.