AI Semiring
AI Semiring
Abstract
Many important problems in AI, among them #SAT, parameter learning and proba-
bilistic inference go beyond the classical satisfiability problem. Here, instead of finding a
solution we are interested in a quantity associated with the set of solutions, such as the
number of solutions, the optimal solution or the probability that a query holds in a solu-
tion. To model such quantitative problems in a uniform manner, a number of frameworks,
e.g. Algebraic Model Counting and Semiring-based Constraint Satisfaction Problems, em-
ploy what we call the semiring paradigm. In the latter the abstract algebraic structure
of the semiring serves as a means of parameterizing the problem definition, thus allowing
for different modes of quantitative computations by choosing different semirings. While
efficiently solvable cases have been widely studied, a systematic study of the computational
complexity of such problems depending on the semiring parameter is missing. In this work,
we characterize the latter by NP(R), a novel generalization of NP over semiring R, and
obtain NP(R)-completeness results for a selection of semiring frameworks. To obtain more
tangible insights into the hardness of NP(R), we link it to well-known complexity classes
from the literature. Interestingly, we manage to connect the computational hardness to
properties of the semiring. Using this insight, we see that, on the one hand, NP(R) is al-
ways at least as hard as NP or Modp P depending on the semiring R and in general unlikely
to be in FPSpace(poly). On the other hand, for broad subclasses of semirings relevant
in practice we can employ reductions to NP, Modp P and #P. These results show that
in many cases solutions are only mildly harder to compute than functions in NP, Modp P
and #P, give us new insights into how problems that involve counting on semirings can
be approached, and provide a means of assessing whether an algorithm is appropriate for
a given class of problems.
1. Introduction
Especially in the last decades, there has been a big influx of new quantitative problems
in AI as well as a largely increased interest in quantitative versions of well-known quali-
tative problems and their solution. Prototypical problems involve probabilistic reasoning
over Bayesian networks (Pearl, 1985, 2014; Heckerman, 2008; Niedermayer, 2008) or propo-
sitional theories (De Raedt, Kimmig, & Toivonen, 2007; Baral, Gelfond, & Rushton, 2009;
Lee & Yang, 2017; Sato & Kameya, 1997), counting the models of a logical theory (Valiant,
1979), learning the entailment relation of a logical theory (Khardon & Roth, 1997) or finding
©2023 The Authors. Published by AI Access Foundation under Creative Commons Attribution License CC BY 4.0.
Eiter & Kiesel
an optimal solution to a logical theory (Brailsford, Potts, & Smith, 1999; Erdem, Gelfond,
& Leone, 2016; Kautz & Selman, 1996; Li & Manyà, 2021). More recent advances go even
further than that by computing not only probabilities but also expected utilities (Van den
Berg, Van Bremen, Derkinderen, Kimmig, Schrijvers, & De Raedt, 2021; Van den Broeck,
Thon, Van Otterlo, & De Raedt, 2010) or by learning parameterized probability distribu-
tions (Manhaeve, Dumancic, Kimmig, Demeester, & De Raedt, 2019; Skryagin, Stammer,
Ochs, Dhami, & Kersting, 2021) in neuro-symbolic reasoning. Others introduced advanced
mechanisms to formulate preferences over models (Brewka, Delgrande, Romero, & Schaub,
2015; Ruttkay, 1994) or the ability to capture the lineage of data (Cui, 2002).
This list could be continued and already its length posed the question of how these
problems could be approached in a uniform manner. At this point semirings come into
play. These are algebraic structures R = (R, ⊕, ⊗, e⊕ , e⊗ ) consisting of a nonempty set R
of values together with two binary operations ⊕ and ⊗ called addition and multiplication,
respectively, having neutral elements e⊕ and e⊗ , respectively, that satisfy a set of axioms.
They provide an abstract, algebraic perspective of looking at quantitative computations.
As such, they are a well-suited basis for defining quantitative frameworks that uniformly
capture a multitude of problems by introducing semantics depending on a semiring parame-
ter. Indeed, Kimmig, Van den Broeck, and De Raedt (2017) and Belle and De Raedt (2020)
provide an extensive list of problems, including the ones mentioned above, that are easily
formulated by instantiating a semiring framework with different semirings. To name a few,
SAT corresponds to the Boolean semiring B; #SAT corresponds to the semiring of the nat-
ural numbers N; parameter learning corresponds to the gradient semiring (Manhaeve et al.,
2019); and expected utility computations are handled by the expectation semiring (Eisner,
2002).
This semiring paradigm, which allows us to introduce a multitude of quantitative ver-
sions of a qualitative problem in a uniform manner, was fruitfully used in a manifold of
ways, including but not limited to:
• Algebraic Model Counting (AMC) (Kimmig et al., 2017), which generalizes Weighted
Model Counting to work with semiring values as weights;
• Semiring-based Constraint Satisfaction Problems (SCSPs), which were shown to en-
compass Fuzzy CSPs, Probabilistic CSPs, Weighted CSPs and more, each correspond-
ing to SCSPs over some semiring (Bistarelli, Montanari, Rossi, Schiex, Verfaillie, &
Fargier, 1999);
• Answer Set Programming (ASP) with Algebraic Constraints (Eiter & Kiesel, 2020),
which is an extension of ASP that captures and generalizes many previous quantitative
extensions of ASP in a uniform manner;
• Provenance Semirings (Green, Karvounarakis, & Tannen, 2007), which were shown
to be a useful tool to express which-, why- and bag-why-provenance in the context of
positive relational algebra queries, by employing polynomial semirings;
• algebraic Prolog (Kimmig, Van den Broeck, & De Raedt, 2011), which is not only
available as an implementation for probabilistic logic programming, but also capable
of parameter learning and offers most probable explanation inference by employing
specialized semirings.
208
Semiring Reasoning Frameworks in AI and Their Computational Complexity
This naturally begs the question, already posed by Belle and De Raedt (2020), of how such
general frameworks with a semiring parameter be efficiently implemented.
Obtaining a solution that works for general semirings turns out to be feasible via knowl-
edge compilation (Mengel, 2021; Darwiche & Marquis, 2002). Kimmig et al. (2017) showed
that if the underlying logical theory is compiled into sd-DNNF representation T C, then
we can solve weighted model counting instances over any semiring using polynomially (in
|T C|) many additions and multiplications. This is also the strategy that current implemen-
tations like ProbLog (De Raedt et al., 2007), aspmc (Eiter, Hecher, & Kiesel, 2021) and
ProvSQL (Senellart, Jachiet, Maniu, & Ramusat, 2018) predominantly employ. As Kimmig
et al. (2017) also noted, depending on the specific semiring in use, this is clearly far from
the most efficient solution. Knowledge compilation to sd-DNNF allows one to solve #SAT
in polynomial time after compilation and is thus #P-hard. While this is less of an issue
when we are evaluating a problem over the semiring N of the natural numbers, which has
been shown to lead to #P-hardness, it is for instance an issue for the Boolean semiring B
leading to instances that are in NP. Toda’s Theorem (Toda, 1989) shows that not only NP
but even the whole polynomial hierarchy PH is contained in P#P[1] , i.e., each problem in
PH can be solved in polynomial time with a single call to an #P oracle (tantamount to
solving a single #SAT instance). This gives us the intuition that there is likely a large gap
between NP and #P and, thus, also between the semirings B and N.
We see that to answer the question of what an efficient implementation must look like,
we first need to understand how the computational complexity behaves depending on the
semiring parameter. Here, according to the best of our knowledge, current complexity
results for general semirings are still preliminary.1 Completeness results are only known for
a few specific semirings (Stearns & III, 1996), NP-hardness is only known over idempotent
semirings (Bistarelli et al., 1999) and the EXPTIME upper bound that follows from the
results of Kimmig et al. (2017) assumes that multiplication and addition can be done in
constant time.
Problems studied. In this paper, we therefore take a closer look at the computational
complexity of reasoning frameworks that depend on a semiring parameter such as the ones
above. For this purpose, we first introduce a new machine model called Semiring Turing
Machines (SRTMs) that can solve sum-of-product like problems over semirings while us-
ing the semiring in a black-box fashion. Based on SRTMs we introduce NP(R), the class
of problems solvable by a polynomial time SRTM over semiring R. As the name sug-
gests, NP(R) is a generalization of NP to computations with semirings. It also features
SAT(R), a generalization of SAT over semirings, as a canonical complete problem. Apart
from shedding light on how computations over semirings relate to the classical model of
computation using (non-deterministic) Turing machines, NP(R) and SAT(R) are basic
tools for the characterization of the computational complexity associated with evaluation
over semirings.
Following the introduction of NP(R) and SAT(R), we immediately make use of these
tools to characterize the complexity of a wide variety of semiring frameworks depend-
ing on their semiring parameter. Interestingly, while most frameworks turn out to be
1. This does not extend to the field of fixed-parameter-tractability. There is a wide range of results for
semiring frameworks in this area, cf. (Ganian, Kim, Slivovsky, & Szeider, 2022; Friesen & Domingos,
2016; Bacchus, Dalmao, & Pitassi, 2009)
209
Eiter & Kiesel
NP(R)-complete as expected and thus in a sense equally hard, provenance-queries for dat-
alog (Green et al., 2007) are NP(R)-hard but provably not complete. This already shows
the utility of our toolbox for the comparison of the intrinsic difficulty of different semiring
problems.
However, since SRTMs are a purely hypothetical machine model, this alone only serves
for a comparative analysis but does not give us any tangible insights into the computational
complexity we need to expect in practice. Therefore, we follow up by relating SAT(R) to
classical complexity classes, such as NP (Cook, 1971), #P (Valiant, 1979), OptP (Krentel,
1988), GapP (Fenner, Fortnow, & Kurtz, 1994) and Modp P (Hertrampf, 1990). This allows
us to make statements about how difficult SAT(R) is at least by showing C-hardness, which
among other insights may allow one to assess how far at most a given algorithm is from a
worst-case optimal one. Furthermore, by showing membership in some complexity class C
we can also bound the resource requirements of an algorithm to solve SAT(R).
Naturally, an interesting question is where the hardness associated with a semiring comes
from. The intuition conveyed by our results is that it depends mostly on two factors. The
first factor is the encoding of the values of the semiring. This phenomenon is well known for
the Knapsack problem, which is pseudo-polynomial, i.e., polynomial for the unary encoding
of the integers but NP-hard for the binary encoding of integers. The second factor is the
amount and kind of information that persists in values of the given semiring when they are
added and multiplied; this was already shown to be a discerning factor for the complexity
of conjunctive query containment over data annotated with semiring values (Green, 2011).
For the Boolean semiring B, this information is merely whether there exists a solution; for
the semiring of natural numbers N, it is the number of solutions; and even harder semirings
like polynomial semirings R[(xi )α ] can amalgamate the result of many queries to an NP-
or #P-oracle into one value, when the coefficients are from B and N, respectively.
The difficulty caused by the encoding is not inherently connected to the difficulty as-
sociated with the semiring since different encodings can lead to different complexities over
the same semiring. Therefore, we focus on the second complexity source of a semiring,
i.e., the amount of information captured by its values. In order to avoid interference of
the complexity due to the encoding, we assume efficiency restrictions on the encoding when
necessary. By conducting an analysis of structural properties of semirings and their implica-
tions on information preservation, we manage to provide a tetrachotomy for the complexity
of non-trivial semirings, i.e., we split them into four distinct classes that can all be related
to (although not shown to be complete for) the same complexity class. Intuitively, we
show that for non-trivial semirings the problems over them are either NP-like, Modp P-like,
Modp P ∪ NP-like or #P-like. This C-likeness is reflected in a variety of results, ranging
from C-hardness to non-reducibility to polynomially many C-oracle calls in the general case,
to reducibility to polynomially many C-oracle calls in other, more restricted cases.
Contributions. The main contributions in this paper are briefly summarized as follows:
• We introduce Semiring Turing Machines and show that SAT(R), SCSPs, AMC,
weighted first-order formula evaluation over R, as well as some other problems are
NP(R)-complete for every semiring R, where NP(R) is a novel analog of NP over
semirings. This not only characterizes the computational complexity of these prob-
lems but also provides the base of a toolbox for analyzing the complexity of semiring
210
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Apart from the knowledge gain that our results provide directly, they have immediate
further uses. First, they make the complexity analysis for specific semirings significantly
easier. One example of this is the gradient semiring GRAD, which is used for parame-
ter learning (Kimmig et al., 2017; Manhaeve et al., 2019). By applying our results, we
demonstrate in Section 8 how one may easily prove that it leads to #P-complete prob-
lems. Second, we recall the question of Belle and De Raedt (2020) regarding the efficient
implementation of semiring frameworks depending on the semiring parameter. The authors
suspected that it is neither practical to provide a specific solver for each semiring nor effi-
cient to have one solver that does not differentiate between the semirings. For this reason,
Belle and De Raedt proposed a hybrid approach, in which the evaluation strategies are
adapted for a few different classes of semirings. Indeed, our tetrachotomy results provide
211
Eiter & Kiesel
tangible evidence that the hybrid approach is preferable. On top of that, they furthermore
provide
• a set of properties that separates the semirings into reasonable classes, and
• concrete reductions that can be used as a starting point for an implementation.
2. Preliminaries
We start by giving the necessary preliminaries. Throughout this paper, we assume knowl-
edge of the basics of propositional logic. In this context, we consider propositional theories
T over a set V of Boolean variables (i.e., propositional atoms) using the Boolean connectives
∨, ∧, and ¬ for disjunction, conjunction, and negation, respectively; further connectives, e.g.
material implications →, may be defined as usual. Furthermore, ⊥ and > are shorthands
for an unsatisfiable (false) and a tautologic (true) formula, respectively. For interpretations
of T , we consider subsets I of V ∪ {¬v | v ∈ V} such that ¬v ∈ I iff v 6∈ V. Satisfaction
of formulas, theories φ etc. by an interpretation I is then defined as usual and denoted by
I |= φ.
Apart from that, we need semirings.
Definition 1 (Semiring). A semiring R = (R, ⊕, ⊗, e⊕ , e⊗ ) consists of a nonempty set R
equipped with two binary operations ⊕ and ⊗, called addition and multiplication, where
• (R, ⊕) is a commutative monoid with identity element e⊕ ,
• (R, ⊗) is a monoid with identity element e⊗ ,
• multiplication left and right distributes over addition, and
• e⊕ annihilates R, i.e. ∀r ∈ R : r⊗e⊕ = e⊕ = e⊕ ⊗r.
Here, a monoid M = (M, , e ) consists of a nonempty set M , with a binary operation
and an element e such that
• is associative, i.e.,
for all m1 , m2 , m3 ∈ M it holds that m1 (m2 m3 ) = (m1 m2 ) m3 ;
212
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Furthermore, a semiring R is
• F = (F, +, ·, 0, 1), for F ∈ {N, Z, Q, R}, the semiring of the numbers in F with addition
and multiplication. These semirings are all commutative but not idempotent.
• Rmax = (N ∪ {−∞}, max, +, −∞, 0), Rmin = (N ∪ {∞}, min, +, ∞, 0), the tropical
semirings. These semirings are both commutative and idempotent.
• B = ({0, 1}, ∨, ∧, 0, 1), the Boolean semiring, which is both commutative and idem-
potent.
Example 1. N, the semiring of the natural numbers, is generated by {1} or even by the
empty set. The same holds for the Boolean semiring. On the other hand, the semiring Q
of the rational numbers needs more elements to be generated. {1/n | n ∈ N} is a possible
generator.
For our complexity considerations we need problem reductions. Since we are studying
functional complexity, we use the following notions of reductions.
213
Eiter & Kiesel
• a counting reduction is a metric reduction such that T2 (x, y) = T2 (x0 , y) for all x, x0 , y.
• a Karp reduction is a metric reduction such that T2 (x, y) = y for all x, y.
Also, we use some well-known complexity classes.
• #P (Valiant, 1979) (resp. GapP, Fenner et al., 1994): the functions definable as
the number of accepting paths (resp. minus the number of rejecting paths) of a
nondeterministic polynomial time Turing Machine (NTM);
• OptP (Krentel, 1988): the functions definable as the maximum output of a polyno-
mial time NTM;
• FP: the functions computable in polynomial time;
• FPCk (Jenner & Torán, 1995): the functions computable in polynomial time with
parallel queries to a C oracle, where C is a complexity class;
• FPSpace(poly) (resp. FPSpace(exp)): the functions computable in polynomial
space with polynomial (resp. unrestricted and thus exponential) size output;
• C/poly (Karp & Lipton, 1982): the problems solvable in C with polynomial advice,
where C is a complexity class, i.e., there is a function f such that we can solve the
problem for all inputs x in C given x, f (|x|), where |x| denotes the length of the input
and |f (x)| ∈ O(|x|k ) for constant k ∈ N;
• Modp P (Hertrampf, 1990): the languages L described as x ∈ L iff f (x) 6≡ 0 mod p
for some f in #P;
C [f (n)]
• C1 2 : the problems solvable in C1 with at most f (n) calls to a C2 oracle, where C1
and C2 are complexity classes. Here, C1 is a Turing machine based complexity class
(such that an oracle makes sense);
• BPP (Gill, 1977): the languages L for which some NTM T exists such that if x ∈ L
at least 2/3 of the computation paths of T on x accept and if x 6∈ L at most 1/3 of the
computation paths of T on x accept.
The exact relationship between the different complexity classes is often unclear. However,
it is known that #P, OptP, Modp P and NP are contained in FPSpace(poly). Apart
from that, #P is considered to be at least as hard as NP and Modp P, as we can obtain
the solution of a problem in NP or Modp P via one #P-oracle call. As for the relationship
between NP and Modp P, it is known that NP ⊆ BPPModp P (Bennett & Gill, 1981). In
regards to the power of Turing machines with advice, we note that the advice function
does not need to be computable and thus, P/poly contains some undecidable problems.
Nevertheless, the power of advice is limited: if NP ⊆ P/poly or #P ⊆ FP/poly then the
polynomial hierarchy collapses to a finite level (Karp & Lipton, 1980), which is considered
to be unlikely. On the other hand, it is known that BPP ⊆ P/poly (Bennett & Gill, 1981).
Hardness and completeness are defined as usual:
Definition 4 (Hardness, Completeness). A problem P is C-hard for a complexity class C
under X-reductions, if every problem P 0 ∈ C can be reduced to P by some X-reduction; P
is C-complete under X-reductions, if in addition P ∈ C.
214
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Algebraic Model Counting The first framework we consider is Algebraic Model Count-
ing (AMC), introduced by Kimmig et al. (2017). Intuitively, it is a generalization of weighted
model counting for propositional formulas, with weights that can be values from a semiring.
That is, we take a sum over all interpretations that satisfy a propositional theory T ,
where each addend is a product of the weights of the literals satisfied by the interpretation.
Contrary to weighted model counting, where sum and product need to be the usual addition
and multiplication over the reals, they can be from any semiring here. The same holds for
the weights, which also do not necessarily need to be reals.
Besides the standard applications in SAT, #SAT, and probabilistic inference, the au-
thors showed that AMC can be used to perform sensitivity analysis of probabilistic inference
w.r.t. a parameter by using the semiring of the polynomials with coefficients in [0, 1]. For
more semirings that allow additional applications, like the construction of tractable circuit
representations, we refer the reader to Kimmig et al. (2017).
We see that regardless of the specific semiring, some of the structure stays the same:
Similarly to SAT, MaxSAT and #SAT, we guess an interpretation, obtain a value based
on the truth of the literals and their relation to the propositional theory and in a last step
perform some form of aggregation operation over all interpretations. In the case of SAT,
this corresponds to checking whether a given assignment satisfies the theory and aggregating
these values by quantifying existentially over all possible interpretations. For MaxSAT on
the other hand, we associate a number with a given interpretation and aggregate these
values by taking the maximum.
215
Eiter & Kiesel
* aa 7→ 1 +
ab 7→ 2 a 7→ 5
c1 = , {x, y} , c2 = , {y} .
ba 7→ 3 b→7 6
bb 7→ 4
Together they define the constraint problem C = h{c1 , c2 }, {x, y}i.
The two main operations on constraints are combination ∗ and projection ⇓.
Definition 7 (Combination, Projection). For t = (dx )x∈con and con0 ⊆ con the projection
t ↓con
con0 is equal to (dx )x∈con0 .
The combination c1 ∗ c2 of two constraints ci = hdef i , coni i, i = 1, 2 is the constraint
c = hdef , con1 ∪ con2 i, where
1 ∪con2 con1 ∪con2
def (t) = def 1 (t ↓con
con1 )⊗def 2 (t ↓con 2
)
Intuitively, combination ∗ is the product (⊗) of constraint values and projection ⇓con0 is
the sum (⊕) over all assignments to the variables in con \ con0 . Combination, as the name
says, combines multiple constraints into one, and projection partially evaluates a constraint
thus removing variables from the constraint.
Example 3. The combination c1 ∗ c2 of c1 , c2 is
* aa 7→ 1⊗5 + * aa 7→ 1 + 5 + * aa 7→ 6 +
ab 7→ 2⊗6 ab 7→ 2 + 6 ab 7→ 8
, {x, y} = , {x, y} = , {x, y} .
ba 7→ 3⊗5 ba 7→ 3 + 5 ba 7→ 8
bb 7→ 4⊗6 bb 7→ 4 + 6 bb 7→ 10
The projection c1 ⇓ {x} of c1 down to {x} is
a 7→ 1⊕2 a 7→ min(1, 2) a 7→ 1
, {x} = , {x} = , {x} .
b 7→ 3⊕4 b 7→ min(3, 4) b→7 3
216
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Definition 8 (Consistency-Level). Given an SCSP problem P = hC, coni, the best level of
consistency of P is defined as blevel(P ) = (Πc∈C c) ⇓∅ . Here, Π in the expression Πc∈C c
is used for application of ∗ to all constraints c in C.
So the consistency level can be computed by first combining all constraints (using ∗)
and then projecting onto the empty set (using ⇓∅ ).
* aa 7→ 6 +
ab 7→ 8
, {x, y} ⇓∅ = ε 7→ min(6, 8, 8, 10) , ∅ .
ba 7→ 8
bb 7→ 10
Here, the last expression evaluates to 6, meaning that the consistency level blevel(C) is 6.
Again, we observe a similar structure regardless of the semiring: we can compute the
blevel of a constraint problem P = hC, coni by guessing an assignment to the variables in
con, by evaluating the constraints under the given assignment, taking the product, ⊗, of
their values for that assignment and aggregating the results for each assignment using the
sum, ⊕, of the semiring. This structure is strikingly similar to the approach we can use
to evaluate AMC instances. While the guessed part here is an assignment to multi-valued
variables instead of an interpretation, for both frameworks, we can evaluate an instance by
Using this insight into the structure of the evaluation problems associated with semiring
frameworks, we can now approach the characterization of their complexity.
217
Eiter & Kiesel
is then defined as the sum of the values of all computation paths. Based on SRTMs, we can
then define NP(R), a generalization of NP over semirings.
Putting things together, we prove SAT(R) to be NP(R)-complete under Karp reduc-
tions, thus allowing us to use it as a canonical problem to reduce from, for NP(R)-hardness
proofs.
Furthermore, we consider other alternative ways to generalize NP to a quantitative set-
ting. We highlight the differences in computational power caused already by small changes
to our model and, by this, justify the definition of NP(R) that we chose.
JkKR (I) = k
e⊗ l∈I
JlKR (I) = (l ∈ {v, ¬v})
e⊕ otherwise.
Jα1 + α2 KR (I) = Jα1 KR (I)⊕Jα2 KR (I)
Jα1 ∗ α2 KR (I) = Jα1 KR (I)⊗Jα2 KR (I)
JΣvαKR (I) = JαKR (Iv )⊕JαKR (I¬v )
JΠvαKR (I) = JαKR (Iv )⊗JαKR (I¬v )
218
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Even though we restrict ourselves to ΣBFs, they at first glance seem to be different from
the propositional formulas describing a SAT-instance. Namely, for SAT the quantifier Σ
is implicit since all variables that occur in the SAT-instance are existentially quantified.
For SAT(R), however, this is not the case. Here, we can quantify a variable using Σ in
subexpressions of + and ∗, e.g., formulas like α+Σvβ and Σvα∗Σwβ are allowed. Requiring
all quantifiers to occur outside of subexpressions of + and ∗ is not a semantic restriction
however:
Lemma 11 (Prefix Normal Form). For every ΣBF α over a commutative semiring R there
exists a ΣBF β over R such that
(iii) JαKR (∅) = JβKR (∅), i.e., α and β evaluate to the same value.
Proof (Sketch). This statement can be proved by induction on the number of sum quantifiers
Σ that occur in the subexpression of some other connective + or ∗. The base case is clear,
for the induction step, we show that (Σvα1 ) ∗ α2 is equivalent to Σv(α1 ∗ α2 ) by assuming
w.l.o.g. that α2 does not contain v and that (Σvα1 ) + α2 is equivalent to Σv(α1 + α2 ∗ v)
under the same assumption.
This way the connection between SAT and SAT(R) becomes clearer. In fact, as with
AMC, many versions of SAT can be seen as special cases of SAT(R) for different semirings
R.
Example 5. Over B, the Boolean semiring, SAT(B) is equivalent to SAT: On the one
hand, given a SAT(R)-instance β = Σv1 . . . Σvn γ, where γ is quantifier free, we see that
JβKB (∅) = 1 iff the propositional formula φ obtained from γ by replacing every 0, 1, +, ∗ with
⊥, >, ∨, ∧, respectively, is a yes instance of SAT, i.e., satisfiable.
On the other hand, given a SAT-instance φ, we see that a propositional formula φ in
NNF is satisfiable if the SAT(B)-instance β = Σv1 . . . Σvn γ fulfills JβKB (∅) = 1. Here, γ is
obtained from φ by replacing every ⊥, >, ∨, ∧ with 0, 1, +, ∗, respectively, and {v1 , . . . , vn }
is the set of variables occurring in φ.
Another, more interesting example is LexMaxSAT, the problem of obtaining the lex-
icographically maximum satisfying assignment for a propositional formula φ. W.l.o.g. we
assume that φ is in NNF. We can reformulate LexMaxSAT as a SAT(Rmax )-instance β
over the max-tropical semiring Rmax , where the corresponding instance β is given by
219
Eiter & Kiesel
These examples show that we can use SAT(R) over different semirings R to express
different versions of SAT. Moreover, we observe that problems described by a ΣBF of the
form
β = Σv1 . . . Σvn γ, where γ is quantifier free,
are again structurally similar to the other problems following the semiring paradigm. That
is, the value JβKR (∅) is obtainable by guessing an interpretation I of the variables v1 , . . . , vn ,
evaluating γ using the interpretation, and aggregating the values JγKR (I) using the sum,
⊕, of the semiring.
This guess-evaluate-aggregate pattern is also similar to definition of complexity classes
such as NP, #P and OptP in terms of non-deterministic Turing machines. Based on this
intuition we will next provide NP(R) a generalized version of NP, which also depends on
a semiring parameter, to abstractly characterize the complexity of SAT(R).
On the other hand, too much power should be avoided; to this end, we relegate semiring
computations to weighted transitions.
• R is a commutative semiring,
• R0 ⊆ R is a finite set of semiring values, (intuitively, this is a set of fixed values that
are “known” to M )
220
Semiring Reasoning Frameworks in AI and Their Computational Complexity
As usual, −1 and 1 move the head to the left and right. Intuitively, the combination
of the second and third condition ensures that when an SRTM reads a semiring value r in
a given state then it always, independently of the value at hand, makes a transition with
weight r or with a constant value from the finite set R0 . Note that this “or” is not exclusive.
Having access to some constants is necessary, since every transition is assumed to have a
weight. Additionally, these constants allow us to use semiring values that do not occur in
the input. This is important since otherwise we cannot always multiply partial solutions by
constant factors or even return a constant value.
Importantly, this allows us to always represent the transition function finitely by group-
ing the transitions at state q1 when a semiring value is read to
((q1 , X), (q2 , X), d, X) and ((q1 , X), (q2 , X), d, r),
where X is a placeholder representing any (although the same in all occurrences in the
expression) semiring value and r ∈ R0 .
We remark that in terms of control flow, i.e., “if”-statements, loops, recursive definitions,
etc., SRTMs feature the same possibilities as non-deterministic Turing machines, since the
difference between the two models of computation regarding the transition function δ is
that for SRTMs it is weighted and has some restrictions on the weights. Therefore, we can
use the typical control flow instructions also with SRTMs.
The output of a computation is as follows.
Definition 13 (SRTM function). The value v(c) of an SRTM M on a configuration c =
(q, x, n), where q ∈ Q is a state, x ∈ (Σ ∪ R)∗Lis the string on the tape, and n ∈ N is the
0 r 0
head position, is recursively defined by v(c) = c→cr 0 r⊗v(c ), where c → c denotes that M
can transit from c to c0 with weight r; the empty sum has value e⊗ . The output of M on
input x is v(ι, x, 0).
In other words, this means that the output of an SRTM M is calculated by aggregating
the value vπ of each non-deterministic computation path π using the addition ⊕ of the
semiring R. Here, the value vπ of a non-deterministic computation path π along configu-
r1 rn(π)−1
rations c1 → . . . → cn(π) is given by r1 ⊗ . . . ⊗rn(π)−1 , i.e., by multiplying the weights of
the single transition steps.
Example 6 (SRTM Computation). Consider Algorithm 1, which sketches in pseudocode
the working of an SRTM that solves SAT(R). The computation tree2 of EvalN (α, ∅) with
2. Naturally, we left out transitions with weight 1 for the checks of the if and switch statements.
221
Eiter & Kiesel
α = Σvv ∗ 3 is given in Figure 1. Its initial configuration c0 is the root node of the tree.
Since the SRTM is over the natural number semiring N, the leaves c0.0.0.0 , c0.1.0.0 , i.e., the
configurations without a successor, have the value e⊗ = 1.
The values of their predecessors c0.0.0 and c0.1.0 are both 3 · 1 = 1. It is calculated as the
value of their successor (1) and the weight of the transition, which is 3 in both bases since
the SRTM reads the subformula α = 3 in either case. At their predecessors c0.0 and c0.1 , we
observe a difference in values, i.e., v(c0.0 ) = 0 and v(v0.1 ) = 3, since the SRTM reads the
subformula α = v here and thus transitions either with weight e⊗ or e⊕ depending on the
guess of the value of v in the respective branch. c0.0 and c0.1 have as a common predecessor
the initial configuration c0 . Here, a formula of the form α = Σvα is read and thus both
transitions from c0 to c0.0 and to c0.1 , have weight 1. They correspond to guessing v to be
false and true, respectively. As such, the output value is given by 3.
As we can see, this definition of SRTMs also follows the aforementioned guess-evaluate-
aggregate pattern. With this in place, we define an analog of NP.
Definition 14 (NP(R)). NP(R) is the class of all functions computable in polynomial
time by an SRTM over R.
Here, we choose the name NP(R) to highlight the tight connection to NP, which stems
from the fact that (as we will see later) NP can be seen as NP(B). Indeed, the underlying
idea of SRTMs and NP(R) is to proceed in the same manner as when generalizing a Boolean
logic to a weighted logic. That is, we add weights and replace disjunction by addition and
222
Semiring Reasoning Frameworks in AI and Their Computational Complexity
c0 v(c0 ) = 1 · 0 + 1 · 3
1 1
0 1
3 3
r
Figure 1: A computation tree over N. Each transition c → c0 is annotated with its weight
r and each configuration c is annotated with its value v(c).
conjunction by multiplication over the semiring. Since over the Boolean semiring B the
addition is disjunction and the multiplication is conjunction, solving a problem in NP(B) is
to check whether there exists a non-deterministic computation path with non-zero weight,
i.e., which accepts. The same holds for problems in NP.
Note that NP(R) as it follows from our definition of SRTMs is only some analog of
NP over semirings, and we do not claim that it is the only reasonable one. However, first
and foremost, our goal with this definition is to obtain a complexity class that characterizes
the computational complexity of SAT(R) and other related problems. This succeeds, as
indeed SAT(R) is NP(R)-complete. However, in order to formally state the result we first
need to establish how reductions work in this context, given that we allow semiring values
on the tape explicitly.
where S, V, E 6∈ Σ are distinguished letters such that in SV n E the letter S denotes the start,
the string V n denotes the index n, and E denotes the end of a surrogate (for a semiring
value). For a substitution σ : N → R and a word x ∈ sS,V,E (Σ), we denote by σ(x) the word
in (Σ ∪ R)∗ obtained by replacing SV n E with σ(n).
The idea here is that we refer to surrogates SV E, . . . , SV n E for variable semiring values
instead of actual semiring values r1 , . . . , rn . Thus, we know of the presence of semiring values
but not which semiring value is represented exactly by the surrogate.
Using the surrogate alphabet, we adapt Karp reductions to the context of SRTMs.
223
Eiter & Kiesel
Intuitively, the idea behind surrogate-reductions is that as with SRTMs, we cannot mod-
ify semiring values, make decisions based on them etc. Therefore, also surrogate reductions
must not be able to modify semiring values, produce different outputs based on them etc.,
as this would mean that reductions would have more power than SRTMs, which we need to
avoid if NP(R) should be closed under reductions. The set R0 serves to distinguish semiring
values that should be constant. Instead we can only modify the instance specification that
tells us how we should combine (using sum and product) the semiring values to obtain a
solution from one that is expected by f1 to one that is expected by f2 .
Nevertheless, a reduction T at least needs to be able to transfer the semiring values that
are used in the original instance x to the instance T (x). For this reason, we give T access to
surrogates SV n E for semiring value occurrences such that T can intuitively “copy” semiring
values to another position but cannot do more.
While this is a strong restriction, we will show in Theorem 18 that this suffices to reduce
any problem in NP(R) to SAT(R) for any commutative semiring R.
Surrogate-reductions are appropriate for our setting:
Proof. Let T be the reduction function and R0 = {r1 , . . . , rk } the associated set of semiring
constants. Let M = (R, RM 0 , Q, Σ, ι, t, δ) be an SRTM that solves f . We construct an
2
SRTM M = (R, RM ∪ R , Q0 , Σ0 , ι0 , t0 , δ 0 ) that solves f1 . Note that we give M 0 access to
0 0 0
both RM0 , the set of semiring constants from M , and R0 , the set of semiring constants, fixed
in the reduction.
While SRTMs cannot distinguish different semiring values, they can check whether
there is a semiring value on the tape in a given position. Thus, given some input x ∈
(Σ ∪ R)∗ we can obtain in polynomial time a string x0 ∈ sS,V,E (Σ) from x by using
SV n+k E for the nth semiring value occurrence in x (from left to right). E.g. the string
x = x1 x2 x3 r1 x4 x5 r2 ∈ (Σ ∪ R)∗ , where x1 , . . . , x4 ∈ Σ and r1 , r2 ∈ R, leads to the string
x0 = x1 x2 x3 SV Ex4 x5 SV V E ∈ sS,V,E (Σ) when k = 0. Then, we can apply T to x0 in
polynomial time. Finally, we can execute the algorithm for f2 on T (x0 ). Here, we only need
polynomial extra time to look up the (n − k)th semiring value in the original input when we
need to make a transition with a semiring value under the head and read SV n E for n > k.
For n ≤ k we cannot transition with a weight under the head, since rn does not necessarily
occur in x. However, since we added R0 to the set of constants that M 0 has access to, we
can simply specify a transition with weight rn directly.
With this in mind, we can finally state the main result of the section.
224
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Theorem 18. SAT(R) is NP(R)-complete w.r.t. Karp s-reductions for every commutative
semiring R.
225
Eiter & Kiesel
Example 7 (Separating Function I). The function f : {0, 1}∗ → N[(xi )∞ ], f (w) = x1 +x2 +
· · · + x2|w| cannot be Karp reduced to NP(N[(xi )∞ ]) using an encoding e : N[(xi )∞ ] → Σ∗ in
some appropriate alphabet Σ = {0, 1} ∪ {. . . }, where coefficients, exponents and indices are
encoded in binary, and a polynomial is encoded as a list of the encodings of the monomials.
Assume that on the contrary, αw is the SAT(N[(xi )∞ ])-instance corresponding to input w to
f . Then αw needs to contain each of the monomials x1 , . . . , x2|w| and is therefore necessarily
of size exponential in |w|. Since Karp reductions must be computable in polynomial time,
this is impossible.
On the other hand, when we explicitly write semiring values in encoded form on the
alphabet of a TM, we can guess 1 ≤ i ≤ 2|w| and return xi . Then the sum of all computation
paths is f (w).
Example 8 (Separating Function II). Consider the machine over the semiring N that takes
as input a pair (k, x), where k ∈ N and x ∈ {0, 1}∗ has length |x| = n, and computes a
semiring value as output as follows: first, it sets x1 = k and then iteratively sets xi+1 = xi ∗xi
n
for i = 2, . . . , n. Then the output of the machine is xn = k 2 . This computation is possible
if we allow computations on the tape as described above. On the other hand, every Karp s-
reduction from (k, x) to a SAT(N)-instance α satisfies that JαKN (∅), the result of evaluating
c c
α, is in O(k O(n ) ·2O(n ) ), where c is a constant. This is because we can only use the semiring
value k in α when using s-reductions and since we know that any SAT(N)-instance α has
a value in O(maxr∈α r|α| · 2|α| ).
Note that interestingly, in a circuit version of SAT(N) we are able to express the value
n
k 2 for k ∈ N using an instance of size polynomial in n as they also allow reuse of partial
results multiple times. This also implies that even though CircuitSAT and SAT are Karp-
reducible to one another, the same is in general not the case for SAT(R) and its circuit
version.
Nevertheless, by restricting the semiring computations on the tape to be non-recursive,
i.e., by only allowing the use of intermediate results only once, this problem is avoided. With
this restriction in place the two definitions would result in two machine models with the
same power that can simulate each other. Since, however, the non-recursiveness restriction
is a semantic rather than a syntactic one (and thus harder to verify and enforce) we prefer
our original definition.
Allowing Decisions Based on Semiring Values Recall that Condition 3. on the
weighted transition function δ requires that for each ((q1 , σ1 ), (q2 , σ2 ), e, r) ∈ δ,
σ1 ∈ R ⇒ [∀σ10 ∈ R : ((q1 , σ10 ), (q2 , σ10 ), e, σ10 ) ∈ δ] ∨ [∀σ10 ∈ R : ((q1 , σ10 ), (q2 , σ10 ), e, r) ∈ δ].
Therefore, we cannot distinguish different semiring values that are on the tape during the
computation. That is, we cannot draw conclusions about the semiring value on the tape
based on the state q2 we transition to or based on the symbols on the tape that are non-
semiring values. Furthermore, we cannot distinguish semiring values on the tape based
226
Semiring Reasoning Frameworks in AI and Their Computational Complexity
on the weight of the transitions they are involved in, if the weight is not the semiring
value itself but a constant from R0 . SRTMs without this property may not necessarily be
finitely specified. Apart from that, having the ability to take different transitions based on
the semiring value would allow an SRTM over semiring values from {0, 1}∗ to distinguish
strings that encode halting Turing machines from strings that do not, in constant time.
This is obviously not desirable.
Allowing Semiring Values to be Written Also the first restriction on the weighted
transition relation, which constitutes that we cannot write new semiring values to the tape
or change existing ones, may seem questionable at first glance. Allowing to write or change
semiring values in an unrestricted manner would allow us to distinguish semiring values.
We already described previously why this would be undesirable. However, it is possible to
allow for writing and changing of semiring values on the tape under restrictions such as
only allowing to copy values or write values from a finite set. This would neither lead to
additional power nor would it make the specification of SRTM machines simpler. Therefore,
we chose this simpler version of the definition of SRTMs and only note that this restricted
form of writing semiring values can be simulated.
227
Eiter & Kiesel
Nevertheless, if the functions fi in the expression (1) are given explicitly as key value
pairs of variable assignments and semiring values, we obtain:
Theorem 20. SAT(R) is Karp s-reducible to SumProd(R) and vice versa for every com-
mutative semiring R. Thus, SumProd(R) is NP(R)-complete w.r.t. Karp s-reductions.
In the Boolean case, i.e. R = B, SumProd(R) essentially corresponds to Constraint
Satisfaction Problems (CSP). Here, the reduction from SAT(R) to SumProd(R) borrows
from the fact that 3SAT is NP-complete. However, for semirings in general establishing
this result is more difficult, since the Tseitin-transformation (Tseitin, 1983), which is used
for the proof that 3SAT is NP-complete, does not work anymore in the same way. The idea
of the Tseitin-transformation is to introduce a new variable aβ for a complex subformula β
such that aβ takes the value of β. In the Boolean case, we recall that this is established by
means of the formula aβ ↔ β. In our case, the value of a subformula β may not only be >
or ⊥ as in the Boolean case but can take one of exponentially many different values in the
size of β. So, while we could introduce variables aβ,r that are true iff β evaluates to r, this
would lead to an exponential explosion and is, thus, not helpful for proving the existence
of a Karp s-reduction.
Instead, we need to exploit the distributive law. While naive application of it also leads
to a formula of exponential size, we can avoid this by exploiting the distributivity implicitly
during evaluation as in Algorithm 1. Intuitively, the idea here is to introduce new variables
aβ1 , aβ2 for each non-deterministic choice introduced by a subformula α = β1 + β2 , which
tell us whether we include β1 or β2 . A formal proof is included in Appendix B.
228
Semiring Reasoning Frameworks in AI and Their Computational Complexity
The rest of the cases are as in Definition 10, where we identify p(~x) with a propositional
variable vp(~x) .
We consider the evaluation of ΣFO σ-formulas, which only use sum quantifiers (i.e. Σx):
Quantitative first-order evaluation problems are present for example in probabilistic infer-
ence from Bayesian networks (Van den Broeck, Meert, & Darwiche, 2014); further, Eiter and
Kiesel (2020) showed that aggregation and other extensions of Answer Set Programming
can be modeled as ΣFO-Eval(R) over different semirings R. This opens up a perspec-
tive of optimization based on algebraic rewriting paired with heuristics, as common e.g. for
query languages in databases.
The ΣFO-Eval(R) problem is very similar to SAT(R). Indeed, under the assumption
that I is given explicitly as key value pairs of predicates with variable assignments and
truth values, we obtain:
Theorem 23. Problem ΣFO-Eval(R) is Karp s-reducible to SAT(R), and vice versa,
and thus NP(R)-complete w.r.t. Karp s-reductions for every commutative semiring R.
Proof (sketch). ⇒: Let α be a ΣBF over R. We choose σ = h{⊥, >}, {t(.)}, {xv1 , . . . , xvn }i
and I = {t(>), ¬t(⊥)} and replace every propositional variable v in α by t(xv ).
⇐: We replace p(~x) by Σp(d)∈I ~ Πxi ∈~x vxi ,di , where ~x = x1 , . . . , xr(p) , d~ = d1 , . . . , dr(p) , and
vx,d means that variable x has value d. We add constraints such that when both vxi ,di and
vxi ,d0i are true, then di = d0i and add a quantifier Σvxi ,di for each pair (xi , di ).
Theorem 24. Computing blevel(.) over R is Karp s-reducible to SumProd(R) and vice
versa, and thus NP(R)-complete w.r.t. Karp s-reductions for every commutative semiring
R.
Proof (sketch). The variables of the constraint problem are the ones of SumProd(R) and
for each constraint hdefi , coni i the function defi is a function fi in SumProd(R); blevel(.)
is the solution of SumProd(R).
Theorem 25. AMC over R is Karp s-reducible to SAT(R) and vice versa, and thus
NP(R)-complete w.r.t. Karp s-reductions for every commutative semiring R.
229
Eiter & Kiesel
The main differences between AMC and SAT(R) are that, on the one hand, in AMC the
logical part and the part that weights an interpretation are explicitly separated, whereas for
SAT(R) they are intertwined. Second, while AMC only allows for weight functions that can
be expressed as a product of weights, SAT(R) allows for complex arithmetic expressions
over the semiring.
Proof (sketch). ⇒: We can translate T into a ΣBF β and weight it with α using (vi ∗α(vi )+
¬vi ∗ α(¬vi )) for vi ∈ V.
⇐: As we noticed before, if we were to apply the distributive law exhaustively on a SAT(R)-
instance α, then the expression would be a sum of products of the semiring values r that
occur in the input ΣBF and the literals. We add for each occurrence ri of r a variable vri
with α(vri ) = r, α(¬vri ) = e⊗ . Then we use T to specify which semiring values are included
in the sum.
Here, N∞ corresponds to bag semantics, which means that the label of a query q(x) is
the number of derivations of q(x). The labels of the atoms in the semiring-weighted edb
thus intuitively mean that there are 2, 3, and 4 ways to derive r(a, b), r(b, c), and r(b, a),
respectively.
It follows that the label of q(b, c) under bag semantics is 3 due to the derivation q(b, c) ←
r(b, c) from r(b, c), which itself has 3 derivations according to the edb, and the fact that this
is the only derivation for q(b, c). On the other hand, for q(a, a) the label under bag semantics
230
Semiring Reasoning Frameworks in AI and Their Computational Complexity
is ∞. This can be seen as follows: we can derive q(a, a) from r(a, b), r(b, a) in 2 × 3 ways
according to their labels in the edb. But there exist infinitely many derivations of q(a, a)
from itself using rule r2 instantiated as q(a, a) ← q(a, a), q(a, a), leading to the label ∞.
For the problem of computing the label of a query under provenance semantics it is not
immediately clear how it relates to the other problems discussed in this section. Kimmig
et al. (2017) touched upon the relation of this and other so called Algebraic Derivation
Counting (ADC) formalisms to AMC. They include not only provenance queries but also
semiring parsing (Goodman, 1999) and semiring-weighted dynamic programming (Eisner,
Goldlust, & Smith, 2005). They showed that it is possible to reduce an AMC-instance T, α
to ADC by computing all models of the theory T and viewing them as derivations. As
they noteed, this is obviously ineffective in general as the number of models of T can be
exponential. The explicit computation of all the models is, however, not necessary for a
reduction.
Π = {q ← r1 (Y~1 ), . . . , rn (Y~n )}
We assume here, as usual, that the database D is stored explicitly as a set of tuples
(r(X), k), where r is a predicate and k is its semiring weight.
Π = {q ← r1 (Y~1 ), . . . , rn (Y~n )}
231
Eiter & Kiesel
Note that we only showed NP(R)-completeness for a restricted case of provenance com-
putations here, where the datalog program has only one rule. In fact, it is not possible to
evaluate provenance queries in NP(R) in general. This is not because of hard special cases
caused by the possibility of countably infinite sums, as already Green et al. (2007) gave
an algorithm to recognize this case. The hardness comes from higher expressivity in two
regards instead. First, in the Boolean setting, it is known that the evaluation of a datalog
program is EXPTIME-complete, even for a fixed extensional database D (Dantsin, Eiter,
Gottlob, & Voronkov, 2001). Thus, it seems unlikely that we can stay in NP(R), even when
R = B.
Second, for other semirings, provenance queries are even provably more expressive than
ΣBFs, already for ground programs Π, i.e., programs where only nullary predicates are
used. The latter allow us to express circuit-like terms.
Example 10. Let n ∈ N and consider the positive datalog program
Π = {ai+1 ← ai , ai | i = 1, . . . , n − 1}
and the semiring-weighted extensional database D = {(a1 , 2)}. Then the label li of ai is
given by the recurrence relation l1 = 2 and li+1 = a2i for i > 0. Therefore, the label of an is
n
(. . . (22 )2 . . . )2 = 22 , which is exponential in the size of the input.
232
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Larossa et al. (2010) noted that many typical problems, like SAT, #SAT and MAX-
SAT can be expressed as marginalization problems over different semirings. We show that
moreover the marginalization problem is NP(R)-complete.
where V is the set of variables of T , is the algebraic model count of T with respect to α.
233
Eiter & Kiesel
Now, we can use classical machines to solve SAT(τ (R)) and consider its complexity in
terms of classical complexity classes. Naturally, it depends on the complexity of addition and
multiplication. While for N, B these operations are “easy”, i.e., feasible in polynomial time
given a binary encoding, this is not the case for arbitrary semirings. A single multiplication
may even be undecidable.
Example 11 (Arbitrary Complexity Semirings). Given M ⊆ {0, 1}∗ and , the lexico-
graphical order on {0, 1}∗ , we define the semiring RM = ({0, 1}∗ ∪ {0, 1}, max , ⊗, 0, 1),
where 1 m 0 for m ∈ {0, 1}∗ and
min (m1 , m2 ) m1 , m2 ∈ M ∪ {0} = S
m1 m1 ∈ S, m2 ∈/S
m1 ⊗ m2 : =
m m ∈ S, m ∈
1 /S
2 2
min (m1 , m2 ) otherwise.
Our intuition is that there are two sources of complexity. One is the encoding and the
other seems to be the amount of information that the weighted semantics gives us about
the formula. The latter is determined by the non-collapsing terms in the semiring. For
illustration purposes, consider that over N[(xi )k ] the coefficients c1 , c2 are retained by the
sum c1 x1 + c2 x2 , over N only the sum c1 + c2 is retained after addition, and over B the value
c1 ∨ c2 only tells us if at least one of the values was 1. As a consequence SAT(N[(xi )k ])-
instances are at least as hard as SAT(N)-instances, since N is a subset of N[(xi )k ] with the
same addition and multiplication on N. Additionally, SAT(N)-instances seem to be strictly
harder than SAT(B)-instances as NP can easily be reduced to #P.
We focus on the second source of complexity and address the first by introducing the
notion of an efficient encoding.
234
Semiring Reasoning Frameworks in AI and Their Computational Complexity
235
Eiter & Kiesel
Theorem 33. For (R, C) = (B, NP), (N, #P), (Z, GapP), (Rmax , OptP) and the binary
representation bin of the integers, SAT(bin(R)) is C-complete w.r.t. Karp reductions.
Proof (sketch). Membership holds as bin(n) satisfies Definition 31 and we can, thus, inter-
pret Algorithm 1 as a non-deterministic Turing machine algorithm that generates the correct
polynomial size outputs. For hardness we use reductions from SAT, #SAT, computing the
permanent of an integer matrix, and LexMaxSAT, respectively.
Note that even though every function in OptP can be reduced to a SAT(bin(Rmax ))-
instance, there are functions in OptP that cannot be computed in NP(bin(Rmax )), e.g., x 7→
2|x| . Informally, this is because SRTMs can only generate semiring values by multiplying
numbers from {e⊕ , e⊗ } or the input. The fact that multiplication in Rmax is + implies
that we can only generate numbers that are polynomial in the numbers in the input. For
NP,#P and GapP this effect does not occur.
2. SAT(τ (R)) is Modp P-hard with respect to counting reductions for some p ∈ N or
This means that the problem is either trivial (case 1), or expected not to be solvable
in FP under common complexity theoretic assumptions such as the Exponential Time
Hypothesis (Impagliazzo & Paturi, 2001), otherwise.
Before we continue with the proof, we first make the following remark that we will use
throughout the rest of the paper. Let C = l1 ∨ l2 ∨ l3 be a clause and let l for a literal l
denote the opposite of l, i.e., a = ¬a and ¬a = a for any propositional variable a. Then:
Lemma 35. For every non-trivial semiring R, an interpretation I satisfies C iff for
d(C) := l1 + l1 ∗ l2 + l1 ∗ l2 ∗ l3
it holds that Jd(C)KR (I) = e⊗ . Furthermore, if I does not satisfy C, then Jd(C)KR (I) = e⊕ .
236
Semiring Reasoning Frameworks in AI and Their Computational Complexity
This covers all cases and we see that when I |= C, then Jd(C)KR (I) = e⊗ and otherwise
Jd(C)KR (I) = e⊕ .
since ⊕ is commutative. Last but not least, M must be closed under ⊗. So let n · τ (e⊗ ), m ·
τ (e⊗ ) ∈ M . Then,
237
Eiter & Kiesel
since ⊗ distributes over ⊕ and τ (e⊗ )⊗τ (e⊗ ) = τ (e⊗ ⊗e⊗ ) = τ (e⊗ ). This proves the claim.
Furthermore, for n ≥ p it holds that n · τ (e⊗ ) = (n − p) · τ (e⊗ ). Therefore,
M = {τ (e⊕ ), 1 · τ (e⊗ ), . . . , (p − 1) · τ (e⊗ )} ≡ Zp .
It follows that SAT(τ (R)) is Modp P-hard with respect to counting reductions. We give
a reduction from Modp 3CNF, which V is the problem of deciding whether the number of
models n that a given 3CNF φ = ni=1 Ci with variables v1 , . . . , vm has is not equal to
zero modulo p; this problem is Modp P-complete (Beigel & Gill, 1992). For the proof of
hardness, we again take α = Σv1 . . . Σvm Πni=1 d(Ci ) and observe that JαKτ (R) (∅) = n∗ ·τ (e⊗ ),
where n∗ ≡ N mod p. Since the cardinality of M is finite, we can decide in constant time
what the unique value n∗ ∈ {0, . . . , p − 1} is. The claim follows.
If we restrict ourselves to the case where we cannot have weights and consider an effi-
ciently encoded commutative semiring, we obtain a tetrachotomy result. This means, we
split the complexity associated with a commutative semiring into four distinct cases de-
pending on its properties. The properties we use are periodicity and offset of a periodic
semiring.
Definition 36 (Periodicity, Offset). Let R be a periodic semiring. Then the periodicity
of R is the smallest number p > 0 such that some o ≥ 0 with o · e⊗ = (o + p) · e⊗ exists.
Let p be the periodicity of R. Then the offset of R is the smallest number o ≥ 0 such that
o · e⊗ = (o + p)e⊗ .
Both periodicity and offset are well defined, i.e., there are unique numbers p, o that
satisfy the definition for periodic semirings.
Note that a periodicity of p does not imply that (p + 1) · e⊗ = e⊗ .
Example 14. Consider the semiring
N≤o = ({0, 1, . . . , o}, +, ·, 0, 1),
where i + j := min(o, i + j) and i · j := min(o, i · j), i.e., the semiring over the natural
numbers less than or equal to o. N≤o is periodic with periodicity 1 but 1 + 1 6= 1 when o > 1.
Corollary 37. Let R be a periodic semiring with periodicity p and offset o. Then for all
r ∈ R and o0 ≥ o it holds that o0 · r = (o0 + p) · r.
Proof. This can be shown by exploiting that e⊗ is the neutral element for multiplication
and the distributive law:
L o0 Lo0 Lo0 L 0
o −o Lo
i=1 r = i=1 r⊗e⊗ = r⊗ i=1 e⊗ = r⊗ i=1 e⊗ ⊕ i=1 e⊗
L 0
o −o Lo+p Lo0 +p Lo0 +p
= r⊗ i=1 e⊗ ⊕ i=1 e⊗ = r⊗ i=1 e⊗ = i=1 r.
With this in mind, we can show that the complexity of evaluating SAT(τ (he⊗ iτ (R) ))-
instances, i.e., instances over some efficiently encoded semiring τ (R) that only use weights
of the form k · τ (e⊗ ), falls into one of four distinct cases. Furthermore, we show that the
category a semiring falls into is determined by whether it is periodic, and if so, by its
periodicity and offset.
238
Semiring Reasoning Frameworks in AI and Their Computational Complexity
• τ (R) is periodic with periodicity 1 and SAT(τ (he⊗ i)) is NP-hard w.r.t. counting
reductions and in FPNP[O(1)] ;
• τ (R) is periodic with periodicity p ≥ 2 and offset 0 and SAT(τ (he⊗ i)) is Modp P-hard
w.r.t. counting reductions and in FPModp P[O(1)] ;
• τ (R) is periodic with periodicity p ≥ 2 and offset o > 0 and SAT(τ (he⊗ i)) is NP-
hard, Modp P-hard w.r.t. counting reductions and in FP(NP∪Modp P)[O(1)] ;
• τ (R) is not periodic and #SAT is in FNPSAT(τ (he⊗ i))[1] . Furthermore, if additionally
there is a polynomial p such that for all k ≥ 0 it holds that 2p(kk·e⊗ k) ≥ k, then
SAT(τ (he⊗ i)) is in FP#P[1] .
Note that practically for efficient evaluation also parallel oracle calls to NP and Modp P
could be used.
This result shows that if we only consider instances without semiring values, the already
known complexity classes NP, Modp P and #P suffice to bound the complexity in a rea-
sonable fashion, even if we allow general commutative countable semirings. Unfortunately,
the next subsection shows that this does not simply generalize to the case when we have
non-trivial weights.
We also would like to draw special attention to the last case, where τ (R) is not periodic.
Here, the bounds we can give are weaker than in the other three cases. This is because if
a semiring is periodic, then τ (he⊗ i) is finite, which implies that we can compute for any
r ∈ τ (he⊗ i) in constant time a value k ∈ N such that r = k · e⊗ . On the other hand, if τ (R)
is not periodic, it is not clear whether given r ∈ τ (he⊗ i) it is possible even in polynomial
time to compute k ∈ N such that r = k · e⊗ . The restriction that τ (R) is efficiently encoded
helps us, since it allows us to check in polynomial time whether r = k · e⊗ , given τ (r) and
k. However, as described by Sharma and Singh (2016), it is an open problem whether easy
to compute functions (like f (k) = k · e⊗ ) have an easy to compute inverse (like f −1 (τ (r))).
This explains the weaker lower bound on the hardness of SAT(τ (he⊗ i)).
For the upper bound, our proof for the reduction of SAT(τ (he⊗ i)) to #SAT requires
that for all r ∈ τ (he⊗ i) it holds that the value k ∈ N such that r = k ·e⊗ is single exponential
in the size of the encoding krkτ . We leave the question of the existence of an efficiently
encoded semiring, where this does not hold open.
4. not periodic
What is left to show is the corresponding claim for the complexity of SAT(τ (he⊗ i)).
239
Eiter & Kiesel
Case 1. So let τ (R) have periodicity 1 and let α = Σv1 . . . Σvl γ, where γ is quantifier-free,
be a SAT(τ (he⊗ i))-instance. Since γ only contains weights from τ (he⊗ i), we know that for
any interpretation I the semantics of γ is m · τ (e⊗ ) for some m ≥ 0. Further, let o be
the offset of τ (R). Then we know that (o + m) · τ (e⊗ ) = o · τ (e⊗ ) for all m ≥ 0. Thus,
JγKτ (R) (I) ∈ {0 · τ (e⊗ ), . . . , o · τ (e⊗ )} and also JαKτ (R) (∅) ∈ {0 · τ (e⊗ ), . . . , o · τ (e⊗ )}.
Thus, we can use o2 queries to an NP-oracle to determine for each value i = 1, . . . , o
whether there are 1, . . . , o or more interpretations with value i · τ (e⊗ ). From this we can
derive the value of α. Thus, SAT(τ (he⊗ i)) is in FPNP[O(1)] , since o only depends on the
semiring and not on the instance. For NP-hardness we can use the same construction as in
the proof of Theorem 34.
Case 2. So let τ (R) have periodicity p ≥ 2 and offset 0 and let α = Σv1 . . . Σvl γ, where γ
is quantifier-free, be a SAT(τ (he⊗ i))-instance. Since γ only contains weights from τ (he⊗ i),
we know that for any interpretation I the semantics of α is m · τ (e⊗ ) for some 0 ≤ m ≤ p.
Now, let f ∈ #P be a function that evaluates SAT(bin(N))-instances. We can use f
on α by replacing every value τ (k · e⊗ ) by bin(k). Since k ≡ 0 mod p iff k · τ (e⊗ ) = 0 · e⊗ ,
checking whether the semantics of α is 0 · τ (e⊗ ) is in Modp P by definition.
Additionally, since f ∈ #P implies f + i ∈ #P, we can use p queries to a Modp P-
oracle to determine for each value i = 1, . . . , p whether the semantics of α is i · τ (e⊗ ).
Thus, SAT(τ (he⊗ i)) is in FPModp P[O(1)] , since p only depends on the semiring and not on
the instance. For Modp P-hardness we can use the same construction as in the proof of
Theorem 34.
Case 3. So let τ (R) have periodicity p ≥ 2 and offset o > 0 and let α = Σv1 . . . Σvl γ,
where γ is quantifier-free, be a SAT(τ (he⊗ i))-instance. Since γ only contains weights from
τ (he⊗ i), we know that for any interpretation I the semantics of α is i · τ (e⊗ ) for some
0 ≤ i ≤ o + p.
The rest is a combination of case 1. and 2.: we first check whether i < o using o2 calls to
an NP-oracle. If i < o we are done, otherwise, we use p calls to a Modp P-oracle to obtain
the value i. For hardness we again use the same construction as in the proof of Theorem 34.
Case 4. So let τ (R) not be periodic and let α = Σv1 . . . Σvl γ, where γ is quantifier-free,
be a SAT(τ (he⊗ i))-instance. Since γ only contains weights from τ (he⊗ i), we know that for
any interpretation I the semantics of α is m · τ (e⊗ ) for some m ∈ N. If we can find out
for each r that occurs in γ the natural number kr such that r = kr · e⊗ , we can reduce the
evaluation of α to evaluating α over bin(N), as this will have result m. Given m we can
then compute m · τ (e⊗ ) in polynomial time. This establishes the existence of a counting
reduction from SAT(τ (he⊗ i)) to #SAT, if we can compute given r the natural number kr
such that r = kr · e⊗ .
If we know that for k · τ (e⊗ ) it holds that 2p(kk·e⊗ k) ≥ k for some polynomial p, then,
given the encoding τ (r) we can guess all numbers 0 ≤ k ≤ 2p(krkτ ) and check whether
k · τ (e⊗ ) = τ (r) in non-deterministic polynomial time. By doing this for all weights τ (r)
that occur in α before evaluating α non-deterministically over N and rejecting if a guess
was wrong, we can reduce SAT(τ (he⊗ i)) to #SAT.
As for the containment of #SAT in FNPSAT(τ (he⊗ i))[1] , consider the following algorithm:
given a #SAT-instance φ construct a SAT(τ (he⊗ i))-instance α such that the semantics of
240
Semiring Reasoning Frameworks in AI and Their Computational Complexity
We can use them similarly to reduce problems over one semiring to problems over another
semiring. Formally:
Theorem 40. Let τi (Ri ), i = 1, 2 be two encoded commutative semirings, such that
2. for each τ2 (r2 ) ∈ τ (R2 ) one can compute in polynomial time τ1 (r1 ) s.t. f (τ1 (r1 )) =
τ2 (r2 ) from τ2 (r2 ).
Proof (Sketch). Given a SAT(τ2 (R2 ))-instance α, we can replace all weights τ2 (r2 ) by a
weight τ1 (r1 ) such that f (τ1 (r1 )) = τ2 (r2 ), which is possible in polynomial time by condition
2. We can evaluate the resulting SAT(τ1 (R1 ))-instance and apply the epimorphism f .
Theorem 40 formalizes the intuition which Green and Tannen (2017) also discussed: if
a semiring R2 is the homomorphic image of another semiring R1 , then it is at most as
241
#P
-lik
N[ e
(x M
i) od
FP # ∞]
P pP
k
-co Zp ∪N
FP M
od
mp × P-
k pP
let
e N lik
≤o e
-co [( xi ) M
mp od
let N[ ∞]
e (x pP
i) -lik
Ga k] e
p P-
co Zp
mp × Zp NP
#P let N [(x
-co e Q ≤o i)
-lik
mp [(x ∞] e
M let i)
od e k]
pP Z N
-ha ≤o
rd [(x
O( N i)
1) ∞]
242
Zp B[
[(x (x FP
i)
i) ∞] me Spa
k] c
Eiter & Kiesel
Zp a c mbe e(p
× oll r s o
N ap hip ly)-
≤o B[ se i
(x FP M of mpli
i) k
od PH es
k] p P∪
N P
FP N -co
R k P
mp
ma -co let
Zp x R mp e
mi let
n e
T Op
tP
-co
B mp
let
e
NP
-co
mp
Figure 2 depicts between which semirings we can hope to apply Theorem 40. There, an
arrow R1 → R2 indicates that there exist encoding functions τ1 , τ2 such that the conditions
of Theorem 40 hold. In this map, we see that N[(xi )∞ ], N≤o × Zp [(xi )∞ ], Zp [(xi )∞ ] and
N≤o [(xi )∞ ] are the most information preserving and therefore in a sense hardest #P-like,
Modp P∪NP-like, Modp P-like and NP-like commutative countable semirings, respectively.
Among the four classes, we observe that the #P-like problems are the hardest and that,
naturally, the Modp P ∪ NP-like problems are harder than both Modp P-like and NP-like
problems. Furthermore, we see that by restricting ourselves to polynomials with finitely
many variables, the complexity decreases (presumably) a bit for all types of problems.
Finally, by further epimorphisms, we arrive at semirings that are not over polynomials,
which then often correspond to some classical complexity class, as we already observed in
Theorem 33.
In the following, we further formalize many intuitions, such as the C-likeness, presented
in Figure 2 and present further results on the complexity associated with semirings and
classes thereof, often by using the existence of epimorphisms.
We start by formalizing the intuition that the above mentioned polynomial semirings
are the hardest ones that satisfy a given set of properties.
1. N≤o [(xi )∞ ];
2. Zp [(xi )∞ ];
3. N≤o × Zp [(xi )∞ ];
4. N[(xi )∞ ]
such that for any commutative efficiently encoded commutative semiring τ (R) that is in
addition
243
Eiter & Kiesel
4. not periodic
Proof (Sketch). The idea is as follows. Instead of performing the evaluation explicitly by
performing all the semiring operations on the input values immediately, we replace each
semiring value τ (r) in the given ΣBF α by xτ (r) , where we associate the binary encoding
of r with a natural number corresponding to a variable index. Then we evaluate the trans-
formed instance over the corresponding polynomial semiring, where we obtain a polynomial
as the result. Finally we use the fact that we can encode the values of the polynomial
semiring in such a way that there exists a polynomial time computable epimorphism from
the polynomial semiring to τ (R), which corresponds to evaluating the polynomial with xτ (r)
replaced by τ (r).
Thus, if we find an efficient algorithm for SAT(τ ∗ (S[(xi )∞ ])), with S ∈ {N≤o , Zp , N≤o ×
Zp , N} with the encoding function τ ∗ from the proof, we can use it to solve SAT(τ (R)) for
any efficiently encoded commutative semiring τ (R) with the corresponding periodicity and
offset. Unfortunately, already the result of evaluating a SAT(τ ∗ (B[(xi )∞ ]))-instance α can
be exponential in the size of α. Therefore, any algorithm for SAT(τ ∗ (S[(xi )∞ ])) necessarily
has exponential running time.
One might be tempted to think that this can be avoided by choosing an encoding
function τ that is better than τ ∗ . However, such an encoding τ is unlikely to exist, as the
following result shows.
Theorem 42. Let R = N[(xi )∞ ] (resp. R = B[(xi )∞ ]). If there is an encoding function τ
for R s.t.
3) kxi kτ is polynomial in i,
This would imply Σp2 = PH (Karp & Lipton, 1982), which is considered to be unlikely.
Hence, for any reasonable encoding τ , SAT(τ (N[(xi )∞ ]) and SAT(τ (B[(xi )∞ ])) are unlikely
to have polynomial output and are, therefore, unlikely to be in FPSpace(poly).
244
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Condition 3) of Theorem 42 allows that indices ik are encoded in unary and imposes
no restriction on the encoding of exponents jk . Requiring the exponents to be encoded in
binary puts even already SAT(τ (B[x])) outside of FPSpace(poly), unless NP ⊆ P/poly.
Theorem 43. Let R = N[x] (resp. R = B[x]). If there is an encoding function τ for R s.t.
Proof (sketch) for Theorems 42 and 43. For each n ∈ N, we can construct a ΣBF formula α
of polynomial size s.t. the solution of every #3SAT (resp. 3SAT)-instance with n variables
is obtainable from kJαKR (I)kτ . By the methodology of (Cadoli, Donini, & Schaerf, 1996)
to assess compilability, we then infer #P ⊆ FP/poly (resp. NP ⊆ P/poly).
Theorem 44. If #P ⊆ FP/poly (resp. NP ⊆ P/poly), then there exist encodings τ∞ and
τ1 for N[(xi )∞ ] and N[x] (resp. B[(xi )∞ ] and B[x]) such that the preconditions 1) - 3) of
Theorems 42 and 43 are satisfied.
Proof (sketch). The idea here is as follows: we know that we can obtain the coefficient of a
monomial from JαKR (∅) in #P (resp. NP). Thus, if #P ⊆ FP/poly (resp. NP ⊆ P/poly),
we can also obtain it in FP (resp. P) given polynomial advice.
Using this insight, we can construct an encoding that satisfies the desired properties, by
representing polynomials as a tuple consisting of a SAT(τb (R))-instance and the polynomial
advice(s) necessary to solve the queries for coefficients of monomials in polynomial time.
Here, we only need to make sure that the base encoding τb satisfies condition 3). Such
encodings are easy to find though.
2) we can extract the encoding τ (r0 ) ∈ τ (R) of the coefficient of xji11 ...xjinn from τ (r) in
time polynomial in krkτ , and
245
Eiter & Kiesel
3) kxi kτ is polynomial in i,
then either NP ⊆ P/poly or Modp P ⊆ P/poly for some p ∈ N.
2) we can extract the encoding τ (r0 ) ∈ τ (R) of the coefficient of xi from τ (r) in time
polynomial in krkτ , and
246
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Proof (Sketch). We can obtain the coefficient of the polynomially many monomials in the
solution of an SAT(τ (R[(xi )k ]))-instance with one independent query to an NP(τ (R))-
oracle each. On the other hand we can solve n SAT(τ (R))-instances at the same time
by solving one SAT(τ (R[(xi )k ]))-instance, by multiplying each of them with a different
monomial xi1 .
4. not periodic
then SAT(τ (R)) for instances that contain at most k different semiring values is in
1. FPNP
k ;
Modp P
2. FPk ;
Modp P∪NP
3. FPk ;
4. FP#P
k
respectively.
Proof. Let α be a SAT(τ (R))-instance that contains at most k different semiring values
τ (r1 ), . . . , τ (rk ). We define an epimorphism f : bin(N[(xi )k ]) → τ (R) by defining it on the
N Ni
monomials xi11 . . . xikk as f (xi11 . . . xikk ) = kj=1 ljj =1 τ (rj ). Since τ (R) is efficiently encoded,
and the exponents ij are encoded in unary, f is computable in polynomial time. We can
thus apply Theorem 40 with semirings bin(N[(xi )k ]) and τ (R), since the second condition
is trivially satisfied by using xj as an element that maps to τ (rj ) for j = 1, . . . , k.
Thus, we have a counting reduction from SAT(τ (R)) to SAT(bin(N[(xi )k ])). By ap-
plying Theorem 48 we then obtain a metric reduction to a problem in FP#P k . Since metric
FP#P [1]
reductions are polynomial time functions, we can derive that SAT(τ (R)) is in FP k ,
which is equal to FP#P
k .
The proof for the semirings that are periodic is analogous by performing the same
reduction to
1. SAT(bin(N≤o [(xi )k ])), when τ (R) has periodicity 1 and offset o;
247
Eiter & Kiesel
3. SAT(bin(Zp × N≤o [(xi )k ])), when τ (R) has periodicity p ≥ 2 and offset o > 0.
However, not all relevant SAT(R)-instances have few different semiring values. We can
take this idea even further by considering instances that have many different semiring values
that can be expressed as “reasonably small” sums and products of few different semiring
values. For this, we consider finitely generated semirings.
Definition 50 (Finitely Generated Semiring). Let R = (R, ⊕, ⊗, e⊕ , e⊗ ) be a semiring.
We call R finitely generated, if R = hR? iR for some finite R? ⊆ R.
Commutative semirings that are finitely generated using k elements r1 , . . . rk can be
seen as reduced versions of the semiring of polynomials with variables x1 , . . . , xk . We thus
obtain:
Theorem 51. Let τ (R) be an efficiently encoded commutative Nsemiring that is generated by
e
{r1 , . . . , rk }. Suppose every r ∈ R is of the form r = ni=1 ai · kj=1 rj i,j for some ai , ei,j ∈ N
L
such that
• max{ei,j , log2 (ai ), n} is polynomial in krkτ , and
4. not periodic;
then SAT(τ (R)) is in
1. FPNP
k ;
Modp P
2. FPk ;
Modp P∪NP
3. FPk ;
4. FP#P
k ;
respectively.
Note that k in Theorem 51 may be zero. For example, the natural number semiring N is
generated by the empty set, since every semiring over a subset over the natural numbers with
the same addition and multiplication needs to contain zero and one. Clearly, N = h0, 1iN .
e
If indeed k = 0, the product kj=1 rj i,j takes values e⊗ and the Theorem also holds.
N
248
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Proof (Sketch). As in the proof of Lemma 49, we can find a polynomial time epimorphism
from τ (R) to bin(S[(xi )k ]) for the semiring S ∈ {N≤o , Zp , Zp × N≤o , N} with the same
periodicity as τ (R). However, contrary to Lemma 49, we do not identify each semiring
value in a given instance with a different variable but identify the values r1 , . . . , rk that the
semiring is generated from with the variables x1 , . . . , xk . Due to the preconditions of the
Theorem, we can then apply Theorem 40 to show that we can counting-reduce SAT(τ (R))
to SAT(bin(S[(xi )k )]). By application of Theorem 48 we then prove our claim.
Again note that in case k = 0, the polynomial semiring bin(S[(xi )k ]) is simply the
semiring over the constant polynomials, i.e., bin(S).
Note that when τ (R) is periodic, we know that the coefficients ai can always be chosen
such that they are bounded by a constant.
Furthermore, compare Theorem 51 to Theorem 38 for the case when the encoded semir-
ing τ (R) is not periodic. Clearly, for any semiring τ (he⊗ i) is finitely generated. Thus,
one might be tempted to assume that one can always apply Theorem 51 to derive that
SAT(τ (he⊗ i)) is in FP#P
k . This is not necessarily the case, however, since it is not clear
that the additional preconditions of Theorem 51 are given, even when the semiring is effi-
ciently encoded.
249
Eiter & Kiesel
tion over the reals and general rings, respectively. Roughly speaking, BSS machines operate
over a tape whose cells can hold elements from a ring R, and computation steps are per-
formed by the evaluation of polynomials over R that modify finite sequences of cells; a BSS
machine is a connected directed graph which has input, output, and computation nodes,
and possibly shift and branching nodes, where the former allow for shifting tape contents
and the latter for testing a condition such as r ≥ 0 (if the ring R is ordered) or r = 0 based
on the ring elements on the tape. Notably, Blum et al. remarked that a classical Turing
machine is a BSS-machine over Z2 (using a binary alphabet).
As for complexity, BSS studied in their model ring operations having unit cost, i.e.,
independent of the concrete ring elements used; merely for Z and Q, also bit cost, i.e. log m
where m is the largest number in the computation, was considered. Based on this time
measure, Blum et al. defined then polynomial (P-) time and NP computations over rings,
where in the latter a guess of values from R can be made; notably, over Z we have P 6= NP
under unit cost.
Compared to SRTMs, BSS-machines do not operate over semirings, thus e.g. the natural
numbers N are not covered, as they do not form a ring. While the definition might be
adapted to semirings, a distinctive feature is that BSS-machines work over (strings of) ring
values only, while our SRTMs allow for semiring values in addition to a tape alphabet as
usual. The latter is convenient and provides flexibility for problem representation, which the
BSS model lacks. E.g., for solving the classical SAT problem in the BSS model, propositional
formulas must be first converted into an algebraic form over a ring that can be processed by
a BSS machine; to this end, Blum et al. use a transformation (assuming that input formulas
are already in CNF) into a system of polynomials over the ring Z2 .
Furthermore, in order to ensure efficient (polynomial time) computation, the process-
ing of numbers must be controlled with additional restrictions, such that e.g. recursive
multiplication of values, as discussed in Section 4.2, is prohibited.
Summarizing, the BSS model has been devised with computations over algebraic struc-
tures in mind, where the input is already in a specific form and the cost of algebraic opera-
tions is disregarded respectively for Z and Q estimated by binary number size; semirings like
N are not covered. Efficient computation is hard to ensure, and the linkage to conventional
complexity classes is limited to few cases; different by missing or fixed encodings. This
makes the use of BSS machines for problem solving and complexity analysis in the context
of AI reasoning frameworks as we consider less attractive.
250
Semiring Reasoning Frameworks in AI and Their Computational Complexity
is different from our NP(R) instantiated for R = R, in which we sum up (i.e., “count”)
weighted acceptance paths. However, for SRTMs the numbers involved in a computation are
deliberately restricted compared to BSS machines, in order not to produce large result values
(which does not matter in the BSS-model) such that space efficient storage on a conventional
machine is feasible. Detailing the relationship between NP(R) and an analogue class that
combines weighted acceptance counting with BSS machines is an interesting issue for future
research, especially when it comes to generalizations for other (semi)rings.
Relational Machines SRTMs are further related to the relational machine of Abiteboul
and Vianu (1991, 1995), which was introduced in order to compensate for a mismatch
between computations by a Turing machine and the evaluation of logical formulas over
finite relational structures, which is of central importance for query answering over relational
databases. The generic treatment of elements in such structures, which model relational
databases, by logic and the fact that relations are unordered sets of tuples is in contrast
to string-based representations where in an encoding elements might be distinguished and
by the inherent order of the string’s letter an order of tuples induced; the latter may make
it easy to answer certain queries (e.g., whether a database has an even number of records)
that can not be expressed in a query language without order information (e.g., pure SQL).
To this end, Abiteboul and Vianu extended Turing machines with a “relational storage”
and the ability to perform relational operations (which underlie the evaluation of logical
formulas) directly on the relational storage rather than on the encoding of a database on
a machine’s tape. Emerging relational complexity classes and their relationships allowed
for a precise characterization of the expressive powers of certain database query languages
and to translate relationships of the latter into equivalent questions in standard complexity
theory. Notably, our notion of Karp surrogate-reduction for problems over semirings aims
at a genericity condition similar to the one for databases, but it does not allow for exploiting
in the reduction that different semiring surrogates SV n E and SV m E (i.e., n 6= m), which
corresponds to having different elements in a database, will amount to different semiring
values.
251
Eiter & Kiesel
252
Semiring Reasoning Frameworks in AI and Their Computational Complexity
This means that we can see the elements in GRAD as elements in Q[x] by identifying (1, 0)
and (0, 1) with 1 and x, respectively. The elements in GRAD are however only reduced
versions of the polynomials, i.e., there are additional equalities between values in GRAD
that do not hold in Q[x]. An example is x2 , because (0, 1) ⊗ (0, 1) = (0, 0) but x2 6= 0.
Here, the membership follows from Theorems 48 and 51 while the hardness follows
from the FP#P k -hardness of bin(N) and the fact that f : GRADN → N, (a, b) 7→ a, where
GRADN is the semiring GRAD restricted to elements from N × N, is an epimorphism. The
latter implies that we can use Theorem 40 to prove the hardness part.
253
Eiter & Kiesel
to show that all C-like problems with few weights from the semiring as well as all C-like
problems over a finitely generated semiring with a suitable encoding can be solved in FPCk .
Summing up, our results can be interpreted to give the following intuition: Putting
aside the difficulties caused by the encoding τ , the non-deterministic evaluation problems
over non-trivial semirings R are generally hard, as they are strongly intertwined with one of
NP, Modp P, Modp P ∪ NP and #P based on the periodicity and the offset of R. Within
the class of C-like problems P the number of queries to an C-oracle, whose results can be
obtained from the solution of P , in relation to the size of the P -instance, seems to be
crucial. When it is polynomial an FPCk -computation is sufficient, when it is exponential, an
FPSpace(exp)-computation seems to be necessary.
BSS Machines and SRTMs BBS machines and SRTMs both provide a way to perform
computations over algebraic structures but SRTMs are more restricted. A characterization
of when the machine models differ in power depending on which additional restrictions
are put on the BSS machines will help us better understand the effect of limitations on
the computational model. Especially, a closer look at the difference in power attained by
allowing SRTMs to perform recursive computations with semiring values on the tape is of
interest. While we have seen that over natural numbers N this leads to strictly more powerful
machines –as we can compute a value that is double exponential in the size of the input–
this is not clear for other semirings in general. For example, over the Boolean semiring
B recursive reuse of semiring values in computations does not increase the hardness since
CircuitSAT is Karp-reducible to SAT and vice versa. This begs the question of which
properties a semiring has to satisfy such that recursive semiring computations are harder
than non-recursive ones.
254
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Descriptive Complexity Apart from the computational complexity of logics over semir-
ings, there is also the question of descriptive complexity. Here, Droste and Gastin (2007)
showed that a fragment of weighted monadic second order logic was shown to capture the
sentences recognizable by weighted automata over semirings. This result is a generaliza-
tion of the Büchi, Elgot-Trakhtenbrot Theorem (Büchi, 1960), which states the same in
the unweighted (i.e. Boolean) case. This suggests that we may be able to do the same
for Fagin’s seminal theorem (Fagin, 1974) in descriptive complexity, which states that the
existential fragment of second-order logic characterizes the complexity class NP. Recently,
second-order logics over specific semirings were already used to capture the complexity of
quantitative complexity classes such as FP and #P (Arenas, Muñoz, & Riveros, 2020).
A general theorem that relates NP(R) and second-order logic over semirings R would be
suggestive. Given that SRTMs generalize weighted automata with their semiring weighted
transition functions, our work provides a basis for a generalized version of Fagin’s Theorem
over arbitrary semirings. Such a result and others on descriptive complexity would be valu-
able to assess the expressiveness of AI reasoning frameworks over varying input data when
formulas respectively queries are fixed.
255
Eiter & Kiesel
Acknowledgments
This work has been supported by FWF project W1255-N23. We thank the reviewers for
their feedback and comments to improve this article.
A preliminary version of this work has been presented at AAAI 2021 (Eiter & Kiesel,
2021). This article contains full details as well as refined and extended results.
(iii) JαKR (∅) = JβKR (∅), i.e., α and β evaluate to the same value.
Proof. Let α be a ΣBF over semiring R. We show that we can always push out the sum
quantifiers.
Let α = (Σvα1 ) ∗ α2 . W.l.o.g. we can assume that α2 does not contain v. Then
Since addition distributes over multiplication and α2 does not contain v, we get
256
Semiring Reasoning Frameworks in AI and Their Computational Complexity
• Hi,k , which is true if the M ’s read/write head is at tape cell i at step k of the
computation.
• {rs+1 , . . . , rm } = R0 , which are the constant semiring values that M has access to.
Here, s is the number of semiring values in x.
Since M is a polynomial time SRTM, we can assume the existence of a polynomial p such
that p(n) bounds the number of transitions of M on any input of length n.
Given a finite set I and a family (βi )i∈I of weighted formulas, we use the following
shorthand:
e⊕ if I = ∅
Σi∈I βi = .
βi + Σi∈I\{i∗ } βi if i∗ ∈ I
∗
Note that this is well defined, since I is finite and addition is commutative and associative.
257
Eiter & Kiesel
1. Ti,j,0
Variable ranges: 0 ≤ i < n
For each tape cell i that initially contains symbol j ∈ Σ or j = r when it contains the
semiring value r.
2. Ti,t,0
Variable ranges: −p(n) ≤ i < 0 or n ≤ i ≤ p(n)
Each tape cell i outside of the ones that contain the input contains t.
3. Qι,0
The initial state of M is ι.
4. H0,0
The initial position of the head is 0.
258
Semiring Reasoning Frameworks in AI and Their Computational Complexity
since we only need to take into account the transitions for letters from the alphabet Σ,
the semiring values {r1 , . . . , rs } in the input and the constants {rs+1 , . . . , rm }. With
this restriction |δ 0 | is finite and therefore the size of the sum is bounded by a constant
that only depends on the SRTM.
¬Hi,k + Hi,k ∗ ¬Qq,k + Hi,k ∗ Qq,k ∗ ¬Ti,σ,k
11.
+Hi,k ∗ Qq,k ∗ Ti,σ,k ∗ Hi,k+1 ∗ Qq,k+1 ∗ Ti,σ,k+1
Variable ranges: −p(n) ≤ i ≤ p(n), 0 ≤ k < p(n) and q ∈ Q, σ ∈ Σ ∪ {r1 , . . . , rm } s.t.
there do not exist q 0 , σ 0 , d, r s.t. ((q, σ), (q 0 , σ 0 ), d, r) ∈ δ.
The machine computation has ended. This is included so that when the machine has
reached a final state it stays the same until k reaches p(n).
In order to prove correctness, i.e., that the value of M on x is equal to JΣT ΣH ΣQ αKR (∅),
we prove two claims.
(i) For each interpretation I of the variables Ti,j,k , Hi,k , Qq,k for −p(n) ≤ i ≤ p(n), 0 ≤
k < p(n) and q ∈ Q such that I does not correspond to a computation path of M on
x, it holds that JαKR (I) = e⊕ .
(ii) For each interpretation I of the variables Ti,j,k , Hi,k , Qq,k for −p(n) ≤ i ≤ p(n), 0 ≤
k < p(n) and q ∈ Q such that I corresponds to a computation path π of M on x
(πn(π)−1 )
r(π1 ) r
along configurations cπ1 → . . . → cπn(π) it holds that
0
(πn(π
0 0 )−1 )
r(π1 ) ⊗ . . . ⊗r
L
JαKR (I) = π 0 , s.t.cπ π 0 .
i =ci
If both claims hold, then it follows that JΣT ΣH ΣQ αKR (∅) is equal to the sum of JαKR (I)
over all interpretations I such that I corresponds to a computation path. For each of them,
we know that the weight of the path is the product of the weights of the taken transitions,
according to (ii). Since the value of M on x is equal to the sum of the weights of the paths,
this implies correctness of the reduction.
We proceed to prove the claims. For this, we first generally show that the added sub-
formulas 1. to 11. enforce their given purpose.
For 1. to 4. this is clear: In order for JαKR (I) to be unequal to e⊕ , the variables need
to be included in the interpretation.
5. and 6. together ensure that at each time step there is exactly one symbol in each tape
cell. So assume that Ti,j,k and Ti,j 0 ,k are in I. Then
and so JαKR (I) = e⊕ . Assume alternatively that there are i, k such that for no j the variable
Ti,j,k is in I. Then
JΣj∈Σ∪{r1 ,...,rs } Ti,j,k KR (I) = e⊕ .
7. ensures that the tape remains unchanged unless written, i.e., unless the head is at
position i at step k the value of the tape cell i stays the same. So assume that Hi,k is not
in I but Ti,j,k and Ti,j 0 ,k for j 6= j 0 are in I. Then
J¬Ti,j,k + Ti,j,k ∗ ¬Ti,j 0 ,k+1 + Ti,j,k ∗ Ti,j 0 ,k+1 ∗ Hi,k KR (I) = e⊕ ⊕(e⊗ ⊗e⊕ )⊕(e⊗ ⊗e⊗ ⊗e⊕ ) = e⊕ .
259
Eiter & Kiesel
This means that the expression evaluates to the sum of all weights of the transitions we
take. Note that in order for two transitions ((q, σ), (q10 , σ10 ), d1 , r1 ), ((q, σ), (q20 , σ20 ), d2 , r2 ) to
be different at least one of q10 6= q20 , σ10 6= σ20 , d1 6= d2 or r1 6= r2 needs to hold. If q10 6= q20 ,
σ10 6= σ20 or d1 6= d2 then one of 5., 8., or 9. is falsified. Thus, in this case, we can take multiple
transitions if they differ in the weights only. On the other hand, we must take at least one
transition, since otherwise the whole sum evaluates to e⊕ . It follows that we transition
to exactly one new configuration to obtain a non-zero value for α. In that case, we have
Hi+d,k+1 , Qq0 ,k+1 , Ti,σ0 ,k+1 ∈ I for the corresponding transition(s) ((q, σ), (q 0 , σ 0 ), d, r) ∈ δ 0
and
L
JΣ((q,σ),(q0 ,σ0 ),d,r)∈δ0 Hi+d,k+1 ∗ Qq0 ,k+1 ∗ Ti,σ0 ,k+1 ∗ rKR (I) = ((q,σ),(q 0 ,σ 0 ),d,r)∈δ 0 r.
11. models that if at computation step k when the head is at position i there is no
possible transition for the given state q and tape cell entry σ, then the head position, state
and tape cell entries stay the same. Otherwise, this subformula is not added but one in 10.
is. So assume that Hi,k , Qq,k , Ti,σ,k ∈ I. Then the value of the subformula is
This means that the expression evaluates to e⊗ , if Hi,k+1 , Qq,k+1 , Ti,σ,k+1 ∈ I and evaluates
to e⊕ , otherwise. Thus, the formula enforces the desired constraint: if we are in a configu-
ration without further transitions we stay in it until the time limit p(n) is reached. Notably,
this does not influence the weight, since we always obtain a factor of e⊗ .
Putting things together, we see that 8. and 10./11. together ensure that there is exactly
one state at each time. Similarly, 9. and 10./11. together ensure that there is exactly one
head position at each time. This together with the constraints associated originally with 1.
to 11. show that the desired claims and therefore also the theorem hold.
Proposition B.1. The sum, using ⊕, of the results of all execution paths for a call to
EvalR (α, I) is equal to JαKR (I).
260
Semiring Reasoning Frameworks in AI and Their Computational Complexity
• Case α = α1 ∗ α2 :
The algorithm returns one of the results of the execution paths of EvalR (α1 , I)
multiplied by one of the results of the execution paths of EvalR (α2 , I). By the
induction hypothesis, we know that the sum of all the execution paths of EvalR (αi , I)
is equal to Jαi KR (I). For EvalR (α, I), we have one nondeterministic execution path
for every combination of nondeterministic execution paths of EvalR (αi , I), i = 1, 2
since the nondeterministic choices are made independently. Therefore, if the results
(i) (i)
of the execution paths of EvalR (αi , I) are k1 , . . . , kni we see that the sum of all the
execution paths of EvalR (α, I) is
n1 M
n2
(1) (1)
M
kj1 ⊗kj2
j1 =1 j2 =1
• Case α = Σv α:
Works analogously to case α = α1 + α2 .
261
Eiter & Kiesel
ΣFO-Eval(R)
SCSP
SAT(R)
AMC
SumProd(R)
mrg(F )
Figure 3: Karp s-reductions that are proven to show Theorems 20, 23 to 25 and 29. P → Q
means that a Karp s-reduction from P to Q is given.
Theorem B.2. For every commutative semiring R it holds that each of the following prob-
lems can be reduced to one another using Karp s-reductions:
• SAT(R),
• ΣFO-Eval(R),
• SumProd(R),
262
Semiring Reasoning Frameworks in AI and Their Computational Complexity
We proceed to prove the Karp s-reducibilities in the order specified in the above Theo-
rem.
Proof. Let α be a ΣBF over R with variable v1 , . . . , vn . We choose σ as the triple h{⊥, >},
{t(.)}, {xv1 , . . . , xvn }i and I = {t(>), ¬t(⊥)}. Then we replace every propositional variable
v in α by t(xv ), which symbolizes that v has truth value >, and every quantifier Σv with
the corresponding first order quantifier Σxv . For the resulting ΣFO formula β, it is easy to
see that
JαKR (∅) = JβKR (I)
since the semantics are analogously defined.
This lemma is the one that contains the most difficult steps, since it requires reducing
arbitrary combinations of sums and products to a sum of product.
We first prove some general structural assumptions that we can make about ΣFO for-
mulas:
Lemma B.6. For every ΣFO weighted formula α over a commutative semiring R, domain
D and interpretation I we can construct in polynomial time in α, D, I a ΣFO weighted
formula β = Σx1 . . . Σxn γ, where γ is quantifier free, over R and an interpretation I 0 such
that
JαKσR (I) = JβKσR (I 0 ).
Since addition distributes over multiplication and α2 does not contain x, we get
263
Eiter & Kiesel
Let α = (Σxα1 ) + α2 . We choose some d ∈ D, a new predicate symbol pd∗ with arity one
and define I 0 = I ∪ {pd∗ (d∗ )}. Then β = Σx(α1 + (α2 ∗ pd∗ (x))) has the following semantics
w.r.t I 0 :
Jα2 {x 7→ d}KσR (I 0 ) d = d∗
L σ 0
= d∈D Jα1 {x 7→ d}KR (I )⊕
e⊕ otherwise.
Since pd∗ is a new predicate that does not occur in α, we can remove it from I 0
Lemma B.7. For every ΣFO weighted formula α over a commutative semiring R, finite
domain D, and interpretation I, then we can construct in polynomial time a ΣFO weighted
formula β over R such that in every subformula Σxγ the variable x occurs in γ and
264
Semiring Reasoning Frameworks in AI and Their Computational Complexity
So we can replace Σxγ by (e⊗ + . . . + e⊗ ) ∗ γ without changing the semantics of the formula.
This is further possible in polynomial time and the resulting formula only increases in size
polynomially in |D|. This stays true, when we iteratively perform the replacement for all
such quantifiers Σx.
Proof of Lemma B.5. So let α be a ΣFO weighted formula over R and domain D that is to
be evaluated using interpretation I.
We use Lemmas B.6 and B.7 to ensure that α the input formula is of the form
Σx1 . . . Σxn β
whereas for all (d1 , . . . , dn ) ∈ Dn \ Dn (remember that D is the domain of the ΣFO formula
and D is the domain of the SCSP) it holds that
def 0 (d1 , . . . , dn ) = e⊕ .
Then
blevel(P ) = (ΠC) ⇓∅
= (ΠC) ⇓{x1 ,...,xn } ⇓∅
= hdef , {x1 , . . . , xn }i ⇓∅
= (d1 ,...,dn )∈Dn def 0 (d1 , . . . , dn )
L
265
Eiter & Kiesel
di }KσR (I)
L
= (d1 ,...,dn )∈Dn Jβ{xi 7→
= JΣx1 . . . Σxn βKσR (I)
= JαKσR (I)
So let I be an interpretation and D a domain. We first define the domain D of the constraint
system as D := D ∪ {>, ⊥}
Definition B.9 (Subformulas). Let α a quantifier free weighted formula. Then S(α) the
set of subformulas of α indexed by position p ∈ {0, 1} × {.0, .1}∗ is S 0 (α), where S i (α) for
i = 0, 1 is defined using induction on the structure of the formula as follows:
• Case α ∈ {p(~x), ¬p(~x), k}: Then S i (α) = {(i, α)} for i = 0, 1.
• Case α = α1 + α2 or α = α1 ∗ α2 : Then S i (α) = {(i, α)} ∪ {(i.r, β) | (r, β) ∈
S 0 (α1 )} ∪ {(i.r, β) | (r, β) ∈ S 1 (α2 )} for i = 0, 1.
We assert (in the following referred to as (*)) that for values d~ ∈ Dk , for which we do
~ it is zero, i.e., def (d)
not fix the value def (d), ~ = e⊕ . We define P using S(β). Intuitively,
the strategy is as follows: For each indexed subformula of (s, γ) we add a variable vs that
determines whether the subformula should be included in the computation. Then for atomic
subformulas we add a constraint that has the value of the atomic formula if it is included.
For complex subformula α1 ∗ α2 , resp. α1 + α2 we add constraints that ensure that if the
subformula should be included, then also α1 and α2 , resp. α1 xor α2 have to be included.
Formally, we add the following constraints:
• For each (s, k) ∈ S(β) s.t. k ∈ R:
Add the constraint that evaluates to k when the variable vs has value > and evaluates
to e⊗ otherwise. We add the constraint set
C(s,k) ={c(s,k) }
c(s,k) =h{> 7→ k, ⊥ 7→ e⊗ }, {vs }i
266
Semiring Reasoning Frameworks in AI and Their Computational Complexity
vs → (vs.0 ∧ vs.1 )
¬vs → (¬vs.0 ∧ ¬vs.1 )
Then using Lemma B.8 (where a2 = a3 is possible) we add the constraint set
C(s,α) = {c¬vs ∨vs.0 ∨vs.1 , c¬vs ∨¬vs.0 ∨¬vs.1 , cvs ∨¬vs.0 , cvs ∨¬vs.1 }.
• We further need to assert that s0 , i.e. the variable specifying whether the root node
will be included in the computation, is true: We add it again using Lemma B.8 (with
a1 = a2 = a3 = v0 )
cv0 .
267
Eiter & Kiesel
holds.
• β = k, k ∈ R:
Then P = hh{> 7→ k} ∪ {⊥ 7→ e⊗ }, {v0 }i, {v0 }i. We know
JβKσR (I)
d0 = >
= e⊗ d0 = ⊥
e⊕ otherwise.
• β = p(~x):
Then
P = h{h{(>, d1 , . . . , dk ) 7→ e⊗ | p(~x){xi 7→ di } ∈ I, di ∈ D}
∪ {(>, d1 , . . . , dk ) 7→ e⊕ | p(~x){xi 7→ di } 6∈ I, di ∈ D}
∪ {(⊥, d1 , . . . , dk ) 7→ e⊗ | di ∈ D},
{v0 } ∪ var(~x)i} ∪ {cv0 },
{v0 } ∪ var(~x)i.
Let
(ΠC) ⇓{v0 }∪var(~x) = hdef , {v0 , x1 , . . . , xn }i,
and d1 , . . . , dn ∈ D. Then
e⊗ d0 = >, p(~x){xi 7→ di } ∈ I
e⊕ d0 = >, p(~x){xi 7→ di } 6∈ I
def (d0 , d1 , . . . , dn ) =
e d0 = ⊥,
⊗
e⊕ otherwise.
JβKσR (I)
d0 = >
= e⊗ d0 = ⊥
e⊕ otherwise.
268
Semiring Reasoning Frameworks in AI and Their Computational Complexity
• β = ¬p(~x):
Then
P = h{h{(>, d1 , . . . , dk ) 7→ e⊗ | p(~x){xi 7→ di } 6∈ I, di ∈ D}
∪ {(>, d1 , . . . , dk ) 7→ e⊕ | p(~x){xi 7→ di } ∈ I, di ∈ D}
∪ {(⊥, d1 , . . . , dk ) 7→ e⊗ | di ∈ D},
{v0 } ∪ var(~x)i} ∪ {cv0 },
{v0 } ∪ var(~x)i.
Let
(ΠC) ⇓{v0 }∪var(~x) = hdef , {v0 , x1 , . . . , xn }i,
and d1 , . . . , dn ∈ D. Then
e⊗ d0 = >, p(~x){xi 7→ di } 6∈ I
M e⊕ d0 = >, p(~x){xi 7→ di } ∈ I
def (d0 , d1 , . . . , dn ) =
e⊗ d0 = ⊥,
d∈D
e⊕ otherwise.
JβKσR (I)
d0 = >
= e⊗ d0 = ⊥
e⊕ otherwise.
• β = β1 ∗ β2 :
Then
[
h C(s,α) , {vs | (s, α) ∈ S(β)} ∪ {x1 , . . . , xn }i
(s,α)∈S(β)
[ [
=h C(0.s,α) ∪ C(1.s,α) ∪ C(0,β) ,
(s,α)∈S 0 (β1 ) (s,α)∈S 1 (β2 )
= hC1 ∪ C2 ∪ C(0,β) ,
con1 ∪ con2 ∪ {v0 }i
Using the induction hypothesis we get that
(ΠCi ) ⇓{v0.i ,var(βi )} = hdef i , {v0.i } ∪ var(βi )i,
and for d1 , . . . , dn ∈ D
Jβi {xi 7→ di }KσR (I)
d0 = >
def i (d0 , . . . , dni ) = e⊗ d0 = ⊥
e⊕ otherwise.
269
Eiter & Kiesel
Then for
we see that
def (d0 , . . . , dn )
M N ~ con
= hdef c ,conc i∈C1 ∪C2 ∪C(0,β) def c (d ↓conc )
~
d∈D con1 ∪con2
d0 , dv0.0 , dv0.1 ∈ {⊥, >},
e ⊗ d0 → (dv0.0 ∧ dv0.1 )
M
N ~ con
= hdef c ,conc i∈C1 ∪C2 def c (d ↓conc )⊗ ∧¬d0 → (¬dv0.0 ∧ ¬dv0.1 )
~
d∈D con1 ∪con2
e⊕ otherwise.
N
def c (d~ ↓con
conc ) d0 = dv0.0 = dv0.1 = >,
Nhdef c ,conc i∈C1 ∪C2
M
= ~ con
hdef c ,conc i∈C1 ∪C2 def c (d ↓conc ) d0 = dv0.0 = dv0.1 = ⊥,
~
d∈D con1 ∪con2
e⊕ otherwise.
N
~ con
Nhdef c ,conc i∈C1 def c (d ↓conc ) d0 = dv0.0 = dv0.1 = >,
⊗ hdef c ,conc i∈C2 def c (d~ ↓conc )
con
M
=
N ~ con
hdef c ,conc i∈C1 def c (d ↓conc ) d0 = dv0.0 = dv0.1 = ⊥,
~ con1 ∪con2
⊗ hdef c ,conc i∈C2 def c (d~ ↓con
N
d∈D
con c
)
e⊕ otherwise.
N
~ con
hdef c ,conc i∈C1 def c (d1 ↓conc ) d0 = dv0.0
=
def c (d~2 ↓con
N
⊗ conc ) dv0.1 = >,
N hdef c ,conc i∈C2
M M
= ~ con
hdef c ,conc i∈C1 def c (d1 ↓conc ) d0 = dv0.0
=
~ con ~
d1 ∈D 1 d2 ∈D 2 con
⊗ hdef c ,conc i∈C2 def c (d~2 ↓con
N
conc ) dv0.1 = ⊥,
e⊕ otherwise.
L N ~ con
d~1 ∈Dcon1 \{v0.0 } hdef c ,conc i∈C1 def c (d1 ↓conc ) d0 = dv0.0
=
⊗ d~2 ∈Dcon2 \{v0.1 } hdef c ,conc i∈C2 def c (d~2 ↓conc ) dv0.1 = >,
con
L N
M
=
L N ~ con
d~1 ∈Dcon1 \{v0.0 } hdef c ,conc i∈C1 def c (d1 ↓conc ) d0 = dv0.0
dv0.0 ,dv0.1 ∈D
=
⊗ d~2 ∈Dcon2 \{v0.1 } hdef c ,conc i∈C2 def c (d~2 ↓con
L N
conc ) dv0.1 = ⊥,
e⊕ otherwise.
def 1 (>, d1 , . . . , dn1 ) ∗ def 2 (>, d1 , . . . , dn2 ) d0 = >,
= def 1 (⊥, d1 , . . . , dn1 ) ∗ def 2 (⊥, d1 , . . . , dn2 ) d0 = ⊥,
e⊕ otherwise.
= e⊗ d0 = ⊥,
e⊕ otherwise.
270
Semiring Reasoning Frameworks in AI and Their Computational Complexity
= e⊗ d0 = ⊥,
e⊕ otherwise.
• β = β1 + β2 :
Then
[
h C(s,α) , {vs | (s, α) ∈ S(β)} ∪ {x1 , . . . , xn }i
(s,α)∈S(β)
[ [
=h C(0.s,α) ∪ C(1.s,α) ∪ C(0,β) ,
(s,α)∈S 0 (β1 ) (s,α)∈S 1 (β2 )
Now if we let the constraint problems defined for β1 , β2 be Pi = hCi , coni i, we can see
that (modulo appropriate renaming of the variables of the form vs )
[
h C(s,α) , {vs | (s, α) ∈ S(α)} ∪ {x1 , . . . , xn }i
(s,α)∈S(β)
= hC1 ∪ C2 ∪ C(0,β) ,
con1 ∪ con2 ∪ {v0 }i
and for d1 , . . . , dn ∈ D
Then
def (d0 , . . . , dn )
M N ~ con
= hdef c ,conc i∈C1 ∪C2 ∪C(0,β) def c (d ↓conc )
~
d∈D con1 ∪con2
d0 , dv0.0 , dv0.1 ∈ {⊥, >},
e ⊗ d0 → (dv0.0 xor dv0.1 )
M
N ~ con
= hdef c ,conc i∈C1 ∪C2 def c (d ↓conc )⊗ ∧¬d0 → (¬dv0.0 ∧ ¬dv0.1 )
~
d∈D con1 ∪con2
e⊕ otherwise.
~ con
N
hdef c ,conc i∈C1 ∪C2 def c (d ↓conc ) d0 = dv0.1 = >, dv0.0 = ⊥,
def c (d~ ↓con
N
conc ) d0 = dv0.0 = >, dv0.1 = ⊥,
M
= Nhdef c ,conc i∈C1 ∪C2 ~ con
hdef c ,conc i∈C1 ∪C2 def c (d ↓conc ) d0 = dv0.0 = dv0.1 = ⊥,
~
d∈D con1 ∪con2
e⊕ otherwise.
271
Eiter & Kiesel
~ con
N
hdef c ,conc i∈C1 def c (d1 ↓conc ) d0 = dv0.1 = >
~
N con
⊗ hdef c ,conc i∈C2 def c (d2 ↓conc ) and dv0.0 = ⊥,
~ con
N
hdef ,con i∈C def c (d1 ↓conc ) d0 = dv0.0 = >
M N c c 1
M ~ con
⊗ hdef c ,conc i∈C2 def c (d2 ↓conc ) and dv0.1 = ⊥,
=
N ~ con
d~1 ∈Dcon1 d~2 ∈Dcon2 hdef c ,conc i∈C1 def c (d1 ↓conc ) d0 = dv0.0
=
⊗
N ~ con
hdef c ,conc i∈C2 def c (d2 ↓conc ) dv0.1 = ⊥,
e⊕ otherwise.
~ con
L N
Ld~1 ∈Dcon1 \{v0.0 } Nhdef c ,conc i∈C1 def c (d1 ↓conc ) d0 = dv0.1 = >
⊗ d~2 ∈Dcon2 \{v0.1 } hdef c ,conc i∈C2 def c (d~2 ↓con
conc ) and dv0.0 = ⊥,
~ con
L N
def c (d1 ↓conc ) d0 = dv0.0 = >
~ con \{v }
Ld1 ∈D 1 0.0 Nhdef c ,conc i∈C1
⊗ d~2 ∈Dcon2 \{v0.1 } hdef c ,conc i∈C2 def c (d~2 ↓con conc ) and dv0.1 = ⊥,
M
= L N ~ con
hdef c ,conc i∈C1 def c (d1 ↓conc ) d0 = dv0.0
dv0.0 ,dv0.1 ∈D
d~1 ∈Dcon1 \{v0.0 }
=
⊗
L N ~ con
hdef c ,conc i∈C2 def c (d2 ↓conc ) dv0.1 = ⊥,
~
d2 ∈D con2 \{v0.1 }
e⊕ otherwise.
def 1 (>, d1 , . . . , dn1 )⊗def 2 (⊥, d1 , . . . , dn2 ) d0 = >,
⊕def 1 (⊥, d1 , . . . , dn1 )⊗def 2 (>, d1 , . . . , dn2 )
=
def 1 (⊥, d1 , . . . , dn1 )⊗def 2 (⊥, d1 , . . . , dn2 ) d0 = ⊥,
e⊕ otherwise.
σ σ
Jβ1 {xi 7→ di }KR (I)⊗e⊗ ⊕e⊗ ⊗Jβ2 {xi 7→ di }KR (I) d0 = >,
= e⊗ d0 = ⊥,
e⊕ otherwise.
σ
J(β1 + β2 ){xi 7→ di }KR (I) d0 = >,
= e⊗ d0 = ⊥,
e⊕ otherwise.
Now that we know that the induction invariant holds, i.e., for
S
(Π (s,α)∈S(β) C(s,α) ) ⇓{v0 ,x1 ,...,xn } = hdef , {v0 , x1 , . . . , xn }i,
and d1 , . . . , dn ∈ D
272
Semiring Reasoning Frameworks in AI and Their Computational Complexity
This is because
Proof. Let P = hC, coni be some SCSP over hR, D, V i. Recall that
• vj,d~ for each j = 1, . . . , m and d ∈ DYj , where vj,d~ is true if the input to the function
fj is equal to d~
We define α by setting
• α(vi,d ) = α(¬vi,d ) = e⊗
~ and α(¬v ~) = e⊗
• α(vj,d~) = fj (d) j,d
~
• vj,d~ ↔ vi,d~X for each j = 1, . . . , m and d~ ∈ DYj
V
Xi ∈Y~j i
273
Eiter & Kiesel
Proof. Let the AMC-instance be over variables v1 , . . . , vn , theory T and weight function α.
W.l.o.g. we can assume that the theory T consists of a single propositional formula φ
(otherwise we simply take their conjunction). We apply the Tseitin transformation (Tseitin,
1983) to φ and obtain a 3CNF ψ with additional variables x1 , . . . , xm s.t. each satisfying
assignment of φ is uniquely extendable to a satisfying assignment of ψ. Furthermore, each
satisfying assignment of ψ is a satisfying assignment of φ when restricted to the variables
v1 , . . . , v n .
Recall that by Lemma 35, for each clause l1 ∨ l2 ∨ l3 it holds that
I |= ψ ⇐⇒ JβKR (I) = e⊗
I 6|= ψ ⇐⇒ JβKR (I) = e⊕
fulfills
A(T ) = JγKR (∅).
Lemma B.13. AMC over R is Karp s-reducible to mrg(F ) over R and vice versa.
Proof. We first reduce AMC over R to mrg(F ) over R. Assume we are given an AMC-
instance (T, α) over a commutative semiring R and variables V. W.l.o.g., we can assume
that T is a CNF C1 ∧ · · · ∧ Cn . If this was not the case, we could apply the Tseitin-
transformation and extend α to the added variables by letting α(l) = e⊗ for each of their
literals l. We construct a semiring-weighted CNF F as
F = FT ∪ F+ ∪ F− , where
FT = {(C1 , e⊕ ), . . . , (Cn , e⊕ )},
F+ = {(¬v, α(v)) | v ∈ V},
274
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Then
L
mrg(F ) = I∈Int(F ) φF (I)
L
= I|=T φF+ ∪F− (I)
L N α(v) I 6|= ¬v N α(¬v) I 6|= v
= I|=T v∈V ⊗ v∈V
e⊗ otherwise. e⊗ otherwise.
L α(v)
N I |= v N α(¬v) I |= ¬v
= I|=T v∈V ⊗ v∈V
e⊗ otherwise. e⊗ otherwise.
L N N
= I|=T v∈I α(v)⊗ v6∈I α(¬v)
= A(T ).
We see that the result of the marginalization problem of F over R is equal to A(T ), the
algebraic model count of the instance (T, α). Since we can construct F in polynomial time
from (T, α), this shows that the AMC over R is Karp s-reducible to mrg(F ) over R.
Next, we reduce mrg(F ) over R to AMC over R. Assume we are given a semiring-labeled
CNF F = {(C1 , w1 ), . . . , (Cn , wn )}. Consider the following AMC instance with theory T
and labeling function α such that
n
^
T = Ci ↔ ci
i=1
wi if l = ¬ci ,
α(l) = ,
e⊗ otherwise.
Since we can construct (T, α) in polynomial time from F , this shows that the mrg(F ) over
R is Karp s-reducible to AMC over R.
275
Eiter & Kiesel
a = x1 ,...,xn ∈D m
L N
i=1 fi (~
yi ).
kakτ = k x1 ,...,xn ∈D m
L N
i=1 fi (~
yi )kτ
≤ p(log2 |D| ) max k m
n N
i=1 fi (~
yi )kτ
x1 ,...,xn ∈D
Therefore, the size of the result a and consequently also all intermediate results are bounded
polynomially in the size of the input. We see that we at least have enough space to store all
the results and intermediate results. Furthermore, we know that multiplication and addition
are in FP and therefore also in FPSpace(poly). Last but not least, iterating over all the
assignments of values di ∈ D to variables Xi is also possible in polynomial space.
• SAT(bin(B)) is SAT;
.
For C-hardness, we consider the following reductions
• SAT(bin(B)) is SAT;
276
Semiring Reasoning Frameworks in AI and Their Computational Complexity
I |= ψ ⇐⇒ JβKR (I) = e⊗
I 6|= ψ ⇐⇒ JβKR (I) = e⊕
• Recall that for an n×n matrix A with entries aij ,the permanent is given by
n
X Y
aiσ(i) ,
σ∈Sn i=1
277
Eiter & Kiesel
I |= ψ ⇐⇒ JβKR (I) = e⊗
I 6|= ψ ⇐⇒ JβKR (I) = e⊕
2. for each τ2 (r2 ) ∈ τ (R2 ) one can compute in polynomial time τ1 (r1 ) s.t. f (τ1 (r1 )) =
τ2 (r2 ) from τ2 (r2 ).
Proof. Let the assumptions of the theorem be given. Furthermore, let α be a SAT(τ2 (R))-
instance. We can compute JαKτ2 (R) (∅) as follows.
First we replace every occurrence of a value τ2 (r2 ) with a value τ1 (r1 ) s.t. f (τ1 (r1 )) =
τ2 (r2 ). This is possible in polynomial time. The resulting ΣBF β is a SAT(τ1 (R1 ))-
instance. We now compute JβKτ1 (R1 ) (∅). Then we only need to apply f to the result and
have the solution JαKτ2 (R) (∅). This is possible in polynomial time with one oracle call to
SAT(τ1 (R1 )).
Since we only need to solve one SAT(τ1 (R1 ))-instance and do not require any infor-
mation about the original instance to obtain the final solution from the solution of the
SAT(τ1 (R1 ))-instance we have a counting-reduction.
1. N≤o [(xi )∞ ];
2. Zp [(xi )∞ ];
3. N≤o × Zp [(xi )∞ ];
4. N[(xi )∞ ]
278
Semiring Reasoning Frameworks in AI and Their Computational Complexity
such that for any commutative efficiently encoded commutative semiring τ (R) that is in
addition
4. not periodic
Proof. As the encoding function τ ∗ we take the function that encodes a monomial by rep-
resenting the coefficient and index of each variable in binary and each exponent in unary.
Furthermore, a polynomial is encoded as the list of the encodings of its monomials with
non-zero coefficients. Then we can define an epimorphism f by letting
X i~
i
a~i xi00 · · · · · x ~|i| := ~i∈N∗ ,ij 6=0⇒bin(ij )∈τ (R) a~i · bin(0)i0 ⊗ . . . ⊗bin(|~i|) |~i| .
L
f
|i|
~i∈N∗
For this definition to make sense, recall that τ maps to {0, 1}∗ and therefore τ (R) ⊆ {0, 1}∗ .
Since we can assume w.l.o.g. that for all values r ∈ R it holds that τ (r) ∈ {0, 1}∗ has a 1 as
the first letter, it follows that for some ij ∈ N it holds that bin(ij ) ∈ τ (R). Therefore, the
right-hand side of the definition is always a value in τ (R).
The idea of this definition is that we identify xij with the value that bin(ij ) represents in
τ (R). Then we can perform any calculation over τ ∗ (S[(xi )∞ ]) with S = N≤o , Zp , N≤o ×Zp , N,
depending on the periodicity and offset of R, by using the variables as placeholders for the
actual values. Finally, we can obtain the actual value over τ (R) using f . Note, that the
sum only considers exponent vectors ~i ∈ N∗ where any exponent ij of xj is equal to zero,
when bin(ij ) is not in τ (R) to ensure that f is well defined.
The check whether bin(ij ) is in τ (R) may be expensive. Therefore, f is not necessarily
polynomial time computable over the whole semiring τ ∗ (S[(xi )∞ ]). We consider instead
τ ∗ (S 0 ), where S 0 = S[{xi | bin(i) ∈ τ (R)}]. Then, evaluating f over τ ∗ (S 0 ) takes polynomial
time in the size of the encoding of the input since τ (R) is efficiently encoded.
It is easy to see that the second condition of Theorem 40 is satisfied, since we can map
bin(n) ∈ τ (R) to τ ∗ (xn ), which is obviously contained in τ ∗ (S 0 ).
Thus, we can apply Theorem 40 to show that SAT(τ (R))) is counting reducible to
SAT(τ ∗ (S 0 )). Since τ ∗ (S 0 ) is a subset of τ ∗ (S[(xi )∞ ] it follows that SAT(τ (S 0 ))) is counting
reducible to SAT(τ ∗ (S[(xi )∞ ])). Since counting reducibility is transitive, we are done.
279
Eiter & Kiesel
3) kxi kτ is polynomial in i,
then #P ⊆ FP/poly (resp. NP ⊆ P/poly).
For the proof we use the following theorem due to Cadoli et al. (1996).
S
Theorem C.14. Let Π be an NP-complete problem, and let Π = n∈N Πn , where Πn =
{π ∈ Π | |π| = n}. Moreover, let [P, F, V ] be a problem we want to compile, divided into
fixed part F and varying part V . Suppose that there exists a polynomial p such that, for
each n > 0, there exists an fn ∈ F with the following properties:
1. |fn | < p(n);
Proof of Theorem 42. We use Theorem C.14 with the following [P, F, V ]: P , the problem
we consider, is checking for a monomial V = xji11 ...xjinn whether the corresponding coefficient
in JαKN[(xi )∞ ] (∅) is unequal to zero. The fixed part F is given by the ΣBF α over the
semiring τ (N[(xi )∞ ]). We assume the encoding τ of the polynomials is one that satisfies
the precondition of Theorem 42.
We want to show that [P, F, V ] can be used to solve a #P-complete problem Π as in the
precondition of Theorem C.14. As Π we choose #3SAT. We know that when for π ∈ Π it
holds that |π| ≤ n then π can contain at most n different variables. W.l.o.g. we can assume
that the variables that are used are a1 , . . . , an . Let C1 , . . . , Ck be all the three literal clauses
constructible from a1 , . . . , an ; clearly k is polynomial in n.
We choose fn = αn .
280
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Given π ∈ Π with |πn | we know that all the clauses are three literal clauses using
only the variables a1 , . . . , an . W.l.o.g. we can assume that every variable is used at least
once, otherwise we can simply add ai ∨ ai ∨ ai for each variable that is not used without
changing the number of satisfying assignments. Therefore, the set C(π) of clauses in π is
a subset of the clauses C1 , . . . , Ck , i.e., C(π) = {Ci1 , . . . , Cim } where 1 ≤ ij < ij+1 ≤ k for
j = 1, . . . , m − 1. Then the coefficient of xi1 · · · · · xim in Jαn KN[(xi )∞ ] (∅), which is
JΣa1 . . . Σan Πm 0
j=1 Cij KN[(xi )∞ ] (∅),
is equal to the number of satisfying assignments of π. Since we can extract the binary rep-
resentation of the coefficient in polynomial time from the encoded value τ (Jαn KN[(xi )∞ ] (∅)),
this would imply that #P ⊆ FP/poly.
For B[(xi )∞ ] we use the same setting, except that we use 3SAT and then the coefficient
of xi1 · · · · · xim is equal to whether the 3SAT-instance is satisfiable.
Theorem 43. Let R = N[x] (resp. R = B[x]). If there is an encoding function τ for R s.t.
1) kJαKR (∅)kτ is polynomial in the size of α,
Theorem 44. If #P ⊆ FP/poly (resp. NP ⊆ P/poly), then there exist encodings τ∞ and
τ1 for N[(xi )∞ ] and N[x] (resp. B[(xi )∞ ] and B[x]) such that the preconditions 1) - 3) of
Theorems 42 and 43 are satisfied.
Proof (sketch). For simplicity, we only consider the case where #P ⊆ FP/poly and argue for
the existence of an encoding τ∞ for N[(xi )∞ ] that satisfies the preconditions of Theorem 42.
The proofs for the other cases use similar ideas.
The idea is as follows: First, we choose a basic encoding τ of N[(xi )∞ ], where (i)
coefficients are encoded in binary, (ii) exponents are encoded in binary, (iii) variables indices
are encoded in unary, and (iv) monomials are encoded as tuples consisting of their coefficient
plus a list of the variables together with their exponents. Finally, (v) polynomials are
encoded as lists of their monomials with non-zero coefficients.
Clearly, this encoding does not satisfy condition 1). However, importantly it does sat-
isfy condition 3). Before we continue, recall that given a SAT(τ (N[(xi )∞ ]))-instance α
and a monomial τ (xji11 ...xjinn ), it is possible to compute the coefficient of the monomial in
JαKτ (N[(xi )∞ ]) (∅) in #P. Assuming that #P ⊆ FP/poly, it is also possible in FP/poly. Then,
281
Eiter & Kiesel
let A be an advice oracle that returns the polynomial size advice string A(n) that can be
used to solve any such coefficient query of input size n. Now we consider the representation
of a polynomial p in N[(xi )∞ ] as
where
2. maxmon(β) is the monomial of maximum size encoding that has a non-zero coefficient
in JβKN[(xi )∞ ] (∅), and
3. |(β, maxmon(β))| denotes the size of the string that encodes the pair.
• all |(β, maxmon(β))| advice strings A(i) concatenated are polynomial in kβkτ .
Consequently, there is a representation of the solution JαKτ (N[(xi )∞ ]) (∅) of any instance α of
SAT(τ (N[(xi )∞ ])) whose size is polynomial in the size of α. Namely we can simply take
Furthermore, given this representation of JαKτ (N[(xi )∞ ]) (∅), we can obtain the binary repre-
sentation of any coefficient of any monomial in polynomial time in the size of the represen-
tation, due to the presence of the advice strings.
Last but not least, for xi , the representation
2) we can extract the encoding τ (r0 ) ∈ τ (R) of the coefficient of xji11 ...xjinn from τ (r) in
time polynomial in krkτ , and
282
Semiring Reasoning Frameworks in AI and Their Computational Complexity
3) kxi kτ is polynomial in i,
then either NP ⊆ P/poly or Modp P ⊆ P/poly for some p ∈ N.
Theorem 46. Let R 6= T be a commutative semiring. If there is an encoding function τ
for R[x] s.t.
1) kJαKR[x] (∅)kτ is polynomial in the size of α,
2) we can extract the encoding τ (r0 ) ∈ τ (R) of the coefficient of xi from τ (r) in time
polynomial in krkτ , and
283
Eiter & Kiesel
It remains to show that BPP Modp P ⊆ P/poly follows from Modp P ⊆ P/poly. We
already know that BPP ⊆ P/poly (Bennett & Gill, 1981) with an argument based on
machine simulation. If Modp P ⊆ P/poly holds, we then obtain BPP Modp P ⊆ PP/poly /poly.
To prove the result, it thus remains to show that PP/poly /poly ⊆ P/poly.
Consider a language L that is in PP/poly /poly and solved by a polynomial time machines
M with advice oracle AM , where M uses a further oracle that is evaluated by a polynomial
time machine O that uses and advice oracle AO . Given that PP = P, we can combine M
and O into a single polynomial time machine MC and only need to make sure that we can
supply it with the advice from both AM and AO . The latter is, however, easily achieved.
First note that since M takes polynomial time the queries posed to O are all of polynomial
size p(n) in the size n of the input to M . Thus, given input x of size n, we can use the
following polynomial size advice for MC :
This is still polynomial in n and we have both the necessary advice for the part of M and
of O.
Proof. Let α be some ΣBF over τ (R[(xi )k ]). We can bound the number of monomials in
JαKτ (R[(xi )k ]) (∅) by the monomials that occur in α. Let n be the maximum exponent ei
occurring in the monomials xe11 . . . xekk in α that have a nonzero coefficient. Furthermore,
let m be the number of monomials in α with nonzero coefficients. Then we know that for
all monomials xe11 . . . xekk in JαKτ (R[(xi )k ]) (∅) with nonzero coefficients it holds that ei ≤ nm
since every product can only have m factors, where each factor has at most exponent n.
Therefore, the number of monomials with nonzero coefficients in JαKτ (R[(xi )k ]) (∅) is bounded
by (nm)k . Since k is a constant and n and m are polynomial in the size of the input since
the exponents are encoded in unary, we know that there are at most polynomially many
monomials in JαKτ (R[(xi )k ]) (∅) with nonzero coefficients. Finding each of their coefficients is
possible with a call to a NP(τ (R))-oracle that is independent of the other calls. This shows
NP(τ (R))
that SAT(τ (R[(xi )k ])) is in FPk .
NP(τ (R))
For FPk -hardness, it is sufficient to show that we can obtain the answers to poly-
nomially many NP(τ (R))-queries by a metric reduction to solving one SAT(τ (R[(xi )k ]))-
instance. Since SAT(τ (R)) is NP(τ (R))-complete, we may assume that we have poly-
nomially many SAT(τ (R))-instances α1 , . . . , αn and moreover that each αi in prefix nor-
mal form with the same quantifier prefix Σv1 . . . Σvm . We then construct the following
SAT(τ (R[(xi )k ]))-instance β:
284
Semiring Reasoning Frameworks in AI and Their Computational Complexity
If τ (R) is
4. not periodic;
1. FPNP
k ;
Modp P
2. FPk ;
Modp P∪NP
3. FPk ;
4. FP#P
k ;
respectively.
Proof. Let α a ΣBF over τ (R). We can transform α into a ΣBF β over bin(S[(xi )k ]),
where the binary encoding of the natural numbers bin is extended to the polynomials by
representing polynomials as lists of monomials with exponents in unary and coefficients
encoded by bin and S is
1. N≤o ,
2. Zp ,
3. Zp × N≤o ,
4. N
285
Eiter & Kiesel
4. not periodic.
The transformation works by replacing every value τ (r) ∈ τ (R) that occurs in α by
n mi
e
X Y
bin ai xj i,j
i=1 j=i
Since the size of the representation of JβKbin(S[(xi )k ]) (∅) is polynomial, also the number of
monomials in JβKbin(S[(xi )k ]) (∅) is polynomial. Therefore, we can calculate the values of all
e
the “monomials” τ ( kj=1 rj i,j ) in polynomial time.
N
To compute Lai Nk ei,j
τ ( v=1 j=1 rj )
first consider the binary representation cdlog2 (ai )e . . . c0 ∈ {0, 1}∗ of ai . We know that
Lai Nk ei,j Ldlog2 (ai )e Lt N e
τ ( v=1 j=1 rj ) = t=0 ct · τ ( 2v=1 kj=1 rj i,j ). (4)
286
Semiring Reasoning Frameworks in AI and Their Computational Complexity
for t = 1, . . . , dlog2 (ai )e. This is possible in dlog2 (ai )e steps, where each of them takes
polynomial time and leads to a result that is polynomial in size, since τ (R) is efficiently
encoded.
After having computed these values, we can plug them into Equation (4) and evaluate
it. This is again possible in polynomial time, and leads to a result that is polynomial in
size, since τ (R) is efficiently encoded. For the same reason, summing up all the values
Lai Nk ei,j
τ ( v=1 j=1 rj ) over i is also possible in polynomial time and leads to a polynomial-size
result.
From metric-reducibility to SAT(S[(xi )k ]) and Theorem 48, it follows that SAT(τ (R))
C
is in FPFP
k . The latter class is equal to FPCk , which complete the proof.
such that log2 (mi ) is polynomial in kmkbin . Therefore, the preconditions of Theorem 51
are satisfied and we obtain that SAT(bin(S)n ) is in FP#P k .
For S = Q, this strategy does not apply completely analogously since Q is not finitely
generated. However, we can apply a very similar strategy as follows.
Consider a SAT(bin(Q)n )-instance α. Let bin(p1/q1 ), . . . , bin(pm/qm ) ∈ bin(Q) be the
entries of the weight vectors in α. Furthermore, let l be the least common multiple of
q1 , . . . , qm . Then we can replace these values by polynomials from bin(N[(xi )2 ]) by using
bin(pi l/qi x2 ) if pi ≥ 0,
poly(pi , qi ) =
bin(|pi |l/qi x1 x2 ) if pi < 0.
for bin(pi/qi ). Note that when we replace x1 by −1 and x2 by 1/l, we get the original value
again. The same still holds after addition and multiplication, that is, f : bin(N[(xi )2 ]) →
bin(Q), p(x1 , x2 ) 7→ p(−1, l) is a homomorphism. In fact, when we restrict the codomain of
f to bin(h1/l, −1i, it is even an epimorphism, which is moreover computable in polynomial
time.
287
Eiter & Kiesel
References
Abiteboul, S., & Vianu, V. (1991). Generic computation and its complexity. In Kout-
sougeras, C., & Vitter, J. S. (Eds.), Proc. 23rd Annual ACM Symposium on Theory
of Computing, May 5-8, 1991, New Orleans, Louisiana, USA, pp. 209–219. ACM.
Abiteboul, S., & Vianu, V. (1995). Computing with first-order logic. J. Comput. Syst. Sci.,
50 (2), 309–335.
Allender, E., & Wagner, K. W. (1993). Counting hierarchies: Polynomial time and constant
depth circuits. In Rozenberg, G., & Salomaa, A. (Eds.), Current Trends in Theoret-
ical Computer Science - Essays and Tutorials, Vol. 40 of World Scientific Series in
Computer Science, pp. 469–483. World Scientific.
Arenas, M., Muñoz, M., & Riveros, C. (2020). Descriptive complexity for counting com-
plexity classes. Log. Methods Comput. Sci., 16 (1).
Bacchus, F., Dalmao, S., & Pitassi, T. (2009). Solving #sat and bayesian inference with
backtracking search. J. Artif. Intell. Res., 34, 391–442.
Baral, C., Gelfond, M., & Rushton, J. N. (2009). Probabilistic reasoning with answer sets.
Theory Pract. Log. Program., 9 (1), 57–144.
Beigel, R., & Gill, J. (1992). Counting classes: Thresholds, parity, mods, and fewness.
Theor. Comput. Sci., 103 (1), 3–23.
Belle, V., & De Raedt, L. (2020). Semiring programming: A semantic framework for gen-
eralized sum product problems. Int. J. Approx. Reason., 126, 181–201.
Bennett, C. H., & Gill, J. (1981). Relative to a random oracle A, PA != NPA != co-NPA
with probability 1. SIAM Journal on Computing, 10 (1), 96–113.
Bistarelli, S., Montanari, U., Rossi, F., Schiex, T., Verfaillie, G., & Fargier, H. (1999).
Semiring-based csps and valued csps: Frameworks, properties, and comparison. Con-
straints An Int. J., 4 (3), 199–240.
Blum, L. (1998). Complexity and real computation. Springer.
288
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Blum, L., Shub, M., & Smale, S. (1989). On a theory of computation and complexity over the
real numbers: N P - completeness, recursive functions and universal machines. Bulletin
(New Series) of the American Mathematical Society, 21 (1), 1 – 46.
Brailsford, S. C., Potts, C. N., & Smith, B. M. (1999). Constraint satisfaction problems:
Algorithms and applications. Eur. J. Oper. Res., 119 (3), 557–581.
Brewka, G., Delgrande, J. P., Romero, J., & Schaub, T. (2015). asprin: Customizing answer
set preferences without a headache. In Bonet, B., & Koenig, S. (Eds.), Proceedings of
the Twenty-Ninth AAAI Conference on Artificial Intelligence, January 25-30, 2015,
Austin, Texas, USA, pp. 1467–1474. AAAI Press.
Büchi, J. R. (1960). Weak second-order arithmetic and finite automata. Mathematical Logic
Quarterly, 6 (1-6), 66–92.
Cadoli, M., Donini, F. M., & Schaerf, M. (1996). Is intractability of nonmonotonic reasoning
a real drawback?. Artif. Intell., 88 (1-2), 215–251.
Cook, S. A. (1971). The complexity of theorem-proving procedures. In Harrison, M. A.,
Banerji, R. B., & Ullman, J. D. (Eds.), Proc. 3rd Annual ACM Symposium on Theory
of Computing, May 3-5, 1971, Shaker Heights, Ohio, USA, pp. 151–158. ACM.
Cui, Y. (2002). Lineage tracing in data warehouses. Ph.D. thesis, Stanford University.
Dantsin, E., Eiter, T., Gottlob, G., & Voronkov, A. (2001). Complexity and expressive
power of logic programming. ACM Comput. Surv., 33 (3), 374–425.
Darwiche, A., & Marquis, P. (2002). A knowledge compilation map. J. Artif. Intell. Res.,
17, 229–264.
de Campos, C. P., Stamoulis, G., & Weyland, D. (2020). A structured view on weighted
counting with relations to counting, quantum computation and applications. Inf.
Comput., 275, 104627.
De Raedt, L., Kimmig, A., & Toivonen, H. (2007). Problog: A probabilistic prolog and
its application in link discovery. In Veloso, M. M. (Ed.), IJCAI 2007, Proc. 20th
International Joint Conference on Artificial Intelligence, Hyderabad, India, January
6-12, 2007, pp. 2462–2467.
Droste, M., & Gastin, P. (2007). Weighted automata and weighted logics. Theor. Comput.
Sci., 380 (1-2), 69–86.
Dudek, J. M., Phan, V., & Vardi, M. Y. (2020). ADDMC: weighted model counting with
algebraic decision diagrams. In Proc. Thirty-Fourth AAAI Conference on Artificial
Intelligence, AAAI 2020 New York, NY, USA, February 7-12, 2020, pp. 1468–1476.
AAAI Press.
Eisner, J. (2002). Parameter estimation for probabilistic finite-state transducers. In Proc.
40th Annual Meeting of the Association for Computational Linguistics, July 6-12,
2002, Philadelphia, PA, USA, pp. 1–8. ACL.
Eisner, J., Goldlust, E., & Smith, N. A. (2005). Compiling comp ling: Weighted dynamic pro-
gramming and the dyna language. In Proc. Human Language Technology Conference
and Conference on Empirical Methods in Natural Language Processing, HLT/EMNLP
289
Eiter & Kiesel
2005, 6-8 October 2005, Vancouver, British Columbia, Canada, pp. 281–290. The As-
sociation for Computational Linguistics.
Eiter, T., Hecher, M., & Kiesel, R. (2021). Treewidth-aware cycle breaking for algebraic
answer set counting. In Bienvenu, M., Lakemeyer, G., & Erdem, E. (Eds.), Proc. 18th
International Conference on Principles of Knowledge Representation and Reasoning,
KR 2021, Online event, November 3-12, 2021, pp. 269–279.
Eiter, T., & Kiesel, R. (2020). ASP(AC): Answer set programming with algebraic con-
straints. Theory Pract. Log. Program., 20 (6), 895–910.
Eiter, T., & Kiesel, R. (2021). On the complexity of sum-of-products problems over semir-
ings. In Proc. Thirty-Fifth AAAI Conference on Artificial Intelligence, AAAI 2021,
Virtual Event, February 2-9, 2021, pp. 6304–6311. AAAI Press.
Erdem, E., Gelfond, M., & Leone, N. (2016). Applications of answer set programming. AI
Mag., 37 (3), 53–68.
Fagin, R. (1974). Generalized first-order spectra and polynomial-time recognizable sets.
Complexity of computation, 7, 43–73.
Fenner, S. A., Fortnow, L., & Kurtz, S. A. (1994). Gap-definable counting classes. J.
Comput. Syst. Sci., 48 (1), 116–148.
Friesen, A. L., & Domingos, P. M. (2016). The sum-product theorem: A foundation for
learning tractable models. In Balcan, M., & Weinberger, K. Q. (Eds.), Proc. 33nd
International Conference on Machine Learning, ICML 2016, New York City, NY,
USA, June 19-24, 2016, Vol. 48 of JMLR Workshop and Conference Proceedings, pp.
1909–1918. JMLR.org.
Ganian, R., Kim, E. J., Slivovsky, F., & Szeider, S. (2022). Sum-of-products with default
values: Algorithms and complexity results. J. Artif. Intell. Res., 73, 535–552.
Gary, M. R., & Johnson, D. S. (1979). Computers and intractability: A guide to the theory
of np-completeness..
Gill, J. (1977). Computational complexity of probabilistic turing machines. SIAM J. Com-
put., 6 (4), 675–695.
Goodman, J. (1999). Semiring parsing. Comput. Linguistics, 25 (4), 573–605.
Grädel, E., & Meer, K. (1995). Descriptive complexity theory over the real numbers. In
Leighton, F. T., & Borodin, A. (Eds.), Proc. Twenty-Seventh Annual ACM Symposium
on Theory of Computing, 29 May-1 June 1995, Las Vegas, Nevada, USA, pp. 315–324.
ACM.
Green, T. J. (2011). Containment of conjunctive queries on annotated relations. Theory
Comput. Syst., 49 (2), 429–459.
Green, T. J., Karvounarakis, G., & Tannen, V. (2007). Provenance semirings. In Libkin, L.
(Ed.), Proc. Twenty-Sixth ACM SIGACT-SIGMOD-SIGART Symposium on Princi-
ples of Database Systems, June 11-13, 2007, Beijing, China, pp. 31–40. ACM.
Green, T. J., & Tannen, V. (2017). The semiring framework for database provenance. In
Sallinger, E., Van den Bussche, J., & Geerts, F. (Eds.), Proc. 36th ACM SIGMOD-
290
Semiring Reasoning Frameworks in AI and Their Computational Complexity
291
Eiter & Kiesel
292
Semiring Reasoning Frameworks in AI and Their Computational Complexity
Skryagin, A., Stammer, W., Ochs, D., Dhami, D. S., & Kersting, K. (2021). SLASH: embrac-
ing probabilistic circuits into neural answer set programming. CoRR, abs/2110.03395.
Stearns, R. E., & III, H. B. H. (1996). An algebraic model for combinatorial problems.
SIAM J. Comput., 25 (2), 448–476.
Toda, S. (1989). On the computational power of PP and +p. In 30th Annual Symposium
on Foundations of Computer Science, Research Triangle Park, North Carolina, USA,
30 October - 1 November 1989, pp. 514–519. IEEE Computer Society.
Tseitin, G. S. (1983). On the Complexity of Derivation in Propositional Calculus, p. 466–483.
Springer Berlin Heidelberg, Berlin, Heidelberg.
Valiant, L. G. (1979). The complexity of enumeration and reliability problems. SIAM J.
Comput., 8 (3), 410–421.
Valiant, L. G., & Vazirani, V. V. (1986). NP is as easy as detecting unique solutions. Theor.
Comput. Sci., 47 (3), 85–93.
Van den Berg, B., Van Bremen, T., Derkinderen, V., Kimmig, A., Schrijvers, T., & De Raedt,
L. (2021). From probabilistic netkat to problog: New algorithms for inference and
learning in probabilistic networks. In International Conference on Probabilistic Pro-
gramming, Location: Online.
Van den Broeck, G., Meert, W., & Darwiche, A. (2014). Skolemization for weighted first-
order model counting. In Baral, C., De Giacomo, G., & Eiter, T. (Eds.), Principles of
Knowledge Representation and Reasoning: Proc. Fourteenth International Conference,
KR 2014, Vienna, Austria, July 20-24, 2014. AAAI Press.
Van den Broeck, G., Thon, I., Van Otterlo, M., & De Raedt, L. (2010). Dtproblog: A
decision-theoretic probabilistic prolog. In Fox, M., & Poole, D. (Eds.), Proc. Twenty-
Fourth AAAI Conference on Artificial Intelligence, AAAI 2010, Atlanta, Georgia,
USA, July 11-15, 2010. AAAI Press.
293