Weighted Rewriting: Semiring Semantics for Abstract Reduction Systems
Abstract
We present novel semiring semantics for abstract reduction systems (ARSs). More precisely, we provide a weighted version of ARSs, where the reduction steps induce weights from a semiring. Inspired by provenance analysis in database theory and logic, we obtain a formalism that can be used for provenance analysis of arbitrary ARSs. Our semantics handle (possibly unbounded) non-determinism and possibly infinite reductions. Moreover, we develop several techniques to prove upper and lower bounds on the weights resulting from our semantics, and show that in this way one obtains a uniform approach to analyze several different properties like termination, derivational complexity, space complexity, safety, as well as combinations of these properties.
Keywords and phrases:
Rewriting, Semirings, Semantics, Termination, VerificationCopyright and License:
2012 ACM Subject Classification:
Theory of computation Rewrite systems ; Theory of computation Equational logic and rewriting ; Theory of computation Logic and verificationFunding:
Funded by the DFG Research Training Group 2236 UnRAVeL.Acknowledgements:
We thank the reviewers for their useful remarks and suggestions.Editors:
Maribel FernándezSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Rewriting is a prominent formalism in computer science and notions like termination, complexity, and confluence have been studied for decades for abstract reduction systems (ARSs). Moreover, typical problems in computer science like evaluation of a database query or a logical formula can be represented as a reduction system.
In this paper, we tackle the question whether numerous different analyses in the area of rewriting, computation, logic, and deduction are “inherently similar”, i.e., whether they can all be seen as special instances of a uniform framework. Analogous research has been done, e.g., in the database and logic community, where there have been numerous approaches to provenance analysis, i.e., to not just analyze satisfiability but also explainability of certain results (see, e.g., [14, 15, 20]). In these works, semirings are often used to obtain information beyond just satisfiability of a query. For instance, they may be used to compute the confidence in an answer or to calculate the cost of proving satisfiability.
Example 1 (Provenance Analysis in Databases).
Consider two tables , in a database over the universe with and (where each atomic fact, such as or , has a cost in ), and the formula which represents a database query.
cost cost cost
Our aim is to calculate the maximal cost of proving . For the alternative use of information, i.e., for disjunctions , we take the maximal cost of proving that or are satisfied. For the joint use of information, i.e., for conjunctions , we take the sum of costs for proving that and hold. We can use the arctic semiring to formalize this situation (i.e., we consider with the operations and whose identity elements are and , respectively):
-
For an atom , we set , where is the cost of the atom .111We assume that our formulas do not use negation, a typical restriction for semiring semantics for logic.
-
For formulas , we set and .
This leads to a maximal cost of for proving . We can use a different semiring to calculate a different property. For example, the confidence that a formula holds is computable via the confidence semiring , where all atomic facts are given a certain confidence score.
In general, to compute the weight of an object , one defines an interpretation of the facts or atoms (e.g., the definition of ) which maps objects to elements of the semiring, and an aggregator function for each reduction step (e.g., the rules for and above) which operates on elements of the semiring.
In this work we generalize the idea of evaluating a database query within a given semiring to ARSs. As usual, an ARS is a set together with a binary relation denoting reductions. Note that we have to allow reductions from a single object to multiple ones, as we may have to consider multiple successors (e.g., and for the formula ) in order to define the weight of , whereas in classical ARSs, objects are reduced to single objects. This leads to the notion of sequence ARSs. Similar ideas have been used for probabilistic ARSs [3, 11, 12], where a reduction relates a single object to a multi-distribution over possible results. We will see that probabilistic ARSs can indeed also be expressed using our formalism.
Example 2 (Provenance Analysis for ARSs).
The formulas from Ex. 1 fit into the concept of sequence ARSs: The set contains all propositional, negation-free formulas over the atomic facts (the normal forms of the relation ) and the relation is defined as and , where denotes the sequence containing as first and as second element. Given a semiring, aggregator functions for the reduction steps, and an interpretation of the normal forms, we calculate the weight of a formula as in the previous example. See Sect. 3 for the formal definition.
In order to handle arbitrary ARSs, we have to deal with non-terminating reduction sequences and with (possibly unbounded) non-determinism. For that reason, to ensure that our semantics are well defined, we consider semirings where the natural order (that is induced by addition of the semiring) forms a complete lattice.
In most applications of semiring semantics in logic [15, 20], a higher “truth value” w.r.t. the natural order is more desirable, e.g., for the confidence semiring one would like to obtain a value close to the most desirable confidence . However, in the application of software verification, it is often the reverse, e.g., for computing the runtime of a reduction or when considering the costs as in Ex. 1 for the arctic semiring . While every weight may still be acceptable, the aim is to prove boundedness, i.e., that the maximum (an infinite cost) cannot occur. For example, boundedness can imply termination of the underlying ARS, it can ensure that certain bad states cannot be reached (safety), etc. By considering tuples over different semirings, we can combine multiple analyses into a single combined framework analyzing combinations of properties, where simply performing each analysis separately fails. In Sect. 5, we give sufficient conditions for boundedness and show that the interpretation method, a well-known method to, e.g., prove termination [5, 26, 29] or complexity bounds [9, 10, 22] of ARSs, can be generalized to a sound and (regarding continuous complete lattice semirings) complete technique to prove boundedness. On the other hand, it is also of interest to prove worst-case lower bounds on weights in order to find bugs or potential attacks (e.g., inputs which lead to a long runtime). Moreover, if one determines both worst-case upper and lower bounds, this allows to check whether the bounds are (asymptotically) exact. Thus, we present a technique to find counterexamples with maximal weight in Sect. 6.
So in this paper, we define a uniform framework in the form of weighted ARSs, whose special instances correspond to different semiring interpretations. This indeed shows the similarity between numerous analyses in rewriting, computation, logic, and deduction, because they can all be represented within our new framework. In particular, this uniform framework allows to adapt techniques which were developed for one special instance in order to use them for other special instances. While the current paper is a first (theoretical) contribution in this direction, eventually this may also improve the automation of the analysis for certain instances.
Main Results of the Paper.
-
Moreover, we give a sound (and complete in case of continuous semirings) technique based on the well-known interpretation method to prove boundedness, i.e., to show that the weight of every object in the ARS is smaller than the maximum of the semiring (Thm. 32).
Related Work.
Semirings are actively studied in the database and the logic community. See [20] for the first paper on semiring provenance and [19, 21] for further surveys. Moreover, a uniform framework via semirings has been developed in the context of weighted automata [16], which has led to a wealth of extensions and practical applications, e.g., in digital image compression and model checking. There is also work on semiring semantics for declarative languages like, e.g., Datalog [23], which presents properties of the semiring that ensure upper bounds on how fast a Datalog program can be evaluated. Semiring semantics for the lambda calculus have been provided in [25]. In [8], a declarative programming framework was presented which unifies the analysis of different weighted model counting problems. Within software verification, semirings have been used in [7] for a definition of weighted imperative programming, a Hoare-like semantics, and a corresponding weakest (liberal) precondition semantics, and extended to Kleene algebras with tests in [28]. The weakest precondition semantics of [7] can also be expressed in our formalism, see App. A. For ARSs, so far only costs in specific semirings have been considered, e.g., in [3, 4, 24, 27]. Compared to all this related work, we present the first general semiring semantics for abstract reduction systems and demonstrate how to use semirings for analyzing different properties of programs in a unified way.
Structure.
We give some preliminaries on abstract reduction systems and semirings in Sect. 2. Then, we introduce the new notion of weighted ARSs in Sect. 3 that defines semiring semantics for sequence ARSs. We illustrate the expressivity and applicability of this formalism in Sect. 4. In Sect. 5, we show how to prove boundedness. Here, we first give sufficient criteria that guarantee boundedness, and then we introduce the interpretation method for proving boundedness in general. In Sect. 6, we discuss the problem of finding a worst-case lower bound on the weight, or even a counterexample, i.e., we present a technique to find reduction sequences that lead to unbounded weight. In Sect. 7, we conclude and discuss ideas for future work. Finally, in App. A we show how to express the semantics of [7] in our setting, and we refer to [2] for all proofs.
2 Preliminaries
In this section, we give a brief introduction to abstract reduction systems and define complete lattice semirings that will ensure well-defined semiring semantics for ARSs in Sect. 3. The following definition of ARSs adheres to the commonly used definition, see, e.g., [5, 29].
Definition 3 (Abstract Reduction System, Normal Form, Determinism).
An abstract reduction system (ARS) is a pair with a set and a binary relation .
-
An object reduces to in a single step, abbreviated as , if .
-
An object is called a normal form if there is no such that . The set of all normal forms for is denoted by .
-
Finally, the ARS is deterministic if for every object there exists at most one with . It is finitely non-deterministic222When only regarding classical ARSs, this notion is often called “finitely branching” instead. However, since we will regard sequence ARSs in Def. 9, in this paper the notion “finitely branching” will refer to the branching of their reduction trees, see Def. 10. if for every object there exist at most finitely many objects with .
An important property of ARSs is termination, i.e., the absence of infinite behavior.
Definition 4 (Reduction Sequence, Termination).
Let be an ARS. A reduction sequence is a finite or infinite sequence with , and we say that is terminating if there exists no infinite reduction sequence.
In our new notion of weighted rewriting, we weigh the normal forms in by elements of a semiring, which consists of a set associated with two operations and .
Definition 5 (Semiring).
A semiring is a tuple consisting of a set (called the carrier) together with two binary functions such that is a commutative monoid (i.e., is commutative and associative with identity element ), is a monoid, and distributes over . Furthermore, is a multiplicative annihilator, i.e., for all .
Sometimes we write or to clearly indicate the semiring . If it is clear from the context, we also use to denote the carrier . In Sect. 1, we already mentioned some examples of semirings, namely the confidence semiring and the arctic semiring . Fig. 1 lists some relevant semirings for this work. Here, the multiplication in the formal language semiring is pairwise concatenation, i.e., for , we have .
Later, in Sect. 5 and 6, we establish upper and lower bounds on the weight of a given reduction sequence, respectively. Hence, we need an order on the elements in the semiring. Additionally, the order should be defined in a way that guarantees well-definedness of our semantics. We accomplish this by using the natural order333One can also generalize our results to partially ordered semirings, where the partial order is compatible with addition and multiplication, i.e., addition and multiplication are monotonic (see Def. 30). Note that the natural order is the least (w.r.t. ) such partial order. induced by the addition .
| |
Definition 6 (Natural Order).
The natural order on a semiring is defined for all as iff there exists an element with . A semiring is called naturally ordered if is a partial order, i.e., reflexive, transitive, and antisymmetric.444By definition, is reflexive since , and transitive since and imply by associativity of . So the only real requirement is antisymmetry.
The lack of “negative elements” in semirings ensures that we can define the natural order, because as soon as there exists an element different from with an additive inverse, the relation is not antisymmetric anymore. Every semiring in Fig. 1 is naturally ordered. If the additive operation is addition or maximum, then the order corresponds to the usual order on the extended naturals or extended reals. The natural order on is the subset relation (). Moreover, since the additive operation in the tropical semiring is the minimum, the natural order in this semiring is the reverse of the usual order.
Our semantics in Sect. 3 consider demonic non-determinism. Hence, to analyze worst-case behavior, we want to take the least upper bound over all (possibly uncountably many) schedulers to resolve all non-determinism, i.e., we want to take the least upper bound of arbitrary (possibly uncountable) sets. A partially ordered set, where the least upper bound exists for every two elements, is called a join-semilattice, see e.g., [1]. Since we also need the existence of least upper bounds for infinite uncountable sets, we require complete lattices.555Lattices are semilattices, where in addition to suprema also infima are defined. While we do not need infima for our semantics, the existence of infima is guaranteed if one assumes the existence of suprema for all (possibly uncountable) subsets, see [2].
Definition 7 (Complete Lattice).
A naturally ordered semiring is a complete lattice if the least upper bound (or supremum) exists for every set .
All semirings in Fig. 1 are naturally ordered and complete lattices. A complete lattice semiring does not only have a minimum666Already in naturally ordered semirings, is the minimum: for all , we have , since . , but also a maximum . Furthermore, the existence of every supremum allows us to define infinite sums and products of sequences, see, e.g., [13].
We define sequences , where either for some (then is a finite sequence of length ) or (then is an infinite sequence). By , we denote the set of all non-empty sequences over some set . Furthermore, the subset relation between two sequences is defined via prefixes, i.e., we write if and for all . For a finite sequence , we use the common abbreviation and .
Definition 8 (Infinite Sums and Products).
Let be a complete lattice semiring and an infinite sequence777Note that one typically defines sums for sets and not for sequences in provenance analysis. However, we use the order given by the sequence for our semantics in Sect. 3. over . Then we define the infinite sum and product of as
Infinite sums and products are well defined, since the supremum of any set exists in the complete lattice , hence and for all infinite sequences over .
3 Semiring Semantics for Abstract Reduction Systems
In this section, we introduce weighted abstract reduction systems by defining semiring semantics for ARSs and show that these semantics are well defined for complete lattice semirings. Our definitions are in line with provenance analysis as introduced in Ex. 1. From now on, whenever we speak of a “semiring” we mean a complete lattice semiring.
As for ordinary ARSs, we represent the relation via rules which are selected non-deterministically. However, each rule can have multiple outcomes, as in Ex. 2. Syntactically, for a sequence abstract reduction system, we use a relation that relates a single object to a sequence of all corresponding outcomes that we later weigh using semiring elements. Note that sequences are necessary for reductions like , where both incarnations of may reduce to different objects due to possible non-determinism.
Definition 9 (Sequence Abstract Reduction System).
A sequence abstract reduction system (sARS) is a pair consisting of a set and a binary relation .
-
We write if and . Normal forms and are defined as for ARSs.
-
The sARS is deterministic if for every there is at most one with and finitely non-deterministic if for each , there are only finitely many with . The sARS is finitely branching if for every , the sequence is finite.
We have already seen an example of an sARS in Ex. 2. In ordinary ARSs, it suffices to consider reduction sequences. When using sARSs, we obtain ordered reduction trees instead.
Definition 10 (Reduction Tree).
Let be an sARS. An -reduction tree (-RT) is a labeled, ordered tree with nodes and directed edges , where
-
every node is labeled by an object and
-
every node together with its sequence of direct successors either corresponds to a reduction step or is empty.
We say that is terminating if all -RTs have finite depth.888One could instead attempt to define reduction trees in an inductive way. Then every node labeled with a value from would be a reduction tree and one could lift the reduction to a binary relation which extends reduction trees, i.e., holds if there is a leaf of and a reduction step such that the reduction tree extends by new leaves with and edges for all . However, in this way one would only obtain reduction trees of finite depth, whereas we also need reduction trees of infinite depth in order to represent non-terminating reductions, which would require an additional limit step in the construction.
with semantics in .
semantics in .
Fig. 2(a) depicts a reduction tree for the formula from Ex. 1 and Fig. 2(b) shows a reduction tree for a biased random walk starting at 2, see Ex. 19. We define the weight of a reduction tree w.r.t. a semiring by interpreting the leaf nodes as semiring elements and the inner nodes as combinations of its children. We use so-called aggregator functions to combine weights occurring in reductions based on the semiring addition and multiplication.
Definition 11 (Aggregator).
Let be a semiring and be a set of variables. Then the set of all aggregators (over and ) is the smallest set with
-
for every (constants) and for every (variables),
-
(sums) and (products) for every .
If an aggregator is constructed via finite sequences , then it is a finite aggregator. Let be the set of all variables in and let .
Let and with . Then the aggregator induces a function in the obvious way: For a sequence of length , we have for constants , for variables and , and for , where .
Weighted rewriting considers an sARS together with a semiring , and functions and in order to map objects from to elements of .
Definition 12 (Weighted Abstract Reduction System).
A tuple is a weighted abstract reduction system (wARS) if
-
is an sARS,
-
is a semiring,
-
is the interpretation of normal forms,
-
is the aggregator for every ,
where .
For every , we consider the induced function of arity . Now we introduce our semiring semantics for reduction trees of finite depth by using to interpret the leaves of a reduction tree that are labeled by normal forms. To interpret inner nodes, we use aggregator functions that distinguish between the different reductions. So for the example from Ex. 2 and 2(a), we use a function where is the cost of atom , and we use for every rule and for every rule . Thus, combining the weights of the children via aggregator functions enables us to calculate a weight for the root of any reduction tree with possibly infinite (countable) branching and finite depth.999Alternatively, one could also consider finite-depth reduction trees as first-order ground terms (with function symbols of possibly infinite arity). Then the semiring semantics of Def. 13 would correspond to a polynomial interpretation where the polynomials are constructed using the operations and of the semiring.
Definition 13 (Semiring Semantics).
For a wARS and an -RT of finite depth, we define the weight of at node as
| if | ||||
| if is a leaf and | ||||
The weight of the whole RT is , where is the root node of .
Note that the order of the children is crucial when applying to . This is needed, e.g., when an aggregator is used to represent different probabilities for the successor objects in a biased random walk, see, e.g., Fig. 2(b) and Sect. 4.3.
A reduction tree of finite depth represents one possible execution of the sARS up to a certain number of steps, where the non-determinism is resolved by some fixed scheduler. To define the semantics of an object , we consider any finite number of reduction steps and all possible schedulers. Then we define the weight of as the least upper bound of the weights of all finite-depth reduction trees whose root is labeled with .
Definition 14 (Semantics with Demonic Non-Determinism).
For a wARS and , let be the set of all -reduction trees of finite depth whose root node is labeled with . Then we define the weight of as .101010In principle, , , and are indexed by , but we omitted this index for readability.
Due to possibly uncountably many schedulers, there might be uncountably many reduction trees each with a different weight, see [2]. Nevertheless, since is a complete lattice, the supremum of every set exists and thus, the weight of every object is well defined.
Corollary 15 (Well-Defined Semantics).
For any wARS , the weight is well defined for every object .
The set takes on different shapes depending on the reduction system. If the reduction system is deterministic, then consists of all finite-depth prefixes of a single (potentially infinite-depth) tree. If the sARS is non-deterministic, then may contain uncountably many trees. The maximal size of the sequences in the reduction rules determines the maximal branching degree of the trees. If the sARS is finitely branching, so are the trees in .
The computation of the weight is undecidable in general, since computing single steps with may already be undecidable. However, even if the reductions , the interpretation of the normal forms , and the aggregator functions are computable, computing the weight can still be undecidable, because it can express notions like termination of deterministic systems as demonstrated in the next section (Sect. 4.1).
4 Expressivity of Semiring Semantics
In this section we give several examples to demonstrate the versatility and expressive power of our new formalism, and show that existing approaches for the analysis of reduction systems actually consider specific semirings.
4.1 Termination and Complexity
We can extend any ARS to a wARS such that is equal to the supremum over the lengths of all reduction sequences starting in . For this, we use the sequence relation , the extended naturals semiring , the interpretation for all , and the aggregator whenever . Recall that aggregators use a fixed set of variables . The derivational complexity of (i.e., the supremum of the lengths of possible reduction sequences) is obtained by analyzing the weights of .
Techniques for automatic complexity and termination analysis have been developed for, e.g., term rewrite systems (TRSs) in the literature [5, 29], and there is an annual Termination and Complexity Competition with numerous participating tools [18]. In term rewriting, one considers terms over a set of function symbols and a set of variables . The reduction relation is defined via a set of rewrite rules : If the left-hand side of a rewrite rule in matches a subterm, we can replace this subterm with the right-hand side of the rewrite rule instantiated by the matching substitution. For details, see, e.g., [5, 29].
Example 16 (TRS for Addition).
Let and . A TRS computing the addition of two natural numbers (given in Peano notation via zero and the successor function ) is defined by the two rewrite rules and . allows for the reduction . For derivational complexity analysis, we can consider the wARS .
If the ARS is finitely non-deterministic, then is terminating if and only if for every . While the “if” direction holds for any ARS, due to possibly infinite non-determinism, the “only if” direction does not hold in general.
Example 17 (Non-Deterministic ARS).
Consider the ARS with and from [3]. For , we have as for all there is an -RT of depth with root . However, is terminating.
The definition of can also be adjusted to prove termination and analyze derivational complexity of sequence ARSs.
4.2 Size Bounds
In addition to the runtime of a program, its memory footprint is of interest as well. Consider an operating system which should be able to run forever. However, during this infinite execution, certain values that are stored in memory must not become arbitrarily large, i.e., no overflow should occur. To analyze this, we can use the arctic semiring .
Example 18 (Memory Consumption of Operating System).
Consider a very simplified operating system111111See Sect. A.2 for a more involved operating system algorithm that guarantees mutual exclusion. with two processes and that should be performed repeatedly. The operating system can either be idle, run a process, or add a process at the end of the waiting queue. We represent this by the ARS with . So an object from represents the current state of the operating system (, , or ) and the current waiting queue . The rules of the ARS are , (add a new process to the waiting queue or run some process), (add or to the waiting queue), and (run the process waiting the longest) for all . We use the wARS with for and
Note that we may have a different aggregator for every sequence , i.e., is a constant. We obtain , proving that a reduction leading to a waiting queue of unbounded size exists.
4.3 Probabilistic Rewriting
In [3, 11, 12], ARSs were extended to the probabilistic setting. The relation of a probabilistic ARS has (countable) multi-distributions on the right-hand sides. A multi-distribution on a set is a countable multiset of pairs , where with is a probability and , with . is the set of all multi-distributions on and with is a probabilistic abstract reduction system (pARS). Depending on the property of interest, we can, e.g., use the semiring to describe the termination probability or even the expected derivational complexity of the pARS.
Example 19 (Random Walk).
Consider the biased random walk on given by the probabilistic relation . We use the sARS with , the semiring , the interpretation of the normal form , and the aggregator for every . The weight of the tree from Fig. 2(b) is , since is the probability to reach within two steps. The weight of the infinite extension of the depicted tree is , as such a random walk terminates with probability . In this way one can use semiring semantics to express almost-sure termination (AST) of pARSs [3].
Obviously, we can also consider infinite-support distributions, e.g., consider the probabilistic relation , where denotes the geometric distribution, i.e., for all . Here, we use the sequence ARS with , and the aggregator for every ( and remain as above).
Moreover, we can also use different aggregators and interpretations of normal forms to analyze the probability of reaching a certain normal form, or the expected complexity (i.e., the expected number of reduction steps). For the expected derivational complexity of the biased random walk, we again use the semiring but switch to the interpretation of the normal form and the aggregator , i.e., we add in each step and start with . Then we obtain for every , i.e., the expected derivational complexity is finite for each possible start of the random walk, which proves positive and strong almost-sure termination (PAST and SAST) [3, 12].
4.4 Formal Languages
We can use semirings like to analyze the behavior of systems. Reconsider the setting from Ex. 18. Instead of analyzing the memory consumption of the waiting queue, we can also analyze the possible orders of running processes.
Example 20 (Process Order for Operating System).
Reconsider the sARS for the operating system from Ex. 18. We can use the wARS with , , and
Our operating system allows running the processes in any order, since .
4.5 Combinations of Semirings
Cartesian products (and even matrices) of semirings form a semiring again by performing addition and multiplication pointwise. Moreover, if all the semirings are complete lattices, then so is the resulting Cartesian product semiring.
Lemma 21 (Cartesian Product Semiring).
Let be a family of complete lattice semirings. Then is a complete lattice semiring with , and .
Example 22 (Analyzing Complexity and Safety Simultaneously).
Consider the ARS with . Additionally, consider a certain “unsafe” property, e.g., hitting an even number. To analyze whether all infinite sequences are safe, we take the product semiring over and the Boolean semiring . We use the normal form interpretation and the aggregator for every . The first component describes the derivational complexity, while the second describes whether we reached an even number at some point during the reduction. In Sect. 5, we will see how to prove boundedness (i.e., for every ) indicating safety of every infinite reduction.
Taking tuples for verification is not the same as performing two separate analyses. Analyzing safety and complexity on their own for the ARS from Ex. 22 would fail, since the ARS is neither safe nor has finite complexity for every . Note the change of quantifiers: Instead of “all runs are safe, or all runs are finite”, we prove “all runs are finite or safe”.
4.6 Limitations
The following example illustrates a limit of our approach.
Example 23 (Starvation Freedom).
To analyze starvation freedom, i.e., whether every process will eventually be served, one can use the tuple semiring for our operating system from Ex. 18 (a corresponding more complex example for starvation freedom is presented in Sect. A.2). Now the two entries of the tuples count how often a process was already served. Thus, we can use the wARS with and the aggregator
However, starvation freedom cannot be analyzed via our current definition of in Def. 14. We have for all (i.e., for all non-normal forms). This means that for every such start configuration , there exists a (“worst-case”) reduction of weight where both processes are served infinitely often. However, for starvation freedom, one would have to show that every infinite reduction serves both processes infinitely often (i.e., this would need to hold irrespective of how the non-determinism in the reductions is resolved). However, is not starvation free, since, e.g., we may only serve infinitely often.
So a property like starvation freedom cannot be expressed with our current definition of , because due to the use of the least upper bound in Def. 14, here we only focus on worst-case reductions. An extension of our approach to also analyze (bounds on) best-case reductions in order to prove properties like starvation freedom is an interesting direction for future work.
5 Proving Upper Bounds on Weights
In this section, we present a technique amenable to automation which aims to prove an upper bound on all possible weights of objects , i.e., it shows that for all . For the remaining sections, we fix a wARS .
Definition 24 (Boundedness).
A wARS is bounded if for all .
The examples in Sect. 4 illustrate that boundedness is a crucial property for wARSs, and that depending on the semiring, on the interpretation of the normal forms, and on the aggregators, boundedness may have completely different implications.
We first establish sufficient conditions for boundedness of a wARS in Sect. 5.1. Afterwards, we show in Sect. 5.2 that the well-known interpretation method can be generalized to prove boundedness for wARSs where these conditions are not satisfied.
5.1 Guaranteed Boundedness
One can directly guarantee boundedness by an adequate choice of the semiring, the interpretation of the normal forms, and the aggregators. We say that is universally bounded if there exists a universal bound with for all . An aggregator function is selective if for every there exists an such that . For example, in the bottleneck semiring , finite aggregator functions without constants are always selective, since and are selective functions.
Theorem 25 (Sufficient Condition for Boundedness (1)).
A wARS is
-
not bounded if for some .
-
bounded if is universally bounded and all are selective.
Next, we do not only consider properties of and , but also properties of the sARS in order to guarantee boundedness.
Example 26 (Boundedness for Provenance Analysis Example).
Reconsider the setting of Ex. 1 and the sARS of Ex. 2. Note that all propositional formulas are finite, hence the sARS is finitely branching and terminating. If none of the atomic facts has infinite cost, then no formula has infinite cost, since finite sums and products in the arctic semiring cannot result in if all of its arguments are smaller than .
The latter property of the semiring is called the extremal property (or convex hull concept).
Definition 27 (Extremal Property).
A function over a semiring with has the extremal property if for all . A semiring has the extremal property if and have the extremal property.
If addition and multiplication of a semiring satisfy the extremal property, then sums and products of finite sequences do not evaluate to , i.e., . Thus, every finite aggregator function that does not use the constant never evaluates to . However, this does not necessarily hold for infinite sums, products, and aggregators. Consider, e.g., the subset of the extended natural numbers, where . Selective functions always satisfy the extremal property.
Example 28 (Extremal Property).
Ex. 26 shows that the arctic semiring has the extremal property. The extended naturals semiring also has the extremal property, since and for all . Actually, the extremal property holds for all semirings in Fig. 1 except for the formal languages semiring , where, e.g., . Cartesian products of semirings with the extremal property do not necessarily satisfy the extremal property again: Consider , where the addition of two objects that are different from yields .
This yields another sufficient condition for boundedness (see Ex. 26).
Theorem 29 (Sufficient Condition for Boundedness (2)).
A wARS is bounded if
-
the sARS is terminating, finitely non-deterministic, and finitely branching,
-
the semiring has the extremal property,
-
for all , and
-
all aggregators are finite and do not use as a constant.
5.2 Proving Boundedness via Interpretations
To handle wARSs that neither satisfy the requirements of Thm. 25 nor of Thm. 29, we now extend the well-known interpretation method (see, e.g., [26]) to prove boundedness of general wARSs. In some cases, e.g., when considering term rewriting as in Sect. 4.1, this often allows proving termination automatically. Before presenting the technique to prove boundedness via interpretations, we introduce the notions of monotonicity and continuity.
Definition 30 (Monotonicity, Continuity).
A function on a semiring is monotonic if for all , implies . It is continuous if for all , . A function with is monotonic (continuous) if it is monotonic (continuous) in every argument.
The natural order implies monotonicity of and , and thus, every aggregator function is monotonic as well. An analogous result is obtained if additionally and are continuous.
Lemma 31 (Monotonicity and Continuity of Aggregator Functions).
For a semiring, the operations , , and all aggregator functions are monotonic. Moreover, if and are continuous, then so are all aggregator functions.
Now we show how to use interpretations to prove boundedness of a wARS. The idea is to use an “embedding” (or “ranking function”) which maps every object from to a non-maximal element of the semiring . Due to monotonicity of all aggregator functions, the conditions of Thm. 32 ensure that for all nodes in any finite-depth reduction tree , we have . Hence, is a bound on for all reduction trees .
Theorem 32 (Sufficient and Necessary Condition for Boundedness).
A wARS is bounded if there exists an embedding such that
-
for all and
-
for all .
Then for all . The reverse (“only if”) holds if and are continuous.
As shown in Sect. 4.3, for every probabilistic ARS, we can obtain a corresponding wARS to analyze PAST/SAST. Hence, Thm. 32 allows proving boundedness of this wARS which then implies PAST/SAST of the original probabilistic ARS.
Example 33 (Expected Runtime of Probabilistic ARSs).
We use Thm. 32 to prove that the expected derivational complexity of the biased random walk in Ex. 19 is finite. We use the embedding for all . Note that we indeed have for all . Moreover, for (the only normal form) we have . Regarding the reduction steps, we have for any with :
By Thm. 32, the wARS is bounded, which means that the expected derivational complexity of the biased random walk is finite for every starting position . The embedding gives us a bound on the expected complexity as well, i.e., by Thm. 32 we infer that the expected number of steps is at most three times the start position .
Example 34 (Termination of TRSs).
The next example shows how our approach can be used for automated termination proofs of term rewrite systems. Reconsider the TRS from Ex. 16 with the wARS . We define the embedding with for all recursively as , , and . To prove termination of the rewrite system for all terms, we show that the two inequations required by Thm. 32 hold for all instantiated rewrite rules.121212In order to lift the inequations from rules to reduction steps, one has to ensure that the embedding is strictly monotonic, see, e.g., [5, 29]. For all we have . For the rule and all we get
and for the rule we get . Again, by Thm. 32 the wARS is bounded, hence the TRS terminates.
If one fixes the semiring , the interpretation , and the aggregators , searching for such an embedding can often be automated for arbitrary TRSs using SMT solvers.
Example 35 (Complexity and Safety).
To prove boundedness of the wARS from Ex. 22, we use the embedding if is even and if is odd. Then we have . For odd , we obtain . For even , we get . For even , the reasoning is analogous.
6 Proving Lower Bounds on Weights
Next, we discuss how to analyze lower bounds. In Sect. 6.1, we show how to compute a lower bound on weights and in Sect. 6.2, we show how to prove unboundedness (i.e., ). Such lower bounds are useful to find bugs or potential attacks, e.g., inputs leading to very high computational costs in terms of runtime or memory consumption.
6.1 Approximating the Weight
Since the weight is defined via the supremum of a set, we can approximate from below by considering only nodes up to a certain depth and only certain schedulers. In the following, for every reduction tree and , let denote the tree that results from by removing all nodes with depth .
Corollary 36 (Lower Bound on Weight).
For any , two subsets , and two integers with , we have
Cor. 36 states that we can approximate by starting with some reduction tree with root and considering as a first approximation of the weight (where if ). We can consider nodes of larger depth () and more schedulers () to refine this approximation. However, we have to compute for all reduction trees whose root is labeled with , leading to an exponential number of trees depending on the considered depth and the maximal number of non-deterministic choices between reduction steps of an object.
Thm. 37 shows that this number of calculations is not as high as it seems, and even feasible for deterministic sARSs. Monotonicity of the aggregator functions (Lemma 31) ensures that we have , i.e., to approximate the weight up to depth , we do not have to compute for all , but just . Moreover, we do not need to consider several reduction trees for deterministic systems, but just the supremum obtained when evaluating the “only possible” reduction tree “as much as possible”.
Theorem 37 (Approximating Deterministic Systems).
Let be a deterministic sARS. Then for every , there exists an -reduction tree whose root is labeled with such that and .
6.2 Proving Unboundedness by Increasing Loops
While the interpretation method of Thm. 32 is based on a technique to prove termination of ordinary ARSs, finding loops (i.e., a non-empty reduction sequence ) is one of the basic methods to disprove termination. If we find a finite-depth RT whose root is labeled with and some other node of is also labeled with , then this obviously shows non-termination of the underlying sARS. The reason is that we can obtain an RT of infinite depth by simply using the reduction steps from to repeatedly. For unboundedness, we additionally require that the weight increases with each loop iteration. However, increasing weights are not sufficient for unboundedness, as shown by the following example.
Example 38 (Bounded with Increasing Loop).
Let with and . Moreover, we take the formal languages semiring over , the interpretation , and the aggregators and . Obviously, the wARS admits a loop from to . However, we have , even though we have a loop with increasing weights.
The problem in Ex. 38 is that is not the least upper bound of the weights of the increasing loops. Thus, to infer unboundedness, we require a fixed increase by an element in each iteration such that . Then, we can use the least upper bound of the series of increasing loops as a lower bound for , showing unboundedness.
Before we present the corresponding theorem, we define a partial evaluation of finite-depth trees where the label of the leaf is replaced by a variable .
Definition 39 (Induced Weight Polynomial).
Let be a RT of finite depth with a leaf and let be a specific variable. Then we define:
| if is an inner node and | ||||
The induced weight polynomial is defined by , where is the root of .
Example 40 (Induced Weight Polynomial).
Reconsider the ARS from Ex. 18 in Sect. 4.2. We have the loop and the corresponding finite reduction tree can be seen in Fig. 3. Here, the only leaf is labeled by . If we consider the runtime by using the wARS , then we get the induced weight polynomial . If we consider the size of the waiting list instead, i.e., the wARS from Sect. 4.2, then we get the induced weight polynomial .
Theorem 41 (Proving Unboundedness via Increasing Loops).
Let be a finite RT where both the root and a leaf are labeled with . Moreover, let with . If for all , then .
Example 42 (Unbounded Runtime).
Continuing Ex. 40, we can use Thm. 41 to prove that the runtime of (i.e., the wARS ) is unbounded. Since the induced weight polynomial of the loop from Ex. 40 is , , and for every , we obtain . However, we cannot use Thm. 41 to prove that the memory consumption of (i.e., the wARS to express the size of the waiting list) is unbounded, as there is no with .
There exist several automatic approaches to find loops in, e.g., term rewriting. To lift these techniques to automatic unboundedness proofs for wARSs based on TRSs, one has to formalize the additional property as an SMT problem over the corresponding semiring theory.
7 Conclusion
We have developed semiring semantics for abstract reduction systems using arbitrary complete lattice semirings. These semantics capture and generalize numerous formalisms that have been studied in the literature. Due to our generalization of these formalisms, we can now use techniques and ideas from, e.g., termination analysis, to prove boundedness or other properties (or combinations of properties) of reduction systems using a completely different semiring (e.g., a tuple semiring). In the future, this may be used to improve the automation of specific analyses and lead to further applications of our uniform framework.
There are many directions for future work, e.g., one can try to improve our techniques on proving and disproving boundedness. In order to develop techniques amenable to automation one could focus on term rewrite systems where the reduction relation is represented by a finite set of rules. For proving termination of TRSs, there exist more powerful techniques than just using interpretations (e.g., the dependency pair framework [17]). Thus, we aim to develop a similar framework to analyze boundedness for weighted TRSs in the future. Currently our approach only focuses on (bounds on) worst-case reductions. Therefore, in the future we will also investigate extensions in order to express and analyze properties like starvation freedom where one has to consider all (infinite) reductions. We are also interested in adapting concepts like confluence and unique normal forms to weighted rewriting, e.g., by studying rewrite systems where every reduction tree that starts with the same object has the same weight if it is evaluated “as much as possible”.
References
- [1] Samson Abramsky, Dov M. Gabbay, and Tom S. E. Maibaum. Handbook of Logic in Computer Science. Volume 3. Semantic Structures. Clarendon Press, 1994. URL: https://global.oup.com/academic/product/handbook-of-logic-in-computer-science-9780198537625.
- [2] Emma Ahrens, Jan-Christoph Kassing, Jürgen Giesl, and Joost-Pieter Katoen. Weighted rewriting: Semiring semantics for abstract reduction systems. CoRR, abs/2505.08496, 2025. doi:10.48550/arXiv.2505.08496.
- [3] Martin Avanzini, Ugo Dal Lago, and Akihisa Yamada. On probabilistic term rewriting. Sci. Comput. Program., 185, 2020. doi:10.1016/j.scico.2019.102338.
- [4] Martin Avanzini, Georg Moser, and Michael Schaper. A modular cost analysis for probabilistic programs. Proc. ACM Program. Lang., 4, 2020. doi:10.1145/3428240.
- [5] Franz Baader and Tobias Nipkow. Term Rewriting and All That. Cambridge University Press, 1998. doi:10.1017/CBO9781139172752.
- [6] Christel Baier and Joost-Pieter Katoen. Principles of Model Checking. MIT Press, 2008.
- [7] Kevin Batz, Adrian Gallus, Benjamin Lucien Kaminski, Joost-Pieter Katoen, and Tobias Winkler. Weighted programming: a programming paradigm for specifying mathematical models. Proc. ACM Program. Lang., 6(OOPSLA1):1–30, 2022. doi:10.1145/3527310.
- [8] Vaishak Belle and Luc De Raedt. Semiring programming: A semantic framework for generalized sum product problems. International Journal of Approximate Reasoning, 126:181–201, 2020. doi:10.1016/j.ijar.2020.08.001.
- [9] Guillaume Bonfante, Adam Cichon, Jean-Yves Marion, and Hélène Touzet. Algorithms with polynomial interpretation termination proof. J. Funct. Program., 11(1):33–53, 2001. doi:10.1017/S0956796800003877.
- [10] Guillaume Bonfante, Jean-Yves Marion, and Jean-Yves Moyen. Quasi-interpretations a way to control resources. Theor. Comput. Sci., 412(25):2776–2796, 2011. doi:10.1016/j.tcs.2011.02.007.
- [11] Olivier Bournez and Claude Kirchner. Probabilistic rewrite strategies. Applications to ELAN. In Proc. RTA ’02, LNCS 2378, pages 252–266, 2002. doi:10.1007/3-540-45610-4_18.
- [12] Olivier Bournez and Florent Garnier. Proving positive almost-sure termination. In Proc. RTA ’05, LNCS 3467, pages 323–337, 2005. doi:10.1007/978-3-540-32033-3_24.
- [13] Sophie Brinke, Erich Grädel, Lovro Mrkonjić, and Matthias Naaf. Semiring provenance in the infinite. In The Provenance of Elegance in Computation - Essays Dedicated to Val Tannen, OASIcs 119, pages 3:1–3:26, 2024. doi:10.4230/OASIcs.Tannen.3.
- [14] James Cheney, Laura Chiticariu, and Wang Chiew Tan. Provenance in databases: Why, how, and where. Found. Trends Databases, 1(4):379–474, 2009. doi:10.1561/1900000006.
- [15] Katrin M. Dannert and Erich Grädel. Provenance analysis: A perspective for description logics? In Description Logic, Theory Combination, and All That: Essays Dedicated to Franz Baader on the Occasion of His 60th Birthday, LNCS 11560, pages 266–285, 2019. doi:10.1007/978-3-030-22102-7_12.
- [16] Manfred Droste, Werner Kuich, and Heiko Vogler, editors. Handbook of Weighted Automata. Springer, 2009. doi:10.1007/978-3-642-01492-5.
- [17] Jürgen Giesl, René Thiemann, Peter Schneider-Kamp, and Stephan Falke. Mechanizing and improving dependency pairs. Journal of Automated Reasoning, 37(3):155–203, 2006. doi:10.1007/s10817-006-9057-7.
- [18] Jürgen Giesl, Albert Rubio, Christian Sternagel, Johannes Waldmann, and Akihisa Yamada. The termination and complexity competition. In Proc. TACAS ’19, LNCS 11429, pages 156–166, 2019. Website of TermComp: https://termination-portal.org/wiki/Termination_Competition. doi:10.1007/978-3-030-17502-3_10.
- [19] Boris Glavic. Data provenance. Found. Trends Databases, 9(3-4):209–441, 2021. doi:10.1561/1900000068.
- [20] Todd J. Green, Grigoris Karvounarakis, and Val Tannen. Provenance semirings. In Proc. PODS ’07, pages 31–40, 2007. doi:10.1145/1265530.1265535.
- [21] Todd J. Green and Val Tannen. The semiring framework for database provenance. In Proc. PODS ’17, pages 93–99, 2017. doi:10.1145/3034786.3056125.
- [22] Dieter Hofbauer and Clemens Lautemann. Termination proofs and the length of derivations. In Proc. RTA ’89, LNCS 355, pages 167–177, 1989. doi:10.1007/3-540-51081-8_107.
- [23] Mahmoud Abo Khamis, Hung Q. Ngo, Reinhard Pichler, Dan Suciu, and Yisu Remy Wang. Convergence of Datalog over (pre-) semirings. J. ACM, 71(2):8:1–8:55, 2024. doi:10.1145/3643027.
- [24] Cynthia Kop and Deivid Vale. Cost-size semantics for call-by-value higher-order rewriting. In Proc. FSCD ’23, LIPIcs 260, 2023. doi:10.4230/LIPIcs.FSCD.2023.15.
- [25] Jim Laird, Giulio Manzonetto, Guy McCusker, and Michele Pagani. Weighted relational models of typed lambda-calculi. In Proc. LICS ’13, pages 301–310, 2013. doi:10.1109/LICS.2013.36.
- [26] Dallas S. Lankford. On proving term rewriting systems are Noetherian. Technical Report Memo MTP-3, Department of Mathematics, Louisiana Technical University, 1979. URL: https://www.ens-lyon.fr/LIP/REWRITING/TERMINATION/Lankford_Poly_Term.pdf.
- [27] Matthias Naaf, Florian Frohn, Marc Brockschmidt, Carsten Fuhs, and Jürgen Giesl. Complexity analysis for term rewriting by integer transition systems. In Proc. FroCoS ’17, LNCS 10483, pages 132–150, 2017. doi:10.1007/978-3-319-66167-4_8.
- [28] Igor Sedlár. Kleene algebra with tests for weighted programs. In In Proc. ISMVL ’23, pages 111–116, 2023. doi:10.1109/ISMVL57333.2023.00031.
- [29] Terese. Term Rewriting Systems, volume 55 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 2003.
Appendix A Comparison to Weakest Preweightings for Weighted Imperative Programs
In this appendix, we briefly compare our semantics to the formalism of weakest preweightings () for weighted imperative programs from [7], and we present a more complex mutual exclusion algorithm from [7] which would require weakest liberal preweightings ().
A.1 Weakest Preweightings
Assuming familiarity with the concepts and notation introduced in [7], we show how to adapt them to our setting. This should serve as a high-level illustration of the relationship between weighted abstract reduction systems and the weighted imperative programs from [7]. To do so, we show how to transform the imperative program modeling the ski rental problem from [7] into a weighted ARS using the tropical semiring such that is equal to the “weakest preweighting” of the postweighting on the initial program configuration , where is depicted in Alg. 1.
The ski renting problem is a classical optimization problem. Consider a person that does not own a pair of skis but is going on a skiing trip for an initially unknown number of days. At the dawn of each day, the person can decide whether to rent a pair of skis for 1 € for that day or buy their own pair of skis for € and go skiing without any further costs, instead. What is the optimal strategy for the person to spend a minimal amount of money? In [7] this problem has been modeled via the imperative program in Alg. 1. In general, weighted algorithms contain the standard control-flow instructions from the guarded command language () syntax including non-deterministic branching (), with an additional statement, where is an element from a semiring. The statement represents a operation (or , i.e., skipping the execution step and doing nothing) that is used to give a weight to every execution path through the program. The set of all such programs of the weighted guarded command language is denoted by .
We first define the corresponding sARS representing the possible computations of the program. Here, we let be the set of all configurations of the program and is defined via the transition relation ([7], Definition 3.1). A configuration consists of the remaining program , where denotes an already terminated program; an instantiation of the program variables , where is the set of all such instantiations; a number of already performed execution steps ; and finally, a string indicating the performed choices at non-deterministic steps.
Definition 43 (sARS for Ski Renting Problem).
Following the notations from [7], let be the set of all configurations. Moreover, let . Here, denotes the transition relation according to the small-step operational semantics given in [7], where is the weight of the transition from configuration to configuration . To determine the order of the configurations , we use an arbitrary total order on the transitions. The sARS representing the algorithm of the ski renting problem is .
To answer the question of the ski renting problem, one can compute the weakest preweighting considering the tropical semiring and the postweighting . When applying to the initial configuration where the program variable has the value , one obtains , indicating that it is only beneficial to buy skis if they cost less than the number of skiing days.
A postweighting is a function mapping final states to an element in the semiring, i.e., this corresponds to our interpretation of the normal forms . The transformer aggregates the postweighting along the program execution paths by multiplication and by summing over multiple possibilities during non-determinism. In our setting, this can be expressed by choosing aggregators that are weighted sums for every with for all .
Definition 44 (Aggregators and Interpretation for Ski Renting Problem).
Given a postweighting , we define the interpretation of normal forms as and the aggregators as .
Thus, we obtain the following weighted abstract reduction system.
Definition 45 (wARS for the Ski Renting Problem).
In the end, we get , where is the initial configuration that sets the program variable to the natural number .
Thus, we can express weakest preweightings from [7] in our formalism. One might think that we can even express more than with weakest preweightings, as we can use aggregators that are not just simple weighted sums but arbitrary polynomials. However, we expect that one can transform any program into another program that can represent more complex aggregators of by ordinary weighted sums of . This might be an interesting direction for future research.
A.2 Weakest Liberal Preweightings
In order to express “weakest liberal preweightings” () from [7] in our setting, we would have to extend our definition of in Def. 13. This is similar to the problem of analyzing best-case reductions described in Sect. 4.5.
To see why we currently cannot express , consider Alg. 2 which describes an operating system guaranteeing mutual exclusion. This algorithm from [7] (adapted from [6]) handles processes that want to access a shared critical section which may only be accessed by processes simultaneously. The status of a selected process can be either idle , waiting , or critical . If the process is idle, it becomes waiting. If it is waiting, one checks whether the shared section may be entered . Otherwise (if ), the process keeps on waiting. If process is already in the critical section, it releases it and is updated.
In [7], the natural language semiring and the alphabet is used to describe the different actions, i.e., if process enters the critical section, waits, or releases the critical section, the corresponding branch is weighted by , , or , respectively. Now, allows to reason about the infinite paths represented by this loop. More precisely, one can analyze the language of -words produced by the loop via , and show that there is a word like in the language, which means that process can wait infinitely long. This disproves starvation freedom of Alg. 2.
We can express this algorithm as an sARS similar to the one in Def. 43. As in Ex. 23, to analyze starvation freedom of such an algorithm, we can use the tuple semiring . Then the -th component in a tuple describes how often the process has entered the critical section. In the steps with the weight , the process enters the critical section, so that we have to increase the value in the -th component of the tuple. The corresponding aggregator for such a step would be , where denotes the tuple where the -th component is 1 and all other components are 0. However, as in Ex. 23, starvation freedom cannot be expressed with our current definition of , but we would have to analyze (bounds on) best-case reductions.
