This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

\diagramstyle

[labelstyle=]

Convergence of Datalog over (Pre-) Semirings

Mahmoud Abo Khamis RelationalAI Berkeley CA USA Hung Q. Ngo RelationalAI Berkeley CA USA Reinhard Pichler TU Wien Vienna Austria Dan Suciu University of Washington Seattle WA USA  and  Yisu Remy Wang University of Washington Seattle WA USA
Abstract.

Recursive queries have been traditionally studied in the framework of datalog, a language that restricts recursion to monotone queries over sets, which is guaranteed to converge in polynomial time in the size of the input. But modern big data systems require recursive computations beyond the Boolean space. In this paper we study the convergence of datalog when it is interpreted over an arbitrary semiring. We consider an ordered semiring, define the semantics of a datalog program as a least fixpoint in this semiring, and study the number of steps required to reach that fixpoint, if ever. We identify algebraic properties of the semiring that correspond to certain convergence properties of datalog programs. Finally, we describe a class of ordered semirings on which one can use the semi-naïve evaluation algorithm on any datalog program.

1. Introduction

For fifty years, the relational data model has been the main choice for representing, modeling, and processing data. Its main query language, SQL, is found today in a wide range of applications and devices, from smart phones, to database servers, to distributed cloud-based clusters. The reason for its success is the data independence principle, which separates the declarative model from the physical implementation (DBLP:journals/cacm/Codd70, ), and enables advanced implementation techniques, such as cost-based optimizations, indices, materialized views, incremental view maintenance, parallel evaluation, and many others, while keeping the same simple, declarative interface to the data unchanged.

But scientists today often need to perform tasks that require iteration over the data. Gradient descent, clustering, page-rank, network centrality, inference in knowledge graphs are some examples of common tasks in data science that require iteration. While SQL has introduced recursion since 1999 (through Common Table Expressions, CTE), it has many cumbersome limitations and is little used in practice (frankmcsherry-2022, ).

The need to support recursion in a declarative language led to the development of datalog in the mid 80s (DBLP:conf/pods/Vianu21, ). Datalog adds recursion to the relational query language, yet enjoys several elegant properties: it has a simple, declarative semantics; its naïve bottom-up evaluation algorithm always terminates; and it admits a few powerful optimizations, such as semi-naïve evaluation and magic set rewriting. Datalog has been extensively studied in the literature; see (DBLP:journals/ftdb/GreenHLZ13, ) for a survey and (DBLP:books/mc/18/MaierTKW18, ; DBLP:conf/pods/Vianu21, ) for historical notes.

However, datalog is not the answer to modern needs, because it only supports monotone queries over sets. Most tasks in data science today require the interleaving of recursion and aggregate computation. Aggregates are not monotone under set inclusion, and therefore they are not supported by the framework of pure datalog. Neither SQL’99 nor popular open-source datalog systems like Soufflé (DBLP:conf/cav/JordanSS16, ) allow recursive queries to have aggregates. While several proposals have been made to extend datalog with aggregation (DBLP:conf/pods/GangulyGZ91, ; DBLP:conf/pods/RossS92, ; DBLP:journals/jcss/GangulyGZ95, ; DBLP:journals/vldb/MazuranSZ13, ; DBLP:conf/icde/ShkapskyYZ15, ; DBLP:conf/sigmod/ShkapskyYICCZ16, ; DBLP:conf/amw/ZanioloYDI16, ; DBLP:journals/tplp/ZanioloYDSCI17, ; DBLP:conf/amw/ZanioloYIDSC18, ; DBLP:journals/tplp/CondieDISYZ18, ; DBLP:conf/sigmod/0001WMSYDZ19, ; DBLP:journals/corr/abs-1910-08888, ; DBLP:journals/corr/abs-1909-08249, ; DBLP:journals/debu/ZanioloD0LL021, ), these extensions are at odds with the elegant properties of datalog and have not been adopted by either datalog systems or SQL engines.

In this paper we propose a foundation for a query language that supports both recursion and aggregation. Our proposal is based on the concept of KK-relations, introduced in a seminal paper (DBLP:conf/pods/GreenKT07, ). In a KK-relation, tuples are mapped to a fixed semiring. Standard relations (sets) are 𝔹\mathbb{B}-relations where tuples are mapped to the Boolean semiring 𝔹\mathbb{B}, relations with duplicates (bags) are \mathbb{N}-relations, sparse tensors are \mathbb{R}-relations, and so on. Queries over KK-relations are the familiar relational queries, where the operations ,\wedge,\vee are replaced by the operations ,\otimes,\oplus in the semiring; importantly, an existential quantifier \exists becomes an \oplus-aggregate operator. KK-relations are a very powerful abstraction, because they open up the possibility of adapting query processing and optimization techniques to other domains (DBLP:conf/pods/KhamisNR16, ).

Our first contribution is to introduce an extension of datalog to KK-relations. We call the language datalog\text{\sf datalog}^{\circ}, where the superscript oo represents a (semi)-ring. Datalog\text{\sf Datalog}^{\circ} has a declarative semantics based on the least fixpoint, and supports both recursion and aggregates. We illustrate throughout this paper its utility through several examples that are typical for recursive data processing. In order to define the least fixpoint semantics of datalog\text{\sf datalog}^{\circ}, the semiring needs to be partially ordered. For this purpose, we introduce an algebraic structure called a Partially Ordered Pre-Semiring (POPS), which generalizes the more familiar naturally ordered semirings. This generalization is necessary for some applications. For example, the bill-of-material program (Example 4.2) is naturally expressed over the lifted reals, \mathbb{R}_{\bot}, which is a POPS that is not naturally ordered.

Like datalog, datalog\text{\sf datalog}^{\circ} can be evaluated using the naïve algorithm, by repeatedly applying all rules of the program, until there is no more change. However, unlike datalog, a datalog\text{\sf datalog}^{\circ} program may diverge. Our second contribution consists of a full characterization of the POPS that guarantee that every datalog\text{\sf datalog}^{\circ} program terminates. More precisely, we show that termination is guaranteed iff the POPS enjoys a certain algebraic property called stability (semiring_book, ). The result is based on an analysis of the fixpoint of a vector-valued polynomial function over a semiring, which is of independent interest. With some abuse, we will say in this paper that a datalog\text{\sf datalog}^{\circ} program converges, if the naïve algorithm terminates in a finite number of steps; we do not consider “convergence in the limit”, for example in ω\omega-continuous semirings (DBLP:conf/pods/GreenKT07, ; DBLP:journals/jacm/EsparzaKL10, ).

Finally, we describe how the semi-naïve algorithm can be extended to datalog\text{\sf datalog}^{\circ}, under certain restrictions on the POPS. This should be viewed as an illustration of the potential for applying advanced optimizations to datalog\text{\sf datalog}^{\circ}: in a companion paper (DBLP:conf/sigmod/WangK0PS22, ), we introduced a simple, yet powerful optimization technique for datalog\text{\sf datalog}^{\circ}, and showed, among other things, that magic set rewriting can be obtained using several applications of that rule.

At its essence, a datalog\text{\sf datalog}^{\circ} program consists of solving a fixpoint equation in a semiring, which is a problem that was studied in a variety of areas, like automata theory, program analysis, and many others (MR1470001, ; DBLP:conf/popl/CousotC77, ; MR1728440, ; MR1059930, ; DBLP:conf/lics/HopkinsK99, ; DBLP:journals/tcs/Lehmann77, ; semiring_book, ; MR609751, ). The existence of the fixpoint is usually ensured by requiring the semiring to be ω\omega-continuous. For example, Green et al. (DBLP:conf/pods/GreenKT07, ) studied the provenance of datalog on KK-relations, while Esparza et al. (DBLP:journals/jacm/EsparzaKL10, ) studied dataflow equations, in both cases requiring the semiring to be ω\omega-continuous. This guarantees that the least fixpoint exists, even if the naïve algorithm diverges.

In addition to the (semi-)naïve method, which is a first-order method for solving fixpoint equations, there is a second-order method called the Newton’s method, discovered relatively recently (DBLP:journals/jacm/EsparzaKL10, ; DBLP:conf/lics/HopkinsK99, ) in the program analysis literature. It was shown that Newton’s method requires a smaller number of iterations than the naïve algorithm.111The naïve algorithm is called Kleene iteration method in (DBLP:journals/jacm/EsparzaKL10, ). In the particular case of a commutative and idempotent semiring, Newton’s method always converges, while the naïve algorithm may diverge (DBLP:journals/jacm/EsparzaKL10, ). However, every iteration of Newton’s method requires solving a least fixpoint solution to an inner-recursion, which is expensive. Here, we are seeing the exact same phenomenon when comparing gradient descent vs. Newton’s method in continuous optimization: while Newton’s method may converge in fewer steps, every step is more expensive, and requires the materialization of a large intermediate result (the Hessian matrix). In continuous optimization, Newton’s method is rarely used for large-scale problems for this reason (DBLP:books/sp/NocedalW99, ). For datalog\text{\sf datalog}^{\circ}, it remains unclear whether Newton’s method is more efficient in practice than the naïve algorithm. One experimental evaluation (DBLP:conf/popl/RepsTP16, ) has found that it is not. In contrast, the naïve algorithm, and its extension to the semi-naïve algorithm, is simple, and implemented by all datalog systems today. In this paper we focus only on the convergence of the naïve algorithm, and do not consider Newton’s method.

A preliminary version of this paper appeared in (DBLP:conf/pods/Khamis0PSW22, ). The convergence theorem in stable semirings, Theorem 5.10, is new. The convergence semiring in pp-stable semirings, Theorem 5.12, is improved and extended. We have also included many proofs omitted from (DBLP:conf/pods/Khamis0PSW22, ) and added several examples.

1.1. Overview of the Results

We present here a high-level overview of the main results in this paper. We start by recalling the syntax of a (traditional) datalog program Π\Pi, which consists of a set of rules of the form:

(1) R0(𝑿0)\displaystyle R_{0}(\bm{X}_{0}) :- R1(𝑿1)Rm(𝑿m)\displaystyle\text{ :- }R_{1}(\bm{X}_{1})\wedge\cdots\wedge R_{m}(\bm{X}_{m})

where R0,,RmR_{0},\ldots,R_{m} are relation names (not necessarily distinct) and each 𝑿i\bm{X}_{i} is a tuple of variables and/or constants. The atom R0(𝑿0)R_{0}(\bm{X}_{0}) is called the head, and the conjunction R1(𝑿1)Rm(𝑿m)R_{1}(\bm{X}_{1})\wedge\cdots\wedge R_{m}(\bm{X}_{m}) is called the body. A relation name that occurs in the head of some rule in Π\Pi is called an intensional database predicate or IDB, otherwise it is called an extensional database predicate or EDB. The EDBs form the input database, which is denoted II, and the IDBs represent the output instance computed by Π\Pi, which we denote by JJ. The finite set of all constants occurring in II is called the active domain of II, and denoted ADom(I)\textsf{ADom}(I). The textbook example of a datalog program is one that computes the transitive closure of a graph defined by the edge relation E(X,Y)E(X,Y):

T(X,Y)\displaystyle T(X,Y) :- E(X,Y)\displaystyle\text{ :- }E(X,Y)
T(X,Y)\displaystyle T(X,Y) :- T(X,Z)E(Z,Y)\displaystyle\text{ :- }T(X,Z)\wedge E(Z,Y)

Here EE is an EDB predicate, and TT is an IDB predicate. Multiple rules with the same head are interpreted as a disjunction, and in this paper we prefer to combine them in a single rule, with an explicit disjunction. In particular, the program above becomes:

(2) T(X,Y)\displaystyle T(X,Y) :- E(X,Y)Z(T(X,Z)E(Z,Y))\displaystyle\text{ :- }E(X,Y)\vee\exists_{Z}(T(X,Z)\wedge E(Z,Y))

The semantics of a datalog program is the least fixpoint of the function defined by its rules, and can be computed by the naïve evaluation algorithm, as follows: initialize all IDBs to the empty set, then repeatedly apply all rules, updating the state of the IDBs, until there is no more change to the IDBs. The algorithm always terminates in time polynomial in ADom(I)\textsf{ADom}(I).

We introduce datalog\text{\sf datalog}^{\circ}, a language that generalizes datalog to relations over a partially ordered, commutative pre-semiring, or POPS. A POPS, 𝑷\bm{P}, is an algebraic structure with operations ,\oplus,\otimes on a domain PP, which is also a partially ordered set with an order relation \sqsubseteq and a smallest element \bot. (Formal definition is in Sec. 2). For example, the Boolean semiring 𝔹\mathbb{B} forms a POPS where (,)=(,)(\oplus,\otimes)=(\vee,\wedge), over domain {0,1}\{0,1\}, and the order relation is 010\leq 1. For another example, the tropical semiring, Trop, consists of the real numbers \mathbb{R}, the operations are min,+\min,+, and the order relation xyx\sqsubseteq y is the reverse of the usual order xyx\geq y. If we restrict the tropical semiring to the non-negative reals and infinity, +\mathbb{R}_{+}\cup\infty, then we denote the POPS by Trop+\text{\sf Trop}^{+}. For a fixed POPS 𝑷\bm{P}, a 𝑷\bm{P}-relation of arity kk is a function that maps all kk-tuples over some domain to values in 𝑷\bm{P}; for example, a standard relation is a 𝔹\mathbb{B}-relation, where 𝔹\mathbb{B} is the Boolean semiring, while a relation with duplicates (a bag) is an \mathbb{N}-relation. A datalog\text{\sf datalog}^{\circ} program consists of a set of rules, e.g. like (2), where all relations are 𝑷\bm{P}-relations, and the operators ,,Z\wedge,\vee,\exists_{Z} are replaced by ,,Z\otimes,\oplus,\bigoplus_{Z}, and its semantics is defined as its least fixpoint, when it exists, or undefined otherwise. We will illustrate the utility of datalog\text{\sf datalog}^{\circ} through multiple examples in this paper, and give here only a preview.

Example 1.1.

The all-pairs shortest paths (APSP) problem is to compute the shortest path length T(X,Y)T(X,Y) between all pairs X,YX,Y of vertices in the graph, given that E(X,Y)=E(X,Y)= the length of the edge (X,Y)(X,Y) in the graph. We assume that both EE and TT are Trop+\text{\sf Trop}^{+}-relations. The APSP problem can be expressed very compactly in datalog\text{\sf datalog}^{\circ} as

(3) T(X,Y)\displaystyle T(X,Y) :- E(X,Y)ZT(X,Z)E(Z,Y),\displaystyle\text{ :- }E(X,Y)\oplus\bigoplus_{Z}T(X,Z)\otimes E(Z,Y),

where (,)=(min,+)(\oplus,\otimes)=(\min,+) are the “addition” and “multiplication” in Trop+\text{\sf Trop}^{+}. If we instantiate these operations in (3), the program becomes:

(4) T(X,Y)\displaystyle T(X,Y) :- min(E(X,Y),minZ(T(X,Z)+E(Z,Y))),\displaystyle\text{ :- }\min\left(E(X,Y),\min_{Z}(T(X,Z)+E(Z,Y))\right),

If we use a different POPS in (3), then the same datalog\text{\sf datalog}^{\circ} program will express similar problems, in exactly the same way. For example, if the relations E,TE,T are 𝔹\mathbb{B}-relations, then the program (3) becomes the transitive closure program (2); alternatively, if both E,TE,T are Tropp+\text{\sf Trop}^{+}_{p}-relations, where Tropp+\text{\sf Trop}^{+}_{p} is a semiring defined in Sec. 2, then the program computes the top p+1p+1-shortest-paths.

The least fixpoint of datalog\text{\sf datalog}^{\circ}, if exists, can be computed by the naïve algorithm, quite similar to datalog: initialize all IDBs to \bot, then repeatedly apply all rules of the datalog\text{\sf datalog}^{\circ} program, obtaining an increasing chain of IDB instances, J(0)J(1)J(2)J^{(0)}\sqsubseteq J^{(1)}\sqsubseteq J^{(2)}\sqsubseteq\cdots When J(t)=J(t+1)J^{(t)}=J^{(t+1)}, then the algorithm stops and returns J(t)J^{(t)}; in that case we say that the datalog\text{\sf datalog}^{\circ} program converges in tt steps, or we just say that it converges; otherwise we say that it diverges. Traditional datalog always converges, but this is no longer the case for datalog\text{\sf datalog}^{\circ} programs. There are five possibilities, depending on the choice of the POPS 𝑷\bm{P}:

  1. (i)

    For some datalog\text{\sf datalog}^{\circ} programs, tJ(t)\bigvee_{t}J^{(t)} is not the least fixpoint.

  2. (ii)

    Every datalog\text{\sf datalog}^{\circ} program has the least fixpoint tJ(t)\bigvee_{t}J^{(t)}, but may not necessarily converge.

  3. (iii)

    Every datalog\text{\sf datalog}^{\circ} program converges.

  4. (iv)

    Every datalog\text{\sf datalog}^{\circ} program converges in a number of steps that depends only on |ADom(I)||\textsf{ADom}(I)|.

  5. (v)

    Every datalog\text{\sf datalog}^{\circ} program converges in a number of steps that is polynomial in |ADom(I)||\textsf{ADom}(I)|.

In this paper, we will only consider data-complexity (DBLP:conf/stoc/Vardi82, ), where the datalog\text{\sf datalog}^{\circ} program is assumed to be fixed, and the input consists only of the EDB instance II.

We study algebraic properties of the POPS 𝑷\bm{P} that ensure that we are in one of the cases (iii)-(v); we do not address cases (i)-(ii) in this paper. We give next a necessary and sufficient condition for each of the cases (iii) and (iv), and give a sufficient condition for case (v). For any POPS 𝑷\bm{P}, the set 𝑷=def{uuP}\bm{P}\oplus\bot\stackrel{{\scriptstyle\text{def}}}{{=}}\{{u\oplus\bot}\mid{u\in P}\} is a semiring (Proposition 2.4); our characterization is based entirely on a certain property, called stability, of the semiring 𝑷\bm{P}\oplus\bot, which we describe here.

Given a semiring 𝑺\bm{S} and uSu\in S, denote by u(p):=1uu2upu^{(p)}:=1\oplus u\oplus u^{2}\oplus\cdots\oplus u^{p}, where ui:=uuuu^{i}:=u\otimes u\otimes\cdots\otimes u (ii times). We say that uu is pp-stable if u(p)=u(p+1)u^{(p)}=u^{(p+1)}; we say that the semiring 𝑺\bm{S} is pp-stable if every element uSu\in S is pp-stable, and we say that 𝑺\bm{S} is stable if every element uu is stable for some pp that may depend on uu. A datalog\text{\sf datalog}^{\circ} program is linear if every rule has at most one IDB predicate in the body. We prove:

Theorem 1.2.

Given a POPS 𝐏\bm{P}, the following hold.

  • Every datalog\text{\sf datalog}^{\circ} program converges iff the semiring 𝑷\bm{P}\oplus\bot is stable.

  • Every program converges in a number of steps that depends only on |ADom(I)||\textsf{ADom}(I)| iff 𝑷\bm{P}\oplus\bot is pp-stable for some pp. More precisely, every datalog\text{\sf datalog}^{\circ} program converges in i=1N(p+2)i\sum_{i=1}^{N}(p+2)^{i} steps, where NN is the number of ground tuples consisting of IDB predicates and constants from ADom(I)\textsf{ADom}(I). Furthermore, if the program is linear, then it converges in i=1N(p+1)i\sum_{i=1}^{N}(p+1)^{i} steps.

  • If 𝑷\bm{P}\oplus\bot is 0-stable, then every datalog\text{\sf datalog}^{\circ} program converges in NN steps; in particular, the program runs in polynomial time in the size of the input database.

In a nutshell, the theorem says that convergence of datalog\text{\sf datalog}^{\circ} is intimately related to the notion of stability. The proof, provided in Sec. 5, consists of an analysis of the infinite powerseries resulting from unfolding the fixpoint definition; for the proof of the first item we also use Parikh’s theorem (MR209093, ). As mentioned earlier, most prior work on fixpoint equations assumes an ω\omega-continuous semiring; when convergence is desired, one usually offers the Ascending Chain Condition, ACC (see Sec. 3) as a sufficient condition for convergence. Our theorem implies that ACC is only a sufficient, but not a necessary condition for convergence, for example Trop+\text{\sf Trop}^{+} is 0-stable, and therefore every datalog\text{\sf datalog}^{\circ} program converges on Trop+\text{\sf Trop}^{+}, yet it does not satisfy the ACC condition. A somewhat related result is proven by Luttenberger and Schlund (DBLP:journals/iandc/LuttenbergerS16, ) who showed that, if 11 is pp-stable, then Newton’s method requires at most N+loglogpN+\log\log p iterations. As mentioned earlier, each step of Newton’s method requires the computation of another least fixpoint, hence that result does not inform us on the convergence of the naïve algorithm.

Next, we introduce an extension of the semi-naïve evaluation algorithm to datalog\text{\sf datalog}^{\circ}. It is known that the naïve evaluation algorithm is inefficient in practice, because at each iteration it repeats all the computations that it has done at the previous iterations. Most datalog systems implement an improvement called the semi-naïve evaluation, which keeps track of the delta between the successive states of the IDBs and applies the datalog rules as a function of these deltas to obtain the new iteration’s deltas. Semi-naïve evaluation is one of the major optimization techniques for evaluating datalog, however, it is defined only for programs that are monotone under set inclusion, and the systems that implement it enforce monotonicity, preventing the use of aggregation in recursion. Our second result consists of showing how to adapt the semi-naïve algorithm to datalog\text{\sf datalog}^{\circ}, under certain restrictions of the POPS 𝑷\bm{P}, thus, enabling the semi-naïve algorithm to be applied to programs with aggregation in recursion.

Let’s illustrate the semi-naïve algorithm on the APSP program in Example 1.1. For that, let’s first review the standard semi-naïve algorithm for pure datalog on the transitive closure program (2). While the naïve algorithm starts with T(0)(X,Y)=T^{(0)}(X,Y)=\emptyset and repeats T(t+1)(X,Y)=E(X,Y)ZT(t)(X,Z)E(Z,Y)T^{(t+1)}(X,Y)=E(X,Y)\vee\bigvee_{Z}T^{(t)}(X,Z)\wedge E(Z,Y) for t=0,1,2,t=0,1,2,\ldots, the semi-naïve algorithm starts by initializing T(1)(X,Y)=δ(0)(X,Y)=E(X,Y)T^{(1)}(X,Y)=\delta^{(0)}(X,Y)=E(X,Y), then performs the following steps for t=1,2,3,t=1,2,3,\ldots:

(5) δ(t)(X,Y)\displaystyle\delta^{(t)}(X,Y) =(zδ(t1)(X,Z)E(Z,Y))T(t)(X,Y)\displaystyle=\left(\bigvee_{z}\delta^{(t-1)}(X,Z)\wedge E(Z,Y)\right)\setminus T^{(t)}(X,Y)
T(t+1)(X,Y)\displaystyle T^{(t+1)}(X,Y) =T(t)(X,Y)δ(t)(X,Y).\displaystyle=T^{(t)}(X,Y)\cup\delta^{(t)}(X,Y).

Thus, the semi-naïve algorithm avoids re-discovering at iteration tt tuples already discovered at iterations 1,2,,t11,2,\ldots,t-1.

In order to apply the same principle to the APSP program (4), we need to define an appropriate “minus” \ominus operator on the tropical semiring. This operator is:

(6) vu=\displaystyle v\ominus u= {vif v<uif vu\displaystyle\begin{cases}v&\mbox{if }v<u\\ \infty&\mbox{if }v\geq u\end{cases}

The semi-naïve algorithm for the APSP problem in (3) is a mirror of that in (5):

(7) δ(t)(X,Y)\displaystyle\delta^{(t)}(X,Y) =(minZδ(t1)(X,Z)+E(Z,Y))T(t)(X,Y),\displaystyle=(\min_{Z}\delta^{(t-1)}(X,Z)+E(Z,Y))\ominus T^{(t)}(X,Y),
T(t+1)(X,Y)\displaystyle T^{(t+1)}(X,Y) =min(T(t)(X,Y),δ(t)(X,Y))\displaystyle=\min(T^{(t)}(X,Y),\delta^{(t)}(X,Y))

where the difference operator \ominus is defined in (6). The reason why this algorithm is more efficient than the naïve algorithm is the fact that, in general, a database system needs to store only the tuples that are “present” in a relation, i.e. those whose value is \neq\bot. In our example, only those tuples δ(t)(X,Y)\delta^{(t)}(X,Y) whose value is \neq\infty need to be stored. The \ominus operator in (7) checks if the new value minZδ(t1)(X,Z)+E(Z,Y)\min_{Z}\delta^{(t-1)}(X,Z)+E(Z,Y) is strictly less than the old value T(t)(X,Y)T^{(t)}(X,Y): if not, then it returns \infty, signaling that the value of (X,Y)(X,Y) in both δ(t)(X,Y)\delta^{(t)}(X,Y) and T(t)(X,Y)T^{(t)}(X,Y) does not need to be updated. As a consequence, only those tuples T(t+1)(X,Y)T^{(t+1)}(X,Y) need to be processed at step tt where the value has strictly decreased from the previous step.

Finally, the last topic we address in this paper is a possible way of introducing negation in datalog\text{\sf datalog}^{\circ}. We will show that by interpreting datalog\text{\sf datalog}^{\circ} over a particular POPS called THREE (Sec. 2.5.2) and by appropriately defining a function not, datalog\text{\sf datalog}^{\circ} can express datalog queries with negation under Fitting’s three-valued semantics (DBLP:journals/jlp/Fitting85a, ). The crux in Fitting’s approach is to apply to the three-valued logic (with truth values {0,1,}\{0,1,\bot\}, where \bot means “undefined”) the knowledge order k\leq_{k} with k0\bot\leq_{k}0 and k1\bot\leq_{k}1. Then, the function not defined as 𝚗𝚘𝚝(0)=1\mathtt{not}(0)=1, 𝚗𝚘𝚝(1)=0\mathtt{not}(1)=0, and 𝚗𝚘𝚝()=\mathtt{not}(\bot)=\bot is monotone w.r.t. k\leq_{k}, and one can apply the usual least fixpoint semantics to datalog programs with negation (and, likewise, to datalog\text{\sf datalog}^{\circ} programs with the function not). Hence, in cases when Fitting’s 3-valued semantics coincides with the well-founded semantics, so does datalog\text{\sf datalog}^{\circ} equipped with the function not when interpreted over the POPS THREE.

1.2. Paper organization

We define POPS in Sec. 2 and give several examples. In Sec. 3 we consider the least fixpoint of monotone functions over posets, and prove an upper bound on the number of iterations needed to compute the least fixpoint. We define datalog\text{\sf datalog}^{\circ} formally in Sec. 4, and give several examples. The convergence results described in Theorem 1.2 are stated formally and proven in Sec. 5. Sec. 6 presents a generalization of semi-naïve evaluation to datalog\text{\sf datalog}^{\circ}. We discuss how datalog\text{\sf datalog}^{\circ} can express datalog queries with negation using 3-valued logic in Sec. 7. Finally, we conclude in Sec. 9.

2. Partially Ordered Pre-semirings

In this section, we review the basic algebraic notions of (pre-)semirings, PP-relations, and sum-product queries. We also introduce an extension called partially ordered pre-semiring (POPS).

2.1. (Pre-)Semirings and POPS

Definition 2.1 ((Pre-)semiring).

A pre-semiring (semiring_book, ) is a tuple 𝐒=(S,,,0,1)\bm{S}=(S,\oplus,\otimes,0,1) where \oplus and \otimes are binary operators on SS for which (S,,0)(S,\oplus,0) is a commutative monoid, (S,,1)(S,\otimes,1) is a monoid, and \otimes distributes over \oplus. When the absorption rule x0=0x\otimes 0=0 holds for all xSx\in S, we call 𝐒\bm{S} a semiring.222Some references, e.g. (DBLP:journals/ai/KohlasW08, ), define a semiring without absorption. When \otimes is commutative, then we say that the pre-semiring is commutative. In this paper we only consider commutative pre-semirings, and we will simply refer to them as pre-semirings.

In any (pre-)semiring 𝑺\bm{S}, the relation xSyx\preceq_{S}y defined as z:xz=y\exists z:x\oplus z=y, is a preorder, which means that it is reflexive and transitive, but it is not anti-symmetric in general. When S\preceq_{S} is anti-symmetric, then it is a partial order, and is called the natural order on 𝑺\bm{S}; in that case we say that 𝑺\bm{S} is naturally ordered.

Example 2.2.

Some simple examples of naturally ordered semirings are the Booleans (𝔹=def{0,1},,,0,1)(\mathbb{B}\stackrel{{\scriptstyle\text{def}}}{{=}}\{0,1\},\vee,\wedge,0,1), the natural numbers (,+,×,0,1)(\mathbb{N},+,\times,0,1), and the real numbers (,+,×,0,1)(\mathbb{R},+,\times,0,1). We will refer to them simply as 𝔹,\mathbb{B},\mathbb{N} and \mathbb{R}. The natural order on 𝔹\mathbb{B} is 0𝔹10\preceq_{\mathbb{B}}1 (or false 𝔹\preceq_{\mathbb{B}} true); the natural order on \mathbb{N} is the same as the familiar total order \leq of numbers. \mathbb{R} is not naturally ordered, because xyx\preceq_{\mathbb{R}}y holds for every x,yx,y\in\mathbb{R}. Another useful example is the tropical semiring Trop+=(+{},min,+,,0)\text{\sf Trop}^{+}=(\mathbb{R}_{+}\cup\{\infty\},\min,+,\infty,0), where the natural order xyx\preceq y is the reverse order xyx\geq y on +{}\mathbb{R}_{+}\cup\{\infty\}.

A key idea we introduce in this paper is the decoupling of the partial order from the algebraic structure of the (pre-)semiring. The decoupling allows us to inject a partial order when the (pre-)semiring is not naturally ordered, or when we need a different partial order than the natural order.

Definition 2.3 (POPS).

A partially ordered pre-semiring, in short POPS, is a tuple 𝐏=(P,,,0,1,)\bm{P}=(P,\oplus,\otimes,0,1,\sqsubseteq), where (P,,,0,1)(P,\oplus,\otimes,0,1) is a pre-semiring, (P,)(P,\sqsubseteq) is a poset, and ,\oplus,\otimes are monotone333Monotonicity means xxx\sqsubseteq x^{\prime} and yyy\sqsubseteq y^{\prime} imply xyxyx\oplus y\sqsubseteq x^{\prime}\oplus y^{\prime} and xyxyx\otimes y\sqsubseteq x^{\prime}\otimes y^{\prime}. operators under \sqsubseteq. In this paper, we will assume that every poset (P,)(P,\sqsubseteq) has a minimum element denoted by \bot.

A POPS satisfies the identities =\bot\oplus\bot=\bot and =\bot\otimes\bot=\bot, because, by monotonicity and the fact that (P,,0)(P,\oplus,0) and (P,,1)(P,\otimes,1) are commutative monoids, we have 0=\bot\oplus\bot\sqsubseteq\bot\oplus 0=\bot, and 1=\bot\otimes\bot\sqsubseteq\bot\otimes 1=\bot. We say that the multiplicative operator \otimes is strict if the identity x=x\otimes\bot=\bot holds for every xPx\in P.

Throughout this paper we will assume that \otimes is strict, unless otherwise stated. One of the reasons for insisting on the strictness assumption is that we can “extract” from a POPS a semiring, called the core semiring of the POPS, as shown in the following simple proposition.

Proposition 2.4.

Given an arbitrary POPS 𝐏=(P,,,0,1,)\bm{P}=(P,\oplus,\otimes,0,1,\sqsubseteq). Define the subset P=def{xxP}PP\oplus\bot\stackrel{{\scriptstyle\text{def}}}{{=}}\{{x\oplus\bot}\mid{x\in P}\}\subseteq P. Then, (P,,,0,1)(P\oplus\bot,\oplus,\otimes,0\oplus\bot,1\oplus\bot) is a semiring. We denote this semiring by 𝐏\bm{P}\oplus\bot, and refer to it as the core semiring of 𝐏\bm{P}.

Proof.

We use the fact that \otimes is strict, and check that 𝑷\bm{P}\oplus\bot is closed under \oplus and \otimes: (x)(y)=(xy)()=(xy)(x\oplus\bot)\oplus(y\oplus\bot)=(x\oplus y)\oplus(\bot\oplus\bot)=(x\oplus y)\oplus\bot, and similarly (x)(y)=(xy)(x)(y)=(xy)=(xy)𝑷(x\oplus\bot)\otimes(y\oplus\bot)=(x\otimes y)\oplus(x\otimes\bot)\oplus(y\otimes\bot)\oplus\bot=(x\otimes y)\oplus\bot\oplus\bot\oplus\bot=(x\otimes y)\oplus\bot\in\bm{P}\oplus\bot. Finally, it suffices to observe that =0\bot=0\oplus\bot is the identity for \oplus and 11\oplus\bot is the identity for \otimes. ∎

Every naturally ordered semiring is a POPS, where =0\bot=0 and \otimes is strict, and its core is itself, 𝑺0=𝑺\bm{S}\oplus 0=\bm{S}. The converse does not hold: some POPS are not naturally ordered; a simple example of a non-naturally ordered POPS is the set of lifted reals444The term “lifted” comes from the programming languages community where adding bottom to a set ‘lifts’ the set., =def({},+,,0,1,)\mathbb{R}_{\bot}\stackrel{{\scriptstyle\text{def}}}{{=}}(\mathbb{R}\cup\{\bot\},+,*,0,1,\sqsubseteq), where x+=x=x+\bot=x*\bot=\bot for all xx, and xyx\sqsubseteq y iff x=x=\bot or x=yx=y. Its core semiring is the trivial semiring +={}\mathbb{R}_{\bot}+\bot=\{\bot\} consisting of a single element. We will consider similarly the lifted natural numbers, \mathbb{N}_{\bot}.

2.2. Polynomials over POPS

Fix a POPS 𝑷=(P,,,0,1,)\bm{P}=(P,\oplus,\otimes,0,1,\sqsubseteq). We are interested in analysing behaviors of vector-valued multivariate functions on PP defined by composing \oplus and \otimes. These functions are multivariate polynomials. Writing polynomials in 𝑷\bm{P} using the symbols ,\oplus,\otimes is cumbersome and difficult to parse. Consequently, we replace them with +,+,\cdot when the underlying POPS 𝑷\bm{P} is clear from context; furthermore, we will also abbreviate a multiplication aba\cdot b with abab. As usual, aka^{k} denotes the product of kk copies of aa, where a0=def1a^{0}\stackrel{{\scriptstyle\text{def}}}{{=}}1.

Let x1,,xNx_{1},\ldots,x_{N} be NN variables. A monomial (on 𝑷\bm{P}) is an expression of the form:

(8) m=def\displaystyle m\stackrel{{\scriptstyle\text{def}}}{{=}} cx1k1xNkN\displaystyle c\cdot x_{1}^{k_{1}}\cdot\cdots\cdot x_{N}^{k_{N}}

where cPc\in P is some constant. Its degree is deg(m)=defk1++kN\text{\sf deg}(m)\stackrel{{\scriptstyle\text{def}}}{{=}}k_{1}+\cdots+k_{N}. A (multivariate) polynomial is a sum:

(9) f(x1,,xN)=def\displaystyle f(x_{1},\ldots,x_{N})\stackrel{{\scriptstyle\text{def}}}{{=}} m1+m2++mq\displaystyle m_{1}+m_{2}+\cdots+m_{q}

where each mim_{i} is a monomial. The polynomial ff defines a function PNPP^{N}\rightarrow P in the obvious way, and, with some abuse, we will denote by ff both the polynomial and the function it defines. Notice that ff is monotone in each of its arguments.

A vector-valued polynomial function on 𝑷\bm{P} is a function 𝒇:PNPM\bm{f}:P^{N}\rightarrow P^{M} whose component functions are polynomials. In particular, the vector-valued polynomial function is a tuple of polynomials 𝒇=(f1,,fM)\bm{f}=(f_{1},\ldots,f_{M}) where each fif_{i} is a polynomial in variables x1,,xNx_{1},\ldots,x_{N}.

We note a subtlety when dealing with POPS: when the POPS is not a semiring, then we cannot “remove” monomials by setting their coefficient c=0c=0, because 0 is not absorbing. Instead, we must ensure that they are not included in the polynomial (9). For example, consider the POPS of the lifted reals, 𝑹\bm{R}_{\bot}, and the linear polynomial f(x)=ax+bf(x)=ax+b. If we set a=0a=0, we do not obtain the constant function g(x)=bg(x)=b, because f()=a+b=+b=g()=bf(\bot)=a\bot+b=\bot+b=\bot\neq g(\bot)=b. We just have to be careful to not include monomials we don’t want.

2.3. PP-Relations

Fix a relational vocabulary, σ={R1,,Rm}\sigma=\{R_{1},\ldots,R_{m}\}, where each RiR_{i} is a relation name, with an associated arity. Let DD be an infinite domain of constants, for example the set of all strings over a fixed alphabet, or the set of natural numbers. Recall that an instance of the relation RiR_{i} is a finite subset of Darity(Ri)D^{\text{arity}(R_{i})}, or equivalently, a mapping Darity(Ri)𝔹D^{\text{arity}(R_{i})}\rightarrow\mathbb{B} assigning 11 to all tuples present in the relation. Following (DBLP:conf/pods/GreenKT07, ), we generalize this abstraction from 𝔹\mathbb{B} to an arbitrary POPS 𝑷\bm{P}.

Given a relation name RiσR_{i}\in\sigma, a ground atom of RiR_{i} is an expression of the form Ri(𝒖)R_{i}(\bm{u}), where 𝒖Darity(Ri)\bm{u}\in D^{\textsf{arity}(R_{i})}. Let GA(Ri,D)\textsf{GA}(R_{i},D) denote the set of all ground atoms of RiR_{i}, and GA(σ,D)=defiGA(Ri,D)\textsf{GA}(\sigma,D)\stackrel{{\scriptstyle\text{def}}}{{=}}\bigcup_{i}\textsf{GA}(R_{i},D) denote the set of all ground atoms over the entire vocabulary σ\sigma. The set GA(σ,D)\textsf{GA}(\sigma,D) is the familiar Herbrand base in logic programming. Note that each ground atom is prefixed by a relation name.

Let 𝑷\bm{P} be a POPS. A 𝑷\bm{P}-instance for σ\sigma is a function I:GA(σ,D)𝑷I:\textsf{GA}(\sigma,D)\rightarrow\bm{P} with finite support, where the support is defined as the set of ground atoms that are mapped to elements other than \bot. For example, if 𝑷\bm{P} is a naturally ordered semiring, then the support of the function II is the set of ground atoms assigned to a non-zero value. The active domain of the instance II, denoted by ADom(I)\textsf{ADom}(I), is the finite set ADom(I)D\textsf{ADom}(I)\subseteq D of all constants that occur in the support of II. We denote by Inst(σ,D,𝑷)\textsf{Inst}(\sigma,D,\bm{P}) the set of 𝑷\bm{P}-instances over the domain DD. When σ\sigma consists of a single relation name, then we call II a 𝑷\bm{P}-relation.

An equivalent way to define a 𝑷\bm{P}-instance is as a function I:GA(σ,D0)𝑷I:\textsf{GA}(\sigma,D_{0})\rightarrow\bm{P}, for some finite subset D0DD_{0}\subseteq D; by convention, this function is extended to the entire set GA(σ,D)\textsf{GA}(\sigma,D) by setting I(a):=I(a):=\bot for all aGA(σ,D)GA(σ,D0)a\in\textsf{GA}(\sigma,D)\setminus\textsf{GA}(\sigma,D_{0}). The set Inst(σ,D0,𝑷)\textsf{Inst}(\sigma,D_{0},\bm{P}) is isomorphic to PNP^{N}, where N=|GA(σ,D0)|N=|\textsf{GA}(\sigma,D_{0})|, and, throughout this paper, we will identify a 𝑷\bm{P}-instance with a tuple in PNP^{N}.

Thus, a 𝑷\bm{P}-instance involves two domains: DD, which is called the key space, and the POPS 𝑷\bm{P}, which is called the value space. For some simple illustrations, a 𝔹\mathbb{B}-relation is a standard relation where every ground tuple is either true or false, while an \mathbb{R}-relation is a sparse tensor.

2.4. (Sum-)Sum-Product Queries on POPS

In the Boolean world, conjunctive queries and unions of conjunctive queries are building-block queries. Analogously, in the POPS world, we introduce the concepts of sum-product queries and sum-sum-product queries. In the most simple setting, these queries have been studied in other communities (especially AI and machine learning as reviewed below). In our setting, we need to introduce one extra feature called “conditional”, in order to cope with the fact that 0 is not absorptive.

Fix two disjoint vocabularies, σ,σ𝔹\sigma,\sigma_{\mathbb{B}}; the relation names in σ\sigma will be interpreted over a POPS 𝑷\bm{P}, while those in σ𝔹\sigma_{\mathbb{B}} will be interpreted over the Booleans. Let DD be a domain, and V={X1,,Xp}V=\{X_{1},\ldots,X_{p}\} a set of “key variables” whose values are over the key space DD. They should not be confused with variables used in polynomials, which are interpreted over the POPS 𝑷\bm{P}; we refer to them as “value variables” to contrast them with the key variables. We use upper case for key variables, and lower case for value variables. A σ\sigma-atom is an expression of the form Ri(𝑿)R_{i}(\bm{X}), where RiσR_{i}\in\sigma and 𝑿(VD)arity(Ri)\bm{X}\in(V\cup D)^{\text{arity}(R_{i})}.

Definition 2.5.

A (conditional) sum-product query, or sum-product rule is an expression of the form

(10) T(X1,,Xk)\displaystyle T(X_{1},\ldots,X_{k}) :- Xk+1,,Xp{R1(𝑿1)Rm(𝑿m)Φ(V)}\displaystyle\text{ :- }\bigoplus_{X_{k+1},\ldots,X_{p}}\{{R_{1}(\bm{X}_{1})\otimes\cdots\otimes R_{m}(\bm{X}_{m})}\mid{\Phi(V)}\}

where TT is a new relation name of arity kk, each Rj(𝐗j)R_{j}(\bm{X}_{j}) is a σ\sigma-atom, and Φ\Phi is a first-order (FO) formula over σ𝔹\sigma_{\mathbb{B}}, whose free variables are in V={X1,,Xp}V=\{X_{1},\ldots,X_{p}\}. The LHS of :- is called the head, and the RHS the body of the rule. The variables X1,,XkX_{1},\ldots,X_{k} are called free variables of the query (also called head variables), and Xk+1,,XpX_{k+1},\ldots,X_{p} are called bound variables.

Without the conditional term Φ\Phi, the problem of computing efficiently sum-products over semirings has been extensively studied both in the database and in the AI literature. In databases, the query optimization and evaluation problem is a special case of sum-product computation over the value-space of Booleans (set semantics) or natural numbers (bag semantics). The functional aggregate queries (FAQ) framework (DBLP:conf/pods/KhamisNR16, ) extends the formulation to queries over multiple semirings. In AI, this problem was studied by Shenoy and Schafer (DBLP:conf/uai/ShenoyS88, ), Dechter (DBLP:journals/constraints/Dechter97, ), Kohlas and Wilson (DBLP:journals/ai/KohlasW08, ) and others. Surveys and more examples can be found in (DBLP:journals/tit/AjiM00, ; DBLP:books/daglib/0008195, ). These methods use a sparse representation of the 𝑷\bm{P}-relations, consisting of a collection of the tuples in their support.

The use of a conditional Φ\Phi in the sum-product is non-standard, but it is necessary for sum-product expressions over a POPS that is not a semiring, as we illustrate next.

Example 2.6.

Let E(X,Y)E(X,Y) be a 𝔹\mathbb{B}-relation (i.e. a standard relation), representing a graph. The following sum-product expression over 𝔹\mathbb{B} computes all pairs of nodes connected by a path of length 2:

T(X,Z)\displaystyle T(X,Z) :- Y(E(X,Y)E(Y,Z))\displaystyle\text{ :- }\exists_{Y}\left(E(X,Y)\wedge E(Y,Z)\right)

This is a standard conjunctive query (DBLP:books/aw/AbiteboulHV95, ) (where the semantics of quantification over YY is explicitly written). Here σ={E}\sigma=\{E\}, and σ𝔹=\sigma_{\mathbb{B}}=\emptyset: we do not need the conditional term Φ\Phi yet.

For the second example, consider the same graph given by E(X,Y)E(X,Y), and let C(X)C(X) be an \mathbb{R}_{\bot}-relation associating to each node XX a real number representing a cost, or \bot if the cost is unknown; now σ={C},σ𝔹={E}\sigma=\{C\},\sigma_{\mathbb{B}}=\{E\}. The following sum-product expression computes the total costs of all neighbors of XX:

(11) T(X) :-\displaystyle T(X)\text{ :- } Y{C(Y)E(X,Y)}\displaystyle\sum_{Y}\{{C(Y)}\mid{E(X,Y)}\}

Usually, conditionals are avoided by using an indicator function 1E(X,Y)1_{E(X,Y)}, which is defined to be 11 when E(X,Y)E(X,Y) is true and 0 otherwise, and writing the rule as T(X) :- Y(1E(X,Y)C(Y))T(X)\text{ :- }\sum_{Y}\left(1_{E(X,Y)}\cdot C(Y)\right). But this does not work in \mathbb{R}_{\bot}, because, when YY is mapped to a non-neighboring node which so happens to have an unknown cost (while all neighbors’ costs are known), we have C(Y)=C(Y)=\bot. In this case, 1E(X,Y)C(Y)=0=1_{E(X,Y)}\cdot C(Y)=0\cdot\bot=\bot, instead of 0. Since x+=x+\bot=\bot in \mathbb{R}_{\bot}, the result is also \bot. One may ask whether we can re-define the POPS \mathbb{R}_{\bot} so that 0=0\bot\cdot 0=0, but we show in Lemma 2.8 that this is not possible. The explicit conditional in (11) allows us to restrict the range of YY only to the neighbors of XX.

We now formally define the semantics of (conditional) sum-product queries. Due to the subtlety with POPS, we need to consider an alternative approach to evaluating the results of sum-product queries: first compute the provenance polynomials of the query (10) to obtain the component polynomials of a vector-valued function, then evaluate these polynomials. The provenance polynomials, or simply provenance, are also called lineage, or groundings in the literature (DBLP:conf/pods/GreenKT07, ).

Given an input instance I𝔹Inst(σ𝔹,D,𝔹)I_{\mathbb{B}}\in\textsf{Inst}(\sigma_{\mathbb{B}},D,\mathbb{B}), IInst(σ,D,𝑷)I\in\textsf{Inst}(\sigma,D,\bm{P}), and let D0DD_{0}\subseteq D be the finite set consisting of their active domains and all constants occurring in the sum-product expression (10). Let N=def|GA(σ,D0)|N\stackrel{{\scriptstyle\text{def}}}{{=}}|\textsf{GA}(\sigma,D_{0})| and M=def|GA(T,D0)|=|D0|kM\stackrel{{\scriptstyle\text{def}}}{{=}}|\textsf{GA}(T,D_{0})|=|D_{0}|^{k} be the number of input ground atoms and output ground atoms respectively.

To each of the NN input atoms GA(σ,D0)\textsf{GA}(\sigma,D_{0}) we associate a unique POPS variable x1,,xNx_{1},\ldots,x_{N}. (Recall that we use upper case for key variables and lower case for value variables.) Abusing notation, we also write xR(𝒖)x_{R(\bm{u})} to mean the variable associated to the ground atom R(𝒖)R(\bm{u}). A valuation is a function θ:VD0\theta:V\rightarrow D_{0}. When applied to the body of the rule (10), the valuation θ\theta defines the following monomial:

(12) θ(body)=def\displaystyle\theta(\text{body})\stackrel{{\scriptstyle\text{def}}}{{=}} xR1(θ(𝑿1))xR2(θ(𝑿2))xRm(θ(𝑿m))\displaystyle x_{R_{1}(\theta(\bm{X}_{1}))}\cdot x_{R_{2}(\theta(\bm{X}_{2}))}\cdots x_{R_{m}(\theta(\bm{X}_{m}))}

The provenance polynomial (DBLP:conf/pods/GreenKT07, ) of the output tuple T(𝒂)GA(T,D0)T(\bm{a})\in\textsf{GA}(T,D_{0}) is the following:

(13) fT(𝒂)(x1,,xN)=def\displaystyle f_{T(\bm{a})}(x_{1},\ldots,x_{N})\stackrel{{\scriptstyle\text{def}}}{{=}} θ:VD0:θ(X1,,Xk)=𝒂,I𝔹Φ[θ]θ(body)\displaystyle\sum_{\begin{subarray}{c}\theta:V\rightarrow D_{0}:\\ \theta(X_{1},\ldots,X_{k})=\bm{a},\\ I_{\mathbb{B}}\models\Phi[\theta]\end{subarray}}\theta(\text{body})

In other words, we consider only valuations θ\theta that map the head variables to the tuple 𝒂\bm{a} and satisfy the FO sentence Φ\Phi. There are MM provenance polynomials, one for each tuple in GA(T,D0)\textsf{GA}(T,D_{0}), and they define an MM-tuple of polynomials in NN variables, 𝒇\bm{f}, which in turn defines a function 𝒇:𝑷N𝑷M\bm{f}:\bm{P}^{N}\rightarrow\bm{P}^{M}. The semantics of the query (10) is defined as the value of this polynomial on the input instance IInst(σ,D0,𝑷)I\in\textsf{Inst}(\sigma,D_{0},\bm{P}), when viewed as a tuple I𝑷NI\in\bm{P}^{N}.

Note that, once we have constructed the provenance polynomial, we no longer need to deal with the conditional Φ\Phi, because the grounded version does not have Φ\Phi anymore. In most of the rest of the paper we will study properties of vector-valued functions whose components are these provenance polynomials.

We notice that, as defined, our semantics depends on the choice of the domain D0D_{0}: if we used a larger finite domain D0D0D^{\prime}_{0}\supseteq D_{0}, then the provenance polynomials will include additional spurious monomials, corresponding to the spurious grounded tuples in D0D_{0}^{\prime}. Traditionally, these spurious monomials are harmless, because their value is 0. However, in our setting, their value is \bot, and they may change the result. This is precisely the role of the conditional Φ\Phi in (10): to control the range of the variables and ensure that the semantics is domain independent. All examples in this paper are written such that they are domain independent.

Finally, (conditional) sum-sum-product queries are defined in the natural way:

Definition 2.7.

A (conditional) sum-sum-product query or sum-sum-product rule has the form:

(14) T(X1,,Xk)\displaystyle T(X_{1},\ldots,X_{k}) :- E1Eq\displaystyle\text{ :- }E_{1}\oplus\cdots\oplus E_{q}

where E1,E2,,EqE_{1},E_{2},\ldots,E_{q} are the bodies of sum-product expressions (10), each with the same free variables X1,,XkX_{1},\ldots,X_{k}.

The provenance polynomials of a sum-sum-product query are defined as the sum of the provenance polynomials of the expressions E1,,EqE_{1},\ldots,E_{q}.

2.5. Properties and Examples of POPS

We end this section by presenting several properties of POPS and illustrating them with a few examples.

2.5.1. Extending Pre-semirings to POPS

If 𝑺\bm{S} is a pre-semiring, then we say that a POPS 𝑷\bm{P} extends 𝑺\bm{S} if SPS\subseteq P (SS and PP are their domains), and the operations ,,0,1\oplus,\otimes,0,1 in 𝑺\bm{S} are the same as those in 𝑷\bm{P}. We describe three procedures to extend a pre-semiring 𝑺\bm{S} to a POPS 𝑷\bm{P}, inspired by abstract interpretations in programming languages (DBLP:conf/popl/CousotC77, ).

Representing Undefined:

The lifted POPS is 𝑺=(S{},,,0,1,)\bm{S}_{\bot}=(S\cup\{\bot\},\oplus,\otimes,0,1,\sqsubseteq), where xyx\sqsubseteq y iff x=x=\bot or x=yx=y, and the operations ,\oplus,\otimes are extended to \bot by setting x=x=x\oplus\bot=x\otimes\bot=\bot. Notice that 𝑺\bm{S}_{\bot} is not a semiring, because 0 is not absorbing: 000\otimes\bot\neq 0. Its core semiring is the trivial semiring S={}S_{\bot}\oplus\bot=\{\bot\}. Here \bot represents undefined.

Representing Contradiction:

The completed POPS is 𝑺=(S{,},,,0,1,)\bm{S}_{\bot}^{\top}=(S\cup\{\bot,\top\},\oplus,\otimes,0,1,\sqsubseteq), where xyx\sqsubseteq y iff x=x=\bot, x=yx=y, or y=y=\top and the operations ,\oplus,\otimes are extended to ,\bot,\top as follows: x=x=x\oplus\bot=x\otimes\bot=\bot for all xx (including x=x=\top), and x=x=x\oplus\top=x\otimes\top=\top for all xx\neq\bot. As before, its core semiring is the trivial semiring S={}S_{\bot}^{\top}\oplus\bot=\{\bot\}. Here ,\bot,\top represent undefined and contradiction respectively. Intuitively: \bot is the empty set \emptyset, each element x𝑺x\in\bm{S} is a singleton set consisting of one value, and \top is the entire set SS.

Representing Incomplete Values:

More generally, define 𝒫(𝑺)=(𝒫(S),,,0,1,)\mathcal{P}(\bm{S})=(\mathcal{P}(S),\oplus,\otimes,0,1,\subseteq). It consists of all subsets of 𝑺\bm{S}, ordered by set inclusion, where the operations ,\oplus,\otimes are extended to sets, e.g. AB={xyxA,yB}A\oplus B=\{{x\oplus y}\mid{x\in A,y\in B}\}. Its core semiring is itself, 𝒫(𝑺){0}=𝒫(𝑺)\mathcal{P}(\bm{S})\oplus\{0\}=\mathcal{P}(\bm{S}). Here =\bot=\emptyset represents undefined, =S\top=S represents contradiction, and, more generally, every set represents some degree of incompleteness.

A lifted POPS 𝑺\bm{S}_{\bot} is never a semiring, because 0=\bot\otimes 0=\bot, and the reader may ask whether there exists an alternative way to extend it to a POPS that is also a semiring, i.e. 0x=00\otimes x=0. For example, we can define {}\mathbb{N}\cup\{\bot\} as a semiring by setting x+=x+\bot=\bot for all xx, 0=00\cdot\bot=0 and x=x\cdot\bot=\bot for x>0x>0: one can check that the semiring laws hold. However, this is not possible in general. We prove:

Lemma 2.8.

If 𝐒\bm{S} is any POPS extension of (,+,,0,1)(\mathbb{R},+,\cdot,0,1), then 𝐒\bm{S} is not a semiring, i.e. it fails the absorption law 0x=00\cdot x=0.

Proof.

Let 𝑺=(S,+,,0,1,)\bm{S}=(S,+,\cdot,0,1,\sqsubseteq) be any POPS that is an extension of \mathbb{R}. In particular S\mathbb{R}\subseteq S and SS has a minimal element \bot. Since 0, 1 are additive and multiplicative identities, we have:

+0\displaystyle\bot+0 =\displaystyle=\bot 1\displaystyle\bot\cdot 1 =\displaystyle=\bot

We claim that the following more general identities hold:

x:+x=\displaystyle\forall x\in\mathbb{R}:\ \bot+x= \displaystyle\bot x{0}:x=\displaystyle\forall x\in\mathbb{R}\setminus\{0\}:\bot\cdot x= \displaystyle\bot

To prove the first identity, we use the fact that ++ is monotone in 𝑺\bm{S} and \bot is the smallest element, and derive +x(+(yx))+x=+y\bot+x\sqsubseteq(\bot+(y-x))+x=\bot+y for all x,yx,y\in\mathbb{R}. This implies +x=+y\bot+x=\bot+y for all x,yx,y and the claim follows by setting y=0y=0. The proof of the second identity is similar: first observe that x(yx)x=y\bot\cdot x\sqsubseteq(\bot\cdot\frac{y}{x})\cdot x=\bot\cdot y hence x=y\bot\cdot x=\bot\cdot y for all x,y{0}x,y\in\mathbb{R}\setminus\{0\}, and the claim follows by setting y=1y=1.

Assuming 𝑺\bm{S} is a semiring, it satisfies the absorption law: 0=0\bot\cdot 0=0. We prove now that 0=0=\bot. Choose any x{0}x\in\mathbb{R}\setminus\{0\}, and derive:

=+=(x)+((x))=(x+(x))\displaystyle\bot=\bot+\bot=(\bot\cdot x)+(\bot\cdot(-x))=\bot\cdot(x+(-x)) =0=0.\displaystyle=\bot\cdot 0=0.

The middle identity follows from distributivity. From 0=0=\bot, we conclude that 0 is the smallest element in 𝑺\bm{S}. Then, for every xx\in\mathbb{R}, we have x=x+0x+(x)=0x=x+0\sqsubseteq x+(-x)=0, which implies x=0x=0, x\forall x\in\mathbb{R}, which is a contradiction. Thus, 𝑺\bm{S} is not a semiring. ∎

2.5.2. The POPS THREE

Consider the following POPS: THREE=def({,0,1},,,0,1,k)\texttt{THREE}\stackrel{{\scriptstyle\text{def}}}{{=}}(\{\bot,0,1\},\vee,\wedge,0,1,\leq_{k}), where:

  • ,\vee,\wedge have the semantics of 3-valued logic (DBLP:journals/jlp/Fitting85a, ). More precisely, define the truth ordering 0tt10\leq_{t}\bot\leq_{t}1 and set xy=defmaxt(x,y)x\vee y\stackrel{{\scriptstyle\text{def}}}{{=}}\max_{t}(x,y), xy=defmint(x,y)x\wedge y\stackrel{{\scriptstyle\text{def}}}{{=}}\min_{t}(x,y). We note that this is precisely Kleene’s three-valued logic (DBLP:journals/logcom/Fitting91, ).

  • k\leq_{k} is the knowledge order, defined as <k0\bot<_{k}0 and <k1\bot<_{k}1.

THREE is not the same as the lifted Booleans, 𝔹\mathbb{B}_{\bot}, because in the latter 0=0\wedge\bot=\bot, while in THREE we have 0=00\wedge\bot=0. Its core semiring is THREE={,1}\texttt{THREE}\vee\bot=\{\bot,1\}, and is isomorphic to 𝔹\mathbb{B}. We will return to this POPS in Sec. 7.

2.5.3. Stable Semirings

We illustrate here two examples of semirings that are stable, a property that we define formally in Sec. 5. Both examples are adapted from (semiring_book, , Example 7.1.4) and (semiring_book, , Chapt.8, Sec.1.3.2) respectively. If AA is a set and p0p\geq 0 a natural number, then we denote by 𝒫p(A)\mathcal{P}_{p}(A) the set of subsets of AA of size pp, and by p(A)\mathcal{B}_{p}(A) the set of bags of AA of size pp. We also define

𝒫fin(A)\displaystyle\mathcal{P}_{\texttt{fin}}(A) =defp0𝒫p(A)\displaystyle\stackrel{{\scriptstyle\text{def}}}{{=}}\bigcup_{p\geq 0}\mathcal{P}_{p}(A) fin(A)\displaystyle\mathcal{B}_{\texttt{fin}}(A) =defp0p(A).\displaystyle\stackrel{{\scriptstyle\text{def}}}{{=}}\bigcup_{p\geq 0}\mathcal{B}_{p}(A).

We denote bags as in {{a,a,a,b,c,c}}\{\{a,a,a,b,c,c\}\}. Given 𝒙,𝒚𝒫fin(+)\bm{x},\bm{y}\in\mathcal{P}_{\texttt{fin}}(\mathbb{R}_{+}\cup\infty), we denote by:

𝒙𝒚=def\displaystyle\bm{x}\cup\bm{y}\stackrel{{\scriptstyle\text{def}}}{{=}} set union of 𝒙,𝒚\bm{x},\bm{y} 𝒙+𝒚=def\displaystyle\bm{x}+\bm{y}\stackrel{{\scriptstyle\text{def}}}{{=}} {u+vu𝒙,v𝒚}\displaystyle\{{u+v}\mid{u\in\bm{x},v\in\bm{y}}\}

Similarly, given 𝒙,𝒚fin(+)\bm{x},\bm{y}\in\mathcal{B}_{fin}(\mathbb{R}_{+}\cup\infty), we denote by:

𝒙𝒚=def\displaystyle\bm{x}\uplus\bm{y}\stackrel{{\scriptstyle\text{def}}}{{=}} bag union of 𝒙,𝒚\bm{x},\bm{y} 𝒙+𝒚=def\displaystyle\bm{x}+\bm{y}\stackrel{{\scriptstyle\text{def}}}{{=}} {{u+vu𝒙,v𝒚}}\displaystyle\{\{{u+v}\mid{u\in\bm{x},v\in\bm{y}}\}\}
Example 2.9.

For any bag 𝒙={{x0,x1,,xn}}\bm{x}=\{\{x_{0},x_{1},\ldots,x_{n}\}\}, where x0x1xnx_{0}\leq x_{1}\leq\ldots\leq x_{n}, and any p0p\geq 0, define:

minp(𝒙)=def\displaystyle{\min}_{p}(\bm{x})\stackrel{{\scriptstyle\text{def}}}{{=}} {{x0,x1,,xmin(p,n)}}\displaystyle\{\{x_{0},x_{1},\ldots,x_{\min(p,n)}\}\}

In other words, minp\min_{p} returns the smallest p+1p+1 elements of the bag 𝒙\bm{x}. Then, for any p0p\geq 0, the following is a semiring:

Tropp+=def\displaystyle\text{\sf Trop}^{+}_{p}\stackrel{{\scriptstyle\text{def}}}{{=}} (p+1(+{}),p,p,𝟎p,𝟏p)\displaystyle(\mathcal{B}_{p+1}(\mathbb{R}_{+}\cup\{\infty\}),\oplus_{p},\otimes_{p},\bm{0}_{p},\bm{1}_{p})

where:

𝒙p𝒚=def\displaystyle\bm{x}\oplus_{p}\bm{y}\stackrel{{\scriptstyle\text{def}}}{{=}} minp(𝒙𝒚)\displaystyle{\min}_{p}(\bm{x}\uplus\bm{y}) 𝟎p=def\displaystyle\bm{0}_{p}\stackrel{{\scriptstyle\text{def}}}{{=}} {{,,,}}\displaystyle\{\{\infty,\infty,\ldots,\infty\}\}
𝒙p𝒚=def\displaystyle\bm{x}\otimes_{p}\bm{y}\stackrel{{\scriptstyle\text{def}}}{{=}} minp(𝒙+𝒚)\displaystyle{\min}_{p}(\bm{x}+\bm{y}) 𝟏p=def\displaystyle\bm{1}_{p}\stackrel{{\scriptstyle\text{def}}}{{=}} {{0,,,}}\displaystyle\{\{0,\infty,\ldots,\infty\}\}

For example, if p=2p=2 then {{3,7,9}}2{{3,7,7}}={{3,3,7}}\{\{3,7,9\}\}\oplus_{2}\{\{3,7,7\}\}=\{\{3,3,7\}\} and {{3,7,9}}2{{3,7,7}}={{6,10,10}}\{\{3,7,9\}\}\otimes_{2}\{\{3,7,7\}\}=\{\{6,10,10\}\}. The following identities are easily checked, for any two finite bags 𝒙,𝒚\bm{x},\bm{y}:

(15) minp(minp(𝒙)minp(𝒚))=\displaystyle{\min}_{p}({\min}_{p}(\bm{x})\uplus{\min}_{p}(\bm{y}))= minp(𝒙𝒚)\displaystyle{\min}_{p}(\bm{x}\uplus\bm{y}) minp(minp(𝒙)+minp(𝒚))=\displaystyle{\min}_{p}({\min}_{p}(\bm{x})+{\min}_{p}(\bm{y}))= minp(𝒙+𝒚)\displaystyle{\min}_{p}(\bm{x}+\bm{y})

This implies that, an expression in the semiring Tropp+\text{\sf Trop}^{+}_{p} can be computed as follows. First, convert ,\oplus,\otimes to ,+\uplus,+ respectively, compute the resulting bag, then apply minp\min_{p} only once, on the final result. Tropp+\text{\sf Trop}^{+}_{p} is naturally ordered (see Prop 5.3) and therefore its core semiring is itself, Tropp+p𝟎p=Tropp+\text{\sf Trop}^{+}_{p}\oplus_{p}\bm{0}_{p}=\text{\sf Trop}^{+}_{p}. When p=0p=0, then Tropp+=Trop+\text{\sf Trop}^{+}_{p}=\text{\sf Trop}^{+}, which we introduced in Example 1.1.

Example 2.10.

Fix a real number η0\eta\geq 0, and denote by 𝒫η(+{})\mathcal{P}_{\leq\eta}(\mathbb{R}_{+}\cup\{\infty\}) the set of nonempty, finite sets 𝒙={x0,x1,,xp}\bm{x}=\{x_{0},x_{1},\ldots,x_{p}\} where min(𝒙)max(𝒙)min(𝒙)+η\min(\bm{x})\leq\max(\bm{x})\leq\min(\bm{x})+\eta. Given any finite set 𝒙𝒫fin(+{})\bm{x}\in\mathcal{P}_{\texttt{fin}}(\mathbb{R}_{+}\cup\{\infty\}), we define

minη(𝒙)=def\displaystyle{\min}_{\leq\eta}(\bm{x})\stackrel{{\scriptstyle\text{def}}}{{=}} {uu𝒙,umin(𝒙)+η}\displaystyle\{{u}\mid{u\in\bm{x},u\leq\min(\bm{x})+\eta}\}

In other words, minη\min_{\leq\eta} retains from the set 𝒙\bm{x} only the elements at distance η\leq\eta from its minimum. The following is a semiring:

Tropη+=def\displaystyle\text{\sf Trop}^{+}_{\leq\eta}\stackrel{{\scriptstyle\text{def}}}{{=}} (𝒫η(+{}),η,η,𝟎η,𝟏η)\displaystyle(\mathcal{P}_{\leq\eta}(\mathbb{R}_{+}\cup\{\infty\}),\oplus_{\leq\eta},\otimes_{\leq\eta},\bm{0}_{\leq\eta},\bm{1}_{\leq\eta})

where:

𝒙η𝒚=def\displaystyle\bm{x}\oplus_{\leq\eta}\bm{y}\stackrel{{\scriptstyle\text{def}}}{{=}} minη(𝒙𝒚)\displaystyle{\min}_{\leq\eta}(\bm{x}\cup\bm{y}) 𝟎η=def\displaystyle\bm{0}_{\leq\eta}\stackrel{{\scriptstyle\text{def}}}{{=}} {}\displaystyle\{\infty\}
𝒙η𝒚=def\displaystyle\bm{x}\otimes_{\leq\eta}\bm{y}\stackrel{{\scriptstyle\text{def}}}{{=}} minη(𝒙+𝒚)\displaystyle{\min}_{\leq\eta}(\bm{x}+\bm{y}) 𝟏η=def\displaystyle\bm{1}_{\leq\eta}\stackrel{{\scriptstyle\text{def}}}{{=}} {0}\displaystyle\{0\}

For example, if η=6.5\eta=6.5 then: {3,7}η{5,9,10}={3,5,7,9}\{3,7\}\oplus_{\leq\eta}\{5,9,10\}=\{3,5,7,9\} and {1,6}η{1,2,3}={2,3,4,7,8}\{1,6\}\otimes_{\leq\eta}\{1,2,3\}=\{2,3,4,7,8\}. The following identities are easily checked, for any two finite sets 𝒙,𝒚\bm{x},\bm{y}:

(16) minη(minη(𝒙)minη(𝒚))=\displaystyle{\min}_{\leq\eta}({\min}_{\leq\eta}(\bm{x})\cup{\min}_{\leq\eta}(\bm{y}))= minη(𝒙𝒚)\displaystyle{\min}_{\leq\eta}(\bm{x}\cup\bm{y}) minη(minη(𝒙)+minη(𝒚))=\displaystyle{\min}_{\leq\eta}({\min}_{\leq\eta}(\bm{x})+{\min}_{\leq\eta}(\bm{y}))= minη(𝒙+𝒚)\displaystyle{\min}_{\leq\eta}(\bm{x}+\bm{y})

It follows that expressions in Tropη+\text{\sf Trop}^{+}_{\leq\eta} can be computed as follows: first convert ,\oplus,\otimes to ,+\cup,+ respectively, compute the resulting set, and apply the minη\min_{\leq\eta} operator only once, on the final result. Tropη+\text{\sf Trop}^{+}_{\leq\eta} is naturally ordered (see Prop. 5.4) and therefore its core semiring is itself, Tropη+η𝟎η=Tropη+\text{\sf Trop}^{+}_{\leq\eta}\oplus_{\leq\eta}\bm{0}_{\leq\eta}=\text{\sf Trop}^{+}_{\leq\eta}. Notice that, when η=0\eta=0, then we recover again Tropη+=Trop+\text{\sf Trop}^{+}_{\leq\eta}=\text{\sf Trop}^{+}.

The reader may wonder why Tropp+\text{\sf Trop}^{+}_{p} is defined to consist of bags of p+1p+1 numbers, while Tropη+\text{\sf Trop}^{+}_{\leq\eta} is defined on sets. The main reason is for consistency with (semiring_book, ). We could have defined either semirings on either sets or bags, and both identities (15) and  (16) continue to hold, which is sufficient to prove the semiring identities. However, the stability property which we define and prove later (Proposition 5.4) holds for Tropη+\text{\sf Trop}^{+}_{\leq\eta} only if it is defined over sets; in contrast, Tropp+\text{\sf Trop}^{+}_{p} is stable for either sets or bags (Proposition 5.3).

2.5.4. Nontrivial Core Semiring

In all our examples so far the core semiring 𝑷\bm{P}\oplus\bot is either {}\{\bot\} or 𝑷\bm{P}. We show next that the core semiring may be non-trivial. If 𝑷1,𝑷2\bm{P}_{1},\bm{P}_{2} are two POPS, then their Cartesian product 𝑷1×𝑷2\bm{P}_{1}\times\bm{P}_{2} is also a POPS: operations are defined element-wise, e.g. (x1,x2)(y1,y2)=def(x11y1,x22y2)(x_{1},x_{2})\oplus(y_{1},y_{2})\stackrel{{\scriptstyle\text{def}}}{{=}}(x_{1}\oplus_{1}y_{1},x_{2}\oplus_{2}y_{2}), etc, the order is defined component-wise, and the smallest element is (1,2)(\bot_{1},\bot_{2}).

Example 2.11.

Consider the following two POPS.

  • A naturally ordered semiring 𝑺=(S,S,S,0S,1S,S)\bm{S}=(S,\oplus_{S},\otimes_{S},0_{S},1_{S},\sqsubseteq_{S}). Its core semiring is itself 𝑺S0S=𝑺\bm{S}\oplus_{S}0_{S}=\bm{S}.

  • Any POPS 𝑷\bm{P} where addition is strict: xP=x\oplus_{P}\bot=\bot. (For example, any lifted semiring.) Its core semiring is 𝑷PP={P}\bm{P}\oplus_{P}\bot_{P}=\{\bot_{P}\}.

Consider the Cartesian product 𝑺×𝑷\bm{S}\times\bm{P}. The smallest element is (0S,P)(0_{S},\bot_{P}), and the core semiring is (𝑺×𝑷)(0S,P)=𝑺×{P}(\bm{S}\times\bm{P})\oplus(0_{S},\bot_{P})=\bm{S}\times\{\bot_{P}\}, which is a non-trivial subset of 𝑺×𝑷\bm{S}\times\bm{P}.

3. Least Fixpoint

We review here the definition of a least fixpoint and prove some results needed to characterize the convergence of datalog\text{\sf datalog}^{\circ} programs. Fix a partially ordered set (poset), 𝑳=(L,)\bm{L}=(L,\sqsubseteq). As mentioned in Sec. 2, in this paper we will assume that each poset has a minimum element \bot, unless explicitly specified otherwise. We denote by A\bigvee A, or A\bigwedge A respectively, the least upper bound, or greatest lower bound of a set ALA\subseteq L, when it exists. We assume the usual definition of a monotone function ff between two posets, namely f(x)f(y)f(x)\sqsubseteq f(y) whenever xyx\sqsubseteq y. The Cartesian product of two posets 𝑳1=(L1,1)\bm{L}_{1}=(L_{1},\sqsubseteq_{1}) and 𝑳2=(L2,2)\bm{L}_{2}=(L_{2},\sqsubseteq_{2}), is also the standard component-wise ordering: 𝑳1×𝑳2=def(L1×L2,)\bm{L}_{1}\times\bm{L}_{2}\stackrel{{\scriptstyle\text{def}}}{{=}}(L_{1}\times L_{2},\sqsubseteq), where (x1,x2)(y1,y2)(x_{1},x_{2})\sqsubseteq(y_{1},y_{2}) if x11y1x_{1}\sqsubseteq_{1}y_{1} and x22y2x_{2}\sqsubseteq_{2}y_{2}. An ω\omega-chain in a poset 𝑳\bm{L} is a sequence x0x1x2x_{0}\sqsubseteq x_{1}\sqsubseteq x_{2}\sqsubseteq\cdots, or, equivalently, it is a monotone function 𝑳\mathbb{N}\rightarrow\bm{L}. We say that the chain is finite if there exists n0n_{0} such that xn0=xn0+1=xn0+2=x_{n_{0}}=x_{n_{0}+1}=x_{n_{0}+2}=\cdots, or, equivalently, if xn0=xnx_{n_{0}}=\bigvee x_{n}.

Given a monotone function f:𝑳𝑳f\colon\bm{L}\rightarrow\bm{L}, a fixpoint is an element xx such that f(x)=xf(x)=x. We denote by lfp𝑳(f)\text{\sf lfp}_{\bm{L}}(f) the least fixpoint of ff, when it exists, and drop the subscript 𝑳\bm{L} when it is clear from the context. Consider the following ω\omega-sequence:

(17) f(0)()=def\displaystyle f^{(0)}(\bot)\stackrel{{\scriptstyle\text{def}}}{{=}} \displaystyle\bot f(n+1)()=def\displaystyle f^{(n+1)}(\bot)\stackrel{{\scriptstyle\text{def}}}{{=}} f(f(n)())\displaystyle f(f^{(n)}(\bot))

If xx is any fixpoint of ff, then f(n)()xf^{(n)}(\bot)\sqsubseteq x; this follows immediately by induction on nn. In order to ensure that the least fixpoint exists, several authors require the semiring to be ω\omega-complete and ff to be ω\omega-continuous. In that case the least upper bound nf(n)()\bigvee_{n}f^{(n)}(\bot) always exists, and is equal to lfp(f)\text{\sf lfp}(f), due to Kleene’s theorem; see (davey1990introduction, ). This condition was used extensively in the formal language literature (MR1470001, ; DBLP:conf/popl/CousotC77, ), and also by Green et al. (DBLP:conf/pods/GreenKT07, ). We do not use this condition in this paper, and will not define it formally.

Instead, we are interested in conditions that ensure that the sequence (17) reaches a fixpoint after a finite number of steps, which justifies the following definition:

Definition 3.1.

A monotone function ff on 𝐋\bm{L} (i.e. f:𝐋𝐋f\colon\bm{L}\rightarrow\bm{L}) is called pp-stable if f(p+1)()=f(p)()f^{(p+1)}(\bot)=f^{(p)}(\bot). The stability index of ff is the minimum pp for which ff is pp-stable. The function ff is said to be stable if it is pp-stable for some p0p\geq 0.

If ff is pp-stable, then lfp(f)\text{\sf lfp}(f) exists and is equal to f(p)()f^{(p)}(\bot). Indeed, f(p)()f^{(p)}(\bot) is a fixpoint of ff by definition, and, as mentioned earlier, it is below any fixpoint xx of ff. In this case we will also say that the sequence (17) converges.

A sufficient condition for convergence often found in the literature is the Ascending Chain Condition, or ACC, see e.g. (MR1728440, ; DBLP:journals/jacm/EsparzaKL10, ): the poset 𝑳\bm{L} satisfies ACC if it has no infinite ω\omega-chains, meaning that every strictly increasing chain x0x1x2x_{0}\sqsubset x_{1}\sqsubset x_{2}\sqsubset\cdots must be finite. If 𝑳\bm{L} satisfies ACC, then every function 𝒇\bm{f} on 𝑳\bm{L} is stable, and thus has a least fixpoint. One can also check that, if 𝑳1,,𝑳n\bm{L}_{1},\ldots,\bm{L}_{n} satisfy ACC, then so does 𝑳=def𝑳1××𝑳n\bm{L}\stackrel{{\scriptstyle\text{def}}}{{=}}\bm{L}_{1}\times\cdots\times\bm{L}_{n}. However, as we will see shortly in Sec. 5, when ff is a polynomial, then the ACC is only a sufficient, but not necessary condition for stability.

In this paper we study the stability of functions on a product of posets. To this end, we start by considering two posets, 𝑳1\bm{L}_{1} and 𝑳2\bm{L}_{2} with minimum elements 1\bot_{1} and 2\bot_{2} respectively, and two monotone functions:

f:\displaystyle f: 𝑳1×𝑳2𝑳1\displaystyle\bm{L}_{1}\times\bm{L}_{2}\rightarrow\bm{L}_{1} g:\displaystyle g: 𝑳1×𝑳2𝑳2\displaystyle\bm{L}_{1}\times\bm{L}_{2}\rightarrow\bm{L}_{2}

Let hh be the vector-valued function with components ff and gg, i.e. h=def(f,g):𝑳1×𝑳2𝑳1×𝑳2h\stackrel{{\scriptstyle\text{def}}}{{=}}(f,g):\bm{L}_{1}\times\bm{L}_{2}\rightarrow\bm{L}_{1}\times\bm{L}_{2}. Our goal is to compute the fixpoint of hh by using the fixpoints of ff and gg. We start with a simple case:

Lemma 3.2.

Assume that gg does not depend on the first argument, i.e. g:𝐋2𝐋2g:\bm{L}_{2}\rightarrow\bm{L}_{2}. If p,qp,q are two numbers such that gg is qq-stable and, denoting y¯=defg(q)(2)\bar{y}\stackrel{{\scriptstyle\text{def}}}{{=}}g^{(q)}(\bot_{2}), the function F(x)=deff(x,y¯)F(x)\stackrel{{\scriptstyle\text{def}}}{{=}}f(x,\bar{y}) is pp-stable, then lfp(h)\text{\sf lfp}(h) exists and is equal to lfp(h)=(x¯,y¯)\text{\sf lfp}(h)=(\bar{x},\bar{y}) where x¯=defF(p)(1)\bar{x}\stackrel{{\scriptstyle\text{def}}}{{=}}F^{(p)}(\bot_{1}). Moreover, hh is p+qp+q-stable.

Proof.

We verify that (x¯,y¯)(\bar{x},\bar{y}) is a fixpoint of hh, by direct calculation: h(x¯,y¯)=(f(x¯,y¯),g(y¯))=(F(x¯),g(y¯))=(x¯,y¯)h(\bar{x},\bar{y})=(f(\bar{x},\bar{y}),g(\bar{y}))=(F(\bar{x}),g(\bar{y}))=(\bar{x},\bar{y}).

Next, we show that the stability index of hh is at most p+qp+q. For convenience, define:

y0=def\displaystyle y_{0}\stackrel{{\scriptstyle\text{def}}}{{=}} 2,\displaystyle\bot_{2}, 0:y+1=def\displaystyle\forall\ell\geq 0:\ \ y_{\ell+1}\stackrel{{\scriptstyle\text{def}}}{{=}} g(y),\displaystyle g(y_{\ell}),
x0=def\displaystyle x_{0}\stackrel{{\scriptstyle\text{def}}}{{=}} 1,\displaystyle\bot_{1}, k0:xk+1=def\displaystyle\forall k\geq 0:\ \ x_{k+1}\stackrel{{\scriptstyle\text{def}}}{{=}} f(xk,yq),\displaystyle f(x_{k},y_{q}),
(a0,b0)=def\displaystyle(a_{0},b_{0})\stackrel{{\scriptstyle\text{def}}}{{=}} (1,2),\displaystyle(\bot_{1},\bot_{2}), n0:(an+1,bn+1)=def\displaystyle\forall n\geq 0:\ \ (a_{n+1},b_{n+1})\stackrel{{\scriptstyle\text{def}}}{{=}} h(an,bn).\displaystyle h(a_{n},b_{n}).

By definition, x¯=xp\bar{x}=x_{p} and y¯=yq\bar{y}=y_{q}. We claim the following three statements:

(18) n:(an,bn)\displaystyle\forall n:\ \ (a_{n},b_{n})\sqsubseteq (x¯,y¯)\displaystyle(\bar{x},\bar{y})
(19) {0,,q}:(1,y)\displaystyle\forall\ell\in\{0,\dots,q\}:\ \ (\bot_{1},y_{\ell})\sqsubseteq (a,b)\displaystyle(a_{\ell},b_{\ell})
(20) k{0,,p}:(xk,yq)\displaystyle\forall k\in\{0,\dots,p\}:\ \ (x_{k},y_{q})\sqsubseteq (aq+k,bq+k)\displaystyle(a_{q+k},b_{q+k})

Assuming the claims hold, by setting k=pk=p in Eq. (20) we get (x¯,y¯)=(xp,yq)(ap+q,bp+q)(\bar{x},\bar{y})=(x_{p},y_{q})\sqsubseteq(a_{p+q},b_{p+q}), which, together with inequality (18), proves that (ap+q,bp+q)=(x¯,y¯)(a_{p+q},b_{p+q})=(\bar{x},\bar{y}) and that hh is p+qp+q-stable.

Now we prove the claims.

  • Eq. (18) is immediate, because (x¯,y¯)(\bar{x},\bar{y}) is a fixpoint of hh, and (an,bn)=h(n)(1,2)(a_{n},b_{n})=h^{(n)}(\bot_{1},\bot_{2}) is below any fixpoint of hh (due to monotonicity of hh).

  • To prove Eq (19), we claim that y=by_{\ell}=b_{\ell} for all \ell. Indeed, (a+1,b+1)=h(a,b)=(f(a,b),g(b))(a_{\ell+1},b_{\ell+1})=h(a_{\ell},b_{\ell})=(f(a_{\ell},b_{\ell}),g(b_{\ell})), which implies b+1=g(b)b_{\ell+1}=g(b_{\ell}), which means that yy_{\ell} and bb_{\ell} are the same sequence.

  • Finally, we show Eq. (20) by induction on kk. The base case, k=0k=0, follows from (x0,yq)=(1,yq)(aq,bq)(x_{0},y_{q})=(\bot_{1},y_{q})\sqsubseteq(a_{q},b_{q}) by Eq (19). Assuming the claim holds for kk, we have (xk+1,yq)=(f(xk,yq),yq)(f(aq+k,bq+k),bq+k)(f(aq+k,bq+k),g(bq+k))=h(aq+k,bq+k)=(aq+k+1,bq+k+1)(x_{k+1},y_{q})=(f(x_{k},y_{q}),y_{q})\sqsubseteq(f(a_{q+k},b_{q+k}),b_{q+k})\sqsubseteq(f(a_{q+k},b_{q+k}),g(b_{q+k}))=h(a_{q+k},b_{q+k})=(a_{q+k+1},b_{q+k+1}), proving that the claim holds for k+1k+1.

Next, we generalize the result to the case when both functions depend on both inputs: f:𝑳1×𝑳2𝑳1f:\bm{L}_{1}\times\bm{L}_{2}\rightarrow\bm{L}_{1} and g:𝑳1×𝑳2𝑳2g:\bm{L}_{1}\times\bm{L}_{2}\rightarrow\bm{L}_{2}. We prove:

Lemma 3.3.

Assume that p,qp,q are two numbers such that, for each u𝐋1u\in\bm{L}_{1}, the function gu(y)=defg(u,y)g_{u}(y)\stackrel{{\scriptstyle\text{def}}}{{=}}g(u,y) is qq-stable, and the function F(x)=deff(x,gx(q)(2))F(x)\stackrel{{\scriptstyle\text{def}}}{{=}}f(x,g_{x}^{(q)}(\bot_{2})) is pp-stable. Then the following hold:

  1. (1)

    The function hh is (pq+p+q)(pq+p+q)-stable, and has the least fixpoint (x¯,y¯)(\bar{x},\bar{y}), where

    (21) x¯=def\displaystyle\bar{x}\stackrel{{\scriptstyle\text{def}}}{{=}} F(p)(1)\displaystyle F^{(p)}(\bot_{1}) y¯=def\displaystyle\bar{y}\stackrel{{\scriptstyle\text{def}}}{{=}} gx¯(q)(2)\displaystyle g_{\bar{x}}^{(q)}(\bot_{2})
  2. (2)

    Further assume that f,gf,g also satisfy the symmetric conditions: fv(x)=deff(x,v)f_{v}(x)\stackrel{{\scriptstyle\text{def}}}{{=}}f(x,v) is pp-stable for all v𝑳2v\in\bm{L}_{2}, and G(y)=defg(fy(p)(1),y)G(y)\stackrel{{\scriptstyle\text{def}}}{{=}}g(f_{y}^{(p)}(\bot_{1}),y) is qq-stable. Then, denoting (an,bn)=defh(n)(1,2)(a_{n},b_{n})\stackrel{{\scriptstyle\text{def}}}{{=}}h^{(n)}(\bot_{1},\bot_{2}), the following equalities hold:

    (22) apq+p=\displaystyle a_{pq+p}= x¯\displaystyle\bar{x} bpq+q=\displaystyle b_{pq+q}= y¯\displaystyle\bar{y}

    In particular, hh is pq+max(p,q)pq+\max(p,q)-stable.

Proof.

We start by proving Item (1), generalizing the proof of Lemma 3.2. To verify that (x¯,y¯)(\bar{x},\bar{y}) is a fixpoint of hh, we need to show that f(x¯,y¯)=x¯f(\bar{x},\bar{y})=\bar{x} and g(x¯,y¯)=y¯g(\bar{x},\bar{y})=\bar{y}. Indeed, these follow from qq-stability of gx¯g_{\bar{x}} and pp-stability of FF:

g(x¯,y¯)\displaystyle g(\bar{x},\bar{y}) =gx¯(y¯)=gx¯(gx¯(q)(2))=gx¯(q+1)(2)=gx¯(q)(2)=y¯\displaystyle=g_{\bar{x}}(\bar{y})=g_{\bar{x}}(g_{\bar{x}}^{(q)}(\bot_{2}))=g_{\bar{x}}^{(q+1)}(\bot_{2})=g_{\bar{x}}^{(q)}(\bot_{2})=\bar{y}
f(x¯,y¯)\displaystyle f(\bar{x},\bar{y}) =f(x¯,gx¯(q)(2))=F(x¯)=F(F(p)(1))=F(p)(1)=x¯\displaystyle=f(\bar{x},g_{\bar{x}}^{(q)}(\bot_{2}))=F(\bar{x})=F(F^{(p)}(\bot_{1}))=F^{(p)}(\bot_{1})=\bar{x}

To complete the proof of Item (1), we next prove that hh is (pq+p+q)(pq+p+q)-stable. To this end, define the following sequences:

x0=def\displaystyle x_{0}\stackrel{{\scriptstyle\text{def}}}{{=}} 1\displaystyle\bot_{1} k{0,,p1}:xk+1=def\displaystyle\forall k\in\{0,\dots,p-1\}:\ \ x_{k+1}\stackrel{{\scriptstyle\text{def}}}{{=}} f(xk,yk,q)\displaystyle f(x_{k},y_{k,q})
yk,0=def\displaystyle y_{k,0}\stackrel{{\scriptstyle\text{def}}}{{=}} 2\displaystyle\bot_{2} {0,,q1}:yk,+1=def\displaystyle\forall\ell\in\{0,\dots,q-1\}:\ \ y_{k,\ell+1}\stackrel{{\scriptstyle\text{def}}}{{=}} g(xk,yk,)\displaystyle g(x_{k},y_{k,\ell})
(a0,b0)=def\displaystyle(a_{0},b_{0})\stackrel{{\scriptstyle\text{def}}}{{=}} (1,2)\displaystyle(\bot_{1},\bot_{2}) n0:(an+1,bn+1)=def\displaystyle\forall n\geq 0:\ \ (a_{n+1},b_{n+1})\stackrel{{\scriptstyle\text{def}}}{{=}} h(an,bn)\displaystyle h(a_{n},b_{n})

The sequences xkx_{k} and yk,y_{k,\ell} are illustrated in Fig. 1. We claim that the sequences satisfy the following two properties:

(23) n:(an,bn)\displaystyle\forall n:\ \ (a_{n},b_{n}) (x¯,y¯)\displaystyle\sqsubseteq(\bar{x},\bar{y})
(24) k{0,,p},{0,,q}:(xk,yk,)\displaystyle\forall k\in\{0,\dots,p\},\forall\ell\in\{0,\dots,q\}:\ \ (x_{k},y_{k,\ell}) (an,bn)\displaystyle\sqsubseteq(a_{n},b_{n}) where n=k(q+1)+\displaystyle\mbox{where }n=k(q+1)+\ell

Before proving them, we show how they help complete the proof of both (1) and (2).

  • By setting (k,)=def(p,q)(k,\ell)\stackrel{{\scriptstyle\text{def}}}{{=}}(p,q) and n=p(q+1)+q=pq+p+qn=p(q+1)+q=pq+p+q in Eq. (24) we obtain (x¯,y¯)=(xp,yp,q)(an,bn)(\bar{x},\bar{y})=(x_{p},y_{p,q})\sqsubseteq(a_{n},b_{n}), which, together with Eq. (23) proves that (x¯,y¯)=(an,bn)(\bar{x},\bar{y})=(a_{n},b_{n}) and, therefore, hh is pq+p+qpq+p+q-stable. This completes the proof of Item (1) of the lemma.

  • For Item (2), we notice that if we set (k,)=def(p,0)(k,\ell)\stackrel{{\scriptstyle\text{def}}}{{=}}(p,0) and n=p(q+1)=pq+pn=p(q+1)=pq+p in Eq. (24), then we obtain (x¯,yp,0)=(xp,yp,0)(an,bn)(\bar{x},y_{p,0})=(x_{p},y_{p,0})\sqsubseteq(a_{n},b_{n}), which implies x¯=an=apq+p\bar{x}=a_{n}=a_{pq+p}. By switching the roles of f,gf,g we also obtain y¯=bpq+q\bar{y}=b_{pq+q}, which proves the lemma. In particular, hh is pq+max(p,q)pq+\max(p,q)-stable.

We now prove the two claims (23) and (24). The first claim (23) is immediate, because (x¯,y¯)(\bar{x},\bar{y}) is a fixpoint of hh and (an,bn)=h(n)(1,2)(a_{n},b_{n})=h^{(n)}(\bot_{1},\bot_{2}) is below any fixpoint.

For the second claim in Equation (24), refer to Fig. 1 for some intuition; in particular, note that the mapping (k,)n=defk(q+1)+(k,\ell)\mapsto n\stackrel{{\scriptstyle\text{def}}}{{=}}k(q+1)+\ell is injective for k{0,,p}k\in\{0,\dots,p\}, {0,,q}\ell\in\{0,\dots,q\}, and nn represents the position of (xk,yk,)(x_{k},y_{k,\ell}) in the sequence defined in the figure. Note also that, yk,q=y¯y_{k,q}=\bar{y} for all k{0,,p}k\in\{0,\dots,p\} and xp=x¯x_{p}=\bar{x}; and, anf(an,bn)a_{n}\sqsubseteq f(a_{n},b_{n}) and bng(an,bn)b_{n}\sqsubseteq g(a_{n},b_{n}): this follows from hh being monotone: h(n)(1,2)h(n+1)(1,2)h^{(n)}(\bot_{1},\bot_{2})\sqsubseteq h^{(n+1)}(\bot_{1},\bot_{2}). We prove Eq. (24) by induction on nn.

{diagram}
Figure 1. Computing the fixpoint of (f,g)(f,g).
\Description

Computing the fixpoint of (f,g)(f,g).

The base case when n=0n=0 then k==0k=\ell=0 is trivial, as both sides of Eq. (24) are (1,2)(\bot_{1},\bot_{2}). For the inductive case, assume n>0n>0, and let k,k,\ell be the unique values s.t. n=k(q+1)+n=k(q+1)+\ell. Consider two cases, corresponding to whether we are taking a horizontal step or a vertical step in Fig. 1:

Case 1: >0\ell>0. Then the pre-image of n1n-1 is k,1k,\ell-1, in other words (n1)=k(q+1)+(1)(n-1)=k(q+1)+(\ell-1), and we have (xk,yk,1)(an1,bn1)(x_{k},y_{k,\ell-1})\sqsubseteq(a_{n-1},b_{n-1}) by induction hypothesis for n1n-1. It follows that

(xk,yk,)=(xk,g(xk,yk,1))(an1,g(an1,bn1))(f(an1,bn1),g(an1,bn1))=(an,bn)(x_{k},y_{k,\ell})=(x_{k},g(x_{k},y_{k,\ell-1}))\sqsubseteq(a_{n-1},g(a_{n-1},b_{n-1}))\sqsubseteq(f(a_{n-1},b_{n-1}),g(a_{n-1},b_{n-1}))=(a_{n},b_{n})

where we used the induction hypothesis and the fact that an1f(an1,bn1)a_{n-1}\sqsubseteq f(a_{n-1},b_{n-1}).

Case 2: =0\ell=0. Then the pre-image of n1n-1 is (k1,q)(k-1,q), in other words (n1)=(k1)(q+1)+q(n-1)=(k-1)(q+1)+q, and we have (xk1,yk1,q)(an1,bn1)(x_{k-1},y_{k-1,q})\sqsubseteq(a_{n-1},b_{n-1}) by induction hypothesis. It follows:

(xk,yk,0)=(xk,2)=(f(xk1,yk1,q),2)(f(xk1,yk1,q),yk1,q)(f(an1,bn1),bn1)(f(an1,bn1),g(an1,bn1))=(an,bn)(x_{k},y_{k,0})=(x_{k},\bot_{2})=(f(x_{k-1},y_{k-1,q}),\bot_{2})\sqsubseteq(f(x_{k-1},y_{k-1,q}),y_{k-1,q})\\ \sqsubseteq(f(a_{n-1},b_{n-1}),b_{n-1})\sqsubseteq(f(a_{n-1},b_{n-1}),g(a_{n-1},b_{n-1}))=(a_{n},b_{n})

This completes the proof of Eq. (24).

Next, we present Theorem 3.4, which generalizes Lemma 3.3 from 2 functions to nn functions. Recall that in the lemma we had to consider two derived functions gug_{u} and FF from ff and gg. When generalizing to nn functions, the number of derived functions becomes unwieldy, and it is more convenient to state the theorem for a clone of functions. A clone (DBLP:conf/dagstuhl/2008coc, ) over nn posets 𝑳1,,𝑳n\bm{L}_{1},\ldots,\bm{L}_{n} is a set of functions 𝒞\mathcal{C} where (1) each element f𝒞f\in\mathcal{C} of the form f:𝑳j1××𝑳jk𝑳if:\bm{L}_{j_{1}}\times\cdots\times\bm{L}_{j_{k}}\rightarrow\bm{L}_{i}, where 1j1<j2<<jkn1\leq j_{1}<j_{2}<\ldots<j_{k}\leq n and 1in1\leq i\leq n, is monotone, (2) 𝒞\mathcal{C} contains all projections 𝑳j1××𝑳jk𝑳ji\bm{L}_{j_{1}}\times\cdots\times\bm{L}_{j_{k}}\rightarrow\bm{L}_{j_{i}}, and (3) 𝒞\mathcal{C} is closed under composition, i.e. it contains the function g(f1,,fk)g\circ(f_{1},\ldots,f_{k}) whenever f1,,fk,g𝒞f_{1},\ldots,f_{k},g\in\mathcal{C} and their types make the composition correct. We call 𝒞\mathcal{C} a c-clone if it also contains all constant functions: gu:()𝑳ig_{u}\colon()\rightarrow\bm{L}_{i}, gu()=defug_{u}()\stackrel{{\scriptstyle\text{def}}}{{=}}u, for every fixed uLiu\in L_{i}.

For a simple illustration of a c-clone, consider a POPS 𝑷\bm{P}, and define 𝒞\mathcal{C} to consist of all multivariate polynomials over variables x1,,xnx_{1},\ldots,x_{n}. More precisely, set 𝑳1==𝑳n=def𝑷\bm{L}_{1}=\cdots=\bm{L}_{n}\stackrel{{\scriptstyle\text{def}}}{{=}}\bm{P}, and, for all choices of indices 1j1<j2<<jkn1\leq j_{1}<j_{2}<\cdots<j_{k}\leq n and 1in1\leq i\leq n, let 𝒞\mathcal{C} contain all polynomials f(xj1,,xjk)f(x_{j_{1}},\ldots,x_{j_{k}}), viewed as functions 𝑳j1××𝑳jk𝑳i\bm{L}_{j_{1}}\times\cdots\times\bm{L}_{j_{k}}\rightarrow\bm{L}_{i}. Then 𝒞\mathcal{C} is a c-clone.

Theorem 3.4.

Let 𝒞\mathcal{C} be a c-clone of functions over nn posets 𝐋1,,𝐋n\bm{L}_{1},\ldots,\bm{L}_{n}, and assume that, for every i[n]i\in[n] where we denote by [n][n] the integers from 1 to nn, every function f:𝐋i𝐋if\colon\bm{L}_{i}\rightarrow\bm{L}_{i} in 𝒞\mathcal{C} is pip_{i}-stable. Assume w.l.o.g. that p1p2pnp_{1}\geq p_{2}\geq\cdots\geq p_{n}. Let f1,,fnf_{1},\ldots,f_{n} be functions in 𝒞\mathcal{C}, where fi:𝐋1××𝐋n𝐋if_{i}:\bm{L}_{1}\times\cdots\times\bm{L}_{n}\rightarrow\bm{L}_{i}, and define the function h=def(f1,,fn)h\stackrel{{\scriptstyle\text{def}}}{{=}}(f_{1},\ldots,f_{n}). Then hh is pp-stable, where p=defk=1,ni=1,kpip\stackrel{{\scriptstyle\text{def}}}{{=}}\sum_{k=1,n}\prod_{i=1,k}p_{i}. Moreover, this upper bound is tight: there exist posets 𝐋1,,𝐋n\bm{L}_{1},\ldots,\bm{L}_{n}, a c-clone 𝒞\mathcal{C}, and functions f1,,fnf_{1},\ldots,f_{n}, such that pp is the stability index of hh.

Proof.

We defer the lower bound to Appendix A, and prove here the upper bound. It will be convenient to define the following expression, for every m0m\geq 0 and numbers a1,,ama_{1},\ldots,a_{m}:

Em(a1,,am)=def\displaystyle E_{m}(a_{1},\ldots,a_{m})\stackrel{{\scriptstyle\text{def}}}{{=}} a1+a1a2+a1a2a3+a1a2am=i=1,mj=1,iaj\displaystyle a_{1}+a_{1}a_{2}+a_{1}a_{2}a_{3}\cdots+a_{1}a_{2}\cdots a_{m}=\sum_{i=1,m}\prod_{j=1,i}a_{j}

Note that if we permute the sequence a1,,ama_{1},\ldots,a_{m}, the expression Em(a1,,am)E_{m}(a_{1},\ldots,a_{m}) is maximized when the sequence is decreasing, a1a2ama_{1}\geq a_{2}\geq\cdots\geq a_{m}.

We prove by induction on nn that hh is En(p1,,pn)E_{n}(p_{1},\ldots,p_{n})-stable. When n=1n=1 then the statement holds vacuously, because a function f:𝑳1𝑳1f\colon\bm{L}_{1}\rightarrow\bm{L}_{1} is p1p_{1}-stable by assumption. Assume n>1n>1 and let f1,,fnf_{1},\ldots,f_{n} be as in the statement of the theorem.

Fix an arbitrary dimension i[n]i\in[n]. Let 𝑳i=def𝑳1××𝑳i1×𝑳i+1×𝑳n\bm{L}_{-i}\stackrel{{\scriptstyle\text{def}}}{{=}}\bm{L}_{1}\times\cdots\times\bm{L}_{i-1}\times\bm{L}_{i+1}\cdots\times\bm{L}_{n} be the product of all posets other than 𝑳i\bm{L}_{i}. Given 𝒙=(x1,,xn)𝑳1××𝑳n\bm{x}=(x_{1},\ldots,x_{n})\in\bm{L}_{1}\times\ldots\times\bm{L}_{n}, denote by

(25) xi\displaystyle x_{-i} =def(x1,,xi1,xi+1,,xn)𝑳i\displaystyle\stackrel{{\scriptstyle\text{def}}}{{=}}(x_{1},\ldots,x_{i-1},x_{i+1},\ldots,x_{n})\in\bm{L}_{-i}

the vector consisting of all coordinates other than ii. Define the functions f:𝑳i×𝑳i𝑳if:\bm{L}_{i}\times\bm{L}_{-i}\rightarrow\bm{L}_{i} and g:𝑳i×𝑳i𝑳ig:\bm{L}_{i}\times\bm{L}_{-i}\rightarrow\bm{L}_{-i}:

f(xi,xi)\displaystyle f(x_{i},x_{-i}) =deffi(x)\displaystyle\stackrel{{\scriptstyle\text{def}}}{{=}}f_{i}(x) g(xi,xi)\displaystyle g(x_{i},x_{-i}) =def(f1(x),,fi1(x),fi+1(x),,fn(x))\displaystyle\stackrel{{\scriptstyle\text{def}}}{{=}}(f_{1}(x),\ldots,f_{i-1}(x),f_{i+1}(x),\ldots,f_{n}(x))

Then hh can be written as h(𝒙)=(f(xi,xi),g(xi,xi))h(\bm{x})=(f(x_{i},x_{-i}),g(x_{i},x_{-i})) (with some abuse, assuming f(xi,xi)f(x_{i},x_{-i}) is moved from the 1-st to the ii-th position). The assumptions of Lemma 3.3, including those of Item (2) are satisfied. For example, given xi𝑳ix_{i}\in\bm{L}_{i}, the function gxi(xi)=defg(xi,xi)g_{x_{i}}(x_{-i})\stackrel{{\scriptstyle\text{def}}}{{=}}g(x_{i},x_{-i}) is in the c-clone 𝒞\mathcal{C} and has type 𝑳i𝑳i\bm{L}_{-i}\to\bm{L}_{-i}; hence, it is q=defEn1(p1,,pi1,pi+1,,pn)q\stackrel{{\scriptstyle\text{def}}}{{=}}E_{n-1}(p_{1},\ldots,p_{i-1},p_{i+1},\ldots,p_{n})-stable, by induction hypothesis. Similarly, the function F(xi)=deff(xi,gxi(q)())F(x_{i})\stackrel{{\scriptstyle\text{def}}}{{=}}f(x_{i},g_{x_{i}}^{(q)}(\bot)) is in the c-clone 𝒞\mathcal{C} and has type 𝑳i𝑳i\bm{L}_{i}\rightarrow\bm{L}_{i}, hence it is pip_{i}-stable by the assumption of the theorem. The conditions for Item (2) of Lemma 3.3 are verified similarly.

Lemma 3.3 implies two things. First, hh has a least fixpoint, denoted by lfp(h)=(x¯1,,x¯n)\text{\sf lfp}(h)=(\bar{x}_{1},\ldots,\bar{x}_{n}). Second, from Item (2) of the lemma and from induction hypothesis, the ii-component of h(r)()h^{(r)}(\bot) reaches the fixpoint (h(r)())i=x¯i(h^{(r)}(\bot))_{i}=\bar{x}_{i} when

r=piq+pi=piEn1(p1,,pi1,pi+1,,pn)+piEn(p1,,pn).r=p_{i}q+p_{i}=p_{i}\cdot E_{n-1}(p_{1},\ldots,p_{i-1},p_{i+1},\ldots,p_{n})+p_{i}\leq E_{n}(p_{1},\ldots,p_{n}).

Note that once the fixpoint in a dimension is reached, it stays fixed. Since ii was arbitrary, hh reaches the fixpoint in all dimensions after En(p1,,pn)E_{n}(p_{1},\dots,p_{n}) iterations. ∎

4. DATALOG\textsf{DATALOG}^{\circ}

We define here the language datalog\text{\sf datalog}^{\circ}, which generalizes datalog from traditional relations to 𝑷\bm{P}-relations, for some POPS 𝑷\bm{P}. As in datalog, the input relations to the program will be called Extensional Database Predicates, EDB, and the computed relations will be called Intensional Database Predicates, IDB. Each EDB can be either a 𝑷\bm{P}-relation, or standard relation, i.e. a 𝔹\mathbb{B}-relation, and we denote by σ=def{R1,,Rm}\sigma\stackrel{{\scriptstyle\text{def}}}{{=}}\{R_{1},\ldots,R_{m}\} and σ𝔹=def{B1,,Bk}\sigma_{\mathbb{B}}\stackrel{{\scriptstyle\text{def}}}{{=}}\{B_{1},\ldots,B_{k}\} the two vocabularies. All IDBs are 𝑷\bm{P}-relations, and their vocabulary is denoted by τ={T1,,Tn}\tau=\{T_{1},\ldots,T_{n}\}.

A datalog\text{\sf datalog}^{\circ} program Π\Pi consists of nn sum-sum-product rules r1,,rnr_{1},\ldots,r_{n} (as in Definition 2.7), where each rule rir_{i} has the IDB TiT_{i} in the head:

r1:\displaystyle r_{1}: T1() :-\displaystyle T_{1}(\cdots)\text{ :- } E11E12\displaystyle E_{11}\oplus E_{12}\oplus\cdots
(26) \displaystyle\ldots
rn:\displaystyle r_{n}: Tn() :-\displaystyle T_{n}(\cdots)\text{ :- } En1En2,\displaystyle E_{n1}\oplus E_{n2}\oplus\cdots,

and each EijE_{ij} is a sum-product expression as in (10). The program Π\Pi is said to be linear if each sum-product expression EijE_{ij} contains at most one IDB predicate.

4.1. Least Fixpoint of the Immediate Consequence Operator

The Immediate Consequence Operator (ICO) associated to a program Π\Pi is the function F:Inst(σ,D,𝑷)×Inst(σ𝔹,D,𝔹)×Inst(τ,D,𝑷)Inst(τ,D,𝑷)F:\textsf{Inst}(\sigma,D,\bm{P})\times\textsf{Inst}(\sigma_{\mathbb{B}},D,\mathbb{B})\times\textsf{Inst}(\tau,D,\bm{P})\rightarrow\textsf{Inst}(\tau,D,\bm{P}), that takes as input an instance (I,I𝔹)(I,I_{\mathbb{B}}) of the EDBs and an instance JJ of the IDBs, and computes a new instance F(I,I𝔹,J)F(I,I_{\mathbb{B}},J) of the IDBs by evaluating each sum-sum-product rule. By fixing the EDBs, we will view the ICO as function from IDBs to IDBs, written as F(J)F(J). We define the semantics of the datalog\text{\sf datalog}^{\circ} program (26) as the least fixpoint of the ICO FF, when it exists.

J(0);J^{(0)}\leftarrow\bot\mbox{;}                           // In a naturally ordered semiring this becomes J(0)0J^{(0)}\leftarrow 0
for  t0t\leftarrow 0 to \infty  do
       J(t+1)F(J(t))J^{(t+1)}\leftarrow F(J^{(t)});
       if  J(t+1)=J(t)J^{(t+1)}=J^{(t)}  then
             Break
return J(t)J^{(t)}
Algorithm 1 Naïve evaluation for datalog\text{\sf datalog}^{\circ}

The Naïve Algorithm for evaluating datalog\text{\sf datalog}^{\circ} is shown in Algorithm 1, and it is quite similar to that for standard, positive datalog with set semantics. We start with all IDBs at \bot, then repeatedly apply the ICO FF, until we reach a fixpoint. The algorithm computes the increasing sequence F()F(2)()\bot\sqsubseteq F(\bot)\sqsubseteq F^{(2)}(\bot)\sqsubseteq\cdots When the algorithm terminates we say that it converges; in that case it returns the least fixpoint of FF. Otherwise we say that the algorithm diverges.

4.2. Convergence of datalog\text{\sf datalog}^{\circ} Programs

While every pure datalog program is guaranteed to have a least fixpoint, this no longer holds for datalog\text{\sf datalog}^{\circ} programs. As we mentioned in the introduction, there are five possibilities, depending on the POPS 𝑷\bm{P}:

  1. (i)

    tJ(t)\bigvee_{t}J^{(t)} is not a fixpoint of the ICO; in this case we say that the program diverges. For example, suppose the POPS consists of ×\mathbb{N}\times\mathbb{N}, with pairwise addition and multiplication, i.e. (x,y)(u,v)=(x+u,y+v)(x,y)\oplus(u,v)=(x+u,y+v) and similarly for \otimes, and with the lexicographic order (x,y)(u,v)(x,y)\sqsubseteq(u,v) defined as x<ux<u or x=ux=u and yvy\leq v. If the ICO of a program is the function F(x,y)=(x,y+1)F(x,y)=(x,y+1), then t0F(t)(0,0)=t0(0,t)=(1,0)\bigvee_{t\geq 0}F^{(t)}(0,0)=\bigvee_{t\geq 0}(0,t)=(1,0) is not a fixpoint of FF, because F(1,0)=(1,1)F(1,0)=(1,1); in fact, FF has no fixpoint.

  2. (ii)

    nJ(n)\bigvee_{n}J^{(n)} is always the least fixpoint, but the naïve algorithm does not always terminate. With some abuse we say also in this case that the program diverges. For a simple example, consider the semiring {}\mathbb{N}\cup\{\infty\} and the function F(x)=x+1F(x)=x+1. Its fixpoint is \infty, but it is not computable in a finite number of steps.

  3. (iii)

    The naïve algorithm always terminates, in which case we say that it converges. The number of steps depends on the input EDB database, meaning both the number of ground atoms in the EDB, and their values in 𝑷\bm{P}.

  4. (iv)

    The naïve algorithm always terminates in a number of steps that depends only on the number of ground atoms in the EDB, but not on their values.

  5. (v)

    The naïve algorithm always terminates in a number of steps that is polynomial in the number of ground atoms in the EDB.

In this paper we are interested in characterizing the POPS that ensure that every datalog\text{\sf datalog}^{\circ} program converges. At a finer level, our goal is to characterize precisely cases (iii)-(v). We will do this in Sec. 5, and, for that purpose, we will use an equivalent definition of the semantics of a datalog\text{\sf datalog}^{\circ} program, namely as the least fixpoint of a tuple of polynomials, obtained by grounding the program.

4.3. Least Fixpoint of the Grounded Program

In this paper we consider an equivalent semantics of datalog\text{\sf datalog}^{\circ}, which consists of first grounding the program, then computing its least fixpoint.

Fix an EDB instance I,I𝔹I,I_{\mathbb{B}}, and let D0DD_{0}\subseteq D be the finite set consisting of its active domain plus all constants occurring in the program Π\Pi. Let M=|GA(σ,D0)|M=|\textsf{GA}(\sigma,D_{0})| and N=|GA(τ,D0)|N=|\textsf{GA}(\tau,D_{0})| be the number of ground tuples of the EDBs and the IDBs respectively. We associate them in 1-to-1 correspondence with M+NM+N POPS variables z1,,zMz_{1},\ldots,z_{M} and x1,,xNx_{1},\ldots,x_{N}, and use the same notation as in Sec. 2.4 by writing xTi(𝒂)x_{T_{i}(\bm{a})} for the variable associated to the ground tuple Ti(𝒂)T_{i}(\bm{a}).

Consider a rule Ti() :- Ei1Ei2T_{i}(\cdots)\text{ :- }E_{i1}\oplus E_{i2}\oplus\cdots of the datalog\text{\sf datalog}^{\circ} program, with head relation TiT_{i}. A grounding of this rule is a rule of the form:

xTi(𝒂) :-\displaystyle x_{T_{i}(\bm{a})}\text{ :- } fTi(𝒂)(z1,,zM,x1,,xN)\displaystyle f_{T_{i}(\bm{a})}(z_{1},\ldots,z_{M},x_{1},\ldots,x_{N})

where Ti(𝒂)GA(Ti,D0)T_{i}(\bm{a})\in\textsf{GA}(T_{i},D_{0}) is a ground tuple, and fTi(𝒂)f_{T_{i}(\bm{a})} is the provenance polynomial (defined in Sec. 2.4) of the rule’s body Ei1Ei2E_{i1}\oplus E_{i2}\oplus\cdots Since the value of each EDB variable zRi(𝒖)z_{R_{i}(\bm{u})} is known, we can substitute it with its value, and the provenance polynomial simplifies to one that uses only IDB variables xjx_{j}; we will no longer refer to the EDB variables ziz_{i}. The grounded program consists of all NN groundings, of all rules. Using more friendly indexes, we write the grounded program as:

x1 :-\displaystyle x_{1}\text{ :- } f1(x1,,xN)\displaystyle f_{1}(x_{1},\ldots,x_{N})
(27) \displaystyle\ldots
xN :-\displaystyle x_{N}\text{ :- } fN(x1,,xN)\displaystyle f_{N}(x_{1},\ldots,x_{N})

where each fif_{i} is a multivariate polynomial in the variables x1,,xNx_{1},\ldots,x_{N}. We write 𝒇=(f1,,fN)\bm{f}=(f_{1},\ldots,f_{N}) for the vector-valued function whose components are the NN provenance polynomials, and define the semantics of the datalog\text{\sf datalog}^{\circ} program as its least fixpoint, lfp(𝒇)\text{\sf lfp}(\bm{f}), when it exists, where, as usual, we identify the tuple lfp(𝒇)𝑷N\text{\sf lfp}(\bm{f})\in\bm{P}^{N} with an IDB instance lfp(𝒇)Inst(τ,D0,𝑷)\text{\sf lfp}(\bm{f})\in\textsf{Inst}(\tau,D_{0},\bm{P}). By definition, lfp(𝒇)\text{\sf lfp}(\bm{f}) is equal to the least fixpoint of the ICO, as defined in Sec. 4.1.

4.4. Examples

We illustrate datalog\text{\sf datalog}^{\circ} with two examples. When the POPS 𝑷\bm{P} is a naturally ordered semiring, then we will use the following indicator function [C]01[C]_{0}^{1}, which maps a Boolean condition CC to either 0𝑷0\in\bm{P} or 1𝑷1\in\bm{P}, depending on whether CC is false or true. We write the indicator function simply as [C][C], when the values 0,10,1 are clear from the context. An indicator function can be desugared by replacing {[C]P1PkΦ}\{{[C]\otimes P_{1}\otimes\cdots\otimes P_{k}}\mid{\Phi}\} with {P1PkΦC}\{{P_{1}\otimes\cdots\otimes P_{k}}\mid{\Phi\wedge C}\}. When 𝑷\bm{P} is not naturally ordered, then we will not use indicator functions, see Example 2.6.

aabbccdd12345
(a)
aaC=1C=1bbC=1C=1ccC=1C=1ddC=10C=10
(b)
Figure 2. A graph illustrating Example 4.1 (a) and Example 4.2 (b)
\Description

A graph illustrating Example 4.1 (a) and Example 4.2 (b)

Example 4.1.

Let the EDB and IDB vocabularies be σ={E}\sigma=\{E\} and τ={L}\tau=\{L\}, where EE is binary and LL is unary. Consider the following datalog\text{\sf datalog}^{\circ} program:

(28) L(X) :-\displaystyle L(X)\text{ :- } [X=a]Z(L(Z)E(Z,X))\displaystyle[X=a]\oplus\bigoplus_{Z}\left(L(Z)\otimes E(Z,X)\right)

where aDa\in D is some constant in the domain. We show three different interpretations of the program, over three different naturally ordered semirings. First, we interpret it over the semiring of Booleans. In this case, the program can be written in a more familiar notation:

L(X) :-\displaystyle L(X)\text{ :- } [X=a]01Z(L(Z)E(Z,X))\displaystyle[X=a]_{0}^{1}\vee\exists_{Z}\left(L(Z)\wedge E(Z,X)\right)

This is the reachability program, which computes the set of nodes XX reachable from the node aa. The indicator function [X=a]01[X=a]_{0}^{1} returns 0 or 11, depending on whether XaX\neq a or X=aX=a.

Next, let’s interpret it over Trop+\text{\sf Trop}^{+}. In that case, the indicator function [X=a]0[X=a]_{\infty}^{0} returns \infty when XaX\neq a, and returns 0 when X=aX=a. The program becomes:

L(X) :-\displaystyle L(X)\text{ :- } min((if X=a then 0 else ),minZ(L(Z)+E(Z,X)))\displaystyle\min\left((\texttt{if }X=a\texttt{ then }0\texttt{ else }\infty),\min_{Z}(L(Z)+E(Z,X))\right)

This program solves the Single-Source-Shortest-Path (SSSP) problem with source vertex aa. Consider the graph in Fig. 2(b)(a). The active domain consists of the constants a,b,c,da,b,c,d, and the naïve evaluation algorithm converges after 5 steps, as shown here:

L(a)L(b)L(c)L(d)L(0)L(1)0L(2)015L(3)0149L(4)0148L(5)0148\displaystyle\begin{array}[]{l|c|c|c|c|}\cline{2-5}\cr&L(a)&L(b)&L(c)&L(d)\\ \cline{2-5}\cr L^{(0)}&\infty&\infty&\infty&\infty\\ \cline{2-5}\cr L^{(1)}&0&\infty&\infty&\infty\\ \cline{2-5}\cr L^{(2)}&0&1&5&\infty\\ \cline{2-5}\cr L^{(3)}&0&1&4&9\\ \cline{2-5}\cr L^{(4)}&0&1&4&8\\ \cline{2-5}\cr L^{(5)}&0&1&4&8\\ \cline{2-5}\cr\end{array}

Third, let’s interpret it over Tropp+\text{\sf Trop}^{+}_{p}, defined in Example 2.9. Assume for simplicity that p=1p=1. In that case the program computes, for each node XX, the bag {{l1,l2}}\{\{l_{1},l_{2}\}\} of the lengths of the two shortest paths from aa to XX. The indicator function [X=a][X=a] is equal to {{0,}}\{\{0,\infty\}\} when X=aX=a, and equal to {{,}}\{\{\infty,\infty\}\} otherwise. The reader may check that the program converges to:

L(a)=\displaystyle L(a)= {{0,3}}\displaystyle\{\{0,3\}\} L(b)=\displaystyle L(b)= {{1,4}}\displaystyle\{\{1,4\}\} L(c)=\displaystyle L(c)= {{4,5}}\displaystyle\{\{4,5\}\} L(d)=\displaystyle L(d)= {{8,9}}\displaystyle\{\{8,9\}\}

Finally, we can interpret it over Tropη+\text{\sf Trop}^{+}_{\leq\eta}, the semiring in Example 2.10. In that case the program computes, for each XX, the set of all possible lengths of paths from aa to XX that are no longer than the shortest path plus η\eta.

Example 4.2.

A classic problem that requires the interleaving of recursion and aggregation is the bill-of-material (see, e.g., (DBLP:conf/amw/ZanioloYIDSC18, )), where we are asked to compute, for each part XX, the total cost of XX, of all sub-parts of XX, all sub-sub-parts of XX, etc. The EDB and IDB schemas are σ𝔹={E}\sigma_{\mathbb{B}}=\{E\}, σ={C}\sigma=\{C\}, τ={T}\tau=\{T\}. The relation E(X,Y)E(X,Y) is a standard, Boolean relation, representing the fact that “XX has a subpart YY”; C(X)C(X) is an \mathbb{N}-relation or an \mathbb{R}_{\bot}-relation (to be discussed shortly) representing the cost of XX; and T(X)T(X) is the total cost of XX, that includes the cost of all its (sub-)subparts. The datalog\text{\sf datalog}^{\circ} program is:

T(X) :-\displaystyle T(X)\text{ :- } C(X)+Y{T(Y)E(X,Y)}\displaystyle C(X)+\sum_{Y}\{{T(Y)}\mid{E(X,Y)}\}

When the graph defined by EE is a tree then the program computes correctly the bill-of-material. We are interested, however, in what happens when the graph encoded by EE has cycles, as illustrate with Fig. 2(b)(b). The grounded program is:555Strictly speaking, we should have introduced POPS variables, xT(a),xT(b),x_{T(a)},x_{T(b)},\ldots, but, to reduce clutter, we show here directly the grounded atoms instead of their corresponding POPS variable.

T(a) :-\displaystyle T(a)\text{ :- } C(a)+T(b)+T(c)\displaystyle C(a)+T(b)+T(c)
T(b) :-\displaystyle T(b)\text{ :- } C(b)+T(a)+T(c)\displaystyle C(b)+T(a)+T(c)
T(c) :-\displaystyle T(c)\text{ :- } C(c)+T(d)\displaystyle C(c)+T(d)
T(d) :-\displaystyle T(d)\text{ :- } C(d)\displaystyle C(d)

We consider two choices for the POPS. First, the naturally ordered semiring (,+,,0,1)(\mathbb{N},+,*,0,1). Here the program diverges, since the naïve algorithm will compute ever increasing values for T(a)T(a) and T(b)T(b), which are on a cycle. Second, consider the lifted reals =({},+,,0,1,)\mathbb{R}_{\bot}=(\mathbb{R}\cup\{\bot\},+,*,0,1,\sqsubseteq). Now the program converges in 3 steps, as can be seen below:

T(a)T(b)T(c)T(d)T0T110T21110T31110\displaystyle\begin{array}[]{l|c|c|c|c|}\cline{2-5}\cr&T(a)&T(b)&T(c)&T(d)\\ \cline{2-5}\cr T_{0}&\bot&\bot&\bot&\bot\\ \cline{2-5}\cr T_{1}&\bot&\bot&\bot&10\\ \cline{2-5}\cr T_{2}&\bot&\bot&11&10\\ \cline{2-5}\cr T_{3}&\bot&\bot&11&10\\ \cline{2-5}\cr\end{array}

4.5. Extensions

We discuss here several extensions of datalog\text{\sf datalog}^{\circ} that we believe are needed in a practical implementation.

Case Statements Sum-products can be extended w.l.o.g. to include case statements of the form:

T(x1,,xk)\displaystyle T(x_{1},\ldots,x_{k}) :- case C1:E1;C2:E2;;[ else En]\displaystyle\text{ :- }\texttt{case }C_{1}:E_{1};\ \ \ C_{2}:E_{2};\cdots;[\texttt{ else }E_{n}]

where C1,C2,C_{1},C_{2},\ldots are conditions and E1,E2,E_{1},E_{2},\ldots are sum-product expressions. This can be desugared to a sum-sum-product:

T(x1,,xk)\displaystyle T(x_{1},\ldots,x_{k}) :- {E1C1}{E2¬C1C2}{En¬C1¬C2}\displaystyle\text{ :- }\{{E_{1}}\mid{C_{1}}\}\oplus\{{E_{2}}\mid{\neg C_{1}\wedge C_{2}}\}\oplus\cdots\oplus\{{E_{n}}\mid{\neg C_{1}\wedge\neg C_{2}\cdots}\}

and therefore the least fixpoint semantics and our convergence results in Sec. 5 continue to hold. For example, we may compute the prefix-sum of a vector VV of length 100 as follows:

W(i)\displaystyle W(i) :- case i=0:V(0);i<100:W(i1)+V(i);\displaystyle\text{ :- }\texttt{case }i=0:V(0);\ \ \ \ i<100:W(i-1)+V(i);

Multiple Value Spaces Our discussion so far assumed that all rules in a datalog\text{\sf datalog}^{\circ} program are over a single POPS. In practice one often wants to perform computations over multiple POPS. In that case we need to have some predefined functions mapping between various POPS; if these are monotone, then the least fixpoint semantics still applies, otherwise the program needs to be stratified. We illustrate with an example, which uses two POPS: +\mathbb{R}_{+} and 𝔹\mathbb{B}.

Example 4.3.

We illustrate the company control example from (DBLP:conf/pods/RossS92, , Example 3.2). S(X,Y)=n+S(X,Y)=n\in\mathbb{R}_{+} represents the fact that company XX owns a proportion of nn shares in company YY. We want to compute the predicate C(X,Y)C(X,Y), representing the fact that the company XX controls company YY, where control is defined as follows: XX controls YY if the sum of shares it owns in YY plus the sum of shares in YY owned by companies controlled by XX is >0.5>0.5. The program is adapted directly from (DBLP:conf/pods/RossS92, ):

CV(X,Z,Y) :-\displaystyle CV(X,Z,Y)\text{ :- } [X=Z]S(X,Y)+[C(X,Z)]S(Z,Y)\displaystyle[X=Z]*S(X,Y)+[C(X,Z)]*S(Z,Y)
T(X,Y) :-\displaystyle T(X,Y)\text{ :- } Z{CV(X,Z,Y)Company(Z)}\displaystyle\sum_{Z}\{{CV(X,Z,Y)}\mid{\text{Company}(Z)}\}
C(X,Y) :-\displaystyle C(X,Y)\text{ :- } [T(X,Y)>0.5]\displaystyle[T(X,Y)>0.5]

The value of CV(X,Z,Y)CV(X,Z,Y) is the fraction of shares that XX owns in YY, through its control of company ZZ; when X=ZX=Z then this fraction includes S(X,Y)S(X,Y). The value of T(X,Y)T(X,Y) is the total amount of shares that XX owns in YY. The last rule checks whether this total is >0.5>0.5: in that case, XX controls YY.

The EDB and IDB vocabularies are σ={S}\sigma=\{S\}, σ𝔹={Company}\sigma_{\mathbb{B}}=\{\text{Company}\}, τ={CV,T},τ𝔹={C}\tau=\{CV,T\},\tau_{\mathbb{B}}=\{C\}. The IDBs CV,TCV,T are +\mathbb{R}_{+}-relations, CC is a standard 𝔹\mathbb{B}-relation. The mapping between the two POPS is achieved by the indicator function [Φ]+[\Phi]\in\mathbb{R}_{+}, which returns 0 when the predicate Φ\Phi is false, and 1 otherwise. All rules are monotone, w.r.t. to the natural orders on +\mathbb{R}_{+} and 𝔹\mathbb{B}, and, thus, the least-fixpoint semantics continues to apply to this program. But the results in Sec. 5 apply only to fixpoints of polynomials, while the grounding of our program is no longer a polynomial due to the use of the indicator functions.

Interpreted functions over the key-space A practical language needs to allow interpreted functions over the key space, i.e. the domain DD, as illustrated by this simple example:

Shipping(cid,date+1) :-\displaystyle\texttt{Shipping}(cid,\texttt{date}+1)\text{ :- } Order(cid,date)\displaystyle\texttt{Order}(cid,\texttt{date})

Here date+1\texttt{date}+1 is an interpreted function applied to date. Interpreted functions over DD may cause the active domain to grow indefinitely, leading to divergence; our results in Sec. 5 apply only when the active domain is fixed, enabling us to define the grounding (27) of the datalog\text{\sf datalog}^{\circ} program.

Keys to Values Finally, a useful extension is to allow key values to be used as POPS values, when the types are right. For example, if Length(X,Y,C)\texttt{Length}(X,Y,C) is Boolean relation, where a tuple (X,Y,C)(X,Y,C) represents the fact that there exists a path of length CC from XX to YY, then we can compute the length of the shortest path as the following rule of the tropical semiring Trop+\text{\sf Trop}^{+}:

ShortestLength(X,Y)\displaystyle\texttt{ShortestLength}(X,Y) :- minC([Length(X,Y,C)]0+C)\displaystyle\text{ :- }\min_{C}\left([\texttt{Length}(X,Y,C)]_{\infty}^{0}+C\right)

The key variable CC became an atom over the tropical semiring.

5. Characterizing the Convergence of datalog\text{\sf datalog}^{\circ}

In this section, we prove our main result, Theorem 1.2. As we saw in Sec. 1 (and again in Sec. 4.2), there are five different possibilities for the divergence/convergence of datalog\text{\sf datalog}^{\circ} programs. Our results in this section concern the last three cases, when every datalog\text{\sf datalog}^{\circ} program converges. Recall that by “converge”, we mean that the naïve algorithm terminates in a finite number of steps; we are not interested in “convergence in the limit”.

Throughout this section, we will assume that the datalog\text{\sf datalog}^{\circ} program has been grounded, as in Sec. 4.3, and therefore our task is to study the convergence of a tuple of polynomials, see (27). To reduce clutter when writing polynomials, we will follow the convention in Sec. 2.2 and use the symbols +,+,\cdot instead of ,\oplus,\otimes, while keeping in mind that they represent abstract operations in a POPS.

Consider the following grounded datalog\text{\sf datalog}^{\circ} program, with a single variable xx and a single rule:

(29) x\displaystyle x :- 1+cx\displaystyle\text{ :- }1+cx

We need to compute the least fixpoint of f(x):=1+cxf(x):=1+cx. When the POPS 𝑷\bm{P} is a naturally ordered semiring, then its smallest element is =0\bot=0 and the naïve algorithm computes the sequence:

f(0)(0):=\displaystyle f^{(0)}(0):= 0\displaystyle 0 f(1)(0):=\displaystyle f^{(1)}(0):= 1\displaystyle 1 f(2)(0):=\displaystyle f^{(2)}(0):= 1+c\displaystyle 1+c f(3)(0):=\displaystyle f^{(3)}(0):= 1+c+c2\displaystyle 1+c+c^{2} \displaystyle\ldots f(q)(0):=\displaystyle f^{(q)}(0):= 1+c++cq1\displaystyle 1+c+\cdots+c^{q-1}

If we want every datalog\text{\sf datalog}^{\circ} program to converge on 𝑷\bm{P}, then surely so must our program (29). In essence, the main result in this section is that the converse holds too: if (29) converges on 𝑷\bm{P} for any choice of cc, then every datalog\text{\sf datalog}^{\circ} program converges on 𝑷\bm{P}. For example,  (29) diverges on the semiring \mathbb{N}, because, if c=2c=2, then f(q)(0)=1+2+22++2q1f^{(q)}(0)=1+2+2^{2}+\cdots+2^{q-1}\rightarrow\infty. On the other hand this program converges on the semiring Trop+\text{\sf Trop}^{+} and, therefore, every datalog\text{\sf datalog}^{\circ} program converges on Trop+\text{\sf Trop}^{+}.

In the rest of this section, we prove Theorem 1.2. We start by assuming that the POPS 𝑷\bm{P} is a naturally ordered semiring 𝑺\bm{S}, then extend the result to arbitrary POPS.

5.1. Definition of Stable Semirings

The following notations and simple facts can be found in (semiring_book, ). Fix a semiring 𝑺\bm{S}. For every c𝑺c\in\bm{S} and p0p\geq 0 define:

(30) c(p)=def\displaystyle c^{(p)}\stackrel{{\scriptstyle\text{def}}}{{=}} 1+c+c2++cp\displaystyle 1+c+c^{2}+\cdots+c^{p}
Definition 5.1.

An element c𝐒c\in\bm{S} is pp-stable if c(p)=c(p+1)c^{(p)}=c^{(p+1)}. We say that cc is stable if there exists pp such that cc is pp-stable.

We call the semiring 𝐒\bm{S} stable if every element is stable. We call it uniformly stable if there exists p0p\geq 0 such that every c𝐒c\in\bm{S} is pp-stable; in that case we also call 𝐒\bm{S} a pp-stable semiring.

Note that, an equivalent definition of cc being pp-stable is that

(31) c(p)=c(q)\displaystyle c^{(p)}=c^{(q)} for all q>p,\displaystyle\text{for all }q>p,

this can be seen by induction and from the fact that c(q)=1+cc(q1)c^{(q)}=1+c\cdot c^{(q-1)}.

We recall here a very nice and useful result from (semiring_book, ). A short proof is supplied for completeness.

Proposition 5.2.

If 11 is pp-stable then 𝐒\bm{S} is naturally ordered. In particular, every stable semiring is naturally ordered.

Proof.

If 11 is pp-stable, then 1(p+1)=1(p)1^{(p+1)}=1^{(p)}, which means that 1+1++1(p+1 times)=1++1(p times)1+1+\cdots+1(\mbox{$p+1$ times})=1+\cdots+1(\mbox{$p$ times}), or, in short, p+1=pp+1=p. We prove that, if aSba\preceq_{S}b and bSab\preceq_{S}a hold, then a=ba=b. By definition of S\preceq_{S}, there exist x,yx,y such that a+x=ba+x=b and b+y=ab+y=a. On one hand we have a=b+y=a+x+ya=b+y=a+x+y, which implies a=a+k(x+y)a=a+k(x+y) for every k0k\geq 0, in particular a=a+p(x+y)a=a+p(x+y). On the other hand we have b=a+x=a+k(x+y)+x=a+(k+1)x+kyb=a+x=a+k(x+y)+x=a+(k+1)x+ky. We set k=pk=p and obtain b=a+(p+1)x+py=a+px+py=a+p(x+y)b=a+(p+1)x+py=a+px+py=a+p(x+y) and the latter we have seen is =a=a, proving that a=ba=b. ∎

The converse does not hold in general, for example the semiring \mathbb{N} is naturally ordered but is not stable. However, if 𝑺\bm{S} is both naturally ordered and satisfies the ACC condition (see Sec. 3), then it is also stable. Here, too, the converse fails: Trop+\text{\sf Trop}^{+} is 0-stable, because min(0,x)=0\min(0,x)=0, yet it does not satisfy the ACC condition, e.g. the following is an infinitely ascending chain in Trop+\text{\sf Trop}^{+}: 1>1/2>1/3>1/4>1>1/2>1/3>1/4>\cdots

The case of a 0-stable semiring has been most extensively studied. Such semirings are called simple by Lehmann (DBLP:journals/tcs/Lehmann77, ), are called c-semirings by Kohlas (DBLP:journals/ai/KohlasW08, ), and absorptive by Dannert et al. (DBLP:conf/csl/DannertGNT21, ). In all cases, the authors require 1+a=11+a=1 for all aa (or, equivalently, b+ab=bb+ab=b for all a,ba,b (DBLP:conf/csl/DannertGNT21, )), which is equivalent to stating that aa is 0-stable, and also equivalent to stating that (𝑺,+)(\bm{S},+) is a join-semilattice with maximal element 11. The tropical semiring is such an example; every distributive lattice is also a 0-stable semiring where we set +=+=\vee and =\cdot=\wedge.

We give next two examples of stable semirings. The first one is pp-stable for some p>0p>0 and it is not (p1)(p-1)-stable. The second one is non-uniformly stable. These example are adapted from (semiring_book, ).

Proposition 5.3.

The semiring Tropp+\text{\sf Trop}^{+}_{p} defined in Example 2.9 is pp-stable. Moreover, the bound pp on the stability of Tropp+\text{\sf Trop}^{+}_{p} is tight.

Proof.

Let cTropp+c\in\text{\sf Trop}^{+}_{p}; recall that cc is a bag of p+1p+1 elements in +{}\mathbb{R}_{+}\cup\{\infty\}. For every q1q\geq 1, cqc^{q} consists of the p+1p+1 smallest sums of the form ui1+ui2++uiqu_{i_{1}}+u_{i_{2}}+\cdots+u_{i_{q}}, where each uijcu_{i_{j}}\in c. Furthermore, the value c(q)=1+c+c2++cqc^{(q)}=1+c+c^{2}+\cdots+c^{q} is obtained as follows: (a) consider all sums of up to qq numbers in cc, and (b) retain the smallest p+1p+1 sums, including duplicates. We claim that c(p)=c(p+1)c^{(p)}=c^{(p+1)}. To prove the claim, consider such a sum y=defui0+ui1++uipy\stackrel{{\scriptstyle\text{def}}}{{=}}u_{i_{0}}+u_{i_{1}}+\cdots+u_{i_{p}} in cp+1c^{p+1}. This term is greater than or equal to each of the following p+1p+1 terms: 0, ui0u_{i_{0}}, ui0+ui1u_{i_{0}}+u_{i_{1}}, \ldots, ui0++uip1u_{i_{0}}+\cdots+u_{i_{p-1}}, which are already included in the bags 1,c,c2,,cp1,c,c^{2},\ldots,c^{p}. This proves that every new term in cp+1c^{p+1} is redundant, proving that c(p)=c(p+1)c^{(p)}=c^{(p+1)}.

To show that the bound pp on the stability of Tropp+\text{\sf Trop}^{+}_{p} is tight, it suffices to show that the 1-element 𝟏p={{0,,,}}\bm{1}_{p}=\{\{0,\infty,\dots,\infty\}\} (i.e., pp-times \infty) is not (p1)(p-1)-stable. Indeed, 𝟏pi=𝟏p\bm{1}_{p}^{i}=\bm{1}_{p} for every i1i\geq 1 and 𝟏p+𝟏p1+𝟏p2++𝟏pp1={{0,,0,}}\bm{1}_{p}+\bm{1}_{p}^{1}+\bm{1}_{p}^{2}+\dots+\bm{1}_{p}^{p-1}=\{\{0,\dots,0,\infty\}\} (i.e., pp-times 0) whereas 𝟏p+𝟏p1+𝟏p2++𝟏pp={{0,,0,0}}\bm{1}_{p}+\bm{1}_{p}^{1}+\bm{1}_{p}^{2}+\dots+\bm{1}_{p}^{p}=\{\{0,\dots,0,0\}\} (i.e., p+1p+1-times 0). ∎

Proposition 5.4.

The semiring Tropη+\text{\sf Trop}^{+}_{\leq\eta} defined in Example 2.10 is stable. Moreover, Tropη+\text{\sf Trop}^{+}_{\leq\eta} is not pp-stable for any pp.

Proof.

The proof is similar to that of Prop 5.3. While the elements of Tropp+\text{\sf Trop}^{+}_{p} are bags, those of Tropη+\text{\sf Trop}^{+}_{\leq\eta} are sets. Let cc be an element of Tropη+\text{\sf Trop}^{+}_{\leq\eta}. Then c(q)=1η+c+c2++cqc^{(q)}=1_{\leq\eta}+c+c^{2}+\cdots+c^{q} is obtained as follows: (a) consider all sums of q\leq q numbers; this includes the empty sum, whose value is 0. (b) retain only those sums that are η\leq\eta. If c={0}c=\{0\}, then cc is 0-stable, so assume w.l.o.g. that cc contains some element >0>0. Let x0>0x_{0}>0 be the smallest such element, and let p=ηx0p=\lceil\frac{\eta}{x_{0}}\rceil. We claim that c(p)=c(p+1)c^{(p)}=c^{(p+1)}. To prove the claim, consider a sum of p+1p+1 elements y=xi0++xipy=x_{i_{0}}+\cdots+x_{i_{p}} which belongs to c(p+1)c^{(p+1)} but does not belong to c(p)c^{(p)}. In particular, xij0x_{i_{j}}\neq 0, otherwise we could drop xijx_{i_{j}} from the sum and we had yc(p)y\in c^{(p)}. It follows that y(p+1)x0>ηy\geq(p+1)x_{0}>\eta, which means that yy is not included in c(p+1)c^{(p+1)}. It follows that c(p)=c(p+1)c^{(p)}=c^{(p+1)} as required.

To show that Tropη+\text{\sf Trop}^{+}_{\leq\eta} is not pp-stable for any pp, we assume to the contrary that there does exist pp such that Tropη+\text{\sf Trop}^{+}_{\leq\eta} is pp-stable and derive a contradiction. To this end, choose a+a\in\mathbb{R}_{+} such that 0<a<ηp+10<a<\frac{\eta}{p+1} and let c={a}c=\{a\}. Then we have ci={ia}c^{i}=\{i\cdot a\} for every i1i\geq 1. Recall from Example 2.10 that 𝟏η={0}\bm{1}_{\leq\eta}=\{0\}. Hence, c(p)=𝟏η+c1+c2++cp={0,a,2a,,pa}c^{(p)}=\bm{1}_{\leq\eta}+c^{1}+c^{2}+\dots+c^{p}=\{0,a,2a,\dots,pa\} whereas c(p+1)={0,a,2a,,pa,(p+1)a}c^{(p+1)}=\{0,a,2a,\dots,pa,(p+1)a\}. Indeed, (p+1)ac(p+1)(p+1)a\in c^{(p+1)} because min(c(p+1))=0\min(c^{(p+1)})=0 and (p+1)a<η(p+1)a<\eta due to a<ηp+1a<\frac{\eta}{p+1}. Hence, c(p)c(p+1)c^{(p)}\neq c^{(p+1)}, which contradicts the above assumption that Tropη+\text{\sf Trop}^{+}_{\leq\eta} is pp-stable. ∎

5.2. Convergence in Non-Uniformly Stable Semirings

Let 𝑺\bm{S} be a naturally ordered semiring. Consider a vector-valued function 𝒇\bm{f} with component functions (f1,,fN)(f_{1},\ldots,f_{N}), over variables 𝒙=(x1,,xN)\bm{x}=(x_{1},\ldots,x_{N}). In particular, 𝒇\bm{f} is a map 𝒇:𝑺N𝑺N\bm{f}:\bm{S}^{N}\rightarrow\bm{S}^{N}. Recall that 𝒇\bm{f} is said to be stable if there exists q0q\geq 0 such that 𝒇(q)(𝟎)=𝒇(q+1)(𝟎)\bm{f}^{(q)}(\bm{0})=\bm{f}^{(q+1)}(\bm{0}). If 𝒇\bm{f} was the ICO of a recursion, then being qq-stable means the Naïve algorithm terminates in qq steps. In this section, we prove a result (Theorem 5.10) which essentially says that, if the semiring SS is stable, and if the ICO 𝒇\bm{f} is a vector-valued multi-variate polynomial function in SS, then the Naïve algorithm converges in a finite number of steps. We take the opportunity to develop some terminologies and techniques to prove stronger results in the sections that follow.

The following example illustrates how a univariate quadratic function can be shown to be stable in a stable semiring.666A similar example can be found in (semiring_book, ) where the concept of quasi square root is introduced. However, the formula for the Catalan number cited in the book is incorrect.

Example 5.5.

Consider a single polynomial, i.e. N=1N=1:

(32) f(x)\displaystyle f(x) =b+ax2\displaystyle=b+ax^{2}

Then:

f(0)(0)\displaystyle f^{(0)}(0) =0\displaystyle=0
f(1)(0)\displaystyle f^{(1)}(0) =b\displaystyle=b
f(2)(0)\displaystyle f^{(2)}(0) =b+ab2\displaystyle=b+ab^{2}
f(3)(0)\displaystyle f^{(3)}(0) =b+a(b+ab2)2=b+ab2+2a2b3+a3b4\displaystyle=b+a(b+ab^{2})^{2}=b+ab^{2}+2a^{2}b^{3}+a^{3}b^{4}
f(4)(0)\displaystyle f^{(4)}(0) =b+a(b+ab2+2a2b3+a3b4)2=b+ab2+2a2b3+5a3b4+\displaystyle=b+a(b+ab^{2}+2a^{2}b^{3}+a^{3}b^{4})^{2}=b+ab^{2}+2a^{2}b^{3}+5a^{3}b^{4}+\cdots

(Note that we overloaded notations in the above to make the expressions simpler to parse. We wrote 2ab22ab^{2} to mean abbabba\otimes b\otimes b\oplus a\otimes b\otimes b. In particular, integer coefficients are used to denote repeated summations in the semiring, whose \oplus and \otimes operators are already simplified to ++ and \cdot.) It can be shown by induction that, when qnq\geq n, the coefficient of anbn+1a^{n}b^{n+1} is “stabilized” and it is the Catalan number 1n+1(2nn)\frac{1}{n+1}\binom{2n}{n}:

(33) f(q)(0)\displaystyle f^{(q)}(0) =n=0q1n+1(2nn)anbn+1+n>qλn(q)anbn+1.\displaystyle=\sum_{n=0}^{q}\frac{1}{n+1}\binom{2n}{n}a^{n}b^{n+1}+\sum_{n>q}\lambda_{n}^{(q)}a^{n}b^{n+1}.

The coefficients λn(q)\lambda^{(q)}_{n}\in\mathbb{N} for n>qn>q may not be in their “final form” yet. Now, suppose the element c:=abc:=ab is qq-stable. Then, from identity (33) we can show that ff is also qq-stable. To see this, note that if cc is qq-stable then c(m)=c(q)c^{(m)}=c^{(q)} for any m>qm>q (recall the notation defined in (30)). Thus, for any m>qm>q, a term ambm+1a^{m}b^{m+1} in the expansion of f(q)(0)f^{(q)}(0) will be “absorbed” by the earlier terms:

(34) n=0qanbn+1+ambm+1=b(c(q)+cm)=b(c(m1)+cm)=bc(m)=bc(q)=n=0qanbn+1.\displaystyle\sum_{n=0}^{q}a^{n}b^{n+1}+a^{m}b^{m+1}=b\left(c^{(q)}+c^{m}\right)=b\left(c^{(m-1)}+c^{m}\right)=bc^{(m)}=bc^{(q)}=\sum_{n=0}^{q}a^{n}b^{n+1}.

A simple way to see how the Catalan number shows up is to let qq\to\infty in the formal power series sense  (MR1676282, ). In this case, f(ω)(0)=b+a[f(ω)(0)]2f^{(\omega)}(0)=b+a[f^{(\omega)}(0)]^{2}, which is then solved directly by Newton’s generalized binomial expansion:

(35) f(ω)(0)\displaystyle f^{(\omega)}(0) =12a(114ab)=12a(1n=0(1/2n)(1)nanbn)=n=01n+1(2nn)anbn+1.\displaystyle=\frac{1}{2a}\left(1-\sqrt{1-4ab}\right)=\frac{1}{2a}\left(1-\sum_{n=0}^{\infty}\binom{1/2}{n}(-1)^{n}a^{n}b^{n}\right)=\sum_{n=0}^{\infty}\frac{1}{n+1}\binom{2n}{n}a^{n}b^{n+1}.

Our proof of Theorem 1.2 is based on the two observations in this example. First, we prove in this section that there exists a finite set of monomials, like abab here, whose stability implies the stability of ff. In addition, we prove in the next section that the coefficients, like λn(q)\lambda_{n}^{(q)} above, reach quickly their final values. Notice that, in general, no closed form like (35) exists for f(ω)f^{(\omega)}; for example, if ff has degrees 5\geq 5 then we cannot hope to always obtain such closed form formulas.

We next introduce several notations that we also need in the next section. Given a positive integer kk, a tuple 𝒛=(z1,,zk)\bm{z}=(z_{1},\dots,z_{k}) of symbols or variables, and a tuple 𝒗=(v1,,vk)k\bm{v}=(v_{1},\dots,v_{k})\in\mathbb{N}^{k} of non-negative integers, we denote

(36) 𝒛𝒗\displaystyle{\bm{z}}^{\bm{v}} :=i=1kzivi,\displaystyle:=\prod_{i=1}^{k}z_{i}^{v_{i}},

where the product is the product operator of the semiring under consideration. With this notation, the ii-th component function of a vector-valued polynomial function 𝒇=(f1,,fN)\bm{f}=(f_{1},\dots,f_{N}) can be written in the following form:

(37) fi(𝒙)\displaystyle f_{i}(\bm{x}) =𝒗Viai,𝒗𝒙𝒗,\displaystyle=\sum_{\bm{v}\in V_{i}}a_{i,\bm{v}}\cdot\bm{x}^{\bm{v}},

where the ai,𝒗a_{i,\bm{v}} are constants in the semiring’s domain, and ViV_{i} is a set of length-NN vectors of non-negative integers.

We are interested in the formal expansion of 𝒇(q)(0)\bm{f}^{(q)}(0), in the same way we expressed iterative applications of ff in Example 5.5. The device to express these expansions formally is context-free languages (CFL), as was done in a long history of work in automata theory and formal languages (DBLP:journals/jacm/EsparzaKL10, ; DBLP:conf/lics/HopkinsK99, ).

The non-terminals of the grammar for our CFL consist of all variables (in 𝒙\bm{x}) occurring in 𝒇\bm{f}. Every constant ai,𝒗a_{i,\bm{v}} (shown in (37)) corresponds to a distinct terminal symbol in the grammar. For example, even if ai,𝒗=ai,𝒗a_{i,\bm{v}}=a_{i^{\prime},\bm{v}^{\prime}} for (i,𝒗)(i𝒗)(i,\bm{v})\neq(i^{\prime}\bm{v}^{\prime}), we will consider them different symbols in the symbol set Γ\Gamma of the CFL. Note also that every monomial 𝒙𝒗\bm{x}^{\bm{v}} has a corresponding (symbolic) coefficient ai,𝒗a_{i,\bm{v}}, even if the coefficient is 11. For example 1+x2y1+x^{2}y becomes a+bx2ya+bx^{2}y, with coefficients a=1a=1 and b=1b=1. The production rules are constructed from (37) as follows. For every monomial ai,𝒗𝒙𝒗a_{i,\bm{v}}\bm{x}^{\bm{v}}, with 𝒗=(v1,,vN)Vi\bm{v}=(v_{1},\ldots,v_{N})\in V_{i}, there is a rule:

(38) xi\displaystyle x_{i} ai,𝒗x1x1v1 timesx2x2v2 timesxNxNvN times\displaystyle\to a_{i,\bm{v}}\underbrace{x_{1}\cdots x_{1}}_{v_{1}\text{ times}}\underbrace{x_{2}\cdots x_{2}}_{v_{2}\text{ times}}\dots\underbrace{x_{N}\cdots x_{N}}_{v_{N}\text{ times}}

Given a parse tree TT (from the grammar above), define the yield Y(T)Y(T) of TT to be the product of all terminal symbols at the leaves of TT. For i[N]i\in[N] and a positive integer qq, let 𝒯qi\mathcal{T}^{i}_{q} denote the set of all parse trees of the above grammar, with starting symbol xix_{i}, and depth q\leq q. The following simple but fundamental fact was observed in (DBLP:journals/jacm/EsparzaKL10, ) (for completeness, we include an inductive proof of this fact in the appendix.)

Lemma 5.6 ((DBLP:journals/jacm/EsparzaKL10, )).

Given integers q0q\geq 0 and i[N]i\in[N], the ii-th component of the vector 𝐟(q)(𝟎)\bm{f}^{(q)}(\bm{0}), denoted by (𝐟(q)(0))i(\bm{f}^{(q)}(0))_{i}, can be expressed in terms of the yields of short parse-trees:

(39) (𝒇(q)(0))i\displaystyle(\bm{f}^{(q)}(0))_{i} =T𝒯qiY(T).\displaystyle=\sum_{T\in\mathcal{T}^{i}_{q}}Y(T).
Example 5.7.

Consider the following map 𝒇=(f1,f2)\bm{f}=(f_{1},f_{2}):

(40) [XY][aXY+bY+cuXY+vX+w]\displaystyle\begin{bmatrix}X\\ Y\end{bmatrix}\to\begin{bmatrix}aXY+bY+c\\ uXY+vX+w\end{bmatrix}

Applying the map twice, we obtain

[XY][aXY+bY+cuXY+vX+w][a(aXY+bY+c)(uXY+vX+w)+b(uXY+vX+w)+cu(aXY+bY+c)(uXY+vX+w)+v(aXY+bY+c)+w]\displaystyle\begin{bmatrix}X\\ Y\end{bmatrix}\to\begin{bmatrix}aXY+bY+c\\ uXY+vX+w\end{bmatrix}\to\begin{bmatrix}a(aXY+bY+c)(uXY+vX+w)+b(uXY+vX+w)+c\\ u(aXY+bY+c)(uXY+vX+w)+v(aXY+bY+c)+w\end{bmatrix}

This means the first component of 𝒇(1)(0)\bm{f}^{(1)}(0) is (𝒇(1)(0))1=c(\bm{f}^{(1)}(0))_{1}=c and the first component of 𝒇(2)(0)\bm{f}^{(2)}(0) is (𝒇(2)(0))1=acw+bw+c(\bm{f}^{(2)}(0))_{1}=acw+bw+c. The same result can be obtained via summing up the yields of parse trees of depth 1\leq 1 or 2\leq 2 respectively, of the following grammar, as shown in Fig. 3.

XaXY|bY|c\displaystyle X\to aXY\ |\ bY\ |\ c YuXY|vX|w\displaystyle Y\to uXY\ |\ vX\ |\ w
XXccXXbbYYwwXXaaYYwwXXcc
Figure 3. XX-Parse trees of depth 2\leq 2 for the grammar in Example 5.7
\Description

XX-Parse trees of depth 2\leq 2 for the grammar in Example 5.7

The fact that the symbolic expansions of 𝒇(q)\bm{f}^{(q)} can be expressed in terms of a CFL gives us another advantage: we can make use of Parikh’s theorem (MR209093, ) to further characterize the terms Y(T)Y(T) in expression (39). Note that the yield Y(T)Y(T) can be thought of as a word ww in the CFL, where we “concatenate” (i.e. multiply) all terminal symbols in TT from left to right. Since our multiplicative operator is commutative, only the multiplicities of the symbols matter in differentiating two yields Y(T)Y(T) and Y(T)Y(T^{\prime}). The multiplicities of the symbols are formalized by the Parikh image of the word ww.

More formally, consider our alphabet Σ\Sigma containing all terminal symbols in the CFL. By renaming, we can assume Σ={a1,,aM}\Sigma=\{a_{1},\dots,a_{M}\}, and we write 𝒂=(a1,,aM)\bm{a}=(a_{1},\dots,a_{M}) to denote the vector of all terminal symbols. The Parikh image of a word wΣw\in\Sigma^{*}, denoted by Π(w)\Pi(w), is the vector Π(w)=(k1,,kM)M\Pi(w)=(k_{1},\dots,k_{M})\in\mathbb{N}^{M} where kik_{i} is the number of occurrences of aia_{i} in ww. With this notation, (39) can be expressed as:

(41) (𝒇(q)(𝟎))i\displaystyle(\bm{f}^{(q)}(\bm{0}))_{i} =T𝒯qiY(T)=T𝒯qi𝒂Π(Y(T))\displaystyle=\sum_{T\in\mathcal{T}^{i}_{q}}Y(T)=\sum_{T\in\mathcal{T}^{i}_{q}}\bm{a}^{\Pi(Y(T))}

Parikh’s theorem states that the signatures Π(Y(T))\Pi(Y(T)) in the above expressions have a particular format. In order to state Parikh’s theorem, we need the notion of “semi-linear sets”.

Definition 5.8 (Semi-linear sets).

Given an integer M>0M>0, a set M\mathcal{L}\subseteq\mathbb{N}^{M} is said to be linear if there exist vectors 𝐯0,𝐯1,,𝐯M\bm{v}_{0},\bm{v}_{1},\ldots,\bm{v}_{\ell}\in\mathbb{N}^{M} such that:

=\displaystyle\mathcal{L}= {𝒗0+k1𝒗1++k𝒗k1,,k}\displaystyle\{{\bm{v}_{0}+k_{1}\bm{v}_{1}+\ldots+k_{\ell}\bm{v}_{\ell}}\mid{k_{1},\ldots,k_{\ell}\in\mathbb{N}}\}

A set M\mathcal{L}\subseteq\mathbb{N}^{M} is called semi-linear if it is a finite union of linear sets.

Theorem 5.9 (Parikh’s Theorem (MR209093, )).

Let GG be a context-free grammar with terminal symbols Σ\Sigma, and let L(G)ΣL(G)\subseteq\Sigma^{*} be the language generated by GG. Then Π(L(G))M\Pi(L(G))\subseteq\mathbb{N}^{M} is a semi-linear set.

We now have all the tools to prove the main theorem of this section:

Theorem 5.10.

If the semiring 𝐒\bm{S} is stable, then every polynomial function 𝐟:𝐒N𝐒N\bm{f}:\bm{S}^{N}\rightarrow\bm{S}^{N} is stable.

Proof.

From Parikh’s theorem and identity (41), there is a finite collection 𝒞\mathcal{C}, where every member of 𝒞\mathcal{C} is a tuple of vectors (𝒗0,𝒗1,,𝒗)(M)+1(\bm{v}_{0},\bm{v}_{1},\dots,\bm{v}_{\ell})\in(\mathbb{N}^{M})^{\ell+1} (tuples in 𝒞\mathcal{C} may have different lengths +1\ell+1), satisfying the following condition. For every parse-tree T𝒯qiT\in\mathcal{T}^{i}_{q}, there exists (𝒗0,𝒗1,,𝒗)𝒞(\bm{v}_{0},\bm{v}_{1},\dots,\bm{v}_{\ell})\in\mathcal{C}, and a coefficient vector (k1,,k)(k_{1},\dots,k_{\ell})\in\mathbb{N}^{\ell} for which

(42) Y(T)=𝒂Π(Y(T))=𝒂𝒗0i=1(𝒂𝒗i)ki\displaystyle Y(T)=\bm{a}^{\Pi(Y(T))}=\bm{a}^{\bm{v}_{0}}\prod_{i=1}^{\ell}(\bm{a}^{\bm{v}_{i}})^{k_{i}}

Conversely, for every tuple (𝒗0,𝒗1,,𝒗)𝒞(\bm{v}_{0},\bm{v}_{1},\dots,\bm{v}_{\ell})\in\mathcal{C} and every coefficient vector (k1,,k)(k_{1},\dots,k_{\ell}) there exists a parse-tree TT in some 𝒯qi\mathcal{T}_{q}^{i} for which the identity holds.

Our proof strategy is as follows. We shall define below a finite set BMB\subseteq\mathbb{N}^{M} of exponent vectors and express fi(q)(0)f^{(q)}_{i}(0) by grouping the terms 𝒂𝒗\bm{a}^{\bm{v}} in (41) that have the same exponent vector 𝒗M\bm{v}\in\mathbb{N}^{M}:

(43) (𝒇(q)(𝟎))i\displaystyle(\bm{f}^{(q)}(\bm{0}))_{i} =𝒗Bλ𝒗(q)𝒂𝒗+𝒘Bλ𝒘(q)𝒂𝒘,\displaystyle=\sum_{\bm{v}\in B}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}}+\sum_{\bm{w}\notin B}\lambda^{(q)}_{\bm{w}}\bm{a}^{\bm{w}},

where the coefficients λ𝒗(q)\lambda_{\bm{v}}^{(q)} are integers that may change over time as qq increases:

(44) λ𝒗(q)=|{T𝒯qi:Π(Y(T))=𝒗}|.\displaystyle\lambda^{(q)}_{\bm{v}}=|\{T\in\mathcal{T}^{i}_{q}:\Pi(Y(T))=\bm{v}\}|.

Here, for an element sSs\in S, and a positive integer λ\lambda\in\mathbb{N}, we write λs\lambda s to mean s+s++ss+s+\dots+s, λ\lambda times. In particular, this multiplication of λ\lambda and ss should not be confused with the multiplications of symbols in 𝒂\bm{a} which are done over the multiplicative operator of the semiring. We then prove two claims, for sufficiently large qq the following hold:

  • Claim 1 the coefficients λ𝒗(q)\lambda^{(q)}_{\bm{v}}\in\mathbb{N} for 𝒗B\bm{v}\in B no longer change (they “converge”)

  • Claim 2 for every 𝒘B\bm{w}\notin B, we have

    (45) 𝒗Bλ𝒗(q)𝒂𝒗+𝒂𝒘=𝒗Bλ𝒗(q)𝒂𝒗\displaystyle\sum_{\bm{v}\in B}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}}+\bm{a}^{\bm{w}}=\sum_{\bm{v}\in B}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}}

These two claims together show that 𝒇\bm{f} is stable: (𝒇(q)(𝟎))i=𝒗Bλ𝒗(q)𝒂𝒗(\bm{f}^{(q)}(\bm{0}))_{i}=\sum_{\bm{v}\in B}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}} for large qq.

We start by defining the set BB. Fix a sufficiently large integer pp to be defined later. Define BB to be: 777Given a vector 𝒙=(x1,,xd)d\bm{x}=(x_{1},\ldots,x_{d})\in\mathbb{N}^{d} for some constant dd, we use 𝒙\|\bm{x}\|_{\infty} to denote maxi[d]xi\max_{i\in[d]}x_{i} and 𝒙1\|\bm{x}\|_{1} to denote i[d]xi\sum_{i\in[d]}x_{i}.

(46) B\displaystyle B :={𝒗0+k1𝒗1++k𝒗|(𝒗0,,𝒗)𝒞 and 𝒌=(k1,,k) where 𝒌p}\displaystyle:=\{\bm{v}_{0}+k_{1}\bm{v}_{1}+\cdots+k_{\ell}\bm{v}_{\ell}\ |\ (\bm{v}_{0},\dots,\bm{v}_{\ell})\in\mathcal{C}\text{ and }\bm{k}=(k_{1},\dots,k_{\ell})\in\mathbb{N}^{\ell}\text{ where }\|\bm{k}\|_{\infty}\leq p\}

To prove Claim 1, note that, if the parse tree TT has depth hh, then Π(Y(T))1h\|\Pi(Y(T))\|_{1}\geq h. Consequently, all parse trees whose depths are strictly greater than max𝒗B𝒗1\max_{\bm{v}\in B}\|\bm{v}\|_{1} can no longer contribute to increasing λ𝒗(q)\lambda^{(q)}_{\bm{v}} with 𝒗B\bm{v}\in B; thus, these coefficients converge after iteration number max𝒗B𝒗1\max_{\bm{v}\in B}\|\bm{v}\|_{1}. This is a finite number because (46) implies:

(47) max𝒗B𝒗1max(𝒗0,,𝒗)𝒞(1+p)maxi{0,,}𝒗i1\displaystyle\max_{\bm{v}\in B}\|\bm{v}\|_{1}\leq\max_{(\bm{v}_{0},\dots,\bm{v}_{\ell})\in\mathcal{C}}(1+p\cdot\ell)\max_{i\in\{0,\ldots,\ell\}}\|\bm{v}_{i}\|_{1}

Claim 2 is proved as follows. Given 𝒘B\bm{w}\notin B, as mentioned above, from Parikh’s theorem we know there exists (𝒗0,,𝒗)𝒞(\bm{v}_{0},\dots,\bm{v}_{\ell})\in\mathcal{C} and 𝒌\bm{k}\in\mathbb{N}^{\ell} (but 𝒌>p\|\bm{k}\|_{\infty}>p) such that 𝒘=𝒗0+k1𝒗1++k𝒗\bm{w}=\bm{v}_{0}+k_{1}\bm{v}_{1}+\cdots+k_{\ell}\bm{v}_{\ell}. Rewrite the monomial 𝒂𝒘\bm{a}^{\bm{w}} from the “basis” (𝒗0,,v)(\bm{v}_{0},\dots,v_{\ell}) by:

𝒂𝒘=𝒂𝒗0(𝒂𝒗1)k1(𝒂𝒗)k=m0m1k1mk,\bm{a}^{\bm{w}}=\bm{a}^{\bm{v}_{0}}(\bm{a}^{\bm{v}_{1}})^{k_{1}}\cdots(\bm{a}^{\bm{v}_{\ell}})^{k_{\ell}}=m_{0}m_{1}^{k_{1}}\cdots m_{\ell}^{k_{\ell}},

where to simplify notations we define the monomials mi:=𝒂𝒗im_{i}:=\bm{a}^{\bm{v}_{i}}.

First, let’s assume for simplicity that only one of the kik_{i} is more than pp. Without loss of generality, assume k>pk_{\ell}>p. Then, as long as pp is at least the stability index of mm_{\ell}, thanks to (31) we have

i=0pm0m1k1m1k1mi+m0m1k1mk\displaystyle\sum_{i=0}^{p}m_{0}m_{1}^{k_{1}}\cdots m_{\ell-1}^{k_{\ell-1}}m_{\ell}^{i}+m_{0}m_{1}^{k_{1}}\cdots m_{\ell}^{k_{\ell}} =m0m1k1m1k1m(p)+m0m1k1mk\displaystyle=m_{0}m_{1}^{k_{1}}\cdots m_{\ell-1}^{k_{\ell-1}}m_{\ell}^{(p)}+m_{0}m_{1}^{k_{1}}\cdots m_{\ell}^{k_{\ell}}
=m0m1k1m1k1m(k1)+m0m1k1mk\displaystyle=m_{0}m_{1}^{k_{1}}\cdots m_{\ell-1}^{k_{\ell-1}}m_{\ell}^{(k_{\ell}-1)}+m_{0}m_{1}^{k_{1}}\cdots m_{\ell}^{k_{\ell}}
=m0m1k1m1k1m(k)\displaystyle=m_{0}m_{1}^{k_{1}}\cdots m_{\ell-1}^{k_{\ell-1}}m_{\ell}^{(k_{\ell})}
=m0m1k1m1k1m(p)\displaystyle=m_{0}m_{1}^{k_{1}}\cdots m_{\ell-1}^{k_{\ell-1}}m_{\ell}^{(p)}
=i=0pm0m1k1m1k1mi.\displaystyle=\sum_{i=0}^{p}m_{0}m_{1}^{k_{1}}\cdots m_{\ell-1}^{k_{\ell-1}}m_{\ell}^{i}.

In particular, the term 𝒂𝒘\bm{a}^{\bm{w}} is “absorbed” by the sum of terms of the form 𝒂𝒗=m0m1k1m1k1mi\bm{a}^{\bm{v}}=m_{0}m_{1}^{k_{1}}\cdots m_{\ell-1}^{k_{\ell-1}}m_{\ell}^{i} for ipi\leq p. Since all such 𝒗\bm{v} are in BB (because kipk_{i}\leq p for all i<i<\ell), we have just proved (45) for this simple case of 𝒘\bm{w}.

Second, when more than one of the kik_{i} is greater than pp, we can w.l.o.g. assume k>pk_{\ell}>p. The above reasoning shows that the term 𝒂𝒘\bm{a}^{\bm{w}} is “absorbed” by the sum of terms 𝒂𝒗\bm{a}^{\bm{v}} where 𝒗\bm{v} has one less ki>pk_{i}>p. By induction it follows that all of them will be absorbed by the sum 𝒗B𝒂𝒗\sum_{\bm{v}\in B}\bm{a}^{\bm{v}}. ∎

5.3. Convergence in Uniformly Stable Semirings

We consider the next case, when the semiring 𝑺\bm{S} is uniformly stable, in other words there exists p0p\geq 0 such that every element in 𝑺\bm{S} is pp-stable. In this case, we can strengthen Theorem 5.10 and prove a tighter upper bound on the number of steps needed for convergence. We say that the polynomial function 𝒇:𝑺N𝑺N\bm{f}:\bm{S}^{N}\rightarrow\bm{S}^{N} is linear if every monomial (8) has total degree 1\leq 1. The main theorem (Theorem 5.12) is proved via proving a 11-dimensional version of it, which is then generalized to NN dimensions by applying Theorem 3.4. A univariate polynomial is of the following form:

(48) f(x)=def\displaystyle f(x)\stackrel{{\scriptstyle\text{def}}}{{=}} a0+a1x+a2x2++anxn\displaystyle a_{0}+a_{1}x+a_{2}x^{2}+\cdots+a_{n}x^{n}

The following lemma generalizes special cases studied by Gondran (DBLP:journals/dm/Gondran79, ; semiring_book, ).

Lemma 5.11.

Let 𝐒\bm{S} be a pp-stable semiring and let ff be a univariate polynomial (48). Then: (a) If p=0p=0 then ff is 11-stable; (b) If ff is linear, then it is p+1p+1-stable; (c) In general, ff is p+2p+2-stable.

Proving the lemma will be the bulk of work in this section. Before doing so, let us state and prove the main theorem of the section, concerning the NN-dimensional case.

Theorem 5.12.

Assume that the semiring 𝐒\bm{S} is pp-stable, and let 𝐟:𝐒N𝐒N\bm{f}:\bm{S}^{N}\rightarrow\bm{S}^{N} be a polynomial function. Then:

  1. (1)

    The function 𝒇\bm{f} is i=1N(p+2)i\sum_{i=1}^{N}(p+2)^{i}-stable; if 𝒇\bm{f} is linear, then it is i=1N(p+1)i\sum_{i=1}^{N}(p+1)^{i}-stable.

  2. (2)

    If p=0p=0, then the function 𝒇\bm{f} is NN-stable.

Proof.

To prove item (1), consider the c-clone of polynomial functions. By Lemma 5.11, each univariate polynomial is p+2p+2-stable, and therefore Theorem 3.4 implies that every polynomial function SNSNS^{N}\rightarrow S^{N} is i=1,N(p+2)i\sum_{i=1,N}(p+2)^{i}-stable. If 𝒇\bm{f} is linear, then we consider the c-clone of linear functions, and derive similarly that 𝒇\bm{f} is i=1,N(p+1)i\sum_{i=1,N}(p+1)^{i}-stable.

For item (2), when p=0p=0, consider the expansion of (𝒇(q)(𝟎))i(\bm{f}^{(q)}(\bm{0}))_{i} shown in (41). We will prove that, when q>Nq>N, all parse trees T𝒯qi𝒯NiT\in\mathcal{T}^{i}_{q}-\mathcal{T}^{i}_{N} are “absorbed” by those in 𝒯Ni\mathcal{T}^{i}_{N}:

(49) (𝒇(q)(𝟎))i\displaystyle(\bm{f}^{(q)}(\bm{0}))_{i} =T𝒯qiY(T)=T𝒯NiY(T)=(𝒇(N)(𝟎))i\displaystyle=\sum_{T\in\mathcal{T}^{i}_{q}}Y(T)=\sum_{T\in\mathcal{T}^{i}_{N}}Y(T)=(\bm{f}^{(N)}(\bm{0}))_{i} when qN\displaystyle\text{ when }q\geq N

To see this, consider a parse tree T𝒯qi𝒯NiT\in\mathcal{T}^{i}_{q}-\mathcal{T}^{i}_{N}. Since its depth is >N>N, there is a path from the root to a leaf containing a repeated variable symbol, say xjx_{j} for some j[N]j\in[N]. Let ww be the word that the lower copy of xjx_{j} derives, then the higher copy of xjx_{j} derives some word of the form uwvuwv, and the tree derives the word Y(T)=auwvbY(T)=auwvb for some words a,ba,b. Let TT^{\prime} be the tree obtained from TT by replacing the derivation of the higher-copy of xjx_{j} with the derivation of the lower copy of xjx_{j}. Then, Y(T)=awbY(T^{\prime})=awb. Now, since p=0p=0, we have Y(T)+Y(T)=awb+auwvb=awb(1+uv)=awb=Y(T)Y(T^{\prime})+Y(T)=awb+auwvb=awb(1+uv)=awb=Y(T^{\prime}). Repeating this process, by induction it follows that Y(T)Y(T) is absorbed by T𝒯NiY(T)\sum_{T\in\mathcal{T}^{i}_{N}}Y(T). ∎

In the rest of this section, we prove the main Lemma 5.11.

Proof of Lemma 5.11.

To prove (a), we recall that in a 0-stable semiring, 1+c=11+c=1 for every cSc\in S. If ff is the polynomial in Eq. (48), then we have f(1)(0)=a0f^{(1)}(0)=a_{0}, and ff is 11-stable because

f(2)(0)=a0+i=1na0iai=a0(1+i=1,na0i1ai)=a01=a0=f(1)(0).f^{(2)}(0)=a_{0}+\sum_{i=1}^{n}a_{0}^{i}a_{i}=a_{0}\left(1+\sum_{i=1,n}a_{0}^{i-1}a_{i}\right)=a_{0}1=a_{0}=f^{(1)}(0).

To prove (b), note that linearity means f(x)=a0+a1xf(x)=a_{0}+a_{1}x, and f(n+1)(0)=a0+a1a0+a12a0++a1na0=a1(n)a0,f^{(n+1)}(0)=a_{0}+a_{1}a_{0}+a_{1}^{2}a_{0}+\cdots+a_{1}^{n}a_{0}=a_{1}^{(n)}a_{0}, which implies f(p+1)(0)=f(p+2)(0)f^{(p+1)}(0)=f^{(p+2)}(0) since a1a_{1} is pp-stable.

Part (c) is the most interesting result. Our strategy follows that of the proof of Theorem 5.10. We start by writing an expansion of ff as was done in (41) and the regrouping (43):

(50) f(q)(0)\displaystyle f^{(q)}(0) =T𝒯qY(T)=T𝒯q𝒂Π(Y(T))=𝒗Bλ𝒗(q)𝒂𝒗+𝒘Bλ𝒘(q)𝒂𝒘,\displaystyle=\sum_{T\in\mathcal{T}_{q}}Y(T)=\sum_{T\in\mathcal{T}_{q}}\bm{a}^{\Pi(Y(T))}=\sum_{\bm{v}\in B}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}}+\sum_{\bm{w}\notin B}\lambda^{(q)}_{\bm{w}}\bm{a}^{\bm{w}},

The main difference is that in the CFL for the function (48), the terminal set is Σ={a0,,an}\Sigma=\{a_{0},\dots,a_{n}\}; and, there is only one variable, so we remove the index ii from (41): 𝒯q\mathcal{T}_{q} is the set of all parse trees of depth at most qq, whose root is xx.

The exponent set BB is defined in exactly the same way as that in (46). However, taking advantage of the fact that ff in (48) is univariate, we show in Proposition 5.13 below that the collection 𝒞\mathcal{C} has only one specific tuple of vectors (𝒗0,𝒗1,,𝒗n)(\bm{v}_{0},\bm{v}_{1},\dots,\bm{v}_{n}) (defined in (52)). In particular,

(51) B\displaystyle B :={𝒗0+k1𝒗1++kn𝒗n|𝒌=(k1,,kn)n where 𝒌p}\displaystyle:=\{\bm{v}_{0}+k_{1}\bm{v}_{1}+\cdots+k_{n}\bm{v}_{n}\ |\ \bm{k}=(k_{1},\dots,k_{n})\in\mathbb{N}^{n}\text{ where }\|\bm{k}\|_{\infty}\leq p\}

Finally, to show that ff has stability p+2p+2, we prove in Proposition 5.14 below that the sum 𝒗Bλ𝒗(q)𝒂𝒗\sum_{\bm{v}\in B}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}} is “finalized” (unchanged) when qp+2q\geq p+2. The fact that the remaining coefficients λ𝒘(q)\lambda^{(q)}_{\bm{w}}, 𝒘B\bm{w}\notin B, are absorbed by the sum over BB was shown in (45). The lemma is thus proved, modulo the proofs of the promised propositions below. ∎

The following proposition is a specialization of Parikh’s theorem to the particular grammar arising from the polynomial (48).

Proposition 5.13.

Define the following vectors in n+1\mathbb{N}^{n+1}:

(52) 𝒗0=(1,0,,0)\displaystyle\bm{v}_{0}=(1,0,\dots,0) 𝒗i=(i1,0,,0,1,0,0)\displaystyle\bm{v}_{i}=(i-1,0,\dots,0,1,0,\dots 0) i[n].\displaystyle i\in[n].

Let 𝒯\mathcal{T} be the set of all parse trees for the CFG defined for the polynomial (48), then the Parikh’s images of their yields can be characterized precisely by:

(53) {Π(Y(T))|T𝒯}\displaystyle\{\Pi(Y(T))\ |\ T\in\mathcal{T}\} ={𝒗0+k1𝒗1++kn𝒗n|𝒌n}\displaystyle=\{\bm{v}_{0}+k_{1}\bm{v}_{1}+\cdots+k_{n}\bm{v}_{n}\ |\ \bm{k}\in\mathbb{N}^{n}\}
Proof.

For the forward direction, let TT be any parse tree of the grammar. Let kik_{i} denote the number of derivation rules of the form xaixxx\to a_{i}x\cdots x (xx occurs ii times on the RHS) that were used in the tree. Since each such rule produces one copy of aia_{i} in the yield Y(T)Y(T), it follows that Π(Y(T))=(k0,k1,,kn)\Pi(Y(T))=(k_{0},k_{1},\dots,k_{n}). The numbers kik_{i} are related to one another tightly. Consider the sub-tree of TT containing only the internal nodes (i.e. nodes corresponding to xx, not the terminal symbols), then this sub-tree has exactly k0+i=1nkik_{0}+\sum_{i=1}^{n}k_{i} nodes and i=1niki\sum_{i=1}^{n}ik_{i} edges. In a tree, the number of edges is 11 less than the number of nodes. Hence, k0=1+i=1n(i1)kik_{0}=1+\sum_{i=1}^{n}(i-1)k_{i}, which implies Π(Y(T))=𝒗0+i=1nki𝒗i\Pi(Y(T))=\bm{v}_{0}+\sum_{i=1}^{n}k_{i}\bm{v}_{i}.

For the backward direction, consider an arbitrary vector 𝒌=(k1,,kn)n\bm{k}=(k_{1},\dots,k_{n})\in\mathbb{N}^{n}. We show that we can construct a parse-tree TT whose yield satisfies Π(Y(T))=𝒗0+i=1nki𝒗i\Pi(Y(T))=\bm{v}_{0}+\sum_{i=1}^{n}k_{i}\bm{v}_{i}. We prove this by induction on 𝒌1\|\bm{k}\|_{1}. The base case when 𝒌1=0\|\bm{k}\|_{1}=0 is trivial: the parse tree represents a single rule xa0x\to a_{0}. Consider 𝒌1>0\|\bm{k}\|_{1}>0, and assume ki>0k_{i}>0. Let 𝒌=(k1,,kn)\bm{k}^{\prime}=(k^{\prime}_{1},\dots,k^{\prime}_{n}) be the vector defined by kj=kjk^{\prime}_{j}=k_{j} when jij\neq i, and ki=ki1k^{\prime}_{i}=k_{i}-1. Then, by the induction hypothesis there is a parse tree TT^{\prime} where Π(Y(T))=𝒗0+j=1nkj𝒗j\Pi(Y(T^{\prime}))=\bm{v}_{0}+\sum_{j=1}^{n}k^{\prime}_{j}\bm{v}_{j}. The parse-tree TT^{\prime} must have used at least one rule of the form xa0x\to a_{0} (otherwise the tree is infinite). Construct the tree TT from TT^{\prime} by replacing the rule xa0x\to a_{0} with xaixxx\to a_{i}x\cdots x; and then each of the ii new xx-nodes derives a0a_{0}. Then, it is trivial to verify that Π(Y(T))=𝒗0+j=1nkj𝒗j\Pi(Y(T))=\bm{v}_{0}+\sum_{j=1}^{n}k_{j}\bm{v}_{j}. ∎

Proposition 5.14.

After iteration qp+2q\geq p+2, the sum 𝐯Bλ𝐯(q)𝐚𝐯\sum_{\bm{v}\in B}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}} in (50) remains unchanged.

Proof.

Partition BB into two sets B=B1B2B=B_{1}\cup B_{2}:

(54) B1\displaystyle B_{1} :={𝒗0+k1𝒗1++kn𝒗n|𝒌=(k1,,kn)n where 𝒌p and 𝒌1p}\displaystyle:=\{\bm{v}_{0}+k_{1}\bm{v}_{1}+\cdots+k_{n}\bm{v}_{n}\ |\ \bm{k}=(k_{1},\dots,k_{n})\in\mathbb{N}^{n}\text{ where }\|\bm{k}\|_{\infty}\leq p\text{ and }\|\bm{k}\|_{1}\leq p\}
(55) B2\displaystyle B_{2} :={𝒗0+k1𝒗1++kn𝒗n|𝒌=(k1,,kn)n where 𝒌p and 𝒌1>p}\displaystyle:=\{\bm{v}_{0}+k_{1}\bm{v}_{1}+\cdots+k_{n}\bm{v}_{n}\ |\ \bm{k}=(k_{1},\dots,k_{n})\in\mathbb{N}^{n}\text{ where }\|\bm{k}\|_{\infty}\leq p\text{ and }\|\bm{k}\|_{1}>p\}

Note that the condition 𝒌p\|\bm{k}\|_{\infty}\leq p in the definition of B1B_{1} is redundant (because 𝒌1p\|\bm{k}\|_{1}\leq p implies 𝒌p\|\bm{k}\|_{\infty}\leq p), but we left it there to mirror precisely the definition of BB in (51).

Recall from (44) that λ𝒗(q)\lambda^{(q)}_{\bm{v}} is the number of parse trees T𝒯qT\in\mathcal{T}_{q} where Π(Y(T))=𝒗\Pi(Y(T))=\bm{v}; furthermore, if 𝒗=𝒗0+i=1nki𝒗i\bm{v}=\bm{v}_{0}+\sum_{i=1}^{n}k_{i}\bm{v}_{i}, then 𝒌1depth(T)\|\bm{k}\|_{1}\geq\textsf{depth}(T), because 𝒌1\|\bm{k}\|_{1} is the number of internal nodes of the tree, which is at least its depth. Hence, when 𝒗B1\bm{v}\in B_{1}, only trees of depth 𝒌1p\leq\|\bm{k}\|_{1}\leq p can contribute to increasing λ𝒗(q)\lambda^{(q)}_{\bm{v}}. In other words, these coefficients are fixed after iteration pp.

It remains to show that the sum 𝒗B2λ𝒗(q)𝒂𝒗\sum_{\bm{v}\in B_{2}}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}} is fixed after iteration qp+2q\geq p+2. To this end, note the following. For any element ss in a pp-stable semiring, and any positive integer λp+1\lambda\geq p+1, we have

λs:=s+s++sλ times=(1+1++1)s=(1+1+12+1λ1)s=1(λ1)s=1(p)s=(p+1)s\lambda s:=\underbrace{s+s+\cdots+s}_{\lambda\text{ times}}=(1+1+\dots+1)s=(1+1+1^{2}\dots+1^{\lambda-1})s=1^{(\lambda-1)}s=1^{(p)}s=(p+1)s

In particular, the sum that we want to hold fixed can be written as

(56) 𝒗B2λ𝒗(q)𝒂𝒗\displaystyle\sum_{\bm{v}\in B_{2}}\lambda^{(q)}_{\bm{v}}\bm{a}^{\bm{v}} =𝒗B2min{λ𝒗(q),p+1}𝒂𝒗\displaystyle=\sum_{\bm{v}\in B_{2}}\min\{\lambda^{(q)}_{\bm{v}},p+1\}\bm{a}^{\bm{v}}

It is thus sufficient to prove that, for any 𝒗B2\bm{v}\in B_{2}, we have λ𝒗(q)p+1\lambda_{\bm{v}}^{(q)}\geq p+1 after iteration qp+2q\geq p+2. We will prove something a little stronger:

Claim: for any 𝒗=𝒗0+iki𝒗iB2\bm{v}=\bm{v}_{0}+\sum_{i}k_{i}\bm{v}_{i}\in B_{2}, we have λ𝒗(𝒌+2)𝒌1\lambda_{\bm{v}}^{(\|\bm{k}\|_{\infty}+2)}\geq\|\bm{k}\|_{1}; namely, there are at least 𝒌1\|\bm{k}\|_{1} many parse trees TT with depth at most 2+𝒌2+\|\bm{k}\|_{\infty} and whose Parikh’s image is Π(Y(T))=𝒗\Pi(Y(T))=\bm{v}.

The claim implies what we desire, because for any 𝒗B2\bm{v}\in B_{2}, λ𝒗(p+2)λ𝒗(𝒌+2)𝒌1p+1\lambda^{(p+2)}_{\bm{v}}\geq\lambda^{(\|\bm{k}\|_{\infty}+2)}_{\bm{v}}\geq\|\bm{k}\|_{1}\geq p+1.

We prove the claim by induction on 𝒌\|\bm{k}\|_{\infty}. Consider the base case when 𝒌=1\|\bm{k}\|_{\infty}=1. Let J:={j[n]|kj=1}J:=\{j\in[n]\ |\ k_{j}=1\} and i=max{j|jJ}i=\max\{j\ |\ j\in J\}. We construct parse trees by stitching together the rules (i.e. sub-trees) xajxxx\to a_{j}x\dots x for jJj\in J, and fill up the leaves with xa0x\to a_{0} rules. At the root of the tree, we will apply xaixxx\to a_{i}x\dots x for maximum flexibility, where there are ii xx-nodes to fit the other |J|1|J|-1 rules in. Clearly, there are (i|J|1)((|J|1)!)|J|𝒌1\binom{i}{|J|-1}((|J|-1)!)\geq|J|\geq\|\bm{k}\|_{1} distinct trees that can be constructed this way.

For the inductive step, assume 𝒌>1\|\bm{k}\|_{\infty}>1. Similar to the base case, define J:={j[n]|kj=𝒌}J:=\{j\in[n]\ |\ k_{j}=\|\bm{k}\|_{\infty}\} and i=max{j|jJ}i=\max\{j\ |\ j\in J\}. Let 𝒌\bm{k}^{\prime} be the vector obtained from 𝒌\bm{k} by lowering each kjk_{j} by 11, for jJj\in J; namely, define kj=min{kj,𝒌1}k^{\prime}_{j}=\min\{k_{j},\|\bm{k}\|_{\infty}-1\}. Then, by the induction hypothesis, there are at least 𝒌1\|\bm{k}^{\prime}\|_{1} parse trees TT^{\prime} for which Π(Y(T))=𝒗0+k𝒗\Pi(Y(T^{\prime}))=\bm{v}_{0}+\sum_{\ell}k^{\prime}_{\ell}\bm{v}_{\ell}. From each of these TT^{\prime}, we construct our tree TT by stitching together TT^{\prime} and the rules (i.e. sub-trees) xajxxx\to a_{j}x\dots x, jJj\in J. (Implicitly, xx-leaves are filled up with xa0x\to a_{0} rules.) For the root of TT we use the rule xaixxx\to a_{i}x\dots x. There are ii sub-tree slots to fill, where we can use |J|1|J|-1 sub-trees of the form xajxxx\to a_{j}x\dots x, jJ{i}j\in J-\{i\}, and TT^{\prime}, for a total of |J||J| subtrees. (Note that |J|i|J|\leq i, and thus we have more slots than sub-trees.)

If i2i\geq 2, then the total number of trees that can be obtained this way is 888Note that TT^{\prime} is distinct from any of the trees xajxxx\to a_{j}x\ldots x for jJij\in J-{i} because it has a different signature: TT^{\prime} contains at least two internal nodes of the form xaxxx\to a_{\ell}x\cdots x for >0\ell>0 due to the fact that 𝒌<𝒌1\|\bm{k}\|_{\infty}<\|\bm{k}\|_{1}.

(57) 𝒌1(i|J|)(|J|)!\displaystyle\|\bm{k}^{\prime}\|_{1}\binom{i}{|J|}(|J|)! (𝒌1|J|)i(𝒌1i)i𝒌1\displaystyle\geq(\|\bm{k}\|_{1}-|J|)i\geq(\|\bm{k}\|_{1}-i)i\geq\|\bm{k}\|_{1} as desired.

If i=1i=1, we have to do a bit of extra work. The total number of trees TT constructed above is only 𝒌1=𝒌11\|\bm{k}^{\prime}\|_{1}=\|\bm{k}\|_{1}-1, because the root xa1xx\to a_{1}x has only one slot to fill TT^{\prime} in. Let’s refer to this set as U1U_{1}. We construct another set U2U_{2} of trees by letting TT^{\prime} be at the top, and find a slot to fit the sub-tree xa1xx\to a_{1}x in.

We refer to a node xaxxx\to a_{\ell}x\dots x of a parse-tree as an \ell-node. Since 𝒌p\|\bm{k}\|_{\infty}\leq p and 𝒌1>p\|\bm{k}\|_{1}>p, there must be some >1\ell>1 for which k>0k_{\ell}>0. In particular, there must be a sub-tree of TT^{\prime} whose root node is an \ell-node with >1\ell>1. In TT^{\prime}, find the left most such \ell-node, and the left most 0-node (xa0x\to a_{0}) below it. Replace the xa0x\to a_{0} rule with xa1xa1a0x\to a_{1}x\to a_{1}a_{0} sub-tree. This way of construction gives us the second set U2U_{2} of trees TT for which Π(Y(T))=𝒗\Pi(Y(T))=\bm{v}. We know |U1|=|U2|𝒌11|U_{1}|=|U_{2}|\geq\|\bm{k}\|_{1}-1. Furthermore, there must be at least one tree in U1U_{1} that is not in U2U_{2}, because the tree TT in U1U_{1} with the longest path containing consecutive 11-nodes from the root is not in U2U_{2}. Thus |U1U2|𝒌1|U_{1}\cup U_{2}|\geq\|\bm{k}\|_{1}, and the proof is complete. ∎

Example 5.15.

Assume a semiring that is 11-stable, and let f(x)=a0+a2x2+a3x3+a4x4f(x)=a_{0}+a_{2}x^{2}+a_{3}x^{3}+a_{4}x^{4}. Then:

f(0)(0)=\displaystyle f^{(0)}(0)= 0\displaystyle 0 f(1)(0)=\displaystyle f^{(1)}(0)= a0\displaystyle a_{0} f(2)(0)=\displaystyle f^{(2)}(0)= a0+a02a2+a03a3+a04a4\displaystyle a_{0}+a_{0}^{2}a_{2}+a_{0}^{3}a_{3}+a_{0}^{4}a_{4}

Next, f(3)(0)f^{(3)}(0) is a longer expression that includes monomials like a04a2a3a_{0}^{4}a_{2}a_{3} and a07a2a3a4a_{0}^{7}a_{2}a_{3}a_{4}. None of these monomials appears in f(2)f^{(2)}, hence the stability index for ff is at least 3. On the other hand, f(4)(0)=f(3)(0)f^{(4)}(0)=f^{(3)}(0) because in any new monomial in f(4)(0)f^{(4)}(0), at least one of a2,a3a_{2},a_{3}, or a4a_{4} has degree 2\geq 2, and is absorbed by other monomials already present in f(3)(0)f^{(3)}(0): for example, f(4)(0)f^{(4)}(0) contains the new monomial a05a22a3a_{0}^{5}a_{2}^{2}a_{3}, which is absorbed, because f(4)(0)f^{(4)}(0) also contains the monomials a03a3a_{0}^{3}a_{3} and a04a2a3a_{0}^{4}a_{2}a_{3} (they were already present in f(3)(0)f^{(3)}(0)), and the following identity holds in the 1-stable semiring: a03a3+a04a2a3+a05a22a3=a03a3(1+(a0a2)+(a0a2)2)=a03a3(1+(a0a2))=a03a3+a04a2a3a_{0}^{3}a_{3}+a_{0}^{4}a_{2}a_{3}+a_{0}^{5}a_{2}^{2}a_{3}=a_{0}^{3}a_{3}\left(1+(a_{0}a_{2})+(a_{0}a_{2})^{2}\right)=a_{0}^{3}a_{3}\left(1+(a_{0}a_{2})\right)=a_{0}^{3}a_{3}+a_{0}^{4}a_{2}a_{3}.

5.4. Convergence in Stable POPS

We will now generalize the convergence theorems from semirings to POPS. Let 𝑷\bm{P} be a POPS, and recall that we assume throughout this paper that multiplication is strict, x=x\cdot\bot=\bot. Recall that 𝑺=def𝑷+\bm{S}\stackrel{{\scriptstyle\text{def}}}{{=}}\bm{P}+\bot is a semiring, the core semiring of 𝑷\bm{P}. We call 𝑷\bm{P} stable, or uniformly stable, if the core 𝑺\bm{S} is stable or uniformly stable respectively. We generalize now Theorems 5.10 and 5.12 from stable semirings to stable POPS.

Fix an NN-tuple of polynomials 𝒇=(f1,,fN)\bm{f}=(f_{1},\ldots,f_{N}) over NN variables 𝒙=(x1,,xN)\bm{x}=(x_{1},\ldots,x_{N}). We define the following directed graph G𝒇G_{\bm{f}}. The nodes of the graph are the variables x1,,xNx_{1},\ldots,x_{N}, and there exists an edge xixjx_{i}\rightarrow x_{j} if the polynomial fjf_{j} depends on xix_{i}, i.e. it contains a monomial where the factor xiix_{i}^{\ell_{i}} has a degree i1\ell_{i}\geq 1. Call a variable xix_{i} recursive if it belongs to a cycle, or if there exists a recursive variable xjx_{j} and an edge xjxix_{j}\rightarrow x_{i}. Otherwise, we call xix_{i} non-recursive.

Proposition 5.16.

If xix_{i} is recursive, then for all q0q\geq 0, (𝐟(q)())i𝐏+(\bm{f}^{(q)}(\bot))_{i}\in\bm{P}+\bot. In other words, the recursive variables cannot escape 𝐏+\bm{P}+\bot.

Proof.

We prove the statement by induction on qq. When q=0q=0 the statement holds because, at initialization, (𝒇(0)())i=(\bm{f}^{(0)}(\bot))_{i}=\bot for all ii. Assume the statement holds for q0q\geq 0, and consider the value

(𝒇(q+1)())i=fi((𝒇(q)())1,,(𝒇(q)())N),(\bm{f}^{(q+1)}(\bot))_{i}=f_{i}((\bm{f}^{(q)}(\bot))_{1},\ldots,(\bm{f}^{(q)}(\bot))_{N}),

where ii is such that xix_{i} is recursive. By assumption, fif_{i} contains some monomial cx11xNNc\cdot x_{1}^{\ell_{1}}\cdots x_{N}^{\ell_{N}} that includes a recursive variable xjx_{j}, and by induction hypothesis, (𝒇(q)()))j𝑷+(\bm{f}^{(q)}(\bot)))_{j}\in\bm{P}+\bot. Therefore, (f(q+1)())i(f^{(q+1)}(\bot))_{i} is a sum that includes the expression c(𝒇(q)())11(𝒇(q)())NNc\cdot(\bm{f}^{(q)}(\bot))_{1}^{\ell_{1}}\cdots(\bm{f}^{(q)}(\bot))_{N}^{\ell_{N}}, where the jj-th factor is in 𝑷+\bm{P}+\bot. Therefore (f(q+1)())i𝑷+(f^{(q+1)}(\bot))_{i}\in\bm{P}+\bot because both multiplication and addition with an element in 𝑷+\bm{P}+\bot result in an element in 𝑷+\bm{P}+\bot, by (u+)v=uv+v=uv+(u+\bot)v=uv+\bot v=uv+\bot and similarly (u+)+v=(u+v)+(u+\bot)+v=(u+v)+\bot. ∎

Suppose the polynomial function 𝒇:𝑷N𝑷N\bm{f}:\bm{P}^{N}\rightarrow\bm{P}^{N} has N0N_{0} non-recursive variables and N1N_{1} recursive variables, where N0+N1=NN_{0}+N_{1}=N. We write 𝒇=(𝒈,𝒉)\bm{f}=(\bm{g},\bm{h}), where 𝒈:𝑷N1×𝑷N0𝑷N1\bm{g}:\bm{P}^{N_{1}}\times\bm{P}^{N_{0}}\rightarrow\bm{P}^{N_{1}} are the polynomials associated to the recursive variables, and 𝒉:𝑷N0𝑷N0\bm{h}:\bm{P}^{N_{0}}\rightarrow\bm{P}^{N_{0}} are the rest; note that 𝒉\bm{h} does not depend on any recursive variables. By Lemma 3.2, if 𝒈,𝒉\bm{g},\bm{h} are stable, then so is 𝒇\bm{f}. We claim that the stability index of 𝒉\bm{h} is N0N_{0}. This follows easily by induction on N0N_{0}, using Lemma 3.2. If N0=1N_{0}=1 then h(x)=ch(x)=c for some constant cc, since it cannot depend on any variable. Assume N0>1N_{0}>1. Since none of the variables used by 𝒉\bm{h} is recursive, its graph G𝒉G_{\bm{h}} is acyclic, hence there is one variable without an incoming edge. Write 𝒉=(𝒉,h′′)\bm{h}=(\bm{h}^{\prime},h^{\prime\prime}), where h′′h^{\prime\prime} corresponds to the variable without incoming edge, hence it is a constant function (doesn’t depend on any variables), and 𝒉\bm{h}^{\prime} is a vector of N01N_{0}-1 non-recursive polynomials. The stability index of 𝒉\bm{h}^{\prime} is N01N_{0}-1 by induction hypothesis, while that of h′′h^{\prime\prime} is 1, therefore, by Lemma 3.2, the stability index of 𝒉\bm{h} is (N01)+1=N0(N_{0}-1)+1=N_{0}.

Our discussion implies:

Corollary 5.17.

(Generalization of Theorem 5.10) If the semiring 𝐏+\bm{P}+\bot is stable, then every polynomial function 𝐟:𝐏N𝐏N\bm{f}:\bm{P}^{N}\rightarrow\bm{P}^{N} is stable. In particular, every datalog\text{\sf datalog}^{\circ} program converges on the POPS 𝐏\bm{P}.

Corollary 5.18.

(Generalization of Theorem 5.12). Assume the POPS 𝐏\bm{P} is pp-stable, and let 𝐟:𝐏N𝐏N\bm{f}:\bm{P}^{N}\rightarrow\bm{P}^{N} be a polynomial function. Then function 𝐟\bm{f} is i=0N(p+2)i\sum_{i=0}^{N}(p+2)^{i}-stable; if 𝐟\bm{f} is linear, then it is i=0N(p+1)i\sum_{i=0}^{N}(p+1)^{i}-stable.

In particular, every datalog\text{\sf datalog}^{\circ} program over the POPS 𝐏\bm{P} converges in a number of steps given by the expressions above, where NN is the number of grounded IDB atoms.

The corollaries convey a simple intuition. If the grounded datalog\text{\sf datalog}^{\circ} program is recursive, then the values of the recursive atoms cannot escape the semiring 𝑷+\bm{P}+\bot; the non-recursive atoms, however, can take values outside of this semiring. This can be seen in Example 4.2: when we interpret the program over the lifted reals, \mathbb{R}_{\bot}, then the values of T(a),T(b)T(a),T(b) remain \bot, yet those of T(c),T(d)T(c),T(d) take values that are \neq\bot. This implies that the convergence of a recursive grounded program is tied to the stability of 𝑹+\bm{R}+\bot. The convergence of a non-recursive grounded program, however, follows directly from the fact that its graph is acyclic.

Finally, we prove a sufficient condition for convergence in polynomial time.

Corollary 5.19.

(Generalization of the case p=0p=0 in Theorem 5.12) Assume the POPS 𝐏\bm{P} is 0-stable, and let 𝐟:𝐏N𝐏N\bm{f}:\bm{P}^{N}\rightarrow\bm{P}^{N} be a polynomial function. Then function 𝐟\bm{f} is NN-stable. In particular, every datalog\text{\sf datalog}^{\circ} program over the POPS 𝐏\bm{P} converges in a number of steps that is polynomial in the size of the input database.

The semirings 𝔹,Trop+\mathbb{B},\text{\sf Trop}^{+} are 0-stable; the POPS \mathbb{R}_{\bot} is also 0-stable (because +\mathbb{R}_{\bot}+\bot is the trivial semiring {}\{\bot\}, with a single element). Corollary 5.19 implies that datalog\text{\sf datalog}^{\circ} converges in polynomial time on each of these semirings.

These three corollaries complete the proof of Theorem 1.2 in the introduction.

5.5. Convergence in PTIME for pp-Stable Semirings when p>0p>0

Consider a datalog\text{\sf datalog}^{\circ} program over a pp-stable POPS 𝑷\bm{P}. When p=0p=0 then we know that the naïve algorithm converges in polynomial time. What is its runtime when p>0p>0? Corollary 5.18 gives only an exponential upper bound, and we leave open the question whether that bound is tight. Instead, in this section, we restrict the datalog\text{\sf datalog}^{\circ} program to be a linear program, and ask whether it can be computed in polynomial time, over a pp-stable POPS. We prove two results. First, if the POPS is Tropp+\text{\sf Trop}^{+}_{p} (which is pp-stable) then the naïve algorithm converges in polynomial time. Second, for any pp-stable POPS, the datalog\text{\sf datalog}^{\circ} program can be computed in polynomial time, by using the Floyd-Warshall-Kleene approach (MR1059930, ; DBLP:journals/tcs/Lehmann77, ). We leave open the question whether the naïve algorithm also converges in polynomial time.

We start with some general notations. Fix a semiring 𝑺\bm{S}, and a linear function F:𝑺N𝑺NF:\bm{S}^{N}\rightarrow\bm{S}^{N}. We can write it as a matrix-vector product: F(X)=AX+BF(X)=AX+B, where AA is an N×NN\times N matrix, and XX, BB are NN-dimensional column vectors. After q+1q+1 iterations, the naïve algorithm computes F(q+1)(0)=B+AB+A2B++AqB=A(q)BF^{(q+1)}(0)=B+AB+A^{2}B+\cdots+A^{q}B=A^{(q)}B, where A(q)=defIN+A+A2++AqA^{(q)}\stackrel{{\scriptstyle\text{def}}}{{=}}I_{N}+A+A^{2}+\cdots+A^{q}. The naïve algorithm converges in q+1q+1 steps iff FF is q+1q+1-stable. A matrix AA is called qq-stable (semiring_book, ) if A(q)=A(q+1)A^{(q)}=A^{(q+1)}. The following is easy to check: the matrix AA is qq-stable iff, for every vector BB, the linear function F(X)=AX+BF(X)=AX+B is q+1q+1 stable. Our discussion implies that, in order to determine the runtime of the naïve algorithm on a linear datalog\text{\sf datalog}^{\circ} program over a pp-stable semiring, one has to compute the stability index of an N×NN\times N matrix AA over that semiring. Surprisingly, no polynomial bound for the stability index of a matrix is known in general, except for p=0p=0, in which case AA is NN-stable (this was shown in (DBLP:journals/dm/Gondran79, ), and also follows from our more general Corollary 5.19). We prove here a result in the special case when the semiring is Tropp+\text{\sf Trop}^{+}_{p} (introduced in Example 2.9), which is pp-stable.

Lemma 5.20.

Every N×NN\times N matrix AA over Tropp+\text{\sf Trop}^{+}_{p} semiring is ((p+1)N1)((p+1)N-1)-stable. This bound is tight, i.e., there exist N×NN\times N-matrices over Tropp+\text{\sf Trop}^{+}_{p} whose stability index is (p+1)N1(p+1)N-1.

Proof.

We consider the N×NN\times N-matrix AA over Tropp+\text{\sf Trop}^{+}_{p} as the adjacency matrix of a directed graph GG with NN vertices and up to p+1p+1 parallel edges from some vertex ii to jj. Then AijA_{ij} is a bag of p+1p+1 numbers representing the costs of p+1p+1 edges from ii to jj; if fewer than p+1p+1 edges exists from ii to jj, then we complete the bag with \infty, intuitively saying that no further edge from ii to jj exists. For instance, Aij={1,2,3,,,}A_{ij}=\{1,2,3,\infty,\dots,\infty\} means that there are 3 edges from ii to jj of length 1,2,31,2,3, while Aij={,,}A_{ij}=\{\infty,\dots,\infty\} means that there is no edge from ii to jj.

Claim. Let k1k\geq 1, let B=AB=A^{\ell} with kN\ell\geq k\cdot N, and let bb denote the minimum element in BijB_{ij} for 1i,jN1\leq i,j\leq N. Moreover, let C=I+A+A2++A1C=I+A+A^{2}+\dots+A^{\ell-1}. Then CijC_{ij} contains at least kk elements which are b\leq b.

The upper bound of (N+1)p1(N+1)p-1 follows immediately from the claim. To prove the claim, observe the following:

  • (A)ij(A^{\ell})_{ij} contains the lengths of the p+1p+1 lowest-cost paths in GG from ii to jj consisting of at least kNkN edges.

  • CijC_{ij} contains the lengths of the p+1p+1 lowest-cost paths in GG from ii to jj consisting of at most kN1kN-1 edges.

Consider a cost-bb path (not necessarily simple) from ii to jj in GG containing at least kNkN edges. Every segment of length NN on this path contains at least a simple cycle. Removing the cycle yields an ijij-path with strictly fewer edges with lower or equal cost. By repeating this process, we conclude that there are at least kk different ijij-paths of cost at most bb with <kN<kN edges. This observation proves the claim, and thus the upper bound.

To prove the lower bound, consider the following matrix AA:

(A12A23A(N1)NAN1)\left(\begin{array}[]{cccccc}\infty&A_{12}&\infty&\cdots&\cdots&\infty\\ \ \infty&\infty&A_{23}&\infty&\cdots&\infty\\ \vdots&&&\ddots&\ddots&\vdots\\ \vdots&&&&\ddots&\infty\\ \infty&\cdots&\cdots&\cdots&\infty&A_{(N-1)N}\\ A_{N1}&\infty&\cdots&\cdots&\infty&\infty\end{array}\right)

where we write \infty for the bag {,,}\{\infty,\dots,\infty\}, i.e., the 0-element of Tropp+\text{\sf Trop}^{+}_{p}. And we set A12=A23==A(N1)N=AN1={1,,A_{12}=A_{23}=\dots=A_{(N-1)N}=A_{N1}=\{1,\infty,\dots, }\infty\}, i.e., the number 1 plus pp times \infty. In other words, AA is the adjacency matrix of the directed cycle of length NN. By Claim above, we get A1N(N1)={N1,,,}A^{(N-1)}_{1N}=\{N-1,\infty,\dots,\infty\}. That is, there exists one path from vertex 1 to vertex NN with N1N-1 edges and this path has cost (= length) N1N-1. Moreover, there is an edge of length 11 back to vertex 11. Hence, the p+1p+1 shortest paths from vertex 1 to vertex NN are obtained by looping 0,1,2,,p0,1,2,\dots,p times through the vertices 1,,N1,\dots,N and finally going from 11 to NN along the single shortest path. ∎

The lemma immediately implies:

Corollary 5.21.

Any linear datalog\text{\sf datalog}^{\circ} program over Tropp+\text{\sf Trop}^{+}_{p}, converges in (p+1)N1(p+1)N-1 steps, where N=|D|O(1)N=|D|^{O(1)} is the number of ground IDB tuples. This bound is tight.

Second, we consider arbitrary pp-stable POPS 𝑷\bm{P}, where \cdot is strict and prove that every linear datalog\text{\sf datalog}^{\circ} program can be computed in polynomial time. Gaussian elimination method, which coincides with the Floyd-Warshall-Kleene algorithm (MR1059930, ; DBLP:journals/tcs/Lehmann77, ), computes the closure AA^{*} of an N×NN\times N matrix in O(N3)O(N^{3}) time, in a closed semiring. This immediately extends to a pp-stable semiring, since every pp-stable semiring is closed, by setting a=defa(p)a^{*}\stackrel{{\scriptstyle\text{def}}}{{=}}a^{(p)}. Our next theorem proves that essentially the same algorithm also applies to pp-stable POPS.

Theorem 5.22.

Let 𝐏\bm{P} be a pp-stable POPS, strict (x=x\cdot\bot=\bot), and assume that both operations ++ and \cdot can be computed in constant time. Let f1,,fNf_{1},\ldots,f_{N} be NN linear functions in NN variables. Then, lfp(f1,,fN)\text{\sf lfp}(f_{1},\ldots,f_{N}) can be computed in time O(pN+N3)O(pN+N^{3}).

Proof.

Recall that a polynomial is defined as a sum of monomials, see Eq. (37). Thus, a linear polynomial is given by an expression f(x1,,xN)=iVaixi+bf(x_{1},\ldots,x_{N})=\sum_{i\in V}a_{i}x_{i}+b, for some set V[N]V\subseteq[N]. In other words, we cannot simply write it as i=1,Naixi+b\sum_{i=1,N}a_{i}x_{i}+b because if we want to make ff independent of xix_{i}, then it is not sufficient to set ai=0a_{i}=0 because 0=0\cdot\bot=\bot and x+=x+\bot=\bot; we need to represent explicitly the set of monomials VV in ff. Equivalently, ff is represented by a list of coefficients. Let g(X)=jWcjxj+dg(X)=\sum_{j\in W}c_{j}x_{j}+d be another linear function. We denote by f[g/xk]f[g/x_{k}] the linear function obtained by substituting xkx_{k} with gg in ff. More precisely, if kVk\not\in V then f[g/xk]=ff[g/x_{k}]=f, and if kVk\in V then we replace the term akxka_{k}x_{k} in ff by jW(akcj)xj\sum_{j\in W}(a_{k}c_{j})x_{j}. The representation of f[g/xk]f[g/x_{k}] can be computed in time O(N)O(N) from the representations of ff and gg.

if  N=0N=0  then
       return ()()
if  fNf_{N} is independent of xNx_{N}  then
       c(x1,,xN1)fN(x1,,xN1)c(x_{1},\ldots,x_{N-1})\leftarrow f_{N}(x_{1},\ldots,x_{N-1})
if  fN=aNNxN+b(x1,,xN1)f_{N}=a_{NN}\cdot x_{N}+b(x_{1},\ldots,x_{N-1})  then
       c(x1,,xN1)aNN(p)b(x1,,xN1)+c(x_{1},\ldots,x_{N-1})\leftarrow a_{NN}^{(p)}\cdot b(x_{1},\ldots,x_{N-1})+\bot
(x¯1,,x¯N1)LinearLFP(f1[c/xN],,fN1[c/xN])(\bar{x}_{1},\ldots,\bar{x}_{N-1})\leftarrow\texttt{LinearLFP}(f_{1}[c/x_{N}],\ldots,f_{N-1}[c/x_{N}]);
x¯Nc(x¯1,,x¯N1)\bar{x}_{N}\leftarrow c(\bar{x}_{1},\ldots,\bar{x}_{N-1});
return (x¯1,,x¯N)(\bar{x}_{1},\ldots,\bar{x}_{N})
Algorithm 2 LinearLFP(f1,,fN)\texttt{LinearLFP}(f_{1},\ldots,f_{N})

Algorithm 2 proceeds recursively on NN. Let H=def(f1,,fN)H\stackrel{{\scriptstyle\text{def}}}{{=}}(f_{1},\ldots,f_{N}). Considering the last linear function fN(x1,,xN)f_{N}(x_{1},\ldots,x_{N}), we write HH with some abuse as H(x1,,xN)=(f(x,y),g(x,y))H(x_{1},\ldots,x_{N})=(f(x,y),g(x,y)), where f=def(f1,,fN1)f\stackrel{{\scriptstyle\text{def}}}{{=}}(f_{1},\ldots,f_{N-1}) and g=deffNg\stackrel{{\scriptstyle\text{def}}}{{=}}f_{N}, and similarly x=def(x1,,xN1)x\stackrel{{\scriptstyle\text{def}}}{{=}}(x_{1},\ldots,x_{N-1}), y=defxNy\stackrel{{\scriptstyle\text{def}}}{{=}}x_{N}. Then we apply Lemma 3.3. Since 𝑺\bm{S} is pp-stable, then function gxg_{x} is p+1p+1 stable, hence to compute the fixpoint using Lemma 3.3 we need to represent the function c(x)=defgx(p+1)()c(x)\stackrel{{\scriptstyle\text{def}}}{{=}}g_{x}^{(p+1)}(\bot). There are two cases. The first is when fNf_{N} does not depend on xNx_{N}: then g(x,y)g(x)g(x,y)\equiv g(x) does not depend on yy, and gx(y)g_{x}(y) is a constant function, hence c(x)=gx(p+1)()=g(x)c(x)=g_{x}^{(p+1)}(\bot)=g(x). The second is when fN=aNNxN+b(x1,,xN1)f_{N}=a_{NN}\cdot x_{N}+b(x_{1},\ldots,x_{N-1}) for some aNN𝑷a_{NN}\in\bm{P} and linear function bb in N1N-1 variables. In our new notation, gx(y)=aNNy+b(x)g_{x}(y)=a_{NN}\cdot y+b(x). We thus get

gx(1)()=+b(x)g_{x}^{(1)}(\bot)=\bot+b(x),

gx(2)()=aNN(+b(x))+b(x)=+aNNb(x)+b(x)=aNN(1)b(x)+g_{x}^{(2)}(\bot)=a_{NN}\cdot(\bot+b(x))+b(x)=\bot+a_{NN}\cdot b(x)+b(x)=a_{NN}^{(1)}\cdot b(x)+\bot,

gx(3)()=aNN(aNN(1)b(x)+)+b(x)=aNN(2)b(x)+g_{x}^{(3)}(\bot)=a_{NN}\cdot(a_{NN}^{(1)}\cdot b(x)+\bot)+b(x)=a_{NN}^{(2)}\cdot b(x)+\bot, etc.

Hence, c(x)=gx(p+1)()=aNN(p)b(x)+c(x)=g_{x}^{(p+1)}(\bot)=a_{NN}^{(p)}\cdot b(x)+\bot. Next, following Lemma 3.3, we compute the fixpoint of F(x)=deff(x,c(x))F(x)\stackrel{{\scriptstyle\text{def}}}{{=}}f(x,c(x)): this is done by the algorithm inductively, since both ff and xx have dimension N1N-1.

Finally, we compute the runtime. We need O(p)O(p) operations to compute aNN(p)a_{NN}^{(p)}, then O(N2)O(N^{2}) operations to compute a representation of the linear function cc, then representations of the linear functions f1[c/xN],,fN1[c/xN]f_{1}[c/x_{N}],\ldots,f_{N-1}[c/x_{N}]. Thus, the total runtime of the algorithm is nNO(p+n2)=O(pN+N3)\sum_{n\leq N}O(p+n^{2})=O(pN+N^{3}). ∎

6. Semi-Naïve Optimization

In this section we show that the semi-naïve algorithm for standard datalog can be generalized to datalog\text{\sf datalog}^{\circ}, for certain restricted POPS. The Naïve Algorithm 1 repeatedly applies the immediate consequence operator FF and computes J(0),J(1),J(2),J^{(0)},J^{(1)},J^{(2)},\ldots, where J(t+1)=defF(J(t))J^{(t+1)}\stackrel{{\scriptstyle\text{def}}}{{=}}F(J^{(t)}). This strategy is inefficient because all facts discovered at iteration tt will be re-discovered at iterations t+1,t+2,t+1,t+2,\ldots The semi-naïve optimization consists of a modified program that computes J(t+1)J^{(t+1)} by first computing only the “novel” facts δ(t)=F(J(t))J(t)\delta^{(t)}=F(J^{(t)})-J^{(t)}, which are then added to J(t)J^{(t)} to form J(t+1)J^{(t+1)}. Furthermore, the difference F(J(t))J(t)F(J^{(t)})-J^{(t)} can be computed efficiently, without fully evaluating F(J(t))F(J^{(t)}), by using techniques from incremental view maintenance.

This section generalizes the semi-naïve algorithm from datalog to datalog\text{\sf datalog}^{\circ}. The main problem we encounter is that, while the difference operator is well defined in the Boolean semiring, as xy=defx¬yx-y\stackrel{{\scriptstyle\text{def}}}{{=}}x\wedge\neg y, no generic difference operator exists in an arbitrary POPS. In order to define a difference operator, we will restrict the POPS to be a complete, distributive dioid.

6.1. Complete, Distributive Dioids

A dioid is a semiring 𝑺=(S,,,0,1)\bm{S}=(S,\oplus,\otimes,0,1) for which \oplus is idempotent (meaning aa=aa\oplus a=a). Dioids have many applications in a wide range of areas, see (MR1608370, ) for an extensive coverage. We review here a simple property of dioids:

Proposition 6.1.

Let (S,,,0,1)(S,\oplus,\otimes,0,1) be a dioid. Then, the following hold:

  • (i)

    𝑺\bm{S} is naturally ordered, and the natural order coincides with the relation \sqsubseteq, defined by aba\sqsubseteq b if ab=ba\oplus b=b.

  • (ii)

    \oplus is the same as the least upper bound, \vee.

Proof.

Recall from Sec. 2 that the natural order is defined as aba\preceq b iff c:ac=b\exists c:a\oplus c=b. We first show that \preceq is the same as \sqsubseteq. One direction, aba\sqsubseteq b implies aba\preceq b is obvious. For the converse, assume ac=ba\oplus c=b. Then, ab=a(ac)=ac=ba\oplus b=a\oplus(a\oplus c)=a\oplus c=b due to idempotency, and thus aba\sqsubseteq b. Since \preceq is a preorder, \sqsubseteq is also a preorder. To make it a partial order we only need to verify anti-symmetry, which is easily verified:: ab=ba\oplus b=b and ab=aa\oplus b=a imply a=ba=b. We just proved (i)(i).

To show (ii)(ii), let c=abc=a\oplus b for some a,b,ca,b,c. Then ac=aab=ab=ca\oplus c=a\oplus a\oplus b=a\oplus b=c; thus, aca\sqsubseteq c. Similarly bcb\sqsubseteq c, which means abc=aba\vee b\sqsubseteq c=a\oplus b. Conversely, let d=abd=a\vee b. Then, ad=da\oplus d=d and bd=db\oplus d=d, which means abd=da\oplus b\oplus d=d and thus abd=aba\oplus b\preceq d=a\vee b. ∎

Definition 6.2.

A POPS 𝐒=(S,,,0,1,)\bm{S}=(S,\oplus,\otimes,0,1,\sqsubseteq) is called a complete, distributive dioid if (S,,,0,1)(S,\oplus,\otimes,0,1) is a dioid, \sqsubseteq is the dioid’s natural order, and the ordered set (S,)(S,\sqsubseteq) is a complete, distributive lattice, which means that every set ASA\subseteq S has a greatest lower bound A\bigwedge A, and xA={xaaA}x\vee\bigwedge A=\bigwedge\{{x\vee a}\mid{a\in A}\}. In a complete, distributive dioid, the difference operator is defined by

(58) ba\displaystyle b\ominus a =def{cacb}\displaystyle\stackrel{{\scriptstyle\text{def}}}{{=}}\bigwedge\{{c}\mid{a\oplus c\sqsupseteq b}\}

In order to extend the semi-naïve algorithm to datalog\text{\sf datalog}^{\circ}, we require the POPS to be a complete, distributive dioid. There are many examples of complete, distributive dioids: (2𝑼,,,,𝑼,)(2^{\bm{U}},\cup,\cap,\emptyset,\bm{U},\subseteq) is a complete, distributive dioid, whose difference operator is exactly set-difference ba={cbac}=bab-a=\bigcap\{{c}\mid{b\subseteq a\cup c}\}=b\setminus a; Trop+=(+{},min,+,,0,)\text{\sf Trop}^{+}=(\mathbb{R}_{+}\cup\{\infty\},\min,+,\infty,0,\geq) is also a complete, distributive dioid, whose difference operator is defined by Eq. (6) in Sec. 1.1; and {}\mathbb{N}\cup\{\infty\} is also a complete, distributive dioid. On the other hand, Tropp+\text{\sf Trop}^{+}_{p}, Tropη+\text{\sf Trop}^{+}_{\leq\eta}, \mathbb{R}_{\bot} are not dioids.

The next lemma proves the only two properties of \ominus that we need for the semi-naïve algorithm: we need the first property in Theorem 6.4 to prove the correctness of the algorithm, and the second property in Theorem 6.5 to prove the differential rule.

Lemma 6.3.

Let 𝐒=(S,,,0,1,)\bm{S}=(S,\oplus,\otimes,0,1,\sqsubseteq) be a complete, distributive dioid, and let \ominus be defined by (58). The following hold:

(59) if ab:a(ba)\displaystyle\mbox{if }a\sqsubseteq b:\ \ \ a\oplus(b\ominus a) =b\displaystyle=b
(60) (ab)(ac)\displaystyle(a\oplus b)\ominus(a\oplus c) =b(ac)\displaystyle=b\ominus(a\oplus c)
Proof.

We start by showing a general inequality:

(61) a,bS:a(ba)\displaystyle\forall a,b\in S:\ \ \ a\oplus(b\ominus a) b\displaystyle\sqsupseteq b

This follows from a(ba)=a{xaxb}=a({xaxb})={axaxb}ba\oplus(b\ominus a)=a\oplus\bigwedge\{{x}\mid{a\oplus x\sqsupseteq b}\}=a\vee\left(\bigwedge\{{x}\mid{a\vee x\sqsupseteq b}\}\right)=\bigwedge\{{a\vee x}\mid{a\vee x\sqsupseteq b}\}\sqsupseteq b.

We prove now (59). Denote by A={xaxb}A=\{{x}\mid{a\oplus x\sqsupseteq b}\}, and observe that bAb\in A because abba\oplus b\sqsupseteq b. Therefore ba=Abb\ominus a=\bigwedge A\sqsubseteq b. We also have aba\sqsubseteq b by assumption. It follows that a(ba)bb=ba\oplus(b\ominus a)\sqsubseteq b\oplus b=b. This, together with (61), implies (59).

We prove (60). For any xx for which acxba\oplus c\oplus x\sqsupseteq b holds, also aacxaba\oplus a\oplus c\oplus x\sqsupseteq a\oplus b holds, which implies acxaba\oplus c\oplus x\sqsupseteq a\oplus b because \oplus is idempotent. Conversely, acxaba\oplus c\oplus x\sqsupseteq a\oplus b implies acxba\oplus c\oplus x\sqsupseteq b because abba\oplus b\sqsupseteq b. Hence,

(ab)(ac)\displaystyle(a\oplus b)\ominus(a\oplus c) ={xacxab}={xacxb}=b(ac)\displaystyle=\bigwedge\{{x}\mid{a\oplus c\oplus x\sqsupseteq a\oplus b}\}=\bigwedge\{{x}\mid{a\oplus c\oplus x\sqsupseteq b}\}=b\ominus(a\oplus c)

6.2. The Semi-naïve Algorithm

We describe now the semi-naïve algorithm for a program over a complete, distributive dioid. Following the notations in Sec. 4, we write F(J)F(J) for the immediate consequence operator of the program, where JJ is an instance of the IDB predicates. The semi-naïve algorithm is shown in Algorithm 3. It proceeds almost identically to the Naïve Algorithm 1, but splits the computation JF(J)J\leftarrow F(J) into two steps: first compute the difference F(J)JF(J)\ominus J, then add it to JJ. We prove:

J(0)𝟎J^{(0)}\leftarrow\bm{0};
for  t0t\leftarrow 0 to \infty  do
       δ(t)F(J(t))J(t)\delta^{(t)}\leftarrow F(J^{(t)})\ominus J^{(t)};
        // incremental computation, see Sec. 6.2
       J(t+1)J(t)δ(t)J^{(t+1)}\leftarrow J^{(t)}\oplus\delta^{(t)};
       if  δ(t)=𝟎\delta^{(t)}=\bm{0}  then
             Break
return J(t)J^{(t)}
Algorithm 3 Semi-naïve evaluation for datalog\text{\sf datalog}^{\circ}
Theorem 6.4.

Consider a datalog\text{\sf datalog}^{\circ} program over a complete, distributive dioid. Then the Semi-naïve Algorithm 3 returns the same answer as the Naïve Algorithm 1.

Proof.

We will use identity (59) in Lemma 6.3. Let J(t)J^{(t)} be the sequence of IDB instances computed by the Semi-naïve Algorithm 3, and let J¯(t)\bar{J}^{(t)} be the sequence computed by the Naïve Algorithm 1. Recall that J¯(t)\bar{J}^{(t)} forms an ω\omega-sequence (see Sec. 3), meaning J¯(0)J¯(1)J¯(2)\bar{J}^{(0)}\sqsubseteq\bar{J}^{(1)}\sqsubseteq\bar{J}^{(2)}\sqsubseteq\cdots We prove, by induction on tt, that J(t)=J¯(t)J^{(t)}=\bar{J}^{(t)}. The claim holds trivially for t=0t=0. Assuming J(t)=J¯(t)J^{(t)}=\bar{J}^{(t)} we prove J(t+1)=J¯(t+1)J^{(t+1)}=\bar{J}^{(t+1)}. This follows from:

J(t+1)=\displaystyle J^{(t+1)}= J(t)(F(J(t))J(t))=J¯(t)(F(J¯(t))J¯(t))=F(J¯(t))=J¯(t+1)\displaystyle J^{(t)}\oplus(F(J^{(t)})\ominus J^{(t)})=\bar{J}^{(t)}\oplus(F(\bar{J}^{(t)})\ominus\bar{J}^{(t)})=F(\bar{J}^{(t)})=\bar{J}^{(t+1)}

The first equality is the definition of the semi-naïve algorithm, while the second equality uses the induction hypothesis J(t)=J¯(t)J^{(t)}=\bar{J}^{(t)}. The third equality is based on Eq. (59), J¯(t)(F(J¯(t))J¯(t))=F(J¯(t))\bar{J}^{(t)}\oplus(F(\bar{J}^{(t)})\ominus\bar{J}^{(t)})=F(\bar{J}^{(t)}), which holds because J¯(t)J¯(t+1)=F(J¯(t))\bar{J}^{(t)}\sqsubseteq\bar{J}^{(t+1)}=F(\bar{J}^{(t)}). Finally, the last equality is by the definition of the naïve algorithm. ∎

6.3. The Differential Evaluation Rule

As described, the semi-naïve algorithm is no more efficient than the naïve algorithm. Its advantages comes from the fact that we can compute the difference

(62) δ(t)\displaystyle\delta^{(t)}\leftarrow F(J(t))J(t)\displaystyle F(J^{(t)})\ominus J^{(t)}

incrementally, without computing the ICO FF. Recall that the datalog\text{\sf datalog}^{\circ} program consists of nn rules Ti :- Fi(T1,,Tn)T_{i}\text{ :- }F_{i}(T_{1},\ldots,T_{n}), one for each IDB T1,,TnT_{1},\ldots,T_{n}, where FiF_{i} is a sum-sum-product expression (Eq. (26) in Sec. 4), and the ICO is the vector of the sum-sum-product expressions, F=(F1,,Fn)F=(F_{1},\ldots,F_{n}). The difference (62) consists of computing the following differences, for i=1,ni=1,n:

(63) δi(t)\displaystyle\delta_{i}^{(t)}\leftarrow Fi(T1(t),,Tn(t))Ti(t)\displaystyle F_{i}(T_{1}^{(t)},\ldots,T_{n}^{(t)})\ominus T_{i}^{(t)}

For the purpose of incremental evaluation, we will assume w.l.o.g. that each TjT_{j} occurs at most once in any sum-product term of FiF_{i}; otherwise, we give each occurrence of TjT_{j} in (63) a unique name, see Example 6.6 below for an illustration. Therefore, FiF_{i} is affine999In the datalog context, “linear” is often used instead of “affine”. in each argument TjT_{j}. Notice that, when t1t\geq 1, then Tj(t)=Tj(t1)δj(t1)T_{j}^{(t)}=T_{j}^{(t-1)}\oplus\delta_{j}^{(t-1)} for j=1,nj=1,n, and Ti(t)=Fi(T1(t1),,Tn(t1))T_{i}^{(t)}=F_{i}(T_{1}^{(t-1)},\ldots,T_{n}^{(t-1)}). We prove:

Theorem 6.5 (The Differential Rule).

Assume that the sum-sum-product expression Fi(T1,,Tn)F_{i}(T_{1},\ldots,T_{n}) is affine in each argument TjT_{j}. Then, when t1t\geq 1, the difference (63) can be computed as follows:

(64) δi(t)\displaystyle\delta_{i}^{(t)}\leftarrow (j=1,nFi(T1(t),,Tj1(t),δj(t1),Tj+1(t1),,Tn(t1)))Ti(t)\displaystyle\left(\bigoplus_{j=1,n}F_{i}(T_{1}^{(t)},\ldots,T_{j-1}^{(t)},\delta_{j}^{(t-1)},T_{j+1}^{(t-1)},\ldots,T_{n}^{(t-1)})\right)\ominus T_{i}^{(t)}

Furthermore, if the sum-sum-product FiF_{i} can be written as Fi(T1,,Tn)=EiGi(T1,,Tn)F_{i}(T_{1},\ldots,T_{n})=E_{i}\oplus G_{i}(T_{1},\ldots,T_{n}), where EiE_{i} is independent of T1,,TnT_{1},\ldots,T_{n} (i.e. it depends only on the EDBs), then Eq. (64) can be further simplified to:

(65) δi(t)\displaystyle\delta_{i}^{(t)}\leftarrow (j=1,nGi(T1(t),,Tj1(t),δj(t1),Tj+1(t1),,Tn(t1)))Ti(t)\displaystyle\left(\bigoplus_{j=1,n}G_{i}(T_{1}^{(t)},\ldots,T_{j-1}^{(t)},\delta_{j}^{(t-1)},T_{j+1}^{(t-1)},\ldots,T_{n}^{(t-1)})\right)\ominus T_{i}^{(t)}

The significance of the theorem is that it replaces the expensive computation Fi(T1(t),,Tn(t))F_{i}(T_{1}^{(t)},\ldots,T_{n}^{(t)}) in (63) with several computations Fi()F_{i}(\cdots) (or Gi()G_{i}(\cdots)), where one argument is δj\delta_{j} instead of TjT_{j}. This is usually more efficient, because δj\delta_{j} is much smaller than TjT_{j}.

Proof.

In order to reduce clutter, we will write TjT_{j} for Tj(t1)T_{j}^{(t-1)} and δj\delta_{j} for δJ(t1)\delta_{J}^{(t-1)}. Therefore Tj(t)=TjδjT_{j}^{(t)}=T_{j}\oplus\delta_{j}, and the difference (63) becomes:

(66) δi(t)\displaystyle\delta_{i}^{(t)}\leftarrow Fi(T1δ1,,Tnδn)Fi(T1,,Tn)\displaystyle F_{i}(T_{1}\oplus\delta_{1},\ldots,T_{n}\oplus\delta_{n})\ominus F_{i}(T_{1},\ldots,T_{n})

Fix one IDB predicate TjT_{j}. Since FiF_{i} is affine in TjT_{j}, we can write it as Fj(,Tj,)=EijGij(Tj)F_{j}(\ldots,T_{j},\ldots)=E_{ij}\oplus G_{ij}(T_{j}) where EijE_{ij} does not contain TjT_{j}, and each sum-product in GijG_{ij} contains exactly one occurrence of TjT_{j}. This representation of FiF_{i} depends on the IDB TjT_{j}, hence we index Eij,GijE_{ij},G_{ij} by both ii and jj. Therefore,

Fi(,Tjδj,)=\displaystyle F_{i}(\ldots,T_{j}\oplus\delta_{j},\ldots)= EijGij(Tjδj)=EijGij(Tj)Gij(δj)\displaystyle E_{ij}\oplus G_{ij}(T_{j}\oplus\delta_{j})=E_{ij}\oplus G_{ij}(T_{j})\oplus G_{ij}(\delta_{j})
=\displaystyle= (EijGij(Tj))(EijGij(δj))=Fi(,Tj,)Fi(,δj,)\displaystyle(E_{ij}\oplus G_{ij}(T_{j}))\oplus(E_{ij}\oplus G_{ij}(\delta_{j}))=F_{i}(\ldots,T_{j},\ldots)\oplus F_{i}(\ldots,\delta_{j},\ldots)

because \oplus is idempotent, EijEij=EijE_{ij}\oplus E_{ij}=E_{ij}. Therefore, we have:

Fi(T1δ1,,Tnδn)=\displaystyle F_{i}(T_{1}\oplus\delta_{1},\ldots,T_{n}\oplus\delta_{n})= Fi(T1,T2,,Tn)\displaystyle F_{i}(T_{1},T_{2},\ldots,T_{n})
\displaystyle\oplus Fi(δ1,T2,,Tn)\displaystyle F_{i}(\delta_{1},T_{2},\ldots,T_{n})
\displaystyle\oplus Fi(T1δ1,δ2,,Tn)\displaystyle F_{i}(T_{1}\oplus\delta_{1},\delta_{2},\ldots,T_{n})
\displaystyle\ldots
\displaystyle\oplus Fi(T1δ1,T2δ2,,δn)\displaystyle F_{i}(T_{1}\oplus\delta_{1},T_{2}\oplus\delta_{2},\ldots,\delta_{n})

We substitute this in the difference (66), then cancel the first term Fi(T1,,Tn)F_{i}(T_{1},\ldots,T_{n}) by using identity (60), and obtain

δi(t)\displaystyle\delta_{i}^{(t)}\leftarrow (j=1,nFi(T1δ1,,Tj1δj1,δj,Tj+1,,Tn))Fi(T1,,Tn)\displaystyle\left(\bigoplus_{j=1,n}F_{i}(T_{1}\oplus\delta_{1},\ldots,T_{j-1}\oplus\delta_{j-1},\delta_{j},T_{j+1},\ldots,T_{n})\right)\ominus F_{i}(T_{1},\ldots,T_{n})

This proves equality (64).

To prove (65), we observe that both Fi(T1(t),,Tj1(t),δj(t1),Tj+1(t1),,Tj(t1))=EiGi()F_{i}(T_{1}^{(t)},\ldots,T_{j-1}^{(t)},\delta_{j}^{(t-1)},T_{j+1}^{(t-1)},\ldots,T_{j}^{(t-1)})=E_{i}\oplus G_{i}(\cdots) and Ti(t)=EiGi()T_{i}^{(t)}=E_{i}\oplus G_{i}(\cdots) contain the common term EiE_{i}, and therefore we can use identity (60) to cancel EiE_{i}, replacing each FiF_{i} with GiG_{i}. ∎

We end this section with a short example.

Example 6.6 (Quadratic transitive closure).

Consider the following non-linear datalog program computing the transitive closure:

T(x,y)\displaystyle T(x,y) :- E(x,y)(z:T(x,z)T(z,y))\displaystyle\text{ :- }E(x,y)\vee(\exists z:T(x,z)\wedge T(z,y))

The semi-naïve algorithm with the differential rule (65) proceeds as follows. It initializes T(0)=T^{(0)}=\emptyset and δ(0)=E\delta^{(0)}=E, then repeats the following instructions for t=1,2,t=1,2,\ldots

δ(t)(x,y)\displaystyle\delta^{(t)}(x,y) (z:δ(t1)(x,z)T(t1)(z,y))(z:T(t)(x,z)δ(t1)(z,y))T(t)(x,y)\displaystyle\leftarrow\left(\exists z:\delta^{(t-1)}(x,z)\wedge T^{(t-1)}(z,y)\right)\vee\left(\exists z:T^{(t)}(x,z)\wedge\delta^{(t-1)}(z,y)\right)\setminus T^{(t)}(x,y)
T(t+1)(x,y)\displaystyle T^{(t+1)}(x,y) T(t)(x,y)δ(t)(x,y)\displaystyle\leftarrow T^{(t)}(x,y)\vee\delta^{(t)}(x,y)

6.4. Discussion

The semi-naïve algorithm immediately extends to stratified datalog\text{\sf datalog}^{\circ} (see Sec. 4.5), by applying the algorithm to each stratum.

Our differential rule (64) or (65) is not the only possibility for incremental evaluation. It has the advantage that it requires only nn computations of the sum-sum-product expression FiF_{i}, where nn is the maximum number of IDBs that occur in any sum-product of FiF_{i}. But these expressions use both the previous IDBs Tj(t1)T_{j}^{(t-1)} and current IDBs Tj(t)T_{j}^{(t)}, which, one can argue, is not ideal, because the newer IDB instances are slightly larger than the previous ones. An alternative is to use the 2n12^{n}-1 discrete differentials of FiF_{i}, which use only the previous IDBs Tj(t1)T_{j}^{(t-1)}, at the cost of increasing the number of expressions. Yet a more sophisticated possibility is to use higher order differentials, as pioneered by the DBToaster project (DBLP:journals/vldb/KochAKNNLS14, ).

The techniques described in this section required the POPS to be a complete, distributive dioid. The attentive reader may have observed that the Semi-naïve Algorithm 3 only needs to compute a difference bab\ominus a when aba\sqsubseteq b. This opens the question whether the semi-naïve algorithm can be extended beyond complete, distributive dioids, with a more restricted definition of \ominus. We leave this for future work.

7. POPS and the Well-Founded Model

Our main motivation in this paper was to extend datalog to allow the interleaving of aggregates and recursion. We have seen that by choosing different POPS, one can capture different kinds of aggregations. A large literature on datalog is concerned however with a different extension: the interleaving of negation and recursion. It turns out that a certain POPS can also be used to interpret datalog programs with negation; we give the details in this section.

Let’s briefly review the most important approaches to extend datalog with negation. The simplest is stratified datalog, which is the most commonly used in practice, but has limited expressive power (DBLP:journals/iandc/Kolaitis91, ). Gelfond and Lifschitz (DBLP:conf/iclp/GelfondL88, ) introduced stable model semantics, which has been used in constraint satisfaction systems like DLV (DBLP:journals/tocl/LeonePFEGPS06, ), but has high data complexity, making it unsuitable for large scale data analytics. One possibility is to simply allow the ICO to be non-monotone (DBLP:journals/jcss/KolaitisP91, ), but this leads to an operational, non-declarative semantics. The extension most related to our paper is the well-founded semantics, introduced by Van Gelder et al. (DBLP:journals/jacm/GelderRS91, ), and refined in (DBLP:conf/pods/Gelder89, ; DBLP:conf/pods/Przymusinski89, ; DBLP:journals/jlp/Fitting93, ; DBLP:journals/jlp/Fitting91, ) (see the survey (DBLP:journals/tcs/Fitting02, )). This semantics can be described in terms of an alternating fixpoint (DBLP:conf/pods/Gelder89, ), and therefore it is tractable. Przymusinski (DBLP:journals/fuin/Przymusinski90, ) extended the semantics from 2-valued to 3-valued (thus, allowing atoms to be true, or false, or undefined) and proved that every program has a 3-valued well-founded model that is also the minimal 3-valued stable model. Fitting (DBLP:journals/jlp/Fitting85a, ) extended this result to allow 4-valued logics (to handle contradiction) and other bilattices. In this section we briefly review the well-founded model, and illustrate its connection to the least fixpoint semantics of datalog\text{\sf datalog}^{\circ} on the POPS THREE, introduced in Sec. 2.5.2.

7.1. Review of the Well-founded Model

Instead of a formal treatment, we prefer to describe the well-founded model on a particular example: the win-move game, which has been extensively studied in the literature as a prototypical datalog program with negation that cannot be stratified (DBLP:books/aw/AbiteboulHV95, ). Two players play the following pebble game on a graph E(X,Y)E(X,Y). The first player places the pebble on some node. Players take turn and move the pebble, which can only be moved along an edge. A player who cannot move loses. The problem is to compute the set of winning position for the first player. This set is expressed concisely by the following rule:

(67) Win(X) :-\displaystyle Win(X)\text{ :- } Y(E(X,Y)¬Win(Y))\displaystyle\exists_{Y}(E(X,Y)\wedge\neg Win(Y))

This is a datalog program with negation. Its ICO is no longer monotone, and the standard least fixpoint semantics no longer applies.

a{a}c{c}e{e}f{f}b{b}d{d}
Figure 4. Example graph with edges E={(a,b),(a,c),(b,a),(c,d)E=\{(a,b),(a,c),(b,a),(c,d), (c,e),(d,e),(e,f)}(c,e),(d,e),(e,f)\}, used for the win-move game.
\Description

Example graph with edges E={(a,b),(a,c),(b,a),(c,d)E=\{(a,b),(a,c),(b,a),(c,d), (c,e),(d,e),(e,f)}(c,e),(d,e),(e,f)\}, used for the win-move game.

The well-founded model circumvents this problem. It admits several, equivalent definitions; we follow here the alternating fixpoint semantics from (DBLP:conf/pods/Gelder89, ). Consider the grounding of the win-move program based on the graph shown in Fig. 4. To reduce clutter, we write W(X)W(X) for Win(X)Win(X), and W¯(X)\overline{W}(X) for not(Win(X))\texttt{not}(Win(X)). We also write “=” for :- . Since E(X,Y)=1E(X,Y)=1 whenever the edge (X,Y)(X,Y) is present and E(X,Y)=0E(X,Y)=0 otherwise, the grounded program is:

W(a)=(E(a,a)W¯(a))(E(a,b)W¯(b))(E(a,c)W¯(c))(E(a,d)W¯(d))(E(a,e)W¯(e))(E(a,f)W¯(f))=W¯(b)W¯(c)W(b)=(E(b,a)W¯(a))(E(b,b)W¯(b))(E(b,c)W¯(c))(E(b,d)W¯(d))(E(b,e)W¯(e))(E(b,f)W¯(f))=W¯(a)W(c)=W¯(d)W¯(e)W(d)=W¯(e)W(e)=W¯(f)W(f)=𝟎\left.\begin{array}[]{lll}W(a)&=&(E(a,a)\wedge\overline{W}(a))\vee(E(a,b)\wedge\overline{W}(b))\vee(E(a,c)\wedge\overline{W}(c))\vee(E(a,d)\wedge\overline{W}(d))\vee(E(a,e)\wedge\overline{W}(e))\vee(E(a,f)\wedge\overline{W}(f))\\ &=&\overline{W}(b)\vee\overline{W}(c)\\ W(b)&=&(E(b,a)\wedge\overline{W}(a))\vee(E(b,b)\wedge\overline{W}(b))\vee(E(b,c)\wedge\overline{W}(c))\vee(E(b,d)\wedge\overline{W}(d))\vee(E(b,e)\wedge\overline{W}(e))\vee(E(b,f)\wedge\overline{W}(f))\\ &=&\overline{W}(a)\\ W(c)&=&\overline{W}(d)\vee\overline{W}(e)\\ W(d)&=&\overline{W}(e)\\ W(e)&=&\overline{W}(f)\\ W(f)&=&\bm{0}\end{array}\right.

The rule for W(a)W(a) was obtained by substituting the existential variable YY with each node a,b,c,d,ea,b,c,d,e, then we simplified it noting that E(a,b)=E(a,c)=1E(a,b)=E(a,c)=1 and E(a,a)=E(a,d)=E(a,e)=0E(a,a)=E(a,d)=E(a,e)=0; similarly for W(b)W(b). For the other grounded rules, we show only the final, simplified form.

The alternating fixpoint semantics consists of computing a sequence J(t)J^{(t)}, t0t\geq 0 of standard, 2-valued IDB instances, where J(0)=J^{(0)}=\emptyset, and J(t+1)J^{(t+1)} is obtained by first replacing each negative atoms in every ground rule by its Boolean value according to J(t)J^{(t)}, then J(t+1)J^{(t+1)} is defined as the least fixpoint of the resulting, monotone program. In the above example, we thus get the following sequence of truth assignments:

W(a)W(b)W(c)W(d)W(e)W(f)J(0)=𝟎𝟎𝟎𝟎𝟎𝟎J(1)=𝟏𝟏𝟏𝟏𝟏𝟎J(2)=𝟎𝟎𝟎𝟎𝟏𝟎J(3)=𝟏𝟏𝟏𝟎𝟏𝟎J(4)=𝟎𝟎𝟏𝟎𝟏𝟎J(5)=𝟏𝟏𝟏𝟎𝟏𝟎=J(3)J(6)=𝟎𝟎𝟏𝟎𝟏𝟎=J(4)\displaystyle\begin{array}[]{lllllll}&W(a)&W(b)&W(c)&W(d)&W(e)&W(f)\\ \hline\cr J^{(0)}\ =&\bm{0}&\bm{0}&\bm{0}&\bm{0}&\bm{0}&\bm{0}\\ J^{(1)}\ =&\bm{1}&\bm{1}&\bm{1}&\bm{1}&\bm{1}&\bm{0}\\ J^{(2)}\ =&\bm{0}&\bm{0}&\bm{0}&\bm{0}&\bm{1}&\bm{0}\\ J^{(3)}\ =&\bm{1}&\bm{1}&\bm{1}&\bm{0}&\bm{1}&\bm{0}\\ J^{(4)}\ =&\bm{0}&\bm{0}&\bm{1}&\bm{0}&\bm{1}&\bm{0}\\ J^{(5)}\ =&\bm{1}&\bm{1}&\bm{1}&\bm{0}&\bm{1}&\bm{0}\ =\ J^{(3)}\\ J^{(6)}\ =&\bm{0}&\bm{0}&\bm{1}&\bm{0}&\bm{1}&\bm{0}\ =\ J^{(4)}\\ \end{array}

The following holds: J(0)J(2)J(4)J(5)J(3)J(1)J^{(0)}\subseteq J^{(2)}\subseteq J^{(4)}\subseteq\ldots\subseteq J^{(5)}\subseteq J^{(3)}\subseteq J^{(1)}. In other words, the even-numbered instances form an increasing chain, while the odd-numbered instances form a decreasing chain. Their limits, denote them by L=tJ(2t)L=\bigcup_{t}J^{(2t)} and G=tJ(2t+1)G=\bigcap_{t}J^{(2t+1)}, are the least fixpoint and the greatest fixpoint respectively, of a certain monotone program, see (DBLP:conf/pods/Gelder89, ). The well-founded model is defined as consisting of all positive literals in LL, and all negative literals missing from GG. In our example, the well-founded model is {W(c),W(e),W¯(d),W¯(f)}\{W(c),W(e),\overline{W}(d),\overline{W}(f)\}, because L=J(4)={W(c),W(e)}L=J^{(4)}=\{W(c),W(e)\} and G=J(3)={W(a),W(b),W(c),W(e)}G=J^{(3)}=\{W(a),W(b),W(c),W(e)\}, and its complement is {W(d),W(f)}\{W(d),W(f)\}. Alternatively, the well-founded model can be described as assigning the value 1 to the atoms W(c),W(e)W(c),W(e), the value 0 to the atoms W(d),W(f)W(d),W(f), and the value \bot (undefined) to W(a),W(b)W(a),W(b).

7.2. The POPS THREE

Building on earlier work by Przymusinski (DBLP:journals/fuin/Przymusinski90, ), Fitting (DBLP:journals/jlp/Fitting85a, ) describes the following three-valued semantics of logic programs with negation. Starting from Kleene’s 3-valued logic {0,0.5,0}\{0,0.5,0\}, where ,,¬\vee,\wedge,\neg are max,min,1x\max,\min,1-x respectively (DBLP:journals/logcom/Fitting91, ), he defined two order relations on the set THREE ={,0,1}=\{\bot,0,1\}:

The truth order: 0t\displaystyle 0\leq_{t} t1\displaystyle\bot\leq_{t}1
The knowledge order: k\displaystyle\bot\leq_{k} 0 k1\displaystyle 0\mbox{\hskip 28.45274pt}\bot\leq_{k}1

The truth order is the same order as in Kleene’s 3-valued logic, and, for this purpose, the value \bot can be interpreted as 0.50.5. This is also the standard 3-valued logic used in SQL. Fitting argued that, instead of interpreting logic programs using the truth order, where negation is not monotone, one should interpret them using the knowledge order, where negation is monotone.

Fitting’s semantics coincides, sometimes, with the well-founded model. It also coincides with the least fixpoint of datalog\text{\sf datalog}^{\circ} interpreted over the POPS THREE, and we illustrate next. Recall from Sec. 2.5.2 that THREE=def({,0,1},,,0,1,k)\texttt{THREE}\stackrel{{\scriptstyle\text{def}}}{{=}}(\{\bot,0,1\},\vee,\wedge,0,1,\leq_{k}), is a POPS where the semiring operations are the lub \vee and the glb \wedge of the truth order, and where the order relation is the knowledge order k\leq_{k}. In particular, we have x𝟎=𝟎x\wedge\bm{0}=\bm{0} and x𝟏=𝟏x\vee\bm{1}=\bm{1} for every xx including x=x=\bot. Hence, \wedge is absorbing, i.e., THREE constitutes a semiring and should not to be confused with the POPS 𝔹=def𝔹{}\mathbb{B}_{\bot}\stackrel{{\scriptstyle\text{def}}}{{=}}\mathbb{B}\cup\{\bot\} that we get by lifting the Booleans analogously to lifting the integers and reals to \mathbb{N}_{\bot} and \mathbb{R}_{\bot}, respectively.

The following datalog\text{\sf datalog}^{\circ} program is the win-move game (67) over the POPS THREE:

Win(Y) :-\displaystyle Win(Y)\text{ :- } YE(X,Y)𝚗𝚘𝚝(Win(Y))\displaystyle\bigoplus_{Y}E(X,Y)\wedge\mathtt{not}(Win(Y))

Here, 𝚗𝚘𝚝\mathtt{not} is a monotone function w.r.t. k\leq_{k} defined as 𝚗𝚘𝚝(𝟎)=𝟏\mathtt{not}(\bm{0})=\bm{1}, 𝚗𝚘𝚝(𝟏)=𝟎\mathtt{not}(\bm{1})=\bm{0}, and 𝚗𝚘𝚝()=\mathtt{not}(\bot)=\bot. The fixpoint semantics computes a sequence of IDB instances W(0)W(1)W(2)W^{(0)}\sqsubseteq W^{(1)}\sqsubseteq W^{(2)}\sqsubseteq\cdots, shown here:

W(a)W(b)W(c)W(d)W(e)W(f)W(0)=W(1)=𝟎W(2)=𝟏𝟎W(3)=𝟎𝟏𝟎W(4)=𝟏𝟎𝟏𝟎=W(5)\displaystyle\begin{array}[]{lllllll}&W(a)&W(b)&W(c)&W(d)&W(e)&W(f)\\ \hline\cr W^{(0)}\ =&\bot&\bot&\bot&\bot&\bot&\bot\\ W^{(1)}\ =&\bot&\bot&\bot&\bot&\bot&\bm{0}\\ W^{(2)}\ =&\bot&\bot&\bot&\bot&\bm{1}&\bm{0}\\ W^{(3)}\ =&\bot&\bot&\bot&\bm{0}&\bm{1}&\bm{0}\\ W^{(4)}\ =&\bot&\bot&\bm{1}&\bm{0}&\bm{1}&\bm{0}\ =\ W^{(5)}\end{array}

The least fixpoint W(4)W^{(4)}, is the same as the well-founded model of the win-move program (67).

7.3. Discussion

It should be noted that Fitting’s 3-valued interpretation of logic programs (and, likewise, datalog\text{\sf datalog}^{\circ} over the POPS THREE) does not always yield the well-founded semantics. In fact, in general, it does not even coincide with the minimal model semantics of datalog without negation. To see this, consider the following datalog program (or, equivalently, datalog\text{\sf datalog}^{\circ} program).

P(a) :-\displaystyle P(a)\text{ :- } P(a)\displaystyle P(a)

In the minimal model of this datalog program (and, equivalently, when considering this datalog\text{\sf datalog}^{\circ} program over the POPS 𝔹\mathbb{B}), we have P(a)=𝟎P(a)=\bm{0}. In contrast, Fitting’s 3-valued semantics (and, equivalently, datalog\text{\sf datalog}^{\circ} over the POPS THREE) yields P(a)=P(a)=\bot. In (DBLP:journals/tcs/Fitting02, ), Fitting asks “Which is the ‘right’ choice?” and he observes that a case can be made both for setting P(a)=𝟎P(a)=\bm{0} and for setting P(a)=P(a)=\bot. He thus concludes that the “intended applications probably should decide.”

In (DBLP:journals/jlp/Fitting91, ; DBLP:journals/jlp/Fitting93, ), Fitting further extended his approach to Belnap’s four-valued logic FOUR and, more generally, to arbitrary bilattices. FOUR =({,𝟎,𝟏,},t,k)=(\{\bot,\bm{0},\bm{1},\top\},\leq_{t},\leq_{k}) constitutes the simplest non-trivial, complete bilattice, where the additional truth value \top denotes “both false and true”. We thus have a complete lattice both w.r.t. the truth order 𝟎t,t𝟏\bm{0}\leq_{t}\bot,\top\leq_{t}\bm{1} and w.r.t. the knowledge order k𝟎,𝟏k\bot\leq_{k}\bm{0},\bm{1}\leq_{k}\top, which are visualized in Fig. 5 (cf. (DBLP:journals/jlp/Fitting91, ), Fig. 1). The not function is readily extended to \top by setting 𝚗𝚘𝚝()=\mathtt{not}(\top)=\top. It can be shown that the additional truth value \top has no effect on the fixpoint iteration w.r.t. k\leq_{k} that we considered above for the POPS THREE. In fact, Fitting showed that \top can never occur as truth value in the least fixpoint w.r.t. k\leq_{k} (cf. (DBLP:journals/jlp/Fitting91, ), Proposition 7.1). We note that FOUR is also a POPS, where the semiring operations ,\oplus,\otimes are the glb and lub of the truth order, and the partial order of the POPS is the knowledge order.

{diagram}
Figure 5. Orders k\leq_{k} and t\leq_{t} in the bilattice FOUR (DBLP:journals/jlp/Fitting91, )
\Description

Orders k\leq_{k} and t\leq_{t} in the bilattice FOUR (DBLP:journals/jlp/Fitting91, )

8. Related Work

To empower Datalog, researchers have proposed amendments to make datalog capable of expressing some problems with greedy solutions such as APSP and MST (Minimum Spanning Tree). Most notably, the non-deterministic choice construct was extensively studied early on (MR1842100, ; DBLP:conf/pods/GrecoZG92, ; DBLP:conf/icdt/GrecoSZ95, ). While datalog+choice is powerful, its expression and semantics are somewhat clunky, geared towards answering optimization questions (greedily). In particular, it was not designed to deal with general aggregations.

To evaluate recursive datalog\text{\sf datalog}^{\circ} program is to solve fixpoint equations over semirings, which was studied in the automata theory (MR1470001, ), program analysis (DBLP:conf/popl/CousotC77, ; MR1728440, ), and graph algorithms (MR556411, ; MR584516, ; MR526496, ) communities since the 1970s. (See (MR1059930, ; DBLP:conf/lics/HopkinsK99, ; DBLP:journals/tcs/Lehmann77, ; semiring_book, ; MR609751, ) and references therein). The problem took slightly different forms in these domains, but at its core, it is to find a solution to the equation 𝒙=𝒇(𝒙)\bm{x}=\bm{f}(\bm{x}), where 𝒙𝑺n\bm{x}\in\bm{S}^{n} is a vector over the domain 𝑺\bm{S} of a semiring, and 𝒇:𝑺n𝑺n\bm{f}:\bm{S}^{n}\to\bm{S}^{n} has multivariate polynomial component functions.

When 𝒇\bm{f} is affine (what we called linear in this paper), researchers realized that many problems in different domains are instances of the same problem, with the same underlying algebraic structure: transitive closure (DBLP:journals/jacm/Warshall62, ), shortest paths (DBLP:journals/cacm/Floyd62a, ), Kleene’s theorem on finite automata and regular languages (MR0077478, ), continuous dataflow (DBLP:conf/popl/CousotC77, ; DBLP:journals/jacm/KamU76, ), etc. Furthermore, these problems share the same characteristic as the problem of computing matrix inverse (MR427338, ; tarjan1, ; MR371724, ). The problem is called the algebraic path problem (MR1059930, ), among other names, and the main task is to solve the matrix fixpoint equation X=AX+IX=AX+I over a semiring.

There are several classes of solutions to the algebraic path problem, which have pros and cons depending on what we can assume about the underlying semiring (whether or not there is a closure operator, idempotency, natural orderability, etc.). We refer the reader to (semiring_book, ; MR1059930, ) for more detailed discussions. Here, we briefly summarize the main approaches.

The first approach is to keep iterating until a fixpoint is reached; in different contexts, this has different names: the naïve algorithm, Jacobi iteration, Gauss-Seidel iteration, or Kleene iteration. The main advantage of this approach is that it assumes less about the underlying algebraic structure: we do not need both left and right distributive law, and do not need to assume a closure operator.

The second approach is based on Gaussian elimination (also, Gauss-Jordan elimination), which, assuming we have oracle access to the solution xx^{*} of the 1D problem x=1+axx=1+ax, can solve the algebraic path problem in O(n3)O(n^{3})-time (MR1059930, ; DBLP:journals/tcs/Lehmann77, ).

The third approach is based on specifying the solutions based on the free semiring generated when viewing 𝑨\bm{A} as the adjacency matrix of a graph (DBLP:journals/jacm/Tarjan81a, ). The underlying graph structure (such as planarity) may sometimes be exploited for very efficient algorithms (MR584516, ; MR526496, ).

Beyond the affine case, since the 1960s researchers in formal languages have been studying the structure of the fixpoint solution to x=f(x)x=f(x) when ff’s component functions are multivariate polynomials over the Kleene algebra (MR339568, ; MR209093, ; MR912710, ). It is known, for example, that Kleene iteration does not always converge (in a finite number of steps), and thus methods based on Galois connection or on widening/narrowing approaches (MR1252194, ) were studied. These approaches are (discrete) lattice-theoretic. More recently, a completely different approach drawing inspiration from Newton’s method for solving a system of (real) equations was proposed (DBLP:conf/lics/HopkinsK99, ; DBLP:journals/jacm/EsparzaKL10, ).

Recall that Newton’s method for solving a system of equations g(x)=0g(x)=0 over reals is to start from some point x0x_{0}, and at time tt we take the first order approximation g(x)gt(x):=g(xt)+g(xt)(xxt)g(x)\approx g_{t}(x):=g(x_{t})+g^{\prime}(x_{t})(x-x_{t}), and set xt+1x_{t+1} to be the solution of gt(x)=0g_{t}(x)=0, i.e. xt+1=xt[g(xt)]1g(xt)x_{t+1}=x_{t}-[g^{\prime}(x_{t})]^{-1}g(x_{t}). Note that in the multivariate case gg^{\prime} is the Jacobian, and [g(xt)]1[g^{\prime}(x_{t})]^{-1} is to compute matrix inverse. In beautiful papers, Esparza et al. (DBLP:journals/jacm/EsparzaKL10, ) and Hopkins and Kozen (DBLP:conf/lics/HopkinsK99, ) were able to generalize this idea to the case when g(x)=f(x)xg(x)=f(x)-x is defined over ω\omega-continuous semirings. They were able to define an appropriate minus operator, derivatives of power series over semirings, matrix inverse, and prove that the method converges at least as fast as Kleene iteration, and there are examples where Kleene iteration does not converge, while Newton’s method does. Furthermore, if the semiring is commutative and idempotent (in addition to being ω\omega-continuous), then Newton’s method always converges in nn Newton steps. Each Newton step involves computing the Jacobian gg^{\prime} and computing its inverse, which is exactly the algebraic path problem!

Recently, semi-naïve evaluation has been extended for a higher-order functional language called Datafun (DBLP:journals/pacmpl/ArntzeniusK20, ). The book (semiring_book, ) contains many fundamental results on algebraic structures related to semirings and computational problems on such structures.

9. Conclusions

A massive number of application domains demand us to move beyond the confine of the Boolean world: from program analysis (DBLP:conf/popl/CousotC77, ; MR1728440, ), graph algorithms (MR556411, ; MR584516, ; MR526496, ), provenance (DBLP:conf/pods/GreenKT07, ), formal language theory (MR1470001, ), to machine learning and linear algebra (einsum:rocktaschel, ; DBLP:conf/osdi/AbadiBCCDDDGIIK16, ). Semiring and poset theory – of which POPS is an instance – is the natural bridge connecting the Boolean island to these applications.

The bridge helps enlarge the set of problems datalog\text{\sf datalog}^{\circ} can express in a very natural way. The possibilities are endless. For example, amending datalog\text{\sf datalog}^{\circ} with an interpreted function such as sigmoid will allow it to express typical neural network computations. Adding another semiring to the query language (in the sense of FAQ (DBLP:conf/pods/KhamisNR16, )) helps express rectilinear units in modern deep learning. At the same time, the bridge facilitates the porting of analytical ideas from datalog to analyze convergence properties of the application problems, and to carry over optimization techniques such as semi-naïve evaluation.

This paper established part of the bridge. There are many interesting problems left open; we mention a few here.

The question of whether a datalog\text{\sf datalog}^{\circ} program over pp-stable POPS converges in polynomial time in pp and the size of the input database is open. This is open even for linear programs. Our result on Tropp\text{\sf Trop}_{p} in Sec. 5 indicates that the linear case is likely in PTIME.

We have discussed in Sec. 4 several extensions to datalog\text{\sf datalog}^{\circ} that we believe are necessary in practice. It remains open whether our convergence results continue to hold for those extensions.

Two of the most important extensions of datalog / logic programming are concerned with negation and aggregation. Various semantics have been proposed in the literature for these extensions, see (DBLP:journals/logcom/LiuS20, ) and (DBLP:journals/logcom/LiuS22, ) for overviews of the various approaches. As discussed in Sec. 7, negation can be added to datalog\text{\sf datalog}^{\circ} as an interpreted predicate. In particular, Fitting’s three-valued semantics (DBLP:journals/jlp/Fitting85a, ) of datalog with negation can thus be naturally captured in datalog\text{\sf datalog}^{\circ} by an appropriate choice of the POPS. However, the question remains if we can also extend results for other semantics (above all well-founded semantics (DBLP:journals/jacm/GelderRS91, ) and stable model semantics (DBLP:conf/iclp/GelfondL88, )) from general datalog / logic programming to datalog\text{\sf datalog}^{\circ} with negation.

The extension of datalog with aggregation was one of the original motivations for considering datalog over semirings (DBLP:conf/pods/RossS92, ). Analogously to datalog with negation, also for datalog with aggregation, several semantics have been proposed (DBLP:journals/logcom/LiuS22, ). Again, it remains a question for future work if we can extend our results on datalog\text{\sf datalog}^{\circ} to the various semantics of datalog with aggregation.

More generally, a systematic study of the expressive power of datalog\text{\sf datalog}^{\circ} is left for future work. While we have powerful tools (see, e.g., (DBLP:books/sp/Libkin04, )) for analysing the expressive power of various logics (or, equivalently, of various query languages over the Boolean semiring) and pinpointing their limits, the formal study of the expressive of query languages over semirings has barely started. In their recent work (DBLP:journals/corr/abs-2308-04910, ), Brinke et al. have extended Ehrenfeucht-Fraïssé games to first-order logic over semirings. The extension of such tools to other query languages over semirings, including datalog\text{\sf datalog}^{\circ}, would be a natural next step.

Beyond exact solution and finite convergence, as mentioned in the introduction, it is natural in some domain applications to have approximate fixpoint solutions, which will allow us to trade off convergence time and solution quality. A theoretical framework along this line will go a long way towards making datalog\text{\sf datalog}^{\circ} deal with real machine learning, linear algebra, and optimization problems.

Acknowledgements.
Suciu and Wang were partially supported by NSF IIS 1907997 and NSF IIS 1954222. Pichler was supported by the Austrian Science Fund (FWF):P30930 and by the Vienna Science and Technology Fund (WWTF) [10.47379/ICT2201].

References

  • (1) Abadi, M., Barham, P., Chen, J., Chen, Z., Davis, A., Dean, J., Devin, M., Ghemawat, S., Irving, G., Isard, M., Kudlur, M., Levenberg, J., Monga, R., Moore, S., Murray, D. G., Steiner, B., Tucker, P. A., Vasudevan, V., Warden, P., Wicke, M., Yu, Y., and Zheng, X. Tensorflow: A system for large-scale machine learning. In 12th USENIX Symposium on Operating Systems Design and Implementation, OSDI 2016, Savannah, GA, USA, November 2-4, 2016 (2016), K. Keeton and T. Roscoe, Eds., USENIX Association, pp. 265–283.
  • (2) Abiteboul, S., Hull, R., and Vianu, V. Foundations of Databases. Addison-Wesley, 1995.
  • (3) Abo Khamis, M., Ngo, H. Q., Pichler, R., Suciu, D., and Wang, Y. R. Convergence of datalog over (pre-) semirings. In PODS ’22: International Conference on Management of Data, Philadelphia, PA, USA, June 12 - 17, 2022 (2022), L. Libkin and P. Barceló, Eds., ACM, pp. 105–117.
  • (4) Abo Khamis, M., Ngo, H. Q., and Rudra, A. FAQ: questions asked frequently. In Proceedings of the 35th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, PODS 2016, San Francisco, CA, USA, June 26 - July 01, 2016 (2016), T. Milo and W. Tan, Eds., ACM, pp. 13–28.
  • (5) Aji, S. M., and McEliece, R. J. The generalized distributive law. IEEE Trans. Inf. Theory 46, 2 (2000), 325–343.
  • (6) Arntzenius, M., and Krishnaswami, N. Seminaïve evaluation for a higher-order functional language. Proc. ACM Program. Lang. 4, POPL (2020), 22:1–22:28.
  • (7) Backhouse, R. C., and Carré, B. A. Regular algebra applied to path-finding problems. J. Inst. Math. Appl. 15 (1975), 161–186.
  • (8) Brinke, S., Grädel, E., and Mrkonjic, L. Ehrenfeucht-fraïssé games in semiring semantics. CoRR abs/2308.04910 (2023).
  • (9) Carré, B. Graphs and networks. The Clarendon Press, Oxford University Press, New York, 1979. Oxford Applied Mathematics and Computing Science Series.
  • (10) Codd, E. F. A relational model of data for large shared data banks. Commun. ACM 13, 6 (1970), 377–387.
  • (11) Condie, T., Das, A., Interlandi, M., Shkapsky, A., Yang, M., and Zaniolo, C. Scaling-up reasoning and advanced analytics on bigdata. Theory Pract. Log. Program. 18, 5-6 (2018), 806–845.
  • (12) Cousot, P., and Cousot, R. Abstract interpretation: A unified lattice model for static analysis of programs by construction or approximation of fixpoints. In Conference Record of the Fourth ACM Symposium on Principles of Programming Languages, Los Angeles, California, USA, January 1977 (1977), R. M. Graham, M. A. Harrison, and R. Sethi, Eds., ACM, pp. 238–252.
  • (13) Cousot, P., and Cousot, R. Comparing the Galois connection and widening/narrowing approaches to abstract interpretation. In Programming language implementation and logic programming (Leuven, 1992), vol. 631 of Lecture Notes in Comput. Sci. Springer, Berlin, 1992, pp. 269–295.
  • (14) Creignou, N., Kolaitis, P. G., and Vollmer, H., Eds. Complexity of Constraints - An Overview of Current Research Themes [Result of a Dagstuhl Seminar] (2008), vol. 5250 of Lecture Notes in Computer Science, Springer.
  • (15) Dannert, K. M., Grädel, E., Naaf, M., and Tannen, V. Semiring provenance for fixed-point logic. In 29th EACSL Annual Conference on Computer Science Logic, CSL 2021, January 25-28, 2021, Ljubljana, Slovenia (Virtual Conference) (2021), C. Baier and J. Goubault-Larrecq, Eds., vol. 183 of LIPIcs, Schloss Dagstuhl - Leibniz-Zentrum für Informatik, pp. 17:1–17:22.
  • (16) Das, A., Li, Y., Wang, J., Li, M., and Zaniolo, C. Bigdata applications from graph analytics to machine learning by aggregates in recursion. In Proceedings 35th International Conference on Logic Programming (Technical Communications), ICLP 2019 Technical Communications, Las Cruces, NM, USA, September 20-25, 2019 (2019), B. Bogaerts, E. Erdem, P. Fodor, A. Formisano, G. Ianni, D. Inclezan, G. Vidal, A. Villanueva, M. D. Vos, and F. Yang, Eds., vol. 306 of EPTCS, pp. 273–279.
  • (17) Davey, B. A., and Priestley, H. A. Introduction to lattices and order. Cambridge University Press, Cambridge, 1990.
  • (18) Dechter, R. Bucket elimination: a unifying framework for processing hard and soft constraints. Constraints An Int. J. 2, 1 (1997), 51–55.
  • (19) Esparza, J., Kiefer, S., and Luttenberger, M. Newtonian program analysis. J. ACM 57, 6 (2010), 33:1–33:47.
  • (20) Fitting, M. A kripke-kleene semantics for logic programs. J. Log. Program. 2, 4 (1985), 295–312.
  • (21) Fitting, M. Bilattices and the semantics of logic programming. J. Log. Program. 11, 1&2 (1991), 91–116.
  • (22) Fitting, M. Kleene’s logic, generalized. J. Log. Comput. 1, 6 (1991), 797–810.
  • (23) Fitting, M. The family of stable models. J. Log. Program. 17, 2/3&4 (1993), 197–225.
  • (24) Fitting, M. Fixpoint semantics for logic programming a survey. Theor. Comput. Sci. 278, 1-2 (2002), 25–51.
  • (25) Floyd, R. W. Algorithm 97: Shortest path. Commun. ACM 5, 6 (1962), 345.
  • (26) Ganguly, S., Greco, S., and Zaniolo, C. Minimum and maximum predicates in logic programming. In Proceedings of the Tenth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, May 29-31, 1991, Denver, Colorado, USA (1991), D. J. Rosenkrantz, Ed., ACM Press, pp. 154–163.
  • (27) Ganguly, S., Greco, S., and Zaniolo, C. Extrema predicates in deductive databases. J. Comput. Syst. Sci. 51, 2 (1995), 244–259.
  • (28) Gelder, A. V. The alternating fixpoint of logic programs with negation. In Proceedings of the Eighth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, March 29-31, 1989, Philadelphia, Pennsylvania, USA (1989), A. Silberschatz, Ed., ACM Press, pp. 1–10.
  • (29) Gelder, A. V., Ross, K. A., and Schlipf, J. S. The well-founded semantics for general logic programs. J. ACM 38, 3 (1991), 620–650.
  • (30) Gelfond, M., and Lifschitz, V. The stable model semantics for logic programming. In Logic Programming, Proceedings of the Fifth International Conference and Symposium, Seattle, Washington, USA, August 15-19, 1988 (2 Volumes) (1988), R. A. Kowalski and K. A. Bowen, Eds., MIT Press, pp. 1070–1080.
  • (31) Gondran, M. Algèbre linéaire et cheminement dans un graphe. Rev. Française Automat. Informat. Recherche Opérationnelle Sér. Verte 9, V-1 (1975), 77–99.
  • (32) Gondran, M. Les elements p-reguliers dans les dioïdes. Discret. Math. 25, 1 (1979), 33–39.
  • (33) Gondran, M., and Minoux, M. Graphs, dioids and semirings, vol. 41 of Operations Research/Computer Science Interfaces Series. Springer, New York, 2008. New models and algorithms.
  • (34) Greco, S., Saccà, D., and Zaniolo, C. DATALOG queries with stratified negation and choice: from P to dp{}^{\mbox{p}}. In Database Theory - ICDT’95, 5th International Conference, Prague, Czech Republic, January 11-13, 1995, Proceedings (1995), G. Gottlob and M. Y. Vardi, Eds., vol. 893 of Lecture Notes in Computer Science, Springer, pp. 82–96.
  • (35) Greco, S., and Zaniolo, C. Greedy algorithms in Datalog. Theory Pract. Log. Program. 1, 4 (2001), 381–407.
  • (36) Greco, S., Zaniolo, C., and Ganguly, S. Greedy by choice. In Proceedings of the Eleventh ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, June 2-4, 1992, San Diego, California, USA (1992), M. Y. Vardi and P. C. Kanellakis, Eds., ACM Press, pp. 105–113.
  • (37) Green, T. J., Huang, S. S., Loo, B. T., and Zhou, W. Datalog and recursive query processing. Found. Trends Databases 5, 2 (2013), 105–195.
  • (38) Green, T. J., Karvounarakis, G., and Tannen, V. Provenance semirings. In Proceedings of the Twenty-Sixth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, June 11-13, 2007, Beijing, China (2007), L. Libkin, Ed., ACM, pp. 31–40.
  • (39) Gu, J., Watanabe, Y. H., Mazza, W. A., Shkapsky, A., Yang, M., Ding, L., and Zaniolo, C. Rasql: Greater power and performance for big data analytics with recursive-aggregate-sql on spark. In Proceedings of the 2019 International Conference on Management of Data, SIGMOD Conference 2019, Amsterdam, The Netherlands, June 30 - July 5, 2019 (2019), P. A. Boncz, S. Manegold, A. Ailamaki, A. Deshpande, and T. Kraska, Eds., ACM, pp. 467–484.
  • (40) Gunawardena, J. An introduction to idempotency. In Idempotency (Bristol, 1994), vol. 11 of Publ. Newton Inst. Cambridge Univ. Press, Cambridge, 1998, pp. 1–49.
  • (41) Hopkins, M. W., and Kozen, D. Parikh’s theorem in commutative kleene algebra. In 14th Annual IEEE Symposium on Logic in Computer Science, Trento, Italy, July 2-5, 1999 (1999), IEEE Computer Society, pp. 394–401.
  • (42) Jordan, H., Scholz, B., and Subotic, P. Soufflé: On synthesis of program analyzers. In Computer Aided Verification - 28th International Conference, CAV 2016, Toronto, ON, Canada, July 17-23, 2016, Proceedings, Part II (2016), S. Chaudhuri and A. Farzan, Eds., vol. 9780 of Lecture Notes in Computer Science, Springer, pp. 422–430.
  • (43) Kam, J. B., and Ullman, J. D. Global data flow analysis and iterative algorithms. J. ACM 23, 1 (1976), 158–171.
  • (44) Kleene, S. C. Representation of events in nerve nets and finite automata. In Automata studies, Annals of mathematics studies, no. 34. Princeton University Press, Princeton, N. J., 1956, pp. 3–41.
  • (45) Koch, C., Ahmad, Y., Kennedy, O., Nikolic, M., Nötzli, A., Lupei, D., and Shaikhha, A. Dbtoaster: higher-order delta processing for dynamic, frequently fresh views. VLDB J. 23, 2 (2014), 253–278.
  • (46) Kohlas, J. Information algebras - generic structures for inference. Discrete mathematics and theoretical computer science. Springer, 2003.
  • (47) Kohlas, J., and Wilson, N. Semiring induced valuation algebras: Exact and approximate local computation algorithms. Artif. Intell. 172, 11 (2008), 1360–1399.
  • (48) Kolaitis, P. G. The expressive power of stratified programs. Inf. Comput. 90, 1 (1991), 50–66.
  • (49) Kolaitis, P. G., and Papadimitriou, C. H. Why not negation by fixpoint? J. Comput. Syst. Sci. 43, 1 (1991), 125–144.
  • (50) Kuich, W. The Kleene and the Parikh theorem in complete semirings. In Automata, languages and programming (Karlsruhe, 1987), vol. 267 of Lecture Notes in Comput. Sci. Springer, Berlin, 1987, pp. 212–225.
  • (51) Kuich, W. Semirings and formal power series: their relevance to formal languages and automata. In Handbook of formal languages, Vol. 1. Springer, Berlin, 1997, pp. 609–677.
  • (52) Lehmann, D. J. Algebraic structures for transitive closure. Theor. Comput. Sci. 4, 1 (1977), 59–76.
  • (53) Leone, N., Pfeifer, G., Faber, W., Eiter, T., Gottlob, G., Perri, S., and Scarcello, F. The DLV system for knowledge representation and reasoning. ACM Trans. Comput. Log. 7, 3 (2006), 499–562.
  • (54) Libkin, L. Elements of Finite Model Theory. Texts in Theoretical Computer Science. An EATCS Series. Springer, 2004.
  • (55) Lipton, R. J., Rose, D. J., and Tarjan, R. E. Generalized nested dissection. SIAM J. Numer. Anal. 16, 2 (1979), 346–358.
  • (56) Lipton, R. J., and Tarjan, R. E. Applications of a planar separator theorem. SIAM J. Comput. 9, 3 (1980), 615–627.
  • (57) Liu, Y. A., and Stoller, S. D. Founded semantics and constraint semantics of logic rules. J. Log. Comput. 30, 8 (2020), 1609–1668.
  • (58) Liu, Y. A., and Stoller, S. D. Recursive rules with aggregation: a simple unified semantics. J. Log. Comput. 32, 8 (2022), 1659–1693.
  • (59) Luttenberger, M., and Schlund, M. Convergence of newton’s method over commutative semirings. Inf. Comput. 246 (2016), 43–61.
  • (60) Maier, D., Tekle, K. T., Kifer, M., and Warren, D. S. Datalog: concepts, history, and outlook. In Declarative Logic Programming: Theory, Systems, and Applications, M. Kifer and Y. A. Liu, Eds. ACM / Morgan & Claypool, 2018, pp. 3–100.
  • (61) Mazuran, M., Serra, E., and Zaniolo, C. Extending the power of datalog recursion. VLDB J. 22, 4 (2013), 471–493.
  • (62) McSherry, F. Recursion in materialize. https://github.com/frankmcsherry/blog/blob/master/posts/2022-12-25.md, 2022. Accessed: December 2022.
  • (63) Nielson, F., Nielson, H. R., and Hankin, C. Principles of program analysis. Springer-Verlag, Berlin, 1999.
  • (64) Nocedal, J., and Wright, S. J. Numerical Optimization. Springer, 1999.
  • (65) Parikh, R. J. On context-free languages. J. Assoc. Comput. Mach. 13 (1966), 570–581.
  • (66) Pilling, D. L. Commutative regular equations and Parikh’s theorem. J. London Math. Soc. (2) 6 (1973), 663–666.
  • (67) Przymusinski, T. C. Every logic program has a natural stratification and an iterated least fixed point model. In Proceedings of the Eighth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, March 29-31, 1989, Philadelphia, Pennsylvania, USA (1989), A. Silberschatz, Ed., ACM Press, pp. 11–21.
  • (68) Przymusinski, T. C. The well-founded semantics coincides with the three-valued stable semantics. Fundam. Inform. 13, 4 (1990), 445–463.
  • (69) Reps, T. W., Turetsky, E., and Prabhu, P. Newtonian program analysis via tensor product. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, January 20 - 22, 2016 (2016), R. Bodík and R. Majumdar, Eds., ACM, pp. 663–677.
  • (70) Rocktäschel, T. Einsum is all you need - Einstein summation in deep learning. https://rockt.github.io/2018/04/30/einsum.
  • (71) Ross, K. A., and Sagiv, Y. Monotonic aggregation in deductive databases. In Proceedings of the Eleventh ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, June 2-4, 1992, San Diego, California, USA (1992), M. Y. Vardi and P. C. Kanellakis, Eds., ACM Press, pp. 114–126.
  • (72) Rote, G. Path problems in graphs. In Computational graph theory, vol. 7 of Comput. Suppl. Springer, Vienna, 1990, pp. 155–189.
  • (73) Shenoy, P. P., and Shafer, G. Axioms for probability and belief-function proagation. In UAI ’88: Proceedings of the Fourth Annual Conference on Uncertainty in Artificial Intelligence, Minneapolis, MN, USA, July 10-12, 1988 (1988), R. D. Shachter, T. S. Levitt, L. N. Kanal, and J. F. Lemmer, Eds., North-Holland, pp. 169–198.
  • (74) Shkapsky, A., Yang, M., Interlandi, M., Chiu, H., Condie, T., and Zaniolo, C. Big data analytics with datalog queries on spark. In Proceedings of the 2016 International Conference on Management of Data, SIGMOD Conference 2016, San Francisco, CA, USA, June 26 - July 01, 2016 (2016), pp. 1135–1149.
  • (75) Shkapsky, A., Yang, M., and Zaniolo, C. Optimizing recursive queries with monotonic aggregates in deals. In 31st IEEE International Conference on Data Engineering, ICDE 2015, Seoul, South Korea, April 13-17, 2015 (2015), J. Gehrke, W. Lehner, K. Shim, S. K. Cha, and G. M. Lohman, Eds., IEEE Computer Society, pp. 867–878.
  • (76) Stanley, R. P. Enumerative combinatorics. Vol. 2, vol. 62 of Cambridge Studies in Advanced Mathematics. Cambridge University Press, Cambridge, 1999. With a foreword by Gian-Carlo Rota and appendix 1 by Sergey Fomin.
  • (77) Tarjan, R. E. Graph theory and gaussian elimination, 1976. J.R. Bunch and D.J. Rose, eds.
  • (78) Tarjan, R. E. A unified approach to path problems. J. ACM 28, 3 (1981), 577–593.
  • (79) Vardi, M. Y. The complexity of relational query languages (extended abstract). In Proceedings of the 14th Annual ACM Symposium on Theory of Computing, May 5-7, 1982, San Francisco, California, USA (1982), H. R. Lewis, B. B. Simons, W. A. Burkhard, and L. H. Landweber, Eds., ACM, pp. 137–146.
  • (80) Vianu, V. Datalog unchained. In PODS’21: Proceedings of the 40th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, Virtual Event, China, June 20-25, 2021 (2021), L. Libkin, R. Pichler, and P. Guagliardo, Eds., ACM, pp. 57–69.
  • (81) Wang, Y. R., Abo Khamis, M., Ngo, H. Q., Pichler, R., and Suciu, D. Optimizing recursive queries with progam synthesis. In SIGMOD ’22: International Conference on Management of Data, Philadelphia, PA, USA, June 12 - 17, 2022 (2022), Z. Ives, A. Bonifati, and A. E. Abbadi, Eds., ACM, pp. 79–93.
  • (82) Warshall, S. A theorem on boolean matrices. J. ACM 9, 1 (1962), 11–12.
  • (83) Zaniolo, C., Das, A., Gu, J., Li, Y., Li, M., and Wang, J. Monotonic properties of completed aggregates in recursive queries. CoRR abs/1910.08888 (2019).
  • (84) Zaniolo, C., Das, A., Gu, J., Li, Y., Li, M., and Wang, J. Developing big-data application as queries: an aggregate-based approach. IEEE Data Eng. Bull. 44, 2 (2021), 3–13.
  • (85) Zaniolo, C., Yang, M., Das, A., and Interlandi, M. The magic of pushing extrema into recursion: Simple, powerful datalog programs. In Proceedings of the 10th Alberto Mendelzon International Workshop on Foundations of Data Management, Panama City, Panama, May 8-10, 2016 (2016), R. Pichler and A. S. da Silva, Eds., vol. 1644 of CEUR Workshop Proceedings, CEUR-WS.org.
  • (86) Zaniolo, C., Yang, M., Das, A., Shkapsky, A., Condie, T., and Interlandi, M. Fixpoint semantics and optimization of recursive datalog programs with aggregates. Theory Pract. Log. Program. 17, 5-6 (2017), 1048–1065.
  • (87) Zaniolo, C., Yang, M., Interlandi, M., Das, A., Shkapsky, A., and Condie, T. Declarative bigdata algorithms via aggregates and relational database dependencies. In Proceedings of the 12th Alberto Mendelzon International Workshop on Foundations of Data Management, Cali, Colombia, May 21-25, 2018 (2018), D. Olteanu and B. Poblete, Eds., vol. 2100 of CEUR Workshop Proceedings, CEUR-WS.org.
  • (88) Zimmermann, U. Linear and combinatorial optimization in ordered algebraic structures. Ann. Discrete Math. 10 (1981), viii+380.

APPENDIX

Appendix A Lower Bound for Theorem 3.4

Proof of the lower bound.

To keep the notation simple, we will choose p1=p2==pn=pp_{1}=p_{2}=\dots=p_{n}=p below. It is straightforward to extend this case to arbitrary values p1,p2,,pnp_{1},p_{2},\dots,p_{n}. Moreover, we may restrict ourselves to the case p1p\geq 1, since the lower bound for p=0p=0 is trivial. We define nn posets 𝑳1,,𝑳n\bm{L}_{1},\ldots,\bm{L}_{n}, and functions f1,,fnf_{1},\dots,f_{n} of types fi:j=1,n𝑳j𝑳if_{i}:\prod_{j=1,n}\bm{L}_{j}\rightarrow\bm{L}_{i}, as follows: For every i[n]i\in[n], let 𝑳i=def{aj(i)j}\bm{L}_{i}\stackrel{{\scriptstyle\text{def}}}{{=}}\{a^{(i)}_{j}\mid j\in\mathbb{N}\} with the linear order a0(i)<a1(i)<a2(i)<a^{(i)}_{0}<a^{(i)}_{1}<a^{(i)}_{2}<\dots. By slight abuse, we will simply write 𝑳i=\bm{L}_{i}=\mathbb{N} with the understanding that, in 𝑳i\bm{L}_{i}, integer jj actually stands for aj(i)a^{(i)}_{j}. Only when it comes to the definition of the c-clone and we have to take care of type-compatibilities, it will be important to keep in mind that the 𝑳i\bm{L}_{i}’s are pairwise distinct.

For every i[n]i\in[n], we define the function fi:j=1,n𝑳j𝑳if_{i}\colon\prod_{j=1,n}\bm{L}_{j}\rightarrow\bm{L}_{i} by setting fi(c1,,cn)=dif_{i}(c_{1},\dots,c_{n})=d_{i} via the following case distinction:

  1. (1)

    Case i<ni<n:

    1. (a)

      if ci+1pi+1c_{i+1}\geq p^{i+1} then di=pid_{i}=p^{i};

    2. (b)

      else di=ci+1/pd_{i}=\lfloor c_{i+1}/p\rfloor.

  2. (2)

    Case i=ni=n:

    1. (a)

      if there exists j[n]j\in[n] with cjpjc_{j}\geq p^{j} then dn=pnd_{n}=p^{n};

    2. (b)

      else if cn(cn1+1)pc_{n}\geq(c_{n-1}+1)\cdot p then dn=cnd_{n}=c_{n};

    3. (c)

      else if cn>cn1pc_{n}>c_{n-1}\cdot p then dn=cn+1d_{n}=c_{n}+1;

    4. (d)

      else if there exists j<n1j<n-1 with cjpnj<cn1pc_{j}\cdot p^{n-j}<c_{n-1}\cdot p then dn=cn1pd_{n}=c_{n-1}\cdot p;

    5. (e)

      else dn=cn1p+1d_{n}=c_{n-1}\cdot p+1;

Let h=(f1,,fn)h=(f_{1},\dots,f_{n}) and m0m\geq 0. It is easy to verify that the sequence h(m)(0,,0)h^{(m)}(0,\dots,0) with h=(f1,,fn)h=(f_{1},\dots,f_{n}) and m0m\geq 0 consists of all nn-tuples (c1,,cn)(c_{1},\dots,c_{n}) with 0cipi0\leq c_{i}\leq p^{i} in ascending lexicographical order. The sequence is depicted in Fig. 6. For every ii, the ii-th component is incremented until the limit pip^{i} is reached. Moreover, with each application of hh, we only increment one component. Hence, function hh indeed has stability index p+p2+p3++pnp+p^{2}+p^{3}+\dots+p^{n}.

(0,,0,0),(0,,0,p),(0,,1,p),(0,,1,2p),(0,,p1,p2p),(0,,p1,p2),(0,,0,p,p2),(0,,1,p,p2),(0,,1,p,p2+p),(0,,1,p+1,p2+p),(0,,1,p,p2+2p),(0,,p1,p21,p3p),(0,,p1,p21,p3),(0,,0,p1,p2,p3),(0,,0,p,p2,p3),(0,,1,p,p2,p3),(0,,1,p,p2,p3+p),(p1,p21,,(p1,p21,,pn11,pnp),pn11,pn),(p1,p21,,pn1,pn),(p1,p2,,pn1,pn),(p,p2,,pn1,pn).\left.\begin{array}[]{ccc}(0,\dots,0,0),&\dots&(0,\dots,0,p),\\ (0,\dots,1,p),&\dots&(0,\dots,1,2p),\\ \vdots&&\vdots\\ (0,\dots,p-1,p^{2}-p),&\dots&(0,\dots,p-1,p^{2}),\\ (0,\dots,0,p,p^{2}),\\ (0,\dots,1,p,p^{2}),&\dots&(0,\dots,1,p,p^{2}+p),\\ (0,\dots,1,p+1,p^{2}+p),&\dots&(0,\dots,1,p,p^{2}+2p),\\ \vdots&&\vdots\\ (0,\dots,p-1,p^{2}-1,p^{3}-p),&\dots&(0,\dots,p-1,p^{2}-1,p^{3}),\\ (0,\dots,0,p-1,p^{2},p^{3}),\\ (0,\dots,0,p,p^{2},p^{3}),\\ (0,\dots,1,p,p^{2},p^{3}),&\dots&(0,\dots,1,p,p^{2},p^{3}+p),\\ \vdots&&\vdots\\ (p-1,p^{2}-1,\dots,\hskip 20.0pt&&(p-1,p^{2}-1,\dots,\\ \hskip 30.0ptp^{n-1}-1,p^{n}-p),&\dots&\hskip 33.0ptp^{n-1}-1,p^{n}),\\ (p-1,p^{2}-1,\dots,p^{n-1},p^{n}),\\ \vdots\\ (p-1,p^{2},\dots,p^{n-1},p^{n}),\\ (p,p^{2},\dots,p^{n-1},p^{n}).\end{array}\right.
Figure 6. Sequence of tuples produced by h(m)(0,,0)h^{(m)}(0,\dots,0).
\Description

Sequence of tuples produced by h(m)(0,,0)h^{(m)}(0,\dots,0).

It remains to show that the functions h,f1,,fnh,f_{1},\dots,f_{n} are part of a c-clone 𝒞\mathcal{C}, such that every function f:𝑳i𝑳if\colon\bm{L}_{i}\rightarrow\bm{L}_{i} in 𝒞\mathcal{C} is pp-stable. We choose 𝒞\mathcal{C} as the smallest c-clone containing the functions h,f1,,fnh,f_{1},\dots,f_{n}. We have to show that every function f:𝑳i𝑳if\colon\bm{L}_{i}\rightarrow\bm{L}_{i} in 𝒞\mathcal{C} is pp-stable and that all functions in 𝒞\mathcal{C} are monotone.

Intuition. Before we prove these properties, we discuss the rationale behind the above definition of the functions fif_{i}. The main challenge here is, that the functions fif_{i} have to be defined over the entire domain, i.e., we also have to consider value combinations (c1,,cn)(c_{1},\dots,c_{n}) that are never reached by h(m)(0,,0)h^{(m)}(0,\dots,0). An inspection of the sequence h(m)(0,,0)h^{(m)}(0,\dots,0) shows that, for every i<ni<n, component ci+1c_{i+1} may only range from cipc_{i}\cdot p to (ci+1)p(c_{i}+1)\cdot p. Equivalently, cic_{i} is fully determined by the value of ci+1c_{i+1}, namely ci=ci+1/pc_{i}=\lfloor c_{i+1}/p\rfloor. Hence, in Case 1.b, we set fi(c1,,cn)=ci+1/pf_{i}(c_{1},\dots,c_{n})=\lfloor c_{i+1}/p\rfloor. However, in Case 1.a, we first have to make sure that fi(c1,,cn)f_{i}(c_{1},\dots,c_{n}) never takes a value above pip^{i}.

Similarly, in Case 2.a, whenever one of cjc_{j} has reached its upper bound pjp^{j} (or is even greater), then we also set fn(c1,,cn)f_{n}(c_{1},\dots,c_{n}) to its upper bound, i.e., pnp^{n}. Of course, in the sequence produced by h(m)(0,,0)h^{(m)}(0,\dots,0), the jj-th component can never take a value >pj>p^{j} and also the value pjp^{j} itself is only possible if the nn-th component has already reached pnp^{n}.

After having excluded the case of an excessively big component cjc_{j} in Case 2.a, we still have to distinguish 4 further cases: we have already observed above that the (i+1)(i+1)-st component can only take values in the interval [cip,(ci+1)p][c_{i}\cdot p,(c_{i}+1)\cdot p]. That is, cnc_{n} may only take values in [cn1p,(cn1+1)p][c_{n-1}\cdot p,(c_{n-1}+1)\cdot p]. Hence, if cn(cn1+1)pc_{n}\geq(c_{n-1}+1)\cdot p, then we must not further increase cnc_{n}. This is taken care of by Case 2.b. In fact, in the sequence h(m)(0,,0)h^{(m)}(0,\dots,0), we first have to increase cn1c_{n-1} and possibly further components to the left, before we may continue incrementing cnc_{n}. The incrementation of cnc_{n}, as long as cnc_{n} is in the allowed range, is realized via Case 2.c.

Cases 2.d and 2e only apply if cncn1pc_{n}\leq c_{n-1}\cdot p holds. Both cases cover two kinds of situations: cn=cn1pc_{n}=c_{n-1}\cdot p, which may occur in the sequence h(m)(0,,0)h^{(m)}(0,\dots,0), and cn<cn1pc_{n}<c_{n-1}\cdot p, which cannot occur in this sequence. For the case cn=cn1pc_{n}=c_{n-1}\cdot p, recall that cnc_{n} may only take values in [cn1p,(cn1+1)p][c_{n-1}\cdot p,(c_{n-1}+1)\cdot p]. An inspection of the sequence h(m)(0,,0)h^{(m)}(0,\dots,0) shows that also the components cjc_{j} with j<n1j<n-1 impose a restriction on the allowed values of cnc_{n}, namely: for all j<n1j<n-1, component cnc_{n} must be in the interval [cjpnj,(cj+1)pnj][c_{j}\cdot p^{n-j},(c_{j}+1)\cdot p^{n-j}]. Hence, if cn=cn1pc_{n}=c_{n-1}\cdot p, we have to distinguish the two cases, if we must keep cnc_{n} unchanged and first increment a component cjc_{j} to the left of cn1c_{n-1} (i.e., Case 2.d) or if we may continue incrementing cnc_{n} (i.e., Case 2.e).

Cases 2.d and 2e also cover the case cn<cn1pc_{n}<c_{n-1}\cdot p, which can never occur in h(m)(0,,0)h^{(m)}(0,\dots,0). When defining fn(c1,,cn)f_{n}(c_{1},\dots,c_{n}) in this case, we have to make sure that fnf_{n} is monotone and every function f:𝑳n𝑳nf\colon\bm{L}_{n}\rightarrow\bm{L}_{n} in 𝒞\mathcal{C} is pp-stable. This goal is achieved via Cases 2.d and 2e by treating cn<cn1pc_{n}<c_{n-1}\cdot p in the same way as cn=cn1pc_{n}=c_{n-1}\cdot p. The following example illustrates why this makes sense: let p=3p=3 and n=3n=3, and consider the tuple (2,p,0)(2,p,0). The third component c3=0c_{3}=0 is clearly below the interval of allowed values [p2,p2+p][p^{2},p^{2}+p] by c2=pc_{2}=p. When choosing an appropriate value for f3(2,p,0)f_{3}(2,p,0), we must be careful so as not to destroy monotonicity. In particular, by f3(0,0,0)=1f_{3}(0,0,0)=1, we have to choose f3(2,p,0)1f_{3}(2,p,0)\geq 1. However, when choosing a concrete value 1\geq 1, we also have to keep the pp-stability of all functions f:𝑳n𝑳nf\colon\bm{L}_{n}\rightarrow\bm{L}_{n} in 𝒞\mathcal{C} in mind. In particular, consider the function ff obtained from f3f_{3} when fixing the first two components to constants 22 and pp, i.e., f(x)=f3(2,p,x)f(x)=f_{3}(2,p,x). We cannot simply set f3(2,p,0)=1f_{3}(2,p,0)=1, i.e., f(0)=1f(0)=1 for the following reason: consider the tuple (2,p,1)(2,p,1). By monotonicity, we have to set f(1)=f3((2,p,1)f3(0,0,1)=2f(1)=f_{3}((2,p,1)\geq f_{3}(0,0,1)=2. This argument can be repeated for f3(2,p,x)f_{3}(2,p,x) for every xp2x\leq p^{2}. In order to ensure pp-stability of ff, we have to choose f3(2,p,0)f_{3}(2,p,0) big enough so that at most p1p-1 further incrementations of c3c_{3} are possible. That is why we simply treat f3(2,p,0)f_{3}(2,p,0) in the same way as f3(2,p,p2)f_{3}(2,p,p^{2}).

We now prove that 𝒞\mathcal{C} defined as the smallest c-clone containing functions h,f1,,fnh,f_{1},\dots,f_{n} has the desired properties in terms of monotonicity and pp-stability:

Proof of Monotonicity. We show that every function fif_{i} is monotone. From this, it follows easily that all functions in 𝒞\mathcal{C} are monotone. The case i<ni<n will turn out rather simple. In contrast, the case i=ni=n will require a more detailed analysis. The following observation will be helpful: no matter which of the Cases 2.b – 2.e is used to define fn(c1,,cn)f_{n}(c_{1},\dots,c_{n}), the inequations fn(c1,,cn)pnf_{n}(c_{1},\dots,c_{n})\leq p^{n} and fn(c1,,cn)cnf_{n}(c_{1},\dots,c_{n})\geq c_{n} and fn(c1,,cn)cn1pf_{n}(c_{1},\dots,c_{n})\geq c_{n-1}\cdot p always hold. This property is easy to verify by inspecting the definition of fn(c1,,cn)f_{n}(c_{1},\dots,c_{n}) in each of the four Cases 2.b – 2.e.

Now consider two tuples (c1,,cn)(c_{1},\dots,c_{n}) and (c1,,cn)(c^{\prime}_{1},\dots,c^{\prime}_{n}) with the property (c1,,cn)(c1,,cn)(c_{1},\dots,c_{n})\sqsubseteq(c^{\prime}_{1},\dots,c^{\prime}_{n}), i.e., cjcjc_{j}\leq c^{\prime}_{j} for every jj. In order to show fi(c1,,cn)f_{i}(c_{1},\dots,c_{n}) fi(c1,,cn)\leq f_{i}(c^{\prime}_{1},\dots,c^{\prime}_{n}), we distinguish, which case of the definition of fif_{i} applies to (c1,,cn)(c_{1},\dots,c_{n}).

Case 1: i<ni<n. If (1.a) ci+1pi+1c_{i+1}\geq p^{i+1} then also ci+1pi+1c^{\prime}_{i+1}\geq p^{i+1} and we have fi(c1,,cn)=pi=fi(c1,,cn)f_{i}(c_{1},\dots,c_{n})=p^{i}=f_{i}(c^{\prime}_{1},\dots,c^{\prime}_{n}). On the other hand, if (1.b) ci+1<pi+1c_{i+1}<p^{i+1}, then fi(c1,,cn)=ci+1/p<pif_{i}(c_{1},\dots,c_{n})=\lfloor c_{i+1}/p\rfloor<p^{i}. Hence, no matter whether fi(c1,,cn)f_{i}(c^{\prime}_{1},\dots,c^{\prime}_{n}) is determined via Case 1.a or 1.b, the property fi(c1,,cn)f_{i}(c_{1},\dots,c_{n}) fi(c1,,cn)\leq f_{i}(c^{\prime}_{1},\dots,c^{\prime}_{n}) is always guaranteed.

Case 2: i=ni=n. We analyze each of the Cases 2.a – 2.e separately.

Case 2.a. If there exists j[n]j\in[n] with cjpjc_{j}\geq p^{j} then also cjpjc^{\prime}_{j}\geq p^{j} and we have fn(c1,,cn)=pn=fn(c1,,cn)f_{n}(c_{1},\dots,c_{n})=p^{n}=f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}).

Case 2.b. If cn(cn1+1)pc_{n}\geq(c_{n-1}+1)\cdot p then fn(c1,,cn)=cnpnf_{n}(c_{1},\dots,c_{n})=c_{n}\leq p^{n}. On the other hand, we either have fn(c1,,cn)=pnf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=p^{n} (if Case 2.a applies) or fn(c1,,cn)cnf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})\geq c^{\prime}_{n} (in all other cases) by the above observation. Hence, fn(c1,,cn)fn(c1,,cn)f_{n}(c_{1},\dots,c_{n})\leq f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}) clearly holds.

Case 2.c. If cn>cn1pc_{n}>c_{n-1}\cdot p then fn(c1,,cn)=cn+1pnf_{n}(c_{1},\dots,c_{n})=c_{n}+1\leq p^{n}. Again, recall that we either have fn(c1,,cn)=pnf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=p^{n} (if Case 2.a applies) or fn(c1,,cn)cnf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})\geq c^{\prime}_{n} (in all other cases). Hence, the only interesting case is that Case 2.a does not apply to fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}) and cn=cnc^{\prime}_{n}=c_{n}. We now show that, no matter which of the remaining Cases 2.b – 2.e applies to fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}), we always get the desired inequation fn(c1,,cn)fn(c1,,cn)f_{n}(c_{1},\dots,c_{n})\leq f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}).

Note that we are dealing with the case cn<(cn1+1)pc_{n}<(c_{n-1}+1)\cdot p. Moreover, we are assuming cn=cnc^{\prime}_{n}=c_{n} and cn1cn1c^{\prime}_{n-1}\geq c_{n-1}. Hence, we also have cn<(cn1+1)pc^{\prime}_{n}<(c^{\prime}_{n-1}+1)\cdot p, which means that fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}) cannot be defined via Case 2.b.

If fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}) is defined via Case 2.c, then fn(c1,,cn)=cn+1f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=c^{\prime}_{n}+1 holds and we are done.

If one of the Cases 2.d or 2.e applies, then cn1pcnc^{\prime}_{n-1}\cdot p\geq c^{\prime}_{n} must hold. In contrast, we are considering the Case 2.c for fn(c1,,cn)f_{n}(c_{1},\dots,c_{n}). That is, cn1p<cnc_{n-1}\cdot p<c_{n}. Since we are assuming cn=cnc^{\prime}_{n}=c_{n}, we have cn1>cn1c^{\prime}_{n-1}>c_{n-1} or, equivalently, cn1cn1+1c^{\prime}_{n-1}\geq c_{n-1}+1. By the above observation, we have fn(c1,,cn)cn1pf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})\geq c^{\prime}_{n-1}\cdot p. On the other hand, since Case 2.b does not apply to fn(c1,,cn)f_{n}(c_{1},\dots,c_{n}), we have cn<(cn1+1)pc_{n}<(c_{n-1}+1)\cdot p or, equivalently, cn+1(cn1+1)pc_{n}+1\leq(c_{n-1}+1)\cdot p. In total, this gives fn(c1,,cn)cn1p(cn1+1)pcn+1=fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})\geq c^{\prime}_{n-1}\cdot p\geq(c_{n-1}+1)\cdot p\geq c_{n}+1=f_{n}(c_{1},\dots,c_{n}).

Case 2.d. If there exists j<n1j<n-1 with cjpnj<cn1pc_{j}\cdot p^{n-j}<c_{n-1}\cdot p then fn(c1,,cn)=cn1ppnf_{n}(c_{1},\dots,c_{n})=c_{n-1}\cdot p\leq p^{n}. On the other hand, we either have fn(c1,,cn)=pnf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=p^{n} (if Case 2.a applies) or fn(c1,,cn)cn1pf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})\geq c^{\prime}_{n-1}\cdot p (in all other cases) by the above observation. Either way, fn(c1,,cn)fn(c1,,cn)f_{n}(c_{1},\dots,c_{n})\leq f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}) holds.

Case 2.e. If for all j<n1j<n-1: cjpnjcn1pc_{j}\cdot p^{n-j}\geq c_{n-1}\cdot p then fn(c1,,cn)=cn1p+1pnf_{n}(c_{1},\dots,c_{n})=c_{n-1}\cdot p+1\leq p^{n}. By the above observation, either fn(c1,,cn)=pnf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=p^{n} holds (if Case 2.a applies) or fn(c1,,cn)cn1pf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})\geq c^{\prime}_{n-1}\cdot p (in all other cases) holds. Hence, the only interesting case is that Case 2.a does not apply to fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}) and cn1=cn1c^{\prime}_{n-1}=c_{n-1}. We now show that, no matter which of the remaining Cases 2.b – 2.e applies to fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}), we always get the desired inequation fn(c1,,cn)fn(c1,,cn)f_{n}(c_{1},\dots,c_{n})\leq f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}).

Case 2.b applies only if cn(cn1+1)pc^{\prime}_{n}\geq(c^{\prime}_{n-1}+1)\cdot p, thus fn(c1,,cn)=cnf_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=c^{\prime}_{n}. We are assuming p1p\geq 1; hence (cn1+1)pcn1p+1(c^{\prime}_{n-1}+1)\cdot p\geq c^{\prime}_{n-1}\cdot p+1 holds. In total, we thus have fn(c1,,cn)=cncn1p+1cn1p+1=fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=c^{\prime}_{n}\geq c^{\prime}_{n-1}\cdot p+1\geq c_{n-1}\cdot p+1=f_{n}(c_{1},\dots,c_{n}).

If Case 2.c applies, then cn>cn1pc^{\prime}_{n}>c^{\prime}_{n-1}\cdot p and we set fn(c1,,cn)=cn+1f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=c^{\prime}_{n}+1. Hence, we have fn(c1,,cn)=cn+1>cn1p+1cn1p+1=fn(c1,,cn)f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=c^{\prime}_{n}+1>c^{\prime}_{n-1}\cdot p+1\geq c_{n-1}\cdot p+1=f_{n}(c_{1},\dots,c_{n}).

Note that Case 2.d would mean that there exists j<n1j<n-1 with cjpnj<cn1pc^{\prime}_{j}\cdot p^{n-j}<c^{\prime}_{n-1}\cdot p. However, this cannot happen by our current assumptions, namely: for every jj: cjcjc^{\prime}_{j}\geq c_{j}, cn1=cn1c_{n-1}=c^{\prime}_{n-1}, and for all j<n1j<n-1: cjpnjcn1pc_{j}\cdot p^{n-j}\geq c_{n-1}\cdot p.

Finally, if Case 2.e applies, then fn(c1,,cn)=cn1p+1f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n})=c^{\prime}_{n-1}\cdot p+1. Together with cn1=cn1c^{\prime}_{n-1}=c_{n-1} and fn(c1,,cn)=cn1p+1f_{n}(c_{1},\dots,c_{n})=c_{n-1}\cdot p+1, we again have fn(c1,,cn)fn(c1,,cn)f_{n}(c_{1},\dots,c_{n})\leq f_{n}(c^{\prime}_{1},\dots,c^{\prime}_{n}).

Proof of Stability. By choosing 𝒞\mathcal{C} as the minimal c-clone containing the functions h,f1,,fnh,f_{1},\dots,f_{n}, we know that all functions f:𝑳i𝑳if\colon\bm{L}_{i}\rightarrow\bm{L}_{i} are of the form f𝒄:𝑳i𝑳if_{\bm{c}}\colon\bm{L}_{i}\rightarrow\bm{L}_{i} with 𝒄=(c1,,ci1,ci+1,,cn)\bm{c}=(c_{1},\dots,c_{i-1},c_{i+1},\dots,c_{n}) and f𝒄(x)=fi(c1,,ci1,x,ci+1,,cn)f_{\bm{c}}(x)=f_{i}(c_{1},\dots,c_{i-1},x,c_{i+1},\dots,c_{n}) for some constants cj𝑳jc_{j}\in\bm{L}_{j} for every jij\neq i. We have to show that f𝒄(p)(0)=f𝒄(p+1)(0)f^{(p)}_{\bm{c}}(0)=f^{(p+1)}_{\bm{c}}(0) holds. To this end, we distinguish which of the cases of the definition of fif_{i} applies to (c1,,ci1,0,ci+1,,cn)(c_{1},\dots,c_{i-1},0,c_{i+1},\dots,c_{n}).

Case 1: i<ni<n. If (1.a) ci+1pi+1c_{i+1}\geq p^{i+1} then f𝒄(1)(0)=fi(c1,,ci1,0f^{(1)}_{\bm{c}}(0)=f_{i}(c_{1},\dots,c_{i-1},0, ci+1,,cn)=pi=f(2)𝒄(0)c_{i+1},\dots,c_{n})=p^{i}=f^{(2)}_{\bm{c}}(0). Otherwise, f𝒄(1)(0)=fi(c1,,ci1,0f^{(1)}_{\bm{c}}(0)=f_{i}(c_{1},\dots,c_{i-1},0, ci+1,,cn)=ci+1/p=f(2)𝒄(0)c_{i+1},\dots,c_{n})=\lfloor c_{i+1}/p\rfloor=f^{(2)}_{\bm{c}}(0).

Case 2: i=ni=n. If f𝒄(0)=fn(c1,,cn1,0)f_{\bm{c}}(0)=f_{n}(c_{1},\dots,c_{n-1},0) is determined via Case 2.a, then we have f𝒄(1)(0)=fn(c1,,cn1,0)=pn=f𝒄(2)(0)f^{(1)}_{\bm{c}}(0)=f_{n}(c_{1},\dots,c_{n-1},0)=p^{n}=f^{(2)}_{\bm{c}}(0).

Case 2.b cannot apply, since this would require cn(cn1+1)pc_{n}\geq(c_{n-1}+1)\cdot p, which is impossible in case of cn=0c_{n}=0.

Case 2.c cannot apply either, since it would require cn>cn1pc_{n}>c_{n-1}\cdot p, which is impossible in case of cn=0c_{n}=0.

If Case 2.d applies, then we have f𝒄(1)(0)=fn(c1,,cn1,0)=cn1pf^{(1)}_{\bm{c}}(0)=f_{n}(c_{1},\dots,c_{n-1},0)=c_{n-1}\cdot p. If we now apply ff again, then we are still in Case 2.d, i.e., f𝒄(2)(0)=cn1p=f𝒄(1)(0)f^{(2)}_{\bm{c}}(0)=c_{n-1}\cdot p=f^{(1)}_{\bm{c}}(0).

Finally, if Case 2.e applies, then f𝒄(1)(0)=fn(c1,,cn1,0)=cn1p+1f^{(1)}_{\bm{c}}(0)=f_{n}(c_{1},\dots,c_{n-1},0)=c_{n-1}\cdot p+1 holds. By the definition of fnf_{n}, the last component cannot be incremented beyond cn1p+pc_{n-1}\cdot p+p in this case. Hence, we indeed have f𝒄(p)(0)=f𝒄(p+1)(0)f^{(p)}_{\bm{c}}(0)=f^{(p+1)}_{\bm{c}}(0). ∎

Appendix B Proof of Lemma 5.6

The proof follows the same line of reasoning as (DBLP:journals/jacm/EsparzaKL10, ). We use the same definition of the height of a parse tree TT, namely the number of edges on the longest path from the root to a leaf: for example, trees in Fig. 3 have heights 1, 2, and 2 respectively. As usual, the internal nodes of a parse tree are labeled with non-terminals, and the leaves with terminals. Unlike (DBLP:journals/jacm/EsparzaKL10, ), we do not need to label the internal nodes with pairs (xi,j)(x_{i},j) where xix_{i} is the non-terminal (variable) and jj represents a monomial number in fif_{i}, but we label them only with the variable xix_{i}. This is sufficient because our terminal symbols a𝒗,ia_{\bm{v},i} are in one-to-one correspondence with the monomials in the polynomial fif_{i}.

Recall that each component (f(q)(0))i(f^{(q)}(0))_{i} of 𝒇(q)(0)\bm{f}^{(q)}(0) is a multivariate polynomial in the coefficients 𝒂=(a1,,aM)\bm{a}=(a_{1},\ldots,a_{M}) that occur in all polynomials f1,,fNf_{1},\ldots,f_{N}. When we repeatedly apply 𝒇\bm{f}, each monomial a1v1aMvMa_{1}^{v_{1}}\cdots a_{M}^{v_{M}} may appear multiple times in 𝒇(q)(0)\bm{f}^{(q)}(0); in our Example 5.5 the monomial a3b4a^{3}b^{4} appears 1 times in f(3)(0)f^{(3)}(0), then 5 times in f(4)(0)f^{(4)}(0). Let Mi(q)M^{(q)}_{i} be the bag of monomials occurring in (f(q)(0))i(f^{(q)}(0))_{i}, and let Ni(q)N^{(q)}_{i} be the bag of yields of all derivation trees of depth q\leq q, i.e. {{Y(T)T𝒯qi}}\{\{{Y(T)}\mid{T\in\mathcal{T}^{i}_{q}}\}\}. We prove by induction on qq that Mi(q)=Ni(q)M^{(q)}_{i}=N^{(q)}_{i} for all i=1,Ni=1,N.

When q=0q=0 then both bags are empty. Assuming the statement holds for q0q\geq 0, we prove it for q+1q+1. We prove that Mi(q+1)Ni(q+1)M^{(q+1)}_{i}\subseteq N^{(q+1)}_{i}; the other direction is similar and omitted. By definition, (𝒇(q+1)(0))i=fi(𝒇(q)(0))(\bm{f}^{(q+1)}(0))_{i}=f_{i}(\bm{f}^{(q)}(0)), where fif_{i} is a sum of monomials, see Eq (37). Each monomial in fif_{i} has the form ajx11xNNa_{j}x_{1}^{\ell_{1}}\cdots x_{N}^{\ell_{N}} for some aj𝒂a_{j}\in\bm{a} and some vector of exponents (1,,N)(\ell_{1},\ldots,\ell_{N}). Then fi(𝒇(q)(0))f_{i}(\bm{f}^{(q)}(0)) is a sum of expressions of the form:

(68) aj(𝒇(q)(0))11(𝒇(q)(0))NN\displaystyle a_{j}\cdot(\bm{f}^{(q)}(0))_{1}^{\ell_{1}}\cdots(\bm{f}^{(q)}(0))_{N}^{\ell_{N}}

In other words, we have substituted each xjx_{j} in (37) with (𝒇(q)(0))j(\bm{f}^{(q)}(0))_{j}, which, in turn, is a sum of the monomials in the bag Mj(q)M^{(q)}_{j}. Thus, after expanding the expression (68) we obtain a sum of monomials mm of the following form:

(69) m=\displaystyle m= ajm1,1m1,1mN,1mN,N\displaystyle a_{j}\cdot m_{1,1}\cdots m_{1,\ell_{1}}\cdots\cdots m_{N,1}\cdots m_{N,\ell_{N}}

where mj,kMj(q)m_{j,k}\in M^{(q)}_{j}. To summarize, each monomial mm occurring in Mi(q+1)M^{(q+1)}_{i} can be uniquely obtained as follows: (a) choose one monomial ajx11xNNa_{j}x_{1}^{\ell_{1}}\cdots x_{N}^{\ell_{N}} in the polynomial fif_{i}, (b) for each j=1,Nj=1,N, and each k=1,kk=1,\ell_{k}, choose one monomial mj,km_{j,k} in the bag Mj(q)M^{(q)}_{j} (a total of jj\sum_{j}\ell_{j} choices). Given these choices, we define a unique101010“Unique” means that different choices (a) and (b) will lead to different parse trees. parse tree of depth q+1q+1 whose yield is mm, as follows. (a’) The root node is labeled with the production (38) associated to the monomial that we used in (a). (b’) For each j=1,Nj=1,N and each k=1,jk=1,\ell_{j}, we use the inductive hypothesis Mj(q)=Nj(q)M^{(q)}_{j}=N_{j}^{(q)} and argue that the monomial mj,kMj(q)m_{j,k}\in M^{(q)}_{j} is in Nj(q)N^{(q)}_{j}, thus it is the yield of some parse tree Tj,kT_{j,k} of depth q\leq q. Then we complete our parse tree by setting Tj,kT_{j,k} to be the (j,k)(j,k)-th child of the root node. This tree generates the following word:

ajm1,1m1,1mN,1mN,N\displaystyle a_{j}\cdot m_{1,1}\cdots m_{1,\ell_{1}}\cdots\cdots m_{N,1}\cdots m_{N,\ell_{N}}

This is equal to mm in Eq. (69), proving that mNi(q+1)m\in N^{(q+1)}_{i} and, thus, Mi(q+1)Ni(q+1)M^{(q+1)}_{i}\subseteq N^{(q+1)}_{i}. Containment in the other direction is similar and omitted.