Automated Termination Proofs for Logic Programs by Term Rewriting
There are two kinds of approaches for termination analysis of logic programs: "transformational" and "direct" ones. Direct approaches prove termination directly on the basis of the logic program. Transformational approaches transform a logic program …
Authors: P. Schneider-Kamp, J. Giesl, A. Serebrenik
Automated T ermination Pro ofs for Logic Programs b y T erm Rewriting Peter Schneider-Kamp, R WTH Aachen, Germany J¨ urgen Giesl, RWTH Aachen, Germany Alexander Sereb renik, T U Eindhoven, The Neth e rla n ds Ren´ e Thie m a nn, Universit y o f Innsbruck, Austria There are t wo kinds of approac hes for termination analysis of logic programs: “transfor m ationa l” and “direct” ones. Direct approac hes prov e termination directly on the basis of the logic program. T ransformational approac hes transform a l ogic program into a term rewrite system (TRS) and then analyze termination of the resulting TRS instead. Thus, transf ormational approach es make all metho ds previously developed for TRSs av ailable f or logic programs as w ell. How ever, the applicability of most existing tr ansf ormations i s quite restricted, as they can only b e used for certain sub cl ass es of logic programs. (Most of them are restricted to wel l- mo de d programs.) In this pap er we improv e these transformations suc h that they b ecome applicable for any de finite logic program. T o simulate th e b eha vior of l ogic programs b y TRSs, we slightly modify the notion of rewriting b y p ermitting infinite terms. W e show that our transformation r esults in TR Ss whic h are indeed suitable for automate d termi nation analysis. In con trast to most other metho ds f or termination of logic programs, our tec hnique is also sound for logic programming without o c cur che ck , whic h is t ypically used in practice . W e implemented ou r approac h in th e termination pro ve r AProVE and successfully ev aluated it on a large collection of examples. Categories and Sub ject Descriptors: F. 3. 1 [ Log ic and Meanings of Programs ]: Specifying and V erif ying and Reasoning ab out Programs— Mecha nic al v e rific ation ; D.1.6 [ Progr a mming T ec hniques ]: Logic Programming; I.2.2 [ Ar tificial Intelligence ]: Automatic Programming— Au tomatic analysis of algorithms ; I.2. 3 [ Arti ficial In telligence ]: Deduction and Theorem Pr o v- ing— L o gic pr o gr amming General T erms: Languages, Theory , V erification Additional Key W ords and Phrases: logic programming, termination analysis, term rewri ting, dependency pairs Supported by the Deutsche F orsch ungsgsmeinsc haft DFG under gran t GI 274/5-2. Authors’ addresses: Pe ter Sc hneider-Kamp, J ¨ urgen Giesl, LuFG Informatik 2, R WTH Aachen, Ahornstr. 55, 52074 Aac hen, German y , { psk,giesl } @ informatik .rwth-aachen.de Alexander Serebrenik, Dept. of M athe matics and Computer Science, TU Eindhov en, P .O. Box 513, 5600 M B Eindhov en, The Netherlands, a.serebrenik @tue.nl Ren ´ e Thiemann, Institute of Computer Science, Universit y of Innsbruc k, T echnik er str. 21a, 6020 Innsbruc k, Austria, rene.thiemann@ uibk.ac.a t . Most of the work was carried out while R. Thie- mann was at the LuFG Informatik 2, R WTH Aache n. Pe rmissi on to mak e digital/hard cop y of all or part of this material wi thou t fee for p ersonal or classroom use prov ided that the copies ar e not made or dis tributed for profit or commercial adv anta ge, the ACM cop yright/ server notice, the title of the publication, and its date appear, and notice i s given that copying is by p ermission of the ACM, Inc. T o cop y otherwise, to republish, to p ost on servers, or to r edistribute to lists r equires prior sp ecific p ermission and/or a fee. c 20YY ACM 1529-3785/YY/00-0001 $5.00 ACM T ransactions on Computati onal Logic, V ol. V, No. N, 20 YY, Pa ges 1–49. 2 · P . Schn eider-Kamp, J. Giesl, A. Serebrenik, R. Thiemann 1. INTRODUCTION T ermination of lo g ic progr ams is w idely studied. Mos t automated techn iques try to prov e u niversal termination of definite logic prog rams, i.e ., one tries to show that all deriv ations o f a lo gic pr ogram are finite w.r .t. the left-to-r igh t selection rule. Both “dir ect” and “ transformational” approa ches hav e bee n pr opos e d in the lit- erature (see, e.g., [De Sc hreye and Deco rte 1994 ] for an overview and [Br uy noog he et al. 2 0 07; Co dish et a l. 20 05; Co dish et a l. 20 0 6; De Schreye and Serebrenik 2002 ; Lago on et al. 2003; Mesnard and Rugg ieri 2 003; Mesnard and Serebrenik 200 7; Nguyen and De Schreye 2 005; 2 007; Nguyen et al. 200 8; Ser ebrenik and De Schreye 2005a ; Smaus 200 4] f or more r ecen t w ork on “direc t” approaches). “T ransfor- mational” a pproaches hav e be en developed in [Aguzzi and Mo digliani 1 9 93; Arts and Zantema 1995 ; Ch to urou a nd Rusinowitch 1993 ; Ganzinger and W aldmann 1993; Kris hna Rao et al. 19 98; Marchiori 19 94; 19 9 6; v an Ra amsdonk 1 997] and a co mparison of these a pproaches is given in [Ohlebusch 2001 ]. Moreov e r, similar transformatio nal appr oach es a lso exis t for other programming language s (e.g., see [Giesl et al. 2006 ] for an approach to prove termination of Ha s k ell -prog rams via a tr ansformation to ter m rewriting). Moreov er, there is a lso work in pro gress to develop s uc h approa c hes for imper ativ e programs . In o rder to be success ful for ter mination analysis of lo gic progr ams, tr a nsforma- tional metho ds (I) should b e appli c able for a c lass of lo gic prog r ams as large a s p ossible and (II) s hould pro duce TRSs whose ter mination is e asy t o analyze automatic al ly . Concerning (I), the ab ov e existing transforma tions can only be used for certain sub- classes of logic progr a ms. M ore precisely , a ll approa c hes except [Marchiori 1994 ; 1996] a re r estricted to wel l-mo de d prog rams. The transfor mations of [Marchiori 1994; 1996] als o consider the classes of simply wel l- t yp e d and safely t yp e d pro grams. How ever in contrast to all previo us trans fo rmations, we present a new trans forma- tion which is applicable for any (definite) lo gic prog ram. Like mo st appro ac hes for termination of logic progra ms, we restr ict our selv es to prog rams without cut and negation. While there ar e trans fo rmational approa c hes which g o b eyond defi- nite prog rams [Mar c hiori 1996], it is not clear how to transfor m non-definite logic progra ms into TRSs that are suitable for automate d termination a nalysis, cf. (I I). Concerning (I I), o ne needs an implementation and an empirical ev alua tio n to find o ut whether terminatio n of the transfor med TRSs can indeed be verified au- tomatically for a large class o f e x amples. Unfortunately , to our knowledge there is only a single other ter mination to ol av ailable which implements a transfor ma tional approach. This to ol T ALP [Ohlebusch et al. 200 0] is based on the transformations of [Arts and Zantema 19 95; Chtourou and Rusinowitc h 1993 ; Ganzinger and W ald- mann 1993] which are shown to b e eq ually p o werful in [Ohlebusch 20 01]. So these transformatio ns ar e indeed suitable for automated ter mination analysis, but co n- sequently , T ALP o nly accepts well-mo de d logic prog rams. This is in contrast to our approach which we implemented in our ter mina tion prov er AProVE [Giesl et al. 2006]. O ur exp eriments on large co llections of examples in Section 7 show that our transformatio n indeed pro duces TRSs that ar e suitable for a utomated termina tio n analysis and that AProVE is c ur ren tly among the most p ow erful termination provers AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm R ewri ting · 3 for lo gic progr ams. T o illustra te the starting p oin t for our res earch, we br iefly rev iew re la ted work on connec ting termination a nalysis of log ic pro g rams and term r ewrite sy stems: in Section 1.1 we recapitulate the c lassical tr ansformation of [Arts a nd Zantema 1995; C htourou and Rusinowitc h 1 993; Ganzinger and W a ldma nn 1 993; Ohlebusch 2001] and in Sec tio n 1.2 we discuss the appro ac h of adapting TRS-techniques to the log ic progr amming setting (which can b e se e n as an alternative to our appr o ac h of trans forming logic pr ograms to TRSs). Then in Section 1.3 we give an overview on the structure of the rema inder of the pap er. 1.1 The Classi cal T ransfor mation Our transformation is inspired by the tra nsformation of [Arts and Zantema 1995 ; Cht ourou and Rusinowitch 199 3; Ga nzinger a nd W aldmann 19 93; Ohlebusch 2 001]. In this classical transformation, each a rgumen t p osition of each predicate is either determined to b e an input or an output p osition by a mo ding function m . So for every predicate symbol p of arity n and ev ery 1 ≤ i ≤ n , we hav e m ( p, i ) ∈ { in , out } . Thu s, m ( p , i ) states whether the i -th argument of p is an input ( in ) or an output ( out ) a rgumen t. As mentioned, the mo ding must be s uc h that the logic prog ram is wel l mo de d [Apt and Etalle 1993 ]. W ell-mo dedness guar an tees that each atom selected by the left-to- right selection rule is “sufficiently” instantiated during a n y de r iv ation with a query that is gr o und o n all input p ositions. Mor e precisely , a prog ram is well mo ded iff for a n y of its clauses H :– B 1 , . . . , B k with k ≥ 0, we hav e (a) V out ( H ) ⊆ V in ( H ) ∪ V out ( B 1 ) ∪ . . . ∪ V out ( B k ) a nd (b) V in ( B i ) ⊆ V in ( H ) ∪ V out ( B 1 ) ∪ . . . ∪ V out ( B i − 1 ) for all 1 ≤ i ≤ k V in ( B ) and V out ( B ) are the v aria ble s in terms on B ’s input a nd output po sitions. Example 1. 1. Co nsider the following v a riant of a small example from [Ohlebusch 2001]. p ( X, X ) . p ( f ( X ) , g ( Y )) :– p ( f ( X ) , f ( Z )) , p ( Z, g ( Y )) . Let m b e a mo ding with m ( p , 1) = in and m ( p , 2) = out . Then the progra m is well mo ded: This is obvious for the first clause. F or the second cla use, (a) holds since the output v a riable Y of the head is also an o utput v a riable of the sec o nd b o dy atom. Similarly , (b) ho lds since the input v ariable X of the first b o dy atom is also an input v ariable of the hea d, a nd the input v ariable Z o f the second b o dy a tom is also an output v aria ble of the first b o dy ato m. In the classic al transfor mation from logic pro grams to TRSs, tw o new function symbols p in and p out are int ro duced for each predicate p . W e wr ite “ p ( ~ s, ~ t )” to denote that ~ s and ~ t a re the sequences of terms o n p ’s in- and output po sitions. • F or ea c h fact p ( ~ s, ~ t ), the TRS co n tains the rule p in ( ~ s ) → p out ( ~ t ). • F or each clause c of the form p ( ~ s, ~ t ) :– p 1 ( ~ s 1 , ~ t 1 ) , . . . , p k ( ~ s k , ~ t k ), the r esulting TRS AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 4 · P . Schn eider-Kamp, J. Giesl, A. Serebrenik, R. Thiemann contains the following rules: p in ( ~ s ) → u c, 1 ( p 1 in ( ~ s 1 ) , V ( ~ s )) u c, 1 ( p 1 out ( ~ t 1 ) , V ( ~ s )) → u c, 2 ( p 2 in ( ~ s 2 ) , V ( ~ s ) ∪ V ( ~ t 1 )) . . . u c,k ( p k out ( ~ t k ) , V ( ~ s ) ∪ V ( ~ t 1 ) ∪ . . . ∪ V ( ~ t k − 1 )) → p out ( ~ t ) Here, V ( ~ s ) are the v aria bles o ccurring in ~ s . Moreover, if V ( ~ s ) = { x 1 , . . . , x n } , then “ u c, 1 ( p 1 in ( ~ s 1 ) , V ( ~ s ))” abbrevia tes the term u c, 1 ( p 1 in ( ~ s 1 ) , x 1 , . . . , x n ), etc. If the resulting TRS is terminating, then the orig ina l logic program terminates for any quer y with ground terms o n a ll input po sitions of the pr edicates, cf. [Ohlebusch 2001]. How ever, the conv erse do es not hold. Example 1. 2. F or the pro gram of Example 1.1 , the transformatio n results in the following TRS R . p in ( X ) → p out ( X ) p in ( f ( X )) → u 1 ( p in ( f ( X )) , X ) u 1 ( p out ( f ( Z )) , X ) → u 2 ( p in ( Z ) , X , Z ) u 2 ( p out ( g ( Y )) , X , Z ) → p out ( g ( Y )) The orig inal logic progr am is terminating for any query p ( t 1 , t 2 ) wher e t 1 is a g round term. How ever, the ab ov e TRS is not ter minating: p in ( f ( X )) → R u 1 ( p in ( f ( X )) , X ) → R u 1 ( u 1 ( p in ( f ( X )) , X ) , X ) → R . . . In the lo gic progr a m, after resolving with the second clause, one obtains a query starting with p ( f ( . . . ) , f ( . . . )) . Since p ’s o utput argument f ( . . . ) is already pa rtly instantiated, the sec o nd clause ca nnot b e applied a g ain for this atom. How ev er, this infor mation is neglected in the transla ted TRS. Here, one only rega rds the input arg ument of p in order to determine whether a rule can b e applied. Note that many cur ren t to ols for termination pro ofs of log ic progr ams like cT I [Me s nard and Bagna ra 20 05], T ALP [Ohlebusch e t al. 200 0], T ermiL o g [Lindens trauss et al. 1997], a nd T erminWeb [Co dish a nd T ab o c h 1999] fail on Exa mple 1.1. So this exa mple alr eady illustra tes a drawback of the cla ssical transfo r mation: there are several terminating well-mo ded logic progra ms which are transformed in to non-terminating TRSs. In such cas es, one fails in proving the termination of the logic pro gram. Even worse, most of the ex is ting transforma tions are no t applica ble for lo gic progr ams that are not well mo ded. 1 Example 1. 3. W e mo dify Example 1.1 by replacing g ( Y ) with g ( W ) in the b ody of the seco nd cla use: p ( X , X ) . p ( f ( X ) , g ( Y )) :– p ( f ( X ) , f ( Z )) , p ( Z , g ( W )) . 1 Example 1.3 is neither we ll mo ded nor si mply well typed nor saf el y typed (using the t ypes “ A ny ” and “ Gr ound ”) as required by the transformations of [Aguzzi and M odigliani 1993; Ar ts and Zant ema 1995; Chtourou and Rusino witc h 1993; Ganzinger and W aldmann 1993; Kr ishna Rao et al. 1998; Marchiori 1994; 1996; v an Raamsdonk 1997]. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm R ewri ting · 5 Still, all quer ie s p ( t 1 , t 2 ) terminate if t 1 is ground. But this pro gram is not well mo ded, as the second clause v iolates Condition (a): V out ( p ( f ( X ) , g ( Y ))) = { Y } 6⊆ V in ( p ( f ( X ) , g ( Y ))) ∪ V out ( p ( f ( X ) , f ( Z ))) ∪ V out ( p ( Z, g ( W ))) = { X , Z, W } . T rans- forming the progra m as b efore yields a TRS with the rule u 2 ( p out ( g ( W )) , X , Z ) → p out ( g ( Y )) . So non-well-moded pr ograms r esult in rules with v aria bles like Y in the right- but no t in the left-ha nd side. Such rules are usually forbidden in term rewriting and they do no t terminate, since Y may b e instantiated a r bitrarily . Example 1. 4. A natural non-well-moded exa mple is the a p pend -pr ogram with the cla uses app end ([ ] , M , M ) . app end ([ X | L ] , M , [ X | N ]) :– app end ( L , M , N ) . and the mo ding m ( append , 1) = i n and m ( append , 2) = m ( ap p end , 3) = out , i.e., one only co ns iders app end ’s first a rgumen t a s input. Due to the first claus e app end ([ ] , M , M ) , this progra m is not well mo ded although all queries of the for m app end ( t 1 , t 2 , t 3 ) a re terminating if t 1 is ground. 1.2 T erm Rewriting T echni ques for T ermination o f Logic Programs Recently , several authors tackled the problem of applying termination techniques from ter m re writing for (po s sibly no n-w ell-mo ded) logic progra ms. A framework for in tegrating orders from ter m rewriting int o dir e ct termination appro ac hes for logic progra ms is discussed in [De Schreye and Serebr enik 2002 ]. 2 How ever, the automation of this framew ork is no n-trivial in ge ne r al. As an instance of this framework, the automatic applica tion of p olynomial interpretations (well-kno wn in term r ewriting) to termination a na lysis of logic progra ms is inv estigated in [Nguyen and De Schreye 2 0 05; 2007]. Moreover, [Nguyen et al. 20 0 8] extend this work further by a lso adapting a bas ic version of the dep endency p air appr o ach [Arts and Giesl 2000] fro m TRSs to the logic prog ramming setting. This provides additional evidence tha t techniques develope d for term rewriting can succes sfully b e applied to terminatio n analys is of logic pr ograms. Instead of integrating ea c h terminatio n technique from term re wr iting separ ately , in the current pap er we wan t to make all these techniques av ailable at once. There- fore, unlike [De Sc hreye and Serebre nik 200 2; Nguyen a nd De Schreye 200 5; 20 07; Nguyen et al. 2 008], we cho ose a tra nsformational approach. Our goa l is a metho d which (A) handles pr ograms like Example 1.1 where clas sical transfor ma tions like the one of Section 1.1 fail, (B) handles non-well-mo ded progr ams like Ex ample 1.3 wher e most curr e n t trans- formational techniques are not even a pplica ble, (C) allows the successful aut omate d applicatio n of p ow e r ful techniques from r ewrit- ing for logic progr a ms like Ex a mple 1.1 and 1.3 where current to ols based on 2 But in contrast to [De Schrey e and Serebrenik 2002], transformational approac hes l i k e the one presen ted in this pap er can also apply more recen t termination tec hniques from term r ewriting for termination of logic programs (e.g., r efine d v ar ian ts of the dep endency p air method like [Giesl et al. 2005; Giesl et al. 2006; Hi rok aw a and Middeldorp 2005], semantic lab el ling [Zan tema 1995], matchb ounds [Geser et al. 2004], etc.). AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 6 · P . Schn eider-Kamp, J. Giesl, A. Serebrenik, R. Thiemann direct approa c hes fail. F or larger and more realis tic examples we refer to the exp erimen ts in Section 7. 1.3 Structure of the P ap er After pr esen ting req uired preliminaries in Section 2, in Sec tio n 3 we modify the transformatio n from log ic pr ograms to TRSs to achiev e (A) and (B). So restrictio ns like well-modednes s, simple well-t ypednes s , or safe typedness a re no longer required. Our ne w tr ansformation results in TRSs where the no tio n of “rewriting” has to be sligh tly mo dified: we reg ard a restric ted for m of infinitary rewr iting, called infinitary c onstructor r ewriting . The rea son is that logic progr a ms use unific ation , whereas TRSs use matching . T o illustr ate this difference, co nsider the log ic pro gram p ( s ( X )) :– p ( X ) which do es not ter minate for the query p ( X ): Unifying the quer y p ( X ) with the head of the v ar iable-renamed r ule p ( s ( X 1 )) :– p ( X 1 ) yields the new quer y p ( X 1 ). After- wards, unifying the new query p ( X 1 ) with the head of the v ariable-re na med rule p ( s ( X 2 )) :– p ( X 2 ) yie lds the new quer y p ( X 2 ), etc. In contrast, the related TRS p ( s ( X )) → p ( X ) terminates for all finite terms. When a pplying the r ule to some subterm t , one has to match the left-hand side ℓ of the rule aga ins t t . F or example, when applying the rule to the term p ( s ( s ( Y ))), one would use the matcher that instantiates X with s ( Y ). Th us, p ( s ( s ( Y ))) would b e rewritten to the instantiated r igh t-hand side p ( s ( Y )). Hence, one o ccurrence of the symbol s is eliminated in every rewr ite step. This implies that rewr iting will a lw ays terminate. So in contrast to unification (wher e one s e arches for a substitution θ with tθ = ℓ θ ), here we only use matching (i.e., w e search for a substitution θ with t = ℓθ , but we do not instantiate the term t that is b eing r ewritten). How ever, the infinite deriv a tion of the logic pro gram ab ov e c orresp onds to an infinite reductio n of the TRS ab ov e with the infinite term p ( s ( s ( . . . ))) containing infinitely ma n y nested s -sy mbo ls. So to sim ulate unification b y matching, we hav e to regar d TRSs where the v aria bles in r e write rules may be ins tan tiated by infinite constructor terms. It turns out that this for m of r e writing also allows us to a nalyze the ter mination b eha vior of logic pro gramming with infinite terms, i.e., of lo gic progra mming without oc c ur chec k. Section 4 shows that the existing ter mination techniques for TRSs can easily b e adapted in o r der to prov e termination of infinitary constructor rewriting. F o r a full automation of the approach, one has to trans form the set of queries that has to b e analy z ed for the logic progr am to a corr esponding set of terms that has to be analyzed for the transformed TRS. This set of terms is characterized by a s o - called ar gument filter and we present heuristics to find a suitable a rgumen t filter in Section 5. Section 6 gives a formal pro of that our new transfor mation a nd our approach to automated ter mina tion analysis are strictly mo re powerful than the classical ones of Section 1 .1. W e present and discuss an extensive ex p erimental ev aluatio n of o ur r e s ults in Sec tio n 7 which shows that Goal (C) is achiev ed as well. In other words, the implementation of our appr oach can indeed comp ete with mo dern to ols for dir e c t termination a nalysis of logic progra ms and it succeeds for many pr o grams wher e these too ls fail. Finally , we conclude in Section 8 . Preliminary versions of parts of this pap er app eared in [Schneider-Kamp et al. 2007]. How ever, the present a r ticle extends [Schneider-Kamp e t al. 2007 ] consider- AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm R ewri ting · 7 ably (in particula r , by the re s ults of the Sec tio ns 5 and 6). Section 6 contains a new formal compa rison with the exis ting classica l trans formational approach to termi- nation of log ic prog rams and pr oves formally that our approach is more p ow e r ful. The new contributions of Section 5 improv e the p ow er of our metho d substantially as ca n b e seen in our new exp eriments in Section 7. Moreover, in contrast to [Schn eider-Ka mp et al. 2007], this ar ticle c o n tains the full pr oofs of all results and a discuss ion on the limitations of o ur approa c h in Section 7.2. 2. PRELIMINARIE S ON LOGIC PR OGRAMMING AND R EWRITING W e start with intro ducing the basics on (pos sibly infinite) ter ms and atoms. Then we pr esen t the required notions on logic progr amming a nd on term r ewriting in Sections 2 .1 and 2.2, res pectively . A signatur e is a pair (Σ , ∆) wher e Σ and ∆ are finite sets of function a nd predicate symbols. E ac h f ∈ Σ ∪ ∆ has a n arity n ≥ 0 and w e often write f /n instead of f . W e a lw ays assume that Σ contains at leas t one constant f / 0. This is not a restriction, since enriching the signa tur e by a fresh constant would not change the termination b ehavior. Definition 2.1 (Infi nite T erms and Atoms) . A term ov e r Σ is a tree whe r e every leaf no de is lab elled with a v ariable X ∈ V or with f / 0 ∈ Σ a nd every inner no de with n children ( n > 0) is lab elled with so me f /n ∈ Σ. W e wr ite f ( t 1 , . . . , t n ) for the term with ro ot f a nd direct subtrees t 1 , . . . , t n . A term t is ca lled finite if all paths in the tree t are finite, other wise it is infinite . A term is r ational if it o nly contains finitely many different subterms. The sets of a ll finite terms, all rationa l terms, and a ll (p ossibly infinite) terms over Σ are denoted by T (Σ , V ), T r at (Σ , V ), and T ∞ (Σ , V ), res p ectively . If ~ t is the sequence t 1 , . . . , t n , then ~ t ∈ ~ T ∞ (Σ , V ) means that t i ∈ T ∞ (Σ , V ) for all i . ~ T (Σ , V ) is defined analog ously . F o r a term t , let V ( t ) b e the set of all v ariables o ccurring in t . A p osition p os ∈ N ∗ in a (po ssibly infinite) term t a ddresses a subter m t | p os of t . W e denote the e mpty word (and thereby the top p osition) by ε . The ter m t [ s ] p os results from replacing the subterm t | p os at p osition p os in t by the term s . So fo r p os = ε we have t | ε = t and t [ s ] ε = s . Otherwise p os = i p os ′ for s ome i ∈ N and t = f ( t 1 , . . . , t n ). Then we have t | p os = t | i p os ′ = t i | p os ′ and t [ s ] p os = t [ s ] i p os ′ = f ( t 1 , . . . , t i [ s ] p os ′ . . . , t n ). An atom ov er (Σ , ∆) is a tree p ( t 1 , . . . , t n ), wher e p /n ∈ ∆ and t 1 , . . . , t n ∈ T ∞ (Σ , V ). A ∞ (Σ , ∆ , V ) is the set o f atoms and A r at (Σ , ∆ , V ) (and A (Σ , ∆ , V ), resp.) are the atoms p ( t 1 , . . . , t n ) where t i ∈ T r at (Σ , V ) (and t i ∈ T (Σ , V ), r esp.) for a ll i . W e write A (Σ , ∆) and T (Σ) instead of A (Σ , ∆ , ∅ ) and T (Σ , ∅ ). 2.1 Logic Pro g ramming A clause c is a formula H :– B 1 , . . . , B k with k ≥ 0 a nd H , B i ∈ A (Σ , ∆ , V ). H is c ’s he ad and B 1 , . . . , B k is c ’s b o dy . A finite set of cla uses P is a definite lo gic pr o gr am . A clause with empty b ody is a fact and a clause with empt y head is a query . W e usually o mit “ :– ” in queries and just write “ B 1 , . . . , B k ”. The empty query is denoted ✷ . In quer ies, we a ls o admit rational instead of finite ato ms B 1 , . . . , B k . Since we a r e also interested in logic progr amming without o ccur chec k w e consider infinite substitutions θ : V → T ∞ (Σ , V ). Her e, we allow θ ( X ) 6 = X for infinitely many X ∈ V . Instead of θ ( X ) we o ften write X θ . If θ is a v a riable r enaming AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 8 · P . Schn eider-Kamp, J. Giesl, A. Serebrenik, R. Thiemann (i.e., a one-to-one co rresp ondence on V ), then tθ is a variant of t , wher e t can b e any expres sion (e.g., a term, atom, clause, etc.). W e write θ σ to denote that the application of θ is followed by the application o f σ . A subs titution θ is a u n ifier of tw o terms s and t if a nd only if sθ = tθ . W e c a ll θ the most gener al unifier (mgu) of s and t if and only if θ is a unifier of s and t and for all unifiers σ of s and t ther e is a substitution µ such that σ = θ µ . W e briefly present the pro cedural semantics of logic progra ms ba sed on SLD- resolution using the left-to- righ t selection rule implemented by most Prolog systems. More details on logic pr ogramming can be found in [Apt 199 7], for example. Definition 2.2 (Derivation, T ermination) . Let Q b e a query A 1 , . . . , A m , let c be a clause H :– B 1 , . . . , B k . Then Q ′ is a r esolvent of Q a nd c using θ (deno ted Q ⊢ c,θ Q ′ ) if θ is the mgu 3 of A 1 and H , and Q ′ = ( B 1 , . . . , B k , A 2 , . . . , A m ) θ . A derivation of a pr ogram P and Q is a p ossibly infinite sequence Q 0 , Q 1 , . . . of queries with Q 0 = Q where for all i , w e have Q i ⊢ c i +1 ,θ i +1 Q i +1 for some s ubs titution θ i +1 and so me fresh v ariant c i +1 of a clause o f P . F or a deriv ation Q 0 , . . . , Q n as ab o ve, we a lso write Q 0 ⊢ n P ,θ 1 ...θ n Q n or Q 0 ⊢ n P Q n , and we also write Q i ⊢ P Q i +1 for Q i ⊢ c i +1 ,θ i +1 Q i +1 . The query Q terminates for P if a ll deriv ations of P and Q are finite. Our no tio n of deriv a tion coincides with log ic prog ramming witho ut an o ccur chec k [Colmer auer 19 82] a s implemented in recent Prolog systems such as SICStus or SWI . Since we consider only definite logic progra ms, any progra m whic h is ter mi- nating without o ccur chec k is also ter minating with o ccur chec k, but not vice versa. So if o ur a pproach detects “termina tion”, then the progr am is indeed terminating, no matter whether o ne uses log ic progr a mming with or without o ccur chec k. In other words, our a pproach is s ound for b oth kinds of lo gic progra mming, wherea s most other approa c hes only co nsider lo gic progr amming with o ccur check. Example 2. 3. Reg ard a progr am P with the clauses p ( X ) :– equal ( X , s ( X )) , p ( X ) and equal ( X , X ) . W e o btain p ( X ) ⊢ 2 P p ( s ( s ( . . . ))) ⊢ 2 P p ( s ( s ( . . . ))) ⊢ 2 P . . . , where s ( s ( . . . )) is the term containing infinitely ma n y nested s -symbols. So the finite query p ( X ) leads to a der iv ation with infinite (rational) queries. While p ( X ) is not terminating acco rding to Definition 2.2, it would b e ter minating if o ne uses logic prog ramming with o ccur chec k. Indeed, to ols like c T I [Mesnard and Bagnar a 2005] a nd T erminWeb [Co dish a nd T ab o c h 19 99] r epor t that such quer ies ar e “ter- minating”. So in cont rast to o ur technique, such to ols are in general not s o und for logic pro gramming without o ccur c heck, although this form of log ic progra mming is typically used in practice. 2.2 T erm Rewriting Now w e define TRSs a nd int ro duce the no tio n of infinitary c onstructor r ewriting . F or further deta ils on term rewriting we refer to [Ba ader and Nipko w 19 98]. Definition 2.4 (Infi nitary Constructor R ewriting) . A TRS R is a finite set of 3 Note that f or finite sets of r ational atoms or terms, unification i s decidable, the mgu is unique modulo r enaming, and i t i s a substitution with r ational terms [ Huet 1976]. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm R ewri ting · 9 rules ℓ → r with ℓ , r ∈ T (Σ , V ) a nd ℓ / ∈ V . 4 W e divide the signatur e into define d symbols Σ D = { f | ℓ → r ∈ R , ro ot( ℓ ) = f } and c onstructors Σ C = Σ \ Σ D . R ’s infinitary c onst ructor r ewrite r elation is denoted → R : for s, t ∈ T ∞ (Σ , V ) we hav e s → R t if there is a rule ℓ → r , a po sition p os and a substitution σ : V → T ∞ (Σ C , V ) with s | p os = ℓσ a nd t = s [ r σ ] p os . Let → n R , → ≥ n R , → ∗ R denote rewrite se quences of n steps, o f at least n steps, and of arbitra r y ma n y steps, resp ectively (where n ≥ 0 ). A term t is terminating for R if there is no infinite sequence of the for m t → R t 1 → R t 2 → R . . . A TRS R is terminating if all terms are terminating for R . The ab ov e definition of → R differs from the usua l re write r elation in tw o asp ects: (i) W e only p ermit ins tan tiations of rule v ariables b y constructor ter ms . (ii) W e use substitutions with po ssibly non-ra tional infinite terms. In Ex ample 3.2 and 3.3 in the next section, we will motiv a te these mo difications and show that there ar e TRSs which terminate w.r .t. the usual rew r ite r elation, but a r e non-terminating w.r .t. infinitary constructor r ewriting and vice v ersa. 3. TRANSFORMING LOGIC PROGRAMS INTO TE RM R EWRITE SYSTEMS Now we mo dify the tra ns formation of log ic progr ams into TRSs from Sec tio n 1 to make it applica ble for arbitr ary (p ossibly no n-w ell-mo ded) pro grams a s well. W e present the new tra nsformation in Sectio n 3.1 and prov e its soundness in Section 3.2. Later in Sectio n 6 we will formally prove that the c la ssical transfo rmation is strictly subsumed b y our new one. 3.1 The Improved T ransformation Instead of sepa r ating b etw e e n input and o utput po s itions of a predicate p/n , now we keep al l arguments b oth for p in and p out (i.e., p in and p out hav e ar it y n ). Definition 3.1 (T r ansformation) . A log ic progr am P ov er (Σ , ∆) is tra nsformed int o the following TRS R P ov er Σ P = Σ ∪ { p in /n, p out /n | p/ n ∈ ∆ } ∪ { u c,i | c ∈ P , 1 ≤ i ≤ k , where k is the num ber of ato ms in the b o dy of c } . • F or ea c h fact p ( ~ s ) in P , the TRS R P contains the rule p in ( ~ s ) → p out ( ~ s ). • F or ea c h clause c of the form p ( ~ s ) :– p 1 ( ~ s 1 ) , . . . , p k ( ~ s k ) in P , R P contains: p in ( ~ s ) → u c, 1 ( p 1 in ( ~ s 1 ) , V ( ~ s )) u c, 1 ( p 1 out ( ~ s 1 ) , V ( ~ s )) → u c, 2 ( p 2 in ( ~ s 2 ) , V ( ~ s ) ∪ V ( ~ s 1 )) . . . u c,k ( p k out ( ~ s k ) , V ( ~ s ) ∪ V ( ~ s 1 ) ∪ . . . ∪ V ( ~ s k − 1 )) → p out ( ~ s ) The following tw o examples motiv ate the need for infinitary cons tr uctor rewriting in Definition 3.1, i.e., they motiv ate Mo difications (i) a nd (ii) in Section 2.2. 4 In standard term rewriting, one usually requires V ( r ) ⊆ V ( ℓ ) for all r ules ℓ → r . The reason is that otherwise the standard r ewr ite relation is never we ll founded. How ev er, the infinitary c onstructor r ewrite r elation defined here can b e well founded even i f V ( r ) 6⊆ V ( ℓ ). AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 10 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann Example 3. 2. F or the log ic prog ram of Example 1.1, the tra nsformation of Def- inition 3.1 yields the fo llo wing TRS. p in ( X, X ) → p out ( X, X ) (1) p in ( f ( X ) , g ( Y )) → u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (2) u 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → u 2 ( p in ( Z, g ( Y )) , X , Y , Z ) (3) u 2 ( p out ( Z, g ( Y )) , X , Y , Z ) → p out ( f ( X ) , g ( Y )) (4) This example shows why rule s of TRSs ma y only b e instan tiated with co nstructor terms (Modifica tion (i)). The rea s on is that lo cal v aria bles like Z (i.e., v ariables o ccurring in the bo dy but not in the head of a cla us e) give r is e to r ules ℓ → r where V ( r ) 6⊆ V ( ℓ ) (cf. Rule (2)). Such r ule s ar e never terminating in standard term rewriting. How ever, in our setting one may only ins tan tiate Z with construc to r terms. So in contrast to the o ld transfor mation in Ex a mple 1.2, now all terms p in ( t 1 , t 2 ) terminate fo r the TRS if t 1 is finite, since now the s econd ar gumen t of p in preven ts an infinite applica tion o f Rule (2 ). Indeed, constructo r rewr iting correctly simulates the b eha vior o f lo gic progr ams, since the v a riables in a logic progra m are only instantiated by “cons tr uctor ter ms”. F or the non-well-moded pr ogram o f Ex ample 1.3 , one obtains a s imilar TRS where g ( Y ) is re pla ced by g ( W ) in the right-hand side of Rule (3) a nd the left- hand side o f Rule (4). Again, all terms p in ( t 1 , t 2 ) a re terminating for this TRS provided that t 1 is finite. Thus, we can now handle pro g rams where the class i- cal transfor mation of [Arts and Zantema 1995; C htourou and Rusinowitch 1993 ; Ganzinger and W aldmann 199 3; O hlebusc h 2001] failed, cf. Goals (A) and (B) in Section 1.2. Deriv ations in logic pr ogramming use unific ation , while re w r iting is defined by matching . Example 3 .3 shows that to simulate unification by matching, we hav e to consider substitutions with infinite and even non-r ational terms (Mo dification (ii)). Example 3. 3. Let P b e ordered ( cons ( X, cons ( s ( X ) , XS ))) :– ordered ( cons ( s ( X ) , XS )) . If one o nly c onsiders rewriting with finite or r ational terms, then the transfo r med TRS R P is termina ting . How ever, the query ordered ( YS ) is not terminating for P . Thu s, to obtain a sound approach, R P m ust also b e non-termina ting. I ndee d, the term t = ordered in ( cons ( X, cons ( s ( X ) , co ns ( s 2 ( X ) , . . . )))) is non-terminating with R P ’s rule o rdered in ( cons ( X , con s ( s ( X ) , XS ))) → u ( ordered in ( cons ( s ( X ) , XS )) , X , XS ) . The non-ratio nal ter m t c o rresp onds to the infinite der iv ation with the quer y ordered ( YS ) . 3.2 Soundness o f th e T ransformation W e first show an a ux iliary lemma that is needed to prove the s o undness o f the transformatio n. It r elates deriv a tions with the lo gic progr a m P to rewrite sequences with the TRS R P . Lemma 3.4 (Connecting P and R P ). L et P b e a pr o gr am, let ~ t b e t erms fr om T r at (Σ , V ) , let p ( ~ t ) ⊢ n P ,σ Q . If Q = ✷ , then p in ( ~ t ) σ → ≥ n R P p out ( ~ t ) σ . Otherwise, if Q is “ q ( ~ v ) , . . . ”, then p in ( ~ t ) σ → ≥ n R P r for a term r c ontaining the su bterm q in ( ~ v ) . AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 11 Proof. Le t p ( ~ t ) = Q 0 ⊢ c 1 ,θ 1 . . . ⊢ c n ,θ n Q n = Q with σ = θ 1 . . . θ n . W e use induction on n . The base case n = 0 is trivial, since Q = p ( ~ t ) and p in ( ~ t ) → 0 R P p in ( ~ t ). Now let n ≥ 1. W e firs t r egard the case Q 1 = ✷ and n = 1. Then c 1 is a fact p ( ~ s ) a nd θ 1 is the mgu of p ( ~ t ) and p ( ~ s ). Note that such mgu’s instantiate all v aria bles with constructor terms (as sy m bols of Σ ar e constructor s o f R P ). W e obtain p in ( ~ t ) θ 1 = p in ( ~ s ) θ 1 → R P p out ( ~ s ) θ 1 = p out ( ~ t ) θ 1 where σ = θ 1 . Finally , let Q 1 6 = ✷ . Thus, c 1 is p ( ~ s ) :– p 1 ( ~ s 1 ) , . . . , p k ( ~ s k ) a nd Q 1 is p 1 ( ~ s 1 ) θ 1 , . . . , p k ( ~ s k ) θ 1 where θ 1 is the mgu o f p ( ~ t ) and p ( ~ s ). There is an i with 1 ≤ i ≤ k such that for all j with 1 ≤ j ≤ i − 1 we hav e p j ( ~ s j ) σ 0 . . . σ j − 1 ⊢ n j P ,σ j ✷ . Mo r e- ov er, if Q = ✷ then we can choose i = k and p i ( ~ s i ) σ 0 . . . σ i − 1 ⊢ n i P ,σ i ✷ . Oth- erwise, if Q is “ q ( ~ v ) , . . . ”, then we ca n choos e i such that p i ( ~ s i ) σ 0 . . . σ i − 1 ⊢ n i P ,σ i q ( ~ v ) , . . . Here, n = n 1 + . . . + n i + 1, σ 0 = θ 1 , σ 1 = θ 2 . . . θ n 1 +1 , . . . , and σ i = θ n 1 + ... + n i − 1 +2 . . . θ n 1 + ... + n i +1 . So σ = σ 0 . . . σ i . By the induction hypothes is w e have p j in ( ~ s j ) σ 0 . . . σ j → ≥ n j R P p j out ( ~ s j ) σ 0 . . . σ j and thus also p j in ( ~ s j ) σ → ≥ n j R P p j out ( ~ s j ) σ . Moreover, if Q = ✷ then we also have p i in ( ~ s i ) σ → ≥ n i R P p i out ( ~ s i ) σ where i = k . Otherwise, if Q is “ q ( ~ v ) , . . . ”, then the induction hyp othesis implies p i in ( ~ s i ) σ → ≥ n i R P r ′ , whe r e r ′ contains q in ( ~ v ). Thus p in ( ~ t ) σ = p in ( ~ s ) σ → R P u c 1 , 1 ( p 1 in ( ~ s 1 ) , V ( ~ s )) σ → ≥ n 1 R P u c 1 , 1 ( p 1 out ( ~ s 1 ) , V ( ~ s )) σ → R P u c 1 , 2 ( p 2 in ( ~ s 2 ) , V ( ~ s ) ∪ V ( ~ s 1 )) σ → ≥ n 2 R P u c 1 , 2 ( p 2 out ( ~ s 2 ) , V ( ~ s ) ∪ V ( ~ s 1 )) σ → ≥ n 3 + ... + n i − 1 R P u c 1 ,i ( p i in ( ~ s i ) , V ( ~ s ) ∪ V ( ~ s 1 ) ∪ . . . ∪ V ( ~ s i − 1 )) σ Moreov er, if Q = ✷ , then i = k and the r e write sequence yields p out ( ~ t ) σ , since u c 1 ,i ( p i in ( ~ s i ) , V ( ~ s ) ∪ . . . ∪ V ( ~ s i − 1 )) σ → ≥ n i R P u c 1 ,i ( p i out ( ~ s i ) , V ( ~ s ) ∪ . . . ∪ V ( ~ s i − 1 )) σ → R P p out ( ~ s ) σ = p out ( ~ t ) σ. Otherwise, if Q is “ q ( ~ v ) , . . . ”, then re wr iting yields a term containing q in ( ~ v ): u c 1 ,i ( p i in ( ~ s i ) , V ( ~ s ) ∪ . . . ∪ V ( ~ s i − 1 )) σ → ≥ n i R P u c 1 ,i ( r ′ , V ( ~ s ) σ ∪ . . . ∪ V ( ~ s i − 1 ) σ ) . F or the s oundness pro of, we need another lemma which states that we c a n restric t ourselves to non-ter minating queries which only consist o f a single ato m. Lemma 3.5 (Non-Termina ting Queries). L et P b e a lo gic pr o gr am. Then for every infi nite derivation Q 0 ⊢ P Q 1 ⊢ P . . . , ther e is a Q i of the form “ q ( ~ v ) , . . . ” with i > 0 such t hat the query q ( ~ v ) is also non-terminating. Proof. Ass ume that for all i > 0, the first a to m in Q i do es not have an infinite deriv atio n. Then for ea c h Q i there ar e tw o cases: either the first a tom fails or it ca n s uccessfully b e prov ed. In the for mer case, there is no infinite r eduction from Q i which contradicts the infiniteness of the de r iv ation from Q 0 . Thus for all i > 0 , the firs t atom of Q i is successfully prov ed in n i steps during the deriv ation Q 0 ⊢ P Q 1 ⊢ P . . . Let m be the num b er o f atoms in Q 1 . But then Q 1+ n 1 + ... + n m is the empty quer y ✷ which ag ain co ntradicts the infiniteness of the deriv ation. W e use ar gument filters to characterize the classes of queries whose termina tio n we wan t to analyz e. Related definitions c an b e found in, e.g., [Ar ts and Giesl 200 0; AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 12 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann Leuschel a nd Sø rensen 199 6]. Definition 3.6 (Ar gumen t Filter) . A function π : Σ ∪ ∆ → 2 N is an ar gu ment filter π over a signatur e (Σ , ∆) if and only if π ( f /n ) ⊆ { 1 , . . . , n } for every f /n ∈ Σ ∪ ∆. W e extend π to ter ms and atoms by defining π ( x ) = x if x is a v ariable and π ( f ( t 1 , . . . , t n )) = f ( π ( t i 1 ) , . . . , π ( t i k )) if π ( f / n ) = { i 1 , . . . , i k } with i 1 < . . . < i k . Here, the new terms a nd a toms ar e from the filtered signa ture (Σ π , ∆ π ) where f /n ∈ Σ implies f / k ∈ Σ π and likewise fo r ∆ π . F or a logic progr am P we write (Σ P π , ∆ P π ) instead of ((Σ P ) π , (∆ P ) π ). F or any TRS R , we define π ( R ) = { π ( ℓ ) → π ( r ) | ℓ → r ∈ R} . The set of all argument filters over a signatur e (Σ , ∆) is denoted by AF (Σ , ∆). W e write AF (Σ) instead of AF (Σ , ∅ ) and sp eak o f an a rgument filter “ov er Σ”. W e also write π ( f ) instead of π ( f /n ) if the arity of f is clear fro m the context. An a r gumen t filter π ′ is a r efinement o f a filter π if a nd o nly if π ′ ( f ) ⊆ π ( f ) for all f ∈ Σ ∪ ∆. Argument filters sp ecify thos e p o sitions which hav e to b e instantiated with finite ground terms. T he n, w e ana ly ze terminatio n of all queries Q where π ( Q ) is a (finite) ground atom. In E xample 1.1 , we wan ted to prove termina tio n for all queries p ( t 1 , t 2 ) w he r e t 1 is finite and ground. These queries ar e describ ed by the filter π ( h ) = { 1 } fo r all h ∈ { p , f , g } . Thus, we hav e π ( p ( t 1 , t 2 )) = p ( π ( t 1 )). Note that argumen t filter s a lso o perate on function instead of just pr e dic ate symbols. Therefor e, they can describ e more sophisticated classes of quer ies than the clas s ical appro ac h o f [Arts a nd Zantema 1 9 95; Chtourou and Rusinowitc h 199 3; Ganzinger and W aldmann 1993 ; Ohlebusch 2001] which only distinguishes b et w een input and output p ositions of predicates. F or example, if one wan ts to analyze a ll queries app end ( t 1 , t 2 , t 3 ) where t 1 is a finite list, one would use the filter π ( app e nd ) = { 1 } and π ( • ) = { 2 } , where “ • ” is the list co nstructor (i.e., • ( X, L ) = [ X | L ]). Of course, our metho d can eas ily prov e that a ll these quer ies are terminating for the progra m of Example 1 .4 . Now we show the so undnes s theor em: to prov e termination of all queries Q where π ( Q ) is a finite ground atom, it s uffices to show termination of all those terms p in ( ~ t ) for the TRS R P where π ( p in ( ~ t )) is a finite g r ound term a nd wher e ~ t o nly contains function symbols from the lo gic pr ogram P . Here, π has to b e extended to the new function s y m bols p in by defining π ( p in ) = π ( p ). Theorem 3. 7 (Sou ndness of the Transforma tion) . L et P b e a lo gic pr o- gr am and let π b e an ar gument filter over (Σ , ∆) . We ext end π such that π ( p in ) = π ( p ) for al l p ∈ ∆ . L et S = { p in ( ~ t ) | p ∈ ∆ , ~ t ∈ ~ T ∞ (Σ , V ) , π ( p in ( ~ t )) ∈ T (Σ P π ) } . If al l t erms s ∈ S ar e terminating for R P , then al l queries Q ∈ A r at (Σ , ∆ , V ) with π ( Q ) ∈ A (Σ π , ∆ π ) ar e terminating for P . 5 Proof. Ass ume that ther e is a non-terminating query p ( ~ t ) as ab ov e with p ( ~ t ) ⊢ P Q 1 ⊢ P Q 2 ⊢ P . . . By Lemma 3.5 there is an i 1 > 0 with Q i 1 = q 1 ( ~ v 1 ) , . . . and an infinite deriv ation q 1 ( ~ v 1 ) ⊢ P Q ′ 1 ⊢ P Q ′ 2 ⊢ P . . . F ro m p ( ~ t ) ⊢ i 1 P ,σ 0 q 1 ( ~ v 1 ) , . . . and Lemma 3.4 we g et p in ( ~ t ) σ 0 → ≥ i 1 R P r 1 , whe r e r 1 contains the s ubter m q 1 in ( ~ v 1 ). 5 It is currently op en whether the conv erse holds as well. F or a short discussion see Section 7.2. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 13 By L e mma 3.5 ag ain, ther e is an i 2 > 0 with Q ′ i 2 = q 2 ( ~ v 2 ) , . . . and an infinite deriv atio n q 2 ( ~ v 2 ) ⊢ P Q ′′ 1 ⊢ P . . . F r om q 1 ( ~ v 1 ) ⊢ i 2 P ,σ 1 q 2 ( ~ v 2 ) , . . . a nd Le mma 3.4 we get p in ( ~ t ) σ 0 σ 1 → ≥ i 1 R P r 1 σ 1 → ≥ i 2 R P r 2 , whe r e r 2 contains the s ubter m q 2 in ( ~ v 2 ). Contin uing this reasoning we o btain an infinite sequence σ 0 , σ 1 , . . . o f s ubstitu- tions. F or each j ≥ 0, let µ j = σ j σ j +1 . . . res ult from the infinite co mposition of these substitutions. 6 Since r j µ j is a n instance of r j σ j . . . σ n for all n ≥ j , we o btain that p in ( ~ t ) µ 0 is non-ter minating for R P : p in ( ~ t ) µ 0 → ≥ i 1 R P r 1 µ 1 → ≥ i 2 R P r 2 µ 2 → ≥ i 3 R P . . . As π ( p ( ~ t )) ∈ A (Σ π , ∆ π ) and thus π ( p in ( ~ t )) = π ( p in ( ~ t ) µ 0 ) ∈ T (Σ P π ), this is a contradiction. 4. TERMINA TION OF INFINIT ARY CONSTRUCTOR R EWRITING One o f the mos t p ow erful metho ds for a utomated termination a nalysis of re w r iting is the dep endency p air (D P) metho d [Arts and Giesl 2 000] which is implement ed in most current termination to ols fo r TRSs. Ho wev er, since the DP metho d only prov es termination of term rew r iting with finite terms, its use is not so und in our setting. Nevertheless, we now show tha t o nly very slight mo difications are required to a dapt dep endency pairs fro m or dinary r ewriting to infinitary constructor rewriting. So any re writing to ol implement ing dep endency pairs can easily b e mo dified in or der to prove termination of infinitary constructor rewriting as well. Then, it ca n als o a nalyze terminatio n of lo gic pr ograms using the transfor ma tion of Definition 3.1 . Moreov er, dep endency pairs are a gener al framework that per mits the integration of any termination technique for TRSs [Giesl et al. 2 005, Thm. 36]. Therefore, instead of adapting each technique s eparately , it is sufficient only to adapt the DP framework to infinitary constr uctor rewriting. Then, any termination technique can b e dir ectly used fo r infinitary constructor rewriting . In Section 4.1 , we ada pt the notions and the main ter mination criterion of the dep endency pair metho d to infinitary constructor rewr iting and in Section 4.2 we show how to automa te this criterion b y ada pting the “ DP pro cessors” of the DP framework. 4.1 Depen d ency Pairs for Infini ta ry Rewriti n g Let R be a TRS. F or each defined symbol f /n ∈ Σ D , we ex tend the set of con- structors Σ C by a fresh tuple symb ol f ♯ /n . W e often write F instead of f ♯ . F or 6 The comp osition of infinitely man y substitutions σ 0 , σ 1 , . . . is defined as follows. The definition ensures that tσ 0 σ 1 . . . is an instance of tσ 0 . . . σ n for all terms (or atoms) t and all n ≥ 0. It suffices to define the symbols at the p ositions of tσ 0 σ 1 . . . for an y term t . Obviously , p os i s a posi tion of tσ 0 σ 1 . . . iff p os is a p osition of tσ 0 . . . σ n for some n ≥ 0. W e define that the symbol of tσ 0 σ 1 . . . at such a p osition p os i s f ∈ Σ iff f is at p osition p os in tσ 0 . . . σ m for some m ≥ 0. Otherwise, ( tσ 0 . . . σ n ) | p os = X 0 ∈ V . Let n = i 0 < i 1 < . . . b e the maximal (finite or i nfinite) sequence wi th σ i j +1 ( X j ) = . . . = σ i j +1 − 1 ( X j ) = X j and σ i j +1 ( X j ) = X j +1 for all j . W e require X j 6 = X j +1 , but permit X j = X j ′ otherwise. If this sequence is finite (i.e. , it has the form n = i 0 < . . . < i m ), then we define ( tσ 0 σ 1 . . . ) | p os = X m . O therwis e, the substitutions perf orm infinitely many v ariable renamings. In this case, we use one sp ecial v ariable Z ∞ and define ( tσ 0 σ 1 . . . ) | p os = Z ∞ . So if σ 0 ( X ) = Y , σ 1 ( Y ) = X , σ 2 ( X ) = Y , σ 3 ( Y ) = X , etc., we define X σ 0 σ 1 . . . = Y σ 0 σ 1 . . . = Z ∞ . AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 14 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann t = g ( ~ t ) with g ∈ Σ D , le t t ♯ denote g ♯ ( ~ t ). Definition 4.1 (Dep endency Pair [Arts and Giesl 2000]) . The set of dep endency p airs for a TRS R is D P ( R ) = { ℓ ♯ → t ♯ | ℓ → r ∈ R , t is a subterm of r , ro ot( t ) ∈ Σ D } . Example 4. 2. Co nsider again the lo gic progra m of Exa mple 1.1 which was trans- formed into the following TRS R in Example 3.2. p in ( X, X ) → p out ( X, X ) (1) p in ( f ( X ) , g ( Y )) → u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (2) u 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → u 2 ( p in ( Z, g ( Y )) , X , Y , Z ) (3) u 2 ( p out ( Z, g ( Y )) , X , Y , Z ) → p out ( f ( X ) , g ( Y )) (4) F or this TRS R , we have Σ D = { p in , u 1 , u 2 } and D P ( R ) is P in ( f ( X ) , g ( Y )) → P in ( f ( X ) , f ( Z )) (5) P in ( f ( X ) , g ( Y )) → U 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (6) U 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → P in ( Z, g ( Y )) (7) U 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → U 2 ( p in ( Z, g ( Y )) , X , Y , Z ) (8) While Definition 4.1 is fro m [Arts and Giesl 200 0], all following definitions and theorems are new. They extend exis ting concepts from o rdinary to infinitary con- structor rewriting. F or termination, one tries to prov e that there are no infinite chains of de p endency pairs. Intuitiv ely , a dep endency pair cor resp o nds to a function call and a chain rep- resents a po ssible seq ue nc e of calls that can o ccur during rewr iting. Definition 4.3 extends the notion of chains to infinitary c o nstructor rewr iting. T o this end, we use an a rgument filter π that describ es which arg umen ts of function symbols ha ve to be fi nite terms. So if π do es not delete arguments (i.e., if π ( f ) = { 1 , . . . , n } for all f /n ), then this c orresp onds to ordina ry (finitary) constr uctor rewr iting and if π deletes all ar gumen ts (i.e., if π ( f ) = ∅ for a ll f ), then this cor respo nds to full infinitary constructor rewriting. In Definition 4.3, the TRS D usua lly stands for a set of dep endency pair s. (Note that if R is a TRS, then D P ( R ) is a lso a TRS.) Definition 4.3 (Chain) . Let D , R b e TRSs and π b e an ar gumen t filter. A (po s- sibly infinite) sequence of pairs s 1 → t 1 , s 2 → t 2 , . . . from D is a ( D , R , π )- chain iff • for a ll i ≥ 1, there ar e substitutions σ i : V → T ∞ (Σ C , V ) such that t i σ i → ∗ R s i +1 σ i +1 , a nd • for a ll i ≥ 1, we hav e π ( s i σ i ) , π ( t i σ i ) ∈ T (Σ π ). Mo reov er , if the rewrite seq uence from t i σ i to s i +1 σ i +1 has the for m t i σ i = q 0 → R . . . → R q m = s i +1 σ i +1 , then for all terms in this rewrite sequence we have π ( q 0 ) , . . . , π ( q m ) ∈ T (Σ π ) as well. So all terms in the s equence have finite ground terms on tho s e p ositions which are not filtered aw ay by π . In Example 4.2, “(6), (7)” is a chain for any ar gumen t filter π : if one instantiates X a nd Z with the same finite gro und term, then (6)’s instantiated r ig h t-hand side rewrites to an instance o f (7)’s left-hand side. Note that if one uses a n ar gumen t AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 15 filter π which p ermits an instantiation of X and Z with the infinite term f ( f ( . . . )), then ther e is also an infinite chain “(6 ), (7), (6), (7), . . . ” In o rder to prov e ter mination of a program P , by Theo rem 3.7 w e hav e to show that all ter ms p in ( ~ t ) ar e terminating for R P whenever π ( p in ( ~ t )) is a finite ground term and ~ t only c o n tains function symbols fr om the logic pr ogram (i.e., ~ t contains no defined symbo ls of the TRS R P ). Theo rem 4.4 states that one can prove absence of infinite ( D P ( R P ) , R P , π ′ )-chains instead. Here, π ′ is a filter whic h filters awa y “at least as muc h” as π . Ho wever, π ′ has to b e chosen in such a way that the filter ed TRSs π ′ ( D P ( R P )) and π ′ ( R P ) satisfy the “ variable c ondition ”, i.e., V ( π ′ ( r )) ⊆ V ( π ′ ( ℓ )) for all ℓ → r ∈ D P ( R P ) ∪ R P . Then the filter π ′ detects all po tentially infinite s ubter ms in rewrite seq uences (i.e., a ll subterms which corres p ond to “no n- unification-free parts” of P , i.e., to non-gr ound subterms when “executing” the progra m P ). Theorem 4. 4 (Proving Infinit ar y Termina tion). L et R b e a TRS over Σ and let π b e an ar gument filter over Σ . We extend π to tuple symb ols such that π ( F ) = π ( f ) for al l f ∈ Σ D . L et π ′ b e a r efi n ement of π su ch that π ′ ( D P ( R )) and π ′ ( R ) satisfy the variable c ondition. 7 If t her e is no infin ite ( D P ( R ) , R , π ′ ) -chain, then al l t erms f ( ~ t ) with ~ t ∈ ~ T ∞ (Σ C , V ) and π ( f ( ~ t )) ∈ T (Σ π ) ar e terminating for R . Proof. Ass ume there is a no n-terminating term f ( ~ t ) as ab ov e. Since ~ t do es not contain defined symbols, the first rewr ite step in the infinite sequence is on the ro ot p osition with a rule ℓ = f ( ~ ℓ ) → r wher e ℓσ 1 = f ( ~ t ). Since σ 1 do es not int ro duce defined symbols, a ll defined symbols o f r σ 1 o ccur on p ositions of r . So there is a subter m r ′ of r with defined r oot such that r ′ σ 1 is also non-terminating. Let r ′ denote the sma llest such subterm (i.e., fo r all prop er subterms r ′′ of r ′ , the term r ′′ σ 1 is ter minating). Then ℓ ♯ → r ′ ♯ is the first dep endency pair of the infinite chain that we co ns truct. Note that π ( ℓσ 1 ) and thus, π ( ℓ ♯ σ 1 ) and hence, also π ′ ( ℓ ♯ σ 1 ) = π ′ ( F ( ~ t )) is a finite gro und term by as sumption. Mor eo ver, as ℓ ♯ → r ′ ♯ ∈ D P ( R ) and as π ′ ( D P ( R )) satisfies the v aria ble condition, π ′ ( r ′ ♯ σ 1 ) is finite a nd gro und as w ell. The infinite seq uence contin ues by rewriting r ′ σ 1 ’s pro per subterms rep e a tedly . During this rewriting, the le ft-hand sides of rules ar e instantiated by co nstructor substitutions (i.e., s ubs titutions with range T ∞ (Σ C , V )). As π ′ ( R ) satisfies the v aria ble condition, the terms r e ma in finite and g round when applying the filter π ′ . Finally , a ro ot re wr ite step is pe r formed aga in. Rep eating this construc tio n infinitely ma n y times results in an infinite c hain. The following corolla ry combines Theorem 3.7 a nd Theore m 4.4. It describ es how we use the DP metho d for proving ter mination of logic programs. 7 T o see why the v ariable condition is needed in Theorem 4.4, let R = { g ( X ) → f ( X ) , f ( s ( X )) → f ( X ) } and π = π ′ where π ′ ( g ) = ∅ , π ′ ( f ) = π ′ ( F ) = π ′ ( s ) = { 1 } . R ’s first rule violates the v ariable condition: V ( π ′ ( f ( X ))) = { X } 6⊆ V ( π ′ ( g ( X ))) = ∅ . There is no infinite ch ain, si nce π ′ does not allow us to i nstan tiate the v ariable X i n the dependency pair F ( s ( X )) → F ( X ) b y an infinite term. Nevertheless, there i s a non-terminating term g ( s ( s ( . . . ))) which is filtered to a finite ground term π ′ ( g ( s ( s ( . . . )))) = g . AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 16 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann Corollar y 4.5 (Termina tion of L o gic Prog. by Dependency P airs). L et P b e a lo gic pr o gr am and let π b e an ar gument filter over (Σ , ∆) . We ex tend π to Σ P and t o tuple symb ols such that π ( p in ) = π ( P in ) = π ( p ) for al l p ∈ ∆ . F or al l other symb ols f /n that ar e not fr om Σ or ∆ , we define π ( f /n ) = { 1 , . . . , n } . L et π ′ b e a r efinement of π such that π ′ ( D P ( R P )) and π ′ ( R P ) satisfy the variable c ondition. If ther e is no infin ite ( D P ( R P ) , R P , π ′ ) -chain, then al l queries Q ∈ A r at (Σ , ∆ , V ) with π ( Q ) ∈ A (Σ π , ∆ π ) ar e terminating for P . Example 4. 6. W e wan t to prove terminatio n of Exa mple 1.1 for all querie s Q where π ( Q ) is finite and ground for the filter π ( h ) = { 1 } for all h ∈ { p , f , g } . By Corollar y 4.5, it suffices to s ho w absence of infinite ( D P ( R ) , R , π ′ ) -chains. Here, R is the TRS { (1) , . . . , (4) } fr om Ex ample 3.2 and D P ( R ) are Rules (5) – (8) from Example 4.2. The filter π ′ has to satisfy π ′ ( h ) ⊆ π ( h ) = { 1 } for h ∈ { f , g } and moreov er, π ′ ( p in ) and π ′ ( P in ) must b e subse ts of π ( p in ) = π ( P in ) = π ( p ) = { 1 } . Moreov er, we have to cho ose π ′ such that the v ariable condition is fulfilled. So while π is alwa ys g iven, π ′ has to b e determined automatically . Of co urse, there ar e only finitely many po ssibilities for π ′ . In particular, defining π ′ ( h ) = ∅ for all symbols h is always p ossible. B ut to obtain a succes sful ter mination pro of afterwards, one should try to generate filters where the sets π ′ ( h ) ar e as large as p ossible, since such filters provide more informa tion ab out the finiteness of ar gumen ts. W e will present suitable heuristics for finding such filters π ′ in Section 5. In our e xample, we use π ′ ( p in ) = π ′ ( P in ) = π ′ ( f ) = π ′ ( g ) = { 1 } , π ′ ( p out ) = π ′ ( u 1 ) = π ′ ( U 1 ) = { 1 , 2 } , and π ′ ( u 2 ) = π ′ ( U 2 ) = { 1 , 2 , 4 } . F or the non-well-moded Example 1 .3 we choo se π ′ ( g ) = ∅ instead to s a tisfy the v ariable condition. So to automate the c r iterion of Corollary 4.5 , we hav e to tackle tw o pr oblems: (I) W e s tart with a given filter π which describ es the set of q ueries whose ter mina- tion should be prov ed. Then we have to find a suitable ar gumen t filter π ′ that refines π in such a wa y that the v a r iable c ondition o f Theorem 4.4 is fulfilled a nd that the ter mination pro of is “ lik ely to succeed”. This problem will b e discuss ed in Sec tio n 5 . (II) F or the chosen arg umen t filter π ′ , we have to prove that ther e is no infinite ( D P ( R P ) , R P , π ′ )-chain. W e show how to do this in the following subsection. 4.2 Automation by Adapting the DP Framew or k Now we show how to prov e abse nc e of infinite ( D P ( R ) , R , π )-chains automatically . T o this end, we a dapt the DP fr amework o f [Giesl et al. 20 05] to infinitary rewriting. In this framework, we now c o nsider a rbitrary DP pr oblems ( D , R , π ) where D and R are TRSs and π is an a r gumen t filter. Our go a l is to show that there is no infinite ( D , R , π )-chain. In this case, we call the problem finite . T ermination techniques should now b e formulated as DP pr o c essors whic h op erate on DP pro blems instead of TRSs. A DP pro cessor Pr o c ta k es a DP problem as input and returns a new set of DP pro blems which then hav e to b e solved instead. Pr o c is s ou n d if for all DP pro blems d , d is finite whenev er all DP problems in Pr o c ( d ) are finite. So termination pro ofs s tart with the initial DP pro blem ( D P ( R ) , R , π ). Then this problem is tra nsformed r epeatedly b y sound DP pro cessor s. If the final pro cessors return empty se ts of DP problems , then termination is prov ed. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 17 In Theo rem 4.9, 4.11 , a nd 4.13 w e will r ecapitulate three of the mo s t imp ortant existing DP pro cessors [Giesl et a l. 200 5] and descr ibe how they must b e mo dified for infinitary constructo r rewriting. T o this end, they now als o hav e to take the argument filter π into account. The firs t pro cessor uses an estimate d dep endency gr aph to estimate whic h dependency pairs can follow each other in chains. Definition 4.7 (Estimate d Dep endency Gr aph) . Let ( D , R , π ) b e a DP problem. The no des of the estimate d ( D , R , π ) -dep endency gr aph a re the pairs o f D and there is an a rc fro m s → t to u → v iff CAP ( t ) and a v ar ian t u ′ of u unify with a n mgu µ where π ( CAP ( t ) µ ) = π ( u ′ µ ) is a finite ter m. Here, CAP ( t ) replaces all subterms of t with defined ro ot symbol by different fresh v ar iables. Example 4. 8. F or the DP problem ( D P ( R ) , R , π ′ ) from Example 4 .6 we obtain: (5) o o (7) % % (6) / / e e (8) F or example, ther e is an arc (6) → (7) , as CAP ( U 1 ( p in ( f ( X ) , f ( Z )) , X , Y )) = U 1 ( V , X , Y ) unifies with U 1 ( p out ( f ( X ′ ) , f ( Z ′ )) , X ′ , Y ′ ) by instantiating the a rgu- men ts of U 1 with finite terms. But there ar e no arcs (5) → (5) or (5) → (6) , since P in ( f ( X ) , f ( Z )) a nd P in ( f ( X ′ ) , g ( Y ′ )) do not unify , even if one insta ntiates Z and Y ′ by infinite terms (as p ermitted b y the filter π ′ ( P in ) = { 1 } ). Note that filters a re used to dete ct p o ten tially infinite arguments, but these ar- guments are not r emove d , since they can still b e use ful in the termination pr o of. In Example 4.8, they are nee de d to determine that (5) has no outgo ing ar cs. If s → t, u → v is a ( D , R , π )-chain then there is an ar c from s → t to u → v in the es timated depe ndency graph. T hus, absence of infinite c hains can b e proved separately for ea c h maximal strong ly connected comp onent (SCC) o f the gra ph. This observ ation is used by the following proc essor to modular ize ter mination proo fs by deco mposing a DP proble m into sub-problems . If ther e are n SCCs in the graph and if D i are the dependency pa ir s of the i -th SCC (for 1 ≤ i ≤ n ), then one can decomp ose the set of dep endency pa ir s D into the subsets D 1 , . . . , D n . Theorem 4. 9 (Dependency Gra ph Processor). F or a DP pr oblem ( D , R , π ) , let Pr o c r eturn { ( D 1 , R , π ) , . . . , ( D n , R , π ) } wher e D 1 , . . . , D n ar e the sets of no des of the SCCs in the estimate d dep endency gr aph. Then Pr o c is sound. Proof. W e pr o ve that if s → t, u → v is a chain, then there is an arc fro m s → t to u → v in the estimated dep endency gra ph. This suffices for T he o rem 4 .9 , since then every infinite ( D , R , π )-chain corresp onds to an infinite path in the graph. This path ends in an SCC with no des D i and th us, there is also an infinite ( D i , R , π )- chain. Hence, if all ( D i , R , π ) are finite DP pr oblems, then so is ( D , R , π ). Let s → t, u → v b e a ( D , R , π )-chain, i.e., tσ 1 → ∗ R uσ 2 for some c onstructor substitutions σ 1 , σ 2 where π ( tσ 1 ) and π ( uσ 2 ) are finite. Let p os 1 , . . . , p os n be the top p ositions where t ha s defined symbols. Then CAP ( t ) = t [ Y 1 ] p os 1 . . . [ Y n ] p os n for fre sh v a riables Y j . Mo reov er, let the v ariant u ′ result from u by replac ing every X ∈ V ( u ) b y a fresh v ariable X ′ . Thus, the substitution σ with σ ( X ′ ) = σ 2 ( X ) for all X ∈ V ( u ), σ ( X ) = σ 1 ( X ) for all X ∈ V ( t ), and σ ( Y j ) = uσ 2 | p os j unifies CAP ( t ) and u ′ . So there is a lso an mgu µ where σ = µτ for some substitution τ . AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 18 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann Moreov er, since π ( uσ 2 ) = π ( u ′ σ ) is finite, the term π ( u ′ µ ) is finite, too . Hence , by Definition 4 .7 there is indeed an arc fro m s → t to u → v . Example 4. 10. In Example 4.8 , the o nly SCC consists of (6) a nd (7 ). Thus, the depe ndency graph pro cessor transfo r ms the initial DP problem ( D P ( R ) , R , π ′ ) int o ( { (6) , (7) } , R , π ′ ) , i.e., it deletes the dep endency pairs (5) and (8 ). The next pro cesso r is based on r e duction p airs ( % , ≻ ) where % a nd ≻ are relations on finite terms. Here, % is r eflexiv e, trans itiv e, monoto nic (i.e., s % t implies f ( . . . s . . . ) % f ( . . . t . . . ) for all function symbols f ), and stable (i.e., s % t implies sσ % tσ for all substitutions σ ) and ≻ is a stable well-founded order compatible with % (i.e., % ◦ ≻ ⊆ ≻ or ≻ ◦ % ⊆ ≻ ). Ther e ar e many techniques to search for s uch rela tions a utomatically (recursive path or ders, po lynomial interpretations, etc. [Der sho witz 19 87]). F or a DP problem ( D , R , π ), we now try to find a r eduction pa ir ( % , ≻ ) such tha t all filter e d R -r ules are weakly decreasing (w.r .t. % ) a nd all filter ed D -dep endency pairs are weakly or stric tly decr e a sing (w.r.t. % or ≻ ). 8 Requiring π ( ℓ ) % π ( r ) fo r all ℓ → r ∈ R e ns ures that in chains s 1 → t 1 , s 2 → t 2 , . . . with t i σ i → ∗ R s i +1 σ i +1 as in Definition 4.3, we hav e π ( t i σ i ) % π ( s i +1 σ i +1 ). Hence, if a reduction pair satisfies the above conditions , then the strictly decr easing depe ndency pairs (i.e., those s → t ∈ D where π ( s ) ≻ π ( t )) cannot o ccur infinitely often in chains. So the following pro cessor deletes these pairs from D . F or any TRS D and any r elation ≻ , let D ≻ π = { s → t ∈ D | π ( s ) ≻ π ( t ) } . Theorem 4. 1 1 (Reduction P air P r ocessor). L et ( % , ≻ ) b e a r e duction p air. Then the fol lowing DP pr o c essor Pr o c is soun d. F or ( D , R , π ) , Pr o c r et urns • { ( D \ D ≻ π , R , π ) } , if D ≻ π ∪ D % π = D and R % π = R • { ( D , R , π ) } , otherwise Proof. W e prov e this theo rem by contradiction, i.e., we assume that ( D , R , π ) is infinite and then pro ceed to s ho w that ( D \ D ≻ π , R , π ) has to b e infinite, to o. F ro m the assumption that ( D , R , π ) is infinite, we k no w that there is an infinite ( D , R , π )-chain s 1 → t 1 , s 2 → t 2 , . . . with t i σ i → ∗ R s i +1 σ i +1 . F or any term t we hav e π ( tσ ) = π ( t ) π ( σ ) where π ( σ )( x ) = π ( σ ( x )) fo r all x ∈ V . So b y stabilit y of ≻ and % , D ≻ π ∪ D % π = D implies π ( s i σ i ) = π ( s i ) π ( σ i ) ( % ) π ( t i ) π ( σ i ) = π ( t i σ i ) . (9) Note that π ( s i σ i ) and π ( t i σ i ) a re finite. Thus, co mparing them with % is p ossible. Similarly , by the obs erv ation π ( tσ ) = π ( t ) π ( σ ) we also g e t that t i σ i → ∗ R s i +1 σ i +1 implies π ( t i σ i ) → ∗ π ( R ) π ( s i +1 σ i +1 ). As R % π = R means that π ( R )’s rules are de- creasing w.r.t. % , by monoto nicit y and stability o f % w e g e t π ( t i σ i ) % π ( s i +1 σ i +1 ). With (9), this implies π ( s 1 σ 1 ) ( % ) π ( t 1 σ 1 ) % π ( s 2 σ 2 ) ( % ) π ( t 2 σ 2 ) % . . . As ≻ is com- patible with % and well founded, π ( s i σ i ) ≻ π ( t i σ i ) only ho lds for finitely many i . So s j → t j , s j +1 → t j +1 , . . . is an infinite ( D \ D ≻ π , R , π ) chain for some j a nd thus, the DP pro blem ( D \ D ≻ π , R , π ) is infinite. 8 W e only consider filter e d r ules and dependency pairs. Thus, % and ≻ are only used to compare those parts of terms which remain finite for all i nstan tiations in ch ains. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 19 Example 4. 12. F or the DP problem ( { (6) , (7) } , R , π ′ ) in E xample 4.10 , o ne can easily find a reduction pair 9 where the dep endency pa ir (7) is s tr ictly decreas ing and where (6) and a ll rules a re weakly dec reasing after applying the filter π ′ : P in ( f ( X )) % U 1 ( p in ( f ( X )) , X ) p in ( X ) % p out ( X, X ) U 1 ( p out ( f ( X ) , f ( Z )) , X ) ≻ P in ( Z ) p in ( f ( X )) % u 1 ( p in ( f ( X )) , X ) u 1 ( p out ( f ( X ) , f ( Z )) , X ) % u 2 ( p in ( Z ) , X , Z ) u 2 ( p out ( Z, g ( Y )) , X , Z ) % p out ( f ( X ) , g ( Y )) Thu s, the reductio n pa ir pro cessor can remov e (7) from the DP pro ble m which results in ( { (6) } , R , π ′ ) . By applying the dep endency graph pr ocess or ag ain, one obtains the empt y set of DP problems, since no w the estimated dep endency gra ph only has the no de (6) a nd no arcs . This prov es that the initial DP pro blem ( D P ( R ) , R , π ′ ) from Example 4.6 is finite and thus, the logic progr am from Ex- ample 1.1 terminates for a ll q uer ies Q where π ( Q ) is finite and g round. Note that termination o f the non-well-moded progra m fr om Example 1.3 can b e shown anal- ogously since finiteness of the initial DP problem ca n b e proved in the same way . The only differ ence is that we obtain g instead of g ( Y ) in the la st inequality ab o ve. As in Theo rem 4.9 and 4.1 1, many other existing DP pro cessor s [Gie s l et a l. 2005 ] can ea sily b e adapted to infinitary co nstructor rewr iting as well. Finally , one can also use the following pr o cesso r to transfor m a DP pr oblem ( D , R , π ) for infinitary constructor rewriting into a DP pro blem ( π ( D ) , π ( R ) , id ) fo r or dinary rewriting. Afterwards, any ex is ting DP pro cessor for or dinary rewriting b ecomes applicable. 10 Since any termination technique for TRSs ca n immediately be for m ulated a s a DP pro cessor [Giesl et al. 20 05, Thm. 3 6], now any ter mination technique for ordinary rewriting can b e dir ectly used for infinitary constructor rewriting as well. Theorem 4. 1 3 (Argument Fil ter P rocessor). L et Pr o c ( ( D , R , π ) ) = { ( π ( D ) , π ( R ) , id ) } wher e id ( f ) = { 1 , . . . , n } for al l f / n . Then Pr o c is sound. Proof. If s 1 → t 1 , s 2 → t 2 , . . . is an infinite ( D , R , π )-chain with the substitu- tions σ i as in Definition 4.3 , then π ( s 1 ) → π ( t 1 ) , π ( s 2 ) → π ( t 2 ) , . . . is an infinite ( π ( D ) , π ( R ) , id )-chain with the substitutions π ( σ i ). The reaso n is that t i σ i → ∗ R s i +1 σ i +1 implies π ( t i ) π ( σ i ) = π ( t i σ i ) → ∗ π ( R ) π ( s i +1 σ i +1 ) = π ( s i +1 ) π ( σ i +1 ). Mor e- ov er, by Definition 4.3, a ll terms in the rewr ite seq ue nc e π ( t i σ i ) → ∗ π ( R ) π ( s i +1 σ i +1 ) are finite. 5. REFINING T HE ARGUME N T FIL T E R In Section 3 w e in tro duced a new transfor mation from logic progr ams P to TRSs R P and show ed that to pr o ve the ter mina tion of a class o f queries for P , it is sufficient to analyze the termination b ehavior of R P . O ur criterion to pr o ve termination of logic programs was summarized in Cor o llary 4.5. 9 F or example, one can use the polynomial interpreta tion | P in ( t 1 ) | = | p in ( t 1 ) | = | U 1 ( t 1 , t 2 ) | = | u 1 ( t 1 , t 2 ) | = | u 2 ( t 1 , t 2 , t 3 ) | = | t 1 | , | p out ( t 1 , t 2 ) | = | t 2 | , | f ( t 1 ) | = | t 1 | + 1, and | g ( t 1 ) | = 0. 10 If ( D , R , π ) results f rom the transformation of a l ogic program, then for ( π ( D ) , π ( R ) , id ) it is ev en sound to apply the existing DP pro cessors for innermost rewriting [Giesl et al . 2005; Giesl et al. 2006]. These pro cessors are usually more p o w erful than those f or ordinary rewr iting. The framework presen ted in [ Giesl et al. 2005] ev en supp orts constructor rewri ting. AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 20 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann The transformatio n itself is trivia l to automate and as shown in Section 4, existing systems implement ing the DP method c a n easily b e a dapted to prove termination of infinitary constructor rewriting. The missing par t in the automation is the gen- eration of a suitable arg umen t filter from the use r input, cf. T ask (I) at the end of Section 4.1. After pr esen ting the general algorithm to refine argument filters in Section 5.1, we introduce suitable heuristics in Sectio ns 5.2 a nd 5 .3. Finally , we extend the general a lgorithm for the refinement o f argument filter s by integrating a mo de ana lysis ba sed on a r gumen t filter s in Section 5.4. This allows us to handle logic progra ms where a predicate is used with s ev eral differen t mode s (i.e., where different oc currences of the same pre dicate hav e different input and output p osi- tions). The usefulness of the differen t heuristics fro m Sections 5.2 and 5 .3 and the power of our extension in Section 5.4 will b e ev aluated empirica lly in Se c tion 7. 5.1 Refinement Algorithm for Argument Filters In our approach of Corollar y 4.5, the user supplies an initial argument filter π to describ e the set of quer ies whos e termination should be pr o ved. Ther e are t wo issues with this a ppr oach. Fir st, while a rgument filters provide the us e r with a more expressive to ol to characterize c lasses of queries, ter mination problems are often rather p osed in the fo rm of a mo ding function for compatibility re asons. F or tunately , it is stra igh tforward to e xtract an a ppropriate initial argument filter from such a mo ding function m : we define π ( p ) = { i | m ( p, i ) = in } for all p ∈ ∆ and π ( f /n ) = { 1 , . . . , n } for all function symbols f /n ∈ Σ. Second, and les s trivially , the v ariable condition V ( π ( r )) ⊆ V ( π ( ℓ )) for all rules ℓ → r ∈ D P ( R P ) ∪ R P do es not nec e s sarily hold for the ar gumen t filter π . Thus, a refinement π ′ of π must b e found such that the v ariable condition holds for π ′ . Then, o ur metho d from Corolla r y 4.5 can b e a pplied. Unfortunately , there are often many refinements π ′ of a given filter π such that the v a riable c o ndition holds. The right choice o f π ′ is crucia l for the success of the termination analy s is. As alrea dy mentioned in Exa mple 4.6 , the a rgumen t filter that simply filters aw a y all ar gumen ts of all function symbols in the TRS, i.e., that has π ′ ( f ) = ∅ for a ll f ∈ Σ P , is a r efinemen t of every argument filter π and it obviously s atisfies the v ar iable c ondition. But of co ur se, only termination of trivia l logic programs can be shown when using this refinement π ′ . Example 5. 1. W e cons ider the logic program of Example 1.1 . As shown in Ex- ample 3.2 , the following rule re s ults (among o thers) from the tr anslation of the logic program. p in ( f ( X ) , g ( Y )) → u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (2) Suppo se that we wan t to prove termination of all quer ies p ( t 1 , t 2 ) where b oth t 1 and t 2 are (finite) g round ter ms. This cor respo nds to the mo ding m ( p , 1 ) = m ( p , 2) = in , i.e., to the initial arg umen t filter π with π ( p ) = { 1 , 2 } . In Cor ollary 4 .5 , w e extend π to p in and P in by defining it to be { 1 , 2 } as well. In order to pr ove ter mination, w e now have to find a refinement π ′ of π such tha t π ′ ( D P ( R P )) and π ′ ( R P ) satisfy the v ariable condition and such that there is no infinite ( D P ( R P ) , R P , π ′ ) -chain. Let us first try to define π ′ = π . Then π ′ do es not filter awa y a n y a rgumen ts. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 21 Thu s, π ′ ( p in ) = { 1 , 2 } , π ′ ( u 1 ) = { 1 , 2 , 3 } , and π ′ ( f ) = π ′ ( g ) = { 1 } . B ut then clearly , the v a riable condition do es not hold as Z o ccurs in π ′ ( r ) but not in π ′ ( ℓ ) if ℓ → r is Rule (2) ab ov e. So we hav e to cho ose a different refinement π ′ . There remain three choices how we ca n refine π to π ′ in orde r to filter aw a y the v ariable Z in the right-hand side o f Rule (2): we can filter aw ay the first argument of f by defining π ′ ( f ) = ∅ , we can filter aw ay p in ’s second ar gumen t by defining π ( p in ) = { 1 } , or we can filter aw ay the fir st argument of u 1 by defining π ( u 1 ) = { 2 , 3 } . The decision which of the three choices ab ov e should b e taken must b e done by a suitable heuristic . The following definition gives a formalizatio n for such heuristics. Here we ass ume that the choice only depe nds o n the term t containing a v ariable that lea ds to a violatio n o f the v ariable co ndition and on the po s ition p os of the v aria ble. Then a re finement heuristic ρ is a function s uc h that ρ ( t, p os ) r eturns a function symbol f /n and an argument p osition i ∈ { 1 , . . . , n } such that filtering aw a y the i - th argument of f would era se the p osition p os in the term t . F or instance, if t is the right-hand side u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) of Rule (2) and p os is the positio n of the v ariable Z in this ter m (i.e., p os = 121), then ρ ( t, p os ) can be either ( f , 1 ), ( p in , 2 ), or ( u 1 , 1 ). Definition 5.2 (Re finement Heuristic) . A r efinement heuristic is a ma pping ρ : T (Σ P , V ) × N ∗ → Σ P × N s uc h that whenever ρ ( t, p os ) = ( f , i ), then there is a po sition p os ′ with p os ′ i being a prefix o f p os and ro ot( t | p os ′ ) = f . Given a TRS R P resulting from the transforma tion of a logic prog r am P a nd a refinement heuristic ρ , Algorithm 1 computes a r efinemen t π ′ of a g iv en a rgumen t filter π such that the v ariable condition holds for D P ( R P ) a nd R P . Input : arg umen t filter π , refinement heuristic ρ , TRS R P Output : refined argument filter π ′ such that π ′ ( D P ( R P )) and π ′ ( R P ) sa tisfy the v ariable condition 1. π ′ := π 2. If ther e is a rule ℓ → r fro m D P ( R P ) ∪ R P and a po sition p os with r | p os ∈ V ( π ′ ( r )) \ V ( π ′ ( ℓ )), then: 2.1. Let ( f , i ) b e the result of ρ ( r, p os ), i.e., ( f , i ) := ρ ( r , p os ). 2.2. Mo dify π ′ by removing i from π ′ ( f ), i.e., π ′ ( f ) := π ′ ( f ) \ { i } . F or all o ther symbols from Σ P , π ′ remains unc hanged. 2.3. Go back to Step 2 . Algorithm 1 : Genera l Refinement Algo rithm T ermina tion o f this alg orithm is obvious a s R P is finite and each c hange of the argument filter in Step 2. 2 reduce s the num ber of unfiltered a r gumen ts. Note als o that ρ ( r, p os ) is alwa ys defined since p os is never the top p osition ε . The r eason is that the TRS R P is non- c o llapsing (i.e., it has no rig h t-hand side consisting just o f AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 22 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann a v ar iable). The algorithm is co rrect as it only terminates if the v aria ble conditio n holds for every dep endency pa ir and every rule. Note that if π ′ ( F ) = π ′ ( f ) for every defined function symbol f and if we do not filter aw ay the firs t argument p osition of the function symbols u c,i , i.e., 1 ∈ π ′ ( u c,i ), then the satisfaction of the v ar iable co ndition fo r R P implies that the v ariable condition for D P ( R P ) ho lds as well. Thus, for heuris tics that g ua rant ee the ab ov e prop erties, we only ha ve to consider R P in the ab o ve a lg orithm. 5.2 Simple Refi nement Heuristics The following definition intro duce s tw o simple p ossible r efinemen t heur istics. If a term t has a po sition p os with a v ariable that violates the v aria ble condition, then these heuris tics filter awa y the resp ective a rgumen t p osition of the innermost r esp. the out ermost function s ym bol ab o ve the v a riable. Definition 5.3 (Inn ermost/Outermost R efinemen t Heu ristic) . Let t b e a term and let “ p os i ” resp. “ i p os ” b e a p osition in t . The innermost r efinement heuristic ρ im is defined as follows: ρ im ( t, p os i ) = (ro ot( t | p os ) , i ) The outermost r efi n ement heuristic ρ om is defined as follows: ρ om ( t, i p os ) = (ro ot( t ) , i ) So if t is aga in the term u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ), then the innermos t refinement heuristic would result in ρ im ( t, 1 21) = ( f , 1) and the outermo st refinement heuristic gives ρ om ( t, 1 21) = ( u 1 , 1 ). Both heuris tics defined ab o ve ar e simple but pr oblematic, as shown in E xam- ple 5.4. Filtering the innermost function symbo l often results in the r e mo v al of an argument p osition that is relev ant for termination of another r ule. Filtering the outer most function symbol excludes the p ossibility of filtering the arguments of function symbols fro m the signatur e Σ o f the orig inal logic progra m. Mo reov er , the o utermost heuristic also often remov es the first argument o f some u c,i -symbol. Afterwards, a succ e s sful ter mination pro of is hardly po ssible anymore. Example 5. 4. Co nsider again the lo gic progra m of Exa mple 1.1 which was trans- formed into the following TRS in Exa mple 3 .2. p in ( X, X ) → p out ( X, X ) (1) p in ( f ( X ) , g ( Y )) → u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (2) u 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → u 2 ( p in ( Z, g ( Y )) , X , Y , Z ) (3) u 2 ( p out ( Z, g ( Y )) , X , Y , Z ) → p out ( f ( X ) , g ( Y )) (4) As shown in Example 4.2 w e o btain the following dep endency pairs for the ab o ve rules. P in ( f ( X ) , g ( Y )) → P in ( f ( X ) , f ( Z )) (5) P in ( f ( X ) , g ( Y )) → U 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (6) U 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → P in ( Z, g ( Y )) (7) U 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → U 2 ( p in ( Z, g ( Y )) , X , Y , Z ) (8) AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 23 As in Exa mple 5.1 we want to prove termination of p ( t 1 , t 2 ) for all gr ound ter ms t 1 and t 2 . Hence, we start with the a rgument filter π that do es not filter aw ay any ar gumen ts, i.e., π ( f /n ) = { 1 , . . . , n } for all f ∈ Σ P . W e will now illustrate Algorithm 1 using our tw o heuristics . Using the innermo st refinement heur istic ρ im in the algo rithm, for the se c ond DP (6) we get ρ im ( U 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) , 121) = ( f , 1) . This requires us to filter aw a y the only arg umen t of f , i.e., π ′ ( f ) = ∅ . No w Z is contained in the right-hand side of the thir d DP (7), but not in the filtered le ft-ha nd side anymore. Thu s, we now hav e to filter awa y the first argument of P in , i.e., π ′ ( P in ) = { 2 } . Due to the DP (6), we now also hav e to remove the second a rgumen t X o f U 1 , i.e., π ′ ( U 1 ) = { 1 , 3 } . Consequently , we lose the information ab out finiteness of p ’s firs t argument and therefor e ca nno t s ho w termination of the prog ram anymore. Mor e precisely , there is an infinite ( D P ( R P ) , R P , π ′ ) -chain co nsisting of the depe ndency pairs (6) and (7) using a substitution that instantiates the v ariables X and Z by the infinite ter m f ( f ( . . . )) . This is indeed a chain since all infinite terms are filter ed aw a y by the refined argument filter π ′ . Hence, the termination pro of fa ils. Using the outer most re finemen t heuristic ρ om instead, for the second DP (6) we get ρ om ( U 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) , 121 ) = ( U 1 , 1 ) , i.e., π ′ ( U 1 ) = { 2 , 3 } . Considering the third DP (7) we have to filter aw ay the firs t argument of P in , i.e., π ′ ( P in ) = { 2 } . Due to the DP (6), we now als o have to r emo ve the seco nd argument of U 1 , i.e., π ′ ( U 1 ) = { 3 } . So we obtain the same infinite chain as ab o ve since we lose the information ab out finitenes s of p ’s first argument. Hence, we ag ain cannot show termination. A slightly improv ed version of the outermos t refinement heuristic can be achiev ed by disallowing the filtering of the first arguments o f the symbols u c,i and U c,i . Definition 5.5 (Impr ove d Outermost R efinement Heuristic) . Let t b e a term and p os b e a p osition in t . The impr ove d outermost r efin ement heuristic ρ om ′ is defined as: ρ om ′ ( t, i p os ) = ( ρ om ′ ( t | i , p os ) if i = 1 and either ro ot( t ) = u c,i or r oo t( t ) = U c,i (ro ot( t ) , i ) otherwise Example 5. 6. Reco nsider Exa mple 5 .4. Using the impr o ved o utermost r efine- men t heuristic, for the s e cond rule (2 ) we get ρ om ′ ( u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) , 121 ) = ρ om ′ ( p in ( f ( X ) , f ( Z )) , 21 ) = ( p in , 2 ) r equiring us to filter awa y the second argument of p in , i.e., π ′ ( p in ) = { 1 } . Cons e quen tly , the alg orithm filters awa y the third arguments of b oth u 1 and u 2 , i.e., π ′ ( u 1 ) = { 1 , 2 } and π ′ ( u 2 ) = { 1 , 2 , 4 } . Now the v ar iable condition holds for R P . Therefore, b y defining π ′ ( P in ) = π ′ ( p in ) , π ′ ( u 1 ) = π ′ ( U 1 ) , and π ′ ( u 2 ) = π ′ ( U 2 ) , the v a riable condition also holds for DP ( R P ) . (As ment ioned at the end of Section 5.1, by filtering tuple symbols F in the same wa y as the original symbo ls f and b y ensuring 1 ∈ π ′ ( u c,i ) , it s uffices to chec k the v aria ble condition only for the rules R P and not for the dep endency pairs D P ( R P ) .) This argument filter cor respo nds to the one ch osen in Example 4.6 and as shown in Sec tio n 4 .2 one c a n now easily pr ove termination. AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 24 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann 5.3 T yp e-Based R e finement Heuristic The improved outermos t heur istic from Section 5.2 o nly filters symbols o f the form p in , p out , P in , and P out . Ther efore, the generated ar gumen t filters ar e similar to mo dings. Howev er , there a re cases where one needs to filter function s ym bols from the o riginal logic progr am, to o. In this s ection we show how to o btain a more powerful r efinemen t heuristic using infor mation from inferred types. There a re many approa ches to (dir ect) ter mination analysis of logic progr ams that use type informatio n in orde r to guess suitable “norms” or “rank ing functions” , e.g., [Bossi et al. 19 9 2; Bruyno oghe et a l. 2007 ; Decorte et a l. 19 93; Mar tin et a l. 1996]. In contrast to most o f these appro ac hes, we do no t co nsider typed log ic progra ms, but unt yp ed ones and we use types only as a basis for a heuristic to prov e termination of the transfor med TRS. T o our knowledge, this is the first time that t yp es are co nsidered in the tr ansformational approa c h to terminatio n a nalysis of logic progr ams. Example 5. 7. Now we rega rd the logic progra m from Exa mple 1.3. The rules after the transfor mation o f Definition 3.1 ar e: p in ( X, X ) → p out ( X, X ) (1) p in ( f ( X ) , g ( Y )) → u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (2) u 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → u 2 ( p in ( Z, g ( W )) , X , Y , Z ) (10) u 2 ( p out ( Z, g ( W )) , X , Y , Z ) → p out ( f ( X ) , g ( Y )) (11) Using the improv ed outer mo st refinement heur istic ρ om ′ we start off as in Exa m- ple 5.6 and obtain π ′ ( p in ) = { 1 } , π ′ ( u 1 ) = { 1 , 2 } , and π ′ ( u 2 ) = { 1 , 2 , 4 } . How ever, due to the la s t rule (11) we now get ρ om ′ ( p out ( f ( X ) , g ( Y )) , 21 ) = ( p out , 2 ) , i.e., π ′ ( p out ) = { 1 } . Cons ider ing the third rule (1 0), we have to filter p in once mo re and obtain π ′ ( p in ) = ∅ . So we aga in lose the informatio n ab out finiteness of p ’s fir st argument and ca nnot show termination. Similar to Example 5.4, the inner most refinement heuristic which filters aw ay the only argument of f also fails for this progra m. So in the example ab ov e, neither the innermost nor the (improved) outermost refinement heuristic succeed. W e ther efore pro pose a better heuristic which is like the innermo s t refinement heuristic, but which avoids the filtering of certain arguments o f original function symbols fr om the lo gic progr am. Clo se inspe c tion of the cases where filtering such function symbols is required reveals that it is not advisable to filter aw ay “reflexive” ar gumen ts. Here, we call an arg umen t p osition i of a function symbol f r eflexive (or “ r e cursive ”), if the arguments on p osition i hav e the same “type” as the w ho le term f ( . . . ) itse lf, cf. [W alther 1994 ]. A typ e assignment asso ciates a predicate p/n with an n -tuple of types for its arguments and, similar ly , a function f / n with an ( n + 1 )-tuple where the last e le men t sp ecifies the r esult t yp e of f . Definition 5.8 (T yp es) . Let Θ b e a set o f t yp es (i.e., a set of names). A typ e assignment τ ov er a signa ture (Σ , ∆) and a set of types Θ is a mapping τ : Σ ∪ ∆ → Θ ∗ such that τ ( p/n ) ∈ Θ n for a ll p / n ∈ ∆ and τ ( f /n ) ∈ Θ n +1 for a ll f /n ∈ Σ. Let f /n ∈ Σ be a function s ym bol a nd τ b e a type ass ignmen t with τ ( f ) = AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 25 ( θ 1 , . . . , θ n , θ n +1 ). Then the set of r eflex ive p ositions of f /n is Re flexive τ ( f /n ) = { i | 1 ≤ i ≤ n and θ i = θ n +1 } . T o infer a suitable type a ssignmen t for a logic prog ram, we use the following simple alg orithm. How ever, since we only use types as a heuristic to find suitable argument filters, any o ther type a ssignment would also yie ld a corr ect metho d for termination analysis. In other words, the choice of the t yp e a s signmen t only influences the p o wer of o ur metho d, not its soundness. So unlike [Br uynoog he et al. 20 07], the correc tnes s of our appr o ac h do es not dep end on the logic program or the query b eing well-t yped. Mor e sophisticated type inference algo rithms w ere presented in [Br uynoo g he et al. 2 005; Chara tonik and Po delski 19 98; Gallagher a nd Puebla 20 02; Janssens and B ruynoo ghe 19 92; Lu 20 00; V aucheret and B ueno 2 002], for exa mple. In our simple type infere nce algor ithm, w e define ≃ as the r eflexiv e and transi- tive closure of the following “similarity” relation o n the argument po sitions: Two argument po sitions of (po ssibly differe n t) function or pr edicate sy m bols are “simi- lar” if there exists a prog ram clause such that the argument p ositions are o ccupied by identical v ariables. Moreover, if a term f ( . . . ) o ccurs in the i - th p osition of a function or predic a te symbol p , then the argument p osition of f ’s result is similar to the i -th argument po sition of p . (F or a function symbol f /n we also co nsider the a rgumen t p osition n + 1 which stands for the result of the function.) After having computed the relation ≃ , we then use a t yp e assignment which corresp onds to the equiv alence classes imp osed by ≃ . So o ur simple type inference algo rithm is related to sharing analy sis [Br uynoog he et al. 1996; Co rtesi a nd Fil´ e 1999 ; Lago on and Stuc key 2 002], i.e., the pro gram analysis tha t aims at detecting pro gram v ar i- ables that in some program execution might b e bo und to terms having a co mmon v aria ble. Example 5. 9. As a n e x ample, we compute a suitable type assignment for the logic program from Example 1 .3 : p ( X , X ) . p ( f ( X ) , g ( Y )) :– p ( f ( X ) , f ( Z )) , p ( Z , g ( W )) . Let p i denote the i - th a rgument p osition of p , etc. Then due to the first cla use we obtain p 1 ≃ p 2 , since bo th a rgumen t p ositions ar e o ccupied b y the v a riable X . Moreov er, since Z o ccurs b oth in the first a r gumen t p ositions o f f a nd p in the second c la use, we also hav e p 1 ≃ f 1 . Finally , since an f -term o ccurs in the first and second a rgument of p and since a g -term o ccurs in the second argument of p we also have f 2 ≃ p 1 ≃ p 2 and g 2 ≃ p 2 . In other words, the re la tion ≃ imp oses the tw o e q uiv alence classe s { p 1 , p 2 , f 1 , f 2 , g 2 } and { g 1 } . Hence, w e compute a t yp e assignment with t wo types a and b w her e a and b corres pond to { p 1 , p 2 , f 1 , f 2 , g 2 } and { g 1 } , r e spectively . Thu s, the type assignment is defined a s τ ( p ) = τ ( f ) = ( a, a ) and τ ( g ) = ( b, a ) . Note that the firs t argument of f has the same type a as its result and hence, this argument pos ition is reflexive. On the other hand, the first argument of g has a different type than its result and is therefore not reflexive. Hence, Reflexive τ ( f ) = { 1 } and R eflexive τ ( g ) = ∅ . Now w e can define the following heuristic base d on t ype a s signmen ts. It is like AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 26 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann the innermo st refinement heuristic of Definition 5.3, but now reflexive arguments of function s y m bols from Σ (i.e., from the original lo gic prog ram) ar e not filtered aw a y . Definition 5.10 (T yp e-b ase d R efinement Heuristic) . Let t b e a term, let “ p os i ” be a p osition in t , and let τ be a type as signmen t. The typ e-b ase d r efinement heuristic ρ τ tb is defined as follows: ρ τ tb ( t, p os i ) = (ro ot( t | p os ) , i ) if ro ot( t | p os ) / ∈ Σ or i / ∈ R eflex ive τ (ro ot( t | p os )) ρ τ tb ( t, p os ) otherwise Note that the heuristic ρ τ tb never filters aw ay the first argument of a symbol u c,i or U c,i from the TRSs D P ( R P ) and R P . Therefore, a s mentioned at the end o f Section 5 .1 , we o nly hav e to chec k the v ariable condition for the rules of R P , but not for the dep endency pair s. Example 5. 11. W e contin ue with the logic progra m from Example 1.3 and use the type assig nmen t computed in Ex ample 5.9 ab ov e. The rules a fter the tr ansfor- mation of Definition 3.1 a re the following, cf. Example 5.7. p in ( X, X ) → p out ( X, X ) (1) p in ( f ( X ) , g ( Y )) → u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (2) u 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → u 2 ( p in ( Z, g ( W )) , X , Y , Z ) (10) u 2 ( p out ( Z, g ( W )) , X , Y , Z ) → p out ( f ( X ) , g ( Y )) (11) Due to the o ccurr e nce of Z in the r igh t-hand side of the seco nd rule (2), we compute: ρ τ tb ( u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) , 121) = ρ τ tb ( u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) , 12) as f ∈ Σ and 1 ∈ R eflexive τ ( f ) = ( p in , 2 ) as p in 6∈ Σ Thu s, we filter aw ay the second argument of p in , i.e., π ′ ( p in ) = { 1 } . Consequently , we obtain π ′ ( u 1 ) = { 1 , 2 } and π ′ ( u 2 ) = { 1 , 2 , 4 } . Considering the fourth rule (1 1) we compute: ρ τ tb ( p out ( f ( X ) , g ( Y )) , 21 ) = ( g , 1) as 1 6∈ R eflexive τ ( g ) Thu s, we filter awa y the only ar gumen t o f g , i.e., π ′ ( g ) = ∅ . By filter ing the tuple symbols in the same wa y as the cor respo nding “ lo wer-case” symbols, now the v aria ble condition ho lds for R P and therefo r e also for D P ( R P ) . Indeed, this is the ar gumen t filter chosen in Ex a mple 4.6. With this filter, o ne can eas ily prov e termination o f the progra m, c f. Section 4.2. F or the ab ov e example, it is sufficient only to avoid the filtering o f reflexive po sitions. How ever, in g eneral one should also avoid the filtering of all “unbounded” argument p ositions. An a rgumen t po sition of type θ is “ un bounded” if it may contain subterms from a r ecursive data structure, i.e., if there e xist infinitely many terms of type θ . The decrease of the terms o n such ar gumen t p ositions might b e the reason for the ter mination of the progr am and there fo re, they should not b e filtered aw ay . T o formaliz e the concept of unbo unded arg umen t p ositions, we define the set o f c onstructors of a type θ to consis t of all function symbols whose r esult AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 27 has type θ . Then an arg umen t p osition of a function symbol f is unb ounde d if it is reflexive or if it has a type θ with a constr uctor that has a n unbounded ar gumen t po sition. F or the sa k e of brevity , w e also sp eak of just unb oun de d p ositions when referring to unbounded arg umen t p ositions. Definition 5.12 (Un b ounde d Positions) . Let θ ∈ Θ b e a type and τ b e a type as- signment. A function symbol f /n with τ ( f /n ) = ( θ 1 , . . . , θ n , θ n +1 ) is a c ons t ructor of θ iff θ n +1 = θ . Let Constructors τ ( θ ) b e the set of all constr uctors of θ . F or a function symbol f / n as ab o ve, we define the set of unb ounde d p ositions as the smallest set such that R eflex ive τ ( f /n ) ⊆ Unb ou n de d τ ( f /n ) a nd suc h that i ∈ Unb ounde d τ ( f /n ) if there is a g /m ∈ C onstructor s τ ( θ i ) and a 1 ≤ j ≤ m with j ∈ Unb ounde d τ ( g /m ). In the logic progr am fro m Ex a mples 1.3 and 5.9 , we had τ ( p ) = τ ( f ) = ( a, a ) and τ ( g ) = ( b, a ). Thus, Construct ors τ ( a ) = { f , g } and Constructors τ ( b ) = ∅ . Since the first argument p osition o f f is reflexive, it is a ls o unbounded. The first argument po sition of g is not unbounded, since it is not reflexive and there is no constructor of type b with a n un b ounded arg umen t pos ition. So in this example, there is no difference betw een re fle x iv e a nd unbounded p o sitions. How ever, we will show in E x ample 5.14 tha t ther e are pro grams whe r e these tw o notions differ. F or tha t rea s on, we now improv e our t yp e-based refinement heuristic and disallow the filtering of unbo unded (instead of just reflexive) p ositions. Definition 5.13 (Impr ove d T yp e-b ase d R efinement Heuristic) . Let t be a term, let “ p os i ” b e a p osition in t , and let τ b e a type assignment. The impr ove d t yp e- b ase d r efi n ement heuristic ρ τ tb ′ is defined as follows: ρ τ tb ′ ( t, p os i ) = (ro ot( t | p os ) , i ) if ro ot( t | p os ) / ∈ Σ or i / ∈ Unb ounde d τ (ro ot( t | p os )) ρ τ tb ′ ( t, p os ) otherwise Example 5. 14. The following log ic program inv erts an integer represented b y a sign ( neg or po s ) and by a natural n umber in Peano notation (using s and 0 ). So the int eger num b e r 1 is represented by the term p os ( s ( 0 )) , the in teger num b er − 1 is r e pr esen ted by neg ( s ( 0 )) , and the integer num b er 0 ha s the tw o repres en tations p o s ( 0 ) and ne g ( 0 ) . Here nat ( t ) ho lds iff t r epresent s a natura l num ber (i.e., if t is a term containing just s and 0 ) and inv simply exchanges the function symbols neg and p o s . The main pr edicate s a feinv p erforms the desired inversion where safeinv ( t 1 , t 2 ) only holds if t 1 really represents an int eger nu mber a nd t 2 is its inv ersion. nat ( 0 ) . nat ( s ( X )) :– nat ( X ) . inv ( ne g ( X ) , p os ( X )) . inv ( p os ( X ) , neg ( X )) . safeinv ( X, neg ( Y )) :– inv ( X , neg ( Y )) , nat ( Y ) . safeinv ( X, p os ( Y )) :– in v ( X , p os ( Y )) , nat ( Y ) . AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 28 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann The rules after the tr ansformation of Definition 3 .1 a re: nat in ( 0 ) → nat out ( 0 ) (12) nat in ( s ( X )) → u 1 ( nat in ( X ) , X ) (13) u 1 ( nat out ( X ) , X ) → nat out ( s ( X )) (14) inv in ( neg ( X ) , p os ( X )) → inv out ( neg ( X ) , p os ( X )) (15) inv in ( po s ( X ) , neg ( X )) → i nv out ( po s ( X ) , neg ( X )) (16) safeinv in ( X, ne g ( Y )) → u 2 ( inv in ( X, ne g ( Y )) , X , Y ) (17) u 2 ( inv out ( X, ne g ( Y )) , X , Y ) → u 3 ( nat in ( Y ) , X , Y ) (18) u 3 ( nat out ( Y ) , X , Y ) → safeinv out ( X, ne g ( Y )) (19) safeinv in ( X, p os ( Y )) → u 4 ( inv in ( X, p os ( Y )) , X , Y ) (20) u 4 ( inv out ( X, p os ( Y )) , X , Y ) → u 5 ( nat in ( Y ) , X , Y ) (21) u 5 ( nat out ( Y ) , X , Y ) → safeinv out ( X, p os ( Y )) (22) Let us assume that the user w ants to prov e termination of all quer ies safeinv ( t 1 , t 2 ) where t 1 is ground. So we use the mo ding m ( safei n v , 1) = i n and m ( safeinv , 2 ) = out . Thu s, as initial a rgumen t filter π w e hav e π ( safeinv ) = { 1 } and hence π ( safeinv in ) = π ( SAFEINV in ) = { 1 } , while π ( f /n ) = { 1 , . . . , n } for all f / ∈ { safeinv , safeinv in , SAFEINV in } . In Rule (17) one ha s to filter aw ay the second arg umen t of inv in or the o nly argument of ne g in order to remov e the “e xtra” v ar iable Y on the right-hand s ide. F rom a type infer ence for these rules we obtain the type as signmen t τ with τ ( s ) = ( b, b ) , τ ( 0 ) = ( b ) , and τ ( neg ) = τ ( po s ) = ( b, a ) . So “ a ” corres ponds to the type of in tegers and “ b ” cor respo nds to the type of natura ls. The constructo rs of the natura ls are Const ru ctors τ ( b ) = { s , 0 } . This is a recur siv e da ta struc tur e since s has an unbounded argument: 1 ∈ Reflexive τ ( s ) ⊆ Unb ounde d τ ( s ) . Thus, while neg ’s first ar gumen t po s ition of type b is no t reflexive, it is still unbounded, i.e., 1 ∈ Unb ounde d τ ( neg ) . Hence, our improv ed type- based heuristic decides to filter aw ay the se c o nd argument o f inv in (as in v in is not fro m the o riginal signature Σ ). Now termination is ea s y to show. If one had considered the o r iginal type-bas ed heuristic instead, then the non- reflexive first argument of neg would b e filter e d aw ay . Due to Rule (17), then also the last argument of u 2 has to b e remov ed by the filter. But then the v ar iable Y would not occ ur anymore in the filtered left-hand side of Rule (18). So to satisfy the v aria ble condition for Rule (18), we would hav e to filter aw ay the o nly arg umen t of nat in . Similarly , the only arg umen t of the co rresp onding tuple symbol NA T in would also b e filtered aw ay , blo cking any po ssibilit y for a succes sful terminatio n pro of. 5.4 Mo de Anal ysi s based on Argument Fil ters and an Improved Re finement Algorithm In log ic progra mming, it is not unusual that a predicate is used with different mo des (i.e., that different o ccurrences of the predicate have different input a nd output po sitions). Uniquenes s of mo ding ca n then b e achieved by c r eating appropria te copies o f these predica te symbols and their clauses for every different mo ding. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 29 Example 5. 15. Co nsider the following logic progra m fo r ro tating a list taken from [Co dish 200 7]. Let P b e the app end -pro gram co nsisting o f the clauses fro m Example 1.4 and the new clause rotate ( N , O ) :– app end ( L , M , N ) , app end ( M , L , O ) . (23) with the mo ding m ( rotate , 1 ) = i n a nd m ( rotate , 2) = o ut . F or this mo ding, the progra m is terminating. But while the first use o f app end in Clause (23) supplies it with a ground term only on the last arg umen t p osition, the second use in (23) is with ground terms only o n the fir st t wo argument p ositions. Although the a ppend -cla uses are even well mo ded for b oth k inds of uses, the who le progr am is not. The logic prog ram is trans formed into the following TRS. As b efore, “ [ X | L ] ” is an abbr eviation for • ( X, L ) , i.e., • is the constructor for list insertion. app end in ([ ] , M , M ) → app end out ([ ] , M , M ) (24) app end in ( • ( X, L ) , M , • ( X, N )) → u 1 ( app end in ( L, M , N ) , X , L, M , N ) (25) u 1 ( app end out ( L, M , N ) , X , L, M , N ) → ap pend out ( • ( X, L ) , M , • ( X, N )) (26) rotate in ( N , O ) → u 2 ( app end in ( L, M , N ) , N , O ) (27) u 2 ( app end out ( L, M , N ) , N , O ) → u 3 ( app end in ( M , L, O ) , L, M , N , O ) (28) u 3 ( app end out ( M , L, O ) , L, M , N , O ) → rotate out ( N , O ) (29) Due to the “ex tra” v a riables L and M in the right-hand side of Rule (27) a nd the “extra” v aria ble O in the rig h t-hand side of Rule (28 ), 11 the o nly refined a rgument filter which would satisfy the v ar iable condition of Coro llary 4.5 is the one w he r e π ( append in ) = ∅ . 12 As we can exp ect, for the queries desc ribed by this filter, the app end -progra m is not terminating and, th us, our new approach fails, to o. The common solution [Apt 1997 ] is to pr oduce tw o co pies of the app end -clauses and to r e na me them a part. This is often referr e d to as “ mode-splitting” . First, we create la belled copies o f the predicate symbol app end and lab el the predicate of each app end -atom by the input p ositions o f the mo ding in w hich it is used. Then, we extend our mo ding to m ( app end { 3 } , 3 ) = m ( app end { 1 , 2 } , 1 ) = m ( app end { 1 , 2 } , 2 ) = in and m ( app end { 3 } , 1 ) = m ( app end { 3 } , 2 ) = m ( app end { 1 , 2 } , 3 ) = out . In our example, termination of the resulting logic prog r am can easily b e shown using b oth the cla ssical transforma tion from Section 1.1 o r our new trans formation: rotate ( N , O ) :– append { 3 } ( L , M , N ) , app end { 1 , 2 } ( M , L , O ) . app end { 3 } ([ ] , M , M ) . app end { 3 } ([ X | L ] , M , [ X | N ]) :– app end { 3 } ( L , M , N ) . app end { 1 , 2 } ([ ] , M , M ) . app end { 1 , 2 } ([ X | L ] , L , [ X | N ]) :– a ppend { 1 , 2 } ( L , M , N ) . 11 In the left-hand side of Rule (27), the v ariable O in the second argument of rotate in is remov ed b y the ini tial filter that describ es the desired set of queries given by the user. Consequently , one also has to filter aw ay the last argument of u 2 . Hence, then O is indeed an “extra” v ariable i n the right-han d side of R ule (28). 12 Alternativ ely , one could also filter aw a y the first argumen ts of u 2 and u 3 . But then one wo uld also hav e to satisfy the v ar i able condition for the dep enden cy pairs and one would ob- tain π ( APPEND in ) = ∅ . H enc e, the termination pro of attempt would fail as we ll. AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 30 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann In the example ab o ve, a pr e-pro cessing based on mo dings was sufficie nt for a suc- cessful termination pr oof. In general, thoug h, this is insufficient to handle queries describ ed by an argument filter. T he following exa mple demo nstrates this. Example 5. 16. Co nsider again the log ic progr am P from Example 5.15 w hich is transla ted to the TRS R P = { (24) , . . . , (29) } . This time we wan t to show ter- mination for all queries of the for m rotate ( t 1 , t 2 ) w he r e t 1 is a finite list (pos sibly containing non-gr ound terms as elements). So t 1 is instantiated b y terms of the form • ( r 1 , • ( r 2 , . . . • ( r n , [ ]) . . . )) where the r i can b e arbitrary terms po ssibly containing v aria bles. 13 T o sp ecify these quer ies, the user would pr ovide the initial ar gumen t filter π with π ( rotate ) = { 1 } and π ( • ) = { 2 } . No w our aim is to prove termina tion of a ll queries that ar e ground under the filter π . Thus, the first a rgumen t of rotate is not necessarily a ground ter m (it is only guaranteed to b e g r ound after filter ing aw ay the s e cond argument of • ). Therefore, if one want ed to pr e-pro cess the prog r am us ing mo dings, then one could no t assume that the first a rgument of rotate were ground. Ins tea d, one would hav e to use the mo ding m ( rotate , 1) = m ( rotate , 2) = out . Ther efore, in the c a lls to app end , all arg umen t p ositions would be considered as “ out ” . As a consequence, no renamed-apa rt co pie s of clauses would b e created a nd the termination pro of would fail. In g eneral, our refinement algor ithm from Section 5.1 (Algo r ithm 1) aims to compute an arg umen t filter that filter s aw ay as few arguments a s p ossible while ensuring that the v ariable condition holds. In this way we make sure that the maximal a moun t of information r emains fo r the following ter mina tion analysis. But as Ex a mples 5.15 and 5.1 6 ab o ve demonstrate, ther e a re case s where we need to create r enamed-apart copies o f cla us es for certain pr edicates in order to obtain a viable r efined ar gumen t filter. T o this e nd, a fir s t idea might b e to com bine a n existing mo de inference algorithm with Algo r ithm 1 . How ev er, it is no t clea r how to do such a combination. The pr oblem is that we a lready need to know the refined argument filter in o rder to cr eate suitable copies of clauses. At the same time, we already need the renamed-a part copies o f the clauses in or der to compute the re fined argument filter. Th us, we ha ve a classical “chick en- and-egg” problem. Mo reov er , such a n approach would alwa ys fail for prog rams like Example 5.16 where there exists no suitable pre-pro cessing based on moding s. Therefore, we r eplace Algor ithm 1 by the following new Algorithm 2 tha t simul- taneously refines the ar gumen t filter and cr e a tes r enamed-apart copies on demand. The idea of the algorithm is the following. Whenev er our refinement heuristic suggests to filter aw ay an arg umen t of a symbol p in , then instead of changing the 13 Suc h a termination problem can also result from an initial termi nation problem that was de- scrib ed by mo dings. T o demonstrate this, we could extend the pr ogram by the following clauses. p ( X, O ) :– s2 ℓ ( X, N ) , rotate ( N , O ) . s2 ℓ (0 , [ ]) . s2 ℓ ( s ( X ) , [ Y | N ]) : – s2 ℓ ( X, N ) . T o prov e termination of all queries describ ed by the mo ding m ( p , 1) = in and m ( p , 2) = out , one essen tially has to s ho w termination for all queries of the form rotate ( t 1 , t 2 ) where t 1 is a finite list. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 31 Input : arg umen t filter π , refinement heuristic ρ , TRS R P Output : refined argument filter π ′ and mo dified TRS R ′ P such that π ′ ( R ′ P ) satisfies the v ariable condition 1. R ′ P := R P ∪ { ℓ π ( p ) → r π ( p ) | ℓ → r ∈ R P ( p ) , p/n ∈ ∆ , π ( p ) ( { 1 , . . . , n }} 2. π ′ ( f ) := π ( f ) , for a ll f ∈ Σ (i.e., for functions o f P ) I , for a ll f = p I in with p ∈ ∆ { 1 , . . . , n } , for a ll other symbols f /n 3. If ther e is a rule ℓ → r fro m R ′ P and a po sition p os with r | p os ∈ V ( π ′ ( r )) \ V ( π ′ ( ℓ )), then: 3.1. Let ( f , i ) b e the result of ρ ( r, p os ), i.e., ( f , i ) := ρ ( r , p os ). 3.2. W e p erform a ca se analysis depe nding on whether f has the form p I in for s ome p ∈ ∆. Here, unlab elled symbo ls of the form p in /n are treated as if they were lab elled with I = { 1 , . . . , n } . • If f = p I in , then we mu st hav e r = u ( p I in ( ... ) , . . . ) for s o me symbol u . W e introduce a new function symbol p I \{ i } in with π ′ ( p I \{ i } in ) = I \ { i } if it has not yet b een intro duced. Then: ◦ W e r e place p I in by p I \{ i } in in the right-hand side of ℓ → r : R ′ P := R ′ P \ { ℓ → r } ∪ { ℓ → r } , where r = u ( p I \{ i } in ( ... ) , . . . ). ◦ R ′ P := R ′ P ∪ { s I \{ i } → t I \{ i } | s → t ∈ R ′ P ( p ) } . If this in tro duces new la belled function symbols f /n where π ′ was no t yet de fined on, we define π ′ ( f ) = { 1 , . . . , n } . ◦ Let ℓ ′ → r ′ be the rule in R ′ P with ℓ ′ = u ( p I out ( ... ) , . . . ). W e now r e place p I out by p I \{ i } out in the left-hand side o f ℓ ′ → r ′ : R ′ P := R ′ P \ { ℓ ′ → r ′ } ∪ { ℓ ′ → r ′ } , where ℓ ′ = u ( p I \{ i } out ( ... ) , . . . ). • Otherw is e (i.e., if f does not hav e the form p in or p I in ), then mo dify π ′ by removing i from π ′ ( f ), i.e., π ′ ( f ) := π ′ ( f ) \ { i } . 3.3. Go back to Step 3 . Algorithm 2 : Improved Refinement Algor ithm argument filter a ppropriately , we introduce a new copy o f the s ym bol p in . T o distinguish the different copies of the symbols p in , we lab el them by the argument po sitions that are not filtered aw ay . In genera l, a r emo v al of ar gumen t p ositions of p in can alr eady b e p e r formed by the initial filter π that the user provides in or der to describ e the desir ed set of quer ies. Therefore, if π ( p ) do es not contain all arguments { 1 , . . . , n } for some AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 32 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann predicate sy m bol p/n , then we already intro duce a new symbo l p π ( p ) in and new copie s of the rewrite rules orig inating fr om p . In these rules, we use the new symbol p π ( p ) in instead of p in . Let us reconsider Example 5 .16. T o prove termination o f a ll queries rotate ( t 1 , t 2 ) with a finite list t 1 , the user would select the a rgumen t filter π that elimina tes the second argument of rotate and the first argument of the list constr uctor • . So we hav e π ( rotate ) = { 1 } , π ( • ) = { 2 } , and π ( app end ) = { 1 , 2 , 3 } . Then in addition to the rules (27) - (29) for the symbol ro ta te in we also intro duce the symbo l rotate { 1 } in . Moreov er, in or de r to ens ur e that rotate { 1 } in do es the sa me computation a s rotate in , we a dd the following co pies of the r e write rules (27) - (29) orig inating from the predicate rotate . Here, all ro ot symbols of left- a nd right-hand sides are la b elled with { 1 } . rotate { 1 } in ( N , O ) → u { 1 } 2 ( app end in ( L, M , N ) , N , O ) (30) u { 1 } 2 ( app end out ( L, M , N ) , N , O ) → u { 1 } 3 ( app end in ( M , L, O ) , L, M , N , O ) (31) u { 1 } 3 ( app end out ( M , L, O ) , L, M , N , O ) → rotate { 1 } out ( N , O ) (32) So in Step 1 of the algor ithm, we initialize R ′ P to contain all rules of R P . But in addition, R ′ P contains lab elled co pies of the rules resulting from those predicates p/n where π ( p ) ( { 1 , . . . , n } . In these rules, the ro ot symbols of left- a nd right-hand sides a r e lab elled with π ( p ). F or mally , for every pr edicate sy m bol p ∈ ∆, let R P ( p ) deno te tho s e rules of R P which result from p -clause s (i.e., from clauses whose head is built with the pr edicate p ). So R P ( rotate ) consists of the rule fo r rota te in and the rules for u 2 and u 3 , i.e., R P ( rotate ) = { (27 ) , (28) , (29) } . Then for a term t = f ( t 1 , . . . , t n ) a nd a set of a rgumen t p ositions I ⊆ N , let t I denote f I ( t 1 , . . . , t n ). So for t = rotate in ( N , O ) a nd I = { 1 } , we hav e t I = rotate { 1 } in ( N , O ). Hence if π ( rotate ) = { 1 } , then we extend R ′ P by copies of the rules in R P ( rotate ) where the ro ot symbols are lab elled by { 1 } . In other words, we hav e to add the rules { ℓ π ( p ) → r π ( p ) | ℓ → r ∈ R P ( rotate ) } = { (3 0) , (31) , (32 ) } . In Step 2 , we initialize our desired argument filter π ′ . This filter do es no t yet eliminate any ar gumen ts exc ept for original function s y m bols from the logic program and for symbols of the form p I in . Since in our example, the initial ar gumen t filter π of the user is π ( rotate ) = { 1 } , we have π ′ ( rotate in ) = { 1 , 2 } , but π ′ ( rotate { 1 } in ) = { 1 } . So for symbols p I in , the lab el I describ es those ar g umen ts that ar e no t filtered aw ay . How ever, this do es not hold for the other lab elled s y m bols. So the labe lling o f the symbols u { 1 } 2 , u { 1 } 3 , and a p pend { 1 } out only repr e sen ts that they “b elong” to the symbol rotate { 1 } in . But the arg umen t filter for these symbols can b e determined arbitrar ily . Initially , π ′ would not filter aw ay a n y of their arg umen ts, i.e., π ′ ( u { 1 } 2 ) = { 1 , 2 , 3 } , π ′ ( u { 1 } 3 ) = { 1 , 2 , 3 , 4 , 5 } , and π ′ ( rotate { 1 } out ) = { 1 , 2 } . The filter for original function symbols of the logic pro gram is taken fro m the user-defined a rgumen t filter π . So since the user descr ibed the des ired set o f quer ies by setting π ( • ) = { 2 } , we also hav e π ′ ( • ) = { 2 } . In Steps 3 and 3 .1 , we lo ok for rules violating the v ariable co ndition as in Algorithm 1 . Ag ain, we use a re finement heur istic ρ to sug gest a suitable function AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 33 symbol f and an a rgumen t p osition i that should be filtered aw a y . As b e fo re, we restrict o urselves to re finement heuristics ρ which never select the first argument of a symbol u c,i . In this w ay , w e only ha ve to examine the rules (and not also the depe ndency pair s) for p ossible violations of the v aria ble condition. If f is not a (po ssibly labelle d) symbol of the for m p in or p I in , then w e pr oceed in Step 3. 2 as befor e (i.e., as in Step 2 .2 of Algorithm 1). But if f is a (p ossibly lab elled) symbol of the form p in or p I in , then we do not modify the filter for f . If I are the non-filtered arg ument p ositions of f , then we in tro duce a new function symbol lab elled with I \ { i } instead and replace f by this ne w function symbo l in the r ule that v iolated the v aria ble condition. In o ur example, we had R ′ P = { (24) , . . . , (29 ) , (30) , (31) , (32) } and π ′ was the filter that do es no t eliminate a n y a rgumen ts exce pt for π ′ ( rotate { 1 } in ) = { 1 } and π ′ ( • ) = { 2 } . The rules (25), (27 ), and (30 ) viola te the v ariable co ndition. In the following, we mark the viola ting v ariables by b oxes. Let us re g ard Rule (2 5) first: app end in ( • ( X, L ) , M , • ( X, N )) → u 1 ( app end in ( L, M , N ) , X , L, M , N ) (25) T o r emo ve the v ariable X from the right-hand side, in Step 3.1 any refinement heuristic m ust suggest to filter aw ay the second arg umen t of u 1 . As u 1 do es not hav e the for m p I in , we use the second case o f Step 3.2 . Thus, we change π ′ such that π ′ ( u 1 ) = { 1 , 2 , 3 , 4 , 5 } \ { 2 } = { 1 , 3 , 4 , 5 } . Indeed, now this r ule do es not violate the v ariable condition anymore. W e reach Step 3.3 and, thus, go back to Step 3 where we again choose a r ule that v iolates the v ariable condition. Let us now reg ard Rule (30): rotate { 1 } in ( N , O ) → u { 1 } 2 ( app end in ( L , M , N ) , N , O ) (30) T o remov e the fir st violating v ariable L , in Step 3.1 o ur refinement heur istic sug- gests to filter aw a y the firs t argument of the symbo l app end in . But instea d of chang- ing π ′ ( app end in ), we intro duce a new symbol app end { 2 , 3 } in with π ′ ( app end { 2 , 3 } in ) = { 2 , 3 } . Moreover, we replace the s ym bol app end in in the right-hand side o f Rule (30) by the new s ym bol app end { 2 , 3 } in . Thus, Rule (3 0) is mo dified to rotate { 1 } in ( N , O ) → u { 1 } 2 ( app end { 2 , 3 } in ( L, M , N ) , N , O ) . (33) T o make sure that append { 2 , 3 } in has rewrite rules cor r esponding to the rule s of app end in , w e now have to add copies of a ll r ules that r e sult from the app end - predicate. How ever, here we lab el every ro ot sym b ol by { 2 , 3 } . In other w ords, we hav e to add the following r ules to R ′ P : app end { 2 , 3 } in ([ ] , M , M ) → app end { 2 , 3 } out ([ ] , M , M ) (34) app end { 2 , 3 } in ( • ( X, L ) , M , • ( X, N )) → u { 2 , 3 } 1 ( app end in ( L, M , N ) , X , L, M , N ) (35) u { 2 , 3 } 1 ( app end out ( L, M , N ) , X , L, M , N ) → app end { 2 , 3 } out ( • ( X, L ) , M , • ( X, N )) (36) Now the result of rewriting a ter m appen d { 2 , 3 } in ( . . . ) will always be a term o f the form a ppend { 2 , 3 } out ( . . . ). There fore, we hav e to r e place app end out by app end { 2 , 3 } out in the left-hand side of Rule (31) (since (3 1) is the r ule that a lways “follows” (30)). AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 34 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann So the origina l rule (31) u { 1 } 2 ( app end out ( L, M , N ) , N , O ) → u { 1 } 3 ( app end in ( M , L, O ) , L, M , N , O ) (31) is repla ced by the mo dified rule u { 1 } 2 ( app end { 2 , 3 } out ( L, M , N ) , N , O ) → u { 1 } 3 ( app end in ( M , L, O ) , L, M , N , O ) . (37) Thu s, after the ex ecution o f Step 3.2 , we have R ′ P = { (24) − (2 9) , (33) − (36 ) , (37) , (32) } . In this way , we hav e introduced three new lab elled symbols a p pend { 2 , 3 } in , u { 2 , 3 } 1 , and app end { 2 , 3 } out . On the unlabelled symbo ls , the argument filter π ′ did not change, but we now additionally hav e π ′ ( app end { 2 , 3 } in ) = { 2 , 3 } , π ′ ( u { 2 , 3 } 1 ) = { 1 , 2 , 3 , 4 , 5 } , and π ′ ( app end { 2 , 3 } out ) = { 1 , 2 , 3 } . W e reach Step 3.3 and, thus, go back to Step 3 where we again c ho ose a rule that violates the v ariable condition. L e t us again r egard Rule (30), alb eit in its mo dified form as Rule (33). The v aria ble M still vio la tes the v ar iable condition. In Step 3.1 , the refinement heuristic s ug gests to filter aw ay the second a rgumen t of the s ym bol app end { 2 , 3 } in . Ins tead of changing π ′ , we a gain introduce a new symbol, namely app end { 3 } in with π ′ ( app end { 3 } in ) = { 3 } , and replace the symbol app end { 2 , 3 } in in the right-hand side of Rule (33) by app end { 3 } in . Thus, w e obtain a further mo dification of Rule (33): rotate { 1 } in ( N , O ) → u { 1 } 2 ( app end { 3 } in ( L, M , N ) , N , O ) (38 ) Again, we have to ensure that app end { 3 } in has rewr ite r ules corres p onding to the rules of app end in . T hus, we add copies o f all rules that r esult from the app end -pre dicate where every ro ot s ym bol is lab e lled by { 3 } : app end { 3 } in ([ ] , M , M ) → app end { 3 } out ([ ] , M , M ) (39) app end { 3 } in ( • ( X, L ) , M , • ( X, N )) → u { 3 } 1 ( app end in ( L, M , N ) , X , L, M , N ) (40) u { 3 } 1 ( app end out ( L, M , N ) , X , L, M , N ) → app end { 3 } out ( • ( X, L ) , M , • ( X, N )) (41) W e also have to replace app end { 2 , 3 } out by app end { 3 } out in the left-ha nd side of Rule (37) (since (37 ) is the rule that alwa ys “ fo llo ws” (33)). So the rule (37) is r eplaced by the mo dified rule u { 1 } 2 ( app end { 3 } out ( L, M , N ) , N , O ) → u { 1 } 3 ( app end in ( M , L, O ) , L, M , N , O ) (42) Thu s, after the execution o f Step 3.2 , we ha ve R ′ P = { (24) − (29) , (38 ) − (41) , (34) − (36) , (42) , (32) } . Again we hav e introduced three new lab elled symbols app end { 3 } in , u { 3 } 1 , and app end { 3 } out . On the unlab elled symbols, the a rgumen t filter π ′ did not change, but we now additionally hav e π ′ ( app end { 3 } in ) = { 3 } , π ′ ( u { 3 } 1 ) = { 1 , 2 , 3 , 4 , 5 } , and π ′ ( app end { 3 } out ) = { 1 , 2 , 3 } . W e reach Step 3.3 and, thus, go back to Step 3 where we again choose a rule that violates the v aria ble condition. W e again regard Rule (30), alb eit in its mo dified form as Rule (38 ). The v a riable O still viola tes the v a riable conditio n. In Step 3.1 , a n y r efinemen t heuristic must sugges t to filter awa y the third arg umen t AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 35 of the symbol u { 1 } 2 . As u { 1 } 2 do es not have the fo r m p I in , we use the second c ase o f Step 3.2 . Thus, we change π ′ such that π ′ ( u { 1 } 2 ) = { 1 , 2 , 3 } \ { 3 } = { 1 , 2 } . Indee d, now Rule (38) doe s not violate the v a r iable co ndition anymore. W e reach Step 3.3 and, thus, go back to Step 3 where we again choose a r ule that s till violates the v a riable condition. Let us now rega rd Rule (42): u { 1 } 2 ( app end { 3 } out ( L, M , N ) , N , O ) → u { 1 } 3 ( app end in ( M , L, O ) , L , M , N , O ) (42) Here our r e finement heur istic suggests to filter awa y the third arg ument o f the symbol app end in in or der to remove the extra v ariable O . Instead of changing π ′ , we again introduce a new symbo l, namely app end { 1 , 2 } in with π ′ ( app end { 1 , 2 } in ) = { 1 , 2 } , and r eplace the symbol a ppend in in the rig h t-hand side of Rule (42) by app end { 1 , 2 } in . Thu s, we o btain a further mo dification o f Rule (42 ): u { 1 } 2 ( app end { 3 } out ( L, M , N ) , N , O ) → u { 1 } 3 ( app end { 1 , 2 } in ( M , L, O ) , L, M , N , O ) (43) Again, w e hav e to ensure that a p pend { 1 , 2 } in has rewr ite rules corre s ponding to the rules of app end in . Thus, we a dd copies of a ll r ules that result from the ap pend - predicate w he r e every r oot symbol is lab elled b y { 1 , 2 } : app end { 1 , 2 } in ([ ] , M , M ) → app end { 1 , 2 } out ([ ] , M , M ) (44) app end { 1 , 2 } in ( • ( X, L ) , M , • ( X, N )) → u { 1 , 2 } 1 ( app end in ( L, M , N ) , X , L, M , N ) (45) u { 1 , 2 } 1 ( app end out ( L, M , N ) , X , L, M , N ) → app end { 1 , 2 } out ( • ( X, L ) , M , • ( X, N )) (46) W e also have to repla ce app e nd out by app end { 1 , 2 } out in the left-hand side of Rule (32) (since (32 ) is the rule that a lw ays “follows” (42)). So the rule (32) is replaced by the mo dified rule u { 1 } 3 ( app end { 1 , 2 } out ( M , L, O ) , L, M , N , O ) → rotate { 1 } out ( N , O ) (47) Thu s, a fter the e x ecution of Step 3.2 , we now hav e R ′ P = { (24) − (29) , (38) − (41) , (34) − (36) , (43) − (46) , (47) } . Again we hav e intro duced three new lab e lled symbols a ppend { 1 , 2 } in , u { 1 , 2 } 1 , a nd app end { 1 , 2 } out . O n the unlab elled sym b ols, the argu- men t filter π ′ did not c hange, but we now additionally hav e π ′ ( app end { 1 , 2 } in ) = { 1 , 2 } , π ′ ( u { 1 , 2 } 1 ) = { 1 , 2 , 3 , 4 , 5 } , and π ′ ( app end { 1 , 2 } out ) = { 1 , 2 , 3 } . Note that now we hav e indeed se parated the tw o copies of the app end -rules where app end { 3 } in corres p onds to the version of app end that ha s the third a rgumen t as input and app end { 1 , 2 } in is the version where the first tw o arguments serve as input. This copying of predicates works although the initial a rgumen t filter alr e ady filtered aw a y arguments o f function symbols like “ • ” (i.e., the initial argument filter was already b eyond the ex pressivity of mo dings). Step 3 is rep eated until the v aria ble co ndition is not vio lated a n ymore. Note that Algorithm 2 alwa ys terminates since there a re only finitely many pos s ible lab elled v aria n ts for every symbol. In our example, we obtain the following set of rules R ′ P : AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 36 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann append in ([ ] , M , M ) → app end out ([ ] , M , M ) (24) append in ( • ( X, L ) , M , • ( X, N )) → u 1 ( append in ( L, M , N ) , X, L, M , N ) (25) u 1 ( append out ( L, M , N ) , X, L, M , N ) → app end out ( • ( X, L ) , M , • ( X, N )) (26) rotate in ( N , O ) → u 2 ( append { 3 } in ( L, M , N ) , N , O ) (48) u 2 ( append { 3 } out ( L, M , N ) , N , O ) → u 3 ( append in ( M , L, O ) , L, M , N , O ) (49) u 3 ( append out ( M , L, O ) , L, M , N , O ) → rotate out ( N , O ) (29) rotate { 1 } in ( N , O ) → u { 1 } 2 ( append { 3 } in ( L, M , N ) , N , O ) (38) u { 1 } 2 ( append { 3 } out ( L, M , N ) , N , O ) → u { 1 } 3 ( append { 1 , 2 } in ( M , L, O ) , L, M , N , O ) (43) u { 1 } 3 ( append { 1 , 2 } out ( M , L, O ) , L, M , N , O ) → rotate { 1 } out ( N , O ) (47) append { 2 , 3 } in ([ ] , M , M ) → app end { 2 , 3 } out ([ ] , M , M ) (34) append { 2 , 3 } in ( • ( X, L ) , M , • ( X, N )) → u { 2 , 3 } 1 ( append { 2 , 3 } in ( L, M , N ) , X, L, M , N ) (50) u { 2 , 3 } 1 ( append { 2 , 3 } out ( L, M , N ) , X, L, M , N ) → app end { 2 , 3 } out ( • ( X, L ) , M , • ( X, N )) (51) append { 3 } in ([ ] , M , M ) → app end { 3 } out ([ ] , M , M ) (39) append { 3 } in ( • ( X, L ) , M , • ( X, N )) → u { 3 } 1 ( append { 3 } in ( L, M , N ) , X, L, M , N ) (52) u { 3 } 1 ( append { 3 } out ( L, M , N ) , X, L, M , N ) → app end { 3 } out ( • ( X, L ) , M , • ( X, N )) (53) append { 1 , 2 } in ([ ] , M , M ) → app end { 1 , 2 } out ([ ] , M , M ) (44) append { 1 , 2 } in ( • ( X, L ) , M , • ( X, N )) → u { 1 , 2 } 1 ( append { 1 , 2 } in ( L, M , N ) , X, L, M , N ) (54) u { 1 , 2 } 1 ( append { 1 , 2 } out ( L, M , N ) , X, L, M , N ) → app end { 1 , 2 } out ( • ( X, L ) , M , • ( X, N )) (55) The refined arg umen t filter π ′ is given by π ′ ( append in ) = { 1 , 2 , 3 } π ′ ( rotate { 1 } in ) = { 1 } π ′ ( append { 2 , 3 } in ) = { 2 , 3 } π ′ ( append out ) = { 1 , 2 , 3 } π ′ ( u { 1 } 2 ) = { 1 , 2 } π ′ ( append { 2 , 3 } out ) = { 1 , 2 , 3 } π ′ ( • ) = { 2 } π ′ ( u { 1 } 3 ) = { 1 , 2 , 3 , 4 } π ′ ( u { 2 , 3 } 1 ) = { 1 , 4 , 5 } π ′ ( u 1 ) = { 1 , 3 , 4 , 5 } π ′ ( append { 1 , 2 } in ) = { 1 , 2 } π ′ ( u { 3 } 1 ) = { 1 , 5 } π ′ ( rotate in ) = { 1 , 2 } π ′ ( append { 1 , 2 } out ) = { 1 , 2 , 3 } π ′ ( u { 1 , 2 } 1 ) = { 1 , 3 , 4 } π ′ ( u 2 ) = { 1 , 2 , 3 } π ′ ( rotate { 1 } out ) = { 1 , 2 } π ′ ( append { 3 } in ) = { 3 } π ′ ( append { 3 } out ) = { 1 , 2 , 3 } π ′ ( u 3 ) = { 1 , 2 , 3 , 4 , 5 } π ′ ( rotate out ) = { 1 , 2 } T ermina tion for R ′ P w.r.t. the terms sp ecified by π ′ is now easy to show using our r esults from Sec tion 4. If one is o nly interested in termination of quer ies rotate ( t 1 , t 2 ) for a sp ecific pred- icate symbol like rotate , then one can remove sup erfluous (co pies of ) r ules fro m the TRS befo re starting the termination pro of. F or ex ample, if one only wan ts to prove termination of q ue r ies rotate ( t 1 , t 2 ) fo r finite lists t 1 , then it now suffices to prov e termination of the ab ove TRS for those “start terms” rotate { 1 } in ( . . . ) that are finite and ground under the filter π ′ and where the arguments of rotate { 1 } in do not co n tain any function symbo ls ex cept • and [ ]. Since the rules for rotate in , app end in , and AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 37 app end { 2 , 3 } in (i.e., the rules (24) - (26 ), (29), (34 ), and (48) - (51)) are not r eac hable from these “start terms” , they can immediately b e removed. In other words, for the queries rotate ( t 1 , t 2 ) we indeed need r ules for rotate { 1 } in , app end { 1 , 2 } in , and app end { 3 } in , but the rules for rotate in , app end in , and app end { 2 , 3 } in are super fluous. Note how ever that such sup erfluous copies of rules are never problematic for the termination analysis. If the r ules for app end { 3 } in are terminating for terms that are finite and ground under the filter π ′ , then this als o holds for the app end { 2 , 3 } in - and the app end in -rules, since her e π ′ filters aw a y less arguments. A co rresp onding statement holds for the connection b etw ee n the rotate { 1 } in - and the rota te in -rules. The following theorem prov es the corre c tnes s o f Algorithm 2. More precisely , it s hows that one can use π ′ and R ′ P instead o f π and R P in Theor e m 3.7. So it is sufficient to prov e tha t all terms in the set S ′ = { p π ( p ) in ( ~ t ) | p ∈ ∆ , ~ t ∈ ~ T ∞ (Σ , V ) , π ′ ( p π ( p ) in ( ~ t )) ∈ T (Σ P π ′ ) } are terminating w.r.t. the mo dified TRS R ′ P . In Example 5.16 , S ′ would b e the set of all terms ro t a t e { 1 } in ( t 1 , t 2 ) that are gro und after filtering with π ′ . Hence, this includes all terms where the first arg ument is a finite list. If a ll terms in S ′ are terminating w.r.t. R ′ P , we can conclude that all quer ies Q ∈ A r at (Σ , ∆ , V ) with π ( Q ) ∈ A (Σ π , ∆ π ) are terminating for the orig inal logic progra m. Since π ′ satisfies the v aria ble condition for the TRS R ′ P (and also for D P ( R ′ P ) if 1 ∈ π ′ ( u c,i ) for all symbols of the form u c,i ), one ca n als o use π ′ and R ′ P for the terminatio n criter ion of Co rollary 4.5. In other words, then it is sufficient to prove that there is no infinite ( DP ( R ′ P ) , R ′ P , π ′ )-chain. Theorem 5. 1 7 (Soundn ess of Algorithm 2). L et P b e a lo gic pr o gr am and let π b e an ar gumen t filter over (Σ , ∆) . L et π ′ and R ′ P r esu lt fr om π and R P by Algo rithm 2. L et S = { p in ( ~ t ) | p ∈ ∆ , ~ t ∈ ~ T ∞ (Σ , V ) , π ( p in ( ~ t )) ∈ T (Σ P π ) } . F urthermor e, let S ′ = { p π ( p ) in ( ~ t ) | p ∈ ∆ , ~ t ∈ ~ T ∞ (Σ , V ) , π ′ ( p π ( p ) in ( ~ t )) ∈ T (Σ P π ′ ) } . Al l t erms s ∈ S ar e terminating for R P if al l terms s ′ ∈ S ′ ar e terminating for R ′ P . Proof. W e first show tha t every reductio n of a term fro m S with R P can be s imulated b y the reduction o f a term from S ′ with R ′ P . Mo re precisely , we show the following prop osition where S n = { t | p in ( ~ t ) → n R P t for so me p ∈ ∆, ~ t ∈ ~ T ∞ (Σ , V ), and π ( p in ( ~ t )) ∈ T (Σ P π ) } and S ′ = { t | p π ( p ) in ( ~ t ) → ∗ R ′ P t for some p ∈ ∆, ~ t ∈ ~ T ∞ (Σ , V ), and π ′ ( p π ( p ) in ( ~ t )) ∈ T (Σ P π ′ ) } If s ∈ S n and s ′ ∈ S ′ with Unlab ( s ′ ) = s , then s → R P t implies that ther e is a t ′ with Un lab ( t ′ ) = t and s ′ → R ′ P t ′ . (56) Here, Un lab remov es a ll lab els intro duce d by Algor ithm 2: Unlab ( s ) = ( f ( Unlab ( s 1 ) , . . . , Unlab ( s n )) , if s = f I ( s 1 , . . . , s n ) s, otherwise W e prov e (56) by induction on n . There a re three po s sible cases for s and for the r ule that is applied in the step from s to t . AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 38 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann Case 1 : n = 0 and th us, s = p in ( ~ s ) So s ∈ S and there is a rule ℓ → r ∈ R P with ℓ = p in ( ~ ℓ ) such that s = ℓσ and t = r σ fo r some s ubstitution σ with terms from T ∞ (Σ , V ). Let s ′ ∈ S ′ with U nlab ( s ′ ) = s . Thus, w e also hav e s ′ ∈ S ′ where s ′ = p π ( p ) in ( ~ s ) (since a ter m with a r o ot s ym bol p I in cannot b e obtained fro m S ′ if one has pe r - formed a t least o ne rewrite step with R ′ P ). Due to the constructio n of R ′ P , there exists a rule ℓ π ( p ) → r ′ ∈ R ′ P where U nlab ( r ′ ) = r . W e define t ′ to be r ′ σ . Then we clea r ly hav e s ′ = ℓ π ( p ) σ → R ′ P r ′ σ = t ′ and Unlab ( t ′ ) = t . Case 2 : n ≥ 1 and s = u c,i ( s, ~ q ), s → R P t , t = u c,i ( t, ~ q ) Since s ∈ S n , there exis ts a p in ( ~ s ) with ~ s ∈ ~ T ∞ (Σ , V ) such tha t p in ( ~ s ) → ∗ R P s , i.e., s ∈ S m for s ome m ∈ N . Since the reductio n from p in ( ~ s ) to s is s horter than the ov erall r e duction that led to s , we obtain that m < n . Let s ′ ∈ S ′ with U nlab ( s ′ ) = s . Hence, we have s ′ = u I c,i ( s ′ , ~ q ) for s ome labe l I and Unlab ( s ′ ) = s . Since s ′ ∈ S ′ , there exists a p J in ( ~ s ) with ~ s ∈ ~ T ∞ (Σ , V ) such that p J in ( ~ s ) → ∗ R ′ P s ′ . Hence, s ′ ∈ S ′ as well. Now the induction hyp o thesis implies that there ex ists a t ′ such that s ′ → R ′ P t ′ and Un lab ( t ′ ) = t . W e de fine t ′ = u I c,i ( t ′ , ~ q ). Then we clear ly have s ′ → R ′ P t ′ and Unlab ( t ′ ) = t . Case 3 : n ≥ 1 and s = u c,i ( p out ( ~ s ) , ~ q ) Here, there e x ists a rule ℓ → r ∈ R P with ℓ = u c,i ( p out ( ~ ℓ ) , ~ x ) such that s = ℓσ and t = r σ . Let s ′ ∈ S ′ with Unlab ( s ′ ) = s . Hence, we have s ′ = u I c,i ( p J out ( ~ s ) , ~ q ) for s o me lab els I and J . Since s ′ ∈ S ′ , s ′ resulted from rewriting the term u I c,i ( p J in ( ~ s ) , ~ q ) which m ust be an instantiated right-hand s ide of a rule from R ′ P . Due to the constr uction of R ′ P , then there a lso ex is ts a r ule ℓ ′ → r ′ ∈ R ′ P where ℓ ′ = u I c,i ( p J out ( ~ ℓ ) , ~ x ) and Unlab ( r ′ ) = r . W e define t ′ = r ′ σ . Then we hav e s ′ = ℓ ′ σ → R ′ P r ′ σ = t ′ and clearly Un lab ( t ′ ) = t . W e now pro ceed to prov e the theorem b y contradiction. Assume there is a term s 0 ∈ S that is non-ter minating w.r.t. R P , i.e., there is an infinite sequence of ter ms s 0 , s 1 , s 2 , . . . with s i → R P s i +1 . W e must have s 0 = p in ( ~ t ) with ~ t ∈ ~ T ∞ (Σ , V ) and π ( p in ( ~ t )) ∈ T (Σ P π ). Let s ′ 0 = p π ( p ) in ( ~ t ). Then s ′ 0 ∈ S ′ , s ince π ′ ( p π ( p ) in ( ~ t )) ∈ T (Σ P π ′ ). The reas on is that π ′ ( p π ( p ) in ) = π ( p ) = π ( p in ) and for all f ∈ Σ we ha ve π ′ ( f ) ⊆ π ( f ). So by (56), s ′ 0 ∈ S ′ and Unlab ( s ′ 0 ) = s 0 imply that there is an s ′ 1 with Unlab ( s ′ 1 ) = s 1 and s ′ 0 → R ′ P s ′ 1 . Cle arly , this also implies s ′ 1 ∈ S ′ . B y applying (56) rep eatedly , we ther efore obtain a n infinite seq ue nce of lab elled terms s ′ 0 , s ′ 1 , s ′ 2 , . . . with s ′ i → R ′ P s ′ i +1 . 6. F ORMAL COMP ARISON OF T HE T RANSF ORMA TIONAL APPROA CHES In this s ection we for mally compar e the p o wer o f the cla ssical trans formation from Section 1.1 with the p ow er of our new approa c h. In the clas s ical a pproach, the class of que r ies is characterized by a mo ding function wher eas in our approa c h, it is characterized by an a rgumen t filter. There fo re, the following definition establishes a re la tionship b et w een mo dings and ar gumen t filters. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 39 Definition 6.1 (Ar gumen t Filter Induc e d by Mo ding) . Let (Σ , ∆) b e a signa ture and let m be a mo ding ov er the set of pr edicate sym b o ls ∆. Then for every pr edicate symbol p ∈ ∆ we define the induc e d ar gu ment filter π m ov er Σ P as π m ( p in ) = π m ( P in ) = { i | m ( p, i ) = in } and π m ( p out ) = { i | m ( p, i ) = out } . All o ther function s y m bols f from Σ P are not filtered, i.e., π m ( f /n ) = { 1 , . . . , n } . Example 6. 2. Reg ard a gain the well-moded lo gic pr o gram from E xample 1.1. p ( X , X ) . p ( f ( X ) , g ( Y )) :– p ( f ( X ) , f ( Z )) , p ( Z, g ( Y )) . W e used the mo ding m with m ( p , 1) = in and m ( p , 2 ) = out . T hus, for the induced argument filter π m we have π m ( p in ) = π m ( P in ) = { 1 } and π m ( p out ) = { 2 } . As the cla ssical approa c h is only applicable to well-moded logic progr ams, we restrict our compa r ison to this cla s s. F o r no n-w ell-mo ded progr ams, o ur new ap- proach is clea rly more p ow e r ful, since it can often prove termina tion (cf. Section 7 ), whereas the classica l trans formation is never a pplicable. Our g oal is to show the connec tio n b et ween the TRSs resulting from the tw o transformatio ns. If o ne refines π m to a filter π ′ m by Algorithm 1 using any ar bitrary refinement heuristic, then the TRS of the cla ssical tra ns formation cor respo nds to the TRS of our new transfor mation a fter filter ing it with π ′ m . Example 6. 3. W e contin ue with Example 6.2. The TRS R P resulting from our new transformation was given in Example 3.2 : p in ( X, X ) → p out ( X, X ) (1) p in ( f ( X ) , g ( Y )) → u 1 ( p in ( f ( X ) , f ( Z )) , X , Y ) (2) u 1 ( p out ( f ( X ) , f ( Z )) , X , Y ) → u 2 ( p in ( Z, g ( Y )) , X , Y , Z ) (3) u 2 ( p out ( Z, g ( Y )) , X , Y , Z ) → p out ( f ( X ) , g ( Y )) (4) If we apply the induced a rgumen t filter π m , then we obtain the TRS π m ( R P ) : p in ( X ) → p out ( X ) p in ( f ( X )) → u 1 ( p in ( f ( X )) , X , Y ) u 1 ( p out ( f ( Z )) , X , Y ) → u 2 ( p in ( Z ) , X , Y , Z ) u 2 ( p out ( g ( Y )) , X , Y , Z ) → p out ( g ( Y )) The second rule ha s the “extr a ” v a riable Y on the right-hand side, i.e., it do es not satisfy the v a riable co ndition. Thus, we hav e to r efine the filter π m to a fil- ter π ′ m with π ′ m ( u 1 ) = π ′ m ( U 1 ) = { 1 , 2 } and π ′ m ( u 2 ) = π ′ m ( U 2 ) = { 1 , 2 , 4 } . The resulting TRS π ′ m ( R P ) is iden tical to the TRS R old P resulting from the classica l transformatio n, cf. Example 1.2: p in ( X ) → p out ( X ) p in ( f ( X )) → u 1 ( p in ( f ( X )) , X ) u 1 ( p out ( f ( Z )) , X ) → u 2 ( p in ( Z ) , X , Z ) u 2 ( p out ( g ( Y )) , X , Z ) → p out ( g ( Y )) The following theor em shows that our approa c h (with Co r ollary 4.5) succeeds whenever the cla ssical transforma tion of Section 1.1 yields a ter mina ting TRS. AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 40 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann Theorem 6. 4 (Subsumption of the Classical Transforma tion ) . L et P b e a wel l-mo de d lo gic pr o gr am over a s ignatur e (Σ , ∆) w.r.t. the mo ding m . L et R old P b e the r esult of applying t he classic al tr ansformation of Se ction 1.1 and let R P b e the r esult of our n ew tr ansformation fr om Definition 3.1. Then ther e is a r efin emen t of π ′ m of π m such that (a) π ′ m ( R P ) and π ′ m ( D P ( R P )) satisfy the variable c ondition and (b) if R old P is terminating (with or dinary r ewriting), then ther e is n o infinite ( D P ( R P ) , R P , π ′ m ) -chain. Thus, in p articular, termination of R old P implies that R P is terminating (with infin itary c onstru ctor re writing) for al l terms p in ( ~ t ) with p ∈ ∆ , ~ t ∈ ~ T ∞ (Σ , V ) , and π ( p in ( ~ t )) ∈ T (Σ P π ) . Proof. Le t π ′ m result fro m Algor ithm 1 using a n y r efinemen t heuristic ρ which do es not filter aw ay the first a rgumen t of any u c,i . W e now analyze the structure of the TRS π ′ m ( R P ). F o r any predicate symbol p ∈ ∆, let “ p ( ~ s, ~ t )” denote that ~ s and ~ t are the sequences of terms on p ’s in- and output p ositions w.r.t. the mo ding m . When Algo rithm 1 is applied to compute the r efinemen t π ′ m of π m , one lo oks for a rule ℓ → r from π m ( R P ) such that V ( r ) 6⊆ V ( ℓ ). Such a rule cannot result fr om the facts of the logic pro gram. The rea son is that for each fact p ( ~ s, ~ t ), π m ( R P ) contains the r ule p in ( ~ s ) → p out ( ~ t ) and by well-mo dedness, we have V ( ~ t ) ⊆ V ( ~ s ). F or each r ule c o f the form p ( ~ s, ~ t ) :– p 1 ( ~ s 1 , ~ t 1 ) , . . . , p k ( ~ s k , ~ t k ) in P , the TRS π m ( R P ) co n tains: p in ( ~ s ) → u c, 1 ( p 1 in ( ~ s 1 ) , V ( ~ s ) ∪ V ( ~ t )) u c, 1 ( p 1 out ( ~ t 1 ) , V ( ~ s ) ∪ V ( ~ t )) → u c, 2 ( p 2 in ( ~ s 2 ) , V ( ~ s ) ∪ V ( ~ t ) ∪ V ( ~ s 1 ) ∪ V ( ~ t 1 )) . . . u c,k ( p k out ( ~ t k ) , V ( ~ s ) ∪ V ( ~ t ) ∪ V ( ~ s 1 ) ∪ V ( ~ t 1 ) ∪ . . . ∪ V ( ~ s k − 1 ) ∪ V ( ~ t k − 1 )) → p out ( ~ t ) F or the first rule, b y well-mo dednes s we hav e V ( ~ s 1 ) ⊆ V ( ~ s ) and thus, the only “extra” v ariables on the right-hand side of the first rule m ust b e fr om V ( ~ t ). There is only o ne p ossibility to refine the a rgumen t filter in or de r to remov e them: one has to filter aw a y the resp ective a rgumen t p ositions o f u c, 1 . Hence, the filtered right-hand side of the first rule is u c, 1 ( p 1 in ( ~ s 1 ) , V ( ~ s )) and the filtered left-hand side of the seco nd r ule is u c, 1 ( p 1 out ( ~ t 1 ) , V ( ~ s )). Similarly , for the second rule, well-mo dedness implies V ( ~ s 2 ) ∪V ( ~ s ) ∪V ( ~ s 1 ) ∪V ( ~ t 1 ) ⊆ V ( ~ t 1 ) ∪ V ( ~ s ). So the only “e x tra” v aria ble s on the right-hand side of the second rule a re again fr om V ( ~ t ). As b e fore, to r emo ve them o ne has to filter awa y the resp ectiv e ar gumen t p ositions of u c, 2 . Mo reov e r , since V ( ~ s 1 ) ⊆ V ( ~ s ) we obtain the filtered r igh t-hand side u c, 2 ( p 2 in ( ~ s 2 ) , V ( ~ s ) ∪ V ( ~ t 1 )) for the second rule and the filtered left-hand side u c, 2 ( p 2 out ( ~ t 2 ) , V ( ~ s ) ∪ V ( ~ t 1 )) side in the third rule. An analog ous argument holds for the other r ules. The last rule ha s no extra v aria bles, since V ( ~ t ) ⊆ V ( ~ s ) ∪ V ( ~ t 1 ) ∪ . . . ∪ V ( ~ t k ) by well-modednes s . AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 41 So for any rule c of the logic progr am P , π ′ m ( R P ) ha s the following r ules: p in ( ~ s ) → u c, 1 ( p 1 in ( ~ s 1 ) , V ( ~ s )) u c, 1 ( p 1 out ( ~ t 1 ) , V ( ~ s )) → u c, 2 ( p 2 in ( ~ s 2 ) , V ( ~ s ) ∪ V ( ~ t 1 )) . . . u c,k ( p k out ( ~ t k ) , V ( ~ s ) ∪ V ( ~ t 1 ) ∪ . . . ∪ V ( ~ t k − 1 )) → p out ( ~ t ) Hence, π ′ m ( R P ) = R old P . Since the refined arg umen t filter π ′ m do es not filter awa y the first ar gumen t of any u c,i , b y defining π ′ m ( U c,i ) := π ′ m ( u c,i ), then the v ar iable condition is s atisfied for b oth π ′ m ( R P ) a nd π ′ m ( D P ( R P )) a nd, thus, (a) is fulfilled. Now to prov e (b), we as s ume that R old P is terminating. W e hav e to show that then ther e is no infinite ( D P ( R P ) , R P , π ′ m )-chain. By the soundness o f the a rgu- men t filter pro cessor (Theorem 4.1 3), it suffices to show that there is no infinite ( π ′ m ( D P ( R P )) , π ′ m ( R P ) , i d )-chain. Note that π ′ m ( D P ( R P )) = D P ( π ′ m ( R P )). The r eason is that all u c,i only o ccur on the ro ot level in R P . Mo reov er, all p in -symbols only o ccur in the first arg umen t of a u c,i and 1 ∈ π ′ m ( u c,i ). In other words, o ccurrences of defined function symbols are not remov ed by the filter π ′ m . So we have u → v ∈ π ′ m ( D P ( R P )) iff there is a rule ℓ → r ∈ R P with u = π ′ m ( ℓ ♯ ) , v = π ′ m ( t ♯ ) for a subterm t of r with defined ro ot iff there is a rule ℓ → r ∈ R P with u = ( π ′ m ( ℓ )) ♯ , v = ( π ′ m ( t )) ♯ for a subterm π ′ m ( t ) of π ′ m ( r ) with defined ro ot iff there is a rule ℓ → r ∈ π ′ m ( R P ) with u = ℓ ♯ , v = t ♯ for a subterm t of r with defined ro ot iff u → v ∈ D P ( π ′ m ( R P )) Hence, π ′ m ( R P ) = R old P and π ′ m ( D P ( R P )) = D P ( π ′ m ( R P )) = D P ( R old P ). Thus, it suffices to show absenc e of infinite ( D P ( R old P ) , R old P , i d )-c hains. B ut this follows from ter mina tion of R old P , cf. [Ar ts and Giesl 2 0 00, Thm. 6], since ( P , R , id )-chains corres p ond to c hains for ordinar y (non-infinita r y) rewriting. Hence by Theor em 4.4, termination of R old P also implies that all terms p in ( ~ t ) with p ∈ ∆, ~ t ∈ ~ T ∞ (Σ , V ), and π ( p in ( ~ t )) ∈ T (Σ P π ) ar e terminating w.r.t. R P (using infinitary co nstructor rewriting). The reverse dir ection of the above theorem do es not hold, thoug h. As a coun- terexample, reg ard aga in the lo gic pro gram from E xample 1.1, cf. Ex ample 6.3 . As shown in Example 1.2, the TRS resulting from the class ic al transfor mation is not ter minating. Still, for the filter π ′ m from Ex a mple 6 .3, there is no infinite ( D P ( R P ) , R P , π ′ m )-chain and thus, our metho d of Co rollary 4.5 succeeds with the termination pro of. In other words, o ur new a pproach is st rictly more powerful than the cla ssical transforma tion, even on well-moded programs. Thu s, a termination ana lyzer based on o ur new trans formation should be strictly more success ful in practice, to o. That this is in fact the case will b e demonstra ted in the next section. AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 42 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann 7. EXPERIMENT S AND DISCUSSION W e integrated our appro ac h (including all refinements presented) in the termina tion to ol AProVE [Giesl et al. 20 06] which implemen ts the DP fra mew ork. T o ev aluate our results, we tested AProVE against four other re pr esen tative termina tion to ols for lo gic pr ogramming: T ALP [Ohlebus ch et al. 200 0 ] is the o nly other av ailable to ol based on tr a nsformational metho ds (it use s the cla ssical transfor mation o f Section 1 .1 ), whereas Polytoo l [Nguyen and De Schreye 2007], T erminWeb [Co dish and T ab och 1999 ], and cTI [Mesnard and Bagnar a 20 05] are based on direct ap- proaches. Section 7.1 des cribes the results o f our exp erimental ev aluation and in Section 7.2 we discuss the limitatio ns of our a pproach. 7.1 Experime n tal Evaluation W e ra n the to ols on a set of 296 examples in fully automatic mo de. 14 This set includes all lo gic prog ramming examples fro m the T ermination Pr oblem Data Base [TPDB 200 7] which is used in the annual international T ermination Comp etition [March ´ e and Za n tema 2007 ]. It contains co llections provided b y the develop ers of several differen t to ols including all examples from the exp erimental ev aluatio n of [Bruyno oghe et a l. 2007 ]. How ever, to eliminate the influence of the tr anslation from Prolo g to logic programs, we remov ed all exa mples that use non-trivia l built- in predica tes or tha t are not definite lo gic pr ograms after ignoring the cut op erator . All to ols were run lo cally on an AMD At hlon 64 at 2 .2 GHz under GNU/Linux 2.6 . F or each example we used a time limit of 6 0 seconds. This is s imilar to the wa y that to ols are e v aluated in the annual co mp etitions for termination to ols. AProVE Polyto ol T erminWeb cTI T ALP Successes 232 204 177 167 163 F ailur e s 57 82 118 129 112 Timeouts 7 10 1 0 21 As shown in the table ab o ve, AProVE succee ds on more ex amples than any other to ol. The compa r ison o f AProVE and T ALP shows that our approach improv es significantly up on the previous trans formational metho d that T ALP is based on, cf. Goals (A) and (B). In particular , T ALP fails for a ll no n-w ell-mo ded progr ams. While we have s ho wn our techn ique to b e strictly more p o werful than the pre vious transformatio nal metho d, due to the higher ar it y of the function s y m bols pro duced by our tra nsformation, pr oving ter mination could take more time in so me ca s es. How ever, in the ab ov e exp erimen ts this did not affect the practica l p o wer of our implemen tation. In fact, AProVE is a ble to prov e termina tion well within the time limit for all exa mples where T ALP succe eds. F urther analys is shows that while AProVE never takes more than 15 seconds longer than T ALP , there a re indeed 6 examples w her e AProVE is more than 15 sec o nds faster tha n T ALP . 14 W e comb ined termsize and list-lengt h norm f or T erminW eb and allow ed 5 i terat ions b efore widening for cTI . Apart from that, w e used the default settings of the to ols. F or b oth AProVE and Po lyto ol we used the (fully automated) original executables fr om the T ermination Comp et ition 2007 [March ´ e and Zan tema 2007]. T o refine ar gumen t filters, this version of AProVE uses the refinemen t heuristic ρ tb ′ fr om Definition 5.13. F or a list of the main termination tec hniques used in AProVE , we refer to [Giesl et al. 2005; Giesl et al . 2006]. Of these technique s, only the ones i n Section 4. 2 were adapted to infinitary constructor rewriting. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 43 The comparison w ith P olyto ol , T erminWeb , and cTI demo ns trates that o ur new transformatio nal a pproach is not o nly co mpa rable in p ow e r, but usually more p ow- erful than direct approaches. In fact, there is only a single ex ample wher e one of the o ther to ols (namely Polyto ol ) succeeds a nd AProVE fails. This is the ra ther contriv ed example fro m (2) in Section 7.2 which w e developed to demonstrate the limitations o f our metho d. Polytoo l is only able to ha ndle this exa mple via a pre- pro cessing s tep ba s ed on par tial ev aluation [Nguyen et a l. 200 6; Serebrenik a nd De Schrey e 20 03; T amary and Co dish 2004]. In this example, this pre-pro cessing step results in a trivially terminating logic progr am. Th us, if one combined this pre-pro cessing w ith any of the other to ols, then they would als o b e able to prov e termination of this pa rticular exa mple. 15 Int egrating some for m of par tial ev al- uation into AProVE mig h t b e a n int eresting p ossibility for further impr o vemen t. F or all other examples, AProVE ca n show termina tio n whene ver a t least one of the o ther to ols succeeds. Mo reov e r , there a re se veral exa mples where AProVE suc- ceeds wher eas no other to ol shows the termination. The s e include examples where the termination pro of requir e s more complex or ders. F or instance, termination of the example S GST06/hb al tree.p l ca n b e proved using recursive path or ders with status and termina tion of talp/ apt/merg esort ap.pl is shown using matr ix orders. 16 Note that 52 examples in this collec tion ar e known to b e non-terminating, i.e., there a re at most 244 ter mina ting exa mples. In o ther words, there are only at most 12 terminating examples wher e AProVE did no t manage to prov e termination. With this p erformance, AProVE won the T ermination Comp etition with Polyto ol b eing the s e cond most p ow er ful to ol. The be st to ol for non-termination a nalysis of logic progra ms was NTI [Pay et a nd Mes nard 200 6 ]. How ever, from the exp erimen ts ab o ve one should not draw the co nclusion that the transformatio nal approach is alwa ys b etter tha n the direct appro ac h to termination analysis o f logic pro grams. There a re several extens io ns (e.g ., terminatio n inference [Co dish and T a bo ch 1999 ; Mesnard and Bag nara 2 005], non-termination analy s is [Pa y et and Mesna rd 2006 ], handling num erical data str uctures [Ser ebrenik and De Schrey e 200 4; 2005 b]) tha t ca n curr en tly only be handled by direct techniques and to ols. Regarding the use of term r ewriting techniques for termination analys is of lo g ic progra ms, it is interesting to note that the c ur ren tly most p o werful to ol for di- rect termination a nalysis of logic prog rams ( Polyto ol ) implements the framework of [Nguyen and De Schreye 200 5; 200 7] for applying techniques fro m term r ewrit- ing (most notably p olynomial int erpretatio ns) to logic prog rams dir ectly . This framework forms the basis for further ex tens ions to o ther TRS-termination tech- niques. F or ex ample, it can be extended further by adapting also basic results of the depe ndency pair metho d to the logic pro g ramming s etting [Nguyen et al. 2 008]. Preliminary inv estigations with a pro tot ypical implementation indicate that in this wa y , one can pr o ve termination of several examples wher e the tr a nsformational 15 Similarly , with suc h a pre-pro cessing the existing “direct” tools would also be able to pr o v e termination of the program in Example 1.1. 16 F or recursive path orders with status and matrix orders see [Lescanne 1983] resp. [Endrullis et al. 2006]. AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 44 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann approach w ith AProVE currently fails . So transfo r mational and direct a pproaches b o th hav e their adv ant ages and the most p o werful solution might b e to combine dir ect to ols like Polyto ol with a tr ans- formational prover like AProVE which is based on the contributions o f this pap er. But it is cle ar that it is indeed b eneficial to use termination techniques from TRSs for lo gic progr ams, b oth for direct and for transfor mational a pproaches. In addition to the exp eriments descr ibed ab o ve (which compa re different termi- nation prov ers), we als o p erformed exp erimen ts with several versions of AProVE in order to ev a luate the different heuris tics and algor ithms for the co mputation of ar - gument filters fr om Section 5. The following table shows that indeed our improved t yp e-based r efinemen t heur is tic (tb ′ ) from Sectio n 5.3 significa n tly outp erforms the simple improv ed outermost (om ′ ) and innermost (im) heuristics fro m Section 5.2 . In fact, all examples that co uld b e proved terminating by any of the simple heuristics can als o b e proved terminating b y the type-based heuristic. AProVE tb ′ AProVE o m ′ AProVE im Successes 232 218 195 F ailur e s 57 76 98 Timeouts 7 2 3 So fa r , for all exp eriments we used Algo rithm 2 (fro m Sec tion 5.4) in o rder to compute a refined ar gumen t filter from the initial one. T o ev aluate the adv an tage o f this improv ed alg o rithm ov er Algo rithm 1 (from Sectio n 5.1), we pe rformed exp eri- men ts with the tw o a lg orithms (again using the t yp e-based refinement heuristic tb ′ from Section 5.3 ). The following table shows that Algo rithm 2 is indeed significantly more p ow erful than Alg orithm 1. AProVE Alg orithm 2 AProVE Algorithm 1 Successes 232 212 F ailur e s 57 74 Timeouts 7 10 As mentioned in Section 1.3, preliminary versions of pa rts of this pap er app eared in [Sc hneider-Kamp e t al. 20 07]. How ever, the table below clear ly shows that the results of Section 5 (whic h are new compar ed to [Schneider-Kamp et al. 2 007]) improv e the p ow er of termination a nalysis substantially . T o this end, we compare our new implementation that uses the improv ed type-ba s ed refinement heuris tic (tb ′ ) a nd the improv ed re finement algo rithm (Algorithm 2) from Section 5 with the version of AProVE fr om the T ermination Comp etit ion 2006 that o nly contains the results of [Schneider-Kamp e t a l. 2 007]. T o find arg umen t filters, it uses a simple ad-ho c heuristic which turns out to be clea rly disadv antageous to the new sophisticated tec hniques fro m Section 5 . AProVE tb ′ AProVE [Schneider-Kamp et al. 2007] Successes 232 208 F ailur e s 57 69 Timeouts 7 19 T o run AProVE , for details on our exp erimen ts, and to a ccess our collection of examples, we refer to htt p://apro ve.informatik.rwth-aachen.de/eval/TOCL/ . AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 45 7.2 Limitations Our exper imen ts also con tain examples which demonstra te the limitations of our ap- proach. Of co urse, our implemen tation in AProVE usually fails if ther e are featur e s outside of pure logic pr ogramming (e.g., built-in predicates , negation a s failure, meta progra mming, etc.). W e cons ide r the handling of meta-logica l features such as cuts and meta pr ogramming a s future work. W e think that techniques fro m ter m rewriting ar e esp ecially well-suited to handle meta pro g ramming as term rewriting do es not rely o n a distinction b e t w een pr edicate and function symbols . In the following, we discuss the limitations o f the approach when a pplying it for pure log ic progr amming. In principle, there could be three po in ts of failure: (1) The transformation of Theorem 3.7 could fa il, i.e., there could b e a logic pro - gram which is terminating for the se t of q ueries, but not all corres ponding terms are termina ting in the transfor med TRS. W e do not know of a n y such example. It is currently op en whether this step is in fact complete. (2) The appro ac h via depe ndency pair s (Theorem 4.4) can fail to pr o ve termination of the tra nsformed TRS, although the TRS is termina ting. In pa rticular, this can ha ppen b ecause of the v ariable co ndition re q uired for Theor e m 4.4. This is demonstr ated by the following logic progra m P : p ( X ) :– q ( f ( Y )) , p ( Y ) . p ( g ( X )) :– p ( X ) . q ( g ( Y )) . The resulting TRS R P is p in ( X ) → u 1 ( q in ( f ( Y )) , X ) u 1 ( q out ( f ( Y )) , X ) → u 2 ( p in ( Y ) , X , Y ) u 2 ( p out ( Y ) , X , Y ) → p out ( X ) p in ( g ( X )) → u 3 ( p in ( X ) , X ) u 3 ( p out ( X ) , X ) → p out ( g ( X )) q in ( g ( Y )) → q out ( g ( Y )) and there are the following dep endency pairs. P in ( X ) → Q in ( f ( Y )) (57) P in ( X ) → U 1 ( q in ( f ( Y )) , X ) (58) U 1 ( q out ( f ( Y )) , X ) → P in ( Y ) (59) U 1 ( q out ( f ( Y )) , X ) → U 2 ( p in ( Y ) , X , Y ) (60) P in ( g ( X )) → P in ( X ) (61) P in ( g ( X )) → U 3 ( p in ( X ) , X ) (62) W e wan t to prov e termination o f all queries p ( t ) wher e t is finite and ground (i.e., m ( p , 1) = in ). Lo oking at the logic pr ogram P , it is obvious that they are a ll ter minating. Ho wev er, there is no ar gumen t filter π such tha t π ( R P ) and π ( DP ( R P )) satisfy the v a riable condition and s uc h that there is no infinite ( D P ( R P ) , R P , π )-chain. AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 46 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann T o see this, note that if π ( P in ) = ∅ or π ( g ) = ∅ then we can build an infinite chain with the la st dep endency pair where we instantiate X by the infinite term g ( g ( . . . )). So , let π ( P in ) = π ( g ) = { 1 } . Due to the v ariable condition of the depe ndency pair (59) we know π ( f ) = π ( q out ) = { 1 } a nd 1 ∈ π ( U 1 ). Hence, to satisfy the v ar iable condition in dep endency pa ir (58 ) we must set π ( q in ) = ∅ . But then the last r ule of π ( R P ) do es not satisfy the v aria ble condition. (3) Finally it can happen that the resulting DP pro blem of Theorem 4 .4 is finite, but that our implementation fails to prov e it. The reason c a n b e that one should apply other DP pr ocess ors or DP pro cessor s with other parameters . After all, finitenes s of DP pr oblems is undecidable. This is shown b y the fo llo wing example where we are int erested in all queries f ( t 1 , t 2 ) where t 1 and t 2 are ground terms: f ( X, Y ) :– g ( s ( s ( s ( s ( s ( X ))))) , Y ) . f ( s ( X ) , Y ) :– f ( X , Y ) . g ( s ( s ( s ( s ( s ( s ( X )))))) , Y ) :– f ( X , Y ) . T ermina tion c an (for example) be proved if one uses a p olynomial o rder with co efficien ts from { 0 , 1 , 2 , 3 , 4 , 5 } . But the curr en t auto mation do es not use s uc h po lynomials a nd thus, it fails when tr y ing to prov e termination of this ex ample. While the DP metho d can also b e used for non- termination pro ofs if o ne consid- ers ordina ry r ewriting, this is less o b vious for infinitary constructor rewriting. The reason is that the main termination criter ion is “co mplete” for ordinary r ewriting, but incomplete for infinitary constructor rewriting (cf. the counterexample (2 ) to the completeness of Theorem 4.4 ab ov e). Therefore, in o rder to a lso prov e non- termination o f logic pr o grams, a co m bination of our metho d with a lo op-chec ker for logic progra ms would b e fruitful. As mentioned befo re, a very powerful non- termination to ol for lo gic progr ams is NTI [Pa yet a nd Mesnard 2006 ]. Our collectio n of 296 exa mples contains 23 3 termina ting examples (232 o f thes e can b e succe ss- fully shown by AProVE ), 52 non- terminating examples, and 1 1 exa mples whose termination b ehavior is unk nown. NT I can prove non-terminatio n o f 42 of the 52 non-ter mina ting examples . Hence, a combination of AProVE and NT I would successfully a nalyze the termination b ehaviour of 274 of the 296 examples . 8. CONCLUSION In this pap er, we developed a new tra ns formation from logic pr ograms P to TRSs R P . T o pr ove the termination of a class of quer ies fo r P , it is now sufficient to analyze the termination b ehavior of R P on a corres ponding c la ss of terms w.r.t. infinitary constructor rewriting. This class of ter ms is characterized by a so-called argument filter and we show ed how to g enerate such ar gumen t filters fro m the given clas s of q ue r ies for P . Our appro a c h is even sound for lo g ic pr ogramming without o ccur chec k. T o pr ove termination o f infinitary rewr iting a utomatically , we show ed how to ada pt the DP fr amew ork of [Arts and Giesl 2000; Gies l et al. 2005; Giesl et al. 2006 ] from ordinary term rewr iting to infinitary co nstructor rewr iting. Then the DP framework c an be used for termina tion pro ofs of R P and thus, for automated termina tio n analysis of P . Since any ter mination technique for TRSs can b e formulated a s a DP pro cessor [Giesl et a l. 2005 ], now any such technique AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 47 can als o b e used for log ic progra ms. In addition to the r esults pres e n ted in [Sc hneider-Ka mp et al. 200 7], we showed that our new a pproach s ubs umes the classica l transformatio nal a ppr oach to ter mi- nation ana lysis o f lo gic pr ograms. W e also provided new heuris tics and algorithms for refining the initial a rgumen t filter that improv e the p ow er of o ur metho d (and hence, also of its implemen tation) substantially . Moreov er, we implemented all contributions in o ur termination prover AProVE and p erformed extensive exp eriments whic h demonstr ate that our results ar e indeed applicable in pra ctice. More precis ely , due to o ur c on tributions, AProVE ha s b ecome the cur ren tly most powerful a utomated termination prov er fo r logic progr ams. AC KNOWLEDGMENTS W e thank Mike Co dish, Danny De Sc hreye, and F r ed Mesnard for helpful comments and discus sions on the results presented her e and Ro berto Bagnara , Samir Genaim, and Manh Thang Nguyen for help with the exp eriments. REFERENCES Aguzzi, G. and M odigliani, U. 1993. Pr o ving T ermination of Logic Programs b y T ransforming them into Equiv alen t T erm Rewriting Systems. In FSTTCS ’93 . LNCS, vol. 761. 114–124. Apt, K. R. and Et alle, S. 1993. On the Unification F ree Prolog Programs. In MFCS ’93 . LNCS, v ol. 711. 1–19. Apt, K. R. 1997. F r om L o gic Pr o gr amming to Prolog . Pr en tice Hall, London. Ar ts, T. and Zantema, H. 1995. T ermination of Logic Programs Usi ng Semantic Unification. In L O PSTR ’95 . LN CS, vol. 1048. 219–233. Ar ts, T. and Giesl, J. 2000. T er mination of T erm Rewriting U s ing Dependency Pairs. The or et- ic al Computer Scie nc e 236 , 133–178. Baader, F. an d Nipkow, T. 1998. T erm R e writ ing and Al l That . Cambridge Universit y Press. Bossi, A. , Cocco, N. , and F a bris, M. 1992. Typed Norms. In ESOP ’92 . LNCS, vol. 582. 73–92. Bruynooghe, M. , Demoen, B. , Boulanger, D. , Denecker, M. , an d Mulkers, A. 1996. A F reeness and Sharing Analysis of Logic Programs Based on a Pr e-In terpretat ion. In SAS ’96 . LNCS, vol. 1145. 128–142. Bruynooghe, M. , Gallagher, J . P. , and V an Hum beeck, W. 2005. Inference of W ell-Typings for Logic Programs with Application to T ermination Analysi s. In SAS ’05 . LNCS, vol. 3672. 35–51. Bruynooghe, M. , Codish, M. , Gallagher, J . P. , Genaim, S. , and V anh oof, W. 2007. T ermi- nation Analysis of Logic Pr ograms through Combination of Type-Based Norms. ACM T r ans- actions on Pr o gr amming L anguages and Sy stems 29, 2, Article 10. Chara tonik, W. and Podelski, A. 1998. Directional Type Inference for Logic Programs. In SAS ’98 . LNCS, vol. 1503. 278–294. Chtourou, M. an d R usinowitch, M . 1993. M´ ethode T ransformationelle p our la Pr euv e de T erminaison des Programmes Logiques. Unpublished manuscript. Codish, M. and T aboch, C. 1999. A Seman tic Basis for T ermination Analysi s of Logic Pr ograms. Journal of L o gic Pr o gr amming 41, 1, 103–123. Codish, M. , Lagoon, V. , and Stuckey, P. 2005. T esting for T erm ination with Monotonicit y Constrain ts. In ICLP ’05 . LNCS, vol. 3668. 326–340. Codish, M. , Lagoon, V. , Schachte, P. , and Stuckey, P. 2006. Size-Change T ermi nation Analysis i n k -Bits. In ESOP ’06 . LNCS, vo l. 3924. 230–245. Codish, M . 2007. Collection of B enchmarks. Av ai l able at http://lvs.cs. bgu.ac.il/ ~ mcodish/ suexec/t erminweb/b in/terminweb.cgi?command=examples . Colmerauer, A. 1982. Prolog and Infinite T rees. In Lo gic Pr o gr amming , K. L. Clark and S. T¨ arnlund, E ds. Academic Press, Oxford. AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY. 48 · P . S chneider-Kamp, J. Giesl, A. Serebr enik, R. Thiemann Cor tesi, A. an d Fil ´ e, G . 1999. Sharing is Optimal. Journal of L o gic Pr o gr amming 38, 3, 371–386. De Schrey e, D. and Decor te, S. 1994. T ermination of Logic Programs: The Never-Ending Story. Journal of Lo g i c Pr o gr amming 19-20 , 199–260. De Schreye, D. a nd Serebrenik, A. 2002. Acceptabilit y wi th General Or derings. In Computa- tional Lo g i c: L o gic Pr o g r amming and Beyond. Essays in Honour of R ob ert A. Kowalski, Part I , A. C. Kak as and F. Sadri, Eds. LNCS, vo l. 2407. 187–210. Decor te, S . , De Schreye, D. , an d F a bris, M. 1993. Automatic Inference of Norms: A Miss i ng Link in Automatic T ermi nation Analysis. In ILPS ’93 . MIT Press, Boston, 420–436. Dershowitz , N. 1987. T ermi nation of Rewriting. Journal of Symb olic Computation 3, 1–2, 69–116. Endrullis, J. , W aldmann, J. , and Zantema, H. 2006. Matrix Int erpretations for Proving T er- mination of T erm Rewri ting. In IJCAR ’06 . LNAI, vol. 4130. 574–588. Gallagher, J. P. and Puebla, G. 2002. Abstract Int erpretation ov er N on-determini s tic Fi nite T ree Automata for Set-Based Analysis of Logic Programs. In P A DL ’02 . LNCS, vol. 2257. 243–261. Ganzinger, H. an d W aldma nn, U. 1993. T ermi nat ion Pro ofs of W ell-mo ded Logic P r ograms via Conditional Rewr ite Systems. In CTRS ’92 . LNCS, vol. 656. 430–437. Geser, A. , Hofbauer, D. , and W aldmann, J. 2004. Match -Bounded String Rewriting Systems. Applic able Algebr a in Engine e ring, Communic ation and Computing 15, 3–4, 149–171. Giesl, J. , Thiemann, R. , and S chneider-Kamp, P. 2005. The Dependency Pair F ramework: Comb ining T ec hniques for Automated T ermination Proof s. In L P AR ’04 . LNAI, vo l. 3452. 301–331. Giesl, J. , Schn eider-Kamp, P. , and Thiemann, R. 2006. AProVE 1. 2: Automatic T ermination Pro ofs in the DP F ramework. In IJCAR ’06 . LNAI, vol. 4130. 281–286. Giesl, J. , S wid erski, S. , Schneider-Kamp, P. , a nd Thiemann, R. 2006. Automated T ermination Analysis f or Hask ell : F rom T erm Rewriting to Programmi ng Languages. In R T A ’06 . LNCS, v ol. 4098. 297–312. Giesl, J. , Thiemann, R. , Schneider-Kamp, P. , and F alke, S. 2006. Mechanizing and Impro ving Dependency Pairs. Journal of Automate d R e asoning 37, 3, 155–203. Hiroka w a, N. an d M iddel dorp, A. 2005. Automating the Dep enden cy Pair Metho d. Informa- tion and Computation 199, 1,2, 172–199. Huet, G . 1976. R´ esolution d’Equations dans les Langages d’Ordre 1, 2, . . . , ω . PhD thesis. Janssens, G. and Bruynooghe, M. 1992. Deriving Descri ptions of Possible V alues of Program V ariables by Means of Abstract Interpretat ion. Journal of L o gic Pr o gr amming 13, 2–3, 205–258. Krishna Rao, M. R. K. , Kapu r, D. , and Shyamasund ar, R. K. 1998. T ransformational Metho d- ology f or Proving T erm i nation of Logic Programs. Journal of L o gic Pr o gr amming 34, 1, 1–41. Lagoon, V. an d Stuckey, P. J. 2002. Pr ecise Pa ir-Shari ng Analysis of Logic Programs. In PPDP ’02 . ACM Press, New Y ork, 99–108. Lagoon, V. , Mesnard, F. , and Stuckey, P. J. 2003. T ermination Analysis with Types Is More Accurate. In ICLP ’03 . LNCS, vol. 2916. 254–268. Lescanne, P. 1983. Computer Exp erimen ts with the REVE T erm Rewriting System Generator. In POPL ’ 83 . ACM Press, New Y ork, 99–108. Leuschel, M. and Sørensen, M. H. 1996. Redundant Argument Filtering of Logic Programs. In L O PSTR ’96 . LN CS, vol. 1207. 83–103. Lindenstrauss, N. , S agiv, Y. , and Serebrenik, A. 1997. T ermiLog : A System for Checking T ermination of Queries to Logic Programs. In CA V ’97 . LN C S, vo l. 1254. 444–447. Lu, L. 2000. A Precise Type Analysis of Logic Programs. In PPDP ’00 . ACM Pr ess, N ew Y ork, 214–225. March ´ e, C. an d Zantema, H. 2007. The T ermination Competition. In R T A ’07 . LNCS, vol. 4533. 303–313. See al s o http://w ww.lri.fr / ~ marche/t ermination - competition/ . Marchiori, M. 1994. Logic Programs as T erm Rewriting Systems. In ALP ’94 . LNCS, v ol. 850. 223–241. AC M T ransactions on Computati onal Logic, V ol. V, No. N, 20YY. Automated T ermination Pro ofs fo r Logic Programs by T erm Rewriting · 49 Marchiori, M. 1996. Proving Existent ial T ermination of Norm al Logic Pr ograms. In AMAST ’96 . LNCS, vol. 1101. 375–390. Mar tin, J. , King, A. , and Soper, P. 1996. Typed Norm s for Typed Logic Pr ograms. In LOPSTR ’96 . LNCS, vol. 1207. 224–238. Mesnard, F. and Ruggieri, S . 2003. On Proving Left T ermi nation of Constraint Logic Pr ograms. ACM T r ansactions on Computational L o gic 4, 2, 207–259. Mesnard, F. a nd Bagnara, R. 2005. cTI : A Constrain t-Based T ermination Inference T ool for ISO-Prolog . The ory and Pr actic e of L o gic Pr o gr amming 5, 1&2, 243–257. Mesnard, F. an d Serebrenik, A. 2007. Recurrence with Affine Level Mappings i s P-Time Decidable for CLP(R). The ory and Pr actice of L o gic Pr o g r amming 8, 1, 111–119. Nguyen, M. T. and De Schreye, D. 2005. Polyno mial In terpretations as a B asi s for T ermi nation Analysis of Logic Pr ograms. In ICLP ’05 . LNCS, vol. 3668. 311–325. Nguyen, M. T. , Bruynoogh e, M. , De Sch rey e, D. , and Leuschel, M. 2006. Pr ogram Sp e- cialisation as a Pre- P r ocessing Step f or T ermi nation Analysi s. In WST ’06 . 7–11. A v ailable at http://w ww.easycha ir.org/FLoC- 06/WST- preproceedings.pdf . Nguyen, M. T. and De S chreye, D. 2007. Polytool : Proving T ermination Automatically Based on Polynomial In terpretations. In LOPSTR ’06 . LN CS, vol. 4407. 210–218. Nguyen, M. T. , Giesl, J. , S chneider-Kamp, P. , and De Schrey e, D. 2008. T ermination Analysis of Logic Programs based on Dep ende ncy Graphs. In LOPSTR ’07 . LNCS, v ol. 4915. 8–22. Ohlebusch, E. , Cla ves, C. , and March ´ e, C. 2000. T ALP : A T ool for the T ermination Analysis of Logic Programs. In R T A ’ 00 . LNCS, vol. 1833. 270–273. Ohlebusch, E. 2001. T erm i nation of Logic Programs: Transformational Metho ds Revisited. Applic able Algebr a in Engine e ring, Communic ation and Computing 12, 1–2, 73–116. P a yet, E. and Mesnard, F. 2006. Nont ermination Inference of Logic Programs. ACM T r ansac- tions on Pr o gr amming L anguages and Systems 28, 2, 256–289. v an Raamsdonk, F. 1997. T ranslating Logic Programs into Conditional Rewriting Systems. In ICLP ’97 . M IT Press, B oston, 168–182. Schneider-Kamp, P. , G iesl, J. , Serebren ik, A. , and Thiema n n, R. 2007. Automated T ermi- nation Analysis for Logic P r ograms by T erm Rewriting. In LOPSTR ’06 . LNCS, vol. 4407. 177–193. Serebrenik, A. and De Schreye, D. 20 03. Proving T ermination with Adornments. In LOPSTR ’03 . LNCS, vol. 3018. 108–109. Serebrenik, A. an d De S ch rey e, D. 2004. Inference of T ermination Conditions for Numerical Loops in Prolog . The ory and Pr actic e of Lo gic Pr o gr amming 4, 5&6, 719–751. Serebrenik, A. a nd De Schreye, D. 2005a. On T ermination of Meta-Programs. The ory and Pr actice of L o gic Pr o gr amming 5, 3, 355–390. Serebrenik, A. an d De Schreye, D. 2005b. T ermi nation of Floating Poin t Computations. Journal of Automate d R e asoning 34, 2, 141–177. Smaus, J .-G. 2004. T ermination of Logic Pr ograms Using V ari ous Dynamic Selection Rules. In ICLP ’04 . LNCS, vol. 3132. 43–57. T amar y , L. an d Codish, M . 2004. Abstract Partial Ev aluation for T ermination Analysis. In WST ’ 04 . 47–50. Av ailable at http://aib.info rmatik.rwth- aachen.de/2004/2004- 07.pdf . TPDB 2007. The Term i nation Problem Data Base 4.0 (Ma y 24, 2007). Av ailable at http: //www.lr i.fr/ ~ marche/t pdb/ . V aucheret, C. and Bueno, F. 2002. More Precise Y et Efficient Type Inference f or Logic Pro- grams. In SA S ’02 . LNCS, vol. 2477. 102–116. W al ther, C. 1994. On Proving the T ermination of Algorithms b y Machine . Artificial Intel li- genc e 71, 1, 101–157. Zantema, H. 1995. T ermination of T erm Rewri ting by Semantic Labell ing. F undamenta Infor- matic ae 24, 1–2, 89–105. Receiv ed March 2008; accepted July 2008 AC M T ransaction s on Comp utational Logic , V ol. V, No. N, 20YY.
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment