Abstract 1 Introduction 2 Preliminaries 3 The Transformation of Call-By-Value Systems 4 Static Dependency Pairs and Chains 5 The Innermost DP Framework 6 Universal Computability with Usable Rules 7 Implementation and Evaluation 8 Related Work 9 Conclusion and Future Work References Appendix A Full Proofs

An Innermost DP Framework for Constrained Higher-Order Rewriting

Carsten Fuhs ORCID Birkbeck, University of London, UK Liye Guo ORCID Radboud University, Nijmegen, The Netherlands Cynthia Kop ORCID Radboud University, Nijmegen, The Netherlands
Abstract

Logically constrained simply-typed term rewriting systems (LCSTRSs) are a higher-order formalism for program analysis with support for primitive data types. The termination problem of LCSTRSs has been studied so far in the setting of full rewriting. This paper modifies the higher-order constrained dependency pair framework to prove innermost termination, which corresponds to the termination of programs under call by value. We also show that the notion of universal computability with respect to innermost rewriting can be effectively handled in the modified, innermost framework, which lays the foundation for open-world termination analysis of programs under call by value via LCSTRSs.

Keywords and phrases:
Higher-order term rewriting, constrained rewriting, innermost termination, call by value, open-world analysis, dependency pairs
Funding:
Liye Guo: NWO VI.Vidi.193.075, project “CHORPE”.
Cynthia Kop: NWO VI.Vidi.193.075, project “CHORPE”.
Copyright and License:
[Uncaptioned image] © Carsten Fuhs, Liye Guo, and Cynthia Kop; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Equational logic and rewriting
; Theory of computation Logic and verification
Supplementary Material:
Software  (Source Code): https://github.com/hezzel/cora [27]
Software  (Source Code): https://zenodo.org/records/15318964 [28]
Acknowledgements:
We thank the reviewers for helpful comments that allowed us to improve the presentation.
Editors:
Maribel Fernández

1 Introduction

In the study of term rewriting, termination has been an active area of research for decades. Hundreds of different termination techniques have been developed, along with a variety of (fully automatic) termination analyzers that compete against each other in an annual competition [6]. Many of those techniques have been adapted to different styles of term rewriting (e.g., context-sensitive, relative, constrained and higher-order).

In a recent work [22], we have introduced logically constrained simply-typed term rewriting systems (LCSTRSs): a variant of term rewriting that incorporates both higher-order terms and primitive data types such as integers and bit vectors. This formalism is proposed to be a stepping stone toward functional programming languages: by adapting analysis techniques from traditional term rewriting to LCSTRSs, we obtain many of the ingredients needed by the analysis of functional programs, without limiting ourselves to a particular language.

Our long-term goal is to use LCSTRSs as an intermediate verification language in a two-step process to prove correctness properties (e.g., termination, reachability and equivalence) of a program P written in a real-world programming language with higher-order features (e.g., OCaml and Scala): (1) soundly translate P to an LCSTRS P (i.e., if P is, say, terminating, then so is P), and (2) analyze P. This approach has been successfully applied across paradigms to multiple languages, such as Prolog [44, 17], Haskell [16], Java [39] and C [14], via various flavors of term rewriting. We consider LCSTRSs a highly suitable intermediate language that allows for a direct representation of many programming language features. We particularly study termination, both for its own relevance, and due to the fact that it allows the reduction relation to be used as a decreasing measure in induction, which is a powerful aid to proving many other properties.

Most modern termination techniques for term rewriting are defined within the dependency pair (DP) framework [3, 18], which essentially studies groups of recursive function calls. In [21], a higher-order variant of this framework [35, 36, 34, 13] has been adapted to LCSTRSs, and its usefulness in open-world termination analysis has also been established through the notion of universal computability. However, this method still faces limitations: many commonly used DP processors (termination techniques within the DP framework) have not yet been extended to the higher-order and constrained setting, and whereas the first-order DP framework can deal with both full rewriting and innermost rewriting, most higher-order versions – including the one for LCSTRSs – only concern full rewriting. The incapability to handle innermost rewriting is particularly unfortunate since many functional languages use call-by-value evaluation, which largely corresponds to innermost rewriting.

In this paper, we define the first innermost DP framework for LCSTRSs. We shall present DP processors that explicitly benefit from innermost or call-by-value rewriting.

Contributions.

We start in Section 2 with the preliminaries on LCSTRSs and the notion of computability, which is fundamental to static dependency pairs. Then this paper’s contributions follow:

  • In Section 3, we discuss the innermost and the call-by-value strategies, and present a transformation that allows us to better utilize the call-by-value setting.

  • In Section 4, we recall the notion of a static dependency pair for LCSTRSs [21], and extend it by introducing call-by-value dependency pairs and innermost chains.

  • In Section 5, we present an innermost DP framework, which can be used to prove innermost (and call-by-value) termination through the use of various DP processors. We first review three classes of existing DP processors defined for full rewriting, and see how they adapt to the innermost setting. Then we define three more, specifically for the innermost DP framework:

    • In Section 5.2, following the idea of chaining from first-order rewriting with integer constraints [10, 11, 15], we propose a class of DP processors that merge call-by-value dependency pairs. These DP processors can be particularly useful in the analysis of automatically generated systems, which often give rise to a large body of dependency pairs representing intermediate steps of computation.

    • In Section 5.3, we extend the idea of usable rules [3, 19, 24]. While this idea has been applied to higher-order rewriting [2, 40], logical constraints still pose challenges. In the innermost setting, we are able to define this class of DP processors in their most powerful form, which permanently removes rewrite rules from a DP problem.

    • In Section 5.4, we show how usable rules with respect to an argument filtering may be defined, and how this technique makes first-order reduction pairs applicable. This way a large number of first-order techniques can be employed for higher-order termination without a higher-order modification; to be applied to LCSTRSs, those reduction pairs only need to adapt to logical constraints.

  • In Section 6, we discuss the notion of universal computability [21] with respect to innermost rewriting. We will see that the employment of usable rules significantly increases the potential of the innermost DP framework to analyze universal computability: now we can use fully-fledged reduction pair processors for open-world termination analysis, and thereby harness one of the main benefits of the DP framework in this practical setting.

  • We have implemented all the results in our open-source analyzer Cora. The implementation and the evaluation thereof are described in Section 7.

2 Preliminaries

This section collects the preliminaries from the literature. First, we recall the definition of an LCSTRS [22].111In contrast to [22] and following [21], we assume that is a pattern in every rewrite rule r[φ]. For notational convenience, we also assume that Var(r)Var()Var(φ), which can be guaranteed by a simple transformation and is also adopted in the second half of [22]. Then, we recollect from [13] the definition of computability (with accessibility), particularly under the strategies. We borrow several definitions from the phrasing in [21].

2.1 Logically Constrained STRSs

Terms Modulo Theories.

Given a non-empty set 𝒮 of sorts (or base types), the set 𝒯 of (simple) types over 𝒮 is generated by the grammar 𝒯𝒮(𝒯𝒯). Right-associativity is assigned to so we can omit some parentheses. Given disjoint sets and 𝒱, whose elements we call function symbols and variables, respectively, the set 𝔗 of pre-terms over and 𝒱 is generated by the grammar 𝔗𝒱(𝔗𝔗). Left-associativity is assigned to the juxtaposition operation, called application, so for instance t0t1t2 stands for ((t0t1)t2).

We assume every function symbol and variable is assigned a unique type. Typing works as expected: if pre-terms t0 and t1 have types AB and A, respectively, t0t1 has type B. The set T(,𝒱) of terms over and 𝒱 consists of pre-terms that have a type. We write t:A if a term t has type A. We assume there are infinitely many variables of each type.

The set Var(t) of variables in tT(,𝒱) is defined by Var(𝖿)= for 𝖿, Var(x)={x} for x𝒱 and Var(t0t1)=Var(t0)Var(t1). A term t is called ground if Var(t)=.

For constrained rewriting, we make further assumptions. First, we assume there is a distinguished subset 𝒮ϑ of 𝒮, called the set of theory sorts. The grammar 𝒯ϑ𝒮ϑ(𝒮ϑ𝒯ϑ) generates the set 𝒯ϑ of theory types over 𝒮ϑ. Note that a theory type is essentially a non-empty list of theory sorts. Next, we assume there is a distinguished subset ϑ of , called the set of theory symbols, and the type of every theory symbol is in 𝒯ϑ, which means the type of any argument passed to a theory symbol is a theory sort. Theory symbols whose type is a theory sort are called theory values.222Such theory symbols are simply called values in [22]. In this paper, we call them differently so that they are not to be confused with term values as in call by value. Elements of T(ϑ,𝒱) are called theory terms.

Theory symbols are interpreted in an underlying theory: given an 𝒮ϑ-indexed family of sets (𝔛A)A𝒮ϑ, we extend it to a 𝒯ϑ-indexed family by letting 𝔛AB be the set of mappings from 𝔛A to 𝔛B; an interpretation of theory symbols is a 𝒯ϑ-indexed family of mappings ([[]]A)A𝒯ϑ where [[]]A assigns to each theory symbol of type A an element of 𝔛A and is bijective if A𝒮ϑ. Given an interpretation of theory symbols ([[]]A)A𝒯ϑ, we extend each indexed mapping [[]]B to one that assigns to each ground theory term of type B an element of 𝔛B by letting [[t0t1]]B be [[t0]]AB([[t1]]A). We write just [[]] when the type can be deduced.

Example 1.

Let 𝒮ϑ be {𝗂𝗇𝗍}. Then 𝗂𝗇𝗍𝗂𝗇𝗍𝗂𝗇𝗍 is a theory type over 𝒮ϑ while (𝗂𝗇𝗍𝗂𝗇𝗍)𝗂𝗇𝗍 is not. Let ϑ be {} where :𝗂𝗇𝗍𝗂𝗇𝗍𝗂𝗇𝗍 and n:𝗂𝗇𝗍 for all n. The theory values are the elements of . Let 𝔛𝗂𝗇𝗍 be , [[]]𝗂𝗇𝗍 be the identity mapping and [[]] be the mapping λm.λn.mn. The interpretation of () 1 is the mapping λn. 1n (note that functions in our setting are curried).

Type-preserving mappings from 𝒱 to T(,𝒱) are called substitutions. The domain of a substitution σ is the set dom(σ)={x𝒱|σ(x)x}. Let [x1t1,,xntn] denote the substitution σ such that dom(σ){x1,,xn} and σ(xi)=ti for all i. Every substitution σ extends to a type-preserving mapping σ¯ from T(,𝒱) to T(,𝒱). We write tσ for σ¯(t) and define it as follows: 𝖿σ=𝖿 for 𝖿, xσ=σ(x) for x𝒱 and (t0t1)σ=(t0σ)(t1σ).

A context is a term containing a hole. That is, if we let be a special symbol and assign to it a type A, a context C[] is an element of T(,𝒱{}) such that occurs in C[] exactly once. Given a term t:A, let C[t] denote the term produced by replacing in C[] with t.

A term t is called a (maximally applied) subterm of a term s, written as st, if either s=t, s=s0s1 where s1t, or s=s0s1 where s0t and s0t; i.e., s=C[t] for C[] that is not of form C[t1]. We write st and call t a proper subterm of s if st and st.

Constrained Rewriting.

Constrained rewriting requires the theory sort 𝖻𝗈𝗈𝗅: we henceforth assume that 𝖻𝗈𝗈𝗅𝒮ϑ, {𝔣,𝔱}ϑ, 𝔛𝖻𝗈𝗈𝗅={ 0,1}, [[𝔣]]𝖻𝗈𝗈𝗅=0 and [[𝔱]]𝖻𝗈𝗈𝗅=1. Moreover, we require that ϑ includes symbols :𝖻𝗈𝗈𝗅𝖻𝗈𝗈𝗅𝖻𝗈𝗈𝗅, and for each sort A𝒮ϑ also a symbol A:AA𝖻𝗈𝗈𝗅, interpreted respectively as conjunction and equality operators.

A logical constraint is a theory term φ such that φ has type 𝖻𝗈𝗈𝗅 and the type of each variable in Var(φ) is a theory sort. A (constrained) rewrite rule is a triple r[φ] where and r are terms which have the same type, φ is a logical constraint, Var(r)Var()Var(φ), and is a pattern that takes the form 𝖿t1tn for some 𝖿 and contains at least one function symbol in ϑ. Here a pattern is a term whose subterms are either 𝖿t1tn for some 𝖿 or a variable.333As usual in term rewriting, we do not require that each variable occurs at most once in a pattern. A substitution σ is said to respect a logical constraint φ if σ(x) is a theory value for all xVar(φ) and [[φσ]]=1; σ respects the rule r[φ] if it respects φ.

A logically constrained simply-typed term rewriting system (LCSTRS) collects the above data – 𝒮, 𝒮ϑ, , ϑ, 𝒱, (𝔛A) and [[]] – along with a set of rewrite rules. We usually let alone stand for the system. The set induces the rewrite relation over terms: tt if and only if there exists a context C[] such that one of the following holds:

  1. (1)

    t=C[σ] and t=C[rσ] for some r[φ] and substitution σ which respects φ, or

  2. (2)

    t=C[𝖿v1vn] and t=C[v] for some theory symbol 𝖿 and some theory values v1,,vn,v with n>0 and [[𝖿v1vn]]=[[v]].

If tt due to the second condition, we also write tκt and call it a calculation step. Theory symbols that are not a theory value are called calculation symbols. Let tκ denote the (unique) κ-normal form of t, i.e., the term t such that tκt and t↛κt′′ for any t′′. For example, (𝖿(7(32)))κ=𝖿 42 if 𝖿 is not a calculation symbol, or if 𝖿:𝗂𝗇𝗍AB.

A term t is in normal form if there is no term t such that tt. Given an LCSTRS , the set 𝒩() contains all terms that are in normal form with respect to .

Given an LCSTRS , 𝖿 is called a defined symbol if there is at least one rewrite rule of the form 𝖿t1tnr[φ]. Let 𝒟 denote the set of defined symbols. Theory values and function symbols in (ϑ𝒟) are called constructors.

Example 2.

Consider the following LCSTRS , where 𝗀𝖼𝖽𝗅𝗂𝗌𝗍:𝗂𝗇𝗍𝗅𝗂𝗌𝗍𝗂𝗇𝗍, 𝖿𝗈𝗅𝖽:(𝗂𝗇𝗍𝗂𝗇𝗍𝗂𝗇𝗍)𝗂𝗇𝗍𝗂𝗇𝗍𝗅𝗂𝗌𝗍𝗂𝗇𝗍 and 𝗀𝖼𝖽:𝗂𝗇𝗍𝗂𝗇𝗍𝗂𝗇𝗍:

We use infix notation for some binary operators, and omit logical constraints that are 𝔱. Here is a rewrite sequence: 𝗀𝖼𝖽𝗅𝗂𝗌𝗍(𝖼𝗈𝗇𝗌(1+1)𝗇𝗂𝗅)𝖿𝗈𝗅𝖽𝗀𝖼𝖽 0(𝖼𝗈𝗇𝗌(1+1)𝗇𝗂𝗅)𝗀𝖼𝖽(1+1)(𝖿𝗈𝗅𝖽𝗀𝖼𝖽 0𝗇𝗂𝗅)𝗀𝖼𝖽(1+1) 0κ𝗀𝖼𝖽 2 02.

Innermost Rewriting.

The innermost rewrite relation i requires all the proper subterms of a redex to be in normal form: tit if and only if either (1) there exist a context C[], a substitution σ and a rewrite rule r[φ] such that t=C[σ], s↛s for any proper subterm s of σ and any s, t=C[rσ] and σ respects φ, or (2) tκt.

Similarly, for an LCSTRS 𝒬 we define the relation 𝒬 as reduction using where all proper subterms of a redex are in 𝒬-normal form: t𝒬t if and only if either (1) there exist C[], σ and r[φ] such that t=C[σ], s↛𝒬s for any proper subterm s of σ and any s, t=C[rσ] and σ respects φ, or (2) tκt. Note that i is the same as .

Call-By-Value Rewriting.

We may further restrict a redex by requiring each proper subterm to be a ground term value. Here a term value is either a variable or a term 𝖿v1vn where 𝖿 is a function symbol, vi is a term value for all i, and (1) if there is a rule 𝖿t1tkr[φ], then k>n; (2) if 𝖿 is a calculation symbol, then it takes at least n+1 arguments (i.e., 𝖿:A1An+1B). In this paper, we will typically refer to term values as just values. By definition, all theory values are values, and all values are in normal form.

The definition of the call-by-value rewrite relation v follows the pattern of itvt if and only if either (1) there exist a context C[], a substitution σ and a rewrite rule r[φ] such that t=C[σ], s is a ground value for each proper subterm s of σ, t=C[rσ] and σ respects φ, or (2) tκt.

Example 3.

The rewrite sequence in Example 2 is not innermost (and therefore not call-by-value). An example of a call-by-value rewrite sequence is:

Note that the redex in the first step is 𝗀𝖼𝖽𝗅𝗂𝗌𝗍, which does not have 1+1 as subterm.

Example 4.

Consider the LCSTRS ={𝗁𝖽(𝖼𝗈𝗇𝗌xl)x,𝗍𝗅(𝖼𝗈𝗇𝗌xl)l}. Then the rewrite step 𝗁𝖽(𝖼𝗈𝗇𝗌 42(𝗍𝗅𝗇𝗂𝗅))i42 is an innermost step, but not a call-by-value step. The reason is that the subterm 𝗍𝗅𝗇𝗂𝗅 of the redex is in normal form, but not a value: innermost rewriting also allows for rewriting above function calls that are not defined on the given arguments; in a language like OCaml, the computation would abort with an error.

2.2 Accessibility and Computability

Accessibility.

Assume given a sort ordering – a quasi-ordering over 𝒮 whose strict part = is well-founded. We inductively define two relations + and over 𝒮 and 𝒯: for a sort A and a type B=B1BnC where C is a sort and n0, A+B if AC and ABi for all i, and AB if AC and A+Bi for all i.

Given a function symbol 𝖿:A1AnB where B is a sort, the set Acc(𝖿) of the accessible argument positions of 𝖿 is defined as {i|B+Ai}. A term t is called an accessible subterm of a term s, written as sacct, if either s=t, or s=𝖿s1sn for some 𝖿 and there exists kAcc(𝖿) such that skacct. An LCSTRS is called accessible function passing (AFP) if there exists a sort ordering such that for all 𝖿s1snr[φ] where 𝖿 and xVar(r)Var(φ), there exists k such that skaccx.

Example 5.

An LCSTRS is AFP (with equating all the sorts) if for all 𝖿s1snr[φ] where 𝖿 and i{ 1,,n}, the type of each proper subterm of si is a sort. This is typical for many common examples of higher-order programs manipulating first-order data; e.g., integer recursion or list folding, mapping or filtering; hence, Example 2 is AFP.

Consider {𝖼𝗈𝗆𝗉𝗅𝗌𝗍𝖿𝗇𝗂𝗅xx,𝖼𝗈𝗆𝗉𝗅𝗌𝗍(𝖿𝖼𝗈𝗇𝗌fl)x𝖼𝗈𝗆𝗉𝗅𝗌𝗍l(fx)}, where 𝖼𝗈𝗆𝗉𝗅𝗌𝗍:𝖿𝗎𝗇𝗅𝗂𝗌𝗍𝗂𝗇𝗍𝗂𝗇𝗍 composes a list of functions. This system is AFP with 𝖿𝗎𝗇𝗅𝗂𝗌𝗍𝗂𝗇𝗍.

Consider {𝖺𝗉𝗉(𝗅𝖺𝗆f)f} where 𝖺𝗉𝗉:𝗈𝗈𝗈 and 𝗅𝖺𝗆:(𝗈𝗈)𝗈. This system encodes the untyped lambda-calculus, with 𝖺𝗉𝗉 serving as the application symbol and 𝗅𝖺𝗆 as a wrapper for abstractions. It is not AFP since 𝗈𝗈 cannot be true.

Computability.

A term is called neutral if it takes the form xt1tn for some variable x. A set of reducibility candidates, or an RC-set, for a type-preserving relation over terms – which may stand for , i, but also v – is an 𝒮-indexed family of sets (IA)A𝒮 (let I denote AIA) satisfying the following conditions:

  1. (1)

    Each element of IA is a terminating (with respect to ) term of type A.

  2. (2)

    Given terms s and t such that st, if s is in IA, so is t.

  3. (3)

    Given a neutral term s, if t is in IA for all t such that st, so is s.

A term t0 is called I-computable if either the type of t0 is a sort and t0I, or the type of t0 is AB and t0t1 is I-computable for all I-computable t1:A.

We are interested in a specific RC-set :

Theorem 6 (see [13]).

Given a sort ordering and an RC-set I for , let I be the relation over terms such that sIt if and only if both s and t have a base type, s=𝖿s1sm for some function symbol 𝖿, t=skt1tn for some kAcc(𝖿) and ti is I-computable for all i.

Given an LCSTRS with a sort ordering, there exists an RC-set for such that tA if and only if t:A is terminating with respect to , and for all t such that tt, if t=𝖿t1tn for some function symbol 𝖿, ti is -computable for all iAcc(𝖿).

-computability with respect to the innermost reduction relation i is at the heart of the soundness proofs for the DP framework defined in this paper (Theorems 14 and 36).

3 The Transformation of Call-By-Value Systems

Let us reflect on the shape of call-by-value LCSTRSs. First, we observe that if a pattern t is not a value, neither are its instances, i.e., tσ is not a value for any substitution σ. Hence, under call by value, a rewrite rule r[φ] where not all the proper subterms of are values is never applicable, and we can exclude such rewrite rules without loss of generality.

Second, programming languages hardly allow the addition of constructors to pre-defined (in particular, primitive) data types, such as integers. Given an LCSTRS, in practice, we would also expect, for example, that integer literals are the only constructors for 𝗂𝗇𝗍. Formally, we call a theory sort B inextensible if every function symbol 𝖿:A1AnB is a theory symbol or a defined symbol. We do not require that all theory sorts are inextensible; rather, we assume that for each rewrite rule r[φ], all the variables in Var() whose type is an inextensible theory sort are also in Var(φ). We can do so without loss of generality because such a variable can only be instantiated to a theory value under call by value. We only consider inextensible theory sorts in examples below.

We write φ,x1,,xn for φx1x1xnxn, and conclude the above discussion:

Lemma 7.

We apply the below transformation to an LCSTRS and let be the outcome.

  1. (1)

    Remove all r[φ] where has a proper subterm that is not a value.

  2. (2)

    Replace all remaining r[φ] with r[φ,x1,,xn] where x1,,xn are the variables in Var()Var(φ) whose type is an inextensible theory sort.

Then tvt if and only if tvt for all t and t.

Example 8.

The LCSTRS from Example 2 is transformed as follows: (1) no rewrite rules are removed, and (2) four rewrite rules are replaced by the ones below.

𝖿𝗈𝗅𝖽fy𝗇𝗂𝗅 y [𝔱,y] 𝗀𝖼𝖽mn 𝗀𝖼𝖽(m)n [m<0,n]
𝖿𝗈𝗅𝖽fy(𝖼𝗈𝗇𝗌xl) fx(𝖿𝗈𝗅𝖽fyl) [𝔱,x,y] 𝗀𝖼𝖽mn 𝗀𝖼𝖽m(n) [n<0,m]

We will refer to the result of the transformation as 𝗀𝖼𝖽.

We are particularly interested in call-by-value termination. However, innermost termination is more commonly considered in the term rewriting community, and has been studied extensively for first-order term rewriting. In practice, its difference from call-by-value termination is often irrelevant, and their respective techniques are generally similar. Since all values are in normal form, v is terminating if i is. Hence, we shall formulate our results in terms of innermost rewriting, for the sake of more generality and less bookkeeping.

4 Static Dependency Pairs and Chains

The dependency pair method [3] analyzes the recursive structure of function calls. Its variants are at the heart of most modern automatic termination analyzers for various styles of term rewriting. Static dependency pairs [35, 13], a higher-order generalization of the method, are adapted to LCSTRSs in [21]. Now we extend this adaptation for the evaluation strategies.

First, we recall a notation:

Definition 9.

Given an LCSTRS , let be {𝖿|𝖿𝒟} where 𝒟 is the set of defined symbols in and 𝖿 is a fresh function symbol for all 𝖿. Let 𝖽𝗉 be a fresh sort, and for each defined symbol 𝖿:A1AnB where B𝒮, we assign 𝖿:A1An𝖽𝗉. Given a term t=𝖿t1tnT(,𝒱) where 𝖿𝒟, let t denote 𝖿t1tnT(,𝒱).

The definition of a static dependency pair is adapted as follows:

Definition 10.

A static dependency pair (SDP) is a triple st[φ] where s and t are terms of type 𝖽𝗉, and φ is a logical constraint. This SDP is considered call-by-value if all the proper subterms of s are values. For a rewrite rule r[φ], let SDP(r[φ]) denote the set of SDPs of form x1xm𝗀t1tqyq+1yn[φ] such that

  1. (1)

    :A1Am𝖽𝗉 with fresh variables x1,,xm,

  2. (2)

    rx1xm𝗀t1tq for 𝗀𝒟, and

  3. (3)

    𝗀:B1Bn𝖽𝗉 with fresh variables yq+1,,yn.

Let SDP() be r[φ]SDP(r[φ]). For st[𝔱], we just write st.

Compared to the quadruple definition in [21], this definition omits the L component, because here its bookkeeping role can be assumed by the logical constraint.

Intuitively, every dependency pair in SDP() represents a function call in . If is non-terminating, there must be an infinite “chain” of function calls whose arguments are terminating (in other words, the chain is “minimal”: all the proper subterms are terminating). To distinguish the head symbols of those minimal potentially non-terminating terms, we write 𝖿 instead of 𝖿 at head positions in SDPs. Then calls to a defined symbol 𝖿 (the original) can be assumed to terminate, which is shown separately via 𝖿. And the non-existence of an infinite chain starting from a call to any 𝖿 in SDP() implies the termination of .

Example 11.

Following Example 8, SDP(𝗀𝖼𝖽) consists of the following SDPs:

  1. (1)

    𝗀𝖼𝖽𝗅𝗂𝗌𝗍l𝗀𝖼𝖽mn

  2. (2)

    𝗀𝖼𝖽𝗅𝗂𝗌𝗍l𝖿𝗈𝗅𝖽𝗀𝖼𝖽 0l

  3. (3)

    𝗀𝖼𝖽mn𝗀𝖼𝖽(m)n[m<0,n]

  4. (4)

    𝗀𝖼𝖽mn𝗀𝖼𝖽m(n)[n<0,m]

  5. (5)

    𝗀𝖼𝖽mn𝗀𝖼𝖽n(mmodn)[m0n>0]

  6. (6)

    𝖿𝗈𝗅𝖽fy(𝖼𝗈𝗇𝗌xl)𝖿𝗈𝗅𝖽fyl[𝔱,x,y]

In this paper, a set of rewrite rules plays two roles: (1) it specifies how to rewrite arguments in SDPs, and (2) it determines which rewrite steps are innermost and which terms are values. In Sections 5 and 6, a given set in its first role may be modified (with rewrite rules removed). In this process, if we do not keep the original set, there can be unintended consequences for its second role. For example, consider ={𝖿xr1,𝖺r2}. Note that the first rewrite rule is not applicable to 𝖿𝖺 with respect to innermost rewriting. Now if we remove the second rewrite rule from and consider the new set, the remaining rewrite rule will be applicable, and the term 𝖺 will be a value, which is generally an unwanted change.

Hence, we keep a copy of the original set of rewrite rules to faithfully determine which rewrite steps are innermost and which terms are values. Following [18, 41], we let 𝒬 denote this copy. In contrast to the literature, we consider 𝒬 fixed throughout the analysis of a given system.444A fixed set 𝒬 suffices in this paper because our DP processors may remove rewrite rules, but may not add new rewrite rules or change the signature (e.g., with semantic labeling [45]). Now we formalize the idea of a chain of function calls in the innermost setting:

Definition 12.

Given a set 𝒫 of SDPs and a set of rewrite rules, an innermost (𝒫,)-chain is a (finite or infinite) sequence (s0t0[φ0],σ0),(s1t1[φ1],σ1), such that for all i, siti[φi]𝒫, σi is a substitution which respects φi, siσi is in normal form with respect to 𝒬, and ti1σi1𝒬siσi if i>0.

Example 13.

Following Example 11, (1,[l𝗇𝗂𝗅,m24,n18]),(5,[m24,n18]),(5,[m18,n6]) is an innermost (SDP(𝗀𝖼𝖽),𝗀𝖼𝖽)-chain.

In the above definition, the requirement that siσi is in normal form implies that σi(x) is in normal form for all xVar(si), including fresh variables such as l in SDP (1). Hence, the call-by-value (and therefore innermost) rewrite sequence in Example 3 does not directly translate to an innermost (SDP(),)-chain. Nevertheless, we have the following result:

Theorem 14.

An AFP system is innermost (and therefore call-by-value) terminating if there exists no infinite innermost (SDP(),)-chain.

Proof Idea.

The full proof is in Section A.2, and is very similar to its counterpart for termination with respect to full rewriting [21]: in a non-terminating LCSTRS, we can always identify a non-terminating base-type term t=𝖿t1tn such that all ti are -computable; and from an infinite reduction titit′′i we can find s,u such that s=𝖿(t1)(tn), (s,u) is an instance of a dependency pair, and u is again non-terminating with -computable arguments. The primary difference from [21] is the need to ensure all variables are instantiated to normal forms, which for the fresh variables discussed above means that we must choose the right normal form that still yields non-termination.

5 The Innermost DP Framework

In this section, we modify the constrained DP framework [21] to prove innermost termination. The DP framework is a collection of DP processors, each of which represents a technique.

Definition 15.

A DP problem is a pair (𝒫,) where 𝒫 is a set of SDPs and is a set of rewrite rules. If no infinite innermost (𝒫,)-chain exists, (𝒫,) is called finite. A DP processor is a partial mapping which possibly assigns to a DP problem a set of DP problems. A DP processor ρ is called sound if (𝒫,) is finite whenever all the elements of ρ(𝒫,) are.

Theorem 14 tells us that an AFP system is innermost terminating if (SDP(),) is a finite DP problem. Given a collection of sound DP processors, we have the following procedure: (1) 𝒬, S{(SDP(),)}; (2) while S contains a DP problem (𝒫,) to which some sound DP processor ρ is applicable, S(S{(𝒫,)})ρ(𝒫,). If this procedure ends with S=, we can conclude that is innermost terminating.

5.1 Graph, Subterm Criterion and Integer Mapping Processors

Three classes of DP processors in [21] remain essentially unchanged in the innermost setting. Let us review their application to the system 𝗀𝖼𝖽 from Example 8, which is discussed by [21] in the form of Example 2. First, we consider a graph approximation for (SDP(𝗀𝖼𝖽),𝗀𝖼𝖽):

Definition 16.

For a DP problem (𝒫,), a graph approximation (G,θ) consists of a finite directed graph G and a mapping θ from 𝒫 to the vertices of G such that there is an edge from θ(p0) to θ(p1) whenever (p0,σ0),(p1,σ1) is an innermost (𝒫,)-chain for some σ0 and σ1.

Compared to [21], the main change is that we now check for innermost (𝒫,)-chains to determine which edges must exist. A graph approximation for (SDP(𝗀𝖼𝖽),𝗀𝖼𝖽) is in Figure 1. Despite the slightly different SDPs (due to the transformation of the call-by-value system), this graph approximation is the same as the one in [21].

Figure 1: A graph approximation for (SDP(𝗀𝖼𝖽),𝗀𝖼𝖽).

Given a graph approximation, we can decompose the DP problem:

Definition 17.

Given a DP problem (𝒫,), a graph processor computes a graph approximation (G,θ) for (𝒫,) and the strongly connected components (SCCs) of G, then returns {({p𝒫|θ(p) belongs to S},)|S is a non-trivial SCC of G}.

If a graph processor produces the graph approximation in Figure 1, it will return the set {({6},𝗀𝖼𝖽),({3,4},𝗀𝖼𝖽),({5},𝗀𝖼𝖽)}. Next, we observe that 𝖿𝗈𝗅𝖽 is defined by structural recursion, which can be handled by subterm criterion processors. Let heads(𝒫) denote the set of function symbols heading either side of an SDP in 𝒫, and we have the following definition:

Definition 18.

A projection ν for a set 𝒫 of SDPs is a mapping from heads(𝒫) to integers such that 1ν(𝖿)n if 𝖿:A1An𝖽𝗉. Let ν¯(𝖿t1tn) denote tν(𝖿). A projection ν is said to -orient a subset 𝒫 of 𝒫 if ν¯(s)ν¯(t) for all st[φ]𝒫 and ν¯(s)=ν¯(t) for all st[φ]𝒫𝒫. A subterm criterion processor maps (𝒫,) to {(𝒫𝒫,)} for some non-empty 𝒫𝒫 which is -oriented by some projection for 𝒫.

Choosing ν(𝖿𝗈𝗅𝖽)=3, we have ν¯(𝖿𝗈𝗅𝖽fy(𝖼𝗈𝗇𝗌xl))=𝖼𝗈𝗇𝗌xll=ν¯(𝖿𝗈𝗅𝖽fyl), so a subterm criterion processor maps ({6},𝗀𝖼𝖽) to {(,𝗀𝖼𝖽)}, and (,𝗀𝖼𝖽) can (trivially) be removed by a graph processor. Now we are left with ({3,4},𝗀𝖼𝖽) and ({5},𝗀𝖼𝖽), which involve recursion over integers. We deal with those by means of integer mappings:

Definition 19.

Given a set 𝒫 of SDPs, for all 𝖿heads(𝒫) where 𝖿:A1An𝖽𝗉, let ι(𝖿) be the subset of { 1,,n} such that iι(𝖿) if and only if Ai𝒮ϑ and the i-th argument of any occurrence of 𝖿 in an SDP st[φ]𝒫 is in T(ϑ,Var(φ)). Let 𝒳(𝖿) be a set of fresh variables {xi|iι(𝖿)} where xi:Ai for all i. An integer mapping 𝒥 for 𝒫 is a mapping from heads(𝒫) to theory terms such that for all 𝖿, 𝒥(𝖿):𝗂𝗇𝗍 and Var(𝒥(𝖿))𝒳(𝖿). Let 𝒥¯(𝖿t1tn) denote 𝒥(𝖿)[xiti]iι(𝖿).

Integer mapping processors handle decreasing integer values:

Definition 20.

Given a set 𝒫 of SDPs, an integer mapping 𝒥 is said to >-orient a subset 𝒫 of 𝒫 if φ𝒥¯(s)0𝒥¯(s)>𝒥¯(t) for all st[φ]𝒫, and φ𝒥¯(s)𝒥¯(t) for all st[φ]𝒫𝒫, where φφ denotes that [[φσ]]=1 implies [[φσ]]=1 for each substitution σ which maps variables in Var(φ)Var(φ) to theory values. An integer mapping processor maps (𝒫,) to {(𝒫𝒫,)} for some non-empty 𝒫𝒫 which is >-oriented by some integer mapping for 𝒫.

To deal with ({5},𝗀𝖼𝖽), let 𝒥(𝗀𝖼𝖽) be x2 so 𝒥¯(𝗀𝖼𝖽mn)=n, 𝒥¯(𝗀𝖼𝖽n(mmodn))=mmodn and m0n>0n0n>mmodn. Then an integer mapping processor returns {(,𝗀𝖼𝖽)}, and (,𝗀𝖼𝖽) can (trivially) be removed by a graph processor.

Unlike [21], here an integer mapping processor is applicable to ({3,4},𝗀𝖼𝖽)𝒥(𝗀𝖼𝖽)=x1 and the processor returns {({4},𝗀𝖼𝖽)}. Then ({4},𝗀𝖼𝖽) can be removed by a graph processor. This simpler proof is due to the transformation of the call-by-value system; in both SDPs, m and n can be instantiated only to theory values, which is not the case in [21], and a theory argument processor is needed there. To elaborate, we consider the system :

𝖿xyz𝖿x(x+1)(x1)[y<z]𝖼xyx𝖼xyy

We have 𝖿(𝖼 0 3) 1 2𝖿(𝖼 0 3)((𝖼 0 3)+1)((𝖼 0 3)1)+𝖿(𝖼 0 3) 1 2, and therefore is not terminating with respect to full rewriting. Under call by value, is terminating: the first rewrite rule with x appended to the logical constraint gives the only SDP 𝖿xyz𝖿x(x+1)(x1)[y<z,x], then let 𝒥(𝖿) be x3x2. Here we benefit from call by value.

5.2 The Chaining of Call-By-Value SDPs

Another benefit of call by value is that we may chain together consecutive SDPs, e.g., 𝖿𝖺𝖼𝗍x𝗎1x 1[𝔱,x] and 𝗎1xz𝗎2xz 1[𝔱,x,z] may merge to form 𝖿𝖺𝖼𝗍x𝗎2x 1 1[𝔱,x]. This capability can be important for automatically generated systems.

Definition 21.

Given SDPs p0=(s0𝖿t1tn[φ0]) and p1=(𝖿s1snt1[φ1]) where 𝖿𝒟 and variables are renamed if necessary to avoid name collisions, p0 and p1 are called chainable if p1 is a call-by-value SDP and there exists a substitution σ such that dom(σ)=i=1nVar(si), ti=siσ for all i, and σ(x)T(ϑ,Var(φ0)) for all xdom(σ)Var(φ1). The chaining ch(p0,p1) of p0 and p1 is s0t1σ[φ0(φ1σ)].

Note that in the context of call-by-value rewriting, all SDPs can be assumed to be call-by-value, and therefore it is not particularly restrictive to so require p1 above. To see the importance of this requirement, consider the DP problem ({𝖿𝖺𝖻𝗀(𝗁𝖻𝖺),𝗀(𝗁xy)𝖿xy},{𝗁𝖻𝖺𝗁𝖺𝖻}). If we dropped the call-by-value requirement for the second SDP, the two SDPs would be chainable and yield 𝖿𝖺𝖻𝖿𝖻𝖺. However, 𝖿𝖻𝖺 is not reachable from 𝖿𝖺𝖻 initially, and replacing the original SDPs with the new one is not sound.

Definition 22.

Given a set 𝒫 of SDPs and 𝖿𝒟 such that 𝒫𝖿, 𝒫𝖿r, 𝒫𝖿𝒫𝖿r= and every pair in 𝒫𝖿r×𝒫𝖿 is chainable where 𝒫𝖿={st[φ]𝒫|s=𝖿s1sn} and 𝒫𝖿r={st[φ]𝒫|t=𝖿t1tn}, a chaining processor assigns to a DP problem (𝒫,) the singleton {((𝒫(𝒫𝖿𝒫𝖿r))𝒫,)} where 𝒫={ch(p0,p1)|p0𝒫𝖿r and p1𝒫𝖿}.

Example 23.

Consider the below set 𝒫 of SDPs generated from an imperative program [14]:

𝖿𝖺𝖼𝗍x 𝗎1x 1 [𝔱,x] 𝗎1xz 𝗎2xz 1 [𝔱,x,z]
𝗎2xzi 𝗎3xzi [ix,z] 𝗎3xzi 𝗎4x(zi)i [𝔱,x,z,i]
𝗎2xzi 𝗎5xz [¬(ix),z] 𝗎4xzi 𝗎2xz(i+1) [𝔱,x,z,i]

Chaining processors can iteratively remove the occurrences of 𝗎1, 𝗎3 and 𝗎4, and end with (1) 𝖿𝖺𝖼𝗍x𝗎2x 1 1[𝔱,x], (2) 𝗎2xzi𝗎2x(zi)(i+1)[ix,z], and (3) 𝗎2xzi𝗎5xz[¬(ix),z]. Note that a chaining processor for 𝖿𝒟 removes all the occurrences of 𝖿 in 𝒫, and therefore the process of iteratively applying chaining processors always terminates (on the assumption that heads(𝒫) is finite). In this example, the above outcome cannot be further chained; there is no chaining processor for 𝗎2 because 𝒫𝗎2𝒫𝗎2r contains SDP (23).

Example 24.

Consider the following set 𝒫 of SDPs:

𝖿xy 𝗀(𝖼𝗈𝗆𝖻xy) [x0,y] 𝗀(𝖼𝗈𝗆𝖻zw) 𝗁(z+w) [w0,z]
𝖿xy 𝗀(𝖼𝗈𝗆𝖻(x)y) [x<0,y] 𝗀(𝖼𝗈𝗆𝖻zw) 𝗁(zw) [w<0,z]

where 𝖼𝗈𝗆𝖻:𝗂𝗇𝗍𝗂𝗇𝗍𝗂𝗇𝗍𝗉𝖺𝗂𝗋 is a constructor. Note that 𝖼𝗈𝗆𝖻zw is a value. Chaining processors can remove the occurrences of 𝗀, and end with (1) 𝖿xy𝗁(x+y)[x0y0], (2) 𝖿xy𝗁(xy)[x0y<0], (3) 𝖿xy𝗁(x+y)[x<0y0], and (4) 𝖿xy𝗁(xy)[x<0y<0].

5.3 Usable Rules

A key processor in the DP framework for full rewriting, which also applies in the innermost setting, is the reduction pair processor [21, Definition 25]. This processor is so powerful because it can potentially be used with a wide variety of different reduction pairs and does not require to be monotonic: we must show sφt or sφt for all SDPs st[φ], and sφt for all rules st[φ], and we may then remove the SDPs oriented with .

The challenge is that, no matter how small 𝒫, we must orient all rules in the DP problem – and all processors considered so far only modify the set 𝒫 of SDPs. Fortunately, in the innermost setting, we can see that only some of the rules could potentially be relevant.

To illustrate the idea, consider a system 𝖽𝗋𝗈𝗉 which includes at least the following rewrite rules and no other defining 𝖽𝗋𝗈𝗉, 𝖽𝖿𝗈𝗅𝖽𝗋, 𝖼𝗈𝗇𝗌, or 𝗇𝗂𝗅:

𝖽𝗋𝗈𝗉nll[n0]𝖽𝗋𝗈𝗉n𝗇𝗂𝗅𝗇𝗂𝗅[𝔱,n]𝖽𝗋𝗈𝗉n(𝖼𝗈𝗇𝗌xl)𝖽𝗋𝗈𝗉(n1)l[n>0]
𝖽𝖿𝗈𝗅𝖽𝗋fyn𝗇𝗂𝗅y[𝔱,n]𝖽𝖿𝗈𝗅𝖽𝗋fyn(𝖼𝗈𝗇𝗌xl)fx(𝖽𝖿𝗈𝗅𝖽𝗋fyn(𝖽𝗋𝗈𝗉nl))[𝔱,n]

where 𝖽𝗋𝗈𝗉:𝗂𝗇𝗍𝖺𝗅𝗂𝗌𝗍𝖺𝗅𝗂𝗌𝗍 and 𝖽𝖿𝗈𝗅𝖽𝗋:(𝖺𝖻𝖻)𝖻𝗂𝗇𝗍𝖺𝗅𝗂𝗌𝗍𝖻. To deal with the SDP ({𝖽𝖿𝗈𝗅𝖽𝗋fyn(𝖼𝗈𝗇𝗌xl)𝖽𝖿𝗈𝗅𝖽𝗋fyn(𝖽𝗋𝗈𝗉nl)[𝔱,n]},𝖽𝗋𝗈𝗉), we need a reduction pair processor; roughly, we should show that 𝖼𝗈𝗇𝗌xl is somehow “greater” than 𝖽𝗋𝗈𝗉nl, which cannot be done by a subterm criterion or an integer mapping processor. However, since the variables are to be instantiated to normal forms, any rules other than the ones defining 𝖽𝗋𝗈𝗉 would not be used in a chain for this problem. Hence, only these three rules need to be oriented. This observation leads to the notion of usable rules [3, 13]. We base our formulation on a higher-order version [26] and start with two auxiliary definitions:

Definition 25.

For r[φ] where :A1AnB for B𝒮, let (r[φ])ex be {r[φ],x1rx1[φ],,x1xnrx1xn[φ]} where x1,,xn are fresh variables. Let ex denote r[φ](r[φ])ex.

Definition 26.

The set of usable symbols in a term t with respect to a logical constraint φ, denoted by 𝒰(t)[φ], is defined inductively as follows:

  1. (1)

    Suppose t=𝖿t1tn for 𝖿. If tT(ϑ,Var(φ)), then 𝒰(t)[φ]=; otherwise 𝒰(t)[φ]={(𝖿,n)}i=1n𝒰(ti)[φ].

  2. (2)

    Suppose t=xt1tn for x𝒱. If n=0, then 𝒰(t)[φ]=; otherwise 𝒰(t)[φ]={}.

Here is a special symbol indicating that potentially any symbol could be usable.

The set of usable symbols for a set 𝒫 of SDPs and a set of rewrite rules, denoted by 𝒰(𝒫,), is the smallest set U such that (1) 𝒰(t)[φ]U for all st[φ]𝒫, and (2) 𝒰(r)[φ]U for all (𝖿,n)U and 𝖿t1tnr[φ]ex. Then 𝒰(𝒫,) exists because it is the least pre-fixed point of an order-preserving mapping on a complete lattice.

We present usable rules as a class of DP processors:

Definition 27.

Given sets 𝒫 of SDPs and of rules: if 𝒰(𝒫,), the set 𝒰(𝒫,) of usable rules is defined as {𝖿t1tkr[φ]|(𝖿,n)𝒰(𝒫,) and kn}; otherwise, 𝒰(𝒫,) is undefined. A usable-rules processor assigns to a DP problem (𝒫,) with 𝒩(𝒬)𝒩() the singleton {(𝒫,𝒰(𝒫,))}.

Example 28.

We continue the discussion about 𝖽𝗋𝗈𝗉 and 𝖽𝖿𝗈𝗅𝖽𝗋. Consider the DP problem (𝒫,𝖽𝗋𝗈𝗉) where 𝒫={𝖽𝖿𝗈𝗅𝖽𝗋fyn(𝖼𝗈𝗇𝗌xl)𝖽𝖿𝗈𝗅𝖽𝗋fyn(𝖽𝗋𝗈𝗉nl)[𝔱,n]}. We have 𝒰(𝖽𝖿𝗈𝗅𝖽𝗋fyn(𝖽𝗋𝗈𝗉nl))[𝔱,n]={(𝖽𝖿𝗈𝗅𝖽𝗋,4),(𝖽𝗋𝗈𝗉,2)} and can derive 𝒰(𝒫,)={(𝖽𝖿𝗈𝗅𝖽𝗋,4),(𝖽𝗋𝗈𝗉,2),(𝗇𝗂𝗅,0)}. Hence, 𝒰(𝒫,) consists of the three rules defining 𝖽𝗋𝗈𝗉.

5.4 Argument Filterings

Let us consider the role of in the definition of usable rules: 𝒰(𝒫,) is undefined if 𝒰(𝒫,) – which occurs if the right-hand side of some SDP in 𝒫, or the right-hand side of any rule 𝖿t1tnr[φ]ex with (𝖿,n)𝒰(𝒫,), is not a pattern. This is not a rare occasion in higher-order rewriting. For example, let us rework 𝖽𝖿𝗈𝗅𝖽𝗋 into 𝖽𝖿𝗈𝗅𝖽𝗅:

𝖽𝖿𝗈𝗅𝖽𝗅fyn𝗇𝗂𝗅y[𝔱,n]𝖽𝖿𝗈𝗅𝖽𝗅fyn(𝖼𝗈𝗇𝗌xl)𝖽𝖿𝗈𝗅𝖽𝗅f(fyx)n(𝖽𝗋𝗈𝗉nl)[𝔱,n]

where 𝖽𝗋𝗈𝗉 is defined by the same rules as before. Now we have 𝖽𝖿𝗈𝗅𝖽𝗅fyn(𝖼𝗈𝗇𝗌xl)𝖽𝖿𝗈𝗅𝖽𝗅f(fyx)n(𝖽𝗋𝗈𝗉nl)[𝔱,n], which produces .

However, observe that the problematic subterm fyx and the decreasing subterm 𝖽𝗋𝗈𝗉nl occur in different arguments of 𝖽𝖿𝗈𝗅𝖽𝗅. If we use a reduction pair that considers only the fourth argument, intuitively we can disregard any rules that may be used to reduce the second. This is formalized via an argument filtering [3, 26], which temporarily removes certain subterms from both sides of an ordering requirement before computing usable rules, often drastically reducing the number of usable rules that the reduction pair must consider.

Traditionally, argument filterings are defined for function symbols with a fixed number of arguments. Extending this notion to our curried setting imposes new technical challenges; e.g., if we filter away the second argument of 𝖿:ABC, what type to use for the filtering of 𝖿x, C or BC? Fortunately, this problem is solvable if we do not allow variables to occur at the head of an application in the result of a filtering. This is very different from the approach in [2], which heavily restricts what filtering can be used, to ensure that a variable of higher type and all its possible instances have the same filtering applied to them.

Definition 29.

We assume given a set 𝒮1 of sorts such that 𝒮ϑ𝒮1, and a mapping μ from 𝒯 to 𝒮1 such that μ(A)=A for all A𝒮ϑ. In addition, for each function symbol 𝖿:A1AnB with B𝒮, we assume given a set regard(𝖿){ 1,,n}. Define:

Σ=ϑ{𝖿m:μ(Ai1)μ(Aik)μ(Am+1AnB)𝖿:A1AnBwithB𝒮and 0mnandregard(𝖿){ 1,,m}={i1,,ik}andi1<<ik}{μ(A):μ(A)A𝒯}

The argument filtering with respect to a logical constraint φ is a mapping πφ from T(,𝒱) to T(Σ,{x:μ(A)x:A𝒱}), defined as follows:

  1. (1)

    πφ(𝖿t1tn)=𝖿t1tn if 𝖿t1tnT(ϑ,Var(φ)) and has a base type

  2. (2)

    πφ(𝖿t1tn)=𝖿nπφ(ti1)πφ(tik) otherwise, where {i1,,ik}=regard(𝖿){ 1,,n} and i1<<ik

  3. (3)

    πφ(x)=x for x𝒱; and πφ(xt1tn)=μ(A) if x𝒱 and n>0

By definition, πφ(t):μ(A) for all t:A. Moreover, no subterm of πφ(t) has a variable at the head of an application, and all function symbols have a first-order type and occur maximally applied. Hence, πφ(t) is a (many-sorted) first-order term, just written in applicative notation. For 𝒮1, we may for instance choose 𝒮ϑ{𝗈}, i.e., there is a single sort besides theory sorts.

Now we define usable rules with respect to an argument filtering:

Definition 30.

Given the mapping regard(), 𝒰(𝖿t1tn)[φ] is redefined as {(𝖿,n)}iregard(𝖿){ 1,,n}𝒰(ti)[φ] in the case where 𝖿t1tnT(ϑ,Var(φ)). The definition in other cases is unchanged, and so is the definition of 𝒰(𝒫,).

Let U1 be {πφ(𝖿t1tn)πφ(r)[φ]|(𝖿,n)𝒰(𝒫,) and 𝖿t1tnr[φ]ex}, and U2 be {𝖿nxi1xiky[y=𝖿x1xn]|(𝖿,n)𝒰(𝒫,),𝖿ϑ,n>0,𝖿:A1AnB with B𝒮,regard(𝖿)={i1,,ik} and i1<<ik}.

We redefine 𝒰(𝒫,) as U1U2 if 𝒰(𝒫,), and p+iregard(𝖿) for all (𝖿,n)𝒰(𝒫,), 𝖿s1sp𝗀t1tq[φ] where p<n and 𝗀, and i{ 1,,np} such that q+iregard(𝗀). Otherwise, 𝒰(𝒫,) is undefined.

That is, we consider usable rules only with respect to the positions that are not filtered away. The requirement that p+iregard(𝖿) if (𝖿,n) is a usable symbol and p+in is a technical limitation needed to ensure that applying a rewrite rule at the head of an application does not conflict with the argument filtering.

Next, we recall the notion of a constrained reduction pair from [21], but use a more liberal monotonicity requirement due to the first-order setting created by the filtering.

Definition 31.

A constrained relation R is a set of triples (s,t,φ) where s and t are (first-order) terms which have the same sort and φ is a logical constraint. We write s𝑅φt if (s,t,φ)R. A binary relation R over terms is said to cover a constrained relation R if s𝑅φt implies that (sσ)κR(tσ)κ for each substitution σ which respects φ.

A constrained reduction pair (,) is a pair of constrained relations where is covered by some reflexive and transitive relation such that tktk implies 𝖿t1tk1tktk+1tn𝖿t1tk1tktk+1tn (i.e., monotonicity) for all 𝖿Σ and k{ 1,,n}, is covered by some well-founded relation , and ;+.

Having this, we can define reduction pair processors with respect to an argument filtering:

Definition 32.

A reduction pair processor with argument filterings assigns to a DP problem (𝒫,) with 𝒩(𝒬)𝒩() the singleton {(𝒫𝒫,)} for some non-empty 𝒫𝒫 if there exists a mapping regard() and a constrained reduction pair (,) such that (1) πφ(s)φπφ(t) for all st[φ]𝒫, (2) πφ(s)φπφ(t) for all st[φ]𝒫𝒫, and (3) φr for all r[φ]𝒰(𝒫,).

Example 33.

Consider 𝖽𝖿𝗈𝗅𝖽𝗅, with the following DP problem: ({𝖽𝖿𝗈𝗅𝖽𝗅fyn(𝖼𝗈𝗇𝗌xl)𝖽𝖿𝗈𝗅𝖽𝗅f(fyx)n(𝖽𝗋𝗈𝗉nl)[𝔱,n]},) Let regard(𝖽𝖿𝗈𝗅𝖽𝗅) be { 4}, regard(𝖽𝗋𝗈𝗉) be { 2}, and regard(𝖼𝗈𝗇𝗌) be { 2}. We are obliged to prove (1) 𝖽𝖿𝗈𝗅𝖽𝗅4(𝖼𝗈𝗇𝗌2l)𝔱,n𝖽𝖿𝗈𝗅𝖽𝗅4(𝖽𝗋𝗈𝗉2l), (2) 𝖽𝗋𝗈𝗉2ln0l, (3) 𝖽𝗋𝗈𝗉2𝗇𝗂𝗅0𝔱,n𝗇𝗂𝗅0, and (4) 𝖽𝗋𝗈𝗉2(𝖼𝗈𝗇𝗌2l)n>0𝖽𝗋𝗈𝗉2l. The recursive path ordering for first-order LCTRSs [29] can be used to fulfill these obligations.

6 Universal Computability with Usable Rules

In this section, we study universal computability [21] with respect to innermost rewriting. This concept concerns a modular programming scenario where the LCSTRS represents a single module in a larger program, and corresponds to the termination of a function in all “reasonable” uses, including unknown uses. We recall the notion of a hierarchical combination [31, 32, 33, 9] rephrased in terms of LCSTRSs:

Definition 34 ([21]).

An LCSTRS 1 is called an extension of a base system 0 if the two systems’ interpretations of theory symbols coincide over all the theory symbols in common, and function symbols in 0 are not defined by any rewrite rule in 1. Given a base system 0 and an extension 1 of 0, the system 01 is called a hierarchical combination.

In a hierarchical combination, function symbols in the base system can occur in the extension, but cannot be (re)defined; one may think of 0 as an imported module.

Universal computability is defined on the basis of hierarchical combinations:

Definition 35 ([21]).

Given an LCSTRS 0 with a sort ordering , a term t is called universally computable if for each extension 1 of 0 and each extension of to sorts in 01 (i.e., coincides with over sorts in 0), t is -computable in 01 with . 0 is called universally computable if all its terms are.

In summary, we consider passing -computable arguments to a defined symbol in 0 the “reasonable” way of calling the function. We use SDPs to establish universal computability:

Theorem 36.

An accessible function passing system 0 with sort ordering is universally computable if there exists no infinite innermost (SDP(0),01)-chain for any extension 1 of 0 and extension of to sorts in 01.

This is a more general version of Theorem 14 and will be proved alongside it in Appendix A.2. Note that the original set of rules, 𝒬, in the definition of innermost chain is now 01. We modify the DP framework to prove universal computability for a fixed base system 0.

Definition 37.

A (universal) DP problem (𝒫,,𝚙) consists of a set 𝒫 of SDPs, a set of rewrite rules and a flag 𝚙{𝔡𝔢𝔣,𝔦𝔫𝔡} (for definite or indefinite). A DP problem (𝒫,,𝚙) is finite if either (1) 𝚙=𝔡𝔢𝔣 and there exists no infinite innermost (𝒫,)-chain (with 𝒬0), or (2) 𝚙=𝔦𝔫𝔡 and there exists no infinite innermost (𝒫,1)-chain for any extension 1 of 0 (with 𝒬01).

DP processors are defined in the same way as before, now for universal DP problems. The goal is to show that (SDP(0),0,𝔦𝔫𝔡) is finite, and the procedure for termination in Section 5 still works if we change the initialization accordingly. Unlike [21], here we have the advantage of usable rules: if 𝒰(𝒫,) is defined, then 𝒰(𝒫,1)=𝒰(𝒫,) for any extension 1 (provided all symbols in 𝒫 and are from 0, which is typically the case as DP processors generally do not introduce new symbols). Hence a usable-rules processor assigns to a DP problem (𝒫,,𝚙) the singleton {(𝒫,𝒰(𝒫,),𝔡𝔢𝔣)}.

Even if usable-rules processors are not applicable, we may still use a reduction pair processor with an argument filtering: we do not have to orient the rules in 1 since they cannot be usable. Referring to Definition 32, a reduction pair processor now assigns to a DP problem (𝒫,,𝚙) the singleton {(𝒫𝒫,,𝚙)} without changing the input flag because it does not permanently discard any rule. The other DP processors discussed in Section 5 apply to universal DP problems similarly; they just keep the input flag unchanged in the output.

7 Implementation and Evaluation

We have implemented our results in Cora [27], using a version of HORPO (based on the initial definition in [22]) and its first-order limitation RPO as the only reduction pair. Constraint validity checks are delegated to the SMT solver Z3 [8]. We also use Z3 to seek a good argument filtering and HORPO instance by encoding the requirements into an SMT problem.

Our implementation of the chaining processor from Definition 22 aims to minimize the number of DPs in the resulting problem. To this end, it chooses a function symbol 𝖿 such that the expression |𝒫||𝒫𝖿𝒫𝖿r| with the sets defined as in Definition 22 is minimized.

We evaluated Cora on three groups of benchmarks: our own collected LCSTRS benchmarks, the lambda-free problems from the higher-order category of the TPDB [7], and problems from the first-order “integer TRS innermost” category. The results are summarized below, where “full” considers the framework for full termination with the methods from [21], and “call-by-value” does the transformation of Lemma 7 before applying the innermost framework:

Termination Universal Computability
Full Innermost Call-by-value Full Innermost Call-by-value
Total yes 171 179 182 155 179 182
Total maybe 104 96 93 116 96 93

Note that we gain significant power compared to [21] when analyzing universal computability. This is largely due to the two usable-rules processors: the reduction pair processor cannot be applied on its own in an indefinite DP problem, so either changing the flag from 𝔦𝔫𝔡 to 𝔡𝔢𝔣, or being able to omit the extra rules in a reduction pair, gives a lot of power.

However, the gains for termination are more modest. We suspect the reason is that the new processors primarily find their power in large systems (where it is essential to eliminate many rules when searching for a reduction pair), and automatically generated systems (where there are often many chainable rules), not in the handcrafted benchmarks of the TPDB.

Another observation is that there is no difference in proving power between termination or universal computability, both for innermost and for call-by-value reduction. This may be due to Cora having only one reduction pair (HORPO): on this benchmark set, when HORPO can be applied to simplify a DP problem, then it is also possible to filter away problematic subterms that would stop us from applying usable rules.

A detailed evaluation page is available through the following link:

https://www.cs.ru.nl/˜cynthiakop/experiments/fscd25/

Comparison to Other Analyzers.

While we have made progress, the additions of this paper are not yet sufficient for Cora to compete with dedicated analyzers for first-order integer rewriting, or unconstrained higher-order term rewriting.

In the “integer TRS innermost” category, AProVE [15] can prove innermost termination of 102 benchmarks, while Cora can handle 72 for innermost evaluation and 73 for call-by-value. The most important difference seems to be that AProVE has a much more sophisticated implementation of what we call the integer mapping processor as a reduction pair processor with polynomial interpretations and usable rules with respect to argument filterings [12]. In addition, these benchmarks often have rules such as 𝖿(x)𝗀(x>0,x),𝗀(𝔱,x)r1,𝗀(𝔣,x)r2, which would benefit from a transformation to turn the Boolean subterm x>0 into a proper constraint. Improving on these points is obvious future work.

In the “higher-order union beta” category, Wanda [25] can prove termination of full rewriting of 105 benchmarks, while Cora can handle 79 for innermost or call-by-value reduction. Since these benchmarks are unconstrained, Cora does not benefit here from any of the processors that consider the theory, while Wanda does have many more features to increase its prover ability; for example, polynomial interpretations, dynamic dependency pairs, and delegation of partial problems to a first-order termination tool.

8 Related Work

Dependency Pair frameworks are the cornerstone of most fully automated termination analysis tools for various flavors of first-order [1, 19, 23] and higher-order [2, 13, 30] rewriting. A common theme of these DP frameworks lies in the notions of a problem to be analyzed for presence of infinite chains and processors to advance the proofs of (non-)termination. The notion of DP frameworks has been lifted to constrained rewriting, both in the first-order [10, 12] and recently also in the higher-order [21] setting. The latter work also includes the notion of universal computability, allowing for termination proofs also in the presence of further library functions that are not known at the time of analysis.

Our present DP framework for innermost rewriting is specially designed with termination analysis of functional programs in call-by-value languages (e.g., Scala, OCaml) in mind as a target application. Such LCSTRSs may come from an automated syntactic translation and thus have more rewrite rules with “intermediate” defined symbols than hand-optimized rewrite systems. Our chaining processor renders the analysis of such problems feasible. This kind of program transformation is used also in other program analysis tools [4, 10, 14, 15]; here, we have adapted the technique to higher-order rewriting with constraints.

Usable rules w.r.t. an argument filtering were introduced for first-order rewriting in [19] and soon extended to simply-typed higher-order rewriting for arbitrary rewrite strategies in [2]. Our contribution here is to lift usable rules w.r.t. an argument filtering to a setting with theory constraints and to universal computability, thus opening up the door for applications in analysis of programs for real-world languages. Moreover, we adapt the technique to innermost rewriting and thus do not require that the constrained reduction pair (,) satisfies 𝖼xyx and 𝖼xyy for fresh symbols 𝖼.

9 Conclusion and Future Work

In this paper, we have extended the static dependency pair framework for LCSTRSs to innermost and call-by-value evaluation strategies. In doing so, we have adapted several existing processors for full termination and proposed three processors – chaining, usable rules, reduction pairs with usable rules w.r.t. argument filterings – that were not present for the setting of full termination. These processors apply not only to conventional closed-world termination analysis, but also to open-world termination analysis via universal computability, where the presence of further rewrite rules for library functions is assumed, thus broadening the set of potential start terms that must be considered. Our experimental results on several benchmark collections indicate improvements over the state of the art by exploiting the evaluation strategy via the new processors, most pronounced for universal computability.

There are several directions for future work. Our chaining processors could be improved, e.g., by using unification instead of matching, thus defining a form of narrowing for our constrained DPs in the higher-order setting. Moreover, so far our implementation prohibits chaining a DP with itself to prevent non-termination of repeated applications of the chaining processors. We might loosen this restriction via appropriate heuristics to detect cases in which such self-chaining could be beneficial. In addition, we could investigate chaining not just for DPs, but also for rewrite rules. The integer mapping processor could be improved by lifting polynomial interpretations [43] for higher-order rewriting to the constrained setting of LCSTRSs. Another improvement would consist of moving Boolean expressions from the right-hand side of rewrite rules into their constraints. Techniques like the integer mapping processor or the subterm criterion, which establish weak or strict decrease between certain arguments of dependency pairs, could also be improved by combining them with the size-change termination principle [37]. Size-change termination has been integrated into the first-order DP framework [42, 5], and a natural next step would be to lift this integration to the higher-order DP framework for LCSTRSs, both for innermost and for full termination.

A different avenue could be to research to what extent the termination analysis techniques in this paper can be ported from innermost or call-by-value evaluation to arbitrary evaluation strategies, or to lazy evaluation, as used in Haskell. For the latter, we might consider an approximation of lazy evaluation via a higher-order form of context-sensitive rewriting [1, 38].

Finally, to go back to one of the main motivations of this work, we could devise translations from higher-order functional programming languages with call-by-value semantics (e.g., Scala, OCaml) to LCSTRSs. This would allow for applying the contributions of this paper to prove termination of programs written in these languages, a long-term goal of this line of research.

References

  • [1] B. Alarcón, R. Gutiérrez, and S. Lucas. Context-sensitive dependency pairs. IC, 208(8):922–968, 2010. doi:10.1016/J.IC.2010.03.003.
  • [2] T. Aoto and T. Yamada. Argument filterings and usable rules for simply typed dependency pairs. In S. Ghilardi and R. Sebastiani, editors, Proc. FroCoS, pages 117–132, 2009. doi:10.1007/978-3-642-04222-5_7.
  • [3] T. Arts and J. Giesl. Termination of term rewriting using dependency pairs. TCS, 236(1–2):133–178, 2000. doi:10.1016/S0304-3975(99)00207-8.
  • [4] D. Beyer, A. Cimatti, A. Griggio, M. E. Keremoglu, and R. Sebastiani. Software model checking via large-block encoding. In A. Biere and C. Pixley, editors, Proc. FMCAD, pages 25–32, 2009. doi:10.1109/FMCAD.2009.5351147.
  • [5] M. Codish, C. Fuhs, J. Giesl, and P. Schneider-Kamp. Lazy abstraction for size-change termination. In C. G. Fermüller and A. Voronkov, editors, Proc. LPAR (Yogyakarta), pages 217–232, 2010. doi:10.1007/978-3-642-16242-8_16.
  • [6] Community. Termination competition (TermCOMP). URL: https://termination-portal.org/wiki/Termination_Competition.
  • [7] Community. The termination problem database (TPDB). URL: https://github.com/TermCOMP/TPDB.
  • [8] L. de Moura and N. Bjørner. Z3: An efficient SMT solver. In C.R. Ramakrishnan and J. Rehof, editors, Proc. TACAS, pages 337–340, 2008. doi:10.1007/978-3-540-78800-3_24.
  • [9] N. Dershowitz. Hierarchical termination. In N. Dershowitz and N. Lindenstrauss, editors, Proc. CTRS, pages 89–105, 1995. doi:10.1007/3-540-60381-6_6.
  • [10] S. Falke and D. Kapur. A term rewriting approach to the automated termination analysis of imperative programs. In R. A. Schmidt, editor, Proc. CADE, pages 277–293, 2009. doi:10.1007/978-3-642-02959-2_22.
  • [11] S. Falke, D. Kapur, and C. Sinz. Termination analysis of C programs using compiler intermediate languages. In M. Schmidt-Schauß, editor, Proc. RTA, pages 41–50, 2011. doi:10.4230/LIPIcs.RTA.2011.41.
  • [12] C. Fuhs, J. Giesl, M. Plücker, P. Schneider-Kamp, and S. Falke. Proving termination of integer term rewriting. In R. Treinen, editor, Proc. RTA, pages 32–47, 2009. doi:10.1007/978-3-642-02348-4_3.
  • [13] C. Fuhs and C. Kop. A static higher-order dependency pair framework. In L. Caires, editor, Proc. ESOP, pages 752–782, 2019. doi:10.1007/978-3-030-17184-1_27.
  • [14] C. Fuhs, C. Kop, and N. Nishida. Verifying procedural programs via constrained rewriting induction. ACM TOCL, 18(2):14:1–14:50, 2017. doi:10.1145/3060143.
  • [15] J. Giesl, C. Aschermann, M. Brockschmidt, F. Emmes, F. Frohn, C. Fuhs, J. Hensel, C. Otto, M. Plücker, P. Schneider-Kamp, T. Ströder, S. Swiderski, and R. Thiemann. Analyzing program termination and complexity automatically with AProVE. JAR, 58(1):3–31, 2017. doi:10.1007/s10817-016-9388-y.
  • [16] J. Giesl, M. Raffelsieper, P. Schneider-Kamp, S. Swiderski, and R. Thiemann. Automated termination proofs for Haskell by term rewriting. ACM TOPLAS, 33(2):7:1–7:39, 2011. doi:10.1145/1890028.1890030.
  • [17] J. Giesl, T. Ströder, P. Schneider-Kamp, F. Emmes, and C. Fuhs. Symbolic evaluation graphs and term rewriting: a general methodology for analyzing logic programs. In A. King, editor, Proc. PPDP, pages 1–12, 2012. doi:10.1145/2370776.2370778.
  • [18] J. Giesl, R. Thiemann, and P. Schneider-Kamp. The dependency pair framework: combining techniques for automated termination proofs. In F. Baader and A. Voronkov, editors, Proc. LPAR, pages 301–331, 2005. doi:10.1007/978-3-540-32275-7_21.
  • [19] J. Giesl, R. Thiemann, P. Schneider-Kamp, and S. Falke. Mechanizing and improving dependency pairs. JAR, 37(3):155–203, 2006. doi:10.1007/s10817-006-9057-7.
  • [20] L. Guo, K. Hagens, C. Kop, and D. Vale. Higher-order constrained dependency pairs for (universal) computability. pre-publication Arxiv copy of [21] with additional appendix. doi:10.48550/arXiv.2406.19379.
  • [21] L. Guo, K. Hagens, C. Kop, and D. Vale. Higher-order constrained dependency pairs for (universal) computability. In R. Královič and A. Kučera, editors, Proc. MFCS, pages 57:1–57:15, 2024. doi:10.4230/LIPIcs.MFCS.2024.57.
  • [22] L. Guo and C. Kop. Higher-order LCTRSs and their termination. In S. Weirich, editor, Proc. ESOP, pages 331–357, 2024. doi:10.1007/978-3-031-57267-8_13.
  • [23] N. Hirokawa and A. Middeldorp. Automating the dependency pair method. IC, 199(1-2):172–199, 2005. doi:10.1016/J.IC.2004.10.004.
  • [24] N. Hirokawa and A. Middeldorp. Tyrolean Termination Tool: techniques and features. IC, 205(4):474–511, 2007. doi:10.1016/j.ic.2006.08.010.
  • [25] C. Kop. WANDA – a higher order termination tool (system description). In Z. M. Ariola, editor, Proc. FSCD, pages 36:1–36:19, 2020. doi:10.4230/LIPICS.FSCD.2020.36.
  • [26] C. Kop. Cutting a proof into bite-sized chunks: incrementally proving termination in higher-order term rewriting. In A. P. Felty, editor, Proc. FSCD, pages 1:1–1:17, 2022. doi:10.4230/LIPIcs.FSCD.2022.1.
  • [27] C. Kop et al. The Cora analyzer. URL: https://github.com/hezzel/cora.
  • [28] C. Kop et al. hezzel/cora: FSCD 2025. doi:10.5281/zenodo.15318964.
  • [29] C. Kop and N. Nishida. Term rewriting with logical constraints. In P. Fontaine, C. Ringeissen, and R. A. Schmidt, editors, Proc. FroCoS, pages 343–358, 2013. doi:10.1007/978-3-642-40885-4_24.
  • [30] C. Kop and F. van Raamsdonk. Dynamic dependency pairs for algebraic functional systems. LMCS, 8(2), 2012. doi:10.2168/LMCS-8(2:10)2012.
  • [31] M. R. K. Krishna Rao. Completeness of hierarchical combinations of term rewriting systems. In R. K. Shyamasundar, editor, Proc. FSTTCS, pages 125–138, 1993. doi:10.1007/3-540-57529-4_48.
  • [32] M. R. K. Krishna Rao. Simple termination of hierarchical combinations of term rewriting systems. In M. Hagiya and J. C. Mitchell, editors, Proc. TACS, pages 203–223, 1994. doi:10.1007/3-540-57887-0_97.
  • [33] M. R. K. Krishna Rao. Semi-completeness of hierarchical and super-hierarchical combinations of term rewriting systems. In P. D. Mosses, M. Nielsen, and M. I. Schwartzbach, editors, Proc. CAAP, pages 379–393, 1995. doi:10.1007/3-540-59293-8_208.
  • [34] K. Kusakari, Y. Isogai, M. Sakai, and F. Blanqui. Static dependency pair method based on strong computability for higher-order rewrite systems. IEICE Trans. Inf. Syst., E92.D(10):2007–2015, 2009. doi:10.1587/transinf.E92.D.2007.
  • [35] K. Kusakari and M. Sakai. Enhancing dependency pair method using strong computability in simply-typed term rewriting. AAECC, 18(5):407–431, 2007. doi:10.1007/s00200-007-0046-9.
  • [36] K. Kusakari and M. Sakai. Static dependency pair method for simply-typed term rewriting and related techniques. IEICE Trans. Inf. Syst., E92.D(2):235–247, 2009. doi:10.1587/transinf.E92.D.235.
  • [37] C. S. Lee, N. D. Jones, and A. M. Ben-Amram. The size-change principle for program termination. In C. Hankin and D. Schmidt, editors, Proc. POPL, pages 81–92, 2001. doi:10.1145/360204.360210.
  • [38] S. Lucas. Context-sensitive computations in functional and functional logic programs. JFLP, 1998(1), 1998. URL: http://danae.uni-muenster.de/lehre/kuchen/JFLP/articles/1998/A98-01/A98-01.html.
  • [39] C. Otto, M. Brockschmidt, C. von Essen, and J. Giesl. Automated termination analysis of Java bytecode by term rewriting. In C. Lynch, editor, Proc. RTA, pages 259–276, 2010. doi:10.4230/LIPIcs.RTA.2010.259.
  • [40] S. Suzuki, K. Kusakari, and F. Blanqui. Argument filterings and usable rules in higher-order rewrite systems. IPSJ Online Trans., 4:114–125, 2011. doi:10.2197/ipsjtrans.4.114.
  • [41] R. Thiemann. The DP framework for proving termination of term rewriting. PhD thesis, RWTH Aachen University, Germany, 2007. URL: http://darwin.bth.rwth-aachen.de/opus3/volltexte/2007/2066/.
  • [42] R. Thiemann and J. Giesl. The size-change principle and dependency pairs for termination of term rewriting. AAECC, 16(4):229–270, 2005. doi:10.1007/S00200-005-0179-7.
  • [43] J. van de Pol. Termination proofs for higher-order rewrite systems. In J. Heering, K. Meinke, B. Möller, and T. Nipkow, editors, Proc. HOA, pages 305–325, 1993. doi:10.1007/3-540-58233-9_14.
  • [44] F. van Raamsdonk. Translating logic programs into conditional rewriting systems. In L. Naish, editor, Proc. ICLP, pages 168–182, 1997. doi:10.7551/mitpress/4299.003.0018.
  • [45] H. Zantema. Termination of term rewriting by semantic labelling. FI, 24(1/2):89–105, 1995. doi:10.3233/FI-1995-24124.

Appendix A Full Proofs

A.1 Soundness for Section 5

For soundness of the graph, subterm criterion and integer mapping processors, we refer to Appendix A.2 in [20]; only minimal changes are needed. Below we address the rest.

Theorem 38.

Chaining processors are sound.

Proof of Theorem 38.

Given a DP problem (𝒫,), a defined symbol 𝖿 with the said properties and an infinite innermost (𝒫,)-chain (s0t0[φ0],σ0),(s1t1[φ1],σ1), where variables are renamed to avoid name collisions between any two of the SDPs and dom(σi)Var(si)Var(ti)Var(φi) for all i, we consider k>0 such that tk1=𝖿t1tn and sk=𝖿s1sn. By definition, tiσk1𝒬siσk for all i. Because sk1tk1[φk1] and sktk[φk] are chainable, there exists a substitution σ such that dom(σ)=i=1nVar(si), siσ=ti for all i and σ(x)T(ϑ,Var(φk1)) for all xdom(σ)Var(φk). Hence, siσσk1𝒬siσk for all i. Since si is a value for all i, σk1(σ(x))𝒬σk(x) for all xi=1nVar(si). Now we show that replacing (sk1tk1[φk1],σk1) and (sktk[φk],σk) by (sk1tkσ[φk1(φkσ)],σk1σk) yields an infinite innermost chain. First, it is routine to verify that σk1σk respects φk1(φkσ). Next, sk1(σk1σk)=sk1σk1 so it is in normal form. Last, tkσ(σk1σk)𝒬tkσk𝒬sk+1σk+1.

We present some auxiliary results for the two classes of DP processors based on usable rules in a unified way, regardless of whether an argument filtering is applied. When no filtering is applied, let regard(𝖿)={ 1,,n} for each 𝖿:A1AnB with B𝒮.

Definition 39.

The set 𝒰𝔞(t) of actually usable symbols in a term t is (1) {(𝖿,n)}iregard(𝖿){ 1,,n}𝒰𝔞(ti) if t=𝖿t1tn for 𝖿, t is not a ground theory term, and is not in normal form (with respect to 𝒬), or (2)  otherwise.

Lemma 40.

Given a constraint φ and a substitution σ such that σ(x) is in normal form for all x and is a theory value if xVar(φ): 𝒰𝔞(tσ)𝒰(t)[φ] for all t with 𝒰(t)[φ].

Proof of Lemma 40.

By induction on t. If t=xt1tn with x𝒱, then n=0 because 𝒰(t)[φ]. Hence, tσ=σ(x) is in normal form, and therefore 𝒰𝔞(tσ)=. Otherwise, t=𝖿t1tn for 𝖿. If tσ=𝖿(t1σ)(tnσ) is not a ground theory term, tT(ϑ,Var(φ)) because σ(x) is a theory value for all xVar(φ). So if 𝒰𝔞(tσ), 𝒰(t)[φ]={(𝖿,n)}iregard(𝖿){ 1,,n}𝒰(ti)[φ], and therefore 𝒰(ti)[φ] for each such i. By induction, 𝒰𝔞(tiσ)𝒰(ti)[φ]. Hence, 𝒰𝔞(tσ)𝒰(t)[φ].

Lemma 41.

Given a set 𝒫 of SDPs and a set of rules such that 𝒩(𝒬)𝒩() and 𝒰(𝒫,) is defined: for all terms t, t, if 𝒰𝔞(t)𝒰(𝒫,) and t𝒬t, 𝒰𝔞(t)𝒰(𝒫,).

Proof of Lemma 41.

By induction on t.

  1. (1)

    t=𝖿t1tn for 𝖿, and there exist a rewrite rule r[φ], substitution σ and number pn such that 𝖿t1tp=σ, t=(rσ)tp+1tn, σ(x) is in normal form for all x and σ respects φ. Since 𝒩(𝒬)𝒩(), t is not in 𝒬-normal form, so (𝖿,n)𝒰𝔞(t)𝒰(𝒫,), and therefore 𝒰(rxp+1xn)[φ]𝒰(𝒫,) where xp+1,,xn are fresh variables. Since 𝒰(𝒫,) is defined, 𝒰(𝒫,), and therefore 𝒰(rxp+1xn)[φ]. If p=n, due to Lemma 40, 𝒰𝔞(t)=𝒰𝔞(rσ)𝒰(r)[φ]𝒰(𝒫,). Otherwise, r=𝗀r1rq for 𝗀. Then 𝒰𝔞(t)=𝒰𝔞((rσ)tp+1tn){(𝗀,q+np)}{𝒰𝔞(riσ)1iq,iregard(𝗀)}{𝒰𝔞(tp+j)1jnp,q+jregard(𝗀)} and 𝒰(rxp+1xn)[φ]={(𝗀,q+np)}{𝒰(ri)[φ]1iq,iregard(𝗀)}. Since 𝒰(rxp+1xn)[φ], for each such i, 𝒰𝔞(riσ)𝒰(ri)[φ] due to Lemma 40. Since 𝒰(𝒫,) is defined, each p+jregard(𝖿), and therefore 𝒰𝔞(tp+j)𝒰𝔞(t). Hence, 𝒰𝔞(t)𝒰(rxp+1xn)[φ]𝒰𝔞(t)𝒰(𝒫,).

  2. (2)

    t=𝖿v1vn where 𝖿 is a calculation symbol and v1,,vn are theory values, and t has a base type. Then tκt and t is a theory value. Hence, 𝒰𝔞(t)=.

  3. (3)

    t=𝖿t1tn for 𝖿, and t=𝖿t1tk1tktk+1tn for some k with tk𝒬tk. If t is a ground theory term, so is t, hence 𝒰𝔞(t)=; so assume otherwise. If kregard(𝖿), 𝒰𝔞(t)𝒰𝔞(t)𝒰(𝒫,). If kregard(𝖿), 𝒰𝔞(tk)𝒰𝔞(t)𝒰(𝒫,). By induction, 𝒰𝔞(tk)𝒰(𝒫,). Then 𝒰𝔞(t)𝒰𝔞(t)𝒰𝔞(tk)𝒰(𝒫,).

  4. (4)

    t=xt1tn for x𝒱, and t=xt1tk1tktk+1tn; then 𝒰𝔞(t)=.

Theorem 42.

Usable-rules processors are sound.

Proof of Theorem 42.

Given a DP problem (𝒫,) such that 𝒩(𝒬)𝒩() and 𝒰(𝒫,) is defined, and an infinite innermost (𝒫,)-chain (s0t0[φ0],σ0),(s1t1[φ1],σ1),: for all i, since 𝒰(ti)[φi]𝒰(𝒫,), 𝒰(ti)[φi], and due to Lemma 40, 𝒰𝔞(tiσi)𝒰(ti)[φi]𝒰(𝒫,). Now due to Lemma 41, for all t such that tiσi𝒬t, 𝒰𝔞(t)𝒰(𝒫,), so any 𝒬-step from t is a 𝒬𝒰(𝒫,)-step, given the definition of 𝒰𝔞().

Below we let π denote π𝔱 – the argument filtering with respect to the Boolean 𝔱 – and define σπ for each substitution σ by letting σπ(x) be π(σ(x)).

Lemma 43.

Given a logical constraint φ and a substitution σ such that σ(x) is a theory value for all xVar(φ), πφ(t)σπ=π(tσ) for each pattern t such that all the variables in Var(t) whose type is a theory sort are also in Var(φ).

Proof of Lemma 43.

By induction on t. If t=xt1tn with x𝒱, then n=0 because t is a pattern. Hence, πφ(t)σπ=σπ(x)=π(σ(x))=π(tσ). Otherwise, t=𝖿t1tn for 𝖿. If t is in T(ϑ,Var(φ)) and has a base type, πφ(t)σπ=tσπ=tσ=π(tσ) because σ(x) is a theory value for all xVar(t) and π(v)=v for each theory value v. Otherwise, if regard(𝖿){ 1,,n}={i1,,ik} (with i1<<ik), πφ(t)σπ=𝖿n(πφ(ti1)σπ)(πφ(tik)σπ) and π(tσ)=𝖿nπ(ti1σ)π(tikσ). By induction, πφ(tij)σπ=π(tijσ) for all j{ 1,,k}.

Lemma 44.

Given a set 𝒫 of SDPs, a set of rewrite rules and a constrained relation such that 𝒰(𝒫,) is defined, φr for all r[φ]𝒰(𝒫,) and is covered by some reflexive, transitive and monotonic relation : if 𝒰(t)[φ]𝒰(𝒫,) and σ(x) is a theory value for all xVar(φ), πφ(t)σπκπ(tσ)κ.

Proof of Lemma 44.

By induction on t. If t=xt1tn with x𝒱 then n=0 because 𝒰(t)[φ]. Hence, πφ(t)σπ=σπ(x)=π(σ(x))=π(tσ). Otherwise, t=𝖿t1tn for 𝖿. If t is in T(ϑ,Var(φ)) and has a base type, πφ(t)σπ=tσπ=tσ=π(tσ) because each σ(x) is a theory value so π(σ(x))=σ(x). Otherwise, we have πφ(t)σπ=𝖿n(πφ(ti1)σπ)(πφ(tik)σπ) where regard(𝖿){ 1,,n}={i1,,ik} and i1<<ik. By induction, πφ(tij)σπκπ(tijσ)κ for all j{ 1,,k}, and therefore πφ(t)σπκ𝖿nπ(ti1σ)κπ(tikσ)κ. If tσ is a ground theory term with a base type, 𝖿nxi1xiky[y=𝖿x1xn]𝒰(𝒫,); because covers , 𝖿nπ(ti1σ)κπ(tikσ)κ=𝖿n(ti1σ)κ(tikσ)κ(tσ)κ=π(tσ)κ. Otherwise, we have π(tσ)=𝖿nπ(ti1σ)π(tikσ).

Lemma 45.

Given a set 𝒫 of SDPs, a set of rules and a constrained relation where (1) 𝒩(𝒬)𝒩(), (2) 𝒰(𝒫,) is defined, (3) for all r[φ], all xVar() whose type is a theory sort, xVar(φ), (4) φr for all r[φ]𝒰(𝒫,) and (5)  is covered by a reflexive, transitive, monotonic : if 𝒰𝔞(t)𝒰(𝒫,) and t𝒬t, π(t)κπ(t)κ.

Proof of Lemma 45.

By induction on t.

  1. (1)

    t is a base-type ground theory term; then so is t, and tκt. Hence, π(t)κ=π(t)κ.

  2. (2)

    t=𝖿t1tn for 𝖿, and there exist a number pn, substitution σ and rule r[φ] such that =𝖿1p, ti=iσ for all i{ 1,,p}, t=(rσ)tp+1tn, σ(x) is in normal form for all x and σ respects φ. Since 𝒩(𝒬)𝒩(), (𝖿,n)𝒰𝔞(t)𝒰(𝒫,), and therefore 𝒰(rxp+1xn)[φ]𝒰(𝒫,) and πφ(xp+1xn)πφ(rxp+1xn)[φ]𝒰(𝒫,) for xp+1,,xn fresh variables. We have π(t)=𝖿nπ(ti1)π(tik) where regard(𝖿){ 1,,n}={i1,,ik} and i1<<ilp<il+1<<ik. By Lemma 43, πφ(j)σπ=π(jσ)=π(tj) for all j{ 1,,l}. Since πφ(xj)([xiti]i=p+1n)π=π(tj) for all j{l+1,,k}, π(t)=πφ(xp+1xn)(σ[xiti]i=p+1n)π. Due to Lemma 44, πφ(rxp+1xn)(σ[xiti]i=p+1n)πκπ(t)κ. Because covers and (σ[xiti]i=p+1n)π respects φ, π(t)κπ(t)κ.

  3. (3)

    t=𝖿t1tn (𝖿) is not a base-type ground theory term, and there is m such that t=𝖿t1tm1tmtm+1tn and tm𝒬tm. Then π(t)=𝖿nπ(ti1)π(tik) where regard(𝖿){ 1,,n}={i1,,ik} and i1<<ik. Let ti be ti for all i{ 1,,n}{m}. By induction, π(tm)κπ(tm)κ, and therefore π(t)κ𝖿nπ(ti1)κπ(tik)κ. If t is a ground theory term that has a base type, since (𝖿,n)𝒰𝔞(t)𝒰(𝒫,), we have 𝖿nxi1xiky[y=𝖿x1xn]𝒰(𝒫,); because covers , 𝖿nπ(ti1)κπ(tik)κ=𝖿nti1κtikκtκ=π(t)κ. Otherwise, π(t)κ=𝖿nπ(ti1)κπ(tik)κ.

  4. (4)

    t=xt1tktn for x𝒱, and t=xt1tktn; then π(t)=μ(A)=π(t).

Theorem 46.

If the rewrite rules are preprocessed by Lemma 7, and all theory sorts are inextensible, then reduction pair processors with an argument filtering are sound.

Proof of Theorem 46.

Following Theorem 42, for all i and t such that tiσi𝒬t, 𝒰𝔞(t)𝒰(𝒫,). Due to Lemma 45, π(tiσi)κπ(si+1σi+1)κ for all i. For all i, if siti[φi]𝒫, due to Lemmas 43 and 44, π(siσi)κ=πφi(si)σiπκπφi(ti)σiπκπ(tiσi)κ; if siti[φi]𝒫𝒫, similarly π(siσi)κπ(tiσi)κ. Since is well-founded, an infinite innermost (𝒫,)-chain leads to an infinite innermost (𝒫𝒫,)-chain.

A.2 The Proofs of Theorems 14 and 36

For the properties of -computability, see Appendix A in the extended version of [13]. The following proofs are largely based on Appendix A.3 in [20]; here the novelty lies on the innermostness of chains. Note that undefined function symbols are -computable (see [20]).

Lemma 47.

Assume given an AFP system 0 with sort ordering , an extension 1 of 0 and a sort ordering which extends over sorts in 01. For each defined symbol 𝖿:A1AmB in 0 where B is a sort, if 𝖿s1sm is not -computable in 01 with but si is for all i, then there exist an SDP 𝖿s1sm𝗀t1tn[φ]SDP(0), a substitution σ and a natural number p such that (1) sii01siσ and siσ is in normal form for all ip, (2) si is a fresh variable (si does not occur in sj for any ji) and σ(si)=si for all i>p, (3) σ respects φ, and (4) (𝗀t1tn)σ=𝗀(t1σ)(tnσ) is not -computable in 01 with but uσ is for each proper subterm u of 𝗀t1tn.

Proof.

If the only reducts of 𝖿s1sm were values or 𝖿s1sm with sii01si for all i then 𝖿s1sm would be computable. Hence, there exist 𝖿s1spr[φ]0 (𝖿 cannot be defined in 1) and σ such that sii01siσ and siσ is in normal form for all ip, and σ respects φ; (rσ)sp+1sm is thus a reduct of 𝖿s1sm. At least one such reduct is uncomputable. Let (rσ)sp+1sm be uncomputable, and therefore so is rσ. Also all σ(x) are computable, since these are accessible subterms of some si, since 0 is AFP.

Take a minimal subterm at1tq of r such that tσ is uncomputable. By minimality, each tiσ is computable. Hence, a cannot be a variable, value or constructor, as then σ(x) would be computable, implying computability of tσ. Hence, a is a defined symbol 𝗀.

We have 𝖿s1spxp+1xm𝗀t1tqyq+1yn[φ]SDP(0). Because tσ is uncomputable, there exist computable terms tq+1,,tn such that (tσ)tq+1tn=𝗀(t1σ)(tqσ)tq+1tn is uncomputable. Let σ be such that σ(xi)=si for all i>p, σ(yi)=ti for all i>q, and σ(z)=σ(z) for any other z. Let si denote xi for i>p and ti denote yi for i>q; then 𝖿s1sm𝗀t1tn[φ], σ and p satisfy all requirements.

Corollary 48.

Given an AFP system 0 with sort ordering , an extension 1 of 0 and a sort ordering which extends over sorts in 01, for each defined symbol 𝖿:A1AmB in 0 (B a sort), if 𝖿s1sm is not -computable in 01 with but each si is, there exists an infinite innermost (SDP(0),01)-chain (𝖿s1smt[φ],σ),

Proof.

Repeatedly applying Lemma 47 (on 𝖿s1sm, then on 𝗀(t1σ)(tnσ) and so on) we get three infinite sequences: one of SDPs in SDP(0) (𝖿isi,1si,mi𝖿i+1ti,1ti,ni[φi])i where 𝖿0=𝖿, one of substitutions (σi)i and one of natural numbers (pi)i. Since i01 is exactly 0101, combining the SDPs and the substitutions almost gives us an infinite innermost (SDP(0),01)-chain, except that si,jσi may not be in normal form if j>pi.

We define (σi)i so that, together with the SDPs, we obtain an infinite chain. For all i,j with pi<jmi, si,j is a fresh variable and σi(si,j) is -computable. Let σi(x) be σi(x) for x𝒱{si,pi+1,,si,mi}. To define σi(si,j) for j>pi, let k0 be j and for l0, if kl exists and kl>pi+l, let kl+1 be the index (if any) with si+l,kl=ti+l,kl+1. There are two options:

  1. (1)

    If kl>pi+l for all l such that kl is defined, regardless of whether the sequence is finite, σi+l(si+l,kl)=σi+l(ti+l,kl+1)=σi+l+1(si+l+1,kl+1) for all l such that kl+1 is defined. Let u be an arbitrary normal form of σi(si,j), and let σi+l(si+l,kl) be u for all l where kl is defined.

  2. (2)

    Otherwise, the sequence (kl)l is finite, and kqpi+q where kq is the last in the sequence. Then si+q,kqσi+q is in normal form. Let σi+l(si+l,kl) be si+q,kqσi+q for all l<q.

Hence, we have built an infinite innermost (SDP(0),01)-chain.

Theorem 14. [Restated, see original statement.]

An AFP system is innermost (and therefore call-by-value) terminating if there exists no infinite innermost (SDP(),)-chain.

Proof.

Towards a contradiction, assume that is not innermost terminating. Then there is an uncomputable (not -computable) term u. Take a minimal subterm s of u that is uncomputable; then u=𝖿s1sk where 𝖿 is defined and each si is computable. Let 𝖿:A1AmB for B𝒮. Since s=𝖿s1sk is uncomputable, there exist computable sk+1,,sm with ssk+1sm=𝖿s1sm uncomputable. By Corollary 48 (with 1=), there is an infinite innermost (SDP(),)-chain, giving the required contradiction.

Theorem 36. [Restated, see original statement.]

An accessible function passing system 0 with sort ordering is universally computable if there exists no infinite innermost (SDP(0),01)-chain for any extension 1 of 0 and extension of to sorts in 01.

Proof.

Towards a contradiction, assume that 0 is not universally computable. There exist an extension 1 of 0, sort ordering which extends over sorts in 01 and term u of 0 that is not -computable in 01 with . We consider -computability in 01. Take a minimal uncomputable subterm s of u; then s must take the form 𝖿s1sk with 𝖿 a defined symbol in 0 and each si computable. Let 𝖿:A1AmB. Because s is uncomputable, there exist computable sk+1,,sm of 01 with ssk+1sm=𝖿s1sm uncomputable. Corollary 48 gives the required chain to obtain a contradiction.