Papers
Topics
Authors
Recent
Search
2000 character limit reached

Sum-Product Queries: Inference & Evaluation

Updated 11 July 2026
  • Sum-Product Queries are formal frameworks for exact inference, aggregating factorized terms with decomposable structures in various computational settings.
  • They enable efficient marginalization, conditioning, expectation, and MAP tasks in probabilistic models, databases, and graph networks.
  • Leveraging structural tractability, SPQs achieve polynomial-time exact evaluations by enforcing decomposability and smoothness across factors.

Sum–Product Queries (SPQs) are a family of inference and query-evaluation problems whose common form is an aggregation of factorized terms, typically written either as ν(f)=f(X)p(X)dX\nu(f)=\int f(X)\,p(X)\,dX in probabilistic models or as xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i}) over a commutative semiring. In the literature on Sum-Product Networks (SPNs), SPQs include marginalization, conditional probability, expectation, and MAP-style tasks; in the broader semiring literature, they also encompass satisfiability, constraint satisfaction, optimization, continuous integration, and database query evaluation. The unifying question is structural: under what conditions can these queries be answered exactly in polynomial time, and often in time linear in the representation size, rather than by approximation (Papež et al., 2024, Friesen et al., 2016).

1. Definitions and semantic scope

In SPNs, a sum–product query is any probabilistic inference task expressible as

ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,

where XX is the full set of random variables, p(X)p(X) is the model’s joint distribution, and f(X)f(X) is an “omni-compatible” function encoding the query. For discrete variables the integral becomes a sum. Two standard instances are marginalization,

p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),

and conditional probabilities with evidence E=eE=e,

p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.

This formulation emphasizes SPQs as exact probabilistic inference tasks over a tractable deep generative model (Papež et al., 2024).

A more general algebraic formulation treats SPQs over a commutative semiring (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes). If

xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})0

then the query is

xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})1

Under different semirings this same syntax captures probabilistic marginals, MPE, SAT, #SAT, soft CSP, continuous integration, and nonconvex global optimization. This semiring view is the basis for the claim that tractability is a structural property of the factorization rather than of a single probabilistic formalism (Friesen et al., 2016).

In database theory, the same pattern appears as a query over xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})2-relations: xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})3 with semantics

xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})4

Here the SPQ is a fixed hypergraph-shaped query evaluated on an input database xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})5, and the key parameters become fractional covers, decomposition plans, and space–time exponents rather than probabilistic normalizations (Deeds et al., 15 Sep 2025).

2. Structural conditions for tractability

The central tractability condition is decomposability. In the semiring formulation, a product node over factors xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})6 is decomposable when their scopes xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})7 are pairwise disjoint. The Sum-Product Theorem states that if every product in a factorized function is decomposable, then xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})8 can be computed in time xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})9, where ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,0 is the size of the representation. Conversely, if a product combines factors with overlapping scopes, then in the worst case the SPQ can require time exponential in the number of variables (Friesen et al., 2016).

For SPNs, decomposability is paired with smoothness. Decomposability requires that product nodes combine children with disjoint scopes; smoothness requires that the children of a sum node share the same scope. Under these conditions, SPNs support exact marginalization and partition-function computation in time linear in network size. The requirement that a sum’s weights form a valid mixture is an optional normalization for probabilistic semantics, but it is not needed for tractability itself (Friesen et al., 2016).

This distinction is important because expressive probabilistic models are not automatically tractable. A recurring misconception is that depth alone causes intractability. The SPN literature shows the opposite: an arbitrary number of hidden layers is compatible with exact inference, provided the products remain decomposable. The decisive issue is not depth but scope interaction across factors (Friesen et al., 2016).

The same structural principle reappears in graph models. GraphSPNs and Graph-Induced SPNs are presented precisely as tractable alternatives to graph generative models whose marginals and conditionals otherwise require importance sampling, MCMC, variational inference, or related approximations (Papež et al., 2024, Errica et al., 2023).

3. Exact evaluation algorithms and symbolic conditioning

The standard SPN algorithm for answering an SPQ is a bottom-up evaluation. Evidence or marginalization is incorporated at each input unit ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,1 by replacing its value with

ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,2

where ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,3 is either the full domain for marginalization or the observed value for conditioning. Product nodes compute

ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,4

sum nodes compute

ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,5

and the root output is ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,6. Because of decomposability and smoothness, this single bottom-up sweep yields the exact sum–product result in ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,7 time. A top-down pass can then propagate messages from the root to compute node-wise marginals or recover a maximum-probability configuration, again in time linear in network size (Papež et al., 2024).

The same exactness principle has been extended to symbolic probabilistic programming. SPPL translates probabilistic programs into sum-product expressions, a representation that extends standard SPNs to support mixed-type distributions, numeric transformations, logical formulas, and pointwise and set-valued constraints. It defines three core query forms: ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,8, ν(f)=f(X)p(X)dX,\nu(f)=\int f(X)\,p(X)\,dX,9, and XX0. The language is closed under conditioning: XX1 returns a new sum-product expression representing the conditional distribution. When the event is a simple conjunction on untransformed variables, the conditioning pass touches each node once, yielding runtime XX2 (Saad et al., 2020).

SPPL also formalizes the limits of tractability by imposing restrictions on programs: no unbounded loops, only univariate numeric transformations, and distribution parameters that are either constants or finite-support discrete. Within this fragment, exact symbolic inference can be substantially faster than prior symbolic systems; the reported evaluation includes up to 3500x speedups on targeted benchmarks such as fairness verification of decision tree classifiers, hidden Markov model smoothing, conditioning transformed random variables, and rare event probabilities (Saad et al., 2020).

4. Graph-structured SPQs

GraphSPNs generalize SPNs from fixed-size arrays to variable-size, exchangeable graphs XX3, where XX4 is a node-feature matrix and XX5 is an adjacency tensor. Because SPNs require fixed input size, GraphSPNs first choose an upper bound XX6 on the number of nodes and “virtually pad” any XX7-node graph with XX8 dummy nodes. The feature and adjacency alphabets are extended with a “null” symbol, and the padded graph is reshaped into a vector of length XX9 by row-concatenating p(X)p(X)0 and p(X)p(X)1. This vector is then processed by a standard tensorized SPN with tractable input, product, and sum layers (Papež et al., 2024).

Permutation invariance is enforced by canonical ordering. If p(X)p(X)2 is a canonical re-ordering, then

p(X)p(X)3

Since p(X)p(X)4 for any node permutation p(X)p(X)5, the resulting density is exactly permutation-invariant while requiring only a single SPN forward pass. The reported complexity for answering any SPQ is

p(X)p(X)6

with p(X)p(X)7 sorting overhead and p(X)p(X)8 upward evaluation. On QM9, with p(X)p(X)9, GraphSPNs with canonical ordering answered conditional-generation queries instantly and produced valid and novel molecules; the model was described as competitive to, and sometimes even better than, existing intractable models (Papež et al., 2024).

Graph-Induced SPNs (GSPNs) take a different route. Starting from an input graph f(X)f(X)0, GSPNs unfold a rooted computation tree f(X)f(X)1 of fixed height f(X)f(X)2 for each vertex f(X)f(X)3, attach an SPN to each tree node, and share template parameters across nodes at the same depth. The parent SPN’s parameters are learnable transformations of the a-posterior mixing probabilities of its children’s sum units. The resulting architecture preserves the tractable SPN semantics while mimicking message-passing computations (Errica et al., 2023).

For SPQs on GSPNs, each node performs one SPN evaluation and one SPN backpropagation to compute posterior responsibilities. The end-to-end complexity per forward-and-backward pass is

f(X)f(X)4

for fixed f(X)f(X)5, f(X)f(X)6, and template size. The reported experiments include scarce supervision, missing data, and graph classification. Table 7 compares GSPN to a 10-layer GIN with matched parameter count and reports forward times of f(X)f(X)7 ms versus f(X)f(X)8 ms and backward times of f(X)f(X)9 ms versus p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),0 ms on batches of size p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),1, consistent with the claim that tractability is obtained at a small constant-factor overhead relative to standard GNNs (Errica et al., 2023).

5. Query evaluation in databases and space–time trade-offs

In database settings, SPQs are evaluated over a query hypergraph whose vertices are variables and whose hyperedges are relation scopes. Fractional edge covers determine worst-case exponents, and the recent literature has shifted attention from time complexity alone to combined space–time complexity. One line of work defines several plan families—Generic-Join, Pseudo-Trees, Pseudo-Trees with Caches, Pseudo-Trees with Resets, Recursive Pseudo-Trees, and tree-decomposition plans—and assigns each plan p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),2 an exponent pair p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),3, where space is p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),4 and time is p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),5 (Deeds et al., 15 Sep 2025).

Plan family Mechanism Guarantee
Generic-Join p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),6 Variable order, worst-case-optimal intersections Time p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),7, space p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),8
Pseudo-Trees p(XQ)=XXQp(X),p(X_Q)=\sum_{X\setminus X_Q} p(X),9 Rooted recursion on variables E=eE=e0
Pseudo-Trees with Caches E=eE=e1 Memoized subqueries by context E=eE=e2
PTC with Resets E=eE=e3 Eager cache-filling and lexicographic resets E=eE=e4
Recursive PTs E=eE=e5 Recursive subplans below cache nodes E=eE=e6

These plan classes form a domination hierarchy,

E=eE=e7

and thereby organize a space–time frontier rather than a single optimality criterion. PTC can interpolate between E=eE=e8 with no cache and E=eE=e9 with a cache at every node; resetting can reduce the space exponent from p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.0 to p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.1 at a time cost. A practical implication is that the optimal time complexity is often achievable with asymptotically lower space complexity than traditional approaches (Deeds et al., 15 Sep 2025).

6. Lower bounds, limitations, and open questions

Exact SPQ evaluation is structurally tractable only for certain representations and query hypergraphs. In fine-grained complexity, this limitation is formalized through a semiring-oblivious reduction from p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.2-Clique to p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.3 for any fixed hypergraph p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.4 and any commutative semiring p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.5. The reduction is governed by the weak edge-depth p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.6 of embedding a clique into p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.7. If p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.8 is solvable in time p(XQE=e)=X{XQ,E}p(X)1{E=e}XEp(X)1{E=e}.p(X_Q\mid E=e)= \frac{\sum_{X\setminus\{X_Q,E\}} p(X)\,\mathbf 1\{E=e\}} {\sum_{X\setminus E} p(X)\,\mathbf 1\{E=e\}}.9, then the reduction yields an (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)0-time algorithm for (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)1-Clique (Fan et al., 2023).

This leads to the notion of clique-embedding power,

(Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)2

with

(Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)3

The quantity is decidable via a mixed integer linear program; the stated complexity is 2-EXPTIME in (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)4. The resulting lower bounds match known upper bounds for several families: cycles satisfy (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)5, Loomis–Whitney joins satisfy (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)6, (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)7 satisfies (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)8, (Y,,,e,e)(\mathcal Y,\oplus,\otimes,e_\oplus,e_\otimes)9 satisfies xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})00, and for chordal hypergraphs xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})01 (Fan et al., 2023).

Open questions remain. The “boat” query satisfies xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})02, leaving unresolved whether a faster algorithm exists or whether the lower bound can be strengthened. Other open problems concern whether the supremum defining xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})03 must be approached only as xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})04, whether computing xXi=1mfi(xSi)\bigoplus_{x\in\mathcal X}\bigotimes_{i=1}^m f_i(x_{S_i})05 can be done in better than 2-EXPTIME, and whether non-combinatorial lower bounds can be proved for field-valued or ring-valued semirings (Fan et al., 2023).

A final boundary concerns probabilistic modeling practice. Most deep generative graph models are intractable in the sense that they can sample and estimate likelihoods via Monte Carlo or variational bounds, but computing arbitrary marginals or conditionals requires approximations with no exactness guarantee and often slow mixing. GraphSPNs and related SPN-based constructions occupy a distinct niche: a fully generative graph model with tractable, exact inference for partial-observation queries, at the cost of a padding bound and a careful decomposable design (Papež et al., 2024).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Sum-Product Queries (SPQs).