Incremental Computation of Success Patterns of Logic Programs

A method is presented for incrementally computing success patterns of logic programs. The set of success patterns of a logic program with respect to an abstraction is formulated as the success set of an equational logic program modulo an equality theory that is induced by the abstraction. The method is exemplified via depth and stump abstractions. Also presented are algorithms for computing most general unifiers modulo equality theories induced by depth and stump


Introduction
In abstract interpretation, program analyses are viewed as program execution over non-standard data domains.Cousot and Cousot first laid solid logical foundations for abstract interpretations [1,2].Their idea is to define a collecting semantics for a program which associates each program point with the set of all storage states that are possibly obtained when the execution reaches the point.In practice, an abstraction of the collecting semantics is calculated by simulating over a non-standard data domain the computation of the collecting semantics over the standard data domain.The standard data domain and the non-standard domain are called the concrete domain and the abstract domain respectively.
Abstract interpretation has been used to perform various analyses of logic programs such as occur check analysis [3], mode analysis [4][5][6], sharing analysis [7,8] and type analysis [6,9,10].Further more, a number of abstract interpretation frameworks for logic programs have been brought about [5], Jones et al. [11], Bruynooghe [9] and Marriott et al. [12].With an abstract interpretation framework, the design of a particular analysis reduces to the design of an abstract domain and a number of abstract operations on the abstract domain.
The safeness of the analysis is verified by formalizing a correspondence between the concrete domain and the abstract domain and proving that the abstract operations safely simulate the concrete operations with respect to the correspondence.The correspondence between the abstract domain and the concrete domain can be formalized either as an abstraction (function) from the concrete domain to the abstract domain, or as a concretization (function) from the abstract domain to the concrete domain, or as a joined pair of abstraction and concretization, or as a relation between the concrete domain and the abstract domain.We assume that the correspondence is given as a surjective abstraction from the domain of concrete terms into a domain of abstract terms 1 .
A program analysis is currently performed with respect to a fixed abstraction; and different analyses corresponding to different abstractions are performed separately even when there is a strong relationship between them.Take depth abstractions for example, a depth 3 analysis will be performed separately from a depth 2 analysis even if the result of the depth 2 analysis can be used to perform the depth 3 analysis, as we will show later in this paper.This paper is concerned with refining program analyses whereby the result of a coarser analysis corresponding to a stronger abstraction is used to obtain a finer analysis corresponding to a weaker abstraction.In particular, we are concerned with obtaining finer success patterns of a logic program from coarser success patterns of the same program.We introduce an ordering relation on abstractions of terms.We then argue, for a class of abstractions, that the set of success patterns of a logic program P with respect to an abstraction α is tantamount to the success set of the equational logic program where E α is an equality theory induced by α.Therefore, either the fixpoint semantics or the procedural semantics defined for equational logic programs can be used to compute success patterns of logic programs.From this observation, the success patterns of a logic program P can be computed by incremental refinement.A set of coarser success patterns of P relative to a stronger abstraction α 1 can be obtained by computing the fixpoint semantics of the equational logic program .If the success patterns are not fine enough for the application at hand, candidates for finer success patterns relative to a weaker abstraction α 2 can be generated from the coarser success patterns and verified by using either the procedural or the fixpoint semantics of equational logic program .This refinement process is repeated until success patterns are fine enough for the application. α

P E 
The remainder of this paper is organized as follows.Section 2 presents a fixed-point and a procedural abstract semantics of logic programs for a class of abstractions and lays a foundation for incremental refinement of success patterns of logic programs with respect to that class of abstractions.Sections 3 and 4 devote to incremental refinement of success patterns of logic programs for depth abstractions and stump abstractions respectively.In Section 5, we conclude this paper with a summary of the paper and some points to future work in analysis refinement.  )

A Foundation for Incremental Refinement
where is the set of substitutions.Let . is an equality theory on Term .We extend

Fixpoint and Procedural Abstract Semantics
This section presents a fixpoint and a procedural abstract semantics of a definite logic program P with respect to a stable abstraction  .It is well known that the success set of P is tantamount to the least fixpoint of the following function by van Emden and Kowalski [13]. .
For any logic program P and any abstraction  , is an equational logic program.The fixpoint semantics of given by Jaffar et al. [14] is According to Jaffar et al. [14], for any  A    T .We adopt as the fixpoint abstract semantics of P relative to  .The following lemma states the is a safe approximation of with respect to The procedural semantics of an equational logic program is the equational SLD resolution with  E P  respect to the equality theory , denoted as .
plays same role for as SLD for differs from SLD in the sense that, in , -unification plays the role of normal unification in SLD.In the following, we adapt so that it works on equivalence classes of t and s .The basic step in can now be defined as follows.
Let and be a variant of a clause of P.
is called -derived from and using -mgu # , , where denotes that is provable from P using .This implies that can be used to verify whether an abstract atom is a success pattern of P with respect to  according to lemma 1.In summary,

Foundation for Incremental Refinement
Let 1  and be two abstractions.Define we say that 1  is weaker or finer than and that is stronger or coarser than By Equations ( 3) and (4), Equation ( 5) lays a foundation for incremental refinement of success patterns of logic programs.An initial set of the success patterns of a logic program P can be obtained by computing which is a safe approximation of relative to are not finer enough for the application at hand then finer success patterns can be computed by a generate-and-test approach as follows.Firstly, a weaker abstraction .Secondly, is used to verify if a particular candidate element is in .This process of refinement is repeated until success patterns are fine enough.
for any , i.e., the refinement operator that splits an equivalence class into the set of Then candidates elements for can be generated from by applying to where is defined .
For a given set S of   equivalence classes, returns the union of the sets of equivalence classes resulting from applying to equivalence classes in .

An Example of Incremental Refinement
We illustrate the idea of incremental refinement of success patterns of logic programs by means of depth abstractions proposed by Sato et al. [15].A depth abstraction partitions Term into a finite number of equivalent classes.Two terms belong to the same class iff their term trees are identical to a certain depth n, called the depth of abstraction.For example, is equivalent to to depth 2.
Let denote depth abstraction.replaces each sub-term of t at depth n with a _ that denotes any Deferring a formal presentation of depth abstractions until Section 3, we now show how can be used when it is necessary to increase the depth of abstraction. and Suppose now we want to be more precise and decide to compute .Note that the set of ground atoms that approximates is a subset of the set of ground atoms that approximates.Instead of computing the least fixpoint of , we compute by a generate-and-test approach.We first generate a set of candidate elements for and then use resolution to eliminate false candidates.The generation of candidates is accomplished by applying the refinement operator defined in Section 3 to elements in .For each element in , generates a set of candidates by substituting each occurrence of _ with every element from .Thus, the set of candidates is }.After eliminating candidates that are not provable from P using ,we have SLD The following two sections demonstrate incremental refinement of success patterns of logic programs by considering two families of abstractions, namely depth abstractions and stump abstractions.

Depth Abstractions
The idea of enumerating success patterns of logic programs to a certain depth is due to Sato and Tamaki [15].Depth abstraction has been used to ensure termination of an analysis, e.g.[10,16,17].All terms (resp.atoms) identical to a certain depth are considered equivalent.For example, both and have main functor and the first and the third of their arguments are same.Both of their second arguments have as main functor.If this information is enough, then we can use either or as a representative of them.Since we are not interested in the arguments of we shall replace each argument of with a special symbol _, denoting any term, that is, we use f(a,g(_,_),b) to represent both and .actually represents an infinite number of terms.
This section defines depth abstractions, constructs a refinement operator and an equational unification algorithm for such abstractions, and exemplifies incremental refinement of success patterns with respect to depth abstractions.

Depth Abstractions
Let be a term.Then t is a depth 0 sub-term of t, and a term s is a depth k sub-term of t if s is a depth . Definition 2 Let t be a term.The depth k abstraction of t, denoted by , is obtained by replacing each depth k sub-term of t with an _.
For instance, the depth 2 abstraction of ( ( , ), , and its depth 3 abstraction is .d Now we present an -unification algorithm and prove its correctness.The following algorithm for -unification results from modifying Robinson's unification algorithm [18].Function is true iff -mgu of X and f(X).Algorithm 1 reduces the problem of -unification of X and t into the problem of -unification of X and .
2) applying to eliminate those candidate elements that are not provable from P using .

SLD
The following two examples illustrate incremental refinement of success patterns of logic programs with respect to depth abstractions.
Example 2 Let ={ ( , ), ( , ) ( , ), ( , ), ( ( ), ( )) ( , )} P p a b p X Y q X Y q a b q r X s Y q X Y   We have Example 3 Let P be the same as example 2 and suppose that success patterns in are not fine enough.We compute as follows.We first apply We then apply to eliminate those candidate 2 d SLD elements that are not provable from P by using , has not been removed because it is provable from P by using .The -refutation has been eliminated because it is not a provable from P by using .The -refutation process is as follows.
, ( 4)) q r X s Y  The -refutation fails because no clause head unifies with .

Stump Abstractions
Xu and Warren have introduced a family of abstractions, called stump abstractions, that reflect recursiveness [19].The idea is to detail each atom in to the extent in which some function symbol has been repeated for a given times.

  T
This section defines stump abstractions, constructs a refinement operator and an equational unification algorithm for such abstractions, and exemplifies incremental refinement of success patterns of logic programs with respect to stump abstractions.

Stump Abstractions
Let t be a term and s a sub-term of t.We define as a function which, for each function symbol g in ) , ( t s fc  , registers the number of nodes labelled by g in the path from the root of the term tree of t to but excluding the root of the term tree of s.Let where N is the set of natural numbers.Define , _) Definition 3 Let , and .
is obtained by replacing each sub-term of t satisfying with .Formally,

A Refinement Operator for Stump Abstractions
Let and define As shown later, x y s   s  .Intuitively, the bigger the limit for each function symbol, the weaker the abstraction.

Definition 4 Define
For given and , ) , ( f w The following defined function Term s splits an equivalence class of ground terms for a coarser stump abstraction into the set of equivalence classes of ground terms for a finer stump abstraction.
x y  .This enables us to refine success patterns of P by increasing repetition depths for some function symbols.Suppose that success patterns in are not fine enough and it is necessary to compute for some y such that

Conclusions and Future Work
We have proposed a method for incrementally computing success patterns of logic programs for stable abstractions.We have introduced a partial order on abstractions to reflect relative strength of abstractions.The method makes use of a fixed-point and a procedural abstract semantics of logic programs with respect to stable abstractions, a refinement operator that splits an equivalence class induced by a coarser abstraction into a set of equivalence classes induced by a finer abstraction, and equational unification.The refinement operator is specified.
We have applied the method for incremental refinement of success patterns of logic programs for depth abstractions and stump abstractions by constructing suitable refinement operators and equational unification algorithms.For depth abstractions, abstraction depth can be increased uniformly while for stump abstractions, repetition depth for each function symbol can be increased independently.
For depth abstractions, abstraction depth can only be increased uniformly.That means that every equivalence class has to be split when analysis is refined.It would be better to be able to split some equivalence classes and keep others intact.However, it is not clear if such a fine-tuning approach will guarantee the stability of the resulting abstraction α which is a prerequisite of using to eliminate false candidates.
 SLD Another interesting topic on incremental refinement of success patterns of logic programs is to study the possibility of applying to eliminate false candidates where is the abstraction resulting from refinement.Yet another interesting topic on incremental refinement of success patterns of logic programs is to combine domain refinement such as that proposed in this paper with compositional approach towards logic program analysis proposed by Codish et al. [3] since compositional approach is the only feasible way to analyze large programs.It is necessary to study the interaction between the refinement of analyses of program modules and the composition of analyses of program modules. T   and generation of candidates elements for can be done by splitting one or more equivalence classes of has been eliminated as follows.First, ←p(f(c)) is resolved with the clause resulting in .Then goal is resolved with the unit clause .However, cannot be resolved with b abstract terms identifying the equivalence classes of those ground terms whose main functors is f. (

Refinement of Success Patterns for Depth Abstractions
Define as follows.If then The function Sunif has three parameters.The first parameter w maps each function symbol into the limit of its repetition depth.The second and third parameters are terms to be unified.For any variable X and term t, is true iff X occurs in .This algorithm decides if t 1 and t 2 are -unifiable and, if so, returns an -mgu of t 1 and t 2 .