0% found this document useful (0 votes)
20 views

AI Semiring

The document discusses semiring frameworks that are used to model quantitative problems in artificial intelligence in a uniform manner. It introduces a new complexity class called NP(R) to characterize the computational complexity of such problems depending on the semiring parameter. The paper obtains NP(R)-completeness results for several semiring frameworks and links NP(R) to other known complexity classes to understand the hardness of problems involving counting with semirings.

Uploaded by

YaqoubKhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

AI Semiring

The document discusses semiring frameworks that are used to model quantitative problems in artificial intelligence in a uniform manner. It introduces a new complexity class called NP(R) to characterize the computational complexity of such problems depending on the semiring parameter. The paper obtains NP(R)-completeness results for several semiring frameworks and links NP(R) to other known complexity classes to understand the hardness of problems involving counting with semirings.

Uploaded by

YaqoubKhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

Journal of Artificial Intelligence Research 77 (2023) 207-293 Submitted 06/2022; published 05/2023

Semiring Reasoning Frameworks in AI and Their


Computational Complexity

Thomas Eiter [email protected]


Rafael Kiesel [email protected]
Knowledge Based Systems Group
Institute of Logic and Computation
Vienna University of Technology (TU Wien)
Favoritenstraße 9-11
1040 Vienna, Austria

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

and related quantitative reasoning frameworks, because it provides a collection of var-


ious kinds of problems that we can reduce from/to in order to prove NP(R)-hardness
respectively membership in NP(R).
• We formalize, inspired by (Green, 2011), the intuition that the complexity associated
with a semiring depends on the information its values can preserve. This is achieved by
connecting the algebraic concept of epimorphism (a surjective mapping f : R1 → R2
compatible with the operations), viewed as a measure of this information preserva-
tion, and reductions between semiring problems. Namely, we show that having an
epimorphism with some additional restrictions allows us to solve problems over R2
by solving them over R1 , leading to an “informational-hardness-map” presented in
Section 6 (see Figure 2).
• Depending on the semiring properties of periodicity and offset, we give tetrachotomy
results showing that non-trivial countable, commutative semirings fall into four com-
plexity categories, meaning they are either NP-like, Modp P-like, Modp P ∪ NP-like,
or #P-like. Furthermore, we derive the following specific properties:

– General Hardness: For every non-trivial countable, commutative semiring R, the


problem SAT(R) is NP- or Modp P-hard.
– Zero-One Bounds: When only the weights zero (e⊕ ) and one (e⊗ ) are used, the
difference between the complexity of a C-like problem and the complexity class
C is limited given some additional reasonable restrictions. This shows that very
hard instances require the usage of weights.
– Polynomial Semiring Hardness: For a C-like semiring R we show that R[(xi )∞ ],
the semiring of the polynomials with countably many variables and coefficients
in R, can intuitively be used to solve exponentially many C-problems at the
same time. This implies that SAT(R[(xi )∞ ]) is not in FPSpace(poly), for any
reasonable encoding unless the polynomial hierarchy collapses, which is widely
assumed to be unlikely. Furthermore, for in a sense reasonable encodings, this
question is e.g. for R = N and R = B equivalent to the open complexity-theoretic
question whether #P ⊆ FP/poly (resp. NP ⊆ P/poly).
– Upper Bounds: On the other hand, we show that for a broad subclass of C-like
problems over semirings, SAT(R) is counting-reducible to FPCk , i.e. solvable in
polynomial time with polynomially many parallel queries to a C-oracle.

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.

Outline. In the following, we first provide in Section 2 some necessary preliminaries.


We then provide in Section 3 some examples that motivate the paradigm of computations
with semirings as parameter and give some guidance for its development. Next, we lay
in Section 4 the basis of a methodical complexity analysis of semiring-based formalisms
by introducing NP(R), a semiring version of NP, and SAT(R) as a canonical complete
problem. Afterwards, we immediately employ in Section 5 the NP(R)-completeness result
for SAT(R), by providing a variety of NP(R)-completeness and -hardness results for dif-
ferent semiring frameworks. In the subsequent Section 6 the relation of NP(R) to classical
complexity classes in the form of different upper and lower bounds is explored. In Section 7
we consider related work and discuss our results, while in the final Section 8 conclude with
issues for future research.
Full proofs for all theorems that are only sketched in the main body of the paper can
be found in the appendix.

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

• e is a neutral element for , i.e.,


for all m ∈ M it holds that m e = m = e m.

Furthermore, a semiring R is

• commutative if for all r, r0 ∈ R it holds that r⊗r0 = r0 ⊗r

• idempotent if for all r ∈ R it holds that r⊕r = r


Ln Lm
• periodic if for all r ∈ R there exist n, m ∈ N such that i=1 r = i=1 r

Some examples of well-known semirings are

• 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.

• R[(xi )n ] = (R[(xi )n ], ⊕, ⊗, e⊕ , e⊗ ), for n ∈ N, is the semiring of polynomials with


variables x1 , . . . , xn and coefficients from the semiring R.

• R[(xi )∞ ] = ( n∈N R[(xi )n ], ⊕, ⊗, e⊕ , e⊗ ) is the semiring of polynomials with variables


S
x1 , x2 , . . . and coefficients from the semiring R. The semirings R[(xi )α ] for α ∈
N∪{∞} are commutative (resp. idempotent) if R is commutative (resp. idempotent).

• T = ({e}, , , e, e), the trivial semiring, where e e = e.

Furthermore, we make use of generated semirings.

Definition 2 (Generated Semiring). Let R = (R, ⊕, ⊗, e⊕ , e⊗ ) be a semiring. For any


R? ⊆ R, the semiring generated by R? , denoted hR? iR , is the least (w.r.t. ⊆) semiring
(R0 , ⊕, ⊗, e⊕ , e⊗ ) s.t. R? ⊆ R0 .

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.

Definition 3 (Metric, Counting & Karp Reduction). Let fi : Σ∗ → Σ∗ , i = 1, 2 be functions,


then

• a metric reduction from f1 to f2 is a pair T1 , T2 of polynomial time computable func-


tions T1 : Σ∗ → Σ∗ , T2 : Σ∗ × Σ∗ → Σ∗ such that f1 (x) = T2 (x, f2 (T1 (x))) for every
x ∈ Σ∗ .

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

3. The Semiring Paradigm


Before we introduce new complexity classes to capture the computational complexity of
frameworks that depend on a semiring parameter, we first consider two prominent examples
of such frameworks. This is, on the one hand, to further motivate the interest in a complexity
study. On the other hand, it provides an insight into the structure that is shared by different
such frameworks. The latter is also important as it tells us more about the nature of the
problems at hand and thus guides us to an appropriate definition of a machine model for
computations involving semirings.

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.

Definition 5 (AMC). Given a propositional theory T over propositional variables V, a


commutative semiring R, and a labeling function α : L → R that maps the literals L over
V to R, AMC is to compute the value
L N N
A(T ) = I, s.t. I|=T v∈I α(v)⊗ ¬v∈I α(¬v).

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.

Semiring-based Constrained Satisfaction Problems A similar structure can be ob-


served for Semiring-based Constrained Satisfaction Problems (SCSPs). Bistarelli et al.
(1999) introduced them as a generalization of constraint satisfaction problems parame-
terised with c-semirings R, which are idempotent commutative semirings such that the
axiom ∀r ∈ R : r⊕e⊗ = e⊗ holds. This restriction is due to the fact that SCSPs were de-
fined to capture semantics for the levels of consistency of Constraint Satisfaction Problems
(CSPs), rather than semantics for general quantitative reasoning.

215
Eiter & Kiesel

Definition 6 (Constraint System, Constraint Problem). A constraint system is a tuple


CS = hR, D, V i, where R is a c-semiring, D is a finite domain, and V is an ordered set of
variables. A constraint over CS is a pair hdef , coni, where con ⊆ V and def : Dcon → R is
the value of the constraint. Here, Dcon denotes the set {(dx )x∈con | ∀x ∈ con : dx ∈ D}.
A constraint problem P over CS is a pair P = hC, coni, where C is a multiset of
constraints over CS and con ⊆ V .
Using Dcon instead of D|con| is helpful, since it allows us to associate inputs and their
variable.
Bistarelli et al. (1999) showed that SCSPs correspond to classical CSP, probabilis-
tic CSP, weighted CSP and fuzzy CSP when the c-semiring is respectively chosen as
B, ([0, 1], max, ·, 0, 1), Rmin and ([0, 1], max, min, 0, 1).
Example 2. The following are constraints over CS = hRmin , {a, b}, {x, y}i:

* 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
)

and⊗ is the multiplication of the semiring.


The projection c ⇓con0 of a constraint L c = hdef , coni to con0 ⊆ con is hdef 0 , con0 i with
def 0 (t0 ) = {t∈Dcon |t↓con0 =t0 } def (t), where
L
is the addition of the semiring.
con

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

Using ∗ and ⇓, the consistency-level of an SCSP is defined as follows.

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 ⇓∅ ).

Example 4. The consistency level of C = h{c1 , c2 }, {x, y}i is (c1 ∗ c2 ) ⇓∅ , i.e.,

* 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

1. Guessing some form of assignment;

2. Evaluating the instance for the given assignment; and

3. Aggregating the values of all guesses.

Using this insight into the structure of the evaluation problems associated with semiring
frameworks, we can now approach the characterization of their complexity.

4. Semiring Complexity Classes and a Complete Problem


In this section, we develop a toolbox that first and foremost allows completeness results for
arbitrary commutative semirings for the first time. For this, we first introduce a prototypical
problem called SAT(R) using the insights from the previous sections on what the evaluation
problems over semiring frameworks typically look like. The reason for introducing a new
problem instead of using AMC or SCSPs as a canonical complete problem is that SAT(R) in
our opinion better shows the power of semiring frameworks. Rather than only allowing that
we compute the value of an assignment as a product of weights, it allows us to specify the
value of an assignment as a complex arithmetic expression that depends on a propositional
interpretation.
In order to capture this guess-evaluate-aggregate pattern over different semirings, we
introduce Semiring Turing Machines (SRTMs), a novel machine model that allows restricted
non-deterministic computation of a semiring value in a black box fashion, whose final output

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.

4.1 Weighted Quantified Boolean Formulas and SAT(R)


The most natural way to define SAT(R) is as a special case of weighted Quantified Boolean
Formulas (QBFs).
We define weighted QBFs similarly to other weighted logics (Droste & Gastin, 2007;
Mandrali & Rahonis, 2015).
Definition 9 (Syntax). Let V be a set of propositional variables and R = (R, ⊕, ⊗, e⊕ , e⊗ )
be a commutative semiring. A weighted QBF over R is of the form α given by the grammar

α ::= k | v | ¬v | α + α | α ∗ α | Σvα | Πvα

where k ∈ R and v ∈ V. A variable v ∈ V is free in a weighted QBF α, if α has v is not


in the scope of a quantifier Σv or Πv. A weighted fully quantified Boolean Formula is a
weighted QBF without free variables.
Definition 10 (Semantics). Given a weighted QBF α over a commutative semiring R =
(R, ⊕, ⊗, e⊕ , e⊗ ) and variables from V as well as a propositional interpretation I of V, the
semantics JαKR (I) of α over R w.r.t. I is defined as follows:

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 )

where Iv = I \ {¬v} ∪ {v} and I¬v = I \ {v} ∪ {¬v}.


Weighted QBFs generalize QBFs in negation normal form (NNF), as negation is only
allowed in front of variables. Intuitively, allowing negation in front of complex formulas
would add the ability to test whether the value of a weighted QBF is zero. We can only
test whether an atomic formula is false. Therefore, our variant is or at least seems less
expressive. However, it fits better into the context of the problems we consider, where it
also is not possible to perform such “zero-tests” for complex expressions.
Here, we further focus on ΣBFs, i.e., the weighted fully quantified BFs that contain only
sum quantifiers (i.e. Σv) and we introduce their evaluation problem as

218
Semiring Reasoning Frameworks in AI and Their Computational Complexity

SAT(R): given a ΣBF α over R compute JαKR (∅).

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

(i) β = Σv1 . . . Σvn γ, where γ is quantifier free,

(ii) β can be constructed from α in polynomial time, and

(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

Σv1 . . . Σvn γ ∗ (v1 ∗ 2n−1 + ¬v1 ) ∗ . . . ∗ (vn ∗ 20 + ¬vn ).

As above, γ is obtained from φ by replacing every ⊥, >, ∨, ∧ with −∞, 0, max, +,


Pnrespectively.
Then JβKRmax (∅) = e⊕ = −∞ iff φ is unsatisfiable and JβKRmax (∅) = m = i=1 bi 2n−i iff
the lexicographically maximum satisfying assignment for φ sets vi to true whenever bi = 1.

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).

4.2 Semiring Turing Machines and NP(R)


We generalize NTMs to Semiring Turing Machines (SRTMs) to characterize the complexity
of SAT(R). At this point, we do not want the time and space needed to perform operations
on semiring values that are encoded in a finite alphabet to influence our definition. Thus,
we need SRTMs to be capable of

• performing semiring operations atomically in a black box manner, irrespective of


encodings of values;
• summing up values generated by nondeterministic computations; and
• using semiring values in the input in calculations.

On the other hand, too much power should be avoided; to this end, we relegate semiring
computations to weighted transitions.

Definition 12 (SRTM). A Semiring Turing Machine is a 7-tuple M = (R, R0 , Q, Σ, ι, t, δ),


where

• 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 )

• Q is a finite set of states,

• Σ is a finite set of symbols (the tape alphabet),

• ι ∈ Q is the initial state,

• t ∈ Σ is the blank symbol,

• δ ⊆ (Q × (Σ ∪ R)) × (Q × (Σ ∪ R)) × {−1, 1} × R is a weighted transition relation,


where the last entry of the tuple is the weight. For each ((q1 , σ1 ), (q2 , σ2 ), d, r) ∈ δ the
following holds:

220
Semiring Reasoning Frameworks in AI and Their Computational Complexity

1. M cannot write or overwrite semiring values:


if σ1 ∈ R or σ2 ∈ R, then σ1 = σ2 ,
2. M can only make a transition with weight r when r is from R0 or under the head:
r ∈ R0 or r = σ1 ∈ R
3. M cannot discriminate semiring values:
if σ1 ∈ R, then
(a) for all σ10 ∈ R we have ((q1 , σ10 ), (q2 , σ10 ), d, σ10 ) ∈ δ or
(b) for all σ10 ∈ R we have ((q1 , σ10 ), (q2 , σ10 ), d, r) ∈ δ.

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

Algorithm 1 An SRTM algorithm for SAT(R)


Input A ΣBF α over semiring R and an interpretation I.
Output JαKR (I).
1: function EvalR (α, I)
2: switch α do
3: case α = k:
4: transition with k
5: case α = l, l ∈ {v, ¬v}:
6: if l ∈ I then:
7: transition with e⊗
8: else:
9: transition with e⊕
10: case α = α1 + α2 :
11: Guess i ∈ {1, 2}
12: Execute EvalR (αi , I)
13: case α = α1 ∗ α2 :
14: Execute EvalR (α1 , I)
15: Execute EvalR (α2 , I)
16: case α = Σvα0 :
17: Guess I 0 ∈ {I \ {¬v} ∪ {v}, I \ {v} ∪ {¬v}}
18: Execute EvalR (α0 , I 0 )

α = Σ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

c0.1 v(c0.1 ) = 0 · 3 c0.0 v(c0.0 ) = 1 · 3

0 1

c0.1.0 v(c0.1.0 ) = 3 · 1 c0.0.0 v(c0.0.0 ) = 3 · 1

3 3

c0.1.0.0 v(c0.1.0.0 ) = 1 c0.0.0.0 v(c0.0.0.0 ) = 1

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.

Definition 15 (Surrogate Alphabet). Let R be a semiring and let Σ be some alphabet.


Then the surrogate alphabet sS,V,E (Σ) is set of words over Σ extended with surrogates (for
semiring variables) defined by

sS,V,E (Σ) = (Σ ∪ {SV n E | n ∈ N})∗ ,

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

Definition 16 (Karp Surrogate-Reduction). Let f1 and f2 be functions fi : (Σ ∪ R)∗ →


R, i = 1, 2. Then a Karp surrogate sS,V,E reduction from f1 to f2 is a polynomial time
computable function T : sS,V,E (Σ) → sS,V,E (Σ) with a finite set R0 = {r1 , . . . , rk } ⊆ R,
k ≥ 0, of semiring values such that for all x ∈ sS,V,E (Σ) and σ : N → R such that
σ(i−1) = ri , 1 ≤ i ≤ k, it holds that f1 (σ(x)) = f2 (σ(T (x))).
Since we only use Karp surrogate sS,V,E reductions with surrogate alphabet S, V, E we
omit sS,V,E and write “Karp s-reduction”.

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:

Lemma 17. Let R be a semiring and fi : (Σ ∪ R)∗ → R, i = 1, 2. If f2 ∈ NP(R) and f1 is


Karp s-reducible to f2 then f1 ∈ NP(R).

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.

Proof (sketch). We prove membership constructively, using the SRTM Algorithm 1. We


need to prove that EvalR (α, ∅) = JαKR (∅), for any ΣBF α. When considering the formula
α we could exhaustively apply the distributive law for every addition (+, Σa) that occurs
inside a multiplication (∗). Then one obtains a sum of products of values from the semiring
and literals. In general this would, however, lead to a formula that is exponentially bigger
than α. Instead, the idea of EvalR is to non-deterministically generate every summand s
that we would have after having exhaustively applied the distributive law. For each non-
deterministically generated s consisting of factors f1 , . . . , fm , EvalR has a computation
path that includes a transition with weight fi for each i = 1, . . . , m. This happens in such
a way that each sequence of choices leads to a different s and such that every s is covered
by a sequence of choices. Thus, the sum, using ⊕, of the value of all execution paths for a
call to EvalR (α, ∅) is equal to JαKR (I).
To prove the NP(R)-hardness, we can generalize the well-known Cook-Levin Theorem,
cf. (Gary & Johnson, 1979). Here, we need to rewrite disjunctions a ∨ b into formulas
a + ¬a ∗ b s.t. these constraints can only be equal to either e⊕ or e⊗ but not e⊗ ⊕e⊗ . Apart
from that we only need to add the weights of transitions to the formula.

Nevertheless, before we prove a wide range of semiring formalism to be NP(R)-complete,


we discuss in the following possible alternative choices in the definition of SRTMs and their
effect on the computational power of SRTMs.

4.2.1 Alternative SRTM Definitions


There are multiple possible small changes in the definition of SRTMs that would lead to an
alternative model of non-deterministic computations over semirings and therefore also to an
alternative complexity class NP(R). We discuss some of these possible changes and their
implications on the power of SRTMs, to explain our rationale for choosing this definition of
SRTMs.

Allowing Semiring Operations on the Tape One alternative would be to remove


the weights from the transition functions and instead to let the machine multiply and add
values on a tape explicitly. We see two main options that would enable this change. The
first is to depart from the idea to use semiring values on the tape and to encode them in
some finite alphabet instead. This would have the positive effect of getting a definition that
is very close to the definition of typical non-deterministic TMs. However, this comes with
two significant drawbacks.
First, it implies that we need to choose an encoding of the semiring values. As we will
see later on, in Examples 11 and 12, the choice of the encoding can strongly influence the
complexity of semiring operations. We want to avoid this, since we want to use SRTMs to
characterize the complexity associated with a semiring, rather than the complexity associ-
ated with the encoding of its values.
Second, it would allow for the computation of functions that cannot be Karp-reduced
to SAT(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).

Alternatively, we could allow for the computation of sums/products of pairs of semiring


values, which can be written to the tape (e.g. using multiple tapes or heads). Without
additional restrictions, this would also give SRTMs more power than what can be expressed
using SAT(R).

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.

5. Completeness Results for Semiring Frameworks


SAT(R) and NP(R) generalize SAT and NP to the semiring setting. As we discussed above
their definitions equip SAT(R) and NP(R) with appropriate power. This is underlined also
by the fact that as one expects SAT(R) is NP(R)-complete. Therefore, we now have all the
necessary prerequisites for a complexity analysis of frameworks that are defined dependent
on a semiring parameter.
In the following, we apply the results from above to different semiring formalisms in AI.

5.1 Sum-Of-Products Problems


Another prototypical problem that is similar to SAT(R) is the Sum-of-Products Problem
SumProd(R) (Bacchus et al., 2009). It is defined as follows
Definition 19 (SumProd(R)). Given a finite domain D and functions fi : Dji → R, i =
1, . . . , n, compute
L Nn ~
X1 ,...,Xm ∈D i=1 fi (Yi ), (1)

where Y~i is a vector with entries from a set {X1 , . . . , Xm } of variables.


To solve a problem instance, we need to compute the sum of the products of the functions
fi for all assignments of the variables Xi . Here, the “sum” and the “product” are the
addition ⊕ and multiplication ⊗ of the semiring R, respectively.
There are two main differences between SAT(R) and SumProd(R). The first is that
SumProd(R) does not admit sums that occur under products, whereas for SAT(R) sums
and products can alternate arbitrarily. Second, SumProd(R) is not propositional but more
related to first-order logic, since we are not summing up values using a quantifier Σaα by
evaluating α under both truth values of a. Instead, we are summing up values over all
assignments to variables over a finite domain.

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.

5.2 Weighted First-Order Logic


Weighted first-order logics were introduced by Mandrali and Rahonis (2015) for expressivity
characterizations and by Eiter and Kiesel (2020) for a quantitative extension of ASP.
They are defined over a signature σ = hD, P, X i with predicates p ∈ P that have a fixed
arity r(p) ∈ N over a domain D and variables in X .
Definition 21 (Syntax). Let σ = hD, P, X i be a signature and R = (R, ⊕, ⊗, e⊕ , e⊗ ) be
a commutative semiring. The weighted σ-formulas over R are of the form α given by the
grammar

α ::= k | p(~x) | ¬p(~x) | α + α | α ∗ α | Σxα | Πxα.

Here k ∈ R, p ∈ P, ~x ∈ (D ∪ X )r(p) and x ∈ X . A weighted σ-sentence is a weighted


σ-formula that does not contain free variables.
Note that we again only allow for negation in front of atoms p(~x).
Definition 22 (Semantics). A σ-interpretation is a subset I of {p(~x), ¬p(~x) | p ∈ P and
~x ∈ Dr(p) } s.t. ¬p(~x) ∈ I ⇔ p(~x) 6∈ I for all p ∈ P, ~x ∈ Dr(p) . Given a weighted σ-sentence
β and a σ-interpretation I the semantics JβKR (I) of β over R w.r.t. I is defined as
L
JΣxβKR (I) = d∈D Jβ{x 7→ d}KR (I)
N
JΠxβKR (I) = d∈D Jβ{x 7→ d}KR (I)

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):

ΣFO-Eval(R): Given a weighted ΣFO σ-sentence α over the commutative semiring R


and a σ-interpretation I, compute JαKR (I).

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 ).

5.3 Semiring-based Constraint Satisfaction Problems


Recall the definition of SCSPs from Section 3. We see that the computation of blevel(P )
is a sum of the products of the values of the constraints in P over all possible variable
assignments. If def is given explicitly as key value pairs of variable assignments and semiring
values, we obtain:

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).

5.4 Algebraic Model Counting


Recall the definition of AMC from Section 3. Since AMC also follows the guess-evaluate-
aggregate pattern, we can show:

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.

5.5 Datalog Semiring Provenance


Green at al. (2007) introduced a semiring-based semantics for relational algebra queries. Its
main use case as described in the paper is to allow queries for the provenance of answers
to standard queries. The semantics is capable of expressing bag semantics, why-provenance
and more. Here intuitively, bag semantics tell us not only whether we can derive a query
but also how often we can derive it. Why-provenance tells us instead the different reasons
why we have to derive a query. There are more possibilities but generally, the semiring
semantics allows us to obtain more, often quantitative, information about the derivations
of a query.
For positive logic programs, i.e. datalog programs, their semantics over a commutative
semiring (R, ⊕, ⊗, e⊕ , e⊗ ) is as follows: the label of a query result q(x) is the sum (using
⊕) of the labels of derivation trees for q(x), where the label of a derivation tree is the
product (using ⊗) of the labels of the leaf nodes (i.e. extensional atoms). As the number of
derivation trees may be countably infinite, Green et al. used ω-continuous semirings, where
countable sums have a value. Examples of such semirings are N∞ = (N ∪ {∞}, +, ·, 0, 1),
the natural number semiring extended with infinity, B, and other idempotent semirings.

Example 9 (Bag Semantics). Consider the program

r1 : q(X, Y ) ← r(X, Y ) r2 : q(X, Y ) ← q(X, Z), q(Z, Y )

over N∞ and the semiring-weighted extensional database (edb)

{(r(a, b), 2), (r(b, c), 3), (r(b, a), 4)}.

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.

Theorem 26. Given a positive, single-rule datalog program

Π = {q ← r1 (Y~1 ), . . . , rn (Y~n )}

and a semiring-weighted extensional database D over a commutative semiring R as input,


it is NP(R)-complete w.r.t. Karp s-reductions to compute the label of q.

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.

Proof. Hardness: We provide a reduction from SumProd(R). Let D be a finite domain,


fi : Dki → R, i = 1, . . . , n be functions with the set of semiring values as co-domain, and let
L Nn ~
X1 ,...,Xm ∈D i=1 fi (Yi ), (2)

be the SumProd(R)-instance at hand. Here, Y~i is a tuple consisting of ki elements from


{X1 , . . . , Xm }, the set of variables of the SumProd(R)-instance, for i = 1, . . . , n.
Consider the following positive, single-rule datalog program

Π = {q ← r1 (Y~1 ), . . . , rn (Y~n )}

and the semiring-weighted extensional database


[
D= {(ri (~ yi )) | y~i ∈ Dki }.
yi ), fi (~
i=1,...,n

Both D and Π can be constructed in polynomial time from the SumProd(R)-instance.


Furthermore, the label of the query q is equal to the result of evaluating the SumProd(R)-
instance. Since SumProd(R) is NP(R)-complete w.r.t. Karp s-reductions, also provenance
queries are NP(R)-hard.
NP(R)-membership: We can reduce to SumProd(R) analogously to obtain that prove-
nance queries of the above form over R are in NP(R). This implies NP(R)-completeness
overall.

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.

5.6 Semiring-induced Propositional Logic


Larrosa et al. (2010) introduced an extension of propositional logic with a semiring-based
semantics. They confined to CNF formulas and associated a weight from the semiring with
each of the clauses. Formally:
Definition 27 (SRPL). Given a semiring-labeled CNF F = {(C1 , w1 ) . . . , (Cn , wn )} over
a commutative semiring R, where each Ci is a clause and wi ∈ R is a value from R, the
semantics φi (I) of clause Ci under interpretation I is

wi if I 6|= Ci
φi (I) = .
e⊗ otherwise.
Here, |= is the satisfaction relation of classical propositional logic.
Furthermore, φF (I), the semantics of F under interpretation I is given by
φF (I) = ni=1 φi (I).
N

This is reminiscent of the evaluation of a SumProd(R)-instance for one assignment ~x


~ both the term under the assignment ~x and φF (I) are products of values
to the variables X:
functionally determined by ~x and I, respectively.
As with SumProd(R), one is not interested in the value for a single assignment but in
the sum over all assignments, called marginal here, which is defined as follows:
Definition 28 (Marginalization Problem). Given a semiring-labeled CNF F over a com-
mutative semiring R as input, the marginalization problem over R is to compute
L
mrg(F ) = I∈Int(F ) φF (I),
where Int(F ) denotes for a semiring-labeled CNF F the set of all interpretations of variables
in F .

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.

Theorem 29. The marginalization problem over R is NP(R)-complete w.r.t. Karp s-


reductions for every commutative semiring R.

Proof (Sketch). NP(R)-membership is easy to establish by a simple guess and evaluate


algorithm.
We can prove NP(R)-hardness by a reduction from AMC over R. W.l.o.g. we assume
that the propositional theory T of the given AMC instance is a CNF with clauses C1 , . . . , Cn
and the labeling function is α. Then the result of the marginalization problem for

F = {(C1 , e⊕ ), . . . , (Cn , e⊕ )} ∪ {(¬v, α(v)) | v ∈ V } ∪ {(v, α(¬v)) | v ∈ V },

where V is the set of variables of T , is the algebraic model count of T with respect to α.

5.7 Other Frameworks


There are also other frameworks, such as algebraic Prolog (Kimmig et al., 2011), algebraic
measures (Eiter et al., 2021), and semiring induced valuation algebras (Kohlas & Wilson,
2008) that we can show to be NP(R)-complete using our methodology and the previous
reductions. We refrain from doing so, since the corresponding evaluation problems either
already come with reductions to AMC (Kimmig et al., 2017; Eiter et al., 2021) or are
very similar to other frameworks as in the case of semiring induced valuation algebras and
SCSPs.

6. Relation to Well-known Classical Complexity Classes


We were able to show in the previous section that NP(R) can be used to characterize the
complexity of many different semiring formalisms that each in a way use the guess-evaluate-
aggregate pattern. However, these results only characterize the complexity over different
semirings on a relatively abstract level by using SRTMs as a machine model. In order to
gain more tangible insights into their complexity in a usual setting, we relate NP(R) to
well-known classical complexity classes defined on Turing machines in this section.
For this purpose, we must encode semiring values in a finite tape alphabet. As we will
see, the choice of encoding can strongly influence the complexity of computations over a
semiring. To address this, we introduce conditions for efficient encodings that we can use
to limit the influence of the encoding.
Equipped with this, we first link well known complexity classes such as NP, #P, and
OptP with NP(R) for specific semirings, thus showing that NP(R) is in a sense a proper
generalization of existing quantitative complexity classes.
We then turn to the more general case of commutative semirings as a whole and sub-
classes thereof. Here, we prove on the one hand general lower bounds, upper bounds and
a tetrachotomy result that separates the non-trivial semirings into four distinct types of
problems each of which is strongly connected to either NP, Modp P, NP ∪ Modp P or #P.

233
Eiter & Kiesel

6.1 Encoding Semirings


To represent semiring values on classical Turing machines, we need to encode their values us-
ing an encoding function. We introduce the necessary notions and consider the implications
that the choice of the encoding has on the complexity

Definition 30 (Encoding Function, Encoded Semiring). Let R = (R, ⊕, ⊗, e⊕ , e⊗ ) be a


semiring. Then an injective function τ : R → {0, 1}∗ is an encoding function.
We let τ (R) = (τ (R), ⊕, ⊗, τ (e⊕ ), τ (e⊗ )) denote the encoded semiring given by τ (R) =
{τ (r) | r ∈ R} and on τ (R), s.t. τ (r1 ) τ (r2 ) = τ (r1 r2 ) for = ⊕, ⊗.
Given an encoded value τ (r) we define krkτ , the size of r w.r.t. τ , as the length of the
bitstring τ (r), i.e. |τ (r)|.

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.

Then multiplication requires deciding mi ∈ M . When M corresponds to the Halting problem,


we have undecidability.

However, the difficulty stems from the encoding.

Example 12 (Example 11 cont.). If the encoding τ maps m ∈ {0, 1}∗ to (m, 1) if m ∈ M


and to (m, 0) if m 6∈ M , then multiplication and addition in τ (RM ) are computable in linear
time.

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

Definition 31 (Efficiently Encoded Semiring). Let τ (R) be an encoded semiring. Then


τ (R) is efficiently encoded if there exists a polynomial p(x) s.t. for all τ (r1 ), . . . , τ (rn ) ∈
τ (R) it holds that
1. k ni=1 ri kτ ≤ p(n) maxi=1,...,n kri kτ ,
N

2. k ni=1 ri kτ ≤ p(log2 (n)) maxi=1,...,n kri kτ , and


L

3. τ (r), τ (r0 ) 7→ τ (r r0 ) is in FP for = ⊕, ⊗.


Conditions 1) and 2) ensure that successive multiplications resp. additions do not cause
space explosion, even for sums with exponentially many terms. Condition 3) is necessary
since we at least need single additions and multiplications to be tractable if we want to
solve problems over a semiring efficiently. The idea behind these conditions is to separate
encodings that behave “efficiently” both with respect to space and time and those that
do not. For this, we use restrictions that mirror and slightly relax the properties that the
prototypical binary encoding “bin(.)” of integers satisfies.
As desired and expected, for integers, a binary representation satisfies the restrictions,
whereas a unary representation does not.
Example 13. With binary representation bin(n) = b0 . . . bm s.t. n = m i
P
i=1 bi 2 , the semiring
N of the natural numbers is efficiently encoded. With the unary representation unary(n),
which represents a natural number as a string of n characters, the natural numbers are not
efficiently encoded and in fact do not satisfy any of the conditions 1)-3).
Furthermore, also N[(xi )∞ ] is not efficiently encoded when polynomials are encoded as
ei e
lists of monomials and every monomial of the form c~i xi11 . . . xinin is encoded using a unary
or binary representation of the coefficients c~i , the exponents eij , and variable indices ij .
The conditions of Definition 31 are mild in practice, as besides N many common semir-
ings, e.g. Z, Q, Rmax , are efficiently encodable.
When a semiring is efficiently encoded, we can establish a polynomial space upper bound
on the complexity of ΣBF evaluation.
Proposition 32 (FPSpace(poly) Upper-Bound). If τ (R) is an efficiently encoded com-
mutative semiring, then SAT(τ (R)) is in FPSpace(poly).
Proof (Sketch). As we have seen before, the value of an SAT(τ (R))-instance α can be
expressed as a sum of products of the semiring values in α by implicitly applying the
distributive law on α during evaluation as in Algorithm 1. The length of the encoding
of each addend of this sum is polynomially bounded in the size of α due to condition 1
of efficient encodedness. Since there are only single exponentially many such addends, it
follows from condition 2 of efficient encodedness that the final result also has polynomial
size in the size of the biggest addend and is therefore also polynomial in the size of the input.
By generating the addends one after the other we, thus, stay in polynomial space.

6.2 Results for Specific Semirings


Before we consider the complexity in dependence on the semiring parameter in general,
we relate well-known classical complexity classes to NP(τ (R)) by showing that they share
SAT(τ (R)) as a complete problem for different specific semirings.

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.

6.3 Results for Classes of Semirings


Apart from completeness results for specific semirings, we also care about intuition on why
some semirings come with a higher complexity than others, and about results that help to
characterize new semirings based on their properties. Thus, we consider the complexity of
different classes of semirings that satisfy some property, which allows us to make non-trivial
claims about the complexity entailed by evaluating problems over them.

6.3.1 General Lower Bound and Tetrachotomy


First, we consider how hard SAT(R) has to be at least in general. For this we show the
following result:

Theorem 34 (General Lower Bound). Let τ (R) be an encoded commutative semiring.


Then one of the following holds:

1. τ (R) = T, i.e., the semiring is trivial

2. SAT(τ (R)) is Modp P-hard with respect to counting reductions for some p ∈ N or

3. SAT(τ (R)) is NP-hard with respect to counting reductions.

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

Proof of Lemma 35. We proceed by case distinction. Let I be an interpretation.


Case I |= l1 : Then
Jd(C)KR (I) = e⊗ ⊕e⊕ ⊕e⊕ = e⊗
since Jl1 KR (I) = e⊗ and Jl1 KR (I) = e⊕ .
Case I 6|= l1 , I |= l2 : Then

Jd(C)KR (I) = e⊕ ⊕e⊗ ⊕e⊕ = e⊗ .

Case I 6|= l1 , I 6|= l2 , I |= l3 : Then

Jd(C)KR (I) = e⊕ ⊕e⊕ ⊕e⊗ = e⊗ .

Case I 6|= l1 , I 6|= l2 , I 6|= l3 : Then

Jd(C)KR (I) = e⊕ ⊕e⊕ ⊕e⊕ = e⊕ .

This covers all cases and we see that when I |= C, then Jd(C)KR (I) = e⊗ and otherwise
Jd(C)KR (I) = e⊕ .

Furthermore, for n ∈ N and r ∈ R, we let



e⊕ n=0
n·r = .
((n − 1) · r)⊕r n > 0

Proof of Theorem 34. Assume τ (R) 6= T, since otherwise we are done.


We distinguish the following cases. If for all n ∈ N it holds that n · τ (e⊗ ) = τ (e⊕ )
implies n = 0, then SAT(τ (R)) Vn is NP-hard with respect to counting reductions. For the
proof, consider a 3CNF φ = i=1 Ci with variables v1 , . . . , vm . Then φ is satisfiable iff for
α = Σv1 . . . Σvm Πni=1 d(Ci ) it holds that JαKτ (R) (∅) 6= τ (e⊕ ).
Otherwise, let M = hτ (e⊗ )i and

p = min{n ∈ N | n > 0, n · τ (e⊗ ) = e⊕ }.

We claim that M = {n · τ (e⊗ ) | n ∈ N}. This can be seen as follows. By definition of


generated semirings, hτ (e⊗ )i is the smallest semiring with addition ⊕ and multiplication ⊗
that contains τ (e⊗ ). We go over the relevant semiring axioms one by one. First, τ (e⊕ ) =
0 · τ (e⊗ ) and thus of the desired form. Second, τ (e⊗ ) = 1 · τ (e⊗ ) and thus of the desired
form. Next, M must be closed under ⊕. So let n · τ (e⊗ ), m · τ (e⊗ ) ∈ M . Then,

(n · τ (e⊗ ))⊕(m · τ (e⊗ )) = ((n + 1) · τ (e⊗ ))⊕((m − 1) · τ (e⊗ )) = · · · = (n + m) · τ (e⊗ ),

since ⊕ is commutative. Last but not least, M must be closed under ⊗. So let n · τ (e⊗ ), m ·
τ (e⊗ ) ∈ M . Then,

(n · τ (e⊗ ))⊗(m · τ (e⊗ )) = (n · τ (e⊗ ))⊗((m − 1) · τ (e⊗ )) ⊕ (n · τ (e⊗ ))⊗τ (e⊗ )


= ...
= (n · m) · τ (e⊗ )⊗τ (e⊗ )
= (n · m) · τ (e⊗ ),

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

Theorem 38 (Tetrachotomy). Let τ (R) 6= T be an efficiently encoded commutative semir-


ing. Then we have exactly one of the four following situations:

• τ (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.

Proof. Clearly, τ (R) is exactly one of

1. periodic with periodicity 1

2. periodic with periodicity p ≥ 2 and offset 0

3. periodic with periodicity p ≥ 2 and offset o > 0

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

α is m · τ (e⊗ ), where m is the number V of models of φ. This is possible in polynomial time


by first constructing a 3CNF ψ = ni=1 Ci with variables v1 , . . . , vm and the same number
of models and using α = Σv1 . . . Σvm Πni=1 d(Ci ), where d(Ci ) is as in Lemma 35. Then,
evaluate α, guess 0 ≤ n ≤ 2|V ars(φ)| , where V ars(φ) denotes the set of variables in φ, and
compute n · τ (e⊗ ). If n · τ (e⊗ ) is equal to the semantics of α accept and return n, otherwise
reject.

6.3.2 Upper Bounds using Polynomial Semirings


We have seen results on the hardness of commutative semirings in general and some con-
tainment results for the case when we only use weights of the form k · e⊗ for some k ∈ N in
the evaluation of an instance. In order to also obtain containment results for the case when
we do have arbitrary weights, we need to apply a different kind of strategy.
The problem with proper weights is that they intuitively allow us to preserve more
information when they are added or multiplied. We start with a formalization of this
intuition by showing that epimorphisms, which can be seen to map a semiring R1 to an at
most as informative semiring R2 , can be used to reduce SAT(R2 ) to SAT(R1 ).
This makes polynomial semirings such as N[(xi )∞ ] very interesting for us since they are,
as we will see, the most information preserving countable commutative semirings and can
thus always be reduced to. We show that in some cases this strategy is unlikely to work
but also prove that there are still large subclasses of semirings where it does.
We start by defining epimorphisms.

Definition 39 (Homomorphism, Epimorphism). Let Ri = (Ri , ⊕i , ⊗i , e⊕i , e⊗i ), i = 1, 2


be two semirings. A homomorphism from R1 to R2 is a function f : R1 → R2 s.t. for
= ⊕, ⊗

f (r 1 r0 ) = f (r) 2 f (r0 ) and f (e 1 )=e 2 .

If f is in addition surjective, then it is an epimorphism.

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

1. there exists a polynomial time computable epimorphism f : τ1 (R1 ) → τ2 (R2 ), and

2. for each τ2 (r2 ) ∈ τ (R2 ) one can compute in polynomial time τ1 (r1 ) s.t. f (τ1 (r1 )) =
τ2 (r2 ) from τ2 (r2 ).

Then SAT(τ2 (R2 )) is counting-reducible to SAT(τ1 (R1 )).

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

Relation of complexity classes C and semirings R, indicated by dotted lines C R.


Figure 2: Epimorphisms f : R1 → R2 between semirings, indicated by arrows R1 → R2 .
let
e
Semiring Reasoning Frameworks in AI and Their Computational Complexity

information preserving as R1 and therefore at least as hard structurally. This is because a


homomorphism f may assign different values r 6= r0 ∈ R1 the same value f (r) = f (r0 ) ∈ R2 .
Then, while we could distinguish these values in the context of R1 , we cannot do the same
in R2 . However, clearly it cannot happen that f (r) 6= f (r0 ) ∈ R2 but r = r0 ∈ R1 .
Note that the existence of such an epimorphism does not necessarily mean that the
computational complexity of SAT(R2 ) is lower than SAT(R1 ) unless the other conditions
of Theorem 40 are also satisfied!

Example 15. The semiring RM from Example 11 is a homomorphic image of B[(xi )∞ ]


using the epimorphism defined by f (xi ) = bin(i). But SAT(B[(xi )∞ ]) is in FPSpace(exp),
while, as noted before already a single multiplication in RM may be undecidable. This does
not contradict Theorem 40 since we cannot apply it as computing f (xi · xj ) is not possible
in polynomial time when M corresponds to the Halting problem.

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.

Lemma 41 (Hardest Semirings). There exists an encoding τ ∗ for

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

1. periodic with periodicity 1;

2. periodic with periodicity p ≥ 2 and offset 0;

243
Eiter & Kiesel

3. periodic with periodicity p ≥ 2 and offset o > 0;

4. not periodic

it holds that SAT(τ (R)) is counting reducible to

1. SAT(τ ∗ (N≤o [(xi )∞ ]));

2. SAT(τ ∗ (Zp [(xi )∞ ]));

3. SAT(τ ∗ (N≤o × Zp [(xi )∞ ]));

4. SAT(τ ∗ (N[(xi )∞ ])), respectively.

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.

1) kJαKR (∅)kτ is polynomial in the size of α,

2) we can extract the binary representation of the coefficient n ∈ N (resp. b ∈ B) of


xji11 ...xjinn from τ (r) in time polynomial in krkτ , and

3) kxi kτ is polynomial in i,

then #P ⊆ FP/poly (resp. NP ⊆ P/poly).

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.

1) kJαKR (∅)kτ is polynomial in the size of α,

2) we can extract the binary representation of the coefficient n ∈ N (resp. b ∈ B) of xi


from τ (r) in time polynomial in krkτ , and

3) kxi kτ is polynomial in log2 (i),

then #P ⊆ FP/poly (resp. NP ⊆ P/poly).

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).

Notably, the converse of Theorem 43 also holds:

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.

Thus, the existence of an encoding τ as in Theorem 43 for R = N[x] (resp. R = B[x])


equivalent to the pure complexity-theoretic question whether #P ⊆ FP/poly (resp. NP
⊆ P/poly), which is a well-known open problem in complexity theory.
We can obtain similar results to Theorems 42 and 43 in a more general setting for
polynomials with coefficients from any non-trivial commutative semiring.

Theorem 45. Let R 6= T be a commutative semiring. If there is an encoding function τ


for R[(xi )∞ ] s.t.

1) kJαKR[(xi )∞ ] (∅)kτ is polynomial in the size of α,

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.

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

3) kxi kτ is polynomial in log2 (i),


then either NP ⊆ P/poly or Modp P ⊆ P/poly for some p ∈ N.
As already mentioned before, if NP ⊆ P/poly, then the polynomial hierarchy collapses
to the second level. As a matter of fact, this also holds if Modp P ⊆ P/poly since:
Lemma 47. If Modp P ⊆ P/poly for p ∈ N, p > 1, then NP ⊆ P/poly.
Proof (sketch). Valiant and Vazirani (1986) showed that NP ⊆ RPUnique-SAT . Using RP
⊆ BPP we get RPUnique-SAT ⊆ BPP Unique-SAT and from Unique-SAT ∈ Modp P for any
p ∈ N, p > 1 it follows that NP ⊆ BPP Modp P .
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), even without the assumption
that Modp P ⊆ P/poly. We establish that PP/poly /poly ⊆ P/poly and BPP Modp P ⊆
PP/poly /poly ⊆ P/poly, which proves the result.

It follows that if there is any non-trivial commutative semiring R with an encoding τ


as required by Theorems 45 or 46 then NP ⊆ P/poly. This would imply a collapse of the
polynomial hierarchy and is therefore considered to be unlikely.
Summing up, we see that reducing SAT(τ (R)) to the polynomial semirings is not prac-
tical for encoded semirings τ (R) in general3 . However, we can obtain positive results when
restricting ourselves to polynomials with a limited number of variables by using a different
encoding.
Theorem 48. Let τ (R) be a commutative semiring that is efficiently encoded. Then
NP(τ (R))
SAT(τ (R[(xi )k ])) is FPk -complete for metric reductions, if we extend τ to R[(xi )k ]
by representing polynomials as lists of monomials with exponents in unary and coefficients
encoded by τ .
As mentioned before the semirings of polynomials with coefficients in τ (R) allow one
to solve multiple SAT(τ (R))-instances at the same time. Theorem 48 shows that when
we choose a specific encoding and allow at most k variables then the number of instances
that can be solved using one instance over the corresponding semiring τ (R[(xi )k ]) is exactly
polynomial.
3. Note that Knowledge Compilation (Darwiche & Marquis, 2002) intuitively does something very similar
but optimizes the size of the representation of the polynomials such that it can be bounded using the
treewidth of a given formula.

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 .

As an immediate consequence, we see that SAT(bin(Q[(xi )k ])) and SAT(bin(B[(xi )k ]))


are metrically reducible to FP#P
k (which is equal to FP#P[1] ) and FPNP
k , respectively, and
thus not significantly harder than #P and NP, respectively.
The same can be said when a SAT(τ (R))-instance only contains few values from the
semiring.
Lemma 49. Let k ∈ N be fixed, τ (R) be an efficiently encoded commutative semiring. If
τ (R) is
1. periodic with periodicity 1;

2. periodic with periodicity p ≥ 2 and offset 0;

3. periodic with periodicity p ≥ 2 and offset o > 0;

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

2. SAT(bin(Zp [(xi )k ])), when τ (R) has periodicity p ≥ 2 and offset 0;

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

• we can obtain ai , ei,j from τ (r) in polynomial time.


If τ (R) is
1. periodic with periodicity 1;

2. periodic with periodicity p ≥ 2 and offset 0;

3. periodic with periodicity p ≥ 2 and offset o > 0;

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.

7. Discussion and Related Work


In this section, we consider related models of computation with algebraic structures, de-
scribe some further applications of our results and provide more discussion on the effects of
encodings.

7.1 Other Machine Models


In order to capture the complexity of quantitative reasoning frameworks that are defined
over semirings R, we introduced Semiring Turing Machines. SRTMs are non-deterministic
Turing machines whose result is determined by their transitions that are weighted with
semiring values; SAT(R) and NP(R), the versions of SAT and NP that are generalized to
semirings are in the expected relation, viz. that SAT(R) is NP(R)-complete with respect
to (adjusted) Karp-reductions.
In the literature, other extensions of machine models with means to deal with algebraic
structures have been considered.
Weighted Automata The machine model most related to our SRTMs is that of weighted
automata, which are finite state automata that have a (semiring)-weighted transition func-
tion (Droste & Gastin, 2007). SRTMs are a generalization of weighted automata and can
simulate the latter with ease; informally, they equip weighted automata with memory and
the full computational power of a Turing machine under the restriction that semiring values
are opaque. The connection to weighted automata is especially of interest due to their
connection to descriptive complexity, which opens up future work on the same topic for
SRTMs.
Blum-Shub-Smale Machines Next, our SRTMs are related to Blum-Shub-Smale (BSS)
machines, which were introduced by Blum et al. (1989, 1998) to model algebraic computa-

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.

Real Counting Computations Major motivations of Blum et al. to develop their


machine model were to have an idealized computation model for scientific computation with
real numbers, in which the cost of multiplication is independent of the size of numbers (which
on a Turing machine depends on the encoding), and to bring the theory of computation
into the domain of analysis, geometry and topology, such that the mathematics of these
subjects can then be put to use in the systematic analysis of algorithms (Blum et al., 1989).
Building on the BSS machine model, Meer (2000) developed a theory of counting problems
over the real numbers. To this end, he introduced the class #PR as the real analogue
of #P, which also counts accepting paths but of a non-deterministic BSS machine, and
then embarked on giving a logical characterization of #PR following descriptive complexity
theory over the reals, which has been initiated in (Grädel & Meer, 1995). Meer’s class #PR

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.

Real Counting with Arbitrarily Approximatable Weights A different definition of


#PR and #PS for S ⊆ R was provided by De Campos, Stamoulis, and Weyland (2020).
While they intuitively also define the output of a computation as the sum over weighted
computation paths like we do, they do not assume the values to be given explicitly but
require functions that compute them up to a variable precision of 2−p in polynomial time
in p. This allows them to work with a finite representation of real numbers. Interestingly,
this different way of encoding numbers leads to undecidability of the question whether a
computation in #PQ leads to a value greater than zero. Therefore, we argue that while
this matter of encoding numbers is interesting to allow computations with uncountable
semirings such as R on classical Turing machines, the explicit encoding in our setting is
of more interest when the semiring has only countably many values, as it leads to more
intuitive results.

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

7.2 Applying the Results for Problem Analysis


Just like the quantitative frameworks that are defined over semirings R capture many dif-
ferent quantitative problems when instantiated with the correct semiring, we showed that
the same is the case on the complexity level. Theorem 33 showed that 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. Thus, many well-known complexity
classes can be seen as instantiations of NP(R) with the appropriate semiring under the
usual representation of numbers.
Using NP(R), we are able to characterize the complexity of many semiring frameworks.
As our results show
• Sum-Of-Products Problems (Bacchus et al., 2009),
• Weighted First-Order Logic Evaluation (Mandrali & Rahonis, 2015; Eiter & Kiesel,
2020),
• Semiring-based Constrained Satisfaction Problems (Bistarelli et al., 1999),
• Algebraic Model Counting (Kimmig et al., 2017), and
• Semiring-induced Propositional Logic (Larrosa et al., 2010)
are all NP(R)-complete with respect to Karp-reductions. Furthermore, we saw that Semir-
ing Provenance (Green et al., 2007) for Datalog is NP(R)-hard but not complete and
therefore even harder than other semiring formalisms.
As showcases, we consider some specific semirings to illustrate how our previous results
can be used to analyze the complexity of further specific semirings.
As a consequence of Theorems 40 and 48, or directly from Theorem 51 for the finitely
generated N, Z, we obtain:
Theorem 52. Let S = N, Z, Q. For Sn , n ∈ N, the semiring S over multiple dimensions, we
have that SAT(bin(S)n ) is FP#P
k -complete with respect to metric reductions, where bin(Q)
represents r ∈ Q as pair (bin(p), bin(q)) such that p/q = r, p ∈ Z, q ∈ N and the greatest
common divisor of |p| and q is 1.
As promised in the introduction, we consider in more detail the semiring
GRAD = (Q≥0 × Q, +, ⊗, (0, 0), (1, 0)),
where addition is coordinate-wise and (a1 , b1 ) ⊗ (a2 , b2 ) = (a1 · a2 , a2 · b1 + a1 · b2 ). It was
introduced by (Eisner, 2002) and shown to be useful for parameter optimization (Kimmig
et al., 2017; Manhaeve et al., 2019). Intuitively, we can compute gradient values with
GRAD and for (a, b) the value a to the computed result of some function and b corresponds
to its gradient with respect to some parameter.
There is an epimorphism f from Q[x] to GRAD, which can be seen by defining f on
the monomials qxi as

 i
  (0, q) if i = 1,
q(0, 1) if i > 0,
f (qxi ) = = (0, 0) if i > 1,
|q| otherwise.
(|q|, 0) otherwise.

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.

Theorem 53. SAT(GRAD) is FP#P


k -complete with respect to metric reductions.

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.

7.3 Effects of the Encoding


By considering the complexity of SAT(τ (R)) for encoded semirings τ (R) in terms of classi-
cal complexity classes, we are able to gain a broad overview of how the complexity depends
on the semiring. The main intuition that we gain is that the more information semiring
values can preserve in addition and multiplication the harder it is to evaluate SAT(τ (R)),
which we formalized using epimorphisms in Theorem 40. In the simplest case, where we
consider SAT(τ (he⊗ i)), instances only have weights of the form τ (k · e⊗ ) and can thus only
retain very limited information. Here, there are exactly four different types of non-trivial
problems that can occur. Namely, NP-, Modp P-, Modp P ∪ NP- or #P-like problems,
which are not only similarly hard as the corresponding complexity class but can also be
solved (under some additional restrictions on the encoding function τ ) with a corresponding
oracle.
Interestingly, the separation by problem type is already determined by the periodicity
and offset of the semiring and also applies to the case where general weights are allowed, if
the semiring is efficiently encoded. Namely, there exists an encoding τ ∗ such that all NP-,
Modp P-, Modp P ∪ NP- and #P-like problems can, respectively, be counting reduced to
SAT(τ ∗ (R[(xi )∞ ])) for R ∈ {N≤o , Zp , N≤o × Zp , N. This means that these semirings are in
a sense the hardest ones in this class of problems. In terms of information, the values of
these polynomial semirings intuitively carry the results of multiple C-queries, by handling
one C-query per monomial, where C is the corresponding complexity class of the problem
type.
Unfortunately, this is likely too much information to store in a “reasonable” polynomial
size output. For each n ∈ N we are able to construct a SAT(τ (he⊗ iR[(xi )∞ ]) )-instance of size
polynomial in n, whose result contains as information the solution of every SAT(τ (he⊗ iR ))-
instance without weights of size at most n. Since there are exponentially many such in-
stances, this would mean we would need to compute in some way the solution of exponen-
tially many C-instances. Using this insight we showed that the existence of a “reasonable”
encoding τ such that SAT(τ (R[(xi )∞ ])) is in FPSpace(poly) would imply a collapse of
the polynomial hierarchy and is, thus, considered to be unlikely.
While this strategy of reducing all C-like problems to the corresponding polynomial
semiring τ (R[(xi )∞ ]) does not seem recommendable, we see that with appropriate encodings
τ the semiring τ (R[(xi )k ]) of the polynomials with at most k variables only allows us to
retrieve information about polynomially many calls to a C-oracle. We can exploit this result

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.

8. Summary and Outlook


In this paper, we have presented a model of computation that equips Turing machines with
weighted transitions using values from a semiring, and we have defined with NP(R) an
analogue of NP over generic semirings R ; specific instances can be used to characterize the
complexity of a number of problems in quantitative reasoning frameworks in AI. Further-
more, we have linked the novel semiring complexity classes to standard complexity classes,
by looking into the encoding of a semiring for conventional, string-based computing.
Our investigation of semiring complexity motivated by AI problems is by no means
exhaustive. On the contrary, there are a number of further research issues that emerge
from it that remain for future work.

Other Classes of Semirings In this paper, we have focused on commutative semirings


and restrictions on the addition of the semiring. Dropping commutativity should lead to
problems that are at least as hard as in presence of commutativity according to Theo-
rem 40, since we can find epimorphisms from non-commutative to commutative semirings
but in general not the other way around. While some of our results do not make use of
commutativity, others such as Theorem 51 rely on it. Furthermore, periodicity and offset
are properties of the addition of the semiring. If we impose additional conditions on mul-
tiplication, we may be able to exploit them for better upper bounds on the complexity of
the evaluation problem.

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

Semiring Counting Hierarchy Another issue of computational models over algebraic


structures that would deserve investigation is an analogue of the polynomial hierarchy for
general semirings, going beyond the one for counting problems over the natural numbers
as in the work of Allender and Wagner (1993). For example, the problem MajMajSAT
requires the solution of a counting problem over the natural numbers N on the second level,
cf. (Oztok, Choi, & Darwiche, 2016). Further problems such as computing the maximum
expected utility of a logical theory, probabilistic reasoning over stable models, Maximum
A Posteriori (MAP) inference and some decision theoretic problems are also intrinsically
second-level problems (Kiesel, Totis, & Kimmig, 2022) but use different semirings at the
different levels. The FAQ problem (Khamis, Ngo, & Rudra, 2016) lifts this to problems
at an arbitrary level, by allowing for sequences of semiring aggregates. It would thus be
interesting to enhance the power of SRTMs such that we can solve and characterize the
complexity of such multi-level semiring reasoning frameworks. A promising starting point
for this direction of research is the approach of Ladner (1989) who introduced a counting
version of the polynomial hierarchy based on alternating Turing Machines.

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.

Polynomial Semirings for Knowledge Compilation Another interesting avenue of


research is the application of polynomial semirings in the context of Knowledge Compilation.
Intuitively, many contemporary approaches in that area compile a circuit that represents
a value from B[(xi )∞ ] as succinctly as possible without losing information, cf. (Darwiche
& Marquis, 2002; Kimmig et al., 2017; Dudek, Phan, & Vardi, 2020). In an application
setting such as probabilistic reasoning or most probable explanation inference, this however
may be way more information than necessary. A way to mitigate this problem may be given
by semirings R[(xi )k ] with finitely many variables, which our results suggest may allow for
representations that are lot smaller. This would not only be of theoretical benefit but may
even lead to more efficient inference in practical applications.

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.

Appendix A. Prefix Normal Form


,→ Lemma 11
Lemma 11 (Prefix Normal Form). For every ΣBF α over a commutative semiring R there
exists a ΣBF β over R such that

(i) β = Σv1 . . . Σvn γ, where γ is quantifier free,

(ii) β can be constructed from α in polynomial time, and

(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

JαKR (∅) = J(Σvα1 ) ∗ α2 KR (∅)


= JΣvα1 KR (∅)⊗Jα2 KR (∅)
= (Jα1 KR ({v})⊕JαKR ({¬v})) ⊗Jα2 KR (∅)

Since addition distributes over multiplication and α2 does not contain v, we get

JαKR (∅) = Jα1 KR ({v})⊗Jα2 KR (∅)⊕Jα1 KR ({¬v})⊗Jα2 KR (∅)


= Jα1 KR ({v})⊗Jα2 KR ({v})⊕Jα1 KR ({¬v})⊗Jα2 KR ({¬v})
= Jα1 ∗ α2 KR ({v})⊕Jα1 ∗ α2 KR ({¬v})
= JΣv(α1 ∗ α2 )KR (∅)

So we can choose β = Σv(α1 ∗ α2 ).


Let α = α1 ∗ (Σvα2 ). This case works analogously to the previous one.
Let α = (Σvα1 ) + α2 . Then β = Σv(α1 + α2 ∗ v) has the following semantics w.r.t ∅

JβKR (∅) = JΣv(α1 + α2 ∗ v)KR (∅)


= Jα1 + α2 ∗ vKR ({v})⊕Jα1 + α2 ∗ vKR ({¬v})
= Jα1 + α2 KR ({v})⊕Jα1 KR ({¬v})
= Jα1 KR ({v})⊕Jα1 KR ({¬v})⊕Jα2 KR ({v})

Since w.l.o.g. v does not occur in α2 we have

JβKR (∅) = Jα1 KR ({v})⊕Jα1 KR ({¬v})⊕Jα2 KR ({v})

256
Semiring Reasoning Frameworks in AI and Their Computational Complexity

= JΣvα1 KR (∅)⊕Jα2 KR (∅)


= J(Σvα1 ) + α2 KR (∅)

So we can choose β = Σv(α1 + α2 ∗ v).


The case α = α1 + Σxα2 works analogously.
This shows that we can always push the Σ quantifier to the top in polynomially many steps
in the number of occurrences of ∗, + in α. Furthermore, as we only add ∗v to the formula
at most once for every combination of Σ and + in α, the size of β is also polynomial in
α.

Appendix B. NP(R)-completeness and Karp Reducibility


We prove NP(R)-completeness of SAT(R) and show that SAT(R), SumProd(R), AMC,
SCSP and ΣFO-Eval(R) are Karp-reducible to one another.

B.1 NP(R)-completeness of SAT(R)


,→ Theorem 18
Theorem 18. SAT(R) is NP(R)-complete w.r.t. Karp s-reductions for every commutative
semiring R.
Proof. Containment follows from Algorithm 1 and Proposition B.1.
For hardness we generalize the Cook-Levin Theorem. So let M = (R, R0 , Q, Σ, ι, t, δ)
be a polynomial time SRTM and x ∈ (Σ ∪ R)∗ be the input for which we want to compute
the output of M .
We define the following propositional variables:
• Ti,j,k , which is true if tape cell i contains symbol j at step k of the computation.

• Hi,k , which is true if the M ’s read/write head is at tape cell i at step k of the
computation.

• Qq,k , which is true if M is in state q at step k of the computation.


Furthermore, we need the following semiring values
• ri , which is the ith semiring value of the input x, and

• {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

We define a weighted QBF ΣT ΣH ΣQ α, where ΣT, ΣH, and ΣQ correspond to the


(sum) quantification of all variables Ti,j,k , Hi,k , and Qq,k , respectively, and α is the product
(i.e. connected with ∗) of the following subformulas

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.

5. ¬Ti,j,k + Ti,j,k ∗ ¬Ti,j 0 ,k


Variable ranges: −p(n) ≤ i ≤ p(n), j ∈ Σ ∪ {r1 , . . . , rs }, 0 ≤ k ≤ p(n)
There is at most one symbol per tape cell.

6. Σj∈Σ∪{ri1 ,...,rim } Ti,j,k


Variable ranges: −p(n) ≤ i ≤ p(n), 0 ≤ k ≤ p(n)
There is at least one symbol per tape cell.

7. ¬Ti,j,k + Ti,j,k ∗ ¬Ti,j 0 ,k+1 + Ti,j,k ∗ Ti,j 0 ,k+1 ∗ Hi,k


Variable ranges: −p(n) ≤ i ≤ p(n), j 6= j 0 ∈ Σ ∪ {r1 , . . . , rs }, 0 ≤ k < p(n)
Tape remains unchanged unless written.

8. ¬Qq,k + Qq,k ∗ ¬Qq0 ,k


Variable ranges: q 6= q 0 ∈ Q, 0 ≤ k ≤ p(n)
There is at most one state at a time.

9. ¬Hi,k + Hi,k ∗ ¬Hi0 ,k


Variable ranges: i 6= i0 , −p(n) ≤ i ≤ p(n), −p(n) ≤ i0 ≤ p(n), 0 ≤ k ≤ p(n)
There is at most one head position at a time.

¬Hi,k + Hi,k ∗ ¬Qq,k + Hi,k ∗ Qq,k ∗ ¬Ti,σ,k +


10.
Hi,k ∗ Qq,k ∗ Ti,σ,k ∗ Σ((q,σ),(q0 ,σ0 ),d,r)∈δ0 Hi+d,k+1 ∗ Qq0 ,k+1 ∗ Ti,σ0 ,k+1 ∗ r
Variable ranges: −p(n) ≤ i ≤ p(n), 0 ≤ k < p(n) and q ∈ Q, σ ∈ Σ ∪ {ri1 , . . . , rim }
s.t. there exist q 0 , σ 0 , d, r s.t. ((q, σ), (q 0 , σ 0 ), d, r) ∈ δ.
Possible transitions at computation step k when head is at position i with their re-
spective weight.
Here, we use

δ 0 = {((q, σ), (q 0 , σ 0 ), d, r) ∈ δ | σ, σ 0 ∈ Σ ∪ {r1 , . . . , rm }}

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

J¬Ti,j,k + Ti,j,k ∗ ¬Ti,j 0 ,k KR (I) = e⊕ ⊕e⊕ = e⊕ ,

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

8. ensures that there is at most one state at a time by analogous reasoning to 5.


9. ensures that there is at most one head position at a time by analogous reasoning to
5.
10. models the possible transitions at computation step k when the head is at position
i including their respective weights, if there is a possible transition for the given state and
tape cell entry. Otherwise, this subformula is not added but the one in 11. is. So assume
that Hi,k , Qq,k , Ti,σ,k ∈ I. Then the value of the subformula is

J¬Hi,k + Hi,k ∗ ¬Qq,k + Hi,k ∗ Qq,k ∗ ¬Ti,σ,k KR (I)⊕


JHi,k ∗ Qq,k ∗ Ti,σ,k ∗ Σ((q,σ),(q0 ,σ0 ),d,r)∈δ0 Hi+d,k+1 ∗ Qq0 ,k+1 ∗ Ti,σ0 ,k+1 ∗ rKR (I)
= e⊕ ⊕e⊗ ⊗JΣ((q,σ),(q0 ,σ0 ),d,r)∈δ0 Hi+d,k+1 ∗ Qq0 ,k+1 ∗ Ti,σ0 ,k+1 ∗ rKR (I)
= JΣ((q,σ),(q0 ,σ0 ),d,r)∈δ0 Hi+d,k+1 ∗ Qq0 ,k+1 ∗ Ti,σ0 ,k+1 ∗ rKR (I)

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

J¬Hi,k + Hi,k ∗ ¬Qq,k + Hi,k ∗ Qq,k ∗ ¬Ti,σ,k KR (I)⊕


JHi,k ∗ Qq,k ∗ Ti,σ,k ∗ Hi,k+1 ∗ Qq,k+1 ∗ Ti,σ,k+1 KR (I)
= e⊕ ⊕e⊗ ⊗JHi,k+1 ∗ Qq,k+1 ∗ Ti,σ,k+1 KR (I)

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

Proof. We proceed by structural induction on α.


• Case α = k:
The algorithm returns k, therefore the statement is true.
• Case α = l, l ∈ {v, ¬v}:
The algorithm returns e⊕ , e⊗ when l is false or true w.r.t. I, therefore the statement
is true.
• Case α = α1 + α2 :
The algorithm nondeterministically returns EvalR (α1 , I) or 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). Since we guess i ∈ {1, 2} nondeterministically EvalR (α, I) has
all the execution paths of EvalR (α1 , I) and EvalR (α2 , I) and therefore the sum of
all values produced by execution paths of EvalR (α, I) is equal to

Jα2 KR (I)⊕Jα2 KR (I) = JαKR (I).

• 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

By using distributivity, we obtain that this is equal to


 
n1 n2 n1 n2
k (1) ⊗ (1)  (1) (1) IH
M M M M
j1 kj2 = kj1 ⊗ kj2 = Jα1 KR (I)⊗Jα2 KR (I) = Jα1 ∗ α2 KR (I).
j1 =1 j2 =1 j1 =1 j2 =1

• Case α = Σv α:
Works analogously to case α = α1 + α2 .

B.2 Complexity of SumProd(R), AMC, SCSP, ΣFO-Eval(R), mrg(F ), Datalog


Semiring Provenance
,→ Theorems 20, 23 to 25 and 29
For the Karp-reducibility between SAT(R), SumProd(R), AMC, SCSP, ΣFO-Eval(R),
mrg(F ), we do not prove interreducibility between two problems at a time but prove it by
using the strategy visualized in Figure 3.

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),

• Computing blevel(P ) of an SCSP P over R,

• SumProd(R),

• AMC over R, and

• Computing mrg(F ) for a semiring-labeled CNF F over R.

Proof. Karp s-reducibility is transitive, therefore it suffices to prove

• SAT(R) is Karp s-reducible to ΣFO-Eval(R)

• ΣFO-Eval(R) is Karp s-reducible to computing blevel(P ) of an SCSP P over R

• Computing blevel(P ) of an SCSP P over R is Karp s-reducible to SumProd(R)

• SumProd(R) is Karp s-reducible to AMC over R

• AMC over R is Karp s-reducible to SAT(R)

• AMC over R is Karp s-reducible to mrg(F ) over R

• mrg(F ) over R is Karp s-reducible to AMC over R

This gives us that as desired

Corollary B.3. Theorems 20, 23 to 25 and 29 hold.

262
Semiring Reasoning Frameworks in AI and Their Computational Complexity

Proof. We proved in Theorem 18 that SAT(R) is NP(R)-complete. It follows from The-


orem B.2 and Lemma 17 that also all other problems are NP(R)-complete. Additionally,
Karp s-reducibility is shown in Theorem B.2.

We proceed to prove the Karp s-reducibilities in the order specified in the above Theo-
rem.

Lemma B.4. SAT(R) is Karp s-reducible to ΣFO-Eval(R)

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.

Lemma B.5. ΣFO-Eval(R) is Karp s-reducible to computing blevel(P ) of an SCSP P


over R

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 ).

Proof. Let α be a ΣFO weighted formula over semiring R, D be a domain and I be an


interpretation. We show that we can always push out the sum quantifiers.
Let α = (Σxα1 ) ∗ α2 . W.l.o.g. we can assume that α2 does not contain x. Then

JαKσR (I) = J(Σxα1 ) ∗ α2 KσR (I)


= JΣxα1 KσR (I)⊗Jα2 KσR (I)
σ σ
L 
= d∈D Jα1 {x 7→ d}KR (I) ⊗Jα2 KR (I)

Since addition distributes over multiplication and α2 does not contain x, we get

JαKσR (I) = (Jα1 {x 7→ d}KσR (I)⊗Jα2 {x 7→ d}KσR (I)


L
Ld∈D
= d∈D J(α1 ∗ α2 ){x 7→ d}KσR (I)
= JΣx(α1 ∗ α2 )KσR (I)

So we can choose β = Σx(α1 ∗ α2 ) and I 0 = I.


Let α = α1 ∗ (Σxα2 ). This case works analogously to the previous one.

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βKσR (I 0 ) = JΣx(α1 + (α2 ∗ pd∗ (x)))KσR (I 0 )


= d∈D J(α1 + (α2 ∗ pd∗ (x))){x 7→ d}KσR (I 0 )
L

= d∈D Jα1 {x 7→ d}KσR (I 0 )⊕J(α2 ∗ pd∗ (x)){x 7→ d}KσR (I 0 )


L

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

Jα2 KσR (I) d = d∗



σ 0 L σ
JβKR (I ) = d∈D Jα1 {x 7→ d}KR (I)⊕
e⊕ otherwise.
σ σ
L 
= d∈D Jα1 {x 7→ d}KR (I) ⊕Jα2 KR (I)
= JΣxα1 KσR (I)⊕Jα2 KσR (I)
= J(Σxα1 ) + α2 KσR (I)

So we can choose β = Σx(α1 + (α2 ∗ pd∗ (x))), I 0 = I ∪ {pd∗ (d∗ )}.


The case α = α1 + (Σxα2 ) works analogously.
This shows that we can always push the Σ quantifier to the top in polynomially many steps
in the number of occurrences of ∗ and + in α. Since we only need to add one predicate
pd∗ to handle all the disjunctions, the size of the interpretation only increases polynomially.
Last but not least, we only add ∗pd∗ (x) to the formula at most once for every combination
of Σ and + in α, the size of β is also polynomial in α.

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

JαKσR (I) = JβKσR (I).

Proof. Let α be a ΣFO weighted formula over semiring R, D be a domain, and I be an


interpretation. We iteratively replace every subformula Σxγ where γ does not contain x of
α by a formula with the same semantics w.r.t. D and I.
So let Σxγ be a weighted formula where γ does not contain x. It has the semantics

JΣxγKσR (I) = Jγ{x 7→ d}KσR (I)


L
Ld∈D
= (e⊗ ⊗JγKσR (I))
Ld∈D σ
= d∈D e⊗ ⊗JγKR (I)
σ σ
L 
= d∈D Je⊗ KR (I) ⊗JγKR (I)
= Je⊗ + . . . + e⊗ KσR (I)⊗JγKσR (I)

264
Semiring Reasoning Frameworks in AI and Their Computational Complexity

= J(e⊗ + . . . + e⊗ ) ∗ γKσR (I).

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.

We need one more auxiliary lemma:


Lemma B.8. For each clause a1 ∨ a2 ∨ a3 , where ai is a literal over the variables vs , s ∈ S
we can construct a constraint ca1 ∨a2 ∨a3 = hdef , coni s.t. def (d1 , d2 , d3 ) = e⊗ if d1 , d2 , d3 is
a satisfying assignment of a1 ∨ a2 ∨ a3 .
Proof. We can do this as follows.


 d1 , d2 , d3 ∈ {⊥, >},
e⊗ ∃i : (ai = vs ∧ di = >)

def (d1 , d2 , d3 ) = (3)

 ∨(ai = ¬vs ∧ di = ⊥)
e⊕ otherwise.

con is simply the set of variables that occur in a1 ∨ a2 ∨ a3 .

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 β

for some quantifier free β, that contains every variable xi , i = 1, . . . , n. We define P =


hC, {s, x1 , . . . , xn }i inductively on the structure of β s.t.

(ΠC) ⇓{x1 ,...,xn } = hdef , {x1 , . . . , xn }i,

and for all (d1 , . . . , dn ) ∈ Dn it holds that

def (d1 , . . . , dn ) = Jβ{xi 7→ di }KσR (I)

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

= (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

• For each (s, p(~x)) ∈ S(β):


We can see p(~x) as a constraint on the variables in ~x that evaluates to e⊗ when
p(σ(~x)) ∈ I for the assignment σ of the variables var(~x) in ~x and e⊕ otherwise. This
however only happens when the variable vs has value >, otherwise the value is e⊗ .
As a consequence we add the constraint set
C(s,p(~x)) = {c(s,p(~x)) }
c(s,p(~x)) = 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},
{vs } ∪ var(~x)i

• For each (s, ¬p(~x)) ∈ S(β):


Analogously with e⊗ and e⊕ swapped. We add the constraint set
C(s,¬p(~x)) = {c(s,¬p(~x)) }

266
Semiring Reasoning Frameworks in AI and Their Computational Complexity

c(s,¬p(~x)) = 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},
{vs } ∪ var(~x)i

• For each (s, α) ∈ S(β), α = α1 ∗ α2 :


Then we know that (s.0, α1 ), (s.1, α2 ) ∈ S(β). We require that for vs , vs.0 , vs.1 the
following relation holds:

vs → (vs.0 ∧ vs.1 )
¬vs → (¬vs.0 ∧ ¬vs.1 )

We can rewrite them in 3CNF as follows

(¬vs ∨ vs.0 ) ∧ (¬vs ∨ vs.1 )


(vs ∨ ¬vs.0 ) ∧ (vs ∨ ¬vs.1 ).

Then using Lemma B.8 (where a2 = a3 is possible) we add the constraint set

C(s,α) = {c¬vs ∨vs.0 , c¬vs ∨vs.1 , cvs ∨¬vs.0 , cvs ∨¬vs.1 }.

• For each (s, α) ∈ S(β), α = α1 + α2 :


Then we know that (s.0, α1 ), (s.1, α2 ) ∈ S(β). We require that for vs , vs.0 , vs.1 the
following relation holds:

vs → (vs.0 ∧ ¬vs.1 ∨ ¬vs.0 ∧ vs.1 )


¬vs → (¬vs.0 ∧ ¬vs.1 )

We can rewrite them in 3CNF as follows

(¬vs ∨ vs.0 ∨ vs.1 ) ∧ (¬vs ∨ ¬vs.0 ∨ ¬vs.1 )


(vs ∨ ¬vs.0 ) ∧ (vs ∨ ¬vs.1 ).

Then using Lemma B.8 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 .

So overall the constraint problem P is given as


[
h C(s,α) ∪ {cv0 }, {vs | (s, α) ∈ S(β)} ∪ {x1 , . . . , xn }i.
(s,α)∈S(β)

267
Eiter & Kiesel

This is feasible to construct in polynomial time in the size of β.


We prove the correctness of the approach by structural induction on β. We use the
induction invariant that for
S
(Π (s,α)∈S(β) C(s,α) ) ⇓{v0 ,x1 ,...,xn } = hdef , {v0 , x1 , . . . , xn }i,

and for all d1 , . . . , dn ∈ D

 Jβ{xi 7→ di }KσR (I)



d0 = >
def (d0 , . . . , dn ) = e⊗ d0 = ⊥
e⊕ otherwise.

holds.
• β = k, k ∈ R:
Then P = hh{> 7→ k} ∪ {⊥ 7→ e⊗ }, {v0 }i, {v0 }i. We know

(ΠC) ⇓v0 = hh{> 7→ k, ⊥ 7→ e⊗ }, {v0 }i.

Then due to Assertion (*)



 k d=>
def (d0 ) = e⊗ d=⊥
e⊕ otherwise.

 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 )

{v0.s | (s, α) ∈ S 0 (β1 )} ∪ {v1.s | (s, α) ∈ S 1 (β2 )} ∪ {v0 } ∪ var(β1 ) ∪ var(β2 )i


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
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

(ΠC) ⇓{v0 ,var(β)} = hdef , {v0 } ∪ var(β)i,

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.

 Jβ1 {xi 7→ di }KσR (I)⊗Jβ2 {xi 7→ di }KσR (I) d0 = >,


= e⊗ d0 = ⊥,
e⊕ otherwise.

270
Semiring Reasoning Frameworks in AI and Their Computational Complexity

 J(β1 ∗ β2 ){xi 7→ di }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 )

{v0.s | (s, α) ∈ S 0 (β1 )} ∪ {v1.s | (s, α) ∈ S 1 (β2 )} ∪ {v0 } ∪ var(β1 ) ∪ var(β2 )i

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

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.

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

 Jβ{xi 7→ di }KσR (I)



d0 = >
def (d0 , . . . , dn ) = e⊗ d0 = ⊥
e⊕ otherwise.

it remains to show that for

∪ {cv0 }) ⇓{x1 ,...,xn } = hdef 0 , {x1 , . . . , xn }i,


S
(Π (s,α)∈S(β) C(s,α)

and for all d1 , . . . , dn ∈ D

def 0 (d1 , . . . , dn ) = Jβ{xi 7→ di }KσR (I).

272
Semiring Reasoning Frameworks in AI and Their Computational Complexity

This is because

def 0 (d1 , . . . , dn ) = ~ ↓con )


L N
d0 ∈D def (d0 , . . . , dn )⊗ hdef c ,conc i∈{cv0 } def c (d conc
σ

M  Jβ{xi 7→ di }KR (I) d0 = > 
e⊗ d0 = >,
= e⊗ d0 = ⊥ ⊗
e⊕ otherwise.
e⊕ otherwise.

d0 ∈D
M  Jβ{xi 7→ di }Kσ (I) d0 = >
= R
e⊕ otherwise.
d0 ∈D
= Jβ{xi 7→ di }KσR (I).

Lemma B.10. Computing blevel(P ) of an SCSP P over R is Karp s-reducible to the


problem SumProd(R).

Proof. Let P = hC, coni be some SCSP over hR, D, V i. Recall that

blevel(P ) = (Πhdef ,con0 i∈C hdef , con0 i) ⇓∅


L N ~ con
= d∈D
~ con hdef ,con0 i∈C def (d ↓con0 )

We therefore choose the SumProd(R)-instance with variables X1 , . . . , Xn , where n = |con|


and functions {def | hdef , coni ∈ C}. Then the value of this SumProd(R)-instance is equal
to blevel(P ).

Lemma B.11. SumProd(R) is Karp s-reducible to AMC over R

Proof. Assume we are given a SumProd(R)-instance over variables X1 , . . . , Xn , functions


f1 , . . . , fm with inputs Y~1 , . . . , Y~m and domain D. We construct the AMC-instance as follows.
We add the variables

• vi,d for each i = 1, . . . , n and d ∈ D, where vi,j is true if Xi takes values d

• 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

We define T as the propositional theory containing the following formulas

• ¬vi,d ∨ ¬vi,d0 for each i = 1, . . . , n and d 6= d0 ∈ D

• d∈D vi,d for each i = 1, . . . , n


W

~
• vj,d~ ↔ vi,d~X for each j = 1, . . . , m and d~ ∈ DYj
V
Xi ∈Y~j i

273
Eiter & Kiesel

Then every satisfying interpretation I of T corresponds to one assignment of the variables


Xi to domain values di . Furthermore, for each such I the variables vj,d~ tell us which input
the function fj gets.
N
Since we sum up v∈I α(v) for each satisfying interpretation I and for each such I it
holds that m
N Nm ~
j=1 α(vj,d~) = j=1 fj (d), we see that A(T ) over R is exactly the value of the
SumProd(R)-instance.

Lemma B.12. AMC over R is Karp s-reducible to SAT(R).

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 |= l1 ∨ l2 ∨ l3 ⇐⇒ Jl1 + ¬l1 ∗ l2 + ¬l1 ∗ ¬l2 ∗ l3 KR (I) = e⊗


I 6|= l1 ∨ l2 ∨ l3 ⇐⇒ Jl1 + ¬l1 ∗ l2 + ¬l1 ∗ ¬l2 ∗ l3 KR (I) = e⊕ .

So we can proceed as follows: in ψ we replace every clause l1 ∨ l2 ∨ l3 by l1 + ¬l1 ∗ l2 +


¬l1 ∗ ¬l2 ∗ l3 and subsequently every ∧ by ∗. We call the resulting formula β and see that

I |= ψ ⇐⇒ JβKR (I) = e⊗
I 6|= ψ ⇐⇒ JβKR (I) = e⊕

Therefore, the ΣBF γ defined as

Σv1 . . . Σvn Σx1 . . . Σxm β ∗ Πni=1 (vi ∗ α(vi ) + ¬vi ∗ α(¬vi ))

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

F− = {(v, α(¬v)) | v ∈ V}.

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.

where c1 , . . . , cn are distinct variables that do not occur in F . Then


L N N
A(T ) = I|=T v∈I α(v)⊗ ¬v∈I α(¬v)
L N
= I|=T ¬ci ∈I α(¬ci )
L N
= I i, s.t. I6|=Ci wi
= mrg(F ).

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.

Appendix C. Relation to Classical Complexity Classes


C.1 FPSpace(poly)-membership of SAT(R) for Efficiently Encoded Semirings
,→ Proposition 32
Proposition 32 (FPSpace(poly) Upper-Bound). If τ (R) is an efficiently encoded com-
mutative semiring, then SAT(τ (R)) is in FPSpace(poly).
Proof. We have seen that SAT(τ (R)) is Karp s-reducible to SumProd(τ (R)), therefore it
is sufficient to prove FPSpace(poly)-membership for SumProd(τ (R)).

275
Eiter & Kiesel

Assume we are given a SumProd(τ (R))-instance and a domain D as a set of variables


X1 , . . . , Xn and functions f1 , . . . , fm with input vectors Y~1 , . . . , Y~m consisting of variables
from X1 , . . . , Xn . The value of this instance is then given by

a = x1 ,...,xn ∈D m
L N
i=1 fi (~
yi ).

We can bound kakτ by using that τ (R) is efficiently encoded.

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

≤ p(n log2 |D|) max p(m) max kfi (~


yi )kτ
x1 ,...,xn ∈D i=1,...,m

≤ p(n log2 |D|)p(m) max max kfi (~


yi )kτ
x1 ,...,xn ∈D i=1,...,m

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.

C.2 NP, #P, GapP, OptP-completeness of SAT(B), SAT(N), SAT(Z),


SAT(Rmax )
,→ Theorem 33
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. Membership is not hard to see:

• SAT(bin(B)) is SAT;

• SAT(bin(N)) can be solved in #P by simulating Algorithm 1, where instead of re-


turning k we generate k accepting paths;

• SAT(bin(Z)) can be solved in GapP by simulating Algorithm 1, where instead of re-


turning k we generate k accepting and zero rejecting paths if k ≥ 0 and zero accepting
and |k| rejecting paths, otherwise;

• SAT(bin(Rmax )) can be solved in OptP by simulating Algorithm 1, exactly as it is.

.
For C-hardness, we consider the following reductions

• SAT(bin(B)) is SAT;

• We can reduce #SAT to SAT(bin(N)) as follows.


Let φ be the propositional formula, whose satisfying assignments we want to count.
We apply the Tseitin transformation (Tseitin, 1983) to φ and obtain a 3CNF ψ with

276
Semiring Reasoning Frameworks in AI and Their Computational Complexity

additional variables x1 , . . . , xm s.t. each satisfying assignment of φ is uniquely extend-


able to a satisfying assignment of ψ. Furthermore, for each satisfying assignment of
ψ is a satisfying assignment of φ when restricted to the original variables v1 , . . . , vn .
Recall that by Lemma 35, for each clause l1 ∨ l2 ∨ l3 it holds that

I |= l1 ∨ l2 ∨ l3 ⇐⇒ Jl1 + ¬l1 ∗ l2 + ¬l1 ∗ ¬l2 ∗ l3 KR (I) = e⊗


I 6|= l1 ∨ l2 ∨ l3 ⇐⇒ Jl1 + ¬l1 ∗ l2 + ¬l1 ∗ ¬l2 ∗ l3 KR (I) = e⊕ .

So we can proceed as follows: in ψ we replace every clause l1 ∨ l2 ∨ l3 by l1 + ¬l1 ∗


l2 + ¬l1 ∗ ¬l2 ∗ l3 and subsequently every ∧ by ∗. The resulting formula β fulfills

I |= ψ ⇐⇒ JβKR (I) = e⊗
I 6|= ψ ⇐⇒ JβKR (I) = e⊕

Therefore, the semantics of the ΣBF defined as

Σv1 . . . Σvn Σx1 . . . Σxm β

is exactly the number of satisfying assignments of φ.

• Recall that for an n×n matrix A with entries aij ,the permanent is given by
n
X Y
aiσ(i) ,
σ∈Sn i=1

where Sn is the set of permutations of the numbers 1, . . . , n. We reduce computing


the permanent of a given integer matrix A, which is well-known to be #P-complete
(Valiant, 1979), to SAT(bin(Z)) as follows.
We use variables vij , which are true when we include the value aij in the current
product. We construct a weighted QBF α s.t. JαKZ (I) = e⊗ if the variables vij ∈ I
correspond to a permutation and e⊕ otherwise.
We define α as the product of the following weighted formulas

– ¬vij + vij ∗ ¬vij 0 for each i = 1, . . . , n and j 6= j 0 = 1, . . . , n (include at most one


element per row)
– vi1 + . . . + vin for each i = 1, . . . , n (include at least one element per column)
– ¬vij + vij ∗ ¬vi0 j for each i 6= i0 = 1, . . . , n and j = 1, . . . , n (include at most one
element per column)

Then the semantics of the ΣBF

Σa11 . . . Σann α ∗ Πni,j=1 (vij ∗ aij + ¬vij )

is exactly the permanent of A.

277
Eiter & Kiesel

• We can reduce LexMaxSAT to SAT(bin(Rmax )) as follows. Let φ be the proposi-


tional formula whose maximum satisfying assignments we want to know. We again as
in the proof of #P-hardness for SAT(bin(N)) obtain the formula β s.t.

I |= ψ ⇐⇒ JβKR (I) = e⊗
I 6|= ψ ⇐⇒ JβKR (I) = e⊕

Then the semantics of the ΣBF

Σv1 . . . Σvn Σx1 . . . Σxm β ∗ Πni=1 (vi ∗ 2n−i + ¬vi )

is the bitstring representing the maximum satisfying assignment of φ respectively −∞


if there is none.

C.3 Results for Classes of Semirings


C.3.1 Reducibility via Epimorphisms
,→ Theorem 40
Theorem 40. Let τi (Ri ), i = 1, 2 be two encoded commutative semirings, such that

1. there exists a polynomial time computable epimorphism f : τ1 (R1 ) → τ2 (R2 ), and

2. for each τ2 (r2 ) ∈ τ (R2 ) one can compute in polynomial time τ1 (r1 ) s.t. f (τ1 (r1 )) =
τ2 (r2 ) from τ2 (r2 ).

Then SAT(τ2 (R2 )) is counting-reducible to SAT(τ1 (R1 )).

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.

Lemma 41 (Hardest Semirings). There exists an encoding τ ∗ for

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

1. periodic with periodicity 1;

2. periodic with periodicity p ≥ 2 and offset 0;

3. periodic with periodicity p ≥ 2 and offset o > 0;

4. not periodic

it holds that SAT(τ (R)) is counting reducible to

1. SAT(τ ∗ (N≤o [(xi )∞ ]));

2. SAT(τ ∗ (Zp [(xi )∞ ]));

3. SAT(τ ∗ (N≤o × Zp [(xi )∞ ]));

4. SAT(τ ∗ (N[(xi )∞ ])), respectively.

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

C.3.2 Impossibility Results for Polynomial Semirings


,→ Theorems 42, 43, 45 and 46
Theorem 42. Let R = N[(xi )∞ ] (resp. R = B[(xi )∞ ]). If there is an encoding function τ
for R s.t.
1) kJαKR (∅)kτ is polynomial in the size of α,

2) we can extract the binary representation of the coefficient n ∈ N (resp. b ∈ B) of


xji11 ...xjinn from τ (r) in time polynomial in krkτ , and

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);

2. for all π ∈ Πn , there exists a vπ ∈ V such that:

(a) vπ can be computed from π in polynomial time;


(b) hfn , vπ i is a “yes” instance of P iff π is a “yes” instance of Π.

With the above hypothesis, if [P, F, V ] is compilable, then NP ⊆ P/poly.


The proof can be found in (Cadoli et al., 1996) and can be extended to a proof for an
analogous statement resulting in #P ⊆ FP/poly.

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 .

αn =Σc1 . . . Σck Σa1 . . . Σan Πki=1 (Ci0 ∗ ci ∗ τ (xi ) + ¬ci )

where Ci = l1 ∨ l2 ∨ l3 is replaced by Ci0 = l1 + ¬l1 ∗ l2 + ¬l1 ∗ ¬l2 ∗ l3 . Since k is polynomial


in n and kxi kτ is polynomial in i, we know that αn and therefore fn is of polynomial size
in 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 α,

2) we can extract the binary representation of the coefficient n ∈ N (resp. b ∈ B) of xi


from τ (r) in time polynomial in krkτ , and

3) kxi kτ is polynomial in log2 (i),


then #P ⊆ FP/poly (resp. NP ⊆ P/poly).
Proof. We proceed as in the proof of Theorem 42, this time however we use fn = αn where
i
αn =Σc1 . . . Σck Σa1 . . . Σan Πki=1 Ci0 ∗ ci ∗ τ (x2 ) + ¬ci ,
i1 +···+2im
vn =x2 .

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

(β, A(|(β, maxmon(β))|), A(|(β, maxmon(β))| − 1), . . . , A(0)),

where

1. β is a SAT(τ (N[(xi )∞ ]))-instance such that JβKτ (N[(xi )∞ ]) (∅) = τ (p),

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.

The size of the representation is polynomial in kβkτ , since

• maxmon(β) is polynomial in kβkτ

• |A(n)| is polynomial in n and, therefore,

• |A(n)| is polynomial in kβkτ for n ≤ |(β, maxmon(β))| and, therefore, also

• 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

(α, A(|(α, maxmon(α))|), A(|(α, maxmon(α))| − 1), . . . , A(0)).

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

(τ (xi ), A(|(τ (xi ), τ (xi ))|), . . . , A(0))

is polynomial in i, since kxi kτ is polynomial in i. Thus, we have a representation of the


polynomials that satisfies all three conditions. However, we need an encoding and therefore
cannot allow multiple representations of the same value but we must choose exactly one.
This is easily fixed though, by choosing that representation of p that has the shortest ΣBF
formula α, breaking ties using the lexicographical ordering. We can verify that this only
makes representations smaller and use this encoding as τ∞ .

Theorem 45. Let R 6= T be a commutative semiring. If there is an encoding function τ


for R[(xi )∞ ] s.t.

1) kJαKR[(xi )∞ ] (∅)kτ is polynomial in the size of α,

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

3) kxi kτ is polynomial in log2 (i),


then either NP ⊆ P/poly or Modp P ⊆ P/poly for some p ∈ N.
Proof of Theorem 45 and 46. As in the proof of Theorem 34, we use that for any non-trivial
commutative semiring τ (R) it holds that either
1. k · τ (e⊗ ) = τ (e⊕ ) implies k = 0 or

2. τ (he⊗ i) ≡ Zp for some p ∈ N.


In the first case we can derive NP ⊆ P/poly, in the second Modp P ⊆ P/poly from the
preconditions of the theorems.
To prove this, we can reuse the ΣBFs from the proofs of Theorem 42 and Theorem 43
for Theorem 45 and 46, respectively. The size restrictions are given as before. Apart from
that, we only need to use that Modp 3CNF is Modp P-complete.
Then, we can see as before that we can read off the solution of any (Modp )3CNF-
instance of size at most n as a coefficient of Jαn Kτ (R[(xi )∞ ) (∅). Here, we note again, that
as in the proof of Theorem 34 we only need to recognize a fixed set of values - which is
possible in constant time - to derive the result of the (Modp )3CNF-instance from the
coefficient.

Lemma 47. If Modp P ⊆ P/poly for p ∈ N, p > 1, then NP ⊆ P/poly.


Proof. Valiant and Vazirani (1986) showed that NP ⊆ RPUnique-SAT . Here, Unique-SAT
is the problem of determining whether a propositional formula φ has a satisfying assignment,
given the additional knowledge that φ has at most one satisfying assignment. Furthermore,
recall that RP is the class of languages L for which there exists a polynomial time non-
deterministic Turing machine M such that if x ∈ L then at least half of the computation
paths of M (x) accept and if x 6∈ L then none of the computation paths accept. Intuitively,
the definition of RP is more restrictive than that of BPP because if a computation path
of the RP-machine M that recognizes L accepts on x, we know that x ∈ L, whereas for a
BPP-machine, this means that x ∈ L is likely but not necessarily the case. Indeed, RP ⊆
BPP, since if L is in RP due to NTM M , then we can prove it is also in BPP by executing
M twice independently on a given input x.
Using these insights, it follows that NP ⊆ RPUnique-SAT ⊆ BPP Unique-SAT . Further-
more, clearly Unique-SAT is in Modp P for any p ∈ N, p > 1. Thus, we can replace the
Unique-SAT-oracle with a Modp P-oracle and obtain NP ⊆ BPP Modp P .

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 :

(AM (n), AO (p(n)), AO (p(n) − 1), . . . , AO (0)).

This is still polynomial in n and we have both the necessary advice for the part of M and
of O.

C.3.3 Possibility Results for R[(xi )k ]


,→ Theorem 48
Theorem 48. Let τ (R) be a commutative semiring that is efficiently encoded. Then
NP(τ (R))
SAT(τ (R[(xi )k ])) is FPk -complete for metric reductions, if we extend τ to R[(xi )k ]
by representing polynomials as lists of monomials with exponents in unary and coefficients
encoded by τ .

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 β:

Σv1 . . . Σvm α1 ∗ τ (x1 ) + . . . + αn ∗ τ (xn1 ).

284
Semiring Reasoning Frameworks in AI and Their Computational Complexity

The coefficient of xi1 is then the solution of αi . As β is constructible in time polynomial in


the size of α1 , . . . , αn , we have the desired metic reduction, which opmpletes the proof.

C.3.4 Possibility Results for Commutative Finitely Generated Semirings


,→ Theorem 51
Theorem 51. Let τ (R) be an efficiently encoded commutative Nsemiring that is generated by
Ln k ei,j
{r1 , . . . , rk }. Suppose every r ∈ R is of the form r = i=1 ai · j=1 rj for some ai , ei,j ∈ N
such that

• max{ei,j , log2 (ai ), n} is polynomial in krkτ , and

• we can obtain ai , ei,j from τ (r) in polynomial time.

If τ (R) is

1. periodic with periodicity 1;

2. periodic with periodicity p ≥ 2 and offset 0;

3. periodic with periodicity p ≥ 2 and offset o > 0;

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.

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

if τ (R) is, respectively,

1. periodic with periodicity 1 and offset o

285
Eiter & Kiesel

2. periodic with periodicity p ≥ 2 and offset 0

3. periodic with periodicity p ≥ 2 and offset o > 0

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

when Ln Nmi ei,j


τ (r) = i=1 ai j=i τ (rj ) .
Recall that when k = 0, i.e., τ (R) is already generated by the empty set, these equations
collapse to
n
!
X
bin ai · 1
i=1
and Ln
τ (r) = i=1 ai · e⊗
since we take the neutral element of multiplication as the value of an empty product.
During the above transformation, we only need to check whether ai is in S and replace
ai by an equivalent value if not. Namely, if S = N≤o , we use the minimum of ai and
o, if S = Zp , we use the unique integer n in {0, . . . , p − 1} such that ai ≡ n mod p, if
S = Zp × N≤o , we use (n, m), where n is the unique integer in {0, . . . , p − 1} such that
ai ≡ n mod p and m is the minimum of ai and o, otherwise, S = N in which case we know
that ai ∈ N. We can obtain the above expression in polynomial time. Hence, the size of β
is also polynomial in the input.
Theorem 48 tells us, that SAT(bin(S[(xi )k ])) satisfies the desired complexity assertion.
Furthermore, given JβKbin(S[(xi )k ]) (∅) we can compute JαKτ (R) (∅) in polynomial time. This
can be seen as follows. Let
n k
X Y e
JβKS[(xi )k ] (∅) = ai xj i,j .
i1 ,...,ik =1 j=1

Then we know that Ln Lai Nk ei,j


JαKR (∅) = i1 ,...,ik =1 v=1 j=1 rj .

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

Thus, we can proceed by first iteratively computing


L2t Nk ei,j L t−1 N e L2t−1 Nk ei,j
τ( v=1 j=1 rj ) = τ ( 2v=1 kj=1 rj i,j )⊕τ ( v=1 j=1 rj )

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.

C.4 Derived Results


,→ Theorem 52
Theorem 52. Let S = N, Z, Q. For Sn , n ∈ N, the semiring S over multiple dimensions, we
have that SAT(bin(S)n ) is FP#P
k -complete with respect to metric reductions, where bin(Q)
represents r ∈ Q as pair (bin(p), bin(q)) such that p/q = r, p ∈ Z, q ∈ N and the greatest
common divisor of |p| and q is 1.

Proof. For S = N and S = Z we see that Sn is finitely generated by {e1 , . . . , en } and


{e1 , . . . , en , (−1, . . . , −1)}, respectively, where ei is the vector whose j th entry is 0 if j 6= i
and 1 if i = j. Furthermore, every number m = (m1 , . . . , mn ) ∈ S can be represented as a
sum
|mi | 
n X
X ei if mi ≥ 0,
m=
(−1, . . . , −1)ei if mi < 0.
i=1 j=1

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

Thus, we can metrically reduce SAT(bin(Q)n ) to SAT(bin(N[(xi )2 ])n ). However, the


semiring bin(N[(xi )2 ])n is finitely generated, by {ei , ei x1 , ei x2 | i = 1, . . . , n} and satis-
fies the preconditions of Theorem 51. Thus, SAT(bin(N[(xi )2 )n ) and consequently also
SAT(bin(Q)n ) is in FP#P k .
Regarding hardness, note that already SAT(bin(N)) is FP#P k -hard with respect to met-
ric reductions: Given n SAT(bin(N))-instances I1 , . . . , In we can compute the value of
the SAT(bin(N))-instance αn = I1 ∗ bin(2k ) + . . . + In ∗ bin(2k∗n ), where k is such that
2k > JIi Kbin(N) (∅) for all i. Such a k can be found and is polynomial in the size of the
instances. Due to the choice of k we can understand the result of αn as a list of the re-
sults of Ii in binary representation. From the FP#Pk -hardness it immediately follows, that
SAT(bin(S)n ) is even FP#P
k -complete with respect to metric reductions for S = N, Z, Q.

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

SIGACT-SIGAI Symposium on Principles of Database Systems, PODS 2017, Chicago,


IL, USA, May 14-19, 2017, pp. 93–99. ACM.
Heckerman, D. (2008). A tutorial on learning with bayesian networks. In Holmes, D. E., &
Jain, L. C. (Eds.), Innovations in Bayesian Networks: Theory and Applications, Vol.
156 of Studies in Computational Intelligence, pp. 33–82. Springer.
Hertrampf, U. (1990). Relations among mod-classes. Theor. Comput. Sci., 74 (3), 325–328.
Impagliazzo, R., & Paturi, R. (2001). On the complexity of k-sat. J. Comput. Syst. Sci.,
62 (2), 367–375.
Jenner, B., & Torán, J. (1995). Computing functions with parallel queries to NP. Theor.
Comput. Sci., 141 (1&2), 175–193.
Karp, R., & Lipton, R. J. (1982). Turing machines that take advice. In L’Enseign. Math.,
Vol. 28.
Karp, R. M., & Lipton, R. J. (1980). Some connections between nonuniform and uniform
complexity classes. In Miller, R. E., Ginsburg, S., Burkhard, W. A., & Lipton, R. J.
(Eds.), Proc. 12th Annual ACM Symposium on Theory of Computing, April 28-30,
1980, Los Angeles, California, USA, pp. 302–309. ACM.
Kautz, H. A., & Selman, B. (1996). Pushing the envelope: Planning, propositional logic and
stochastic search. In Clancey, W. J., & Weld, D. S. (Eds.), Proc. Thirteenth National
Conference on Artificial Intelligence, AAAI 96, Portland, Oregon, USA, August 4-8,
1996, Volume 2, pp. 1194–1201. AAAI Press / The MIT Press.
Khamis, M. A., Ngo, H. Q., & Rudra, A. (2016). FAQ: questions asked frequently. In
Milo, T., & Tan, W. (Eds.), Proc. 35th ACM SIGMOD-SIGACT-SIGAI Symposium
on Principles of Database Systems, PODS 2016, San Francisco, CA, USA, June 26 -
July 01, 2016, pp. 13–28. ACM.
Khardon, R., & Roth, D. (1997). Learning to reason. J. ACM, 44 (5), 697–725.
Kiesel, R., Totis, P., & Kimmig, A. (2022). Efficient knowledge compilation beyond weighted
model counting. CoRR, abs/2205.07496.
Kimmig, A., Van den Broeck, G., & De Raedt, L. (2011). An algebraic prolog for rea-
soning about possible worlds. In Burgard, W., & Roth, D. (Eds.), Proceedings of the
Twenty-Fifth AAAI Conference on Artificial Intelligence, AAAI 2011, San Francisco,
California, USA, August 7-11, 2011. AAAI Press.
Kimmig, A., Van den Broeck, G., & De Raedt, L. (2017). Algebraic model counting. J.
Appl. Log., 22, 46–62.
Kohlas, J., & Wilson, N. (2008). Semiring induced valuation algebras: Exact and approxi-
mate local computation algorithms. Artif. Intell., 172 (11), 1360–1399.
Krentel, M. W. (1988). The complexity of optimization problems. J. Comput. Syst. Sci.,
36 (3), 490–509.
Ladner, R. E. (1989). Polynomial space counting problems. SIAM J. Comput., 18 (6),
1087–1097.

291
Eiter & Kiesel

Larrosa, J., Oliveras, A., & Rodrı́guez-Carbonell, E. (2010). Semiring-induced propositional


logic: Definition and basic algorithms. In Clarke, E. M., & Voronkov, A. (Eds.),
Logic for Programming, Artificial Intelligence, and Reasoning - 16th International
Conference, LPAR-16, Dakar, Senegal, April 25-May 1, 2010, Revised Selected Papers,
Vol. 6355 of Lecture Notes in Computer Science, pp. 332–347. Springer.
Lee, J., & Yang, Z. (2017). Lpmln, weak constraints, and p-log. In Singh, S., & Markovitch,
S. (Eds.), Proceedings of the Thirty-First AAAI Conference on Artificial Intelligence,
February 4-9, 2017, San Francisco, California, USA, pp. 1170–1177. AAAI Press.
Li, C. M., & Manyà, F. (2021). Maxsat, hard and soft constraints. In Biere, A., Heule, M.,
van Maaren, H., & Walsh, T. (Eds.), Handbook of Satisfiability - Second Edition, Vol.
336 of Frontiers in Artificial Intelligence and Applications, pp. 903–927. IOS Press.
Mandrali, E., & Rahonis, G. (2015). Weighted first-order logics over semirings. Acta Cybern.,
22 (2), 435–483.
Manhaeve, R., Dumancic, S., Kimmig, A., Demeester, T., & De Raedt, L. (2019). Deep-
problog: Neural probabilistic logic programming. In Beuls, K., et al. (Eds.), Proc.
31st Benelux Conference on Artificial Intelligence (BNAIC 2019), Brussels, Belgium,
November 6-8, 2019, Vol. 2491 of CEUR Workshop Proceedings. CEUR-WS.org.
Meer, K. (2000). Counting problems over the reals. Theor. Comput. Sci., 242 (1-2), 41–58.
Mengel, S. (2021). Counting, Knowledge Compilation and Applications.
Niedermayer, I. S. P. D. (2008). An introduction to bayesian networks and their contem-
porary applications. In Holmes, D. E., & Jain, L. C. (Eds.), Innovations in Bayesian
Networks: Theory and Applications, Vol. 156 of Studies in Computational Intelligence,
pp. 117–130. Springer.
Oztok, U., Choi, A., & Darwiche, A. (2016). Solving pppp -complete problems using knowl-
edge compilation. In Baral, C., Delgrande, J. P., & Wolter, F. (Eds.), Principles of
Knowledge Representation and Reasoning: Proc. Fifteenth International Conference,
KR 2016, Cape Town, South Africa, April 25-29, 2016, pp. 94–103. AAAI Press.
Pearl, J. (1985). Bayesian networks : a model of self-activated memory for evidential rea-
soning. In Proc. 7th Conference of the Cognitive Science Society, 1985, pp. 329–334.
Pearl, J. (2014). Graphical models for probabilistic and causal reasoning. In Gonzalez,
T. F., Diaz-Herrera, J., & Tucker, A. (Eds.), Computing Handbook, Third Edition:
Computer Science and Software Engineering, pp. 44: 1–24. CRC Press.
Ruttkay, Z. (1994). Fuzzy constraint satisfaction. In Proceedings of 1994 IEEE 3rd Inter-
national Fuzzy Systems Conference, Vol. 2, pp. 1263–1268.
Sato, T., & Kameya, Y. (1997). PRISM: A language for symbolic-statistical modeling. In
Proc. Fifteenth International Joint Conference on Artificial Intelligence, IJCAI 97,
Nagoya, Japan, August 23-29, 1997, 2 Volumes, pp. 1330–1339. Morgan Kaufmann.
Senellart, P., Jachiet, L., Maniu, S., & Ramusat, Y. (2018). Provsql: Provenance and
probability management in postgresql. Proc. VLDB Endow., 11 (12), 2034–2037.
Sharma, A., & Singh, S. K. (2016). One way functions–conjecture, status, applications and
future research scope. International Journal of Computer Applications, 153 (8).

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

You might also like