Katholieke Universiteit Leuven - core.ac.uk · massimo@hilb ert.math.unip d.it Abstract Recen tly,...

23
Exploiting the power of typed norms in automatic inference of interargument relations Stefaan Decorte, Danny De Schreye, Massimo Fabris Report CW 246, January 1997 Katholieke Universiteit Leuven Department of Computer Science Celestijnenlaan 200A – B-3001 Heverlee (Belgium)

Transcript of Katholieke Universiteit Leuven - core.ac.uk · massimo@hilb ert.math.unip d.it Abstract Recen tly,...

Exploiting the power of typed norms in

automatic inference of interargument

relations

Stefaan Decorte, Danny De Schreye, Massimo Fabris

Report CW246, January 1997

Katholieke Universiteit LeuvenDepartment of Computer Science

Celestijnenlaan 200A – B-3001 Heverlee (Belgium)

Exploiting the power of typed norms in

automatic inference of interargument

relations

Stefaan Decorte, Danny De Schreye, Massimo Fabris

Report CW246, January 1997

Department of Computer Science, K.U.Leuven

Abstract

Recently, the introduction of type formalisms for statically analysinglogic programs has become a commonly applied technique. Morespecifically in termination analysis, typed norms have been intro-duced as a refined way to measure the sizes of terms and atoms.While the expressiveness of these typed norms makes them prac-tically indispensable for a refined termination analysis - particu-larly when proving termination of queries with partially instantiatedterms -, it was not clear how relations between the sizes of (differ-ently measured) arguments of predicates could be derived, and whatsense they would make. We present a technique based on abstractinterpretation for computing such relations and indicate its role intermination analysis. The resulting analysis extends the power ofsome of the more refined automatic termination analysis techniquespresented previously.

Exploiting the Power of Typed Norms inAutomatic Inference of Interargument RelationsStefaan Decorte� Danny De SchreyeyDepartment of Computer Science, K.U.Leuven,Celestijnenlaan 200A, B-3001 Heverlee, Belgium.e-mail : fstefaan,[email protected] FabriszDip. di Matematica Pura e Applicata, Universita di PadovaVia Belzoni 7, 35131 Padova - Italye-mail : [email protected], the introduction of type formalisms for statically analysing logic programshas become a commonly applied technique. More speci�cally in termination analysis,typed norms have been introduced as a re�ned way to measure the sizes of terms andatoms. While the expressiveness of these typed norms makes them practically indis-pensable for a re�ned termination analysis - particularly when proving termination ofqueries with partially instantiated terms -, it was not clear how relations between thesizes of (di�erently measured) arguments of predicates could be derived, and whatsense they would make. We present a technique based on abstract interpretation forcomputing such relations and indicate its role in termination analysis. The result-ing analysis extends the power of some of the more re�ned automatic terminationanalysis techniques presented previously.1 IntroductionTypes are ful�lling an increasingly important role in state of the art approaches to LogicProgram termination analysis (e.g. [4], [17], [3], [7]). The main reason for this is thatone wants to be able to study termination properties of programs for queries containingpartially instantiated terms. Most of the earlier work in this area (e.g. [16], [13]) wasrestricted to queries with ground input arguments and relied on mode information tospecify the queries of interest and the way the input data propagates throughout thecomputation.Depending on the actual strategy of the termination analysis there could be variousreasons and proposed functionalities for integrating type information. But, the followingtwo very related purposes stand out :�supported by GOA, "Non-standard applications of abstract interpretation", DPWB, Belgium.ysenior research associate of the Belgian National Fund for Scienti�c Research.zpartially supported by "Progetto Finalizzato Sistemi Informatici e Calcolo Parallelo" of CNR undergrant 89.00026.69.

1) By providing accurate information on the structure of terms occurring in derivations,types allow to select re�ned ways to measure the size of these terms. Functions fromterms to natural numbers, interpreted as measuring the size of each term, are referred toas norms and form the basis of the well-founded orderings used to prove termination inmany techniques (e.g. [15], [13], [14], [20], [2], [18], [6], [16]).2) Types allow to select the norm in such a way that the norm of those terms in the deriva-tions that are taken into account for the well-founded ordering (which can be thought ofas the 'input' terms) is guaranteed not to grow unboundedly in size due to subsequentderivation steps. The point here is that, if we adopt a norm counting the number ofelements in a list, although the norm of a term [a; bjx], denoted jj[a; bjx]jj, is equal to2, subsequent derivation steps could instantiate x to [c; djy], increasing the norm of the(more instantiated) term to 4. If such increases are not delimited by some upperbound,then the value of the term under the norm can hardly be useful to set up a �nite well-founded order for the derivation. Such upperbounds are typically derived from the term,the type of all possible further instantiation that can occur on it in future derivation stepsand the norm itself.In [7] we propose a technique for inferring appropriate norms from type information.The inferred norms are slightly more general than the ones mentioned above. In thesetting of [7], a typed norm is a function which maps every pair (t; �), consisting of a termt and a type � such that t belongs to � , to a natural number. The type system is that ofnormal rigid types introduced in [9]. Under a typed norm, a same term can be measuredin di�erent ways depending on the type it is considered to belong to. These di�erent typememberships will typically result from the di�erent argument positions of predicates inwhich that same term may occur.To illustrate this, consider the following one-level attening program.Example 1.1 ( atten) atten([]; []): atten([LjZ]; U) atten(Z; U 0); append(L; U 0; U):Assume that we know that the queries of interest are atten(t1; t2), where the typeof t1 is the set of lists of lists of any terms �1, and the type of t2 is the set of lists of anyterms �2. A type inference system (e.g. [9]) allows to derive that any descending call hasthe same types. Assume that typed norms jj:jj�1 and jj:jj�2 are de�ned asjj[t1jt2]jj�1 = jjt2jj�2 + jjt2jj�1jjtjj�1 = 0, for any other termandjj[t1jt2]jj�2 = 1 + jjt2jj�2jjtjj�2 = 0, for any other termClearly, the term [[1; 2]] belongs to the type �1 as well as to �2, and jj[[1; 2]]jj�1 = 2, whilejj[[1; 2]]jj�2 = 1.The purpose of allowing the generality of typed norms is both to facilitate the auto-matic inference of "suitable" norms from type information (see [7]) and to improve theexpressivity of interargument relations. Here, an interargument relation refers to a rela-tion that holds between the (typed) norms of the terms in di�erent argument positions(measured according to each argument's type) of success instances of a predicate. To2

illustrate the latter point, notice that in the atten example the interargument relationjjt1jj�1 = jjt2jj�2 holds for any success atom atten(t1; t2). No "non-typed" norm is capa-ble of representing this, since even expressing this relation requires norms that do assigndi�erent sizes to a same term, depending on the type it is considered to belong to.The main property of the typed norms inferred in [7] is rigidity. For any term t1of type �1 and for any substitution � : jjt1�jj�1 = jjt1jj�1. Note that normal rigid typesare substitution closed, so that jjt1�jj�1 is well de�ned. Rigidity of (typed) norms is aconservative way of ensuring that no unbounded growth of the norm of a term can occurdue to further derivation steps. In general, it is also a practical way of ensuring it, sincefor typed norms it can be syntactically veri�ed (see [7]). In fact, this syntactic veri�cationforms the key criterion for inferring the norms from the given types.As argued in [7], typed norms can easily be integrated into existing termination anal-ysis techniques, such as [6], [20], [2]. Only one aspect of the termination analysis is anexception in this respect : the inference of the interargument relations. As we reportedin [7], a rather straightforward extension of the technique proposed in [19] to the case oftyped norms will be sound, but the loss in precision is most often unacceptable. We referto subsection 2.3 for a discussion of the problems.In this paper, we propose an automated technique for inferring interargument relationsfor typed norms. As in [19], 1) we infer systems of linear relations to approximate theinterargument relations, and 2) we formulate the technique as an instance of an abstractinterpretation framework. A main distinction with respect to [19] - besides of the focuson typed norms and the improved expressivity this entails - is the use of the bottom-upabstract interpretation framework of [1], which reduces the technical complexity of theanalysis. The main advantage of this framework being that we can abstract away fromthe operational semantics of SLD-resolution, used in top-down abstract interpretationframeworks.The remainder of the paper is organised as follows. In section 2 we recall somepreliminary notions regarding normal rigid types and typed norms, termination analysisand interargument relations. In section 3 we introduce a notion of a back-propagatedsuccess-typed program, which is a key notion for overcoming the problems in inferringinterargument relations for typed norms. Section 4 presents the abstract domain and theabstract analysis. In section 5 we present a detailed example. Finally, we discuss themerits of the technique and relate it to other work.2 Preliminaries2.1 (labelled) rigid typesThe type formalism chosen in this paper is the one of [9]. The reasons for this choice are1) rigid types provide su�cient precision for the application, 2) automatic inference ofrigid types through abstract interpretation has been fully developed and described in [9],3) the tools for inferring them are available at our site, allowing for extensive experimentswith the proposed techniques. Due to space restrictions and since rigid types are not partof the contribution of this paper, we refer to [9] and [12] for the underlying intuitions.Here, we only recall the basic de�nitions and give an example.There exist a number of primitive types (e.g. INT, REAL), which represent subsets ofthe set of constants in the language. We denote the set of all primitive types by P , and we3

assume that there exists a function Denote : P ! 2ConstP , mapping each primitive typeto a corresponding set of constants. We use ConstP and FunP to to denote respectivelythe set of constants and the set of function symbols of P .Rigid types are formally de�ned by means of type graphs, which are a particularinstance of directed graphs. We assume that the reader is familiar with the basics ofgraph theory.De�nition 2.1 (labelled rigid type graph; adapted from [9])A labelled rigid type graph T is a 6-tuple, (Nodes,ForArcs,BackArcs,Label,ArgPos,TypeLabel),where1. Nodes is a �nite, non-empty set of nodes,2. ForArcs � Nodes�Nodes such that (Nodes;ForArcs) is a tree,3. BackArcs � Nodes� Nodes such that for each arc (m;n) 2 BackArcs, node n is anancestor of node m in ForArcs,4. Label is a function Nodes! P [ ConstP [ FunP [ fMAX; ORg, and5. ArgPos is a function: Sk>0(fm 2 Nodes j Label(m) = f=k 2 FunP g � f1; : : : ; kg)!Nodes n frootg, such that for each m 2 Nodes, with Label(m) = f=k, ArgPos(m; �) :f1; : : : ; kg ! Nodes is a bijection from f1; : : : ; kg onto fn 2 Nodes j (m;n) 2ForArcs [ BackArcsg.6. TypeLabel is a function Nodes! TypeNames and TypeNames is a set of uniqueidenti�ers.Each node n such that Label(n) = f=k has k immediate descendants, each node labelledOR has at least two immediate descendants, and the other nodes have no descendants andare called terminal nodes. Descendants of OR-nodes or functor-nodes are found using theDesc function.De�nition 2.2Desc : fn 2 Nodes j Label(n) 2 FunP [ fORgg ! 2Nodes : Desc(n) = fn0 j (n; n0) 2ForArcs [ BackArcsg.A rigid type graph T describes a (possibly in�nite) set of �nite terms. This set of�nite terms is found by means of the denotation function, ID. We refer to ([12], Def.2.3.4 and following) for formal de�nition.In [7], the function TypeLabel was introduced to regard a rigid type graph as aspeci�cation of a set of rigid types : every node in the type graph can be considered asthe root of a new type graph, de�ned by the subgraph rooted at that node. In the sequelwe will use rigid types as a shorthand for labelled rigid types.The next de�nition enables us to associate sets of terms to TypeLabels.De�nition 2.3 (denotation of a TypeLabel)Let L = TypeLabel(n) be the TypeLabel of a node n in a labelled type graph T . Weextend the notion of denotation to TypeLabels as : IL(L) = ID(n).A labelled rigid type is now presented by means of its graphical representation. In�gure 1 the set of all nil-terminated lists which take nil-terminated lists of any terms aselements is depicted as a type graph. It could be used to specify the call type of the �rstargument of the atten predicate in Example 1.1.4

OR

OR

[]/2

[]/2nil/0

nil/0

L5

L4

L1

L3

Max

L7

L6

L2

Figure 1: An example of a labelled graphIn [9], rigid type graphs are used as a component of an abstract domain. For reasonsof e�ciency, rigid type graphs must be further restricted to normal type graphs.De�nition 2.4 (principal nodes; see [9]: de�nition 4.5)Let T=(Nodes,ForArcs,BackArcs,Label,ArgPos,TypeLabel) be a rigid type graph. Theprincipal nodes of a node n 2 Nodes are found by means of the function Principal :Nodes! 2Nodes:Principal(n) = Sn02Desc(n) Principal(n0) if Label(n) = ORPrincipal(n) = fng otherwise:The main limitation imposed by normal type graphs is that principal nodes of anygiven node should have distinct function symbols. Note that the type in �gure 1 satis�esthis normality criterion.2.2 Typed normsOR-nodes de�ne a type whose denotation is the union of the denotation of some othertypes. Moreover, if we work with normal type graphs this is a union of disjoint sets ofterms. Under the assumption that we deal with normal types and given such a term, thegraph enables us to identify in an unambiguous way its TypeLabel. The next de�nitioncollects for some OR-node all TypeLabels which are relevant (in the above sense) for it.De�nition 2.5 (Successor type label set of an OR-node)Let T be a labelled type graph and n a node in T such that label(n) = OR. The successortype label set of n; succ label(n) is de�ned assucc label(n) = fL j 9(n;m) 2 ForArcs [BackArcs ^m0 2 Principal(m)^TypeLabel(m0) = Lg:Given a normal type T , in [7] the authors faced the problem of deriving a norm whichmakes all terms in the denotation of the type rigid.5

De�nition 2.6 (typed norm induced by a TypeLabel in a normal type)Let T be a labelled normal type and L = TypeLabel(n) the TypeLabel of a node n in T .The typed norm induced by L is the function jj:jjL : TermP =� ! IN de�ned as :if label(n) = OR then jjtjjL =PLi2Succ Label(n) jjtjjLielse if label(n) = f=k then jjf(t1; :::; tk)jjL = cf;L +Pni=1 jjtijjLiwith Li = TypeLabel(ArgPos(n; i))and cf;L a constant depending on f and L:else jjtjjL = 0Because of the restriction to normal types, the case in which label(n) = OR reducesjjtjjL to exactly one of the jjtjjLi. As mentioned above, for normal types, the top-levelfunctor of t corresponds to a unique m0 2 Principal(n) and its TypeLabel(m0). Sincemoreover jjtjjL = 0 for terms t such that t 62 IL(L), at most one of the summands inPLi2Succ Label(n) jjtjjLi is non-zero.The last case in the de�nition captures primitive types and the MAX type. Thesetypes get assigned the constant zero-norm.Each normal type is now assigned a norm as follows:De�nition 2.7 (typed norm induced by a normal type)Let T be a labelled normal type. The norm induced by T , denoted jj:jjT , is the norminduced by TypeLabel(nroot).The following proposition is the main result of the construction.Proposition 2.8 Let T be a labelled normal type and L = TypeLabel(n) the TypeLabelof a node in T . Then 8t 2 IL(L) : t is rigid with respect to jj:jjL.Example 2.9 (typed norm induced by the typegraph of Fig. 1)De�nition 2.6 can be applied to each node in the labelled graph presented in Figure 1.This gives the following de�nitions :jj:jjL2 = jj:jjL5 = jj:jjL7 � 0jjtjjL1 = jjtjjL2 + jjtjjL3jjtjjL4 = jjtjjL5 + jjtjjL6jj[X jY ]jjL3 = c:=2;L3 + jjX jjL4 + jjY jjL1jj[X jY ]jjL6 = c:=2;L6 + jjX jjL7 + jjY jjL4To clarify the de�nition, we can resolve this system in function of jj:jjL1 and jj:jjL4(these correspond to the call types in catenate and append).jj[X jY ]jjL1 = c:=2;L3 + jjX jjL4 + jjY jjL1jj[X jY ]jjL4 = c:=2;L6 + jjY jjL4Note that when determining the constants c:=2;L3 and c:=2;L6 as respectively 0 and 1, weobtain the norm used in the introduction. 6

2.3 Termination analysis and interargument relationsAlthough typed norms o�er higher precision in measuring sizes of terms, they have thedisadvantage of complicating the termination analysis. In particular, inference of interar-gument relations needs special consideration. One may intuitively expect complications,because norms form the basic building blocks to associate well-founded orders to deriva-tions in termination proofs. So, measuring terms of di�erent types in di�erent ways(especially, measuring a same term di�erently depending on the considered type) can beexpected to obscure the termination argument.In this paper we follow the termination analysis framework of [6]. This is not alimitation in the sense that most of the results in the following sections can easily beintegrated in other frameworks, such as e.g. [2]. To simplify the discussion, we recall thekey notions of [6] in the context of directly recursive programs only. In what follows, �denotes the variant relation on both atoms and terms.De�nition 2.10 (call set)Let P be a de�nite program and S a set of atomic queries with a �xed predicate symbol.The call set, Call(P; S), is the set of all atoms A such that a variant of A is a selectedatom in some derivation for (P;Q), for some Q 2 S and under the left-to-right selectionrule.In our setting we will assume that S is speci�ed in terms of the predicate symbol p=nand an n-tuple of normal rigid call types (T1; � � � ; Tn) for its argument. In other words,S = f p(t1; � � � ; tn)jti 2 ID(Ti)g for some given T1; � � � ; Tn. Furthermore, we assume thatan upper approximation of Call(P; S) is provided using the type inference of [9]. Thus, foreach predicate q=m in P , we assume that an m-tuple of normal rigid types (S1; � � � ; Sm)has been inferred, such that if q(s1; � � � ; sm) 2 Call(P; S), then si 2 ID(Si); 8i = 1; � � � ; m.De�nition 2.11 (level mapping)A level mapping is a function f : Call(P; S)=�! IN .In this paper we only consider level mappings de�ned through the following scheme.For any predicate q=m in P , let (S1; � � � ; Sm) be the associated call types generated by thetype inference. Let jj:jjS1; � � � ; jj:jjSm be any sequence of associated typed norms generatedfor S1; � � � ; Sm following [7]. Then for any q(s1; � � � ; sm) 2 Call(P; S); f(q(s1; � � � ; sm) issome positive linear combination of jjs1jjS1 ; � � � ; jjsmjjSm , where the coe�cients dependonly on q=m.De�nition 2.12 (acceptability wrt S)Let S be a set of atomic queries with a �xed predicate and P a de�nite directly recursiveprogram. P is acceptable wrt S if there exists a level mapping f and a model I for P ,such that� for any A 2 Call(P; S)� for any clause A0 B1; � � � ; Bn in P , such that mgu(A;A0) = � exists,� for any atom Bi, such that I j= Bj�; 1 � j > i and having the same predicatesymbol as A : 7

f(A) > f(Bi�)The following proposition is one of the key results in [6].Proposition 2.13 A directly recursive program P terminates for any query in S if andonly if P is acceptable wrt S.From the above it becomes clear that the extension from norms to typed norms hasno impact on the termination conditions as such. The reason is that, although di�erentterms may be measured using di�erent norms depending on their types, the two atomsA and Bi� in the acceptability condition are measured in the same way. This is becausethey have the same predicate, there is only one tuple of call types associated to eachpredicate and the level mapping is de�ned as a �xed combination of the typed normsassociated to the call types. Thus, the call and descending recursive call are measured inthe same way, and De�nition 2.12 remains to capture well-founding and termination.The problem of providing the model I in the de�nition of acceptability is a quitedi�erent matter. In [6] this is done by computing an interargument relation for the inter-mediate atoms B1; � � � ; Bi�1. This in turn is achieved through abstract interpretation, asdiscussed in [18]. In the setting of typed norms the notion of an interargument relationneeds to be specialised wrt the types of the argument positions. In the following de�ni-tion, we assume that for any type T a corresponding typed norm jj:jjT generated as in [7]has been �xed.De�nition 2.14 (interargument relation wrt a tuple of types)Let p=n be a predicate of P and (T1; � � � ; Tn) an n-tuple of normal rigid types. Aninterargument relation for p=n wrt (T1; � � � ; Tn) is a relation R � INn such that for anyp(t1; � � � ; tn) satisfying P j= p(t1; � � � ; tn) and ti 2 ID(Ti); 8i = 1; � � � ; n; R(jjt1jjT1; � � � ;jjtnjjTn) holds.Notice that the notion is more speci�c than that of an interargument relation in thesense that the relation is not required to hold for the entire success set for p in P . Inparticular, given a clauseq(s1; � � � ; sm) p(t1; � � � ; tn); (1) r(u1; � � � ; uk); (2) q(s01; � � � ; s0m)we will usually be interested in an interargument relation for p=n and r=k which holdswrt the types that the arguments of these predicates have when point 2 in the derivationis reached. Notice that these types may be more speci�c than the success types for p=nin general in P . The reasons are : 1. The clause may possibly be activated with a speci�ccall type, 2. the success substitutions for r=k may further specialise the success types ofp=n.One of the main problems we now need to solve is to produce a set of type tuples,as input for the de�nition of the interargument relation, that is su�ciently precise andconsistent to provide a useful model for de�nition 2.12. Here, the following considerationsare important. We illustrate them with the above example.1. A simple solution would be to apply the type inference of [9] and to collect allsuccess types that hold at execution point 2 for the intermediate atoms (p=n and8

r=k) and for all other predicates on which these depend in P . The problem is that,given an additional clausep(t01; � � � ; t0n) s(v1; � � � ; vl) (3)of P , a method such as the one in [9] will only provide success types for s=l whichhold locally at point 3, without incorporating the additional instantiations causedon s(v1; � � � ; vl) by solving r(u1; � � � ; uk) (at point 2). In theory, this is no problem,in the sense that the success types at point 3 will provide a correct interargumentrelation for s=l. However, the interargument relations for p=n and r=k (at point 2)need to be computed on the basis of the interargument relations for the predicateson which they depend in P . The fact that the latter relations are computed withrespect to quite di�erent success types (e.g. those that hold at point 3) causesenormous consistency problems : the same terms are measured with respect todi�erent norms, making propagation of relations over di�erent clause levels virtuallyimpossible.2. An alternative is to use the bottom-up type inference of [1]. However, here theproblem is that such an approach does not easily allow to take the call information,with which a clause is entered, into account.3. A �nal option, and essentially the solution we take in the remainder of the paper,is to use the approach of [9] augmented with a reexecution strategy (see e.g. [11]).This means that, once success types for p=n have been computed, the type inferenceis restarted using the previously obtained success types as the call types for p=n. Bydoing so, instantiations caused in the �nal part of a derivation are back-propagatedonto previous calls.3 Back-propagated success-typed programsIn this section we associate to a given de�nite program P , a predicate symbol p=n of Pand an n-tuple �T = (T1; :::; Tn) of normal rigid types a type-annotated program, Pp; �T .In light of the discussion ending the previous section, p=n ful�ls the role of either p=n orr=k in the example clause, and �T that of the types of the arguments of p=n (or r=k) atexecution point 2. Intuitively, Pp; �T annotates all predicates of P that depend on p=n witha tuple of success types that a type inference system augmented with reexecution wouldassign to them. As such, all success type annotations will be consistent with the types�T , in the sense that they take into account any further instantiations produced betweenthe successful refutation of the atom and execution point 2.We will refer to such programs Pp; �T as back-propagated success-typed programs, whichre ects this intuition.De�nition 3.1 (type-annotated atom)For any atom A = p(t1; � � � ; tn) and n-tuple of types �T = (T1; � � � ; Tn), the type-annotatedatom associated to A and �T is A �T = pT1;���;Tn(t1; � � � ; tn).De�nition 3.2 (well-typed atom)A well-typed atom is a type-annotated atom pT1;���;Tn(t1; � � � ; tn) such that ti 2 ID(Ti); 8i =1; � � � ; n. 9

In the sequel we assume that our language is extended with a set of extra built-inpredicates, =T;T , one for each normal rigid type T . On the level of logic, one may thinkof these predicates as simple renamed versions of the usual uni�cation without any addedfunctionality. The added functionality will only turn up on the level of the abstractinterpretation.De�nition 3.3 (type-annotated clause)For any clause C : A0 A1; � � � ; An , such that Ai has arity mi, 8i = 0; � � � ; n, and forany (n+ 1)-tuple of tuples of types, ( �T0; � � � ; �Tn), where �Ti = (T 1i ; � � � ; Tmii ); i = 0; :::; n;A �T00 A �T11 ; � � � ; A �Tnn is a type-annotated clause.De�nition 3.4 (success-typed clause)Let P be a de�nite program, C : p(t1; :::; tm) A1; � � � ; An a clause in P and �T =(T1; � � � ; Tm) an m-tuple of types. A success-typed clause associated to P;C and �T is atype-annotated clausepT1;���;Tm(t1; � � � ; tm) A �T11 ; � � � ; A �Tnnsuch that for every substitution � satisfying pT1;���;Tm(t1; � � � ; tm)� is a well-typed atomand P j= (A1; � � � ; An)�, we have that A �Tii � is a well-typed atom, 8i = 1; � � � ; n.De�nition 3.5 (failed type-annotated clause)A failed type-annotated clause is a type-annotated clauseA �T00 A �T11 ; � � � ; A �Tnnsuch that there exists an i; 1 � i � n, and a T ji in �Ti, with T ji =?.De�nition 3.6 (back-propagated success-typed program)Let P be a de�nite program, p a predicate symbol of P with aritym and �T = (T1; � � � ; Tm)an m-tuple of types. A back-propagated success-typed program associated to P; p and �T isa de�nite program Pp; �T such that :1. for each clause C : p(t1; � � � ; tm) A1; � � � ; An in P either there exists a failedsuccess-typed clause associated to P;C and �T , or Pp; �T contains a unique success-typed clause associated to P;C and �T .2. for every predicate QS1;���;Sr in Pp; �T , di�erent from =S1 ;S1 , Pp; �T is a back-propagatedsuccess-typed program associated to P; q and (S1; � � � ; Sr).Example 3.7 (permute)The following program (in normal form) is a back-propagated success-typed program10

associated to the well-known permute (with delete) program, permute=2 and (�2; �2). Wedenote bypermute�2;�2(X; Y ) X =�2;�2 []; Y =�2;�2 []:permute�2;�2(X; Y ) Y =�2;�2 [EjL];delete�2;MAX;�2(X;E;R);permute�2;�2(R;L):delete�2;MAX;�2(Y;X; L) Y =�2;�2 [X jL]:delete�2;MAX;�2(Y;X; L) Y =�2;�2 [H jT1];L =�2 ;�2 [H jT2];delete�2;MAX;�2(T1; X; T2):Essentially, a back-propagated success-typed program (in short, success-typed program)Pp; �T associated to P; p and �T has essentially the same clauses as P , except that : 1) Pp; �Tmay have multiple annotated versions of the same clause in P , 2) all explicit uni�cationsare replaced by typed uni�cations, 3) some clauses of P which lead to failure for theconsidered types may have no counterpart in Pp; �T .Due to this relation between P and Pp; �T , we have the following proposition :Proposition 3.8 (completeness of success-typed programs)Let P; p and �T be as above and let Pp; �T be an associated success-typed program. Forany atom p(t1; � � � ; tm) such that P j= p(t1; � � � ; tm) and ti 2 ID(Ti); i = 1; � � � ; m, we havePp; �T j= pT1;���;Tn(t1; � � � ; tn).This property is crucial in the next section. Here, the inference of an interargumentrelation for p wrt �T in P will be performed by inferring an interargument relation forpT1;���;Tn wrt �T in Pp; �T . Proposition 3.8 states that the latter interargument relation isalso an interargument relation for p wrt �T in P .Throughout the remainder of the paper we assume that the program P is in normalform (see e.g. [9]). On the highest level this means that all uni�cations are made explicitusing the uni�cation builtin =/2. Furthermore, all arguments of atoms with user de�nedpredicates are variables and, for each clause, all such variables in the clause are mutuallydistinct. Non-variable terms may only occur at the right-hand side of =/2 and can only beof the type f(X1; � � � ; Xn); n � 0 (0 corresponds to a constant), with X1; � � � ; Xn distinctvariables. Any program can be transformed into an equivalent program in normal form.Note that if P is in normal form, then Pp; �T is in normal form as well, (remember that wedo not regard typed uni�cation as di�erent from the usual explicit uni�cation), for any pand �T .We conclude the section with one further re�nement on the notion of a success-typedprogram. In essence, its purpose is to avoid that multiple occurrences of a same variablein a clause get di�erent annotations.De�nition 3.9 (consistently, success-typed program)Let P be a program in normal form, p=m a predicate in P and �T an m-tuple of types. Asuccess-typed program Pp; �T associated to P; p and �T is consistent if for each clause C inP and for each variable X occurring in C there exists a unique type T such that :11

� if X occurs as the i-th argument of an atom qS1;���;Sr (t1; � � � ; tr), then Si = T ,� if X occurs as the i-th argument of f(t1; � � � ; tr) in an atom Y =S;S f(t1; � � � ; tr),then S is a union type with subtype f(S1; � � � ; Sr) and Si = T .The success-typed program in Example 3.7 is consistent.4 Derivation of linear interargument relations with re-spect to typed normsFor this section, we assume that P is a consistently success-typed program and that npredicates (di�erent from the annotated uni�cation) are de�ned in it. Subsection 4.4describes how to compute bottom-up for each of these predicates a linear interargumentrelation with respect to the types with which they are adorned. First we provide a solidbase for the procedure by describing the concrete and abstract domain, abstraction (andconcretisation) function and some useful operations.4.1 Concrete domainObviously the concrete domain consists of sets of annotated atoms. All atoms in such aset obey their annotations, i.e. the atoms are well-typed. We can equip D with a partialorder relation � de�ned as the subset relation on sets.4.2 Abstract domainAnalogously to [19], we abstract size relations as systems of linear equations. A lin-ear equation is an equation of the form a1X1 + � � �+ amXm = b where ai; b 2 Q; 8i 2f1; � � � ; mg. Geometrically interpreted, (the set of solutions of) such an equation corre-sponds to a hyperplane of dimension m � 1 in m-dimensional space. Then, a systemof such equations corresponds to the intersection of the hyperplanes associated to eachequation. Such systems can be represented by a matrix of the form �A � �X = �c, where �A isan m�n matrix of real numbers, �X is an n�1 matrix of variables and �c is a 1�m matrixof real numbers. Because di�erent systems can have the same set of solutions, thus candenote the same hyperplane, a canonical form is introduced: the so-called row echelonform of a system. A system of equations �A � �X = �c is in row echelon form if its augmentedmatrix (i.e. the matrix [ �Aj�c]) is in reduced row echelon form. Three conditions must besatis�ed for such a matrix [ �Aj�c] = [aij ]: 1) the �rst non-zero entry in a row is 1, 2) for anyrow i0 let j0 be the �rst column with a non-zero entry, then for all i > i0; j � j0; aij = 0,3) for any row i0, let j0 be the �rst non-zero entry, then for all i < i0; aij0 = 0.This form can always be obtained by repeated application of one of three basic opera-tions: multiplication of a row by a scalar, addition of one row to another and permutationof two rows.Because there exist multiple ways to represent unsolvable systems, we adopt theconvention to denote such a system by the symbol ?. We refer to [19] for more details.In the abstract interpretation procedure, the following operations on systems of equa-tions will occur frequently. 12

� Intersection. Obviously, a tuple is a solution of the intersection of two systems ifit is a solution of both systems. Thus, the intersection of two systems of equationscorresponds to the set of solutions of the combined systems. Computing the inter-section of two systems �A1 � �X = �c1 and �A2 � �X = �c2 corresponds to reducing to rowechelon form the augmented matrix" �A1�A2 ����� �c1�c2 #� Disjunction. Given two systems of equations S1 and S2, their disjunction is anew system which has as solutions the solutions of both systems. Of course, theunion of two hyperplanes is very seldom a new hyperplane. We refer to [10] for thepresentation of a technique which computes the most precise system of equationswhose solution set comprises the two given hyperplanes.� Restriction. Let �A be anm�n-matrix and let �X be the transposition of [X1; � � � ; Xn].The restriction of a system �A � �X = �c to variables Xk+1; � � � ; Xn is a system�Ar � �Xr = �cr ( �Ar has dimension m0 � (n� k)) such that9x1; � � � ; xn 2 IR : (x1; � � � ; xk; xk+1; � � � ; xn) is a solution of �A � �X = �cm(xk+1; � � � ; xn) is a solution of �Ar � �Xr = �cr[19] describes how to compute this operation for a system in reduced row-echelonform.� Extension. This is the converse of the restriction operation. The operation mapsa system �A � �X = �c to a system �Ae � �Xe = �ce such that(x1; � � � ; xk) is a solution of �A � �X = �cm8xk+1; � � � ; xn 2 IR : (x1; � � � ; xk; xk+1; � � � ; xn) is a solution of �Ae � �Xe = �ceIn practice, this is performed by adding (n � k) colums of 0's to �A and adding krows of a single 0 to �c.A partial order can be established on these systems of linear equations as follows: LetS1 = �A1 � �X = �c1 and S2 = �A2 � �X = �c2. Then S1 � S2 i� S1 =?, or S2 = >, or theintersection of S1 and S2 is S1. We have S1 � S2 i� S1 � S2 and S2 � S1. Obviously, ?and > are minimal and maximal for this order.Two extremely useful operations on systems with the same domain, are the least upperbound and the greatest lower bound operation. They are de�ned as follows. Let S; S1 andS2 denote systems of linear equations with S1; S2 62 f?;>g:� lub(S;>) = lub(>; S) = >.� lub(S;?) = lub(?; S) = S.� lub(S1; S2) = disjunct(S1; S2). 13

The greatest lower bound is de�ned as:� glb(S;>) = glb(>; S) = S.� glb(S;?) = glb(?; S) =?.� glb(S1; S2) = intersect(S1; S2).As [19] indicates, there do not exist in�nitely ascending chains of systems S0 < S1 < � � �.The maximum length of a strictly ascending chain is equal to the dimension of the domain.We are now in a position to specify our abstract domain. If we denote the set ofall possible systems of linear equations over k variables by Ekq , then we �x our abstractdomain to be D� = (Ek1q ; Ek2q ; � � � ; Eknq ), for some k1; � � � ; kn 2 IN , i.e. elements of ourabstract domain correspond to n-tuples of systems of linear equations of �xed dimensions.The order on systems of equations naturally induces an order relation v on our abstractdomain: 8 < S1; � � � ; Sn >;< S 01; � � � ; S 0n >2 D� : < S1; � � � ; Sn >v< S 01; � � � ; S 0n > i�Si � S0i; 8i 2 f1; � � � ; ng. Similarly, we can lift the equivalence � on systems of equationsto this domain.Proposition 4.1 D� is a complete lattice with as bottom element <?; � � � ;?> and astop element < >; � � � ;> >.4.3 Abstraction and concretisation functionWe �rst restrict our attention to a single system of equations. Let S be a set of atomswith predicate symbol pT1;���;Tm . We de�ne the abstraction of S; _�(S); to be a repre-sentative of the least �-equivalence class of Emq having all tuples (jjt1jjT1; � � � ; jjtmjjTm);pT1;���;Tm(t1; � � � ; tm) 2 S as solutions. This also �xes the concretisation function: given aset of linear equations S over m variables and a predicate pT1;���;Tm, then the concretisa-tion for that predicate, _ (S; pT1;���;Tm) = fpT1;���;Tm(t1; � � � ; tm) j (jjt1jjT1; � � � ; jjtmjjTm) is asolution of S and ti 2 ID(Ti)g. It can easily be proved that S1 � S2 i� _ (S1; p) � _ (S2; p),for any p with appropriate arity.In general, the abstraction function is de�ned as follows. Let us �rst �x an order onthe predicate symbols of the program by the use of a bijection � : Pred(P )! f1; � � � ; ng,where Pred(P ) is the set of all predicate symbols de�ned in P (annotated uni�cationexcluded). We assume that the arity of ��1(i) is ki; 8i 2 f1; � � � ; ng. Given a set ofatoms A = [ni=1Ai; where Ai is a set of atoms with predicate symbol pT1;���;Tm and�(pT1;���;Tm) = i, then, �(A) =< S1; � � � ; Sn > where Si = _�(Ai). This de�nition alsoallows to �x our concretisation function : (< S1; � � � ; Sn >) = [ni=1 _ (Si; ��1(i)).Proposition 4.2 The partial orders � on D and v on D� and the concretisation function(abstraction function) establish a Galois connection between both domains.Proposition 4.3 The abstract domain does not contain in�nitely ascending chains.Proof Trivial, because there does not exist an in�nite sequence of systems of linearequations E0 @ E1 @ � � � The maximal length of strictly ascending tuples of systems isbounded by the sum of the number of variables in each system.14

4.4 Bottom-up abstract interpretation procedureThe goal of abstract interpretation is to approximate the semantics of programs. In thispaper we consider the TP semantics and we adopt the bottom-up abstract interpretationof [1]. The basic operation is the abstract interpretation of uni�cation. In [19], using atop-down framework, given a call to uni�cation, X = t, and an abstract call substitution,Ekq (a system of linear equations) the abstract success substitution is Ekq[fX = absjj:jj(t)g.Here, absjj:jj is called the abstract norm and it is a function which maps each term t toa linear arithmetic expression, which can best be described as a partial evaluation of theconcrete norm on the term. In our setting, the notion is generalised to type-annotateduni�cation and typed norms as follows:De�nition 4.4 (size expression induced by a typed norm jj:jjL)Let T be a labelled normal type, let L = TypeLabel(n) be the TypeLabel of a node n in T ,and jj:jjL the associated norm. A term t is mapped to the size expression absL(t) inducedby the norm jj:jjL by means of the following function absL : TermP =� ! L<0;1;+;�>de�ned asif label(n) = OR then absL(X) = Xotherwise absL(t) =PLi2SuccLabel(n) absLi(t)else if label(n) = f=k then absL(X) = XabsL(f(t1; :::; tk)) = cf;L +Pni=1 absLi(ti)with Li = TypeLabel(ArgPos(n; i))otherwise absL(t) = 0else absL(t) = 0We use absT (t) as a shorthand for absL(t) for a type T with root r and TypeLabel(r) = L.The abstract T �P operator is de�ned in three stages. First, we introduce an auxiliaryfunction A which, given an atom (either user de�ned or uni�cation) and the currentlyobtained element E of the abstract domain, selects from E the information relevant tothis atom.De�nition 4.5 ALet p �T =k be a predicate de�ned in P and let E 2 D� be a vector of systems of equations,one system for each of the n predicates occurring in P . By E[p �T ] we denote the systemof equations corresponding to p �T=k. Then the operator A abstracts atoms as followsA : �BP �D� ! [i2INEiq :A(X =T;T t; E) = fX = absT (t)gA(p �T (X1; � � � ; Xk); E) = E[p �T ]� where � is a renaming of the variables in E[p �T ] accordingto X1; :::; XkNext we de�ne a T�P operator which, for each E 2 D�, computes the separate entries inthe �nal n-tuple, T �P (E) 2 D�. More in particular, T�P : Pred(P )�D� ! [ni=1Ekiq , withT�P (��1(i); E) 2 Ekiq .De�nition 4.6 T�PLet pT1;���;Tk 2 Pred(P ) and assume that pT1;���;Tk is de�ned by m clauses C1; � � � ; Cmin P . We further assume that the heads of all clauses Ci; i = 1; � � � ; m are identical, i.e.15

pT1;���;Tk(X1; � � � ; Xk) for a �xed tuple of variables (X1; � � � ; Xk). Finally, let (Zi1; � � � ; Zili) =(X1; � � � ; Xk; Y ik+1; � � � ; Y ili) be the tuple of all variables occurring in Ci; i = 1; � � � ; m, where(Y ik+1; � � � ; Y ili) are the local variables.T�P (p �T ; E) = lub(A(p �T(X1; � � � ; Xk); E); lubi=1;���;m(Ei))whereEi = restrict((X1; � � � ; Xk); EBodyi)EBodyi = glbB2Body(Ci)(EB)EB = extend((Zi1; � � � ; Zili); A(B;E)):Lemma 4.7 A(p �T (X1; � � � ; Xk); E) � T�P (p �T ; E).Proof Trivial.From T�P , we can now easily de�ne T �P : D� ! D�.De�nition 4.8 T �PT �P : D� ! D� : E !< T�P (��1(1); E); � � � ; T�P (��1(n); E) >.Lemma 4.9 T �P is monotonic.Proof A proof has been included in the appendix.De�nition 4.10 !-�rst powers of T �PThe !-�rst powers of the operator are de�ned as usual:T �P " 0 =<?; � � � ;?>.T �P " (i+ 1) = T �P (T �P " i).T �P " ! = lubi2INT �P " i.Proposition 4.11 There exists an n 2 IN such that T �P " n is a least �xpoint.Proof This is an immediate consequence from:1) E v T �P (E) (because of Lemma 4.7)2) T �P (E) is monotonic3) D� has no in�nite ascending chains.Proposition 4.12 T �P safely approximates the TP -operator.Proof We again refer to the appendix where the proposition is proved.16

5 An exampleConsider our atten program of example 1.1 and suppose we would like to derive aninterargument relation for atten with respect to the types �1 and �2 of the introduction.First we rewrite the atten program as a consistently success-typed program associatedto P , atten/2 and �T = (�1; �2) which for simplicity we denote as PT . atten�1;�2(X; Y ) X =�1;�1 []; Y =�2;�2 []: atten�1;�2(X; Y ) X =�1;�1 [LjZ]; atten�1;�2(Z; U);append�2;�2;�2(L; U; Y ):append�2;�2;�2(X; Y; Z) X =�2;�2 []; Y =�2;�2 Z:append�2;�2;�2(X; Y; Z) X =�2;�2 [H jT1];Z =�2;�2 [H jT2];append�2;�2;�2(T1; Y; T2):As a convenience, let us number these clauses TC1 till TC4. As PT de�nes two predicateswith arity 2 and 3 respectively, T �PT is de�ned on < E2q ; E3q > i.e. we adopt the conventionthat in a couple < Sf ; Sa >; Sf corresponds to a system of equations for atten�1;�2 andSa to one for append�2;�3;�3 . In order to enhance the readability of this example we donot work with the matrix representation of the systems of equations. Neither do we showwhere the extension operation comes in.Then:T �PT " 0 =<?;?>.T �PT " 1: Here we have to compute both T�PT ( atten�1;�2=2; <?;?>) andT�PT (append�2 ;�2;�2=3; <?;?>). Starting with atten�1;�2 , we compute for both of itsclauses TC, (glbB2Body(TC)A(B;<?;?>))jfX;Y g. TC1 gives glb(fX = 0g; fY = 0g)jfX;Y g= fX = 0; Y = 0g.For TC2 we obtain glb(fX = L + Zg;?;?)jfX;Y g =?. Hence lub(?; fX = 0; Y = 0g;?) = fX = 0; Y = 0g.For TC3, for append�2;�2;�2=3, glb(fX = 0g; fY = Zg)jfY;X;Zg = fX = 0; Y = Zg iscomputed. TC4 gives glb(fX = 1 + T1g; fZ = 1 + T2g;?)jfY;X;Zg =?.lub(?; fX = 0; Y = Zg;?) = fX = 0; Y = Zg.Thus, T �PT " 1 =< fX = 0; Y = 0g; fX = 0; Y = Zg >.T �PT " 2: We again consider all clauses, now making use of the information computed in theprevious iteration. For TC1, we obtain glb(fX = 0g; fY = 0g)jfX;Y g = fX = 0; Y = 0g.TC2 gives glb(fX = L + Zg; fZ = 0; U = 0g; fL = 0; U = Y g)jfX;Y g = fX = 0; Y = 0g.Then T�PT ( atten�1;�2=2; T �PT " 1) = lub(fX = 0; Y = 0g; fX = 0; Y = 0g; fX = 0; Y =0g) = fX = 0; Y = 0g.TC3 results in glb(fX = 0; Y = Zg)jfY;X;Zg = fX = 0; Y = Zg and TC4 in glb(fX =1+T1g; fZ = 1+T2g; fT1 = 0; Y = T2g)jfY;X;Zg = fX = 1; Z = 1+Y g. lub(fX = 0; Y =Zg; fX = 0; Y = Zg; fX = 1; Z = 1 + Y g) = fX + Y = Zg.Thus, T �PT " 2 =< fX = 0; Y = 0g; fX + Y = Zg >.T �PT " 3: The information of T �PT " 2 is now available for computing both T�PT ( atten�1;�2=2;< fX = 0; Y = 0g; fX + Y = Zg >) and T�PT (append�2;�2;�2=3; < fX = 0; Y =0g; fX + Y = Zg >). This gives the following : for TC1: glb(fX = 0g; fY = 0g)jfX;Y g =17

fX = 0; Y = 0g while TC2 gives glb(fX = L+Zg; fZ = 0; U = 0g; fL+U = Y g)jfX;Y g =fX = Y g. Then lub(fX = 0; Y = 0g; fX = 0; Y = 0g; fX = Y g) = fX = Y g.For T�PT (append�2;�2;�2=3; T �PT " 2) we look at its two clauses: TC3 yields glb(fX =0g; fY = Zg)jfX;Y;Zg = fX = 0; Y = Zg. From TC4 we derive glb(fX = 1 + T1g; fZ =1 + T2g; fT1+ Y = T2g)jfX;Y;Zg = fX + Y = Zg. Thus upb(fX + Y = Zg; fX = 0; Y =Zg; fX + Y = Zg) = fX + Y = Zg.As a result, T �PT " 3 =< fX = Y g; fX + Y = Zg >.T �PT " 4: This results in no new information, so that the least �xpoint is reached inT �PT " 3.The resulting size relation says that whenever an atom atten(t1; t2) is a logical con-sequence of the atten program, and its arguments satisfy t1 2 ID(�1); t2 2 ID(�2), thenjjt1jj�1 = jjt2jj�2 . We have derived a size relation expressing that both lists contain thesame number of basic elements.6 ConclusionsThe contribution of this paper is to �ll in the one technical gap needed to extend automatictermination analysis techniques such as the ones in [20] and [17] to be able to takeadvantage of typed norms: the inference of interargument relations for such norms. At�rst sight, this can be regarded as a minor, technical point. It should be observed howeverthat, although [20] is one of the more powerful automatic termination techniques available,the method was still based on ordinary norms. In [7], [3] and [4] it has been clearly pointedout that termination analysis for non-ground queries can be signi�cantly improved onlyif type information is taken into account. Furthermore, [7] convincingly shows that typesallow for improved automatic inference of norms and that the expressivity of the typednorms is a signi�cant enhancement.From these observations, we are convinced that any state-of-the-art approach to ter-mination analysis needs to take type information into account and that any future workin this direction will need to address the same problems raised by type-specialised normsthat we dealt with in this paper.On the level of practicality, our approach can deal with any of the programs success-fully studied in [17], since typed norms extend non-typed ones. Moreover, practically allthe examples mentioned in [7], which fall outside the scope of [17], can successfully behandled by our extension. Flatten is just one representative of this class. Others are thetree-to-list conversion and the change predicate. See [3] for a more extensive list.In view of full automation, the only component of our approach of which automationwas not described in this paper is the generation of consistently success-typed programs.In [8] we give a constructive transformation that assigns a consistently success-typedprogram to any given program, predicate and tuple of success types. The transformationrelies on an abstract interpretation with reexecution.One might worry that the di�erent layers of abstract interpretation in this approachbecome - as a whole - computationally unfeasable and needlessly complex.We are cur-rently investigating the problem of merging the di�erent interpretations into a singleone-traversal analysis. The main trade-o� in this attempt is to avoid too much decreasein precision.With respect to related work on inference of interargument relations, we refer to [5]18

for an overview. That paper also discusses the di�erences in expressivity, e.g. in relationto the use of systems of linear equations. With respect to [19] the main di�erences are theimproved expressivity by integrating types and the use of a conceptually simpler abstractinterpretation scheme.References[1] R. Barbuti, R. Giacobazzi, and G. Levi. A general framework for semantics-basedbottom-up abstract interpretation of logic programs. ACM Transactions on Pro-gramming Languages and Systems, 15(1):133{181, 1991.[2] A. Bossi, N. Cocco, and M. Fabris. Proving termination of logic programs by exploit-ing term properties. In Proc. CCPSD-TAPSOFT'91, pages 153{180. Springer-Verlag,LNCS 494, 1991.[3] A. Bossi, N. Cocco, and M. Fabris. Typed norms. In B. Krieg-Brueckner, editor,Proc. ESOP'92, pages 73{92. Springer-Verlag, LNCS 582, 1992.[4] F. Bronsard, T.K. Lakshman, and U.S. Reddy. A framework of directionality forproving termination of logic programs. In Krzysztof Apt, editor, Proc. JICSLP '92,pages 321{335. MIT Press, 1992.[5] D. De Schreye and S. Decorte. Termination of logic programs: the never-endingstory. Journal of Logic Programming, (Special anniversary edition), 1994. Acceptedfor publication.[6] D. De Schreye, K. Verschaetse, and M. Bruynooghe. A framework for analysingthe termination of de�nite logic programs with respect to call patterns. In Proc.FGCS'92, pages 481{488, ICOT Tokyo, 1992. ICOT.[7] S. Decorte, D. De Schreye, and M. Fabris. Automatic inference of norms : a missinglink in automatic termination analysis. In D. Miller, editor, Proceedings ILPS'93,pages 420{436, Vancouver, Canada, 1993.[8] S. Decorte, D. De Schreye, and M. Fabris. Exploiting the power of typed normsin automatic inference of interargument relations. Technical report, Department ofComputer Science, K.U.Leuven, Belgium, 1994.[9] G. Janssens and M. Bruynooghe. Deriving descriptions of possible values of programvariables by means of abstract interpretation. Journal of Logic Programming, 13(2& 3):205{258, 1992.[10] M. Karr. A�ne relationships among variables of a program. Acta Informatica,6:133{151, 1976.[11] B. Le Charlier and P. Van Hentenryck. Reexecution in abstract interpretation ofprolog. In Krzysztof Apt, editor, Proceedings of the Joint International Conferenceand Symposium on Logic Programming, pages 750{764. MIT Press, 1992.[12] A. Mulkers. Deriving Live Data Structures in Logic Programs by means of AbstractInterpretation. Number 675 in LNCS. Springer-Verlag, 1993.19

[13] L. Pl�umer. Termination proofs for logic programs. Number 446 in LNAI. Springer-Verlag, 1990.[14] L. Pl�umer. Automatic termination proofs for Prolog programs operating on non-ground terms. In Proc. ILPS'91, pages 503{517, San Diego, October 1991. MITPress.[15] K. Sohn and A. Van Gelder. Termination detection in logic programs using argumentsizes. In Proceedings 10th symposium on principles of database systems, pages 216{226. ACM Press, May 1991.[16] J.D. Ullman and A. Van Gelder. E�cient tests for top-down termination of logicalrules. Journal ACM, 35(2):345{373, April 1988.[17] K. Verschaetse. Static Termination Analysis for De�nite Horn Clause Programs.PhD thesis, Dept. Computer Science, K.U.Leuven, 1992.[18] K. Verschaetse and D. De Schreye. Deriving termination proofs for logic programs,using abstract procedures. In Proc. ICLP'91, pages 301{315, Paris, June 1991. MITPress.[19] K. Verschaetse and D. De Schreye. Derivation of linear size relations by abstractinterpretation. In M. Bruynooghe and M. Wirsing, editors, Proceedings PLILP'92,LNCS 631, pages 296{310. Springer-Verlag, 1992.[20] K. Verschaetse, S. Decorte, and D. De Schreye. Automatic termination analysis. InProc. LOPSTR'92, LNCS. Springer-Verlag, 1993.

20

A ProofsLemma A.1 T �P is monotonic:Proof Let E =< Ek1q ; � � � ; Eknq >;E 0 =< E 0k1q ; � � � ; E 0knq >2 D� and E v E 0. We needto prove T �P (E) v T �P (E 0). By de�nition of v and T �P it is su�cient to prove that for alli = 1; � � � ; n; E v E 0 implies T�P (pi; E) � T�P (pi; E 0). Obviously, A(pi(X1; � � � ; Xn); E) �A(pi(X1; � � � ; Xn); E 0), so that it remains to be shown that e! lubi=1;���;m(restrict((X1;� � � ; Xk); glbB2Body(Ci)(extend((Zi1; � � � ; Zili);A(B; e))))) is monotonic.First note that e ! A(B; e) is monotonic. If B is a uni�cation, then A(B; e) isindependent of e. Else, let B = pj( �U) and assume that E v E 0. We have: A(B;E) =E[pj] renamed to �Y = Ekjq renamed to �Y � E 0kjq . Finally, all of the operations extend,restrict, lub and glb are monotonic, which concludes the proof.Proposition A.2 T �P safely approximates the Tp-operator.Proof We must prove: 8E =< E1; � � � ; En >; T �P (E) w �(TP ( (E))). (E) correspondsto a set of atoms fpT1;���;Tk(t1; � � � ; tk)g. We know that (jjt1jjT1; � � � ; jjtkjjTk) is a solutionof E[pT1;���;Tk ] and that ti 2 ID(Ti).TP ( (E)) corresponds to a set of ground atoms fpT1;���;Tn(t1; � � � ; tn)g and for each ofthese atoms there exists a ground clause pT1;���;Tn(t1; � � � ; tn) BT 11 ;���;T 1m11 (t11; � � � ; t1m1); � � � ;BT l1;���;T lmll (tl1; � � � ; tlml). Also, 8i; BT i1;���;T imii (ti1; � � � ; timi) 2 (E). This implies that 8j; tij 2ID(T ij) and that (jjti1jjT i1; � � � ; jjtimi jjT imi) a solution is of E[BT i1;���;T imii ]. Let us now look atthe abstraction of this set. It is a systems of equations which is a representative of the leastequivalence class having the tuples (jjt1jjT1; � � � ; jjtnjjTn) as solutions, i.e. �(Tp( (E))) =<E1; � � � ; Ek > and (jjt1jjT1; � � � ; jjtnjjTn) is a solution of E[pT1;���;Tn].Now, T �P (E) =< E 01; � � � ; E 0k >. It is su�cient to prove that 8i; E 0i � Ei or _ (E 0i) �_ (Ei)(= TP ( (E))).Suppose that TP ( (E)) contains the atom pT1;���;Tn(t1; � � � ; tn) and that (jjt1jjT1; � � � ;jjtnjjTn) is not a solution of E0[pT1;���;Tn ]. Then either, it is not a solution of E[pT1;���;Tn ] ornot of lubi=1;���;m(restrict((X1; � � � ; Xk); glbB2Body(Ci)(extend((Zi1; � � � ; Zil );A(B;E))))).If the atom is in (E), our assumption is false because the the tuple is a solutionof E[pT1;���;Tn ]. In the other case, it must be such that for all clauses Ci, the tupleis not a solution of restrict((X1; � � � ; Xk); glbB2Body(Ci)(extend((Zi1; � � � ; Zil );A(B;E))))Because the restriction operator does not remove solutions, 8i, the tuple may not bea solution of glbB2Body(Ci)(extend((Zi1; � � � ; Zil );A(B;E))). We now �x Ci to the clausespeci�ed above. Then, considering the glb operation, this condition is equivalent to 9jsuch that the tuple (jjtj1jjT j1 ; � � � ; jjtjmj jjT jmj ) is not a solution of A(BT j1 ;���;Bjmj ; E). This isa contradiction because for that clause we know that (jjtj1jjT j1 ; � � � ; jjtjmj jjT jmj ) is a solutionof E[BT j1 ;���;T jmjj ]; 8j. 21