Uncurrying for Termination

Similar documents
Lecture Notes in Computer Science, Proceedings of the 16th Internationa RTA 2005, Nara, Japan, April 19-21,

Tsukuba Termination Tool

Automated Termination Proofs with AProVE

Proving Termination with (Boolean) Satisfaction

Functional Logic Programming: From Theory to Curry

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

Intersections and Unions of Session Types

Consistency and Set Intersection

Higher-Order Recursive Path Orderings à la carte

Handout 9: Imperative Programs and State

Constrained Term Rewriting tool

VMTL A Modular Termination Laboratory

Analysing the Complexity of Functional Programs: Higher-Order Meets First-Order

Rewriting. Andreas Rümpel Faculty of Computer Science Technische Universität Dresden Dresden, Germany.

9.5 Equivalence Relations

Evaluation Strategies for Functional Logic Programming

Automated Termination Proofs for Haskell by Term Rewriting

Type Systems COMP 311 Rice University Houston, Texas

Module 11. Directed Graphs. Contents

3 No-Wait Job Shops with Variable Processing Times

Tyrolean Complexity Tool: Features and Usage

1 Problem Description

A Fast Arc Consistency Algorithm for n-ary Constraints

Unifying and extending hybrid tractable classes of CSPs

Termination of Isabelle Functions via Termination of Rewriting

Constrained Types and their Expressiveness

Safe Stratified Datalog With Integer Order Does not Have Syntax

SAT and Termination. Nao Hirokawa. Japan Advanced Institute of Science and Technology. SAT and Termination 1/41

Scan Scheduling Specification and Analysis

Discrete mathematics

Term Algebras with Length Function and Bounded Quantifier Elimination

Multi-paradigm Declarative Languages

CS 512, Spring 2017: Take-Home End-of-Term Examination

Network Topology and Equilibrium Existence in Weighted Network Congestion Games

Math 190: Quotient Topology Supplement

NP-Hardness. We start by defining types of problem, and then move on to defining the polynomial-time reductions.

On Reconciling Data Exchange, Data Integration, and Peer Data Management

1.3. Conditional expressions To express case distinctions like

Propagate the Right Thing: How Preferences Can Speed-Up Constraint Solving

Database Systems. Basics of the Relational Data Model

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Designing Views to Answer Queries under Set, Bag,and BagSet Semantics

Slothrop: Knuth-Bendix Completion with a Modern Termination Checker

The Inverse of a Schema Mapping

Reasoning About Set Comprehensions

CS422 - Programming Language Design

Reduced branching-factor algorithms for constraint satisfaction problems

Discrete Optimization. Lecture Notes 2

Proving Theorems with Athena

For several classes of TRSs, innermost normalisation already suces for termination [Gra95, Gra96]. Moreover, several modularity results exist for inne

Chapter 2 The Language PCF

On Meaning Preservation of a Calculus of Records

CSC 501 Semantics of Programming Languages

COMP 382: Reasoning about algorithms

Finding Strongly Connected Components

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

type classes & locales

An Annotated Language

On Universal Cycles of Labeled Graphs

Automated Termination and Confluence Analysis of Rewrite System

Negations in Refinement Type Systems

Type Inference with Recursive Type Equations

Section 6.3: Further Rules for Counting Sets

3.7 Denotational Semantics

Comparing Cubes. Steffen van Bakel Luigi Liquori Simona Ronchi della Rocca Paweł Urzyczyn

Algebra of Sets (Mathematics & Logic A)

Lecture 22 Tuesday, April 10

Topological properties of convex sets

Infinite Derivations as Failures

CS40-S13: Functional Completeness

An Implementation of the Language Lambda Prolog Organized around Higher-Order Pattern Unification

V Advanced Data Structures

XI International PhD Workshop OWD 2009, October Fuzzy Sets as Metasets

A Simplified Abstract Syntax for the Dataflow Algebra. A. J. Cowling

DETECTING NON-TERMINATION IN CONSTRAINT HANDLING RULES

AXIOMS FOR THE INTEGERS

Improving the Efficiency of Non-Deterministic Computations

Data-Driven Induction of Recursive Functions from Input/Output-Examples

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections p.

Bound Consistency for Binary Length-Lex Set Constraints

However, this is not always true! For example, this fails if both A and B are closed and unbounded (find an example).

Circuit versus CNF Reasoning for Equivalence Checking

PCP and Hardness of Approximation

A more efficient algorithm for perfect sorting by reversals

TERMINATION ANALYSIS FOR FUNCTIONAL PROGRAMS

Formal Languages and Automata

Estimation of Parallel Complexity with Rewriting Techniques

Propositional Logic. Part I

Topology and Topological Spaces

V Advanced Data Structures

Lecture Notes on Real-world SMT

Applied Algorithm Design Lecture 3

Cantor-Schröder-Bernstein Theorem, Part 1

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

International Journal of Mathematical Archive-4(2), 2013, Available online through ISSN

The Geodesic Integral on Medial Graphs

MA651 Topology. Lecture 4. Topological spaces 2

Data-Driven Induction of Recursive Functions from Input/Output-Examples

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

Integration and Optimization of Rule-based Constraint Solvers

Transcription:

Uncurrying for Termination Nao Hirokawa and Aart Middeldorp Institute of Computer Science University of Innsbruck 6020 Innsbruck, Austria {nao.hirokawa,aart.middeldorp}@uibk.ac.at Abstract. In this note we present a transformation from untyped applicative term rewrite systems to functional term rewrite systems that preserves termination. Our transformation can handle head variables in right-hand sides of rewrite rules. 1 Introduction We are concerned with proving termination of applicative rewrite systems. The signature of an applicative term rewrite system (ATRS) consists of variables, constants, and a single binary function symbol called application and denoted by the infix and left-associative symbol. In examples we often use juxtaposition instead of. Every ordinary first-order rewrite system (TRS) can be transformed into an applicative rewrite system by currying. Proving termination of ATRSs is challenging because simplification orders are not effective as is the only function symbol of non-zero arity. Moreover, the dependency pair method is of little help as is the only defined non-constant symbol. Definition 1. Let F be a (functional) signature. The currying system C(F) consists of the rewrite rules f i+1 (x 1,...,x i, y) f i (x 1,..., x i ) y for every n- ary function symbol f F and every 0 i < n. Here f n = f and, for every 0 i < n, f i is a fresh function symbol of arity i. The currying system C(F) is confluent and terminating. Hence every term t has a unique normal form t C(F). For instance, f(a, b) is transformed into f a b. Definition 2. Let R be a TRS over the signature F. The curried system R C(F) is the ATRS consisting of the rules l C(F) r C(F) for every l r R. The signature of R C(F) contains the application symbol and a constant f 0 for every function symbol f F. In the following we write R C for R C(F) whenever F can be inferred from the context or is irrelevant. Moreover, we write f for f 0. This research is supported by FWF (Austrian Science Fund) project P18763.

Example 3. The TRS R 0 + y y 0 y 0 s(x) + y s(x + y) s(x) y (x y) + y is transformed into the ATRS R C + 0 y y 0 y 0 + (s x) y s (+ x y) (s x) y + ( x y) y Every rewrite sequence in R can be transformed into a sequence in R C, but the reverse does not hold. For instance, with respect to the above example, the rewrite step + (s ( 0)) 0 s (+ ( 0) 0) in R C does not correspond to a rewrite step in R. Nevertheless, termination of R implies termination of R C, a result due to Kennaway et al. [6]. Theorem 4. A TRS R is terminating if and only if R C is terminating. 2 Uncurrying As an immediate consequence we get the following transformation method for proving termination of ATRSs. Corollary 5. An ATRS R is terminating if and only if there exists a terminating TRS S such that S C = R (modulo renaming). In [5] this method is called transformation A. As can be seen from the following example, the method does not handle partially applied terms and, more seriously, head variables. Hence the method is of limited applicability as it cannot cope with the higher-order aspects modeled by ATRSs. Example 6. Consider the ATRS R (from [2]) 1: id x x 4: map f nil nil 2: add 0 id 5: map f (: x y) : (f x) (map f y) 3: add (s x) y s (add x y) Rules 1 and 4 are readily translated into functional form: 1: id 1 (x) x 4: map 2 (f, nil) nil However, we cannot find functional forms for rules 2 and 3 because the arity of add is 1 in rule 2 and 2 in rule 3. Because of the presence of the head variable f in the subterm f x, there is no functional term t such that t C = : (f x) (map f y). Hence rule 5 cannot be transformed.

For simply typed rewrite systems Aoto and Yamada [1, 2] introduced transformation techniques that use type information. Head variables are removed by instantiating them with template terms of the appropriate type. In [3] they adapted the dependency pair method to deal with simply typed ATRSs. In this note we present a different solution for the untyped case. At the end of this section we relate our approach to the one of [1, 2]. Definition 7. Let F be an applicative signature. The uncurrying system U(F) consists of the rewrite rules f i (x 1,...,x i ) y f i+1 (x 1,..., x i, y) for every constant f F and every i 0. Here f 0 = f and, for every i > 0, f i is a fresh function symbol of arity i. The uncurrying system U(F) is confluent and terminating. Hence every term t has a unique normal form t U(F). Definition 8. Let R be an ATRS over the signature F. The uncurried system R U(F) is the TRS consisting of the rules l U(F) r U(F) for every l r R. In the following we write R U for R U(F) whenever F can be inferred from the context or is irrelevant. Example 9. The ATRS R of Example 6 is transformed into R U : 1: id 1 (x) x 4: map 2 (f, nil) nil 2: add 1 (0) id 5: map 2 (f, : 2 (x, y)) : 2 (f x, map 2 (f, y)) 3: add 2 (s 1 (x), y) s 1 (add 2 (x, y)) The TRS R U is an obvious candidate for S in Corollary 5. However, as can be seen from the following example, the rules of R U are not enough to simulate an arbitrary rewrite sequence in R. Example 10. The non-terminating ATRS R = {id x x, f x id f x} is transformed into the terminating TRS R U = {id 1 (x) x, f 1 (x) id 2 (f, x)}. In the above example we need rules that connect id 2 and id 1 as well as f 1 and f. The natural idea is now to add sufficiently many rules of F U. Definition 11. Let R be an ATRS over a signature F. The applicative arity aa(f) of a constant f F is defined as the maximum n such that f t 1 t n is a subterm in the left- or right-hand side of a rule in R. This notion is extended to terms as follows: { aa(f) if t is a constant f aa(t) = aa(t 1 ) 1 if t = t 1 t 2 Note that aa(t) is undefined if the head symbol of t is a variable. We define U(R, F) as the union of R U and the subset of F U consisting of all rules f i (x 1,..., x i ) y f i+1 (x 1,...,x i, y) with 0 i < aa(f). We say that R is left head variable free if aa(t) is defined for every subterm t of a left-hand side of a rule in R.

In the following we write U(R) for U(R, F) whenever F can be inferred from the context or is irrelevant. Example 12. Consider the ATRS R in Example 10. We have aa(id) = 2 and aa(f) = 1. The TRS U(R) consists of the following rules id 1 (x) x id x id 1 (x) f x f 1 (x) f 1 (x) id 2 (f, x) id 1 (x) y id 2 (x, y) and is easily shown to be terminating. As the above example shows, we do not yet have a sound transformation. The ATRS R admits the cycle f x id f x f x. In U(R) we have f 1 (x) id 2 (f, x) but the term id 2 (f, x) does not rewrite to f 1 (x). It would if the rule id x y x y would be present in R. This inspires the following definition. Definition 13. Let R be a left head variable free ATRS. The η-saturated ATRS R η is the smallest extension of R such that l x r x R η whenever l r R η and aa(l) > 0. Note that R = Rη, so the rules added during η-saturation do not affect the termination behaviour of R. We can now state our main result. Theorem 14. A left head variable free ATRS R is terminating if U(R η ) is terminating. We skip the proof due to lack of space. Instead we revisit Example 6. Example 15. Consider again the ATRS R of Example 6. Proving termination of the transformed TRS U(R η ) id 1 (x) x : x : 1 (x) id x id 1 (x) add 1 (0) id : 1 (x) y : 2 (x, y) add x add 1 (x) add 2 (0, y) id 1 (y) add 1 (x) y add 2 (x, y) add 2 (s 1 (x), y) s 1 (add 2 (x, y)) map 2 (f, nil) nil s x s 1 (x) map x map 1 (x) map 2 (f, : 2 (x, y)) : 2 (f x, map 2 (f, y)) map 1 (x) y map 2 (x, y) is a piece of cake with the dependency pair method (recursive SCC algorithm with three applications of the subterm criterion). The next example shows that left-head variable freeness condition cannot be weakened to the well-definedness of aa(l) for every left-hand side l. Example 16. Consider the non-terminating ATRS R f (x a) f (g b) g b h a

The transformed TRS U(R η ) f 1 (x a) f 1 (g 1 (b)) g 1 (b) h 1 (a) f x f 1 (x) g x g 1 (x) is terminating because its rules are oriented from left to right by the lexicographic path order with precedence g 1 f 1 h 1 a b. Note that aa(f (x a)) = 0. The uncurrying transformation is not always useful. Example 17. Consider the one rule TRS R = {C x y z u x z (x y z u)} from [4]. The termination of R is proved by the lexicographic path order with empty precedence. The transformed TRS U(R η ) consists of C 4 (x, y, z, u) x z (x y z u) C x C 1 (x) C 2 (x, y) z C 3 (x, y, z) C 1 (x) y C 2 (x, y) C 3 (x, y, z) w C 4 (x, y, z, w) None of the tools that participated in the 2005 termination competition is able to prove the termination of U(R η ). At the end of this section we briefly discuss the work of Aoto and Yamada [1, 2] for proving termination of simply typed ATRSs by transformation techniques. After performing η-saturation, they eliminate head variables by instantiating them with template terms of the appropriate type. In a final step, the resulting ATRS is translated into functional form. Example 18. Consider again the ATRS R of Example 6. Suppose we adopt the following type declarations: 0: int, s: int int, nil: list, (:): int list list, id: int int, add: int int int, and map: (int int) list list. The head variable f in the right-hand side : (id x) (map f y) has type int int. There are three template terms of this type: s, id, and add z. Instantiating f by these three terms in R η produces the ATRS R : id x x map f nil nil add 0 id map s (: x y) : (s x) (map s y) add 0 y id y map id (: x y) : (id x) (map id y) add (s x) y s (add x y) map (add z) (: x y) : (add z x) (map (add z) y) The TRS R U is terminating because its rules are oriented from left to right by the lexicographic path order. According to the main result of [2], the simply typed ATRS R is terminating, too. The advantage of the simply typed approach is that the uncurrying rules are not necessary because the application symbol has been eliminated from R U. This typically results in simpler termination proofs. It is worthwhile to investigate whether a version of head variable instantiation can be developed for the untyped case. We would like to stress that with the simply typed approach one obtains termination only for those terms which are simply typed. Our approach, when it works, provides termination for all terms, irrespective of any typing discipline.

3 Mirroring In the final part of this note we describe a trivial mirroring technique for TRSs. This technique can be used to eliminate some of the head variables in an ATRS. Definition 19. Let t be a term. The term t M is defined as follows: t M = t if t is a variable and t M = f(t M n,..., tm 1 ) if t = f(t 1,..., t n ). Moreover, if R is a TRS then R M = {l M r M l r R}. We obviously have t R u if and only if t M R M u M. This gives the following result. Theorem 20. A TRS R is terminating if and only if R M is terminating. Example 21. Consider the one-rule ATRS R x (a a a) a (a a) x While R has a head variable in its left-hand side, the mirrored version R M a (a a) x x (a a a) is left head variable free. The transformed TRS U((R M ) η ) a 2 (a 1 (a), x) x a 2 (a, a) a x a 1 (x) a 1 (x) y a 2 (x, y) is easily proved terminating with dependency pairs and a linear polynomial interpretation. Needless to say, mirroring may also introduce head variables in ATRSs. We anticipate that partial mirroring will be more effective in practice. References 1. T. Aoto and T. Yamada. Termination of simply typed term rewriting by translation and labelling. In Proc. 14th RTA, volume 2706 of LNCS, pages 380 394, 2003. 2. T. Aoto and T. Yamada. Termination of simply-typed applicative term rewriting systems. In Proc. 2nd HOR, Technical Report AIB-2004-03, RWTH Aachen, pages 61 65, 2004. 3. T. Aoto and T. Yamada. Dependency pairs for simply typed term rewriting. In Proc. 16th RTA, volume 2706 of LNCS, pages 120 134, 2005. 4. N. Dershowitz. 33 Examples of termination. In French Spring School of Theoretical Computer Science, volume 909 of LNCS, pages 16 26, 1995. 5. J. Giesl, R. Thiemann, and P. Schneider-Kamp. Proving and disproving termination of higher-order functions. In Proc. 5th FroCoS, volume 3717 of LNAI, pages 216 231, 2005. 6. R. Kennaway, J.W. Klop, M.R. Sleep, and F.J. de Vries. Comparing curried and uncurried rewriting. Journal of Symbolic Computation, 21(1):15 39, 1996.