<<

University of California

Santa Cruz

Automated Termination Analysis for Logic Programs

A dissertation submitted in partial satisfaction

of the requirements for the degree of

Doctor of Philosophy

in

Computer and Information Sciences

by

Kirack Sohn

Decemb er

The dissertation of Kirack Sohn is approved

Allen Van Gelder

Phokion G Kolaitis

Al Kelly

Dean of Graduate Studies and Research

c

Copyright by

Kirack Sohn

iii

Contents

Abstract vii

Acknowledgements viii

Intro duction

Why Termination Analysis

How It Works

Outline of the Thesis

Logic Programming Preliminaries

Logic Programs

SLD Resolution

Fixp oint Semantics

Deductive Databases

Termination Detection

Basic Concepts

Predicate Dep endency Graphs

Mo dular Termination Analysis

BoundFree Adornments

RuleGoal Graphs

Adorned Programs

Subterm Ordering

Abstractions of Terms

Related Work

Argument Size Constraints

iv

Derivation of Termination Condition

Multiple Bound Arguments

Extension to Mutual Recursion

Mutual Recursion

Nonlinear Recursion

Limitations

Extension to CLPR

Discussion

Inference of Interargument Constraints

Intro duction

Basic Concepts

Transformations Corresp onding to Logic Programs

Translativeness Prop erty

Extreme Points of a Polycone

Summary

Relational Groundness Analysis

Intro duction

Basic Concepts

Abstraction

Relational Abstract Domains

Groundness Constraints

Simplications and Normal Forms

BottomUp Groundness Analysis

Summary

Conclusion

v

A FourierMotzkin Elimination

B Finding All Extreme Points and Rays

C Sessions for Test Programs

C Permutation

C Expression Parser

D Test input programs

D App end

D Merge

D Mergesort

D Permutation

D Parser

References

vi

List of Figures

A logic program permutation

An SLD tree via the computation rule selecting the leftmost subgoal

An SLD tree via the computation rule selecting the rightmost subgoal

SLDNFRefutation Pro cedure

A predicate dep endency graph

bf

A rulegoal graph for the adorned query perm

The rst argument of append goal over execution a at initial call Termsize

b after one recursive call Termsize c after two recursive calls

Termsize d after three recursive calls Termsize

a tree representation of ab termsize and listsize b tree

representation of aXY termsize X Y and listsize Y

Nonnegative linear combination

Extension to mutual recursion

Polycones after recursive transformations

Diagram of ground analysis

B Algorithm to nd all extreme p oints and rays

B Extreme p oints and extreme rays of a p olycone

Automated Termination Analysis for Logic Programs

Kirack Sohn

abstract

The question of whether logic programs with function symb ols terminate in a topdown

like execution is considered Automated termination analysis is an essential to ol

for generating a suitable control in mo dern deductive database systems such as LDL and

NAIL

We describ e a metho d of identifying a nonnegative linear combination of b ound argument

sizes which if found strictly decreases in a topdown execution of logic programs Testing

a termination condition is transformed to a feasibility problem of linear inequalities using

duality theory of linear programming For nontrivial termination pro ofs we often need to

know the relationship among argument sizes of a predicate We formalize the relationship

by a xp oint of recursive transformation mimicking immediate consequence op erator

Since the transformation sometimes fails to nitely converge we provide some practical

techniques to resolve this problem We also need to indicate which arguments are b ound

to ground terms during goal reduction A metho d for deriving such binding information is

describ ed in the framework of abstract interpretation Positive prop ositional formula are

used to represent groundness dep endency among arguments of a predicate

This metho dology can handle nonlinear recursion mutual recursion and cases in which

no sp ecic argument is certain to decrease Several programs that could not b e shown to

terminate by earlier published metho ds are handled successfully

Keywords logic programs deductive databases termination interargument constraints groundness analysis

viii

Acknowledgements

First of all I would like to thank Allen Van Gelder who is a wonderful advisor and a

source of inspiration His unfailing sharpness of thought was a strong supp ort He taught

and inuenced me in very many ways a balance b etween theory and practice how to

tackle problems technical writing and presentation skills More imp ortantly he supplied

me a mo del for a scientist

My sincere thanks also go to Phokion Kolaitis who provided me with a rm basis of

logic in computer science I also thank David Haussler who served for my oral exam and

Al Kelly who read my dissertation and all professors in CISCE at UCSC who taught me

computer sciences I thank Lynne Sheehan for her help and advice It has b een pleasant

to ask her help and discuss problems My colleagues H Yo on TJ Park Kjell Post Yumi

Tsuji discussed my work with me and made insightful observations They made it enjoyable

to stay here at UCSC Thanks guys

The most imp ortant supp ort came to me from my family my wife Hyunjo o and our

wonderful kid DongGyu who have kept my mo o d high and shared the burden of my

study Finally my deep est appreciation go es to my parents in Korea for their incessant

encouragement and patience

Intro duction

Logic programming was rst intro duced in a seminal article of Kowalski in Kow

It has b een successfully used as a to ol for several areas includin g compiler writing exp ert

system design natural language pro cessing hardware design and knowledgebase design

for two decades The p ower of logic programming stems from two facts its formalism is so

simple and its semantics is based on clean mathematical logic

Although it is more relevant in logic programming than in pro cedural programming

termination analysis was a relatively neglected sub ject in logic programming areas in

contrast to the endeavor made for pro cedural languages for a long time The last few

years have nevertheless seen a variety of prop osed metho ds D De Schreye and S Decorte

studied and collected in their reference list a total of pap ers published on this topic since

DSD This proliferation is mainly motivated by the practical needs for termination

analysis such as in the area of control generation and program verication A ma jor concern

in this case is automation of the termination pro of pro cess Nai UVG APP BSb

DSVB Plua Plub Sag SVG Another approach concerns the characterization

of terminating logic programs It aims at the treatment of negation as nite failure or the

b etter understanding of decidability issues AP AB Dev These rather theoretical

works usually provides manually veriable criteria for termination

Undecidability of the halting problem a classical result of theoretical computer science

states that it is undecidable to determine whether or not any program terminates The

prop osed metho d of this thesis only analyzes a sucient condition ie a program may

terminate without our metho d detecting that fact

This intro ductory chapter is organized as follows In Section we describ e why

termination analysis has practical imp ortance in particular with regard to its application

to deductive databases In Section we briey describ e how the analysis works in general

and what treatments are needed in case of termination analysis for logic programs In

Section we give the organization of the thesis serving as a short intro duction to each

chapter

Why Termination Analysis

There are a numb er of situations where termination analysis is useful and necessary

One obvious contribution of termination analysis is to the development of reliable software

Motivations for termination analysis in logic programming however arise from more or less

dierent purp oses

The wellknown Kowalskis formula Kow says a logic program can b e viewed as

Algorithm Logic Control Since the control comp onent of a logic program is

indep endent of its logic comp onent various control schemes tailored for the applications

can b e develop ed Standard Prolog interpreters equipp ed with depthrst search strategy

are one example of control scheme Unfortunately this control scheme is unfair that is

we are not guaranteed to always nd a success branch which is logically derivable due to a

nonterminating computation To complement such a shortcoming termination analysis

is useful With the negation as nite failure rule the requirement of having a nite

computation tree asso ciated with a negated atom is also closely related to termination

analysis

Let us now turn to the application of logic to databases often called deductive databases

Recently many prototyp es eg Aditi CORAL EKS LDL LOGRES LOLA NAIL

GLUE RDL XSB have b een demonstrated in research environments and a numb er

of applications have b een develop ed using these systems They seem to b e promising

alternatives for next generation database systems

A deductive database is divided into two comp onents an extensional database EDB

which consists of a set of database facts and an intensional database IDB which consists

of a set of rules dening how additional relations are computed IDBs may b e evaluated

either topdown or b ottomup Bottomup evaluation is often said to b e more ecient

for logic programs with nite domains Datalog however there is no corresp onding

claim for general logic programs with function symb ols One of main problems in this

regard is to generate suitable evaluation strategy Capture rules were intro duced to decide

which evaluation strategy is eciently applicable to a logic program provided with a goal

UVG Ull MUVG A capture rule is a statement of the form if the rules satisfy

suchandsuch conditions then a go o d evaluation metho d is suchandsuch A minimal

requirement to apply topdown execution metho d is the guarantee of termination for any

query of interest Ullman and Van Gelder were the rst who studied termination analysis

in deductive database environments with a strong emphasis on automation of the analysis

UVG Later the metho d was enhanced by Plumer Plua Plub and Van Gelder

and Sohn SVG Bro dsky and Sagiv who studied termination of Datalog programs were

also main contributors along this line BSb Sag

How It Works

In this section we shall describ e the basic structure of termination pro of for logic

programs Every termination pro of is tantamount to showing the wellfoundedness no

innitely decreasing sequence of a computation path Consider a simple while lo op in C

s while x

s x x

The sources of innite computation in pro cedural programs are lo ops In this example we

have a lo op control construct while The valid domain for x at s is p ositive Supp ose the

initial value of x is p ositive say N otherwise the execution will exit from the while lo op by

the test x at s Since the p ositive value satises the test the value of x decrements by

at s A simple induction shows that the value of x changes over the execution as follows

N N N K

where N K and N K The sequence is not innitely decreasing showing

termination of while lo op

Let us take one more example illustrating termination detection technique

s while x N

s x x

The technique used in the rst example is not directly applicable here Let us asso ciate a

function f x N x with the while lo op so that we consider the value of f x instead of x

Now the domain of f x at s is p ositive and f x decreases by over the execution of while

lo op since x increases by Then the sequence of the values of f x over the execution is

nite showing the termination Essentially what we should do to prove termination is to

nd such a function f that its range is nonnegative and its value decreases over execution

although the ab ove two examples are to o simple to describ e detailed pro of techniques

The idea used in the ab ove pro cedural programs is universal in termination pro of for

any language However pro ofs are quite dierent in technical levels due to the dierences in

the structure and the attributes of underlying languages The following is a logic program

similar to the rst C program Note there are no lo op control structures in logic programs

since recursion is the only way to iterate computation

r p

r psX pX

The term sX denotes the successor to X so it can b e viewed as X First of all we

can not say whether the program terminates or not without taking a call or query to the

pro cedure into account The reason is logical variables are totally dierent from pro cedural

ones which are always b ound Logical variables do not have any values initially but they

may b e b ound to values after the pro cedures are called The value is p ermanent once it is

b ound called single assignment Thus we need to make sure the call binds the variable

X For example a call pss which binds the logical variable X terminates But pU

do es not terminate What happ ens is the call pU do es not bind X so the new call pX

rep eats the previous call More dicult problems of this kind arise from unication and

partially b ound structures

Another technical diculty arises from nondeterministic b ehavior of logic programs

Unlike pro cedural programs there is conceptually no single thread of computation in the

r perm

r permP XL

r appendE XF P

r appendE F P

r permP L

r append L L

r appendXL L XL

r appendL L L

Figure A logic program permutation

execution of logic programs

Termination analysis can b e aected by the underlying mechanism of handling nonde

terminism such as backtracking rulegoal tree expansion One alternative is to consider all

the computation threads for termination simultaneously indep endently of the mechanisms

used This typ e of termination is called universal termination taken in most published

research

To understand the problems with resp ect to deriving level mapping function let us

consider a practical logic program in Figure which in turn will b e used as an example

program in this thesis The readers who are not familiar with the syntax and semantics of

logic programs are advised to skip or get back after reading Chapter In Figure perm

succeeds when one argument is a p ermutation of list elements in the other argument and

append succeeds when its third argument is a concatenation of the rst two

We want to prove termination of a query perm with the rst argument b ound As a

matter of fact we need to prove two subgoals append in r and r b efore the recursive

subgoal perm in r assuming standard Prolog computation rule selecting leftmost subgoal

The pro of in either case of append goals is direct b ecause one b ound argument in the

recursive subgoal is a prop er subterm of the b ound argument in the same p osition of the head

in r More precisely a prop er subterm ordering is not innitely decreasing so a sequence

of append goals is not innitely decreasing to o b ecause the rst or third arguments of the

goals are ordered by prop er subterm ordering However the termination of perm cannot b e

proved similarly b ecause there is no direct relationship b etween P and P

Our approach to this problem is to infer the relationship among arguments in the

subgoals append in this case so as to relate P and P Analysis of append rules supplies the

fact that the list length of the third argument of append is equal to the sum of the length of

the rst two List length is the numb er of elements in a list Omitting some arithmetic we

can conclude the list length of P is less than the list length of P hence proving termination

of the query perm with the rst argument b ound To achieve nontrivial termination pro ofs

it is essential to derive the relationship among argument sizes Note two nonrecursive rules

r and r play no part in termination analysis

Outline of the Thesis

In Chapter we describ e basic notations and concepts of logic programming used in this

thesis It also serves as a brief intro duction to logic programming and deductive databases

We assume logic programs are executed in a topdown lefttoright Prologlike fashion

Internal data are organized using structures in Prolog context which are almost always

pro cessed through recursive rules As in earlier metho ds termination of recursion on

structures can b e achieved by showing a wellfoundedness of goalreduction graph

In Chapter we describ e termination pro of pro cedure based on argument sizes This

chapter result from collab orative works with A Van Gelder We b egin this chapter by giving

the basic concepts for termination analysis such as predicate dep endency graphs b ound

free adornments rulegoal graphs wellfounded ordering and size abstraction of terms

We then describ e how to formalize termination condition and transform it to testable form

using linear programming theory

We view argument sizes of derivable facts involving an nary predicate as p oints in the

n

nonnegative orthant of R Our approach is to nd a nonnegative linear combination of

b ound argument sizes of recursive goals which decreases by at least some p ositive constant

in each recursive call Existence of such a nonnegative linear combination proves the

termination of a recursive goal since argument sizes are constrained to nonnegativity so is

its nonnegative combination Our metho d applies to nonlinear and mutual recursion with

a slight extension We also discuss limitations of our metho d

Lo cal variables are logical variables which do not app ear in the head but app ear

somewhere else in the rule It is often the case that there is no direct relationship among

the argument sizes in a head and those in a recursive subgoal due to the o ccurrences of

lo cal variables Termination analysis for a certain rule may require the constraints among

argument sizes of subgoals b efore a chosen recursive subgoal

In Chapter we will describ e how to derive those constraints socalled interargument

constraints of a predicate Interargument constraints are essentially a set of constraints

which every derivable fact with resp ect to a predicate satises Research on this topic has

recently b een studied as a separate task BSa VG BS In this thesis the argument

sizes of derivable facts with resp ect to an nary predicate are viewed as a set of p oints

n

in R which are approximated by their convex hull Such constraints are formalized by

a xp oint of recursive transformation mimicking immediate consequence op erator used

to dene the xp oint semantics However the transformation do not necessarily converge

in nitely many iterations Approximating p olycones to their ane hulls provides useful

interargument constraints in many practical programs guaranteeing convergence

For a class of linear recursive logic programs satisfying socalled translativeness

prop erty precise interargument constraints can b e obtained via the analysis of structures

of recursive transformations

We need to nd extreme p oints of p olycones in a certain representation to verify a

xp oint Finding extreme p oints is a timeconsuming pro cess We investigate an ecient

metho d to nd them by exploiting information on adjacency of extreme p oints

One of the most attractive features of logic programs is that arguments may b e used

bidirectionall y as input or output at runtime Groundness analysis is a dataow analysis

to infer whether the arguments of a call are instantiated to ground terms b efore the call is

made or after the call is completed

In Chapter we formalize an ecient and precise groundness analysis for logic programs

as an instance of an abstract interpretation Aliased variables are variables which share the

same ob ject They are often a hindrance to precise groundness analysis Though relational

groundness analysis can resolve globally the problems due to aliased variables it has b een

considered to b e impractical since tables representing the relationship are usually very big

hence hard to handle In our formalism the groundness relationships are represented in

the form of b o olean OR constraints Since in practice such constraints are almost always in

simple computable forms our metho d runs eciently The abstract domain is exemplied

with b ottomup abstract interpretation nding success patterns of a predicate groundness

information after a call is completed

This chapter is rather indep endent of the main research thread In general groundness

information is used by a compiler to eect various optimizations However to apply our

termination analysis to general logic programs where safety assumption do es not hold

groundness analysis is necessary

Chapter discusses further research directions and concludes the thesis

Logic Programming Preliminaries

Since logic programming was intro duced in Kowalskis seminal pap er in Kow

logic has b een successfully used as a for two decades in various areas

of computer sciences not to mention articial intelligence and database Its p ower stems

from simple formalism and rigorous mathematical framework This chapter intro duces the

basic concepts of logic programming which will in turn b e used throughout the thesis

Since this chapter serves only a short intro duction to logic programming enough to follow

the thesis readers may consult the b o ok by Lloyd Llo for details

Logic Programs

We rst give an inductive denition of terms Constants or variables are terms If f is

an nary function symb ol and t t are terms then f t t is a term If p is an

n n

nary predicate symb ol and t t are terms then pt t is an atom A literal is

n n

either an atom or a negated atom A negated atom is a negative literal one that is not

negated is a p ositive literal A clause is a disjunction of literals A Horn clause is a clause

with at most one p ositive literal A Horn clause is thus either

A single p ositive literal eg pab which we regard as a fact

One or more negative literals with no p ositive literal which we regard as a goal or

A p ositive literal and one more negative literals which is a rule

A Horn clause of group in the form of q q p is logically equivalent to

n

q q p The latter is natural expression of an inference rule which can b e

n

understo o d as If q q are true then p is true Following Prolog syntax we shall use

n

the notation

p q q

n

for q q p The atom p is called the head of the rule and q q is called the

n n

b o dy A logic program or just a program is a nite set of rules and facts

Variables app earing only in the b o dy may b e viewed as existentially quantied in the

b o dy while other variables are universally over the entire rule For example a logical rule

path with variables X Y and Z

pathX Y pathX Z pathZ Y

can b e understo o d as For all X and Y there is a path from X to Y if there exists Z such that

there is a path from X to Z and there is a path from Z to Y The predicate path denes

essentially transitive closure relation

Following Prolog syntax Horn clause of group in the form of q q is

n

denoted

q q

n

It is called a goal clause that is a clause with no head Each q i n is called a

i

subgoal of the goal clause

Technically an empty clause that is a clause with empty head and empty b o dy is

denoted This clause is understo o d as a contradiction

In examples we shall use standard Edinburghstyle Prolog syntax CM SS

Variables are denoted by a character string starting with upp ercase letters while constants

function symb ols and predicate symb ols are denoted by a character string starting with

lower case letters The syntax HT equivalent to HT denotes a list whose head is

H and tail is T Null or empty list is denoted by a constant read as nil a b

c is a list of three elements X Y U is a list with at least two elements

In Prolog terminology a structure is viewed as an uninterpreted function symb ol with

terms as its arguments Structures are the only ob ject to organize data lo cal to rules Such

data are almost always pro cessed through recursion called recursion on structure The

set of all rules with the predicate p in the head of the rules is called the pro cedure or

denition of p A ground term clause is one without variables

Example Consider a simple Prolog program dening the transitive closure relation

r pathX Y connectedX Y

r pathX Y connectedX Z pathZ Y

r connectedsfo ny

r connectedny paris

The fact connectedsfo ny can b e read as there is a connection from sfo to ny The

rule r and r say for all X and Y there is a path from X to Y if there is a connection from

X to Y or if there exists Z such that there is a connection from X to Z there is a path from Z

to Y The predicate connected denes EDB relation and the predicate path denes IDB

relation The rules r r are the pro cedure of the predicate path

SLD Resolution

In this section we intro duce such notions as unication and SLDresolution which are

central to logic programming

A substitution is a nite mapping from variables to terms and is written as a set of

variableterm pairs

fx t x t g

n n

When the substitution is applied to a syntactic ob ject e it reads informally all o ccurrences

of variables x x in e are replaced by or are b ound to terms t t resp ectively

n n

The resulting syntactic ob ject is e A pair x t is called a binding Note the notation

i i

implies the variables x x are distinct If a substitution is a onetoone and onto

n

mapping ie p ermutation from its domain and itself it is called a renaming substitution

A variant of an expression is obtained by applying a renaming substitution to the expression

If all t t are ground then is called a ground substitution or instantiation For a

n

ground substitution e is called a ground instance of e

Example Atom pUVZ is a variant of pXYZ since pUVZ can b e obtained

by applying a renaming substitution fXUYVUXVYg to pXYZ Atom paba is a

ground instance of pXYX

Substitutions can b e comp osed Given substitutions fx u x u g and

m m

fy v y v g the comp osition of and is the substitution obtained from the set

n n

fx u x u y v y v g

m m n n

by removing those pairs x u for which x u and removing any pairs y v for which

i i j j

y fx x g A substitution is said to b e more general than a substitution if we

j m

have for some substitution A substitution is a unier of expressions A and B

if A and B are syntactically identical A and B are uniable if there exists a unier A

unier of A and B is called a most general unier or shortly mgu if it is more general

than any other unier of A and B If A and B are uniable then there exists a most general

unier mguA B which is unique up to variable renaming

Example Supp ose we have two atoms pXY and paU and a substitution

fXa Yb Ubg They are uniable since pXY paU A substitution fXa

YUg is more general than since there is a substitution fYbUbg such that

Indeed is the most general unier

Let G b e the goal A A A and C b e the clause AB B G is

m n q

derived from G and C using mgu if the following holds

A is an atom called the selected atom in G

m

is an mgu of A and A

m

G is the goal A A B B A A

m q m k

An SLDderivation consists of a nite or innite sequence G G G of goals a

sequence C C of variants of program clauses and a sequence of mgus such

that

C has no variables in common with G G and

i i

each G is derived from G and C using

i i i i

A single derivation step is called SLDresolution

A computation rule uniquely determines which atom called selected atom is selected

for every goal in a derivation The standard Prolog computation rule is to always select the leftmost atom in a goal

An SLDderivation is nite if for some goal G in the derivation there is no next goal

i

There are two cases The SLDderivation is successful if G is an empty goal In this

i

case it is called an SLDrefutation for the initial goal G The second case o ccurs when

the derivation is nitely failed A derivation fails nitely if for some G no head of the

i

variant of a clause unies with the selected atom of G The totality of SLDderivations

i

constructed starting from G under a certain computation rule forms a search space called

an SLDtree Let P b e a program G a goal and R a computation rule The SLDtree for

P fGg via R is a tree of goals dened as follows

The ro ot is G

Let G b e a no de in the tree and A a selected atom of G under R The no de G has

exactly one descendant for every clause C of P such that A unies with the head of

the variant C of C This descendant is derived from G and C using an mgu of A

and the head of C

SLDresolution is a renement of the resolution inference rule given by Robinson An

inference rule is correct or sound if only valid formulas are inferred It is called complete if

all valid formulas can b e inferred Resolution is sound and complete for logical formulas in

clausal form Soundness of SLDresolution is directly implied by soundness of resolution

While SLDresolution is incomplete for clauses in general it is complete for Hornclauses

indep endently of computation rules An SLDderivation is fair if every atom that app ears

in the derivation is chosen at some step The success set of a denite program P is the set

of all A B such that the queried program P A has an SLDrefutation A success set

P

corresp onds to the least Herbrand mo del of mo deltheoretic semantics

Example Continuing with Example Figure shows a nite SLD tree for initial

goal pathsfo D constructed by standard Prolog computation rule select leftmost atom

while Figure shows an innite SLD tree for the same initial goal constructed by selecting

rightmost goal In Figure and Figure p and c stand for path and connected

resp ectively Selected atoms are underlined and used clauses and p erformed substitutions

are indicated Used rules are appropriately renamed This example shows the choice of

psfoD

r r

X sfoY D X sfoY D

R

csfoD csfoZ pZ D

r r

Dny Z ny

pnyD

success Dny

r r

X nyY D X nyY D

R

cnyD cnyZ pZ D

r r

Dparis Z paris

pparisD

success Dparis

r r

X parisY D X parisY D

R

cparisD cparisZ pZ D

failure failure

Figure An SLD tree via the computation rule selecting the leftmost subgoal

psfoD

r r

X sfoY D X sfoY D

R

csfoZ pZ D

csfoD

r r r

Dny

X Z Y D X Z Y D

R

csfoZ cZ Z pZ D

success Dny

r r

csfoZ cZ D

R

nite subtree innite path

r r

Z sfoDny Z nyDparis

R

csfony

csfosfo

failure

r

success Dparis

Figure An SLD tree via the computation rule selecting the rightmost subgoal

computation rule has a great b earing on the size and structure of the corresp onding SLD

tree However in b oth SLD trees we nd the same success set fpathsfo ny pathsfo

parisg by the indep endence of computation rule

We now turn to the problem of searching SLDtrees to nd success branches Two

wellknown search strategies are depthrst and breadthrst Depthrst search strategy

is employed in most Prolog implementations since it can b e implemented very eciently

However the eciency is achieved on the sacrice of fairness of SLDresolution As shown

in Figure once we get into the innite branch the other success branches will never

b e explored In this thesis SLDresolution equipp ed with leftmost computation rule and

depthrst search strategy like standard Prolog system is assumed unless explicitly stated

otherwise

With Horn clauses we can express what is true but not what is false That is SLD

resolution can not deduce negative information There are some examples where it is

natural to require that also negative information can b e deduced One p ossibility to do

that is to conclude that a fact A is true if A is not proved from a program P This rule

is usually called closed world assumption Unfortunately it is not an eective reasoning

metho d since the set of negative facts derived by closed world assumption is not necessarily

recursively enumerable A way out of this problem is to adopt some more restrictive form

of unprovability namely nite failure An SLDtree is nitely failed if it is nite and every

branch is failure So we conclude A if the SLD tree asso ciated with a ground atom A

is nitely failed SLDresolution together with negation as nite failure is called SLDNF

resolution The algorithm in Figure describ es how SLDNFrefutation works

Fixp oint Semantics

The set of ground terms which can b e constructed from the function symb ols o ccurring

in a program P is called Herbrand Universe U of P The set of ground atomic formulas

P

which can b e constructed from the predicate and function symb ols o ccurring in P is called

the Herbrand Base B of P P

function SLDNFquery a set of literals fL L g b o olean

m

b egin

if query is empty then return TRUE

else

b egin

select a literal L from query such that

i

L is a p ositive literal Rt t or a negative ground literal P

i n

if L is p ositive then

i

b egin

for all data base clause Rt t L L

n p

if L and Rt t unify then

i

n

b egin

compute mgu

if SLDNFfL L L L L L g then return TRUE

i i m

p

end

return FALSE

end

else L is negative ground

i

if SLDNFfPg then return FALSE

if the return value is TRUE an SLDNFrefutation is found for P

else there is a nitely failed SLDNFtree

else return SLDNFfL L L L g

i i m

end

end

Figure SLDNFRefutation Pro cedure

The meaning mo del of a logic program can b e obtained by a xp oint of a certain

function T called immediate consequence op erator with resp ect to a program P

P

T I I

P k k

This function which is a total mapping from the p owerset of Herbrand Base to itself is

dened as follows

T I fhead j head body GP and body is true in I g

P

where GP is a set of ground instantiations of the rules in P

T is monotone so it reaches a xp oint by Tarskis classical xp oint theorem Starting

P

with empty interpretation T arrives at a least xp oint however dep ending on starting

P

interpretations there exist numerous xp oints The transformation may need innite

iterations b efore reaching a xp oint Details can b e found in Llo Hog

Basically our algorithm to infer interargument constraints simulates the immediate

consequence op erator T

P

Deductive Databases

One interpretation of logic is the database interpretation Here a logic program is

regarded as a database We thus obtain a very natural and p owerful generalization of

relational databases which corresp ond to logic programs solely of ground unit clauses The

concept of logic as a uniform language for data programs queries views and integrity

constraints has great theoretical and practical p otential

In the deductive database environment facts are usually stored in the database and

the predicate is said to dene an extensional database EDB relation One computed by

logical rules is called an intensional database IDB relation A Datalog program is a logic

program which contains no function symb ols of arity

Unlike the approach taken in logic as a programming language in database context we

are interested in nding all facts implied by the logical rule Therefore to have op erations

on Datalog programs make sense we need to make sure the relation with resp ect to a

predicate is nite One simple way to solve the problem is to put syntactic restrictions on

rules so that no innite relations are created The source of inniteness is a variable that

app ears only in the head of a rule For example consider the following logic program

r lovesX Y subjectX

r subjectJesus

The subject is an EDB relation and the intended meaning of lovesX Y is X loves Y

The rule r denes an innite relation since the second argument Y of love is universally

quantied and do es not app ear in the subgoal That is the relation can b e interpreted as

Jesus loves whatever is in the universe

A rule is dened to b e safe if all variables in the head also app ear in the b o dy of the

rule If the relation of subgoals are nite then the relation of the predicate of the head is

also nite since all the values for the variables in the head come from the set of values in

the variables in the subgoals which is nite The rule r in the ab ove program is not safe

since Y do es not app ear in the b o dy

Logical rules can b e evaluated topdown or b ottomup Topdown evaluation is b elieved

to b e more ecient for logical rule with function symb ols Our research fo cuses on whether

or not topdown evaluation terminates Since we are interested in nding all solutions of a

query in database environment we need to guarantee all the branches of the SLDtree are

nite This typ e of termination is called universal termination Note the search strategy is

irrelevant since we examine the whole SLDtree with resp ect to a given query However

the computation rule is imp ortant as shown in Example Many deductive database

implementations employ dynamic subgoal ordering Although we assume a lefttoright

computation rule our termination analysis technique can also b e applied to an evaluation strategy with subgoal ordering

Termination Detection

Basic Concepts

Predicate Dep endency Graphs

For the eective analysis of logic programs we often need to know the way predicates

in a logic program dep end on each other To do so we construct a digraph whose no des

are predicates An arc from no de p to no de q is drawn if p is the predicate of the head of

a certain rule and q is the predicate of its subgoal Intuitively q supp orts the derivation

or solution of p A logic program is recursive if its predicate dep endency graph has one or

more cycles

From the digraph we can identify the strongly connected comp onents SCCs and the

partial order induced up on them A recursive subgoal is one whose predicate is in the same

SCC as the head of the rule An SCC with more than one predicate is said to have mutual

recursion If each rule in an SCC has at most one recursive subgoal then the recursion in

this SCC is said to b e linear In fact most recursions in logic programs are linear

Mo dular Termination Analysis

In general mo dularity reduces the task of termination analysis signicantly To do so

we shall analyze one SCC at a time starting from the lowest level of the partial order

Successful termination analysis lets us march to upp er levels Usually the analysis of an

SCC requires the information on the predicates in lower SCCs such as interargument

constraints

Example Consider a rather unmotivated example b elow

r pfX qX

r qfX rX

r rfX pX sX

r sfX sX

p

AK

A

A

A

SCC

A

A

A

A

q

r

SCC s

Figure A predicate dep endency graph

r s

Let us draw a predicate dep endency graph for this program We have four predicates

p q r s in the program so we draw four no des In r p dep ends on q so we draw an

arc from p to q By doing the same thing for other rules we have the predicate dep endency

graph for the ab ove logical rules as shown in Figure Using algorithms to nd SCCs

which can b e found in many algorithm textb o oks for example CLR we identify two

SCCs SCC consisting of the predicate s and SCC consisting of the predicates p q r

SCC is linear recursive while SCC is mutually recursive Since SCC is in the lower level

than SCC in the partial order induced on SCCs we do termination analysis of SCC b efore

SCC If it is shown to terminate we move to SCC otherwise we stop there by rep orting

we can not show termination

BoundFree Adornments

Unlike pro cedural or functional programs logic programs are bidirectional that is

arguments to a pro cedure may b e used as input output or b oth This bidirectional use

of arguments makes it dicult to analyze logic programs for termination p ossibly various

dataow analyses to o In termination analysis we are mainly interested in how input

data structures are pro cessed during recursive calls Therefore we need to indicate which

arguments are used as input Since there is no precise dichotomy of inputoutput for

arguments b ound arguments containing no variables can b e viewed as input We shall

use the same notations as in Ull for b oundfree adornments and rulegoal graphs in the

following section

An argument is said to b e b ound or ground if all the variables in the argument are

b ound otherwise free Whenever we consider a goal in the execution of logic program

say

pt t

n

that goal is asso ciated with a binding relation for some subset of ps arguments so as to

indicate which arguments are b ound and which are not by an adornment or binding pattern

The adornment is a string of bs and f s of length n for nary predicate p If ith symb ol of

the adornment is b then the ith argument of p is b ound If the ith symb ol of the argument

is f then the ith argument is free A class of goals whose binding pattern is is denoted

p

Supp ose we have a goal append whose rst and second arguments are b ound and the

bbf

third free Then its adorned predicate is denoted append Of course we may have a goal

f f b

append with a dierent binding pattern say append

1

In logic programming world the terminology ground is usually used instead of b ound used in

deductive database world

We also need to indicate the b oundfree status of variables in a rule to construct a

rulegoal graph which is intro duced in the next section Assuming that all the variables

in a subgoal b ecome b ound after the subgoal is pro cessed successfully we have two simple

rules to indicate which variables are b ound and which free

A variable that app ears in the b ound argument of the head is b ound b efore pro cessing

any subgoals

After pro cessing a subgoal G during rule evaluation a variable that app ears anywhere

i

in G or was b ound b efore pro cessing G is b ound

i i

Note that all the variables in a rule are b ound after pro cessing the last subgoal Since

we concern several dierent situations during rule evaluation we indicate them using

subscripted rule numb er When r is the rule considered the situation b efore pro cessing

j

any subgoals is denoted r while the situation after pro cessing the ith subgoal is r An

j ji

adornment for a rule indicates which variable are b ound and which are free The notation

we use for a rule adornment is a sup erscript of the form X X jY Y where X s

m n

are b ound and the Y s are free

Example Consider the recursive path rule r

r pathX Y arcX Z pathZ Y

Supp ose path is called with the binding for the rst argument Then in the rule b efore

consideration of any subgoals only X is b ound We represent this fact by the adorned

X jY Z

The rst subgoal arcXZ provides a binding for Z so the situation after rule r

X Z jY

considering the rst subgoal is represented by r

RuleGoal Graphs

We can represent the patterns of binding that o ccur in topdown evaluation by a nite

structure called a rulegoal graph Supp ose we are given a set of Hornclause rules and a

query goal If p is the predicate of the query and is the adornment that has b whenever

the query sp ecies a value for the corresp onding argument and has f whenever no value is

sp ecied then we b egin construction of the rulegoal graph for this query with the no de

p

We then consider each no de in the rulegoal graph and expand it according to the

following rule As we expand we add goal no des which are adorned predicates and rule

no des which are no des representing a rule and some numb er of the subgoals for that rule

Using the notation describ ed ab ove we have r with an adornment to represent rule

r b efore considering any subgoals and r with an adornment to represent rule r after

i

considering its rst i subgoals

A goal no de with EDB predicate has no successors

A goal no de that is an IDB predicate p with an adornment has a successor rule

no de r for each rule r whose head predicate is p

j j

Consider a rule no de r and supp ose q t t is the i st subgoal of r As

ji k j

successors of the rule no de r we draw a goal no de q with an appropriate adornment

ji

and a rule no de r unless the i st subgoal is the last If the goal no de q

ji

already exists it is simply connected as a successor

Rule no des are also adorned in the way we describ ed in the previous section Figure

bf

shows a rulegoal graph constructed by a query goal perm and a logic program perm in

Figure

The construction of rulegoal graphs was describ ed under the assumption that all the

variables in a subgoal b ecome b ound after the subgoal is pro cessed successfully This

assumption is not so realistic The construction may b e imprecise since we do not consider

the problems with resp ect to aliased variables These problems can b e resolved by the

groundness analysis presented in Chapter The complexity of rulegoal graphs was studied

in UV Theoretically its size is exp onential of input programs but is known to b e

practically linear

bf

perm

P jE X F P L j

r r

f f b

append

P E X F jP L

r

X LjLL Lj

r r

P E X F P jL

bbf

append r

X LLjL Lj

r r

bf

Figure A rulegoal graph for the adorned query perm

Adorned Programs

In the previous section we describ ed how to construct rulegoal graphs For termination

analysis we will consider adorned programs which are direct translation of rulegoal graphs

Example Consider again a logic program perm in Figure Its rulegoal starting

b

from a query goal perm f is constructed in a way describ ed in the previous section and is

illustrated in Figure Annotating the predicates of a program with the binding patterns

in its rulegoal graph we have a sp ecialized version of the program conforming to an query

goal The following adorned program is given by the rulegoal graph in Figure

bf

r perm

bf

r perm P XL

f f b

append E XF P

bbf

append E F P

bf

perm P L

bbf

r append L L

bbf

r append XL L XL

bbf

append L L L

f f b

r append L L

f f b

r append XL L XL

f f b

append L L L

Pro cedure perm is always called with the rst argument b ound and the second free

bbf f f b

Pro cedure append is called in two dierent patterns namely append and append So

we have two versions of append pro cedure These two versions are considered as dierent

pro cedures and separate termination pro ofs will b e tried The sp ecialized version of a

program annotated with the binding patterns will b e called a adorned program Each

pro cedure is asso ciated with a unique single binding pattern

Subterm Ordering

We rst give some basic concepts on ordering

R

a

R R

b b

R R

c c

a b

R

c

c d

Figure The rst argument of append goal over execution a at initial call

Termsize b after one recursive call Termsize c after two recursive

calls Termsize d after three recursive calls Termsize

Denition A partially ordered set P is a reexive antisymmetric and transitive

binary relation on a set P A strictly partially ordered set P is an antisymmetric

and transitive binary relation on a set P A partially ordered set P is totally ordered if

for any two elements a and b in P either a b or b a A strict partial ordering on a

set P is wellfounded if for any element s in P there is no innitely decreasing sequence

s s s of elements s s s of P For example the relation on the set of

natural numb ers N is wellfounded while it is not wellfounded on the set of integers Z

A logic program terminates if and only if the trace pro of tree or SLD tree of the

execution of the program is nite For example try to prove termination of a query

appendabc L L As shown in Figure the rst argument reduces to nil

during the recursive call of the initial query so the call append U V do es not unify

with the recursive rule So the trace is nite However one do es not want to construct a

trace explicitly b ecause the construction may b e a nonterminating task and it is imp ossible

to handle every sp ecic input Instead we consider a class of queries classied by binding

patterns Therefore one may show a trace must b e nite by syntactic prop erties of clauses

that are p ossibly called We usually exploit the wellfoundedness of an ordering over goals

More precisely we show that the order asso ciated with the states in the trace is well

founded and b etween every two consecutive states the order decreases As an example of

wellfounded ordering let us take prop er subterm ordering on ground terms

bbf

Example Continuing with Example consider a query append Supp ose

A B if B is a subterm of A and appendA A A appendB B B

subter m append

if A B Clearly subterm ordering is wellfounded since there are only nite

subter m

numb er of prop er subterms for a ground term

In adorned pro cedure r r for append the rst argument L of the recursive sub

bbf

goal append L L L is a subterm of the rst argument XL of the head

bbf

append XL L XL That is XL L By the denition of

subter m

append

appendXL L XL appendL L L

append

bbf

For every two consecutive goals of the SLDtree if append XL L XL

bbf

is a goal then append L L L is its immediate descendant by the unication

bbf

Therefore the path from the initial query append to empty goal is nite hence proving

bbf

termination of append

Subterm ordering is enough to detect termination for many simple examples However it

is often the case that there is no syntactic relationship b etween arguments in head and those

in recursive subgoals since arguments are pro cessed through subgoals b efore the recursive

ones See Example It is dicult and unnecessary to relate terms by subterm ordering

By this reason we will intro duce size abstraction of terms in the following section

Abstractions of Terms

In a logical rule the b o dy of the rule may contain variables that do not app ear in the

head We usually refers to them as lo cal variables A subterm ordering is not adequate to

detect termination of logic programs containing lo cal variables since there is no syntactic

relationship b etween two terms In this section we describ e size abstractions of terms to

give ordering on ground terms

Size abstraction is a mapping from terms to natural numb ers Ullman and Van Gelder

UVG were the rst to intro duce an abstraction function for terms motivated by the

fact that subterm ordering is incapable of handling problems due to lo cal variables They

used listsize abstraction as a basis for the wellfounded ordering in a topdown termination

analysis which is dened in the following

Denition List size is dened as follows

l istsiz et if t f t t

n n

l istsiz et

t if t is a variable

if t is a constant

Listsize is informally the numb er of edges in the rightmost path in the tree representation

of a ground term For terms containing logical variables a real variable X constrained to

nonnegativity is asso ciated with each logical variable X For instance the listsize size of

fagXX is X

Listsize abstraction is capable of detecting termination of structural recursions relying

on rightmost paths such as lists However it often fails when treelike data structures are

used

Example Consider a program visiting a binary tree in depthrst manner

traversenil

traversetL R traverseL traverseR

tLR can b e thought as a binary tree whose left subtree is L and right subtree is R Supp ose

that traverse is called with its argument b ound By constructing a rulegoal graph from

b

traverse we know traverse is always called with its argument b ound Therefore we

can measure its listsize and compare their sizes to analyze termination In order to show

b

termination of traverse we have to show every pair of head and recursive subgoal has

wellfounded ordering Consider the head and the rst subgoal The listsize of the head

argument is R and the listsize of the argument in the second subgoal is R so R R

That proves the termination of the cycle from the head and the rst subgoal Now consider

the cycle from the head and the second subgoal the listsize of the head argument is R

and the listsize of the argument of the second subgoal is L hence no relationship b etween

b

two argument sizes So it fails to prove termination of traverse

In spite of this shortcoming shown in the ab ove example the basic reason why UVG

used listsize is that their inference algorithm for interargument constraints can only handle

the relationship b etween two logical variables each variable representing a listsize of an

argument This restriction was lifted by Plumer who used a linear norm as abstraction

function Later Sohn and Van Gelder also provided a metho d resolving such problems

using structural term size We will describ e the metho d in detail in the following section

Denition Structural term size is dened as follows

P

n

n ter msiz et if t f t t

i n

i

ter msiz et

t if t is a variable

if t is a constant

It is informally the numb er of edges in the tree representation of a ground term For terms

containing logical variables a real variable X constrained to nonnegativity is asso ciated

with each logical variable X Note that the structural term size of such terms is a linear

p olynomial of those real variables whose co ecients are p ositive integers More formally

This measure is called structural in that every p ortion of a term structure contributes

to the size measure Figure shows the listsize and termsize of two terms

Example Continuing with Example termsizes of tL R L and R are L R

L and R resp ectively The termsize of recursive subgoal is less than that of head since

R R

a a

R R

b X Y

a b

Figure a tree representation of ab termsize and listsize b

tree representation of aXY termsize X Y and listsize Y

L R L and L R R So the goals over two cycles are wellfounded showing

b

termination of traverse

Related Work

Most termination detection metho ds attempted to prove that the goal reduction graph

is wellfounded In order to show termination we sometimes need to know the relationship

among argument sizes of certain predicates We describ e several approaches develop ed in

earlier work

Naishs metho d Nai was based on the measure of prop er subterm which gives

a partial order on logical terms His idea was that if there exists a subset of b ound

arguments for each predicate such that no b ound argument increases and some b ound

argument decreases in any recursive rule of the predicate the recursive subgoals are well

founded A typical pro cedure for his metho d was one that merges two lists maintaining

order Dep ending on which rule applies at a particular step either the rst argument

decreases or the second one do es He gave an algorithm determining whether some subset of

the b ound arguments of each predicate existed such that each recursive call was guaranteed

to reduce one or more elements of the subset without changing others This exp onential

time algorithm was made semip olynomial by Sagiv and Ullman SU

Ullman and Van Gelder UVG prop osed a metho d to test topdown termination with

a view of testing the applicability of topdown capture rules in a knowledgebase system

They intro duced a measure of terms called list size which corresp onds to the numb er of

edges in rightmost path in a tree representation of terms This measure corresp onds to the

length of a list however it is less natural for general structural terms such as binary trees

leading to failure to detect termination They gave an algorithm for identifying and testing

a restricted class of rules those satisfying socalled uniqueness prop erty which guarantees

that the set of inequality constraints b etween two arguments is unique Termination of such

rules could b e tested in p olynomial time in the numb er of predicate symb ols and the numb er

of rules The idea of using interargument constraints in the form of inequality b etween

two argument p ositions was rst intro duced Candidates of interargument inequalities

sucient for termination were generated and then their validity was tested

Bro dsky and Sagiv studied inference of interargument constraints called monotonicity

constraints BSa and termination detection BSb in logic programs without function

symb ols Datalog programs as two separate tasks

A monotonicity constraint is a statement that one argument of a predicate is greater

than another in all derivable or given for EDB facts for that predicate Such constraints

were the backb one of their termination detection metho d called argument mapping

Argument mappings can b e viewed as monotonicity constraints b etween an argument in

a head and one in a subgoal and comp osing argument mappings as unications Although

monotonicity constraints were not p owerful enough to characterize the prop erty of derivable

facts their metho d could detect termination due to certain unication issues such as o ccur

check Their exp onentialtime algorithm could test necessary and sucient condition for

termination on nite database relations on the assumption that monotonicity constraints

were externally supplied They also gave a sucient condition for termination on innite

database relations Logic programs with function symb ols can b e simulated by Datalog

with innite database relations They recently prop osed a metho d to infer inequality

constraints b etween two arguments in programs with function symb ols BS

Plumer describ ed some extensions for rules that did not satisfy the uniqueness

prop erty Plua Plub His main contribution was that certain constraints involving

more than two argument p ositions could b e used However he required an admissibility

prop erty on the rules Moreover mutual recursion presented problems for his metho d He

claimed that every mutual recursion could b e eliminated by unfolding technique which

do es not seem to terminate His algorithm was exp onentialtime since he had to guess one

inequality p er predicate and the numb er of p ossible guesses was exp onential in the numb er

of arguments in a predicate

Van Gelder VG investigated the problem of deriving constraints among argument

sizes His metho d was aimed at nding all constraints in the form of p olyhedral convex

cones Thus those constraints can b e viewed at least as inequalities among linear com

binations of any numb er of argument p ositions His metho d works b ottomup starting

from a base p olyhedral cone corresp onding to base cases of recursive rules recursive

transformations similar to the immediate consequence op erator T are applied to input

P

p olycone until a xp oint is reached The recursive transformation generally needs innitely

many iterations for reaching a xp oint His metho d showed the nature of interargument

constraints and how they could b e derived naturally

Argument Size Constraints

We b egin by pro cessing each recursive rule in the SCC separately If the rule has several

recursive subgoals each is pro cessed separately Say a rule with head p and a recursive

subgoal q has b een chosen We obtain linear equations

2

Plumer assumed there were b ounds on clause structures hence claiming that the complexity is linear

x a A

x y

y b B

c C

where x is the vector of b ound argument sizes in p y is the vector of b ound argument sizes

in the recursive subgoal q and is the vector of other variables that app ear in constraints

includin g those representing the sizes of logical variables and unb ound arguments

a A b and B are derived directly from the rule under consideration c and C are derived

from interargument constraints on p ossibly p q and subgoals that precede q in the rule

b o dy The constraints are obtained by the metho d in Chapter or supplied by other

external means such as VG BS

Example Consider the adorned logic program perm

bf

r perm

bf

r perm P XL

f f b

append E XF P

bbf

append E F P

bf

perm P L

The problem is that no order relationships among pairs of arguments show that P P

That is inference systems can derive P E and P F but neither E nor F is P

Considering the recursive rule r which is called with the rst argument b ound and the

second free we show how Eq is set up for this rule

T

Let b e the vector P X L E F P We have x P so a and A are

a

A

3 bf

This example was studied by Plumer Plua perm cannot b e shown to terminate by any of the

previous metho ds cited Plumer suggests that unfolding transformations on append can lead to a set of

rewritten rules that his metho d can handle but no algorithm is given

Similarly y P so

b

B

Two append subgoals precede the recursive subgoal in the b o dy We assume that analysis

of the append pro cedure has supplied the imp orted constraint

append append append

Applying this to each append subgoal and noting that the termsize of X F is X F

we get

E X F P E F P

Putting this in the array format of Eq gives

c

C

Discussion of this rule continues in Example

Derivation of Termination Condition

For each predicate p in the SCC we designate a nonnegative vector with arity equal

i i

to the numb er of b ound arguments in p If x is the vector of these b ound arguments then

i i

T

the inner pro duct x is the function that should decrease during recursion Figure

i

i

illustrates the situation pictorially Supp ose we have two recursive subgoals whose sizes

T T T T

are denoted y and y is a nonnegative vector Since x y and x y

nonnegative linear combination of goal size decreases regardless of which recursive subgoal

we follow Finally the nonnegative linear combination will approach to zero along the

vector over the recursive calls That is our goal here is to nd a value for the vectors

that guarantee this function decreases

x

6

x

t t

y

p p

p B p

p p

p B t p

x

p

p B

p

p B

p

p B

p

t p p B

y

p p

p p B

p p

p p B

p p

p p B

p p

t p p B

y

p

p B

p

t BN

y

-

x

Figure Nonnegative linear combination

Again let p b e the predicate in the head of the rule and let p b e the predicate of the

i j

chosen recursive subgoal that led to Eq To avoid excessive subscripting we shall refer

to x y and rather than to x x and

i i j j

We want to cho ose and to ensure that for all x y and that satisfy the constraints

Eq we have

T T

x y

ij

where is chosen to b e or as describ ed in Section for mutual recursion but is ij

simply if i j

For the moment regard and as constants The question then is whether

xy Eq implies Eq

As is well known this can b e solved as a linear programming problem in which the ob jective

is

T T

minimize x y

sub ject to Eq Letting b e the minimum of the ob jective function the implication

Eq holds if and only if

ij

Now consider the dual of the ab ove minimization problem PS Sch We use for

dual variables u with the same arity as x v with the same arity as y and w with the

same arity as c That is one dual variable is asso ciated with each constraint in the primal

b ecause these constraints are equalities u v and w have unrestricted ranges The dual is

given by

maximize

a

T T T

u v w

b

c

sub ject to

I A

T T T T T

v w u

I B

C

By duality theory this has the same optimum as the primal and so Eq is true if

and only if the dual constraints of Eq remain satisable with the addition of

a

T T T

u v w

b

ij

c

The key observation is that and app ear linearly in the dual constraints so we can

regard them as variables and remain with a linear system Lassez made essentially the

same observation but in a more circumlo cutory fashion Lasb We incorp orate the nal

constraints

Combining into one matrix transp osing and reversing signs as appropriate gives

I I

u

I I

v

T T T

A B C

w

T T T

a b c

ij

I

I

This set of constraints is very amenable to reduction by FourierMotzkin elimination Sch

LHM Lasb In this technique a variable is eliminated by cancelling all p ositive

o ccurrences with all negative o ccurrences pairwise creating new rows with in that

variables column Then all rows containing a nonzero co ecient for that variable can

b e eliminated preserving satisability See App endix A for details

In fact from the origin of a A b and B in Eq we know that all entries of these

vectors and matrices are nonnegative We can use this fact to p erform FourierMotzkin

elimination on u and v in Eq giving

T T T

C A B

w

T T T

c a b

ij

I

I

To claim a theoretical p olynomial time b ound we stop with Eq and give the undis

tinguished variables w unique names so they do not clash with undistinguished variables obtained from other rulesubgoal analyses

In practice to conclude the pro cessing of this rulesubgoal combination we p erform

FourierMotzkin elimination on w as well leaving constraints that only involve the dis

tinguished variables and If the subgoal predicate is the same as the

i j

head then and constraints are appropriately simplied Although has not b een

ij

sp ecied yet if i j we still regard it as a constant

Example Continuing with Example the constraints corresp onding to Eq are

w

w

Eliminating w and w reduces them to

Finally requiring and setting gives the single constraint

Because this is the only rule and only recursive subgoal termination can b e demonstrated

using A Prolog session of termination pro of for this example can b e found in

App endix C

In general each combination of rule and recursive subgoal in the SCC is pro cessed to

pro duce constraints on the s A solution that satises all constraints simultaneously

i

with chosen appropriately see Section proves topdown termination for the SCC

ij

Again to claim the theoretical but largely imaginary p olynomial time b ound we

observe that the size of all the constraints combined is p olynomial in the size of the input

where the imp orted feasibility constraints that led to matrices c and C are counted as part

of the input The nal constraints represent a feasibility problem in linear programming

In practice FourierMotzkin elimination is simple and adequate

Multiple Bound Arguments

In recursive pro cedures with several b ound arguments some previously develop ed meth

o ds require searching through subsets of b ound arguments andor paths in the dep endency

graph Nai Plua One of our main motivations in using linear techniques was to

shortcircuit this complicated and exp ensive task Our metho d seeks a nonnegative linear

combination of the b ound arguments that suces for all cases

Example The following pro cedure merges two input lists VG We assume the rst

and second arguments are b ound and the third is free

bbf

r merge Ys Ys

bbf

r merge Xs Xs

bbf

r merge X Xs Y Ys X Zs

X Y

bbf

merge Y Ys Xs Zs

bbf

r merge X Xs Y Ys Y Zs

Y X

bbf

merge Ys X Xs Zs

Note that there is no explicit relationship b etween the size of a b ound argument in the head

and the size of the corresp onding b ound argument in the recursive subgoal The rst two

rules are nonrecursive Now we pro cess the third rule

T

Let b e the vector X X s Y Y s Z s We derive a A b and B from Eq

a

A

b

B

The matrices c and C are empty b ecause the subgoal X Y do es not supply any

contribution

By substituting these into Eq letting and then

ij

eliminating redundant rows we have the following constraints

By symmetry the constraints for the fourth rule can b e obtained by interchanging the rst

and second columns in the ab ove matrix

Now combining two sets of constraints and simplifying them reduces them to

The solution implies the sum of two b ound arguments always decreases in every

recursive call

Extension to Mutual Recursion

One useful feature of our metho dology is that rules with mutual recursion and nonlinear

recursion do not require much extension to the techniques already illustrated

Mutual Recursion

Mutual recursion wherein the SCC contains more than one predicate arises naturally

in userwritten rules and can also b e intro duced by predicate splitting rule transformations

whose purp ose is to make every subgoal uniable with the head of every rule for the same

named predicate

In the case of mutual recursion the set of must b e chosen so that regarding them as

ij

edge weights every cycle in the dep endency graph has p ositive weight Rather than sp ecify

this condition as a set of p ossibly exp onentially many additional linear constraints we do

the following

For i j set when required by existing constraints in the dual that is when

ij

T T

a dual constraint in Eq has as the constant and has only zeros in c and a

ij

Set all other

ij

Compute the minplus closure by Floyds algorithm of the resulting edgeweighted

graph check that there are no zeroweight cycles A zeroweight cycle is strong

evidence of nontermination and the algorithm rep orts it if found and halts

Assuming all have b een chosen so that there are no zeroweight cycles the constraints

ij

from all rulesubgoal combinations are combined and tested for feasibility as illustrated in

Example b elow

Although no natural examples are known it is p ossible that no feasible solution exists

with nonnegative but some feasible solution do es exist that includes some negative

ij

yet has only p ositive cycles Here we sketch the metho d of nding feasible solutions to

ij

systems of constraints like those in Section but without imp osing an arbitrary constraint

that all Intuitively this allows for the p ossibility that the critical b ound subgoals

ij

get larger b efore getting smaller in such a way that they are smaller by the time a cycle

around the dep endency graph has b een completed We are aware of no natural examples

of such rules

We need to add constraints that guarantee for each simple cycle in the dep endency graph

that the sum of the s around that cycle is p ositive There could b e exp onentially many

such cycles in principle The idea of path constraints was suggested by C H Papadimitriou

For each triple of predicates p p and p in the same SCC with k i and k j add

i j k

the constraint The new variables represent shortest paths Their base

ij ik j k ij

cases are Positive cycles are enforced by Again the p olynomial time

ij ij ii

b ound may b e claimed by reference to linear programming theory in practice our program

quietly runs FourierMotzkin elimination on the reducing the path inequalities to involve

ij

only and constants These are added to other constraints as discussed in Section

ij

Nonlinear Recursion

Nonlinear recursion o ccurs frequently in divideandconquer algorithms and many other

applications The main p oint is that when the second and subsequent recursive subgoals are

b eing analyzed for constraints on and the earlier recursive subgoals must contribute

i j

their interargument feasibility constraints to the eort Therefore interargument feasibility

constraints must b e pro duced for the entire SCC b efore its termination analysis b egins

Example Issues of b oth mutual and nonlinear recursion are illustrated with the

following rules which sp ecify an arithmetic expression parser The rst argument is the

list to b e parsed and is assumed b ound The second argument is the unparsed sux or

continuation and is free

eL T tL C eC T

eL T tL T

tL T nL C tC T

tL T nL T

n A T eA T

nL T T zL

The only nonrecursive rule is the last z is in a lower SCC We supp ose no knowledge ab out

z

ee

e

e

J

J

J

J

J

J

et ne

J

J

J

J

J

J

tt nn t n

n

t

tn

Figure Extension to mutual recursion

This example was studied by Plumer Plua who eliminated mutual recursion by

pushing e n and t into the third argument of a new predicate parseL T P Intuitively

such a syntactic change should not make a substantial dierence He had to make further

ad hoc assumptions to handle parse

The predicate dep endency graph is drawn in Figure To apply our metho d to mutual

recursion we have to make sure every simple cycle has a p ositive weight That is

ee

tt

nn

et tn ne

We shall only discuss in detail the derivation of constraints for the rst rule and its e

subgoal Recall that the form is

x a A y b B c C x y

The rst p oint is that the t subgoal precedes the e subgoal so should supply feasibility

constraints values for c and C in Eq even though it is in the same SCC It is not

immediately obvious what these constraints are but they can b e found by the Van Gelders

metho ds VG and are

t t

that is t t is a slack variable

T

Let b e the vector L T C The ab ove equation generates

c

C

We also have

a

A

b

B

Let us identify e with t with and n with Then the constraints corresp onding to

T T T T

Eq are note that A B and a b form the second column

w

ee

Elimination of the nondistinguished w b oils this down to

ee

The development for the third rule with t as the recursive subgoal is similar yielding

tt

The rst rule with t as the recursive subgoal and the third rule with n as the recursive

subgoal pro duce the same constraints as the second and fourth rules which are discussed

next

The second and fourth rules are straightforward yielding but the imp ortant

p oint is that their constraints force and to b e

et tn

Finally the fth rule gives

ne

which do es not force to b e b ecause a These constraints reduce to and

ne

ne

Besides selflo ops the dep endency graph has edges e t t n and n e As men

tioned and were required to b e However assigning the weight results

et tn ne

in no zeroweight cycles so the termination test is able to continue Of course and

ee tt

are Now straightforward computation leads to

so termination is proved A Prolog session of termination pro of for this example can b e

found in App endix C

Limitations

A set of rules may terminate in topdown execution due to the inability of certain

terms to unify rather than b ecause of term size reduction Sometimes the syntactic

transformations describ ed later clarify such situations b efore termination detection b egins

The argument mapping metho d BSb BS pays closer attention to unication issues

than we do and has the remarkable prop erty of detecting certain cases where unication

fails due to the o ccurs check

r qXY eXY

r qXffX pXffX qXfX

r qXffY pXfY

r pXY eXY

r pXfY rXfY pXY

r rXY eXY

r rXfY qXY rXY

r rfXfX tfXfX

r tXY eXY

r tfXfY qfXfY tXY

There are several cycles in predicate dep endency graphs Consider the cycle q p

r t q pro duced by r r r r No argument sizes diminish through the cycle so our

metho d fails to detect the termination of the cycle Supp ose initial call to q unies with qX

ffX Following the cycle two new goals pX ffX by r and rX ffX

by r are generated The goal rX ffX fails to unify with the head rfX fX

of r with o ccurcheck Sagivs metho d can detect termination of such situation Sag

4

This example was given by Sagiv in p ersonal communication

Usually the problem regarding o ccurcheck at one step of resolution can b e resolved by

predicate splitting For example consider a recursive rule

pX X pX fX

The subgoal do es not unify with the head so we assign dierent predicate name say

pX X pX fX

However predicate splitting is not p owerful enough to capture the o ccur check problem due

to several steps of resolution as in Sagivs example

Also it is p ossible that b ound arguments really do shrink during recursion but the

interargument constraints to prove that fact are not derivable by known metho ds For

instance the feasible region may not b e accurately characterized by a nite set of linear

constraints Consider a mergesort example

m mergesort

m mergesortXX

m mergesortXYRsZs

splitXYRsUsVs

mergesortUsUsort

mergesortVsVsort

mergeUsortVsortZs

s split

s splitXXsXYsZs splitXsZsYs

merge is a usual pro cedure to merge two sorted lists Our inference algorithm for

interargument constraints supplies a linear constraint

split split split

Applying this constraint to the rst subgoal in m we have a linear constraint among

variables

X Y Rs U s V s

This do es not imply the head argument size X Y Rs is greater than the recursive

subgoal argument size U s or V s hence failure to prove termination There are two p ossible

remedies for this problem

One approach is to get stronger interargument constraints Since split divides the

input list rst argument into two lists second and third arguments evenly if the rst

argument has more than two elements split then the rst argument size is greater

than the other two split split and split split The split subgoal in m

satises the premise So we can conclude that termsizeXYRs termsizeUs and

bf

termsizeXYRs termsizeVs This proves termination of mergesort However it

is noticed many published metho ds to infer disjunctive constraints are practically unusable

owing to their higher complexity

The other approach intro duced by UVG is to apply predicate splitting so that

termination b ehavior is b etter exp osed It is simple to apply the technique and adequate

to resolve the problem The rst subgoal split in m do es not unify with s The relation

split can b e split into three relations split split and split The heads of rules with

which splitXYRsUsVs do es not unify are renamed to split those with which

splitXYRsUsVs do es unify are renamed to split Rules for split are added

splitXYZ splitXYZ and splitXYZ splitXYZ Finally split

subgoals in the program are sp ecialized to split or split if p ossible The ab ove example

transforms into

m mergesort

m mergesortXX

m mergesortXYRsZs

splitXYRsUsVs

mergesortUsUsort

mergesortVsVsort mergeUsortVsortZs

s split

s splitXXsXYsZs splitXsZsYs

s splitXsYsZs splitXsYsZs

s splitXsYsZs splitXsYsZs

Rep eated application of predicate splitting terminates essentially b ecause rules are simply

partitioned and no substitutions are done

Unfolding is just an application of resolution If predicate p has k rules pX B X

i i i

then one rule in which p is a subgoal say q Y pZ can b e replaced by k rules

q Y B X

i i i

where the are the resp ective most general uniers of X and Z

i i

Safe unfolding is a sp ecial case that applies when no rule for p has p as a subgoal In

this case all p subgoals are replaced by unfolding and p is thereby removed from that SCC

of the dep endency graph Continuing the ab ove example safe unfolding applies to split

then to split and gives

m mergesort

m mergesortXX

m mergesortXYRsZs

splitXYRsUsVs

mergesortUsUsort

mergesortVsVsort

mergeUsortVsortZs

s splitXX

s splitXXsXYsZs splitXsZsYs

s splitXsYsZs splitXsYsZs

s split

If split is not referenced elsewhere their rules may b e discarded Rep eated application of

safe unfolding must terminate b ecause SCCs shrink up on each application hence the term

safe So many practical cases of mutual recursion can b e eliminated by this transformation

that there is sometimes the mistaken p erception that all can b e

In the ab ove program we still notice the rst subgoal split in m do es not unify with

s Applying one more predicate splitting and unfolding gives

m mergesort

m mergesortXX

m mergesortXYRsZs

splitXYRsUsVs

mergesortUsUsort

mergesortVsVsort

mergeUsortVsortZs

s splitXXXX

s splitXXsXYsZs splitXsZsYs

Inferring interargument constraints for the split predicate in the ab ove program

split

split

split

These equations imply that termsizeXYRs termsizeUs and termsizeXYRs

bf

termsizeVs That shows termination of mergesort

Extension to CLPR

In this section we briey discuss the extension of our metho d to CLPR programs

Further research on this area will b e investigated later

We cannot apply our termination detection metho d directly to CLPR programs The

reason is variables in CLPR are real variables so they are not constrained to nonnegativity

Therefore the assumption that nonnegative combination of b ound arguments x in

Eq are p ositive do es not hold

We need to know the domain where recursive calls are satised Consider the while

example in CLPR

whileXY

X Y

whileX Y

whileXY X Y

Note X and Y are real variables When b oth arguments of a goal are b ound the goal

terminates b ecause the second argument grows faster than the rst nally violating the

condition X Y

Let x and x b e the rst argument and the second of while predicate resp ectively In

order for a goal to unify with while rule recursively the goal must satisfy the constraint

x x b ecause of the subgoal X Y in the recursive rule In addition to Eq as

termination condition we have to ensure that x x implies x

Let Rx b e the constraint set asso ciated with a predicate so that a goal unies

recursively The following constitutes termination condition for one rule

xy Rx implies x Eq implies Eq

In case of the ab ove while example the constraint that must b e is derived How

to derive Rx in general will b e a further research topic

Discussion

We have presented a metho dology for termination detection that uses duality theory of

linear programming and is quite general and straightforward

This metho d can b e fully automated and is easy to implement We implemented the

metho d in Prolog The complete system consists of lines of Prolog co de Some

p erformance measures are listed in Table and the Prolog sessions for two test inputs

input program perm quicksort mergesort parser

cputime in milliseconds

ratio

Table Performance measures of termination detection

perm and parser are shown in App endix C The programs were tested on SUN sparc

station using Sicstus Prolog The second row of Table indicates the analysis time

and the third row indicates the ratio of analysis time to compilation time

ratio analysis time compilation time

The results show the analysis is quite slow compared to the compilation of the programs

Our broad conclusion is the termination detection together with the inference of inter

argument constraints See Section can b e available as an user option of Prolog compilers

The program perm and parser are typical linear and mutually programs resp ectively with

which the p ower of our metho d is shown We have not tested our implementation with

substantial size of programs b ecause our program take only pure logic program without

negation cut or builtin predicates as an input However we conjecture that the running

time for large input is only linear of running times for our test inputs since a practical logic

program is divided into small strongly connected comp onents in its predicate dep endency graph

Inference of Interargument Constraints

Intro duction

Our termination detection metho d describ ed in the previous chapter was built on the

basis of interargument constraints for predicates imp orted from lower SCCs In this chapter

we will describ e how to infer such constraints

Lo cal variables are those app earing only in the b o dy of a rule

In many programs see Example it is often the case that there are no direct

relationships among the argument sizes in a head and those in a recursive subgoal due

to existence of lo cal variables So termination pro of usually requires the relationship among

argument sizes of subgoals in order to relate the argument sizes in the head and the recursive

subgoals

Example Consider a recursive rule

paX pX

The term size of the head argument is bigger than that of the subgoal argument size

b ecause there are no lo cal variables In this case termination pro of is direct Consider

another recursive rule

pX aX Y pY

Let x y denote the size of X and the size of Y resp ectively and a the ith argument size

i

of a X and Y are not related to each other in this form since Y is a lo cal variable By

the subgoal a X is pro cessed into Y somehow If it is true that a a then we can infer

x y a a is called an interargument constraint for a It can b e inferred by taking the

semantics of the denition for a into account

We also b elieve the relationships among argument sizes are useful for showing safety

of queries in deductive databases for co de improvement using b etter memory allo cation

strategies and for deciding granularity of tasks in the parallel execution of logic programs

as well as for automatic termination pro ofs

Interargument constraint for short IC of a predicate is a set of constraints which every

derivable fact with resp ect to the predicate satises Metho ds to derive ICs have b een

studied recently in terms of Datalog BSa BS or logical rules with function symb ols

VG In their metho ds IC is formalized by the least xp oint of b ottomup inference

op erator similar to immediate consequence op erator In BS ICs are captured by a

disjunctive union of inequalities b etween two argument sizes They show undecidabili ty

results on interesting questions such as whether a sp ecic pro cedure for computing ICs

computes a nite set of constraints Van Gelder studied a metho d to derive a single

conjunctive set of constraints by taking the convex union of disjunctive sets of constraints

as an input for b ottomup inference VG It is often the case that b oth metho ds fail to

nitely converge

In this chapter IC with resp ect to nary predicate is captured by a single p olyhedral

n

convex set in the nonnegative orthant of R called a p olycone We formalize the derivation

of ICs in a way similar to VG This metho d is an instance of b ottomup abstract

interpretation based on xp oint semantics so correctness is guaranteed We intro duce

two new techniques to capture ICs in nite time using ane widening and translativeness

prop erty

Widening p olycones to ane hulls accelerates the convergence of the transformation

asso ciated with the inference op erator up to nitely many iterations yet supplying useful

ICs

We characterize a class of linear recursive logic pro cedures satisfying translativeness

prop erty for which precise ICs corresp onding to lfp of the transformation are auto

matically given Whether a pro cedure satises translativeness prop erty can b e tested by

analyzing the relationship b etween argument sizes of the head and those of the recursive

subgoal Many practical programs satisfy the translativeness prop erty and ICs which

cannot b e derived by other metho ds can b e captured

We also investigate an ecient metho d to nd extreme p oints in an ane image of a

p olycone which is essential to verifying a xp oint of a transformation We b elieve this

metho d is also useful in the implementation of CLPR

Overall the main contribution of this chapter is to provide an ecient metho d to derive

precise ICs for practical logic programs

Example With a simple append pro cedure we compare our results with others Sagiv

and Bro dskys metho d BS cannot capture the IC we derive here since their IC is in the

form of inequalities b etween two argument p ositions Van Gelders metho d VG do es

not converge with this example his heuristic that sometimes works gives the same IC

However we provide an ane widening that always works Let us consider a version of the

usual append pro cedure abstracted by listsize See Example for rules

append t t t

append u v w u v w appendu v w

The relationship among argument sizes with resp ect to append is essentially an innite set

fappend x x append x x append x x g

We approximate this set to the convex union of the set elements which is appendy x y x

That implies that the size of the third argument is the sum of the size of the rst and the size

of the second It is indeed a xp oint of our transformation supplied with ane widening

which is derived in three steps of transformations

The relationship can also b e captured via the analysis of the structure of a transformation

since append pro cedure satises translativeness prop erty Recursive pro cedures in logic

programs usually handle structures as a backb one of recursion called recursion on structures

that is some elements of a structure are pro cessed in a recursive call and the rest is passed

for the subsequent calls Linear recursive pro cedures relying on recursion on structures

technique usually are translative

Section intro duces basic concepts on term size abstraction and linear constraints

In Section we formalize transformations to derive ICs and intro duce ane widening

to approximate the least xp oint

Section intro duces the translativeness prop erty of a class of linear recursive logic

programs For such a class of programs ICs are obtained with no iterations Linear

recursive programs relying on recursion on structures usually satisfy this prop erty

Section concerns a metho d nding all extreme p oints of a p olycone in parametric

representation We remove nonextreme p oints from ane images of extreme p oints of a

p olycone using the adjacency graph on extreme p oints

Section summaries the chapter

Basic Concepts

Logic programs can b e abstracted by the size of terms Our metho d do es not dep end

on any sp ecic size denition In examples we shall use listsize UVG and structural

term size VG SVG List size and structural term size are dened informally to b e

the numb er of edges in the rightmost path and the numb er of edges resp in the tree

that represents the ground term For terms containing logical variables a real variable x

constrained to nonnegativity is asso ciated with each logical variable X For instance the

listsize and structural term size of fagXX are x and x resp A rule is

abstracted by replacing terms by their sizes We shall call the resulting rules and programs

abstract rules and abstract programs resp

Example Consider usual append pro cedure

a T T

aXU V XW aUVW

Replacing terms by their structural term sizes reduces to the following CLPRlike

pro cedure

a t t t

a x u v x w x u v w au v w

The ith argument size of predicate p is denoted by p for example a a v a v

i

or a v v in the base rule of Example a denotes a vector of a s

i

n

A p olyhedral convex set in R is the intersection of nitely many closed halfspaces A

n

p olycone is a p olyhedral convex set in the nonnegative orthant of R IC with resp ect to an

n n

nary predicate p is captured in the form of a p olycone in R A p olycone in R is usually

m

represented by an ane image of another p olycone in R that is represented in the form

of

p a Ax

C x

where p is the vector of variables representing argument sizes x is the vector of parameters

a is a vector constant A is a matrix and C x is a set of constraints in parameter

space containing nonnegativity constraints for parameters Eq is called parametric

representation of a p olycone We sometimes use the same symb ol for example to

denote a p olycone or its parametric representation however its meaning should b e clear

by the context An empty p olycone is denoted by whose parametric representation is

inconsistent

The parametric representation of a p olycone can b e generated by a tuple of a set of

p oints and a set of rays called a generator The p olycone is a vector sum of a convex hull of

p oints x x and a cone of rays y y that is

n m

P P

p x y

i i j j

P

i

i n

i

j m

j

We shall say that a p olycone in Eq is generated by p oints x x and rays y y

n m

A unique minimal generator called a frame is obtained by eliminating nonextreme p oints

and rays from the generator Equivalence of two p olycones can b e tested by comparing their

frames A generator and a frame of a p olycone are denoted by gen and frame

resp For example let b e a p olycone corresp onding to Eq gen is fx x g

n

fy y g

m

The convex union t of two p olycones and is dened as the closure of the

set of p oints that are convex combinations of any two p oints of union of two p olycones t

is commutative and asso ciative A convex union of n p olycones is denoted by

n

tf g The generator of tf g is a tuple of the union of sets of p oints and

n n

the union of sets of rays in the generators of s so its parametric representation can b e

i

generated by p oints and rays in gen gen

n

The ane hull a of a p olycone is the smallest subspace containing If

gen fx x g fy y g then

n m

P P

p x y

i i j j

a

P

i

See Sch Ro c for details on p olyhedral convex sets

Substitution x e x e is dened in an usual way that is a variable x is

n n i

replaced by a linear arithmetic term e Using vector notation it is denoted by xe

i

A predicate dep endency graph is a digraph with no des of predicates and arcs from p to

q where p is a head predicate of a certain rule and q is its subgoal predicate Intuitively

q supp orts the derivation or solution of p We identify strongly connected comp onents

SCC of this digraph and a directed acyclic graph DAG whose no des are SCCs In the

actual derivation of ICs we analyze each SCC at a time starting from the leaves in the

DAG The analysis of an SCC is supp orted by ICs from the lower SCCs

Transformations Corresp onding to Logic Programs

k i

Supp ose there are k predicates p p in a program P and let ap denote the arity

1 k

ap ap i

b e parametric representations of p olycones in R R of p Let 1

k

p

p

b e the set of all convex sets in the p ositive Let U resp ectively and 1

i

k

p p

p

i

ap

U forms a complete lattice equipp ed with U orthant of R and U U

1

k

p

p

comp onentwise subset ordering v We now intro duce a transformation corresp onding to one logical rule

Denition natural transformation Supp ose the ith nonbase abstract rule whose

head predicate is p is in the form of

pe q f r g

where is a vector of variables app earing in the rule e e e f f f

ap aq

g g g are vectors of linear arithmetic terms Assume that every p olycone is

ar

in parametric representation The natural transformation U U corresp onding

pi p

to the ith rule of predicate p is dened by

p e

q f

q

pi

r g

r

For ith base abstract rule in the form of

pe

we have the following base p olycone

p e

B

pi

Example Continuing with Example supp ose we have a parametric representation

of a p olycone fa t t t g Then fa x u v x w

a

u v t w t x u v w t g For the base rule we have a

p olycone B fa t t t g

a

We extend this formalism to the whole program P in a natural way

Denition recursive transformation A recursive transformation T U U asso ci

P

is dened by a convex union T T ated with a program P is a direct pro duct of T

i 1

k

p

p p

of l base p olycones and m natural transformations asso ciated with the rules whose head

i

predicate is p

T T 1 T

k

P

p

p

tfB B g T

i i i i i

p p l p p m p

Natural transformation and recursive transformation are similar to those in VG but

more general

Theorem A recursive transformation T is monotone

P

Pro of The op erations involved in T are essentially intersection pro jection and convex

P

union of p olycones These op erations preserve monotonicity

Theorem There exists the least xp oint asso ciated with T

P

Pro of It follows from the fact that T is monotone and U forms a complete lattice

P

Our formalism is an instance of abstract interpretation hence correctness is guaranteed A

xp oint can b e veried by comparing the frames of p olycones in and T comp onentwise

Example Continuing with Example we now compute the least xp oint of recur

sive transformation Since there is only one predicate a in a program Let B T denote

B T T resp Note that denotes an empty p olycone In parametric

a a P a

representation we omit nonnegativity constraints of variables How to nd extreme p oints

and rays will b e covered in Section

base p olycone B fa t tg frameB f g f g

natural transformation

recursive transformation convex union of B and frameT f g f g

verify a xp oint frame frameT

so generate the parametric representation of T

natural transformation T fa x u v x w u v t w tg

frameT f g f g

p p

6 6

- -

p p

b a

p p

6 6

- -

p p

c d

Figure Polycones after recursive transformations

recursive transformation convex union of B and T

frameT f g f g

verify a xp oint frameT frameT

so generate the parametric representation of T

With one more transformation we reach the least xp oint IC generated by the frame of

lfp is fa u v u v g In append pro cedure its third argument size is equal to the sum of its rst and second

Unfortunately recursive transformations asso ciated with many practical programs often

fail to converge nitely in particular if we use listsize abstraction

Example Consider an abstract pro cedure b elow

pt t t

pu v u v pu v

In Figure a shows the p olycone from the base case rule b and c shows the

p olycones after one and two recursive transformations resp ectively d shows the p olycone

after innite transformations which is the xp oint of the transformation

Whether a recursive transformation converges nitely is b elieved to b e undecidable In logic

programs data structures in input arguments are usually transferred to output arguments

even though they may b e broken into smaller ones or combined into larger ones or the

values of elements are pro cessed In terms of argument sizes the relationship among them

may b e approximated by a set of equalities that represents an ane subspace Requiring

the least xp oint is to o much in general however p ostxp oints are also a correct upp er

approximation of least xp oint by Tarskis xp oint theorem T x x implies lfp T x

The idea of using widening has already b een used in the abstract interpretation of programs

in pro cedural languages CH

We now describ e what we call ane widening To simplify notations let us omit

subscripts concerning predicate name and supp ose there is only one predicate in a program

A is an ane subspace wrt the predicate If A is a p ostxp oint of T we are done

i i

with a correct IC Otherwise we widen T A to its ane hull A Supp ose A is such a

i i l

p ostxp oint that it is found for the rst time in the computation of A A

Theorem The sequence A A A is nite

l

1

Bro dsky and Sagiv studied inference of disjunction of inequalitie s b etween two argument p ositions

With a transformation similar to our recursive transformation they proved the question on convergence is

undecidabl eBS

2

If x  T x x  T x then x is a p ostxp oint prexp oint of T

Pro of It is enough to show the dimension of A is greater than that of A for i

i i

n

l since A s are ane subspaces in R where n is the arity of a predicate asso ciated

i

with the recursive transformation T A T A since A is not a p ostxp oint of T and

i i i

T A A since A is an ane hull of T A So A is an ane subspace prop erly

i i i i i

includin g A that is the dimension of A is greater than that of A

i i i

Although ane widening sometimes widens to no constraints it provides yet useful IC

with many practical programs

Example Let us consider append pro cedure with a constraint that all list elements

are integers

a T T

aXU V XW integerX aUVW

The purp ose of intro ducing the constraint integerX is to set the termsize of X to zero

The abstracted version of the ab ove append pro cedure is as follows

a t t t

a x u v x w x u v w x au v w

Using recursive transformation without ane widening the transformation do es not con

verge nitely since it expands the input convex set inch by inch at every iteration We now

try with ane widening A T fa a a g is an ane subspace which is

onedimensional frameA t T A f g f g so its ane hull is

A fa a a g which is twodimensional With one more iteration we nd that A

is a p ostxp oint of T fortunately a xp oint

Translativeness Prop erty

Let p b e a vector of argument sizes in a head and p a vector of argument sizes in a

recursive subgoal All nonrecursive subgoals are replaced by their ICs Then an abstract

n

rule can b e viewed as a p olycone in R so this p olycone can b e generated by its extreme

p oints and rays

Example Consider the naive reverse pro cedure

r

rXUW rUV aVXW

Applying listsize abstraction to the pro cedure we have

r

r u w u v w r u v av w

The analysis for a supplies an IC a a a Replacing av w by a a

a a v a a w reduces to the following abstract pro cedure

r

r u w u v w r u v v w

Let r and r denote the argument sizes of head and recursive subgoal resp So we have the

following parametric representation for r r r r

r u r w r u r v v w u v w

The parametric representation generated by the extreme p oints and rays is

r u

r v

r u

r v

u

v

Denition translativeness A natural transformation asso ciated with a linear

n

recursive rule is viewed as a p olycone in R when all nonrecursive subgoal are replaced by

their ICs Supp ose the parametric representation generated by extreme p oints and rays of

n

the p olycone in R is in the form of

P B A p

B C C B C B B C

A A A A

P p

P

i

i j k

y b oils down to where P and P are p ermutations Substituting P

p A B P p

P

i

i j

where P is P P If a natural transformation can b e reduced to Eq is P

translative

Let denote a p olycone represented by

p A B

P

i

i j

is indeed a vector sum of and P

P

Now we intro duce some useful op erations on p olycones

n

Denition Let b e p olycones in R The vector sum scalar multiplication

and linear transformation of p olycones are dened as follows

vector sum fx y jx y g

scalar multiplication fxjx g

linear transformation A fAxjx g where A is a matrix

Lemma The following equalities on p olycones hold

A A A

A t A t A

t t

Supp ose we have k base p olycones and l P translative natural transformations Then we

can simplify the recursive transformation T as follows

T B t t B t P t t P

k l

B t t B t t t P

k l

t P

B R

where B t t B and t t

B k R l

We now describ e how P translative natural transformation can b e unfolded to I

translative transformation using unfolding where I is an identity matrix

Denition Unfolding Supp ose T is P translative transformation T is obtained

by applying T to T

T T t P t P

B R B R

0 0

P t

R B

0 0

P t P and where

R R B R B R B

Applying at most n unfoldings in which n is the arity of the asso ciated predicate we can

get I translative transformation since P is a p ermutation matrix

Theorem Let T b e a translative transformation in the form of

T t

B R

and the generators of and are

B R

gen fu u g fv v g

B k l

gen fx x g fy y g

R n m

then

genlfpT fu u g fv v x x y y g

k l n m

Pro of

T t t t t k t

B R B R B R B

t t t t k t

B R R R

fxjx g

B R

In practice linearly recursive logic programs relying on recursion on structures technique

usually satisfy translativeness prop erty Hence their tight interargument constraints can b e

found without any iterations

Example The following pro cedure is intended to divide its rst argument into its

second and third argument In order to assure balanced division of the input list the last

two arguments are interchanged up on recursion

d

dX U X V W integerX dU W V

Applying termsize abstraction to the pro cedure we have

d

d u v w u v w du w v

Clearly frame f g fg From the second rule we get a P translative

B

transformation

P

R

where

fd g

R

P

Applying an unfolding b oils down to I translative transformation

0 0

t T

R B

0 0

f g fg By f g fg and frame where frame

R B

Theorem

d

d

lfpT

d

It implies that the rst argument size is the sum of the second and the third and the

rst argument size is greater than the second or the third if the rst is p ositive which is

imp ortant information when handling termination pro ofs It is noted that Van Gelders

recursive transformation do es not converge with this example and his heuristic do es not

work VG Sagiv and Bro dskys metho d can infer only inequalities b etween two argument

p ositions BS Recursive transformation with ane widening describ ed in the previous

section gives an IC d d d which is less precise than the ab ove

Extreme Points of a Polycone

n

Parametric representation of a p olycone in R can b e viewed as a set of constraints

m m n

in R and an ane transformation from R to R

x a A

Lemma The extreme p oints in are ane images of the extreme p oints of

ep fa Ap j p epg

where epS is the set of extreme p oints in S

The extreme rays in are images of linear transformation of the extreme rays of

er fAr j r erg

where erS is the set of extreme rays in S

is a p olycone so there are nite numb er of extreme p oints and rays As there is an

algorithm to nd all extreme p oints and rays of a p olycone in MR VG we can

eectively compute them See App endix B

The cost of computing all extreme p oints and rays dep ends on the numb er of parameters

and constraints Before we compute extreme p oints and rays we should b e able to

eliminate redundant parameters and constraints unless the cost of elimination is exp ensive

Parametric representation of a p olycone usually has the constraints in the form of equalities

Gaussian elimination pro cedure reduces equalities to inequalities eliminating at most n

parameters where n is the numb er of equalities By exploiting the fact that p olycone is

constrained to nonnegativity we can eliminate redundant inequalities and parameters

a x a x a x b where a b is redundant

n n i

a x a x a x b where a b forces x with nonzero co ecient to

n n i i

b e zero

a x a x a x b where a b makes the p olycone inconsistent

n n i

An implicit equality corresp onds to the elimination of one parameter and one constraint

The cost of nding an implicit equality is equivalent to that of running a linear program

General techniques for redundancy elimination of linear constraints can b e found in

KLTZ LHM

To verify a xp oint of a recursive transformation T we need to extract extreme p oints

and rays from p oints and rays transformed from the constraint set Supp ose we have k

p oints p p and l rays r r A ray r is nonextreme if it is nonnegative linear

k l i

combination of the other rays In other words a ray r is nonextreme if the following linear

i

system is solvable

X

r r

i j j j

j i

Similarly a p oint p is nonextreme if the following system is solvable

i

X X X

p p r

i j j j j j j j

j i

Thus we can eliminate nonextreme p oints and rays by testing the solvability of a certain

linear system Solvability of a linear system can b e tested theoretically in p olynomial time

by Khachiyans ellipsoid metho d or Karmarkars metho d Sch It also can b e tested

by exp onential time algorithm such as FourierMotzkin elimination or the rst phase of

simplex metho d Those p olynomial time algorithms have b een rep orted to b e impractical

unless the input size is substantially large The exp onentialtime algorithm will work if we

can maintain small input sizes

FourierMotzkin elimination stops up on nding an inconsistent inequality while the rst

phase of Simplex algorithm stops up on nding a feasible solution Thus in case many

nonextreme p oints or rays are present the rst phase of Simplex algorithm must b e used

In any case maintaining small input sizes is a key to using exp onentialtime algorithms

successfully

As we deal with p olytop es in the following we will use vertex instead of extreme

p oint Ane images of vertices in a p olytop e may contain a high degree of redundancy

It is the case that the numb er of neighb ors adjacent to a vertex is usually far less than that

of vertices in p olytop es Theorem says it is enough to show that an ane image v is

a convex combination of only its neighb ors on a graph induced by ane transformation in

order to show that v is not a vertex We are working on the extension to general p olyhedral

convex sets Let V fv v v g b e the set of vertices and E fe e e g the set

n m

of edges in Thus G V E represents the adjacency graph on vertices of a p olytop e

This graph can b e constructed using a variant of Simplex algorithm which nds all basic

feasible solutions rather than an optimal solution A graph G V E is one induced

by an ane transformation

V fv j v V g

E fv v j v v v v E g

Denition Gru Let G V E b e a graph M a set of vertices of G and v u

two vertices of G which do not b elong to M M separates v from u provided every path

connecting v and u contains some vertex in M

Conjecture Let v and u b e two vertices in an adjacency graph G of a p olytop e P

separated by M V Then the line segment connecting v and u passes through the convex

hull of M

Note the following theorem is based on Conjecture

Theorem Supp ose Conjecture holds Let x V and fy y g b e the set of

k

vertices adjacent to x Then x is a vertex in i x is not a convex combination of

y s

i

Pro of Sketch

Trivial

Let fz z g b e the set of vertices not adjacent to x in V If there exist no such

l

z s pro of is trivial

i

Let fp p g b e the set of vertices in V which are transformed to x and fq q g

m n

the set of vertices in V which are transformed to fy y g and fr r g the set of

k o

vertices in V which are transformed to fz z g

n

Each line segment connecting p and r i f mg j f og must pass

i j

through ConvexHull fq q g by Conjecture Since ane transformation preserves

n

the convexity each line segment connecting x and z j f l g must pass through

j

ConvexHull fy y g Thus x is a vertex

m

Summary

We formalized a metho d of deriving constraints among argument sizes and provided an

ane widening op eration to accelerate the convergence in nitely many steps yet providing

useful interargument constraints

We dened a class of linear recursive logic programs in terms of translativeness prop erty

For such a class tight interargument constraints are automatically given via the analysis

of the structure of transformations In practice most of logic programs are linear recursive

and rely on recursion on structure technique hence satisfying translativeness prop erty

input program append merge perm mergesort parser

cputime in milliseconds

ratio

Table Performance measures of inference of interargument constraints

The most costly op erations in the pro cedure of handling linear constraints are the

pro jections and nding all the extreme p oints and rays of p olycones We presented a

metho d exploiting information on adjacency of extreme p oints which outp erforms metho ds

using FourierMotzkin variable elimination

We implemented the metho d in Prolog The complete system consists of lines

of Prolog co de Some p erformance measures are listed in Table The input progrmas

are shown in App endix D The ratio was dened in Section Some discussion on the

p erformance results also can b e found in that section The programs were tested on SUN

sparc station

We are working on the extension of translativeness to nonlinear recursion

Relational Groundness Analysis

Intro duction

Logic programming has b een successfully used as a to ol for several areas including

compiler writing exp ert system design natural language pro cessing hardware design and

knowledgebase design One of the most attractive features of Prolog is bidirectional use of

arguments for input output or b oth however in practical programs most pro cedures do

not make this sophisticated use of arguments Using mo de information allows compilers to

pro duce more sp ecic co de which results in substantial sp eedup Mel With this regard

Warren intro duced explicit mo de declarations to help the compiler pro duce b etter co de

War But mo de declarations must b e veried since wrong annotation may intro duce

subtle errors in program executions

Another approach is to infer mo de declarations automatically via abstract interpretation

Mel BJCB MU DW Abstract interpretation has b een used as standard means

for dataow analysis since it was placed on a solid semantic basis by Cousot and Cousot

CC See CC for the theory and applications to logic programming

Early work done by Mellish Mel pro duced erroneous results since aliasing eects

resulting from unication was not considered which was corrected later Mel

Mannila and Ukkonen MU used simple twovalued abstract domains fg r ound any g

hence f r ee mo de cannot b e inferred g r ound f r ee any are abstractions of ground terms

free variables all ground or nonground terms resp ectively In addition their metho d

could not handle the problem with aliased variables accurately

Bruyno oghe et al BJCB suggested multipasses algorithm rep eat previous call

strategy to resolve aliasing problem which are considered to b e costly if the strategy is

applied globally

1

In their pap er nong r ound means p ossibly nonground which means any

Debray and Warren DW presented an algorithm to give a sound and ecient

treatment of aliasing However their metho d pro duces less precise mo de information since

they use conservative lo cal analysis in which all unsafe instantiations are replaced by any

In this chapter we study relational abstract domains which describ e p ossible groundness

relationships among arguments Like MU we only analyze groundness however our

metho d provides great accuracy with resp ect to groundness It is also noted that success of

correctness pro ofs like program termination relies on preciseness of groundness information

UVG Plub SVG

Let us consider a call pA fAB in which we have no instantiation information

on A and B Hence the goal is abstracted as pany any in the previous cited metho ds

But more careful lo ok at the call gives us the p ossible combinations of call patterns

fp p p g where and are g r ound and nong r ound resp ectively to keep

notations simple That is if the second argument is g r ound then the rst has no other

choice but g r ound Supp ose we have a clause pU fab With the call pattern

pany any the success pattern after the call to the clause is pany g r ound whereas with

our call pattern the success pattern is pg r ound g r ound Preciseness of success patterns

aect the subsequent call patterns immediately It should b e mentioned that if we use a

table of p ossible groundness relationships among arguments as shown ab ove we will end

up with combinatorial blowup

We now intro duce simple b o olean constraints to denote groundness relation Roughly a

term can b e abstracted as a logical disjunction of variables o ccurring in the term For

example pa a b is the abstraction of the goal pA fAB where a and b are

prop ositional variables corresp onding to A and B and is b o olean OR

Using p ositive prop ositional formula called domain PROP for groundness analysis has

b een studied by Marriott and Sndergaard MS The domain was further studied by

Cortesi et al CFW Our abstract domain is simpler than PROP since we only use

p ositive prop osition formula forming socalled a b o olean cone For such formula we can

easily nd a minimal generator set which is a unique minimal representation Therefore

g t

t g

g g t t t t

t t g

t t t t g

g t

g t

c b a

Figure Diagram of ground analysis

testing if two formula are equivalent can b e done eciently Main contribution of our

study is to intro duce novel concepts on b o olean cones and develop op erations to accomplish

eciently relational groundness analysis and to provide b ottomup groundness analysis

using prop ositional formula

In Section we describ e notations used through the chapter and intro duce groundness

abstraction of logic programs and concepts prop erties and op erations on b o olean cones

Section describ es some simplication pro cedures to remove redundancy in groundness

constraints

Section presents b ottomup groundness analysis mimicking immediate consequence

op erator

Section summarizes the chapter

The framework similar to our relational b ottomup analysis has b een investigated on

real arithmetic domain to derive constraints among argument sizes by Van Gelder VG

Basic Concepts

Abstraction

We now describ e abstraction of terms atoms and clauses Logic programs can b e

abstracted by groundness relationships among terms Informally sp eaking groundness

abstraction of a term carries the information that if all the variables in the term are ground

then the term is ground We cho ose the b o olean value to denote ground So x y is the

groundness abstraction of fXY That is if x X and y Y are ground then x y

fXY is ground Let v ar st denote a set of variables in a term t We shall use

lowercase letters for the b o olean variables corresp onding to logical variables

Example Figure illustrates groundness relationships of three atoms a pa

b pU fUV and c pU V fUV The lattices a b and c in Figure

are p ossible relationships for unary binary and ternary predicate resp ectively Circled

dots represent p ossible relationships for the three atoms listed ab ove For example for the

atom pU fUV b oth arguments can b e either ground or free and the rst

argument can b e ground and the second free But it is imp ossible to have the rst free

and the second ground

For notational convenience we shall use p for a b o olean variable representing groundness

i

abstraction of ith argument of predicate p Bo olean terms are terms built from b o olean

variables and connective b o olean OR Note that we do not use NOT and AND in

b o olean terms We often use a vector notation to denote a vector of b o olean terms For

example a a b b c c denotes a b c and a b c Substitution

x e x e is dened in an usual way that is a b o olean variable x is replaced by a

n n i

b o olean term e Using vector notation it is denoted by xe

i

Denition Let t b e a logical term Then t is a groundnessabstracted term

if v ar st is empty

t

x otherwise

xv ar st

Let p b e nary predicate Then groundnessabstracted atom is as follows

pt t t pt t t

n n

Abstraction of clauses is obtained by applying abstraction to each atom o ccurring in the clauses

Example Let us consider the usual append pro cedure

a U U

aXU V XW aU V W

Applying groundness abstraction to each clause transforms it to groundnessabstracted

pro cedure

a u u

ax u v x w au v w

Since terms are b o olean expressions unication must b e replaced by b o olean constraint

solving in the execution of the groundnessabstracted pro cedure

Relational Abstract Domains

We now intro duce b o olean cones and their constraint representation We also examine

some op erations like ORclosure as least upp er b ound op eration and equivalence of two

b o olean cones which are useful in nding the xp oint of a certain transformation concerning

groundness relation

n n

Denition Let a b f g C f g is a b o olean cone if

C

If a C and b C then a b C

Example f g is a b o olean cone whereas

f g is not

We use the word b o olean cones since they have the prop erties similar to those of convex

n

cones in R We now examine some useful prop erties of b o olean cones

Lemma Intersection of two b o olean cones C and C is a b o olean cone C

Pro of Clearly is in C Supp ose a and b are in C Therefore a and b are in b oth C

and C Since C and C are b o olean cones a b is in b oth C and C Then a b is also

in C

Example Let C f g and

T

C f g C and C are b o olean cones C C f g

is also a b o olean cone

n m

Lemma The pro jection of b o olean cone in f g onto f g where m n is also

a b o olean cone

Pro of Trivial

n

We now intro duce the concept similar to extreme rays of convex cones in R which

we call generators Generator sets serve as the unique minimal representation of b o olean

cones Therefore testing equivalence of two cones reduces to comparing two generator sets

Bo olean OR of two vectors is a vector of the results of comp onentwise OR

Denition Let C b e a b o olean cone C and C Then is a generator of C if

and cannot b e the b o olean OR of any other p oints in C A minimal generator set

g enC of C is a set of all generators in C A generator set is the set including a minimal

generator set and the p oints which can b e generated by the minimal generator set

Example g enf g f g

We can get a minimal generator set from a generator set by removing nongenerators A

nongenerator is a b o olean OR of some generators Testing if a p oint is a generator can b e

done as follows Supp ose we have a generator set fy y y g and we want to test if y

n

is a generator If y is not a generator then there must b e a a such that a f g

n i

and

y a y a y

n n

If ith comp onent of y is and ith comp onent of y is then a has no other choice but

j j

zero For other a s we can assign s Then we can evaluate the ab ove formula If it is

j

true y is a nongenerator otherwise a generator This test is done in linear time in terms

of the size of the generator set

Lemma There exists a unique minimal generator set g enC for any b o olean cone C

Pro of Supp ose G and G are two generator sets for a b o olean cone C and G G

Therefore there exists x such that x G and x G Since G is a generator set x

can b e a b o olean OR of some p oints g g in G Since g g are memb ers of C

k k

they are in G or b o olean combinations of generators in G That concludes x is a b o olean

combination of generators in G which is a contradiction

n

Let U b e the set of all b o olean cones in f g Equipp ed with the subset ordering

n

U forms a complete lattice with an empty set as the least element f g as the greatest

T F

element set intersection as greatest lower b ound op eration ORclosure as least upp er

b ound op eration as dened b elow

Denition The ORclosure of n cones C C C is the set of p oints which are

n

F

the b o olean OR of any p oints in C s it is denoted by fC C C g

i n

F

Lemma Let C C C b e b o olean cones fC C C g is the set generated

n n

by the union of the generator sets of C C C

n

Pro of It follows from the denition of a b o olean cone and a generator set

Example Let C f g and C f g

F

and C b e fC C g Their generator sets are g enC f g and g enC

f g Their union is g enC f g Hence C

f g

Groundness Constraints

The success of relational groundness analysis relies on whether we have eciently

computable form of relations Groundness relationships among arguments with resp ect

to a predicate can b e represented in the form of a set of b o olean constraints

Denition Let e e e e b e b o olean terms and c c c b o olean

n m

equalities Let p p p b e a vector of b o olean variables corresp onding to groundness

n

abstraction of arguments of predicate p

G fp e c c c g

m

is called a groundness constraint for a predicate p If m it is called a simplied

groundness constraint for p

Theorem A groundness constraint denes a b o olean cone

Pro of It is enough to show that one conjunction of a groundness constraint denes a

b o olean cone since the intersection andor pro jection of b o olean cones is also a b o olean

cone Each conjuction G is in the following form

x x y y

n m

The mo del of this formula G is the set of all the satisable assignments Let v v b e

k

a tuple of all the variables app earing in G is clearly a satisable assignment Let

a a and b b b e two satisable assignments of G Then a b a b

n n n k

is also a satisable assignment since a b a b has more s than a a or

k k k

b b

k

Simplications and Normal Forms

The most costly op eration is to test equivalence of two groundness constraints which

must b e p erformed at each iteration of transformation concerning abstract interpretation

This op eration is tantamount to nding generators of pro jection of cones since generators

are unique minimal representation of cones In most cones asso ciated with practical

programs generators can b e obtained by the following simplication rules

x y z is equivalent to x y z

If x y z w is a constraint and w do es not app ear on the lefthand side

substitute the lefthand side into every place where w app ears If w app ears nowhere

delete the constraint

If x app ears on the same side as y in every o ccurrence x can b e deleted

A simplied groundness constraint corresp onds to a set of p oints including generators which

reduces to a generator set by removing redundancy This is explained in the following

example

Example Let C fp x w y w x y w g b e a simplied groundness constraint

x w y w x y w x y w where can b e viewed as scalar

multiplication and as comp onentwise b o olean OR Then and

are candidates for generators and is redundant since

So g enC f g This example also explains how to generate groundness

constraints from generators

Let us turn our attention to groundness constraints which cannot b e simplied by the ab ove

simplication rules One way to nd generators is to transform equalities with b o olean terms

to ones with real arithmetic terms That is

x x x y y y

n m

can b e transformed to

x x x y

n

x x x y

n

x x x y

n m

y y y x

m

y y y x

m

y y y x

m n

x x x y y y f g

n m

It is easy to prove that b oth have the same set of solutions and extreme rays of the linear

arithmetic systems are vectors of or s after b eing normalized so that one of their p ositive

comp onents is

Theorem If x is a generator of a b o olean cone represented by a groundness

constraint then it is a normalized extreme ray of a convex cone represented by a linear

arithmetic constraint transformed from the groundness constraint

Pro of Supp ose x is a generator and it is not a normalized extreme ray Since x is not

a normalized extreme ray x is a p ositive combination of some normalized extreme rays

y y that is

n

x a y a y

n n

where a is p ositive Let us consider a sum of y y that is

i n

x y y

n

The value x whenever x and the value x whenever x Therefore

i i

i i

Eq implies Eq In fact Eq is exactly how we compute

x y y

n

Since y y are the p oints in the b o olean cone x is not a generator Contradiction

n

As there are wellknown metho ds to nd extreme rays of convex cones same as nding

extreme p oints of convex p olytop es VG Lasa we can nd candidates for generators

for the corresp onding b o olean cones by removing redundancy

BottomUp Groundness Analysis

In the preceding sections we describ ed the relational abstract domain and some useful

op erations on the domain We now give a b ottomup abstract interpretation to get success

patterns in the form of groundness constraints

Abstract interpretation consists of abstract domain and abstract op erations which

mimics base semantics faithfully Hence b ottomup abstract interpretation mimics xp oint

semantics Formal framework of b ottomup abstract interpretation can b e found in CC

MS

Now we dene a transformation mimicking immediate consequence op erator

Denition Supp ose we have k predicates whose names are p q r in an abstract

program and p is ith clause having the head predicate p and so forth Let P Q R b e

i

groundness constraints asso ciated with those predicates and U the set of all b o olean cones

p

determined by the arity of the predicate p and so forth Let U U U U Let x b e a

p q r

vector of groundness constraints P Q R U U U Recursive transformation

p q r

T is a mapping from U to U and T is a mapping from U to U as given b elow

p p

T x T x T x T x

p q r

F

m

T x fT 1 x T 2 x T xg

p p

p p

x fp a Qqb Rrcg T

i

p

where there are m clauses having the head predicate p and the ith abstract clause of the

predicate p is in the form of

pa q b r c

Theorem There exists the least xp oint of T and it can b e reached in nite numb er

of iterations

is clearly monotone so T is monotone The domain Pro of By its denition T

p

i

U U U forms a nite complete lattice equipp ed with comp onentwise subset or

p q r

dering

In practice it is more ecient to pro cess strongly connected comp onents separately in

predicate dep endency graphs starting from leaves in a tree induced by SCCs

Example Continuing with Example

T T fa u ug

G

T T T fT fa x u v x w u v u w u gg

fa x v x v g

input program append merge perm mergesort parser

cputime in milliseconds

ratio

Table Performance measures of inference of success patterns

Interested readers are invited to verify T T which is the least xp oint of T Note

that we only use simplication rules to reduce to simplied groundness constraints The

resulting xp oint shows that in the success pattern of append pro cedure if the rst and

second argument are ground then the third is ground and vice versa

Summary

We presented a novel relational groundness analysis in this chapter To compute

groundness relations eciently we used b o olean constraints forming b o olean cones We

intro duced the concept of generators to facilitate the equivalence test of two sets of b o olean

constraints

We implemented the metho d in Prolog Some p erformance measures are listed in

Table The ratio was dened in Section The input programs are shown in

App endix D The programs were tested on SUN sparc station The domain PROP was

implemented by B Le Charlier and P Van Hentenryck LCVH and by M Co dish and B

Demo en CD Our current implementation can take programs in pure Prolog as input

We are working on lifting this limitation It will b e interesting to compare our p erformance

results with their results

Including freeness analysis and developing ecient test of cone equivalence will b e future

research directions

Conclusion

We have presented a metho dology for termination analysis in logic programming

environment Our metho d is mo dular in that we examine one strongly connected comp onent

by one in the predicate dep endency graph of a program Nonnegative linear combination of

b ound argument sizes is used as levelmapping function To test if this function decreases

in wellfounded domain we have transformed the test condition into solvability problem of

a linear system using duality theory of linear programming This metho d is straightforward

and general Unlike other metho ds our metho d could b e extended to nonlinear and mutual

recursion with only slight mo dication

We often need to know the relationship among argument sizes of a predicate in a subgoal

to relate head argument sizes and recursive subgoal argument sizes We have formalized a

metho d of deriving such relationship using transformation similar to immediate consequence

op erator The transformation acts on abstract domain where only the size of a term

is considered This transformation however do es not necessarily converge Since it is

dicult and unnecessary to nd the least xp oint we have provided an ane widening

approximation to accelerate the convergence of the transformation up to nitely many

steps

We have also dened a class of linear recursive logic programs in terms of translativeness

prop erty For such a class tight interargument constraints are automatically given via the

analysis of the structure of transformations In practice most of logic programs are linear

recursive and rely on recursion on structure technique hence satisfying translativeness

prop erty

Groundness analysis plays a very imp ortant role for global optimization of Prolog

compiler It is also required in order to apply our termination analysis metho d to Prolog

programs rather than knowledgebase systems Relational groundness analysis has b een

thought to b e costly in published pap ers We have suggested to use b o olean constraints

to represent groundness relationship among arguments of a predicate This metho d works

quite eectively with the help of simplication pro cedures and gives more precise analysis

since it resolves the problem due to aliased variables

The prototyp e of the implementation is done in Prolog The p erformance measures have

showed termination analysis is so ecient and precise that it can b e practically applied to large programs

App endix A FourierMotzkin Elimination

FourierMotzkin elimination pro cedure is used to test if a system of linear constraints are

solvable In this technique a variable is eliminated by cancelling all p ositive o ccurrences

with all negative o ccurrences pairwise creating new rows with in that variables column

Then all rows containing a nonzero co ecient for that variable can b e eliminated preserving

solvability If there are only p ositive or negative o ccurrences of the variable all the

inequalities containing p ositive or negative o ccurrences are deleted The reasoning is the

variable can have arbitrary values dep ending on how other variables are constrained

Consider the following linear constraints

x x x

x x

x x

x

Using the matrix notations for denoting the system of inequalities

The vertical line denotes

Try to eliminate the rst column corresp onding to x Column and have p ositive

co ecients while Column and have negative co ecients So each pair of rows with

p ositive rows and rows with negative rows that is Column and Column and

Column and Column and can b e canceled with appropriate multiplication and

addition op erations so that the co ecient of x is zero For example multiplying Row by

and then adding Row and Row makes the co ecient zero Deleting all the rows with

nonzero co ecients gives a new linear system pro jected on fx x gspace

After eliminating x and x in the same way we have the following matrix

Since vertical bar represents it is indeed It is contradictory so the initial

linear system is unsolvable This pro cess is inherently exp onentialtime since it may double

the numb er of inequalities at each variable elimination How big the numb er of inequalities

grows dep ends on the order of variables we cho ose to eliminate For example if we cho ose

x to eliminate instead of x in the initial linear system the resulting numb er of inequalities

after elimination will b e This naive FourierMotzkin elimination is useless in practice

Heuristics is used in order to minimize the growth of the numb er of inequalities Let P

i

and N denote the numb er of p ositive and negative o ccurrences of x resp ectively P N

i i i i

is the numb er of new inequalities intro duced by eliminating x P N is the numb er of

i i i

inequalities deleted by eliminating x Therefore P N P N is the dierence in

i i i i i

the numb er of inequalities after eliminating x We cho ose x as a pivot variable such that

i i

P N P N is minimal

i i i i

Without sophisticated redundancy check FourierMotzkin elimination is almost useless

for sizable input For example what follows is an articially made system of linear inequalities

Initially it has inequalities After eliminating one two three and four variables the

numb er of inequalities is resp ectively

However the linear inequalities generated to test termination condition have usually

many zero co ecients Thats b ecause terms contains only one or two variables Consider

the following CLPR program

pX N D

X Xpos Xneg

D N Xpos Xneg

Xpos Xneg N

pX N D

X Xpos Xneg

D N Xpos Xneg

D

Xpos Xneg Xpos Xneg

D N Xpos Xneg

X Xpos Xneg

pX N D The matrix corresp onds to termination condition

After eliminating one two three and four variables the numb er of inequalities is

resp ectively Our broad conclusion is that it is adequate and simple to use Fourier

Motzkin elimination for our termination analysis

App endix B Finding All Extreme Points and Rays

In this chapter we describ e how to mo dify Simplex algorithm to nd all extreme p oints

and rays of a p olycone Simplex algorithm assumes the feasible region is b ounded and visits

basic feasible solutions extreme p oints in such a way that they maximize or minimize

the ob ject function

In our setting we need to nd all basic feasible solutions for short BFS Since BFSs are

connected and we can move from BFS to BFS by pivoting op eration we can use exhaustive

graph search algorithm such as depthrst search The question is how we can identify

extreme rays

The simplex algorithm of linear programming can b e mo died to nd the extreme p oints

and directions of a p olycone Background on this algorithm can b e found in Papadimitriou

and Steiglitz PS Ch and elsewhere we review the essentials briey Assume we have

a linear programming problem in a standard form except for the ob jective function which

may b e treated as That is we have a linear system

A b

that describ es the p olycone where A is an m N matrix of full rank and m N This

includes x and the slack indep endent variables of the generalized Tucker representation

its arity is N Recall that a basis for the problem is a set of m linearly indep endent columns

of A designated A for i m B denotes the nonsingular matrix comp osed of the

B i

basis columns of A Here B is an melement subset of f N g in a xed sequence

An extreme p oint is a nonnegative vector P such that

P for k B

k

P ith comp onent of B b

B i

It is well known that basic feasible solutions corresp ond to vertices extreme p oints of the

p olycone and that they can b e enumerated by pivoting from one basis to another

Supp ose a column say A in the simplex tableau is all nonp ositive An extreme ray is

j

a nonnegative vector R such that

Phase I

Find rst feasible basis

Try every p ossible combination of pivot columns

and rows until you get a feasible basis

If you nd a row whose co ecients are all nonnegative

and whose constant is negative while pivoting or

there is no feasible basis

then the linear system is inconsistent stop

Phase I I

DFSbasis tableau

Mark the basis visited

Print an extreme p oint and rays if any

NONDETERMINISM HERE

Pick a column entering variable which is not in basis

and at least one of whose memb ers is p ositive

If the column is all nonp ositive its an extreme ray

Find rows whose is minimum so the entering variable

guarantees new basis forms an extreme p oint

If no such column and row is found fail

else pivot on tableau to pro duce new tableau

DFSnew neighb oring basis new tableau

Figure B Algorithm to nd all extreme p oints and rays

R

j

R for k j k B

k

R ith comp onent of A

j

B i

The reasoning is we can move from P along R indenitely More details can b e found in

VG CH

x

er er

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p 6

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p p

p p p p p p p p p p p p p p p p p p p p

t t -

x

ep ep

Figure B Extreme p oints and extreme rays of a p olycone

Consider the following system of linear inequalities Supp ose x and x are constrained

to nonnegativity

x

B

x

x x

The shaded area of Figure B depicts the feasible region As shown in the picture

we have two extreme p oints and and two extreme rays and In

what follows we describ e how to nd those extreme p oints and rays with this example By

adding slack variables x x and x and putting the system into matrix form we have a

tableau in standard form

x x x x x

The Basis is fx x x g so we nd an extreme p oint The second column is all

nonp ositive so we nd one extreme ray This basis is marked as visited The

underlined entry is a pivot element so we move to a new basis fx x x g The imp ortant

p oint is Simplex metho d never gets back to this tableau b ecause it always marches towards

a optimal solution while our metho d using DFS gets back to explore other adjacent vertices

So we need to keep the state of this tableau hence big overhead

x x x x x

Here we nd an extreme p oint and an extreme ray By entering x in

the basis we have a new basis fx x x g

x x x x x

Here we nd an extreme p oint and an extreme ray By entering x

we move to a new basis fx x x g Since this basis is already marked we lo ok for another

pivot element In this simple example there are no other pivot elements so we backtrack

to the previous tableau

Finally deleting slack variables from the extreme p oints and rays provides us with two

extreme p oints and and two extreme rays and for the initial linear system

App endix C Sessions for Test Programs

C Permutation

terminatepermbfperm

RuleGoal Graph

goalpermbfpermbfappendbbfappendffb

ruleruleappendffbappendbbfpermbf

goalappendbbfappendbbfruleruleappendbbf

goalappendffbappendffbruleruleappendffb

Predicate Dependency Graph

adjpermbfpermbfappendbbfappendffb

adjappendbbfappendbbf

adjappendffbappendffb

Strongly Connected Components

permbf appendffb appendbbf

SCCpermbf testing termination

range of deltapermbfpermbf inf

range of phipermbfpermbf

range of alphapermbf inf

SCCpermbf shown to terminate

SCCappendffb testing termination

range of deltaappendffbappendffb inf

range of phiappendffbappendffb

range of alphaappendffb inf

SCCappendffb shown to terminate

SCCappendbbf testing termination

range of alphaappendbbf inf

range of deltaappendbbfappendbbf inf

range of phiappendbbfappendbbf

range of alphaappendbbf inf

SCCappendbbf shown to terminate

statisticsruntimeT

T

C Expression Parser

terminateebfent

RuleGoal Graph

goalebfebftbfruletbfebfruletbf

goaltbftbfnbfrulenbftbfrulenbf

goalnbfebfzbruleebfrulezb

goalzbrulerulerule

Predicate Dependency Graph

adjebfebftbf

adjtbftbfnbf

adjnbfebfzb

adjzb

Strongly Connected Components

ebfnbftbf

SCCebfnbftbf testing termination

range of alphatbf inf

range of alphanbf

range of alphaebf

range of deltatbftbf

range of deltatbfnbf

range of deltanbfebf

range of deltaebftbf

range of phitbfnbf

range of deltaebfebf

range of phinbfebf

range of phitbftbf

range of phitbfebf

range of phiebftbf

range of phinbftbf

range of phinbfnbf

range of phiebfnbf

range of phiebfebf

SCCebfnbftbf shown to terminate

statisticsruntimeT

T

App endix D Test input programs

D App end

the third argument is a concatenation of the first two

appendLL

appendHLLHL appendLLL

D Merge

merge U and V into W

mergeU U

merge V V

mergeU Us V VsU Rs U V mergeV Vs Us Rs

mergeU UsV VsU V Rs U V mergeVs Us Rs

mergeU UsV VsV Rs U V mergeVs U Us Rs

D Mergesort

merge sort

msort

msortX X

msortX Y RZ

splitX Y RUV

msortU U

msortV V

mergeU V Z

split U into V and W evenly

split

splitE U E V W splitU W V

merge U and V into W

mergeU U

merge V V

mergeU Us V VsU Rs U V mergeV Vs Us Rs

mergeU UsV VsU V Rs U V mergeVs Us Rs

mergeU UsV VsV Rs U V mergeVs U Us Rs

D Permutation

one argument is a permutation of the other

perm

permLHT

appendVHUL

appendVUW

permWT

appendLL

appendHLLHL appendLLL

D Parser

arithmetic expression parser

zL

eL T tL T

eL T tL C eC T

tL T nL T

tL T nL C tC T

nL T T zL

n A T eA T

References

AB K R Apt and M Bezem Acyclic programs New Generation Computing

AP K R Apt and D Pedreschi Studies in pure Prolog termination In Proceedings

of Esprit symposium on computational logic pages Brussels Novemb er

APP F Afrati C Papadimitriou G Papageorgiou A R Roussou Y Sagiv and

J D Ullman On the convergence of query evaluation Journal of Computer and

System Sciences

BJCB M Bruyno oghe G Janssens A Callebaut and Demo en B Abstract interpre

tation Towards the global optimisation of Prolog programs In Proceedings of

the International Symposium on Logic Programming IEEE Press

BSa A Bro dsky and Y Sagiv Inference of monotonicity constraints in Datalog

programs In Eighth ACM Symposium on Principles of Database Systems pages

BSb A Bro dsky and Y Sagiv On termination of Datalog programs In First

International Conference on Deductive and ObjectOriented Databases pages

Kyoto Japan

BS A Bro dsky and Y Sagiv Inference of inequality constraints in logic programs

In Tenth ACM Symposium on Principles of Database Systems

CC P Cousot and R Cousot Abstract interpretation A unied lattice mo del for

static analysis of programs by construction or approximation of xp oints In

Conference Record of the th ACM Symposium on Principles of Programming

Languages

CC P Cousot and R Cousot Abstract interpretation and application to logic

programs Journal of Logic Programming

CD M Co dish and B Demo en Analysing logic programs using propositional

logic programs and a magic wand In D Miller editor Logic Programming

Proceedings of the International Symposium pages Cambridge

Massachusetts MIT Press

CFW G Cortesi G File and W Winsb orough PROP revisited Prop ositional

formula as abstract domain for groundness analysis In Proceedings of Sixth

IEEE Symposium on Logic In Computer Science pages Cambridge

Massachusetts IEEE Computer So ciety Press

CH P Cousot and N Halbwachs Automatic discovery of linear restraints among

variables of a program In Conference Record of the th ACM Symposium on

Principles of Programming Languages pages

CLR T H Cormen C E Leiserson and R L Rivest Introduction to Algorithms

pages MIT Press New York

CM W F Clo cksin and C S Mellish Programming in Prolog SpringerVerlag New

York

Dev P Devienne Weighted graphs a to ol for studying the halting problem and

time complexity in term rewriting systems and logic programming Theoretical

Computer Science

DSD D De Schreye and S Decorte Termination of logic programs the neverending

story preprint

DSVB D De Schreye K Verschaetse and M Bruyno oghe A practical technique for

detecting nonterminating queries for a restricted class of horn clauses using

directed weighted graphs In Proc th Intl Conf on Logic Programming pages

Jerusalem

DW S K Debray and D S Warren Automatic mo de inference for logic programs

Journal of Logic Programming

Gru B Grun baum Convex Polytopes John Wiley and Sons New York

Hog C J Hogger Essentials of Logic Programming Oxford University Press New

York

KLTZ M H Karwan V Lofti J Telgen and S Zionts Redundancy in Mathematical

Programming A StateoftheArt Survey SpringerVerlag New York

Kow R A Kowalski Predicate logic as a programming language In Proceedings of

IFIP pages Amsterdam NorthHolland

Kow R A Kowalski Algorithm logic control Communications of the ACM

Lasa JL Lassez Parametric queries linear constraints and variable elimination In

Proceedings of DISCO Springer Verlag Lecture Notes in Computer Science

Lasb JL Lassez Querying constraints In Ninth ACM Symposium on Principles of

Database Systems pages

LCVH B Le Charlier and P Van Hentenryck Groundness analysis for prolog imple

mentation and evaluation of the domain PROP In Proceedings of Symposium

on Partial Evaluation and Semanticsbased Program Manipulation

LHM JL Lassez H Huynh and K McAlo on Simplication and elimination of

redundant linear arithmetic constraints In North American Conf on Logic

Programming pages

Llo J W Lloyd Foundations of Logic Programming SpringerVerlag New York

Mel C S Mellish The automatic generation of mo de declaration for logic programs

Technical Rep ort DAI Research Pap er Department of Articial Intelligence

University of Edinburgh Scotland

Mel C S Mellish Some global optimizations for a prolog compiler Journal of Logic

Programming

Mel C S Mellish Abstract interpretation of Prolog programs In S Abramsky

and C Hankin editors Abstract Interpretation of Declarative Languages pages

Ellis Horword Chichester UK

MR T H Matheiss and D S Rubin A survey and comparison of metho ds for nding

all vertices of convex p olyhedral sets Mathematics of Operations Research

MS K Marriott and H Sndergaard Bottomup abstract interpretation of logic

programs In S K Debray and M Hermenegildo editors Logic Programming

Proceedings of the Fifth International Conference pages Cambridge

Massachusetts MIT Press

MS K Marriott and H Sndergaard Notes for a tutorial on abstract interpretation

of logic programs North American Conf on Logic Programming

MU H Mannila and E Ukkonen Flow analysis of Prolog programs In Proceedings

of the International Symposium on Logic Programming IEEE Press

MUVG K Morris J D Ullman and A Van Gelder Design overview of the Nail system

In Third Intl Conf on Logic Programming pages

Nai L Naish Automatic generation of control for logic programs Technical Rep ort

Dept of Computer Science University of Melb ourne Melb ourne Australia

Plua L Plumer Termination Proofs for Logic Programs volume of Lecture Notes

in Articial Intel ligence SpringerVerlag

Plub L Plumer Termination pro ofs for logic programs based on predicate inequalities

In Proc th Intl Conf on Logic Programming pages Jerusalem

PS C H Papadimitriou and K Steiglitz Combinatorial Optimization Prentice

Hall Englewo o d Clis NJ

Ro c R T Ro ckafellar Convex Analysis Princeton University Press Princeton NJ

Sag Y Sagiv A termination test for logic programs In Proceedings of ILPS pages

San Diego MIT Press

Sch A Schrijver Theory of Linear and Integer Programming Wiley New York

SS L Sterling and E Shapiro The Art of Prolog MIT Press Cambridge

Massachusetts

SU Y Sagiv and J D Ullman Complexity of a topdown capture rule Technical

Rep ort STANCS Stanford University

SVG K Sohn and A Van Gelder Termination detection in logic programs using

argument sizes In Tenth ACM Symposium on Principles of Database Systems

Ull J D Ullman Implementation of logical query languages for databases ACM

Transactions on Database Systems

Ull J D Ullman Principles of Database and Know ledgebase Systems Computer

Science Press Ro ckville MD

UV J D Ullman and M Y Vardi The complexity of ordering subgoals In

Proceedings of Principles of Database Systems pages

UVG J D Ullman and A Van Gelder Testing applicabili ty of topdown capture rules

Technical Rep ort STANCS Dept of Computer Science Stanford

University Stanford CA April

UVG J D Ullman and A Van Gelder Ecient tests for topdown termination of

logical rules Journal of the ACM

VG A Van Gelder Deriving constraints among argument sizes in logic programs

Annals of Mathematics and Articial Intel ligence Extended abstract

app ears in Ninth ACM Symp osium on Principles of Database Systems

War D H D Warren Implementing prolog compiling predicate logic programs

Technical Rep ort DAI Research Pap er and Department of Articial

Intelligence University of Edinburgh Scotland