Abstract 1 Introduction 2 Preliminaries 3 Semiring Semantics for Abstract Reduction Systems 4 Expressivity of Semiring Semantics 5 Proving Upper Bounds on Weights 6 Proving Lower Bounds on Weights 7 Conclusion References Appendix A Comparison to Weakest Preweightings for Weighted Imperative Programs

Weighted Rewriting: Semiring Semantics for Abstract Reduction Systems

Emma Ahrens ORCID RWTH Aachen University, Germany Jan-Christoph Kassing ORCID RWTH Aachen University, Germany Jürgen Giesl ORCID RWTH Aachen University, Germany Joost-Pieter Katoen ORCID RWTH Aachen University, Germany
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, Verification
Copyright and License:
[Uncaptioned image] © Emma Ahrens, Jan-Christoph Kassing, Jürgen Giesl, and Joost-Pieter Katoen; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Rewrite systems
; Theory of computation Equational logic and rewriting ; Theory of computation Logic and verification
Related Version:
Full version, including all proofs: https://arxiv.org/abs/2505.08496 [2]
Funding:
Funded by the DFG Research Training Group 2236 UnRAVeL.
Acknowledgements:
We thank the reviewers for their useful remarks and suggestions.
Editors:
Maribel Fernández

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 R, P in a database over the universe U={a,b} with R=U and P=U×U (where each atomic fact, such as Ra or Pab, has a cost in {}), and the formula ψ which represents a database query.

R= cost a 2 b   P= cost cost a a 2 b a a b 7 b b 10   ψ=Ra(PabPbb)

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 𝕊𝖺𝗋𝖼=(±,max,+,,0) to formalize this situation (i.e., we consider {,} with the operations max and + whose identity elements are and 0, respectively):

  • For an atom α, we set α=c, where c 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 φφ=max{φ,φ} and φφ=φ+φ.

This leads to a maximal cost of ψ=Ra+PabPbb=2+max{7,10}=12 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 𝕊𝖼𝗈𝗇𝖿=([0,1],max,,0,1), where all atomic facts are given a certain confidence score.

In general, to compute the weight a of an object a, 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 A 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 A contains all propositional, negation-free formulas over the atomic facts 𝙽𝙵={Ru1,Pu1u2u1,u2U}A (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 1. 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 𝕊𝖺𝗋𝖼=(±,max,+,,0). 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.

  • We generalize abstract reduction systems to a weighted version (Def. 12) that is powerful enough to express complex notions like termination, complexity, and safety of (probabilistic) rewriting, and even novel combinations of such properties (see Sect. 4).

  • We provide several sufficient criteria that ensure boundedness (Thm. 29 and 25).

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

  • Finally, we develop techniques to approximate the weights (Thm. 37) and to detect counterexamples that show unboundedness (Thm. 41).

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 (A,) with a set A and a binary relation A×A.

  • An object aA reduces to b in a single step, abbreviated as ab, if (a,b).

  • An object aA is called a normal form if there is no bA such that ab. The set of all normal forms for (A,) is denoted by 𝙽𝙵.

  • Finally, the ARS (A,) is deterministic if for every object aA there exists at most one bA with ab. 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 aA there exist at most finitely many objects bA with ab.

An important property of ARSs is termination, i.e., the absence of infinite behavior.

Definition 4 (Reduction Sequence, Termination).

Let (A,) be an ARS. A reduction sequence is a finite or infinite sequence a1a2 with aiA, and we say that (A,) 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 S associated with two operations and .

Definition 5 (Semiring).

A semiring 𝕊 is a tuple (S,,,𝟎,𝟏) consisting of a set S (called the carrier) together with two binary functions ,:(S×S)S such that (S,,𝟎) is a commutative monoid (i.e., is commutative and associative with identity element 𝟎), (S,,𝟏) is a monoid, and distributes over . Furthermore, 𝟎 is a multiplicative annihilator, i.e., 𝟎s=s𝟎=𝟎 for all sS.

Sometimes we write 𝕊 or 𝟎𝕊 to clearly indicate the semiring 𝕊. If it is clear from the context, we also use 𝕊 to denote the carrier S. 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 P1,P2Σ, we have P1P2={uvuP1,vP2}.

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 .

𝕊 =(,+,,0,1) 𝕊 =(0,+,,0,1)
𝕊𝗍𝗋𝗈𝗉 =(,min,+,,0) 𝕊𝖺𝗋𝖼 =(±,max,+,,0)
𝕊𝔹 =({𝖿𝖺𝗅𝗌𝖾,𝗍𝗋𝗎𝖾},,,𝖿𝖺𝗅𝗌𝖾,𝗍𝗋𝗎𝖾) 𝕊𝖼𝗈𝗇𝖿 =([0,1],max,,0,1)
𝕊𝖻𝗈𝗍𝗍𝗅𝖾 =(±,max,min,,) 𝕊Σ =(2Σ,,,,{ε})
Figure 1: Non-exhaustive list of complete lattice semirings 𝕊=(S,,,𝟎,𝟏).
Definition 6 (Natural Order).

The natural order on a semiring 𝕊 is defined for all s,t𝕊 as st iff there exists an element u𝕊 with su=t. A semiring is called naturally ordered if is a partial order, i.e., reflexive, transitive, and antisymmetric.444By definition, is reflexive since s𝟎=s, and transitive since sv=t and tw=u imply s(vw)=u 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) T𝕊 exists for every set T𝕊.

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 s𝕊, we have 𝟎s, since 𝟎s=s. 𝟎==𝕊, but also a maximum =S𝕊. Furthermore, the existence of every supremum allows us to define infinite sums and products of sequences, see, e.g., [13].

We define sequences T=(xi)iI=[x1,x2,]𝕊, where either I={i1in} for some n (then T is a finite sequence of length n) or I=1 (then T is an infinite sequence). By 𝖲𝖾𝗊(X), we denote the set of all non-empty sequences over some set X. Furthermore, the subset relation between two sequences T=(xi)iI,T=(xi)iI𝖲𝖾𝗊(X) is defined via prefixes, i.e., we write TT if II and xi=xi for all iI. For a finite sequence T=[s1,,sn]𝖲𝖾𝗊(𝕊), we use the common abbreviation T=i=1nsi=s1sn and T=i=1nsi=s1sn.

Definition 8 (Infinite Sums and Products).

Let 𝕊 be a complete lattice semiring and T 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 T as

T={TfinTfin is a finite prefix of T},T={TfinTfin is a finite prefix of T}.

Infinite sums and products are well defined, since the supremum of any set exists in the complete lattice 𝕊, hence T𝕊 and T𝕊 for all infinite sequences T 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 (A,) consisting of a set A and a binary relation A×𝖲𝖾𝗊(A).

  • We write aB=[b1,b2,] if B𝖲𝖾𝗊(A) and (a,B). Normal forms and 𝙽𝙵 are defined as for ARSs.

  • The sARS (A,) is deterministic if for every aA there is at most one B with aB and finitely non-deterministic if for each aA, there are only finitely many B𝖲𝖾𝗊(A) with aB. The sARS is finitely branching if for every aB, the sequence B 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 (A,) be an sARS. An (A,)-reduction tree ((A,)-RT) 𝔗=(V,E) is a labeled, ordered tree with nodes V and directed edges EV×V, where

  • every node vV is labeled by an object avA and

  • every node v together with its sequence of direct successors vE=[wV(v,w)E] either corresponds to a reduction step av[awwvE] or vE is empty.

We say that (A,) is terminating if all (A,)-RTs have finite depth.888One could instead attempt to define reduction trees in an inductive way. Then every node labeled with a value from A 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 v of 𝔗 and a reduction step avB such that the reduction tree 𝔗 extends 𝔗 by new leaves wb with awb=b and edges (v,wb) for all bB. 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.

(a) Reduction tree for formula ψ
with semantics in 𝕊𝖺𝗋𝖼.
(b) Reduction tree for a random walk with
semantics in 𝕊.
Figure 2: Two example reduction trees, where each node v is labeled with avA and the small numbers are the corresponding weights 𝔗v. Colored nodes are labeled by normal forms.

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 𝒱={v1,v2,} be a set of variables. Then the set of all aggregators (over 𝕊 and 𝒱) is the smallest set with

  • s for every s𝕊 (constants) and v for every v𝒱 (variables),

  • F (sums) and F (products) for every F𝖲𝖾𝗊().

If an aggregator is constructed via finite sequences F, then it is a finite aggregator. Let 𝒱(f) be the set of all variables in f and let 𝗆𝖺𝗑𝒱(f)=sup{ivi𝒱(f)}.

Let f and n with n𝗆𝖺𝗑𝒱(f). Then the aggregator f induces a function f:𝕊n𝕊 in the obvious way: For a sequence T=[s1,]𝖲𝖾𝗊(𝕊) of length n, we have s(T)=s for constants s, vi(T)=si for variables vi and 1in, and (F)(T)=[f1(T),f2(T),] for F=[f1,f2,], where {,}.

Weighted rewriting considers an sARS (A,) together with a semiring 𝕊, and functions 𝖿𝙽𝙵 and 𝖠𝗀𝗀𝗋aB in order to map objects from A to elements of 𝕊.

Definition 12 (Weighted Abstract Reduction System).

A tuple (A,,𝕊,𝖿𝙽𝙵,𝖠𝗀𝗀𝗋aB) is a weighted abstract reduction system (wARS) if

  • (A,) is an sARS,

  • 𝕊 is a semiring,

  • 𝖿𝙽𝙵:𝙽𝙵𝕊 is the interpretation of normal forms,

  • 𝖠𝗀𝗀𝗋aB is the aggregator for every aB,

where 𝗆𝖺𝗑𝒱(𝖠𝗀𝗀𝗋aB)|B|.

For every 𝖠𝗀𝗀𝗋aB, we consider the induced function 𝖠𝗀𝗀𝗋aB:𝕊n𝕊 of arity n=|B|. 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 𝖠𝗀𝗀𝗋φψ[φ,ψ]=v1v2 for every rule φψ[φ,ψ] and 𝖠𝗀𝗀𝗋φψ[φ,ψ]=v1v2 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 𝖠𝗀𝗀𝗋avB are constructed using the operations and of the semiring.

Definition 13 (Semiring Semantics).

For a wARS (A,,𝕊,𝖿𝙽𝙵,𝖠𝗀𝗀𝗋aB) and an (A,)-RT 𝔗=(V,E) of finite depth, we define the weight 𝔗v of 𝔗 at node vV as

𝔗v =𝖿𝙽𝙵(av) if av𝙽𝙵
𝔗v =𝟎 if v is a leaf and av𝙽𝙵
𝔗v =𝖠𝗀𝗀𝗋avB[𝔗wwvE] if v is an inner node and B=[awwvE].

The weight of the whole RT 𝔗 is 𝔗=𝔗r, where rV is the root node of 𝔗.

Note that the order of the children B=[awwvE] is crucial when applying 𝖠𝗀𝗀𝗋avB to [𝔗wwvE]. 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 aA, we consider any finite number of reduction steps and all possible schedulers. Then we define the weight of a as the least upper bound of the weights of all finite-depth reduction trees whose root is labeled with a.

Definition 14 (Semantics with Demonic Non-Determinism).

For a wARS 𝒲=(A,, 𝕊,𝖿𝙽𝙵,𝖠𝗀𝗀𝗋aB) and aA, let Φ(a) be the set of all (A,)-reduction trees of finite depth whose root node is labeled with a. Then we define the weight of a as a={𝔗𝔗Φ(a)}.101010In principle, a, 𝔗, and 𝔗v 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 (A,,𝕊,𝖿𝙽𝙵,𝖠𝗀𝗀𝗋aB), the weight a is well defined for every object aA.

The set Φ(a) takes on different shapes depending on the reduction system. If the reduction system is deterministic, then Φ(a) consists of all finite-depth prefixes of a single (potentially infinite-depth) tree. If the sARS is non-deterministic, then Φ(a) 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 Φ(a).

The computation of the weight a is undecidable in general, since computing single steps with may already be undecidable. However, even if the reductions aB, the interpretation of the normal forms 𝖿𝙽𝙵, and the aggregator functions 𝖠𝗀𝗀𝗋aB are computable, computing the weight a 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 (A,) to a wARS 𝖼𝗉𝗅𝗑(A,)=(A,𝚜,𝕊,𝖿𝙽𝙵𝖼𝗉𝗅𝗑,𝖠𝗀𝗀𝗋a𝚜B𝖼𝗉𝗅𝗑) such that a is equal to the supremum over the lengths of all reduction sequences starting in aA. For this, we use the sequence relation 𝚜={a𝚜[b]ab}, the extended naturals semiring 𝕊, the interpretation 𝖿𝙽𝙵𝖼𝗉𝗅𝗑(a)=𝟎𝕊=0 for all a𝙽𝙵𝚜, and the aggregator 𝖠𝗀𝗀𝗋a𝚜[b]𝖼𝗉𝗅𝗑=1𝕊v1=1+v1 whenever a𝚜[b]. Recall that aggregators use a fixed set of variables 𝒱={v1,}. The derivational complexity of (A,) (i.e., the supremum of the lengths of possible reduction sequences) is obtained by analyzing the weights a of 𝖼𝗉𝗅𝗑(A,).

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 t𝒯(Σ,𝒱) 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 𝒱={x,y}. 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 𝗉𝗅𝗎𝗌(𝗌(x),y)𝗌(𝗉𝗅𝗎𝗌(x,y)) and 𝗉𝗅𝗎𝗌(𝒪,y)y. allows for the reduction 𝗉𝗅𝗎𝗌(𝗌(𝒪),𝗌(𝒪))𝗌(𝗉𝗅𝗎𝗌(𝒪,𝗌(𝒪)))𝗌(𝗌(𝒪)). For derivational complexity analysis, we can consider the wARS (𝒯(Σ,𝒱),𝚜,𝕊,𝖿𝙽𝙵𝖼𝗉𝗅𝗑,𝖠𝗀𝗀𝗋a𝚜B𝖼𝗉𝗅𝗑).

If the ARS (A,) is finitely non-deterministic, then (A,) is terminating if and only if a𝖼𝗉𝗅𝗑(A,)< for every aA. 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 (a,) with a={a} and ={ann}{n+1nn} from [3]. For 𝖼𝗉𝗅𝗑(a,), we have a= as for all n there is an (a,)-RT of depth n+1 with root a. However, (a,) is terminating.

The definition of 𝖼𝗉𝗅𝗑(A,) 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 P1 and P2 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 𝖮𝖲={𝗂𝖽𝗅𝖾(p),𝗐𝖺𝗂𝗍(p),𝗋𝗎𝗇(p)p{P1,P2}}. So an object from 𝖮𝖲 represents the current state of the operating system (𝗂𝖽𝗅𝖾, 𝗐𝖺𝗂𝗍, or 𝗋𝗎𝗇) and the current waiting queue p. The rules of the ARS are 𝗂𝖽𝗅𝖾(p)𝗐𝖺𝗂𝗍(p), 𝗂𝖽𝗅𝖾(p)𝗋𝗎𝗇(p) (add a new process to the waiting queue or run some process), 𝗐𝖺𝗂𝗍(p)𝗂𝖽𝗅𝖾(pP1),𝗐𝖺𝗂𝗍(p)𝗂𝖽𝗅𝖾(pP2) (add P1 or P2 to the waiting queue), and 𝗋𝗎𝗇(P1p)𝗂𝖽𝗅𝖾(p),𝗋𝗎𝗇(P2p)𝗂𝖽𝗅𝖾(p) (run the process waiting the longest) for all p{P1,P2}. We use the wARS (𝖮𝖲,,𝕊𝖺𝗋𝖼,𝖿𝙽𝙵𝗌𝗂𝗓𝖾,𝖠𝗀𝗀𝗋aB𝗌𝗂𝗓𝖾) with 𝖿𝙽𝙵𝗌𝗂𝗓𝖾(𝗋𝗎𝗇(ε))=0 for 𝙽𝙵={𝗋𝗎𝗇(ε)} and

𝖠𝗀𝗀𝗋𝗂𝖽𝗅𝖾(p)𝗐𝖺𝗂𝗍(p)𝗌𝗂𝗓𝖾=𝖠𝗀𝗀𝗋𝗂𝖽𝗅𝖾(p)𝗋𝗎𝗇(p)𝗌𝗂𝗓𝖾=v1𝖠𝗀𝗀𝗋𝗋𝗎𝗇(P1p)𝗂𝖽𝗅𝖾(p)𝗌𝗂𝗓𝖾=𝖠𝗀𝗀𝗋𝗋𝗎𝗇(P2p)𝗂𝖽𝗅𝖾(p)𝗌𝗂𝗓𝖾=v1𝖠𝗀𝗀𝗋𝗐𝖺𝗂𝗍(p)𝗂𝖽𝗅𝖾(pP1)𝗌𝗂𝗓𝖾=𝖠𝗀𝗀𝗋𝗐𝖺𝗂𝗍(p)𝗂𝖽𝗅𝖾(pP2)𝗌𝗂𝗓𝖾=v1𝕊𝖺𝗋𝖼(|p|+1)=max{v1,|p|+1}.

Note that we may have a different aggregator for every sequence p{P1,P2}, i.e., |p|+1 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 A is a countable multiset of pairs (p:a), where p with 0<p1 is a probability and aA, with (p:a)μp=1. Dist(A) is the set of all multi-distributions on A and (A,) with A×Dist(A) 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 ={n+1{2/3:n,1/3:n+2}n}. We use the sARS (,) with ={n+1[n,n+2]n}, the semiring 𝕊, the interpretation of the normal form 𝖿𝙽𝙵(0)=1, and the aggregator 𝖠𝗀𝗀𝗋n+1[n,n+2]=(2/3𝕊v1)𝕊(1/3𝕊v2)=2/3v1+1/3v2 for every n. The weight of the tree 𝔗 from Fig. 2(b) is 𝔗=4/9, since 4/9 is the probability to reach 0 within two steps. The weight of the infinite extension 𝔗 of the depicted tree 𝔗 is 𝔗=1, as such a random walk terminates with probability 1. 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 ={n+1{Geo(m):mm}n}, where Geo denotes the geometric distribution, i.e., Geo(m)=(1/2)m+1 for all m. Here, we use the sequence ARS (,) with ={n+1[0,1,2,]n}, and the aggregator 𝖠𝗀𝗀𝗋n+1[0,1,2,]=m=0(Geo(m)𝕊vm+1) for every n (𝖿𝙽𝙵 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 𝖿𝙽𝙵(0)=0 and the aggregator 𝖠𝗀𝗀𝗋n+1[n,n+2]=1+2/3v1+1/3v2, i.e., we add 1 in each step and start with 0. Then we obtain n for every n, 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 (𝖮𝖲,,𝕊Σ,𝖿𝙽𝙵𝖿𝖺𝗂𝗋,𝖠𝗀𝗀𝗋aB𝖿𝖺𝗂𝗋) with Σ={P1,P2}, 𝖿𝙽𝙵𝖿𝖺𝗂𝗋(𝗋𝗎𝗇(ε))=𝟏𝕊Σ={ε}, and

𝖠𝗀𝗀𝗋𝗂𝖽𝗅𝖾(p)𝗐𝖺𝗂𝗍(p)𝖿𝖺𝗂𝗋=𝖠𝗀𝗀𝗋𝗂𝖽𝗅𝖾(p)𝗋𝗎𝗇(p)𝖿𝖺𝗂𝗋=v1𝖠𝗀𝗀𝗋𝗐𝖺𝗂𝗍(p)𝗂𝖽𝗅𝖾(pP1)𝖿𝖺𝗂𝗋=𝖠𝗀𝗀𝗋𝗐𝖺𝗂𝗍(p)𝗂𝖽𝗅𝖾(pP2)𝖿𝖺𝗂𝗋=v1𝖠𝗀𝗀𝗋𝗋𝗎𝗇(P1p)𝗂𝖽𝗅𝖾(p)𝖿𝖺𝗂𝗋={P1}𝕊Σv1𝖠𝗀𝗀𝗋𝗋𝗎𝗇(P2p)𝗂𝖽𝗅𝖾(p)𝖿𝖺𝗂𝗋={P2}𝕊Σv1

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 (𝕊i)1in be a family of complete lattice semirings. Then 𝕊=×i=1n𝕊i is a complete lattice semiring with (x1,,xn)𝕊(y1,,yn)=(x1𝕊1y1,,xn𝕊nyn), and (x1,,xn)𝕊(y1,,yn)=(x1𝕊1y1,,xn𝕊nyn).

Example 22 (Analyzing Complexity and Safety Simultaneously).

Consider the ARS (,) with ={nn2nodd}{nn+2n2,neven}{nn2n2,neven}. 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 𝖿𝙽𝙵(0)=(0,𝗍𝗋𝗎𝖾) and the aggregator 𝖠𝗀𝗀𝗋n𝚜[m]=(1,[nmod2=0])𝕊v1 for every nm. 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., n(,𝗍𝗋𝗎𝖾) for every n) 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 n. 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 (𝖮𝖲,,𝕊×𝕊,𝖿𝙽𝙵𝗌𝗍𝖺𝗋𝗏,𝖠𝗀𝗀𝗋aB𝗌𝗍𝖺𝗋𝗏) with 𝖿𝙽𝙵𝗌𝗍𝖺𝗋𝗏(𝗋𝗎𝗇(ε))=𝟎(𝕊×𝕊)=(0,0) and the aggregator

𝖠𝗀𝗀𝗋𝗂𝖽𝗅𝖾(p)𝗐𝖺𝗂𝗍(p)𝗌𝗍𝖺𝗋𝗏=𝖠𝗀𝗀𝗋𝗂𝖽𝗅𝖾(p)𝗋𝗎𝗇(p)𝗌𝗍𝖺𝗋𝗏=v1𝖠𝗀𝗀𝗋𝗐𝖺𝗂𝗍(p)𝗂𝖽𝗅𝖾(pP1)𝗌𝗍𝖺𝗋𝗏=𝖠𝗀𝗀𝗋𝗐𝖺𝗂𝗍(p)𝗂𝖽𝗅𝖾(pP2)𝗌𝗍𝖺𝗋𝗏=v1𝖠𝗀𝗀𝗋𝗋𝗎𝗇(P1p)𝗂𝖽𝗅𝖾(p)𝗌𝗍𝖺𝗋𝗏=(1,0)v1𝖠𝗀𝗀𝗋𝗋𝗎𝗇(P2p)𝗂𝖽𝗅𝖾(p)𝗌𝗍𝖺𝗋𝗏=(0,1)v1

However, starvation freedom cannot be analyzed via our current definition of a in Def. 14. We have a=(,) for all a𝖮𝖲{𝗋𝗎𝗇(ε)} (i.e., for all non-normal forms). This means that for every such start configuration a, 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 P1 infinitely often.

So a property like starvation freedom cannot be expressed with our current definition of a, 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 a of objects aA, i.e., it shows that a for all aA. For the remaining sections, we fix a wARS (A,,𝕊,𝖿𝙽𝙵,𝖠𝗀𝗀𝗋aB).

Definition 24 (Boundedness).

A wARS is bounded if a for all aA.

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 C𝕊{} with 𝖿𝙽𝙵(a)C for all a𝙽𝙵. An aggregator function 𝖠𝗀𝗀𝗋aB:𝕊|B|𝕊 is selective if for every [s1,s2,]𝕊|B| there exists an 1i|B| such that 𝖠𝗀𝗀𝗋aB[s1,s2,]=si. For example, in the bottleneck semiring 𝕊𝖻𝗈𝗍𝗍𝗅𝖾=(±,max,min,,), finite aggregator functions without constants are always selective, since max and min are selective functions.

Theorem 25 (Sufficient Condition for Boundedness (1)).

A wARS is

  • not bounded if 𝖿𝙽𝙵(a)= for some a𝙽𝙵.

  • bounded if 𝖿𝙽𝙵 is universally bounded and all 𝖠𝗀𝗀𝗋aB are selective.

Next, we do not only consider properties of 𝖿𝙽𝙵 and 𝖠𝗀𝗀𝗋aB, 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 𝕊𝖺𝗋𝖼=(±,max,+,,0) 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 f:𝕊n𝕊 over a semiring 𝕊 with n has the extremal property if f(e1,,en) for all e1,,en𝕊{}. A semiring 𝕊=(S,,,𝟎,𝟏) 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 T𝕊{} do not evaluate to , i.e., T and T. 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 a+b and ab for all a,b. 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 (A,) is terminating, finitely non-deterministic, and finitely branching,

  • the semiring 𝕊 has the extremal property,

  • 𝖿𝙽𝙵(a) for all a𝙽𝙵, and

  • all aggregators 𝖠𝗀𝗀𝗋aB are finite and do not use as a constant.

While the requirements in Thm. 29 may seem restrictive, the ones on 𝖿𝙽𝙵 and 𝖠𝗀𝗀𝗋aB only consider certain edge cases. However, termination of the underlying sARS is a crucial requirement for Thm. 29 that one has to prove beforehand.

Ex. 17 presents an unbounded wARS which satisfies many of the constraints from Thm. 29, but illustrates the importance of finite non-determinism. Infinite non-determinism allows the existence of a chain of reduction trees with ascending weights which reaches in the limit.

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 f:𝕊𝕊 on a semiring 𝕊 is monotonic if for all s,t𝕊, st implies f(s)f(t). It is continuous if for all T𝕊, f(T)={f(t)tT}=f(T). A function f:𝕊n𝕊 with n2 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 A 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 v in any finite-depth reduction tree 𝔗, we have 𝔢(av)𝔗v. Hence, 𝔢(a) is a bound on 𝔗 for all reduction trees 𝔗Φ(a).

Theorem 32 (Sufficient and Necessary Condition for Boundedness).

A wARS is bounded if there exists an embedding 𝔢:A𝕊{} such that

  • 𝔢(a)𝖿𝙽𝙵(a) for all a𝙽𝙵 and

  • 𝔢(a)𝖠𝗀𝗀𝗋aB[𝔢(b)bB] for all aB.

Then 𝔢(a)a for all aA. 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 𝔢(n)=3n=3n for all n. Note that we indeed have 𝔢(n)= for all nA=. Moreover, for 0 (the only normal form) we have 𝔢(0)=0=𝖿𝙽𝙵(0). Regarding the reduction steps, we have for any n+1[n,n+2] with n:

𝔢(n+1)𝖠𝗀𝗀𝗋n+1[n,n+2][𝔢(n),𝔢(n+2)]3(n+1)𝖠𝗀𝗀𝗋n+1[n,n+2][3n,3(n+2)]3+3n12/33n1/33(n+2)= 3+3n

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

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 (𝒯(Σ,𝒱),𝚜,𝕊,𝖿𝙽𝙵𝖼𝗉𝗅𝗑,𝖠𝗀𝗀𝗋a𝚜B𝖼𝗉𝗅𝗑). We define the embedding 𝔢:𝒯(Σ,𝒱) with 𝔢(t) for all t𝒯(Σ,𝒱) recursively as 𝔢(𝒪)=0, 𝔢(𝗌(t))=𝔢(t)1, and 𝔢(𝗉𝗅𝗎𝗌(t1,t2))=2𝔢(t1)𝔢(t2)1. 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 t𝙽𝙵𝚜 we have 𝔢(t)𝖿𝙽𝙵𝖼𝗉𝗅𝗑(𝒪)=0. For the rule 𝗉𝗅𝗎𝗌(𝗌(x),y)𝚜[𝗌(𝗉𝗅𝗎𝗌(x,y))] and all t1,t2𝒯(Σ,𝒱) we get

𝔢(𝗉𝗅𝗎𝗌(𝗌(t1),t2))𝖠𝗀𝗀𝗋a𝚜[b](𝔢(𝗌(𝗉𝗅𝗎𝗌(t1,t2))))2𝔢(t1)𝔢(t2)31𝔢(𝗌(𝗉𝗅𝗎𝗌(t1,t2)))2𝔢(t1)+𝔢(t2)+32𝔢(t1)𝔢(t2)3= 2𝔢(t1)+𝔢(t2)+3

and for the rule 𝗉𝗅𝗎𝗌(𝒪,y)𝚜[y] we get 𝔢(𝗉𝗅𝗎𝗌(𝒪,t1))𝖠𝗀𝗀𝗋a𝚜[b](𝔢(t1))𝔢(t1)+1𝔢(t1)+1. Again, by Thm. 32 the wARS is bounded, hence the TRS terminates.

If one fixes the semiring 𝕊, the interpretation 𝖿𝙽𝙵, and the aggregators 𝖠𝗀𝗀𝗋aB, 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 𝔢(n)=(|n|2,𝗍𝗋𝗎𝖾) if n is even and 𝔢(n)=(,𝖿𝖺𝗅𝗌𝖾) if n is odd. Then we have 𝔢(0)=(0,𝗍𝗋𝗎𝖾)=𝖿𝙽𝙵(0). For odd n, we obtain 𝔢(n)=(,𝖿𝖺𝗅𝗌𝖾)=𝖠𝗀𝗀𝗋n𝚜[n2](𝔢(n2))=𝖠𝗀𝗀𝗋n𝚜[n2](,𝖿𝖺𝗅𝗌𝖾)=(1+,[nmod2=0]𝖿𝖺𝗅𝗌𝖾). For even n2, we get 𝔢(n)=(n2,𝗍𝗋𝗎𝖾)=𝖠𝗀𝗀𝗋n𝚜[n2](𝔢(n2))=𝖠𝗀𝗀𝗋n𝚜[n2](n21,𝗍𝗋𝗎𝖾)=(1+n21,[nmod2=0]𝗍𝗋𝗎𝖾). For even n2, 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 a and in Sect. 6.2, we show how to prove unboundedness (i.e., a=). 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 a is defined via the supremum of a set, we can approximate a from below by considering only nodes up to a certain depth and only certain schedulers. In the following, for every reduction tree 𝔗 and n0, let 𝔗|n denote the tree that results from 𝔗 by removing all nodes with depth >n.

Corollary 36 (Lower Bound on Weight).

For any aA, two subsets ΨΘΦ(a), and two integers n,m with nm, we have

𝟎{𝔗|n𝔗Ψ,nn}{𝔗|m𝔗Θ,mm}a.

Cor. 36 states that we can approximate a by starting with some reduction tree 𝔗 with root a and considering 𝔗|0 as a first approximation of the weight (where 𝔗|0=𝟎 if a𝙽𝙵). We can consider nodes of larger depth (𝟎𝔗|0{𝔗|0,𝔗|1}{𝔗|0,𝔗|1,𝔗|2}a) and more schedulers (𝟎𝔗|n{𝔗|n,𝔗|n}a) to refine this approximation. However, we have to compute 𝔗|n for all reduction trees 𝔗 whose root is labeled with a, 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 𝟎𝔗|0𝔗|1𝔗|2a, i.e., to approximate the weight up to depth n, we do not have to compute 𝔗|n for all nn, but just 𝔗|n. 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 (A,) be a deterministic sARS. Then for every aA, there exists an (A,)-reduction tree 𝔗 whose root is labeled with a such that 𝟎𝔗|0𝔗|1𝔗|2a and {𝔗|nn}=a.

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 aa) is one of the basic methods to disprove termination. If we find a finite-depth RT 𝔗 whose root is labeled with a and some other node of 𝔗 is also labeled with a, 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 a to a 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 A={a,b} with a[a] and a[b]. Moreover, we take the formal languages semiring 𝕊Σ over Σ={0,1}, the interpretation 𝖿𝙽𝙵(b)=𝟏𝕊Σ={ε}, and the aggregators 𝖠𝗀𝗀𝗋a[a](x)=({1}𝕊Σx)𝕊Σx={1wwx}x and 𝖠𝗀𝗀𝗋a[b](x)=x. Obviously, the wARS (A,) admits a loop from a to a. However, we have a={1}Σ=, 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 t in each iteration such that i=1t=. Then, we can use the least upper bound of the series of increasing loops as a lower bound for a, showing unboundedness.

Before we present the corresponding theorem, we define a partial evaluation of finite-depth trees where the label of the leaf v0 is replaced by a variable X.

Definition 39 (Induced Weight Polynomial).

Let 𝔗 be a RT of finite depth with a leaf v0 and let X be a specific variable. Then we define:

𝔗v0v0 =X
𝔗v0v =𝖿𝙽𝙵(av) if vv0 and av𝙽𝙵,
𝔗v0v =𝟎 if vv0 is a leaf and av𝙽𝙵,
𝔗v0v =𝖠𝗀𝗀𝗋avB[𝔗v0wwvE] if v is an inner node and B=[awwvE]

The induced weight polynomial 𝒫v0(𝔗)𝕊[X] is defined by 𝒫v0(𝔗)=𝔗v0r, where rV is the root of 𝔗.

Example 40 (Induced Weight Polynomial).

Reconsider the ARS (𝖮𝖲,) from Ex. 18 in Sect. 4.2. We have the loop 𝗂𝖽𝗅𝖾(ε)𝗐𝖺𝗂𝗍(ε)𝗂𝖽𝗅𝖾(P1)𝗋𝗎𝗇(P1)𝗂𝖽𝗅𝖾(ε) and the corresponding finite reduction tree can be seen in Fig. 3. Here, the only leaf v0 is labeled by 𝗂𝖽𝗅𝖾(ε). If we consider the runtime by using the wARS 𝖼𝗉𝗅𝗑(𝖮𝖲,), then we get the induced weight polynomial X+4. If we consider the size of the waiting list instead, i.e., the wARS (𝖮𝖲,,𝕊𝖺𝗋𝖼,𝖿𝙽𝙵𝗌𝗂𝗓𝖾,𝖠𝗀𝗀𝗋aB𝗌𝗂𝗓𝖾) from Sect. 4.2, then we get the induced weight polynomial max{X,1}.

Theorem 41 (Proving Unboundedness via Increasing Loops).

Let 𝔗 be a finite RT where both the root r and a leaf v0r are labeled with a. Moreover, let t𝕊 with i=1t=. If 𝒫v0(𝔗)(s)st for all s𝕊, then a=.

Figure 3: An example of a finite reduction tree containing a loop from 𝗂𝖽𝗅𝖾(ε) to itself. The corresponding evaluation of the induced weight polynomial for the runtime is depicted in red above the nodes, and for the space of the waiting list in blue below the nodes.
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 X+4, i=14=, and 𝒫v0(𝔗)(s)s+4 for every s𝕊, we obtain 𝗂𝖽𝗅𝖾(ε)=. However, we cannot use Thm. 41 to prove that the memory consumption of (𝖮𝖲,) (i.e., the wARS (𝖮𝖲,,𝕊𝖺𝗋𝖼,𝖿𝙽𝙵𝗌𝗂𝗓𝖾,𝖠𝗀𝗀𝗋aB𝗌𝗂𝗓𝖾) to express the size of the waiting list) is unbounded, as there is no t𝕊𝖺𝗋𝖼{} with i=1t=.

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 t𝕊:i=1t=s𝕊:𝒫v0(𝔗)(s)st 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 δ0 is equal to the “weakest preweighting” 𝗐𝗉𝖲𝗄𝗂𝖠𝗅𝗀(𝟏) of the postweighting 𝟏 on the initial program configuration δ0, where 𝖲𝗄𝗂𝖠𝗅𝗀 is depicted in Alg. 1.

Algorithm 1 SkiAlg algorithm modeling the ski rental problem from [7].

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 n 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 y € 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 s statement, where s𝕊 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 (A,) representing the possible computations of the program. Here, we let A be the set of all configurations of the program and is defined via the transition relation ([7], Definition 3.1). A configuration (C,σ,n,w) consists of the remaining program C𝗐𝖦𝖢𝖫{}, 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 n; and finally, a string w{L,R} indicating the performed choices at non-deterministic steps.

Definition 43 (sARS for Ski Renting Problem).

Following the notations from [7], let Q=(𝗐𝖦𝖢𝖫{})×Σ××{L,R} be the set of all configurations. Moreover, let ={δ[δ1,δ2,](δ,w,δi)Δ}. Here, ΔQ×𝕊×Q denotes the transition relation according to the small-step operational semantics given in [7], where w is the weight of the transition (δ,w,δi) from configuration δ to configuration δi. To determine the order of the configurations δ1,δ2,, we use an arbitrary total order on the transitions. The sARS representing the algorithm of the ski renting problem is (Q,).

To answer the question of the ski renting problem, one can compute the weakest preweighting 𝗐𝗉𝖲𝗄𝗂𝖠𝗅𝗀(𝟏) considering the tropical semiring 𝕊𝗍𝗋𝗈𝗉=(,min,+,,0) and the postweighting 𝟏. When applying 𝗐𝗉𝖲𝗄𝗂𝖠𝗅𝗀(𝟏) to the initial configuration where the program variable n has the value n0, one obtains n0y=min{n0,y}, indicating that it is only beneficial to buy skis if they cost less than the number of skiing days.

A postweighting is a function f:Σ𝕊 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 𝖠𝗀𝗀𝗋aB=1i|B|eivi for every aB with ei𝕊 for all 1i|B|.

Definition 44 (Aggregators and Interpretation for Ski Renting Problem).

Given a postweighting f, we define the interpretation of normal forms as 𝖿𝙽𝙵=f and the aggregators as 𝖠𝗀𝗀𝗋aB=[wivi(a,wi,bi)Δ].

Thus, we obtain the following weighted abstract reduction system.

Definition 45 (wARS for the Ski Renting Problem).

The wARS for the ski renting problem is (Q,,𝕊𝗍𝗋𝗈𝗉,𝖿𝙽𝙵,𝖠𝗀𝗀𝗋aB), with Q, as in Def. 43 and 𝖿𝙽𝙵, 𝖠𝗀𝗀𝗋aB as in Def. 44.

In the end, we get δ0=𝗐𝗉𝖲𝗄𝗂𝖠𝗅𝗀(𝟏)(δ0)=n0y=max{n0,y}, where δ0 is the initial configuration that sets the program variable n to the natural number n0.

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 C into another 𝗐𝖦𝖢𝖫 program C that can represent more complex aggregators of C by ordinary weighted sums of C. 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 a 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 N processes that want to access a shared critical section which may only be accessed by y processes simultaneously. The status [i] of a selected process i can be either idle (n), waiting (w), or critical (c). If the process i is idle, it becomes waiting. If it is waiting, one checks whether the shared section may be entered (y>0). Otherwise (if y=0), the process keeps on waiting. If process i is already in the critical section, it releases it and y is updated.

Algorithm 2 Operating system for mutual exclusion from [7].

In [7], the natural language semiring and the alphabet Σ={Ci,Wi,Ri1iN} is used to describe the different actions, i.e., if process i enters the critical section, waits, or releases the critical section, the corresponding branch is weighted by Ci, Wi, or Ri, 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 W2ω in the language, which means that process 2 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 ×i=1N𝕊. Then the i-th component in a tuple describes how often the process i has entered the critical section. In the steps with the weight Ci, the process i enters the critical section, so that we have to increase the value in the i-th component of the tuple. The corresponding aggregator for such a step would be eiv1, where ei denotes the tuple (0,,0,1,0,,0) where the i-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 a, but we would have to analyze (bounds on) best-case reductions.