
Rewriting Techniques for Analysing Termination and Complexity Bounds of �afe Programs� Salvador Lucas Ricardo Pe˜na Sistemas Inform´aticos y Computaci´on Sistemas Inform´aticos y Computaci´on Universidad Polit´ecnica de Valencia Universidad Complutense de Madrid Camino de Vera s/n, 46022 Prof. ! "arc´ıaSantesmases s/n, 2$040 [email protected] ricardo%sip.ucm.es Abstract. �afe is a &rst-order ea(er functional lan(ua(e )it* facilities for pro(rammer-controlled destruction and copyin( of data structures and is intended for compile-time analysis of memory consumption In �afe, *eap and stac+ memory consumption depends on t*e len(t* of recursive calls c*ains ,nsurin( termination of �afe pro(rams -or of par- ticular function calls) is t*erefore essential to implement t*ese features. /urt*ermore, 0ein( a0le to (ive 0ounds to the c*ain len(t* required 0y suc* terminatin( calls 0ecomes essential in computin( space 0ounds In t*is paper, )e investi(ate *o) to analyze termination of �afe pro' (rams 0y usin( standard term rewritin( tec*niques, i.e., 0y transform- in( �afe pro(rams into term rewritin( systems )*ose termination can 0e automatically analysed 0y means of existin( tools /urt*ermore, )e investi(ate *o) to use proofs of termination )*ic* com0ine the depen' dency pairs approac* )ith polynomial interpretations to o0tain suita0le 0ounds to t*e len(t* of c*ains of recursive calls in �afe pro(rams Keywords: 4ermination, 4erm 5ewritin( Systems, Space complexity 1 Introduction �afe [21, 18] is a first-order eager functional language with facilities for program- mer controlled destruction and cop!ing of data structures, intended for compile time anal!sis of emor! consumption. In �afe, the allocation and deallocation of compiler-defined memor! regions for data structures are associated with func- tion application. So, heap me or! consumption depends $oth on the num$er of recursive calls and on the length of calls chains" In order to compute space $ounds for the heap it is essential to compute $ounds to these figures and, in turn, to previousl! ensure termination of such functions. In this paper we investigate how to use rewriting techniques for proving ter- mination of �afe programs and, at the same time, giving appropriate $ounds to the num$er of recursive calls as a first step to compute space $ounds. In par- ticular, we introduce a transformation for proving termination of �afe programs $! translating the into &erm Rewriting Systems 'TRS(" � Salvador Lucas )as partially supported 0y the ,U -/,7,5. and t*e Spanish M,C (rant TI8 2009-6$0:;'C02'02 5icardo Pe<na )as partially supported 0y t*e Madrid 5egion Government under (rant S'050=/4IC/0409 (P5>M,S?S. )* Both termination and complexit! $ounds of programs have $een investigated in the abstract framewor- of &er Rewriting S!stems [3, 20]" / suitable wa! to prove termination of programs written in declarative programming languages li-e Has-ell or 1aude is translating them into 'variants of( ter rewriting systems and then using techniques and tools for proving termination of rewriting. See [9, 10] for recent proposals of concrete procedures and tools which appl! to the aforementioned programming languages" Polynomial interpretations have $een extensivel! investigated as suitable tools to address different issues in ter rewriting [3]" 4or instance, the limits of polynomial interpretations regarding their abilit! to prove termination of rewrite systems were first investigated in [12] $! considering the derivational complexity of pol!nomiall! terminating &RSs, i.e", the upper $ound of the lengths of arbi- trary '$ut finite( derivations issued from a given ter 'of sizen( in a terminating TRS" Hofbauer has shown that the derivational complexit! of a terminating &RS can $e $etter appro,i ated if pol!nomial interpretations over the reals 'instead of the more traditional polynomial interpretations over the naturals) are used to prove termination of the &RS [11]" Complexit! analysis of first order functional programs 'or TRSs( has also $een successfull! addressed $! using polynomial interpretations [4–6]" The ai of these papers is to classif! TRSs in different 'time or space( complexit! classes according to the 'least( -ind of pol!nomial interpretation which is 'wea-l!( com- patible with the TRS" Recent approaches [5] com$ine the use of path orderings [8] to ensure $oth termination together with suitable pol!nomial interpreta- tions for giving $ounds to the length of the rewrite se%uences 'which are -nown finite due to the ter ination proof(" Polynomials which are used in this set- ting are weakly monotone, i.e", ifx≥y thenP'. , x, . .(≥P'...,y,...(" This is in contrast with the use of pol!nomials in proofs of polynomial ter- mination [15], where monotony is re%uired 'i.e., wheneverx>y, we have P'...,x,...(>P'...,y,...((" However, when usin g polynomials in proofs of termination using the dependenc! pair approach [1], monoton! is not longer necessar! and we can use weakl! monotone pol!nomials again [7, 17]" The real advantage is that, we can now avoid the use of path orderings to ensure termi- nation; with the same pol!nomial interpretation we can $oth prove termination and, as we show in this paper, obtain suitable complexit! $ounds" 4urthermore, since the limits of using path orderings to prove termination of rewrite s!stems are well-known, and they obviously restrict the variet! of programs they can deal with, we are able to improve on the current techni%ues. 2 Preliminaries / $inar! relationR on a setA is terminating 'or well-founded( if th ere is no infinite se%uencea 1 R a2 R a3 ···" Throughout the paper,X denotes a count- able set of variables andF denotes a signature, i. e., a set of function s! $ols {f, g, . .}, each having a fixed arit! given $! a mapping ar;F→N" The set of terms built fromF andX isT'F,X (" Positions p, q, . are represented $! chains of positive natural nu $ers used to address su$terms oft" Positions are ordered $! the standard prefi, ordering≤" The set of positions o f a ter t is )) Pos't(" The subter at posi tionp oft is denoted ast| p andt[s] p is the term t with the subterm at positionp replaced $!s" / context is a termC[ ] with a <hole= 'formall!, a fresh constant s! $ol(" / rewrite rule is an ordered pair 'l,r(, writtenl→r, with l,r∈T'F,X(,l �∈ X and Var'r(⊆ Var'l(" / TRS is a pairR>'F,R( whereR is a set of rewrite rule s" ?iven a TRSR, a ter t∈T'F,X ( rewrites tos 'at positionp∈Pos't((, writtent→ R s, if there is a positionp∈Pos't(, a su$stitutionσ, and a rulel→r inR such thatt| p >σ'l( ands>t[σ'r)] p" The ter t| p is called a redex oft" / ter t∈T'F,X( inner- i most rewrites tos, writtent →R s ift→ R s at positionp andt| p contains no i redex" / TRSR is 'innermost( termina ting if→ R 'resp. →R( is terminating. / conditional, oriented TRS '6TRS(, has rules of the for l→r⇐C, whereC>s 1 →t 1, . , sk →t k is called an oriented condition" ?iven a CTRS R, we letR u $e the set of rulesR u >{l→r|l→r⇐C ∈R}" / CTRS which satisfies Var'r(⊆ Var'l(∪ Var'C( for every conditional rule is called a 3-CTRS" #t is deterministic if the variables of the right-hand sidet i of ever! conditions i →t i ofC are introduced $efore they are used in the left-hand side sj of a subsequent conditions j →t j" / deterministic 3-CTRSR is s!ntactically deter inistic if, for ever! rulel→r⇐s 1 →t 1, . , sk →t k inR every termt i is a constructor term or a ground normal form with respect toR u" 3 The �afe language �afe was introduced as a research platfor to investigate analyses related to sharing of data structures and to memor! consumption. Currently it is equipped with a type syste guaranteeing that, in spite of the emor! destruction facili- ties of the language, all well-typed programs will $e free of dangling pointers at runtime" 1ore information can $e found at [21, 18] and [19]" There are two versions of �afe; full-Safe, in which programmers are supposed to write their programs, and Core-Safe 'the compiler transformed version of full-Safe(, in which all program analyses are defined. 4ull-�afe syntax is close to Has-ell=s. The ain differences are that �afe is eager and first-order. �afe admits two basic t!pes 'booleans and integers(, alge- $raic datat!pes (introduced $! the usual data declarations(, and the function definitions $! eans of conditional equations with the usual facilitites for pat- tern matching, use of let and case expressions, and where clauses" No recursion is possible inside let e,pressions and where clauses and no local function def- inition can $e given" /dditionall!, the progra er can specify a destructive pattern atching operation $! using s! $ol A after the pattern" The intended meaning is the destruction of the cell associated with the constructor sy $ol, thus allowing its reuse later" / �afe program consists of a sequence of 'possibl! recursive) function definitions together with a main expression. The erge-sort program of 4igure 1 uses a constant heap space to implement the sorting of the list" This is a consequence of the destructive constant-space versions splitD and mergeD of the funtions which respectivel! split a list into two pieces and erge two sorted lists. The t!pes shown in the program are inferred $! the compiler" / sy $ol A in a t!pe signature indicates that the corresponding )9 splitD@@∀a, ρ.Int→AaBC%ρ→ρ→-AaB%ρ,AaB%ρ.%ρ splitD0 xsC D-AB,xsC.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages15 Page
-
File Size-