Abstract
We propose a new order-theoretic characterisation of the class of polytime computable functions. To this avail we define the small polynomial path order ( for short). This termination order entails a new syntactic method to analyse the innermost runtime complexity of term rewrite systems fully automatically: for any rewrite system compatible with that employs recursion up to depth d, the (innermost) runtime complexity is polynomially bounded of degree d. This bound is tight. Thus we obtain a direct correspondence between a syntactic (and easily verifiable) condition of a program and the asymptotic worst-case complexity of the program.
Keywords: Term rewriting, Complexity analysis, Implicit computational complexity, Automation
1. Introduction
In this paper we are concerned with the complexity analysis of term rewrite systems (TRSs for short). Based on a careful investigation into the principle of predicative recursion as proposed by Bellantoni and Cook [1] we introduce a new termination order, the small polynomial path order ( for short). The order provides a new characterisation of the class of polytime computable functions. Any function f computable by a TRS compatible with is polytime computable. On the other hand for any polytime computable function f, there exists a TRS computing f such that is compatible with . Moreover directly relates the depth of recursion of a given TRS to the polynomial degree of its runtime complexity. More precisely, we call a rewrite system predicative recursive of degree d if is compatible with and the depth of recursion of all function symbols in is bounded by d (see Section 3 for the formal definition). We establish that any predicative recursive rewrite system of degree d admits runtime complexity in . Here n refers to the sum of the sizes of inputs. Furthermore we obtain a novel, order-theoretic characterisation of , the class of functions computed on register machines in steps.
Thus we obtain a direct correspondence between a syntactic (and easily verifiable) condition of a program and the asymptotic worst-case complexity of the program. In this sense our work is closely related to similar studies in the field of implicit computational complexity (ICC for short). On the other hand the order entails a new syntactic criteria to automatically establish polynomial runtime complexity of a given TRS. This criteria extends the state of the art in runtime complexity analysis as it is more precise or more efficient than related techniques. Note that the proposed syntactic method to analyse the (innermost) runtime complexity of rewrite systems is fully automatic. For any given TRS, compatibility with can be efficiently checked by a machine. Should this check succeed, we get an asymptotic bound on the runtime complexity directly from the parameters of the order. It should perhaps be emphasised that compatibility of a TRS with implies termination and thus our complexity analysis technique does not presuppose termination.
In sum, in this work we make the following contributions:
-
–
We propose a new recursion-theoretic characterisation over binary words of the class . We establish that those functions that are definable with d nestings of predicative recursion can be computed by predicative recursive TRSs of degree d (cf. Theorem 4). Note that these functions belong to .
-
–
We propose the new termination order ; captures the recursion-theoretic principles of the class . Thus we obtain a new order-theoretic characterisation of the class . Moreover, for any predicative recursive TRS of degree d its runtime complexity lies in (cf. Theorem 1). Furthermore this bound is tight, that is, we provide a family of TRSs, delineated by , whose runtime complexity is bounded from below by , cf. Example 5.
-
–
We extend upon by proposing a generalisation, denoted , admitting the same properties as above. This generalisations incorporates a more general recursion scheme that makes use of parameter substitution (cf. Theorem 2).
-
–
We establish a novel, order-theoretic characterisation of . We show that corresponds to the class of functions computable by tail-recursive predicative TRSs of degree d. This characterisation is based on the generalised small polynomial path order (cf. Theorem 6).
-
–
gives rise to a new syntactic method for polynomial runtime complexity method. This method is fully automatic. We have implemented the order in the Tyrolean Complexity Tool
, version 2.0, an open source complexity analyser [2]. The experimental evidence obtained indicates the efficiency of the method and the obtained increase in precision.
1.1. Related work
There are several accounts of predicative analysis of recursion in the (ICC) literature. We mention only those related works which are directly comparable to our work. See [3] for an overview on ICC.
The class is a syntactic restriction of the recursion-theoretic characterisation of the class of exponential time computable functions, given by Arai and the second author in [4]. To account for the fact that is not closed under composition in general, the definition of relies on a syntactically restricted form of composition. The same composition scheme allows a fine-grained control in our class through the degree of recursion. In [5] the authors use the class as a sufficient basis for an order-theoretic account of , the exponential path order ( for short). Due to the close relationship of and , our order is both conceptually and technically close to .
Notably the clearest connection of our work is to Marion's light multiset path order (LMPO for short) [6] and the polynomial path order ( for short) [7–9]. Both orders form a strict extension of , but lack the precision of the latter. Although LMPO characterises , the runtime complexity of compatible TRSs is not polynomially bounded in general. induces polynomial runtime complexities, but the obtained complexity certificate is usually very imprecise. In particular, due to the multiset status underlying , for each one can form a TRS compatible with that defines only a single function, but whose runtime is bounded from below by a polynomial of degree d, in the sizes of the inputs.
In Bonfante et al. [10] restricted classes of polynomial interpretations are studied that can be employed to obtain polynomial upper bounds on the runtime complexity of TRSs. Polynomial interpretations are complemented with quasi-interpretations in [11], giving rise to alternative characterisations of complexity classes. None of the above results are applicable to relate the depth of recursion to the runtime complexity, in the sense mentioned above. Furthermore it is unknown how the body of work on quasi-interpretations can be employed in the context of runtime complexity analysis. We have also drawn motivation from Leivant's and Marion's characterisations of [12,13], that provide related fine-grained classification of the polytime computable functions. Again, these results lack applicability in the context of runtime complexity analysis.
Polynomial complexity analysis is an active research area in rewriting. Starting from [14] interest in this field greatly increased over the last years, see for example [15–18] and [19] for an overview. This is partly due to the incorporation of a dedicated category for complexity into the annual termination competition (TERMCOMP).1 However, it is worth emphasising that the most powerful techniques for runtime complexity analysis currently available, basically employ semantic considerations on the rewrite systems, which are notoriously inefficient.
We also want to mention ongoing approaches for the automated analysis of resource usage in programs. Notably, Hoffmann et al. [20] provide an automatic multivariate amortised cost analysis exploiting typing, which extends earlier results on amortised cost analysis. Finally Albert et al. [21] present an automated complexity tool for Java Bytecode programs, Alias et al. [22] give a complexity and termination analysis for flowchart programs, and Gulwani et al. [23] as well as Zuleger et al. [24] provide an automated complexity tool for C programs.
1.2. Outline
We present the main intuition behind and provide an informal account of the obtained technical results.
The order essentially embodies the predicative analysis of recursion set forth by Bellantoni and Cook [1]. In [1] a recursion-theoretic characterisation of the class of polytime computable functions is proposed. This analysis is connected to the important principle of tiering introduced by Simmons [25] and Leivant [26,27,12]. The essential idea is that the arguments of a function are separated into normal and safe arguments (or correspondingly into arguments of different tiers). Building on this work we present a subclass of . Crucially the class admits only a weak form of composition. Inspired by a result of Handley and Wainer [28], we show that captures the polytime functions. This establishes our first main result.
We formulate the class over the set of binary words, the empty word is denoted by ϵ. Arguments of functions are partitioned into normal and safe ones. In notation, we write where normal arguments are to the left, and safe arguments to the right of the semicolon. Abbreviate and . The class , depicted in Fig. 1, is the smallest class containing certain initial functions and closed under safe recursion on notation (SRN) and weak safe composition (WSC). By the weak form of composition only values are ever substituted into normal argument positions.
Fig. 1.
Defining initial functions and operations for .
Suppose the definition of a TRS is based on the equations in . It is not difficult to deduce a precise bound on the runtime complexity of by measuring the number of nested applications of safe recursion, the so called depth of recursion. In contrast Bellantoni and Cooks definition [1] of is obtained from Fig. 1 by replacing weak safe composition with the more liberal scheme of safe composition (SC): . As soon as one of the functions is size increasing, a tight correspondence between the runtime complexity and the depth of recursion is lost.
Our central observation is that from the function algebra , one can distill a termination argument for the TRS . With , this implicit termination argument is formalised as a termination order. In order to employ the separation of normal and safe arguments, we fix for each defined symbol in a partitioning of argument positions into normal and safe positions. For constructors we fix (as in ) that all argument positions are safe. Moreover restricts recursion to normal argument. Dual, only safe argument positions allow the substitution of recursive calls. Via the order constraints we can also guarantee that only normal arguments are substituted at normal argument positions. We emphasise that our notion of predicative recursive TRS is more liberal than the class . Notably values are not restricted to words, but can be formed from arbitrary constructors. We allow arbitrary deep right-hand sides, and implicit casting from normal to safe arguments. Still the main principle underlying remains reflected.
The remainder of the paper is organised as follows. After giving some preliminaries, Section 3 introduces the order . Here we also prove correctness of with respect to runtime complexity analysis. In Section 4 we incorporate parameter substitution into the order . In Section 5 we then show that these orders are complete for , in particular we precisely relate to the class . In total we obtain an order-theoretic characterisation of . Exploiting the fine-grained control given by the degree of recursion, in Section 6 we provide an order-theoretic characterisation of . Finally in Sections 7 and 8 we clarify the expressiveness of the established small polynomial path orders and conclude.
2. Preliminaries
We denote by the set of natural numbers . For a finite alphabet of characters, we denote by the set of words over , the empty word is denoted by ε. Let R be a binary relation. We denote by the transitive, by the transitive and reflexive closure, and denotes for the n-fold composition of R. We write aRb for , the relation R is well-founded if there exists no infinite sequence . The relation R is a preorder if it is transitive and reflexive, it is a strict partial order if it is irreflexive, antisymmetric and transitive, and R is an equivalence relation if it is reflexive, symmetric and transitive. Note that the transitive and reflexive closure of an order R (on a set S) gives always a preorder. Consider a preorder ⩾. Define if and . Then this equivalence defines a partitioning of ⩾ into the equivalence ∼ and a strict partial order >.
2.1. Term rewriting
We assume at least nodding acquaintance with the basics of term rewriting [29]. We fix a countably infinite set of variables and a finite set of function symbols , the signature. For each , the arity of f is fixed. The set of terms formed from and is denoted by . A term is called ground if it contains no variables. The set of ground terms is indicated by . The signature contains a distinguished set of constructors , elements of are called values. Elements of that are not constructors are called defined symbols and collected in . If not mentioned otherwise we denote by variables, denote defined symbols. Terms are denoted by or , and values by . All denotations are possibly followed by subscripts. We use the notation to abbreviate a finite sequence of terms .
The root symbol of term t is denoted as . The size of t is denoted by and refers to the number of occurrences of symbols t, the depth is given recursively by if , and . Here we employ the convention that the maximum of an empty set is equal to 0. A rewrite rule is a pair of terms, in notation , such that the left-hand side is not a variable, the root f is defined, and all variables appearing in the right-hand r occur also in l. A term rewrite system (TRS for short) is a set of rewrite rules.
We adopt call-by-value semantics and define the rewrite relation as follows.
If we say that s reduces to t in one step. For (i) we make various assumptions on : we suppose that there is exactly one matching rule ; the arguments () contains no defined symbols; and variables occur only once in . That is, throughout this paper we fix to denote a completely defined,2 orthogonal constructor TRS [29]. Furthermore we are only concerned with innermost rewriting. Note that orthogonality enforces that our model of computation is deterministic.3 If a term t has a normal form, then this term is unique and denoted by t↓. For every n-ary defined symbol , defines a partial function where
and is undefined otherwise. Note that when is terminating, i.e. when is well-founded, the function is total.
Following [30] we adopt a unitary cost model. Bounds are of course expressed with respect to the size of terms. Let denote the set of basic (also called constructor based) terms where and . We define the (innermost) runtime complexity function as
Hence maximises over the derivation height of terms s of size up to n, regarding only basic terms. The latter restriction accounts for the fact that computations start only from basic terms. The runtime complexity function is well-defined if is terminating. If is asymptotically bounded from above by a polynomial, we simply say that the runtime of is polynomially bounded. This unitary cost model is reasonable:
Proposition 1 Adequacy theorem —
(See [31–33].) All functions computed by are computable on a conventional models of computation, viz Turing machines, such that the time complexity on the latter is polynomially related to .
In particular, if the runtime of is polynomially bounded then is polytime computable on a Turing machine for all .
We say that a function symbol f is defined based on g, in notation , if there exists a rewrite rule where g occurs in r. We call f recursive if holds, i.e. if f is defined based on itself. Recursive functions symbols are collected in . Noteworthy our notion also captures mutual recursion. We denote by ⩾ the least preorder on containing and where constructors are equivalent, i.e. and for all constructors . The preorder ⩾ is called the precedence of . We denote by > and ∼ the separation of ⩾ into the strict partial order > and the equivalence ∼. Note that for , if then also ; similar implies . The rank of with respect to ⩾ is inductively defined by . The depth of recursion of is defined in correspondence to the rank, but only takes recursive symbols into account: let be the maximal recursion depth of a function symbol g underlying the definition of f; then if f is recursive, otherwise .
Example 1
Consider following TRS , written in predicative notation.
The TRS follows along the line of from Fig. 1. The functions and denote addition and multiplication on natural numbers, in particular where . The precedence is given by where addition (+) and multiplication (×) are recursive, but is not recursive. We have since addition is recursive, as is not recursive but multiplication is recursive we have .
2.2. Register machines
In this paper, we are considering register machine (RM for short) over words as initially proposed by Shepherdson and Sturgis in [34]. We employ following notations and conventions. An RM M consists of a finite set of registers that store words over . Like values, i.e. constructor terms, words are denoted by , and denote sequences of words. No confusion can arise from this. For r a register, we use to refer to the content of register r. The control of M consists of a finite sequences of (labeled) instructions which are executed sequentially by M. Here an instruction can be one of the following:
-
(i)
Append instruction : place on the left-hand end of ;
-
(ii)
Delete instruction : remove the left-most character from , if ;
-
(iii)
Conditional jump instruction : jump to instruction , if the left-most character of is , otherwise proceed with the next instruction;
-
(iv)
Copy instruction : overwrite by .
Our definition departs from [34] in following minor respects. Unlike in [34], we suppose that the set of registers is finite. This simplification does not impose any restrictions. Due to the absence of memory indirection instructions, only a fixed number of registers can be accessed by a machine M anyway. The instructions (i)–(iii) correspond to the minimal instruction set given in [34, Section 6], with the difference that in [34] the instruction (i) appends to the right. The additional copy instruction (iv) added from the extended instruction set of [34, Section 2] ensures that copying words has unitary cost. A configuration of the RM M is a tuple where are the content of the m registers and j ranges over the labels of instructions of M, and the dedicated halting label . We denote by the one-step transition relation obtained in the obvious way from our informal account of the instruction set (i)–(iv). For the halting label we set for all words (). We say that the RM M computes the (partial) function with defined as follows:
We also say that on inputs the computation halts in ℓ steps. Denote by the length, or size, of the word u. Extend this to so that denotes the sum of the sizes of . Let . We denote by the class of functions computed by some RM M in the above way, where M halts on all inputs in no more than steps.
3. The small polynomial path order
We arrive at the formal definition of the small polynomial path order ( for short). Conceptually this order is a tamed recursive path order with product status, embodying predicative analysis of recursion set forth by Bellantoni and Cook [1].
Throughout this section, fix a TRS . For each function symbol f, we assume an a priori separation of argument positions into normal and safe ones. Arguments under normal positions play the role of recursion parameters, whereas safe argument positions allow the substitution of recursive results, compare the definition of drawn in Fig. 1 on page 5. For constructors c we fix that all argument positions are safe. As in Example 1, we indicate this separation directly in terms and write where the arguments to the left of the semicolon are normal, the remaining arguments are safe. This separation and the precedence ⩾ underlying the analysed TRS induces an instance of , which is denoted by below.
In order to define , we introduce some auxiliary relations. First of all, we lift equivalence ∼ underlying the precedence ⩾ of to terms, disregarding the order on arguments: s and t are equivalent, in notation , if , or and where and there exists a permutation π on argument positions such that for all . Safe equivalence takes also the separation of argument positions into account. In the definition of , we additionally require that i is a normal argument position of f if and only if is normal argument position of g. We emphasise that ∼ (and consequently ) preserves values: if and then . We extend the subterm relation to term equivalence. Consider . Define if either or , where holds if for some argument of s (). We denote by the restriction of where only normal arguments are considered: if for some normal argument position .
Definition 1
Let s and t be terms such that . Then if one of the following alternatives holds.
- 1.
for some argument of s ().
- 2.
, where and the following holds:
- –
for all normal arguments ;- –
for all safe arguments ;- –
t contains at most one (recursive) function symbol h with .- 3.
, where and the following holds:
- –
for some permutation π on ;- –
for some permutation τ on .Here denotes that either or holds. In the last clause we use also for the extension of to products: means for all , and indicates that additionally holds for at least one .
Throughout the following, we write if follows from the ith clause in Definition 1. A similar notation is employed for the consecutive introduced orders.
We say that the TRS is compatible with if all rules are oriented from left to right: for all rules . As forms a restriction of the recursive path order, compatibility with implies termination [29].
Definition 2
We call the TRS predicative recursive (of degree d) if is compatible with an instance of and the maximal recursion depth of is d.
Consider the orientation of a rule . The case is intended to capture functions f defined by weak safe composition (WSC), compare Fig. 1. In particular the use of allows only the substitution of normal arguments of f in normal argument positions of g. The last restriction put onto is used to prohibit multiple recursive calls. If one drops this restriction, the TRS consisting of and is compatible with but its runtime complexity can be only exponentially bounded. Finally, accounts for recursive calls, in combination with we capture safe recursion (SRN). The next theorem provides our second main result.
Theorem 1
Suppose is a predicative recursive TRS of degree d. Then the derivation height of any basic term is bounded by a polynomial of degree in the sum of the depths of normal arguments . In particular, the runtime complexity function is bounded by a polynomial of degree d.
As a consequence of Theorem 1 and the adequacy theorem (c.f. Proposition 1), any predicative recursive (and orthogonal) TRS computes a function from . We remark that Theorem 1 remains valid for the standard notion of innermost rewriting [29] on constructor TRSs. Neither orthogonality nor our fixed call-by-value reduction strategy is essential, compare [9].
We continue with an informal account of Definition 1 in our running example, the admittedly technical proof is shortly postponed.
Example 2 Example 1 continued —
We show that the TRS depicted in Example 1 is predicative recursive. Recall that the precedence underlying is given by , and that . The degree of recursion of is thus two.
The case is standard in recursive path orders and allows the treatment of projections as in rules 1 and 2. We have using and likewise using . Observe that the rule
is oriented by only: using and twice , i.e., y is a normal argument of , we have . Using that also and holds, another application of orients rule 5.
Finally, consider the recursive cases of addition (rule 3) and multiplication (rule 4). These can be oriented by a combination of and . We exemplify this on the rule
Employing , case is applicable. Thus orientation of this rule simplifies to and . The former constraint is satisfied by definition. Since × is recursive, using the latter constraint reduces to and the trivial constraint . Clearly holds as and . Hence we are done.
Note that any other partitioning of argument positions of multiplication invalidates the orientation of rule 4. The sub-constraint requires that at least the first argument position of times is normal, the sub-constraint enforces that also the second parameter is normal. The order thus determines that multiplication performs recursion on its first arguments, and that the second parameter should be considered normal since it is used as recursion parameter in addition. Reconsidering the orientation of rule 5, the use of propagates that takes only normal arguments.
By Theorem 1 we obtain that addition admits linear, and multiplication as well as admits quadratic runtime complexity. Overall the runtime complexity of is quadratic.
The following examples clarifies the need for data tiering.
Example 3 Example 2 continued —
Consider the extension of by the two rules
that express exponentiation in an exponential number of steps. The definition of is not predicative recursive, since the recursive result is substituted as recursion parameter to multiplication. For this reason the orientation with fails.
The next example is negative, in the sense that the considered TRSs admits polynomial runtime complexity, but fails to be compatible with .
Example 4 Example 3 continued —
Consider now the TRS where the rule 4 is replaced by the rule
The resulting system admits polynomial runtime complexity. On the other hand, Theorem 1 is inapplicable since the system is not predicative recursive.
We emphasise that the bound provided in Theorem 1 is tight, in the sense that for any d we can define a predicative TRS of degree d admitting runtime complexity .
Example 5
We define a family of TRSs () inductively as follows: and extends by the rules
Let . It is easy to see that is predicative recursive (with underlying precedence ). As only () are recursive, the recursion depth of is d.
But also the runtime complexity of is in : For this is immediate. Otherwise, consider the term () which reduces to in one step. As the latter iterates for n times, the lower bound is established by inductive reasoning.
We now show that is correct, i.e. we prove Theorem 1. Suppose is a predicative recursive TRS of degree d. Our proof makes use of a variety of ingredients. In Definition 3 we define a predicative interpretation that flatten terms to sequences of terms, separating safe from normal arguments. In Definition 4 we introduce a family of orders on sequences of terms. The definition of (for fixed ℓ) does not explicitly mention predicative notions and is conceptually simpler than . In Lemma 4 we show that predicative interpretations embeds rewrite steps into , as pictured in Fig. 2. Consequently the derivation height of s is bounded by the length of descending sequences, which in turn can be bounded sufficiently whenever s is basic (cf. Lemma 7).
Fig. 2.

Predicative embedding of into .
Consider a step . Due to the limitations imposed by , it is not difficult to see that if rσ is not a value itself, then at least all normal arguments are values. We capture this observation in the set , defined as the least set such that (i) , and (ii) if , and then . This set is closed under rewriting.
Lemma 1
Suppose is compatible with . If and then .
Proof
The lemma follows by a straightforward inductive argument on Definition 1. □
Observe that includes all basic terms. For the runtime complexity analysis of , it thus suffices to consider reductions on only.
3.1. Predicative interpretation of terms as sequences
Predicative interpretations separate safe from normal arguments. To this avail, we define the normalised signature to contain all symbols from , with the sole difference that the arity of defined symbols f with k normal arguments is k in . A term t is normalised, if . Below we retain the separation into constructors, recursive and non-recursive symbols. As a consequence, the rank and recursion depth coincide with respect to both signatures, and also . Terms are also called basic, these are obtained from by dropping safe arguments.
To formalise sequences of (normalised) terms, we use an auxiliary variadic function symbol ∘. Here variadic means that the arity of ∘ is finite but arbitrary. We always write for , and if we write then . We use to denote terms or sequences of terms. In contrast, , possibly followed by subscripts, denote terms which are not sequences. Abusing set-notation, we write if for some . We lift terms equivalence to sequences by disregarding the order of elements: if for all and some permutation π on . We denote by the concatenation of sequences. To avoid notational overhead we overload concatenation to both terms and sequences. For sequences a define , and for terms t define . We set where and .
Definition 3
We define the predicative interpretation , mapping terms to sequences of normalised terms as follows:
Note that the predicative interpretation is a sequence of (normalised) basic terms for any term . To get the reader prepared for the definition of the order on sequences as defined below, we exemplify Definition 3 on a predicative recursive TRS.
Example 6
Consider following predicative recursive TRS where
Consider a substitution . The embedding of root steps () results in the following order constraints.
Kindly observe that in the first line we employed because yσ is a value. In the second line we tacitly employed the overloading of concatenation:
Consider now a rewrite step below the root for . As , without loss of generality the rewrite step happens below a safe argument position. Hence
for some values , terms and . To embed such rewrite steps we have to prove
We emphasise that for a root step of a predicative recursive TRS , the length of does not depend on σ, since images of σ are removed by the predicative interpretation. As a consequence, each step in an -derivation on increases the length of predicative interpretations by a constant (depending on ) only. Below, we bind this constant by the maximal size of a right-hand side in .
3.2. Small polynomial path order on sequences
We arrive at the definition of the order on sequences. This order is used to orient images of the predicative interpretation . The parameter in controls the width of terms and sequences, and is crucial for the analysis of the length of -descending sequences carried out below.
Definition 4
Let ⩾ denote a precedence. For all we define on terms and sequences of terms inductively such that:
- 1.
if , and the following conditions hold:
- –
for all ;- –
.- 2.
if , and for some permutation π on :
- –
.- 3.
if the following conditions hold:
- –
for all ;- –
at most one element () contains a symbols g with ;- –
.- 4.
if there exists terms or sequences () such that:
- –
;- –
.We denote by
that either or holds. We use and also for their extension to products: if for all , and for at least one ; likewise if
for all , and for at least one .
We point out that misses the case: if
for some argument . Since predicative interpretations remove values, the clause is not needed, compare the embedding of rule 1 given in Example 6. This case would invalidate the central Lemma 7 given below, which estimates the length of descending sequences. Observe that on constructor based left-hand sides, the order constraints imposed by and translate to the order constraints imposed by and on normal arguments. The clauses and extend the order from terms to sequences. Noteworthy the second clause in reflects that we do not allow multiple recursive calls, compare and the definition of the predicative interpretation. We exercise Definition 4 on the constraints obtained in Example 6.
Example 7 Example 6 continued —
We show that the order constraints drawn in Example 6 can be resolved for . Let be a substitution. Consider first the root step due to rule 1. Exploiting the shape of σ, we have . For the root step caused by rule 2 we have
Note that and thus is needed in the proof step 5.
The next lemma collects frequently used properties of .
Lemma 2
For all we have:
- –
,
- –
, and
- –
implies .
Proof
All but the third property follow directly from definition. Suppose holds, and let . We show . First suppose . Then we conclude
employing the assumption and for all . Otherwise , hence by assumption. Then with
for all , where at least one orientation is strict. From this and again using () we conclude
□
We emphasise that as a consequence of Lemma 2 we have that holds whenever holds. The order constraints on sequences are defined so that sequences purely act as containers. More precise, every -descending sequence starting from can be seen as a combination of possibly interleaved, but otherwise independent -descending sequences starting from the elements .
3.3. Predicative embedding
We now close the diagram outlined in Fig. 2 on page 9, that is we prove the predicative embedding exemplified in Example 7 on the TRS . As a preparatory step, we consider root steps first. The complete embedding is then established in Lemma 4.
Lemma 3
Consider a rewrite rule . Let be a substitution. If holds then .
Proof
Let . We first show
(⁎) by induction on . The non-trivial case is when rσ is not a value, otherwise . Suppose thus where r is not a value. By definition
First consider the element . We either have or by the assumption that r is not a value. In the case , we have and for all normal arguments . The latter reveals that the instances are equivalent to proper subterms of the left-hand side . Using this and that trivially holds we conclude . In the remaining case , we have , where and moreover for some permutation π. By reasoning as above we see and conclude . Hence overall we obtain .
Now consider the remaining elements , where . Then each t occurs in the interpretation of a safe argument of rσ, say for some . One verifies that, holds: if then by definition, otherwise holds and we obtain . By induction hypothesis we have . As we hence obtain for all and safe positions of g. This concludes (⁎).
We return to the proof of the lemma. A standard induction gives that the length of is bounded by , compare the remark after Example 6. Using that σ maps to values, a second induction on gives that contains at most one (defined) function symbol g equivalent to f. Summing up, using (⁎) we conclude . Observe that by assumption the direct subterms of lσ are values, and thus by definition. The lemma thus follows by one application of . □
Lemma 4
Let denote a predicative recursive TRS and let . If and then .
Proof
Let and consider a rewrite step . We prove the lemma by induction on the rewrite position. In the base case we consider a root step for some rule . Since is predicative recursive, holds. By Lemma 3 we have . Since the result follows.
For the inductive step, consider a rewrite step below the root. Since this step is of the form
where for some . Wlog. we assume t is not a value. Using the induction hypothesis and Lemma 2 we conclude
□
3.4. Binding the length of -descending sequences
The following function relates a term, or sequence of terms, to the length of its longest -descending sequence.
Definition 5
For all , we define .
This function is well-defined, as is well-founded. The latter can be seen as forms a restriction of the multiset path order [35]. We remark that due to Lemma 2, whenever . The following lemma confirms that sequences act as containers only.
Lemma 5
For all sequences , .
Proof
Let be a sequence and observe . This is a consequence of Lemma 2. Hence, in particular we obtain: .
To complete the proof, we proceed by induction on . The base case follows trivially. For the induction step, we show that implies . From this, we obtain , which together with the above observation yields . Suppose . Then this is only possible due to . Hence b is equivalent to , where
for all and for at least one . In particular, and . As we have for all , induction hypothesis is applicable to b and all (). It follows that
□
We now approach Lemma 7, where we show that for some constant and . The proof of Lemma 7 is slightly involved, and requires induction on the rank r of f and side induction on m. The constant c is defined in terms of for natural numbers :
Below the argument r will be instantiated by the rank, and d by the depth of recursion of a function symbol f. The next lemma is a technical lemma to ease the presentation of the proof of Lemma 7. The assumptions correspond exactly to the main induction hypothesis (IH) and side induction hypothesis (SIH) of Lemma 7.
Lemma 6
Consider and suppose that
(IH)
(SIH) Then
(†)
(‡)
Proof
First consider the case . Then and so and hold. From the order constraints on arguments we can derive . Observe that the assumption gives also . Summing up, simple arithmetical reasoning gives the implication (†) from (IH). Similar, when holds we have and . The order constraints on arguments give . From this, the implication (‡) follows directly from (SIH). □
Lemma 7
For all , .
Proof
Let ℓ be fixed. To show the theorem, we show
In proof we employ induction on and side induction on . Abbreviate and . Assume that holds. We prove , where we show only the more involved inductive case . The base case follows by similar reasoning. We analyse two cases.
If is a sequence, then by assumption . Thus and , i.e. either or holds for all . Due to the second condition imposed on , we even have for all but one . Suppose first that f is recursive. Then implies . Using induction and side induction hypothesis to satisfy the assumptions of Lemma 6, we obtain
Here the second inequality is obtained by combining the conclusions of the two implications provided by Lemma 6. We conclude the case as follows.
Suppose now that f is not recursive. Then also . Employing that implies , using Lemma 5 and Lemma 6 we see
This finishes the cases when b is a sequence.
Finally, when is a term we conclude directly by Lemma 6, using similar to above. □
Putting things together, we arrive at the proof of our first theorem.
Proof of Theorem 1
Let denote a predicative recursive TRS. We prove the existence of a constant such that for all values the derivation height of is bounded by , where n is the sum of the depths of normal arguments .
Consider a derivation . Let . By Lemma 1 it follows that , and consequently due to Lemma 4. So in particular the length n is bounded by the length of descending sequences starting from . By Lemma 5, . Thus Lemma 7 gives the constant as desired. □
4. Parameter substitution
Bellantoni already observed that his definition of is closed under safe recursion on notation with parameter substitution. Here a function f is defined from functions and by
| () |
We introduce the small polynomial path order with parameter substitution ( for short), where clause is extended to account for the schema . Theorem 1 remains valid under this extension.
Definition 6
Let s and t be terms such that . Then if one of the following alternatives holds.
- 1.
for some argument of s ().
- 2.
, where and the following holds:
- –
for all normal arguments ;- –
for all safe arguments ;- –
t contains at most one (recursive) function symbols g with .- 3.
, where and the following holds:
- –
for some permutation π on ;- –
for all safe arguments ;- –
arguments contain no (recursive) symbols g with .Here denotes that either or . In the last clause, we use also for the product extension of (modulo permutation).
We adapt the notion of predicative recursive TRS of degree d to in the obvious way. Note that does not hold in general, due to the third constraint put onto . Still, the above order extends the analytic strength of small polynomial path orders.
Lemma 8
If a TRS is compatible with then is also compatible with using the same precedence and separation of argument positions.
Proof
Consider the orientation of a rule . To prove the lemma, we show that holds by replacing every application of by . We prove this claim by induction on . We consider the only non-trivial case where appears in the proof of . Compare the case with the new case . Using the induction hypothesis, the order constraints on normal arguments are immediately satisfied. Now fix a safe argument of t. From we obtain a safe argument of s with . Hence holds by induction hypothesis. Thus holds as desired. Observe that the safe arguments of s are proper subterms of the left-hand side l, hence the terms contain no defined symbols. Since collapses to the subterm relation on constructor terms, it follows that the safe argument of t are constructor terms too. From this we see that the final constraint of is satisfied. □
Parameter substitution extends the analytic power of significantly. Noteworthy, can deal with tail-recursive rewrite systems.
Example 8
The TRS consisting of the three rules
which reverses lists formed from the constructors and . Define the separation of argument positions as indicated in the rules. The underlying precedence is given as . Since is the only recursive symbol, the degree of recursion of is one.
Notice that orientation of the final rule with the induced reduces to the unsatisfiable constraint . In contrast, orientation with the induced reduces to the constraint , which can be resolved by one application of followed by three applications of .
As a consequence of the next theorem, the runtime of is inferred to be linear.
Theorem 2
Let be a predicative recursive TRS of degree d (with respect to Definition 6). Then the derivation height of any basic term is bounded by a polynomial of degree in the sum of the depths of normal arguments . In particular, the runtime complexity function is bounded by a polynomial of degree d.
Proof
We observe that under the new definition all proofs, in particular the predicative embedding shown in Section 3.3, go through unchanged. □
5. Predicative recursive rewrite systems compute all polytime functions
In this section we show that is complete for . Indeed, we can even show a stronger result. Let f be a function from that makes only use of d nestings of safe recursion on notation, then there exists a predicative recursive TRS of degree d that computes the function f.
By definition for Bellantoni and Cooks predicative recursive characterisation of given in [1]. Concerning the converse inclusion, the following theorem states that the class is large enough to capture all the polytime computable functions.
Theorem 3
Every polynomial time computable function belongs to .
One can show this fact by following the proof of Theorem 3.7 in [28], where the unary variant of is defined and the inclusion corresponding to Theorem 3 is shown. The completeness of for the polytime computable functions is an immediate consequence of Theorem 3 and the following result.
Theorem 4
For any -function f there exists a predicative recursive TRS computing f and of degree d, where d equals the maximal number of nested application of (SSRN) in the definition of f.
Proof
Let f be a function coming from . A witnessing TRS is obtained via a term rewriting characterisation of the class depicted in Fig. 1 on page 5. The term rewriting characterisation expresses the definition of as an infinite TRS . We define a one-to-one correspondence between functions from and the set of function symbols for as follows. Constructor symbols ϵ, and are used to denote binary words. The function symbols , , , and correspond respectively to the initial functions , P, , C and of . The symbol is used to denote the function obtained by composing functions h and according to the schema of (WSC). Finally, the function symbol corresponds to the function defined by safe recursion on notation from g, and in accordance to the schema (SRN). With this correspondence, is obtained by orienting the equations in Fig. 1 from left to right.
By induction according to the definition of f in we show the existence of a TRS and a precedence such that:
- 1.
is a finite restriction of ,
- 2.
contains the rule(s) defining the function symbol corresponding to f,
- 3.
is compatible with induced by ,
- 4.
is maximal in the precedence underlying , and
- 5.
the depth of recursion equals the maximal number of nested application of (SRN) in the definition of f in .
It can be seen from conditions (1), (3) and (5) that the theorem is witnessed by . To exemplify the construction we consider the step case that f is defined from some functions by the schema (SRN). By induction hypothesis we can find witnessing TRSs with underlying precedences respectively for . Extend the set of function symbols by a new recursive symbol . Let be the TRS consisting of , , and the following three rules:
It is not difficult to see that the precedence of extends the precedences , and by and for .
Let be the induced by . Then it is easy to check that enjoys conditions (1) and (2). In order to show condition (3), it suffices to orient the three new rules by . For the first rule, holds by the definition of . For the remaining two rules we only orient the case . Since is a recursive symbol and holds, holds. This together with the definition of the precedence allows us to conclude .
Consider condition (4). For each function from , the corresponding function symbol is maximal in the precedence by induction hypothesis for . Hence by the definition of , is maximal in .
It remains to show condition (5). Notice that , since is a recursive symbol. Without loss of generality let us suppose . Then by induction hypothesis for g, equals the maximal number of nested application of (SRN) in the definition of g in . Hence equals the one in the definition of f in . □
We obtain that predicative recursive TRSs give a sound and complete characterisation of the polytime computable functions.
Theorem 5
The following classes of functions are equivalent:
- 1.
The class of functions computed by predicative recursive TRSs.
- 2.
The class of functions computed by predicative recursive TRSs allowing parameter substitution.
- 3.
The class of functions computable in polynomial time.
Proof
Let and refer to the classes defined in clauses (1) and (2) respectively. We have
For the second inclusion we tacitly employed the adequacy theorem. □
We remark that from our standing restriction on TRSs, orthogonality is essentially used to ensure that semantics of TRSs are well-defined. Orthogonality could be replaced by the less restrictive, although undecidable, notion of confluence.
As a corollary to Theorem 5 we obtain that the class , viz , is closed under parameter substitution.
Corollary 1
For any functions , there exists a unique polytime computable function f such that and for each .
6. Predicative recursion precisely captures register machine computations
Exploiting the fine-grained control given by the degree of recursion, we now provide an order-theoretic characterisation of via predicative tail-recursive TRSs.
Definition 7
A TRS is tail-recursive if for every rule , if g with occurs in r then it occurs at the root position in r. The TRS is predicative tail-recursive (of degree d), if it is tail-recursive and predicative recursive (of degree d), with respect to Definition 6.
For instance, the TRS from Example 8 is a predicative tail-recursive TRS. The restriction to tail-recursion is unarguably severe. Still, predicative tail-recursive TRSs of degree d can compute polynomials (in unary notation) for all .
Example 9
Let denote a polynomial with constants . The TRS is given by the following rules.
This TRS is tail-recursive, moreover it is predicative recursive with recursive symbols and precedence . In total, is thus predicative tail-recursive, of degree d.
Let denote the denotation of as value with constructors and 0. One verifies that for , reduces to the value , for . Thus for all .
6.1. Predicative tail-recursive TRSs of degree d are complete for
Fix a register machine M that computes a function in time . We show that this function is computable by a predicative tail-recursive TRS of degree d. Let denote the set of constructors that contains a symbol ϵ, and for each a unary symbol . Then the word can be represented as value over . Having this correspondence in mind, we confuse words with such values below. Furthermore, we suppose for each instruction label of M a designated constant used to denote this label. The following lemma shows that the one-step transition relation of M is expressible by a predicative TRS of degree 0.
Lemma 9
Let M be a RM with m registers. There exists a predicative tail-recursive TRS of degree 0 defining the symbols , such that
iff .
Proof
Suppose . For the definition of , note that only if the jth instruction in the control of M is a jump instruction. In this case, can be determined by the left-most character of one of the values (). And so can be computed in one step using pattern-matching on the inputs only. Similarly, for the definition of , the word is either , ϵ, one of or the direct subterm of . Again the precise shape can be determined purely by pattern matching on the inputs . □
Lemma 10
Let . Then f is computed by a predicative tail-recursive TRS of degree d.
Proof
Suppose the function is computed by an RM M in time . Let denote constants such that for all . The construction of is an adaption of the TRS given in Example 9, using the TRS provided in Lemma 9 to simulate one step of the RM M. Let be the numbers of registers of M. For function symbols as provided in Lemma 9, let be the ℓ-fold parallel composition of on terms , given by and
Observe that iterated application of Lemma 9 yields:
(1) For each and , let be fresh a function symbol with normal and m safe argument positions. Let , and denote pairwise distinct variables. The TRS extends by the following rules.
Here the index r ranges over , the index i ranges over and . Let and be vectors of words of length k. Observe that
This derivation can be shown by induction on r and , in correspondence to Example 9. For words , this thus yields
(2) Putting the derivations (1) and (2) together, and using that RM M runs in time on input , we conclude that holds.
Observe that the precedence ⩾ of on defined symbols is given by
where only the symbols for are recursive in . In particular, the recursion depth of is thus d. It is also not difficult to see that is predicative recursive. As is tail-recursive, the lemma follows. □
6.2. Predicative tail-recursive TRSs of degree d are sound for
We now show the converse of Lemma 10. Fix a predicative tail-recursive TRS of degree d. Call a function symbol monadic if its arity is at most one. Suppose all constructors of are monadic and consider a defined symbol f in . We show that the function computed by can be implemented on an RM , operating in time . The restriction to monadic constructors allows us to identify values of with words over the alphabet , which contains for every constructor a distinct letter . We use the word to denote the value . Having this correspondence in mind, we again confuse words with values.
To ease presentation, we first consider the sub-case where is simple. Here a rule is called simple if r is a constructor term or where g is either a defined or a constructor symbol and . Furthermore is called simple if all its rules are simple.
Lemma 11
If is simple, then for every defined symbol f from .
Proof
For each defined symbol f in with k normal and l safe arguments, we define a corresponding RM with input registers and output variable . On input and the RMs run in time . To simplify the presentation, we first suppose that the precedence of is strict on defined symbols, i.e. for implies . The construction is by induction on the rank p of f, the bound is proven by induction on p and side induction on . Suppose the input registers hold the values .
First observe that is able to determine in constant time (depending only on ) the (unique) rewrite rule applicable to . Since there are only a constant number of rules in , it suffice to realise that the time required for pattern matching depends only on . To this end, suppose we want to match against the left hand-side . Due to linearity, can match the arguments against individually. For this, the RM just has to copy sequentially each argument to a temporary register, can then be matched against the corresponding argument using a constant number of jump and delete instructions.
Once the applicable rewrite rule has been identified, the RM can proceed according to its right-hand side as follows. If rewrites in one step to a value, say w, then for some constructor context C and substitution . Then some input register holds the word . Notice that the contexts C and depend only on the applied rewrite rule. Hence can provide the result w in register in constant time. Thus suppose does not rewrite to a value in one step. Since is simple
As is predicative recursive, holds for all . Furthermore, either or holds by our assumption that ⩾ is strict on defined symbols. In both cases, order constraints on normal arguments give (), i.e. some input register holds a superterm of . The RM can prepare the arguments in dedicated registers for all in constant time. By induction hypothesis, there exist RMs () that on input registers initialised by , compute the value in time . The RM can use these machines as sub-procedures (cf. [34]) in order to compute (). Overall this requires at most steps, where is the maximal recursion depth of the defined symbols . The interesting case is now when . We analyse the cases and independently.
If then as before we can use a machine given by induction hypothesis that computes where in time , from the already initialised input registers . As a consequence of the order constraints on we see for all . Thus , and hence overall the procedure takes time . For the inclusion we employ and as given by the assumptions.
Otherwise , hence f is recursive. Recall that collapses to the subterm relation (modulo equivalence) on values. From the order constraint on normal arguments it is thus not difficult to derive . Recall since f is recursive. Thus it follows that . Using the side induction hypothesis we conclude that operates in time overall. We conclude this final case.
To lift the assumption on the precedence, suppose is the set of all function symbols equivalent to , i.e., are defined by mutual recursion. Since this class is finite, one can store i (for ) in a dedicated register of , say r. Although more tedious, it is not difficult to see that the above construction can then be altered, so that computes on input . □
We now remove the restriction that is simple. For that we define the relation ⇝ on TRSs as follows. Let be fresh symbols not appearing in . Then
provided the transformed rule is not already simple. The relation ⇝ enjoys following properties.
Lemma 12
- 1.
The relation ⇝ is well-founded.
- 2.
If then .
- 3.
Let be a predicative tail-recursive TRS of degree d that uses only monadic constructors. If then enjoys the same properties.
Proof
Let , where . Then an infinite chain translates into an infinite descend . Hence property 1 follows.
Suppose now . For property 2, consider a rewrite step using a transformed rule . Then
simulates the considered step. So clearly follows.
Finally consider property 3, and consider a TRS such that . Let , denote the rule which is replaced by
Let ⩾ denote the precedence underlying , and ⊒ the precedence underlying the simplified TRS . Notice that ⊒ is an extension of ⩾, which collapses to ⩾ on the signature of . As the freshly introduced symbols are not recursive, the recursion depth of every symbol is preserved by the transformation.
It is obvious that when is tail-recursive, so is . It thus remains to verify that is oriented by the order . Since , and as a consequence , it suffices to show that the orientation of the replaced rule implies
(3)
(4) We perform case analysis on the assumption.
Suppose first holds. Note that by the shape of left-hand sides in and definition of the precedence, g is a constructor in the considered case. In particular g admits only safe argument positions. Thus holds using (). This concludes (3). The assumption give also for all , thus holds and we conclude (4).
Finally suppose that follows by either or . Using the order constraint for all , we see that (3) follows by or respectively. For Eq. (4), observe that since is tail-recursive, the assumption gives () using only applications of and . Repeating these proofs, but employing instead of yields a proof of (4). □
Lemma 13
Let be a predicative tail-recursive TRS of degree d, and suppose all constructors are monadic. Then for every defined symbol f from .
Proof
Let be a ⇝-normal form of our analysed TRS . Then is simple as otherwise ⇝-reducible. Using the assumptions on , Lemma 12 yields that satisfies the preconditions of Lemma 11. Moreover, it shows that computes all functions computed by . We conclude by Lemma 11. □
6.3. Predicative tail-recursive TRSs of degree d characterise
By Lemma 10 and Lemma 13, we obtain following correspondence.
Theorem 6
For each , the following classes of functions are equivalent:
- 1.
The class of functions computed by predicative tail-recursive TRSs of degree d, using only monadic constructors.
- 2.
The class of functions computed by register machines operating in time .
This theorem is closely connected to the recursion-theoretic characterisation of the polytime computable functions provided by Leivant [12], and the one of Marion [13]. Leivant uses ramified recurrence schemes to impose data tiering on functions defined by recursive means. Restricted to word algebras and two tiers, a function f in Leivant's class belongs to , where d corresponds to the number of nested recursive definitions in f. Vice verse, any function in is expressible in Leivant's class using two tiers, and maximal d nested recursive definitions. Hence there is a precise correspondence between the functions f defined in Leivant's class based on d nested recursive definitions, and the functions definable by predicative recursive TRS of degree d. Syntactically, the restriction to two tiers in Leivant's class results in a composition scheme conceptually similar to weak safe composition. Substitution is only allowed on arguments not used for recursion.
Our result as well as Leivant's characterisation, relies on recursion schemes that go beyond primitive recursion with data tiering. Leivant allows recursive definitions by simultaneous recursion. We note that in our context, simultaneous recursion cannot be permitted. In general, such an extension would invalidate Theorem 1 and Theorem 2 respectively. Instead, we resort to parameter substitution, which is essential for our completeness result. Still simultaneous recursion can be reduced to primitive recursion, preserving the data tiering principle underlying [12]. However, this program transformation relies on a form of tupling, and does not preserve the number of nestings of recursive definitions. In our context, parameter substitution can be eliminated in recursive definitions in a similar spirit, at the expense of the depth of recursion.
Restoring to strict ramified recurrence schemes, Marion [13] provides a fine-grained characterisation of in the spirit of Leivant's characterisation and our result above. The underlying strict ramification principle requires that each recursive definition increases the tier of an input. As a consequence, the exponent d is reflected in the maximal level of an input tier. Crucial here again is the restriction to a composition scheme akin to our weak form of composition.
In Marion's characterisation, functions can return multiple values. As a consequence, the simulation of register machine computations requires neither simultaneous recursion nor similar concepts. It is not difficult to show that a modification of our computational model, which accounts for multi-valued functions, allows the completeness result given in Lemma 10 even if we disallow parameter substitution. We feel however that such a modification, tailored specifically to register machines, introduces a rather ad-hoc flavor to our formulation of computation by TRSs.
7. Examples and experimental evaluation
We briefly contrast the orders and to its predecessor [9], Marion's LMPO [6], as well as interpretation methods found in state-of-the-art complexity provers. Furthermore, we present experimental results.
Lightweight multiset path order and polynomial path orders
The order forms a restriction of and LMPO, whereas the latter two orders are incomparable in general. In contrast to the family of polynomial path orders, LMPO allows multiple recursive calls in right-hand sides. As clarified in the next example, extending our methods would invalidate the corresponding main results (Theorem 1 and Theorem 2 respectively).
Example 10
The TRS is given by the following rules:
For a precedence ⩾ that fulfills and we obtain that is compatible with LMPO. This TRS can however neither be handled by nor . It is straightforward to verify that the family of terms admits derivations whose length grows exponentially in n. Still the underlying function can be proven polynomial, essentially relying on memoisation techniques [6].
On the other hand, integrates a multiset status. In contrast, both LMPO and are restricted to product status.
Example 11
Consider the following one-ruled TRS originally stemming from Jean-Jaques Lévy4:
Polynomial runtime complexity of this system can be shown by . The system is neither compatible with an instance of LMPO nor , because the product of arguments to cannot be ordered.
However, the system becomes orientable with an instance of , if we make also the second argument of safe. Observe that holds, using , as well as . From this, one application of orients the rule. Since is the only recursive symbol, Theorem 2 shows that the runtime complexity of is at most linear.
Even though forms a restriction of and LMPO, its extension by parameter substitution is incomparable to LMPO and . Consider the following TRS.
Example 12
The TRS consists of the following rules.5
Due to the last rule, the TRS is neither compatible with , nor LMPO. The system is however compatible with the instance of as induced by the precedence underlying and separation of argument positions indicated in the rules. The degree of recursion of is one. The runtime complexity of is inferred to be linear by Theorem 2.
We remark that can be extended by parameter substitution [9]. Unless , this extension does however not carry over to LMPO, without sacrificing polytime computability. For instance, the natural extension of LMPO by parameter substitution can handle Example 36 from [11]. This example encodes the complete problem of quantifier elimination on quantified Boolean formulas.
Polynomial and matrix interpretations
Small polynomial path orders are in general incomparable to interpretation methods, notably matrix [37] and polynomial interpretations [38]. These are the most frequently used base techniques in complexity tools nowadays. A polynomial interpretation is an -algebra [29] with carrier , where interpretations (for every k-ary function symbol f) are monotone polynomials. A TRS is compatible with a polynomial interpretation, aka polynomially terminating, if for every rule , under any assignment the left-hand side l is interpreted in larger than the interpretation of the right-hand side r. We say that a polynomial interpretation induces polynomial runtime complexity if the interpretation of every basic term is bounded by a polynomial in the size of s. For such an interpretation compatible with , the runtime complexity of is bounded by a polynomial. Additive polynomial interpretations [10], where all constructors c are interpreted by additive polynomials () induce polynomial runtime complexity.
Not every polynomially terminating TRS is predicative recursive, even if only additive interpretations are employed. Vice verse, not every predicative recursive TRS is polynomially terminating so that the underlying interpretation induces polynomial runtime complexity. This is clarified in the next two examples.
Example 13
The one-ruled TRS is polynomially terminating, using interpretations and , but it is not compatible with any of the above mentioned restrictions of recursive path orders.
Example 14
Consider the predicative tail-recursive TRS , which consists of the following two rewrite rules:
Suppose this rewrite system is compatible with a polynomial interpretation . Consider the reduction of a basic term for . This yields a binary tree of height n, with leafs . Observe that by monotonicity, holds. Note that orientation requires that . As a consequence, the interpretation of terms grows exponentially in n. As by compatibility the interpretations of terms necessarily decrease during reduction, it follows that does not induce polynomial runtime complexity.
A matrix interpretation is similar to a polynomial interpretation, but the underlying carrier of the -algebra is (), and interpretation functions are of shape . Here () denote matrices of size , and f is vector over . The notions of compatibility and induced polynomial complexity carry over naturally from polynomial interpretations. As for (additive) polynomial interpretations it can be shown that matrix interpretations are incompatible to small path orders. This is clarified in the next example.
Example 15 Continued from Examples 2 and 13 —
Reconsider the predicative recursive TRS from Example 1. This system cannot be shown compatible with matrix interpretations. Intuitively this holds due to the linear form of matrix interpretations. The interpretation of a basic term has to be a non-linear expression in both x and y.
Vice verse, the (additive) polynomial interpretation given in Example 13 turns naturally into a matrix interpretation compatible with the one-ruled TRS depicted in Example 13. On the other hand, this TRS is not predicative recursive.
Our final example shows that even in cases where semantic methods apply, order-based techniques might deduce a tighter bound.
Example 16 Continued from Example 11 —
While the TRS given in Example 11 can be handled with semantic methods, the polynomial interpretations can only verify a quadratic upper bound. To the contrary, can verify the (non-optimal) linear bound.
Experimental assessment
The small polynomial path order gives rise to a new, fully automatic, syntactic method for polynomial runtime complexity analysis. We have implemented this technique in our complexity tool
[2]. In particular the complexity proofs above have been obtained automatically with
.
In order to further test the viability of small polynomial path orders, we performed experiments on the relative power of (respectively ) with respect to LMPO [6],
[8] and interpretations [10,37] suited to polynomial complexity analysis. Experiments were conducted with
version 2.0,6 on a machine with 8 Dual-Core Opteron™ 885 processors (2.6 GHz). We abort
if a complexity certificate could not be found within 10 seconds. We selected two data-sets: data-set TC constitutes of 597 terminating constructor TRSs and data-set TCO, containing 290 examples, resulting from restricting test-suite TC to orthogonal systems.7
Table 1 summarises the results obtained on data-sets TC and TCO.8 On the larger benchmark TC, the total of 39 examples drawn in column are necessarily a subset of the 54 examples compatible with LMPO, and also the 43 examples compatible with . Note that LMPO induces only exponential bounded runtime complexity. On three examples, including the TRS depicted in Example 10, this bound is indeed tight. Whereas can only give an unspecified polynomial bound, assesses the complexity of compatible systems between constant and cubic. Thus brings about a significant increase in precision, accompanied with only minor decrease in power. This assessment remains true, if we consider the smaller benchmark set TCO. Parameter substitution increases the analytic power of on test-suite TC from 39 to 54 examples. From the 15 new examples, 13 examples are neither compatible with LMPO nor .
Table 1.
Number of oriented problems and average execution times (seconds) on data-sets TC and TCO.
| LMPO | SEM | SEM+ | |||||
|---|---|---|---|---|---|---|---|
| TC | — | — | 9/0.13 | 9/0.13 | — | 3/0.12 | |
| — | — | 23/0.16 | 37/0.21 | 83/0.73 | 89/0.70 | ||
| — | — | 6/0.22 | 7/0.23 | 20/2.17 | 17/1.84 | ||
| — | — | 1/0.58 | 1/0.62 | — | 1/6.66 | ||
| — | 43/0.12 | — | — | — | — | ||
| Compatible | 54/0.14 | 43/0.12 | 39/0.17 | 54/0.21 | 103/1.01 | 110/0.91 | |
| Incompatible | 543/0.25 | 554/0.25 | 558/0.24 | 543/0.25 | 25/4.48 | 25/4.54 | |
| Timeout | — | — | — | — | 469/10.0 | 462/10.0 | |
| TCO | — | — | 5/0.12 | 5/0.12 | — | 3/0.12 | |
| — | — | 14/0.15 | 19/0.18 | 44/0.84 | 45/0.78 | ||
| — | — | 4/0.20 | 4/0.21 | 13/2.04 | 11/1.94 | ||
| — | 24/0.11 | — | — | — | — | ||
| Compatible | 29/0.13 | 24/0.11 | 23/0.15 | 54/0.17 | 57/1.11 | 59/0.96 | |
| Incompatible | 261/0.13 | 266/0.17 | 267/0.17 | 702/0.17 | 8/4.36 | 8/4.29 | |
| Timeout | — | — | — | — | 225/10.0 | 223/10.0 | |
The last two columns in Table 1 indicate the strength of semantic techniques and their combination with (column SEM+). In column SEM we employed matrix interpretations [37] (dimension 1 to 3) as well as additive polynomial interpretations [10] (degrees 2 and 3). Here we make use of the modular combination technique proposed by Zankl and Korp [39] to combine the interpretation techniques. Coefficients, respectively entries in coefficients, range up to 7. To ensure that matrix interpretations induce polynomial runtime complexity, we resort to the non-trivial criteria found in [17]. Column SEM+ corresponds to column SEM, where is additionally integrated.
It is immediate that syntactic techniques alone cannot compete with the expressive power of interpretations. If we consider the total number of compatible systems only, semantic techniques are roughly twice as powerful as the strongest syntactic technique (). Still, the syntactic techniques proposed in this work provide a fruitful addition to the interpretation method. Contrasting columns SEM and SEM+, not only the total number of certified systems, but also the precision of the obtained certificates, is increased by the addition of . Note also the slight decrease in execution time.
8. Conclusion
We propose a new order, the small polynomial path order , together with its extension to parameter substitution. Based on , we delineate a class of rewrite systems, dubbed systems of predicative recursion of degree d, such that for rewrite systems in this class we obtain that the runtime complexity lies in . Exploiting the control given by the degree of recursion, we establish a novel characterisation of the functions computable in time , on register machines via the small polynomial path order .
Thus small polynomial path orders induce a new order-theoretic characterisation of the class of polytime computable functions. This order-theoretic characterisation enables a fine-grained control of the complexity of functions in relation to the number of nested applications of recursion. One the other hand, small polynomial path orders provide a novel syntactic, and very fast, criteria to automatically establish polynomial runtime complexity of a given TRS. The latter criteria extend the state of the art in runtime complexity analysis as it can be more precise or more efficient than previously known techniques.
Acknowledgements
We would like to thank the anonymous reviewers for their valuable comments that greatly helped in improving the presentation.
Footnotes
This work has been partially supported by the Austrian Science Fund, project number I-603-N18, by the John Templeton Foundation, grant number 20442, and the Japan Society for the Promotion of Science, project number 25⋅726.
The restriction is not necessary, but simplifies our presentation, compare [9].
As in [9] it is possible to adopt nondeterministic semantics, dropping orthogonality.
This is Example 2.59 in Steinbach and Kühler's collection of TRSs [36].
This is Example 2.09 in Steinbach and Kühler's collection of TRSs [36].
Available from http://cl-informatik.uibk.ac.at/software/tct/.
The test-suites are taken from the Termination Problem Database (TPDB), version 8.0; http://termcomp.uibk.ac.at.
Full experimental evidence is provided under http://cl-informatik.uibk.ac.at/software/tct/experiments/spopstar-ICC.
Contributor Information
Martin Avanzini, Email: martin.avanzini@uibk.ac.at.
Naohi Eguchi, Email: naohi.eguchi@uibk.ac.at.
Georg Moser, Email: georg.moser@uibk.ac.at.
References
- 1.Bellantoni S., Cook S. A new recursion-theoretic characterization of the polytime functions. Comput. Complexity. 1992;2(2):97–110. [Google Scholar]
- 2.Avanzini M., Moser G. Proc. of 24th RTA. vol. 21. 2013. Tyrolean complexity tool: features and usage; pp. 71–80. (Leibniz International Proceedings in Informatics). [Google Scholar]
- 3.Baillot P., Marion J.-Y., Rocca S.R.D. Guest editorial: special issue on implicit computational complexity. ACM Trans. Comput. Log. 2009;10(4) [Google Scholar]
- 4.Arai T., Eguchi N. A new function algebra of EXPTIME functions by safe nested recursion. ACM Trans. Comput. Log. 2009;10(4):24:1–24:19. [Google Scholar]
- 5.Avanzini M., Eguchi N., Moser G. Proc. of 22nd RTA. vol. 10. 2011. A path order for rewrite systems that compute exponential time functions; pp. 123–138. (Leibniz International Proceedings in Informatics). [Google Scholar]
- 6.Marion J.-Y. Analysing the implicit complexity of programs. Inform. and Comput. 2003;183:2–18. [Google Scholar]
- 7.Arai T., Moser G. Proc. of 15th FSTTCS. vol. 3821. 2005. Proofs of termination of rewrite systems for polytime functions; pp. 529–540. (Lecture Notes in Computer Science). [Google Scholar]
- 8.Avanzini M., Moser G. Proc. of 9th FLOPS. vol. 4989. 2008. Complexity analysis by rewriting; pp. 130–146. (Lecture Notes in Computer Science). [Google Scholar]
- 9.Avanzini M., Moser G. Polynomial path orders. Log. Methods Comput. Sci. 2013;9(4) [Google Scholar]
- 10.Bonfante G., Cichon A., Marion J.-Y., Touzet H. Algorithms with polynomial interpretation termination proof. J. Funct. Programming. 2001;11(1):33–53. [Google Scholar]
- 11.Bonfante G., Marion J.-Y., Moyen J.-Y. Quasi-interpretations: a way to control resources. Theoret. Comput. Sci. 2011;412(25):2776–2796. [Google Scholar]
- 12.Leivant D. Feasible Mathematics II. vol. 13. Birkhäuser; Boston: 1995. Ramified recurrence and computational complexity I: word recurrence and poly-time; pp. 320–343. (Progress in Computer Science and Applied Logic). [Google Scholar]
- 13.Marion J.-Y. On tiered small jump operators. Log. Methods Comput. Sci. 2009;5(1):1–19. [Google Scholar]
- 14.Moser G., Schnabl A. Proc. of 19th RTA. vol. 5117. 2008. Proving quadratic derivational complexities using context dependent interpretations; pp. 276–290. (Lecture Notes in Computer Science). [Google Scholar]
- 15.Hofmann M., Moser G. Proc. RTA–TLCA 2014. vol. 8560. 2014. Amortised resource analysis and typed polynomial interpretations; pp. 272–286. (Lecture Notes of Computer Science). [Google Scholar]
- 16.Hirokawa N., Moser G. Proc. RTA–TLCA 2014. vol. 8560. 2014. Automated complexity analysis based on context-sensitive rewriting; pp. 257–271. (Lecture Notes of Computer Science). [Google Scholar]
- 17.Middeldorp A., Moser G., Neurauter F., Waldmann J., Zankl H. Proc. of 4th CAI. vol. 6472. 2011. Joint spectral radius theory for automated complexity analysis of rewrite systems; pp. 1–20. (Lecture Notes in Computer Science). [Google Scholar]
- 18.Avanzini M., Moser G. Proc. of 24th RTA. vol. 21. 2013. A combination framework for complexity; pp. 55–70. (Leibniz International Proceedings in Informatics). [Google Scholar]
- 19.Moser G. Proof theory at work: complexity analysis of term rewrite systems. arXiv:0907.5527 [abs] CoRR. Habilitation Thesis.
- 20.Hoffmann J., Aehlig K., Hofmann M. Multivariate amortized resource analysis. ACM Trans. Program. Lang. Syst. 2012;34(3):14. [Google Scholar]
- 21.Albert E., Arenas P., Genaim S., Gómez-Zamalloa M., Puebla G., Ramírez D., Román G., Zanardini D. Termination and cost analysis with COSTA and its user interfaces. Electron. Notes Theor. Comput. Sci. 2009;258(1):109–121. [Google Scholar]
- 22.Alias C., Darte A., Feautrier P., Gonnord L. Proc. 17th SAS. vol. 6337. 2010. Multi-dimensional rankings, program termination, and complexity bounds of flowchart programs; pp. 117–133. (Lecture Notes in Computer Science). [Google Scholar]
- 23.Gulwani S., Mehra K., Chilimbi T. Proc. of 36th POPL. ACM; 2009. SPEED: precise and efficient static estimation of program computational complexity; pp. 127–139. [Google Scholar]
- 24.Zuleger F., Gulwani S., Sinn M., Veith H. Proc. of 18th SAS. vol. 6887. 2011. Bound analysis of imperative programs with the size-change abstraction; pp. 280–297. (Lecture Notes in Computer Science). [Google Scholar]
- 25.Simmons H. The realm of primitive recursion. Arch. Math. Logic. 1988;27:177–188. [Google Scholar]
- 26.Leivant D. Proc. of 6th LICS. IEEE Computer Society; 1991. A foundational delineation of computational feasibility; pp. 2–11. [Google Scholar]
- 27.Leivant D. Proc. of 20th POPL. 1993. Stratified functional programs and computational complexity; pp. 325–333. [Google Scholar]
- 28.Handley W.G., Wainer S.S. Computational Logic. vol. 165. 1999. Complexity of primitive recursion; pp. 273–300. (NATO ASI Series F: Computer and Systems Science). [Google Scholar]
- 29.Baader F., Nipkow T. Cambridge University Press; 1998. Term Rewriting and All That. [Google Scholar]
- 30.Hirokawa N., Moser G. Proc. of 4th IJCAR. vol. 5195. 2008. Automated complexity analysis based on the dependency pair method; pp. 364–380. (Lecture Notes in Artificial Intelligence). [Google Scholar]
- 31.Dal Lago U., Martini S. Proc. of 36th ICALP. vol. 5556. 2009. On constructor rewrite systems and the lambda-calculus; pp. 163–174. (Lecture Notes in Computer Science). [Google Scholar]
- 32.Avanzini M., Moser G. Proc. of 10th FLOPS. vol. 6009. 2010. Complexity analysis by graph rewriting; pp. 257–271. (Lecture Notes in Computer Science). [Google Scholar]
- 33.Avanzini M., Moser G. Proc. of 21st RTA. vol. 6. 2010. Closing the gap between runtime complexity and polytime computability; pp. 33–48. (Leibniz International Proceedings in Informatics). [Google Scholar]
- 34.Shepherdson J.C., Sturgis H.E. Computability of recursive functions. J. ACM. 1963;10:217–255. [Google Scholar]
- 35.Ferreira M.F. University of Utrecht, Faculty for Computer Science; 1995. Termination of term rewriting: well-foundedness, totality and transformations. Ph.D. thesis. [Google Scholar]
- 36.Steinbach J., Kühler U. University of Kaiserslautern; 1990. Check your ordering – termination proofs and open problems. Tech. Rep. SEKI-Report SR-90-25. [Google Scholar]
- 37.Endrullis J., Waldmann J., Zantema H. Matrix interpretations for proving termination of term rewriting. J. Automat. Reason. 2008;40(3):195–220. [Google Scholar]
- 38.Lankford D. Louisiana Technical University; 1979. On proving term rewriting systems are Noetherian. Tech. Rep. MTP-3. [Google Scholar]
- 39.Zankl H., Korp M. Proc. of 21st RTA. vol. 6. 2010. Modular complexity analysis via relative complexity; pp. 385–400. (Leibniz International Proceedings in Informatics). [Google Scholar]


that either or holds. We use and also for their extension to products: if for all , and for at least one ; likewise if
for all , and for at least one .
for all , where at least one orientation is strict. From this and again using () we conclude