0 Least Upper Bounds on the Size of Confluence and Church-Rosser
Total Page:16
File Type:pdf, Size:1020Kb
0 Least Upper Bounds on the Size of Confluence and Church-Rosser Diagrams in Term Rewriting and λ-Calculus1 JEROEN KETEMA, Imperial College London JAKOB GRUE SIMONSEN, University of Copenhagen We study confluence and the Church-Rosser property in term rewriting and λ-calculus with explicit bounds on term sizes and reduction lengths. Given a system R, we are interested in the lengths of the reductions in the smallest valleys t !∗ s0 ∗ t0 expressed as a function: ∗ ∗ 0 — for confluence a function vsR(m; n) where the valleys are for peaks t s ! t with s of size at most m and the reductions of maximum length n, and ∗ 0 — for the Church-Rosser property a function cvsR(m; n) where the valleys are for conversions t $ t with t and t0 of size at most m and the conversion of maximum length n. For confluent term rewriting systems (TRSs), we prove that vsR is a total computable function, and for linear such systems that cvsR is a total computable function. Conversely, we show that every total computable function is the lower bound on the functions vsR(m; n) and cvsR(m; n) for some TRS R: In particular, we show that for every total computable function ' : N −! N there is a TRS R with a single term s such that vsR(jsj; n) ≥ '(n) and cvsR(n; n) ≥ '(n) for all n. For orthogonal TRSs R we prove that there is a constant k such that (a) vsR(m; n) is bounded from above by a function exponential in k and (b) cvsR(m; n) is bounded from above by a function in the fourth level of the Grzegorczyk hierarchy. Similarly, for λ-calculus, we show that vsR(m; n) is bounded from above by a function in the fourth level of the Grzegorczyk hierarchy. Categories and Subject Descriptors: F.4.1 [Mathematical Logic and Formal Languages]: Mathematical Logic—Lambda calculus and related systems General Terms: Theory Additional Key Words and Phrases: Term rewriting, lambda calculus, Church-Rosser property, confluence, upper bounds ACM Reference Format: Ketema, J., Simonsen, J.G. 2012. Least Upper Bounds on the Size of Confluence and Church-Rosser Dia- grams in Term Rewriting and λ-Calculus. ACM Trans. Comput. Logic 0, 0, Article 0 (December 2012), 28 pages. DOI:http://dx.doi.org/10.1145/0000000.0000000 1. INTRODUCTION Confluence is the property of some rewriting systems that any peak t ∗ s !∗ t0 has a corresponding valley t !∗ s0 ∗ t0. The valley and the term s0 are said to complete the diagram. 1This work is an extended and revised version of the conference paper [Ketema and Simonsen 2010]. Authors’ addresses: J. Ketema, Department of Computing, Imperial College London, 180 Queen’s Gate, London SW7 2BZ, United Kingdom; Jakob Grue Simonsen, Department of Computer Science, University of Copenhagen (DIKU), Njalsgade 126–128, 2300 Copenhagen S, Denmark Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies show this notice on the first page or initial screen of a display along with the full citation. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is per- mitted. To copy otherwise, to republish, to post on servers, to redistribute to lists, or to use any component of this work in other works requires prior specific permission and/or a fee. Permissions may be requested from Publications Dept., ACM, Inc., 2 Penn Plaza, Suite 701, New York, NY 10121-0701 USA, fax +1 (212) 869-0481, or [email protected]. c 2012 ACM 1529-3785/2012/12-ART0 $15.00 DOI:http://dx.doi.org/10.1145/0000000.0000000 ACM Transactions on Computational Logic, Vol. 0, No. 0, Article 0, Publication date: December 2012. 0:2 J. Ketema and J.G. Simonsen a ≤n ≤n ≤n b c b o / c ≤l ≤l ≤l ≤l Ð Ð d d (a) Confluence (b) Church-Rosser property Fig. 1. Confluence and the Church-Rosser property of a rewrite system R with bounds on the lengths of the reductions. This paper is concerned with finding least upper bounds of l as a function of n. A rewriting system is confluent iff it has the so-called Church-Rosser property; the property that any conversion t $∗ t0 has a corresponding valley t !∗ s0 ∗ t0. As the two notions are equivalent, the terms ‘confluence’ and ‘Church-Rosser property’ are often used interchangeably in the literature; to the authors’ knowledge, all contem- porary research in rewriting systems considers confluence, rather than the classical Church-Rosser property, probably due to the fact that the former seems better suited to the range of standard proof methods available. In functional programming, the Church-Rosser property ensures that different ways of evaluating a program always yield the same result (modulo non-termination): The result of running a program will be independent of the evaluation order or reduction strategy. In logic, if the rewrite system induced by the derivation relation of a deductive system has the Church-Rosser property and is strongly normalizing, the system will be consistent: No statement can both hold and not hold. While the Church-Rosser property has been shown to hold for a variety of rewrite systems, there has, to the authors’ knowledge, never been an investigation into the number of reduction steps in a valley that completes a peak or a conversion of a given size (see Figure 1). Succinctly: The question “How large is the valley as a function of the peak or conversion?” has apparently not been asked before. We find the above question to be intrinsically interesting from a theoretical point of view as Church-Rosser-type results are ubiquitous. However, we also believe the practical implications in mainstream functional programming to be limited: Standard functional languages like ML and HASKELL employ a fixed evaluation strategy such as call-by-value or call-by-need, and there seems to be little interest in performing optimizations by switching strategies (modulo non-termination). However, for more specialized languages, like declarative DSLs where the evaluation order may not be fixed, there may be practical implications: If, for small peaks, the size of the smallest corresponding valley is so large that a term completing the Church-Rosser diagram cannot be computed using realistic resources, then it matters very much which reduc- tion strategy is employed: Choosing the ‘wrong’ evaluation strategy (say, call-by-value) and performing just a few steps of a computation could result in a very long reduction before a result is reached—better to backtrack to the original term and try another strategy. In this paper, we perform the first fundamental study of valley sizes for systems with the Church-Rosser property; specifically we study how the size of a peak or con- version affects the size of the smallest corresponding valley. We consider three very general settings: that of (arbitrary) first-order term rewriting systems, of orthogonal term rewriting systems (roughly corresponding to first-order functional programs that have no fixed evaluation order), and of untyped λ-calculus. We believe that these three ACM Transactions on Computational Logic, Vol. 0, No. 0, Article 0, Publication date: December 2012. Least Upper Bounds on the Size of Confluence and Church-Rosser Diagrams 0:3 Table I. The bounds derived for the valley sizes and their tightness Confluence (vs) Church-Rosser (cvs) Bound Tight? Bound Tight? TRSs Unknown (Section 4) Computable Yes Linear TRSs (Theorem 4.2) (Theorem 4.12) Computable Yes (Section 4) (Theorem 4.5) (Theorem 4.14) Orthogonal TRSs Exponential Yes E 4 Unknown (Section 5) (Theorem 5.5) (Remark 5.6) (Theorem 5.9) λ-calculus E 4 Unknown Unknown (Section 6) (Theorem 6.5) areas cover most of the non-specialized areas where the Church-Rosser property oc- curs. The most significant area omitted is that of general higher-order rewrite systems (including higher-order functional programs and logics with bound variables)—we ex- pect general upper bounds in that case to be very difficult to derive, as is foreshadowed by the difficulties we encounter in our treatment of λ-calculus in Section 6. Valley sizes are measured by two functions, vs : N2 −! N for confluence, and cvs : N2 −! N for the Church-Rosser property. Roughly, vs(m; n) is the least number of steps required to complete a valley for a peak starting from a term of size at most m and with reductions of length at most n. Similarly, cvs(m; n) is the least number of steps required to complete a valley corresponding to a conversion involving at most n steps between two terms of size at most m. Our results on upper bounds are summarized in Table I. In the table, the exponential upper bound for orthogonal TRSs depends on a constant dependent on the specific rewrite system and is thus tractable in some cases. 1.1. Related Work For all the kinds of rewriting considered in this paper, the question of valley sizes in confluence and Church-Rosser diagrams does not appear to have been investigated be- fore. However, in research on the ‘efficiency’ in λ-calculus, some related phenomena have been under scrutiny. Most pertinently, investigations have been performed con- cerning upper bounds on the length of developments by de Vrijer [1985] and concerning standard reductions by Xi [1999]. In typed systems, lower bounds for normalizing re- ductions have been studied by Statman [1979], upper bounds are treated Schwichten- berg [1982; 1991] and Beckmann [2001], and lower and upper bounds are discussed by Springintveld [1993].