
Logic Programs as Term Rewriting Systems Massimo Marchiori Department of Pure and Applied Mathematics University of Padova Via Belzoni Padova Italy maxhilbertmathunipdit Abstract This pap er studies the relationship b etween logic programs and term rewrit ing systems TRSs A comp ositional transform is dened whichgiven a logic program computes a TRS For a relevant class of logic programs called Simply Well Mo ded SWM there is a onetoone corresp ondence b etween computed answer substitutions of the logic program and normal forms of the corresp ond ing TRS Moreover the transform preserves termination ie a logic program terminates i the corresp onding TRS terminates This transform is rened in suchaway that the ab ove results hold for a relevant class of unication free programs containing SWM the class of Flatly Well Mo ded FWM programs Note This work was done during an authors stay at CWI Amsterdam Intro duction The study of transforms from logic programs into term rewriting systems TRSs for short is an imp ortant topic Theoreticallyitisinteresting to analyze which classes of logic programs can b e regarded as TRSs in disguise Practically using an appropriate transform allows to infer prop erties of a logic program from prop erties of the corresp onding TRS For instance this metho d has b een successfully applied in anumberofworks to study termination of logic programs SRK RKS GW AM using transforms that preserve nontermination Transforms that compute TRSs which not only preserve nontermination but are equivalent to the corresp onding logic programs havebeeninvestigated only very recently Mar AM Equivalence means that the logic program terminates i the corresp onding TRS terminates and that computed answer substitutions of the logic program and normal forms of the TRS are in onetoone corresp ondence The aim of this pap er is to provide a compositional transform which maps a logic program into an equivalent TRS Comp ositionality is fundamental b ecause for instance a comp ositional transform allows to transform a logic program into a TRS in a mo dular way ie clause by clause The classes of logic programs we consider are contained in the socalled well mo ded programs DM Moreover the transform can deal with a broader class of programs where typ es instead of mo des are considered The contribution of this pap er can b e summarized as follows First a comp ositional transform Tswm is intro duced which allows to translate into a class of equivalent TRSs b oth the class of Simply Well Mo ded programs of AE and a wider class of programs which are not wel l moded namely the Simply and Well Typ ed programs SWT of AE It is also shown how with little mo dications Tswm can b e extended to the whole class of Well Mo ded programs losing equivalence but still providing a relevant corresp ondence in the sense that if the TRS terminates then the corresp onding logic program terminates as well Finallyitisintro duced a second transform called Tfwm that extends Tswm by translating the class of atly wel l moded programs FWM intro duced in Mar into equivalent TRSs The FWM class has b een proven to b e lo cally maximal among the unication free ones Moreover it is the lo cally greatest class of unication free programs containing SWM Informally a class of logic programs is lo cally maximal resp greatest among the unication free programs if it is maximal resp greatest among those classes of unication free programs that can b e characterized bymeans of clause by clause syntactical criterions see Mar for a formal denition Recall that a logic program is unication free if unication in the resolution pro cess can b e p erformed by means of iterated applications of the simpler pattern matching MK These results can b e roughly summarized in the following slogan Logic Programs Unication Term Rewriting Systems Relations with Previous Work The idea to transform logic programs into TRSs started with SRK and has b een further rened in RKSGW AM The main stimulus in this eld was the study of termination of logic programs a transform is dened with the prop erty that if a logic program do es not terminate then the corresp onding TRS do es not terminate as well Thus a sucient criterion for proving the termination of a logic program consists of checking whether the transformed TRS terminates This approach is attractive b ecause TRSs enjoypowerful techniques to prove termination as path orderings for instance see Der DJ whereas for logic programs the situation is far more complicated In this pap er the ab ove transformational metho dology is taken a step further in the sense that weintro duce transforms that fully translate a logic program this way a sucient but also necessary criterion for termination can b e given A transform treating this kind of corresp ondence was intro duced in AM However this transform is not comp ositional Also the transform Tfwm here pre sented is able to transform classes of logic programs that are completely out of scope from the previous transforms a drawback observed also by the same authors of GW AM The pap er is organized as follows Section gives the necessary preliminaries Section intro duces the concept of transform and a formal setting for its analysis In Section we sp ecify the languages used b oth for the logic programs and the corresp onding TRSs and the basic rewrite rules used in the transforms In Section the transform Tswm is dened and its completeness is proven wrt the class SWM Section intro duces some techniques to simplify the output of a transform and illustrates its application to prove the termination of a logic program by means of an example Section intro duces the transform Tfwmthatisproven complete for the class FWM The relevance of this transform is illustrated by means of a signicant example Finally Section concludes with some imp ortant remarks Pro ofs are here omitted or only sketched they can b e found in the full version of this pap er Preliminaries We assume familiarity with the basic notions regarding logic programs Llo Apt and term rewriting systems Klo In this pap er we will deal only with socalled LDderivations briey derivations that is SLDderivations in which the leftmost selection rule is used With TermF we will denote the set of terms built up from some function set i F Sequences of terms will b e written in vectorial notation eg t and with t we will denote the ith term in t Given a family S of ob jects terms atoms etc VarS is the set of all the variables contained in it moreover S is said linear i no variable o ccurs more than once in it ob jects O O will b e said disjoint i ij n VarO n i VarO s U t will mean that the terms s and t are disjoint and uniable With j tA t A t we will mean the term obtained by t replacing every o ccurrence n n in t of the symbol A with t i n For the sake of simplicitywe will sometimes i i omit brackets from the argument of unary functions eg f g X maybewritten fgX and if t t t the sequence f t ft will b e indicated with f t n n Also given two sequencess s s and t t t we will denote bys t n m the sequence s s t t n m Programs We call logic program a nite set of Horn clauses and goals If the program has no goals it is called a prop er program Let P b e a program P the set of all the goals in P andP P n P Wecall derivation of P a derivation of P fGgwhen G is in P Analogouslywecall computed answer substitution of P a computed answer substitution of P fGg where G is in P The set of all the computed answer substitutions of P is denoted by cas P This formalism is well suited when formulating program prop erties since it allows not to treat separately the clauses and the goal Moreover it is a natural choice when using regular prop erties see b elow that essentially do not distinguish b etween goals and clauses Since we are going to transform logic programs in term rewriting systems the same convention will b e adopted for TRSs as well reading goal as term clause as rewrite rule and derivation as reduction hence an extended TRS is a nite set of rules and a p ossibly innite set of terms The analogous of the set cas P for a TRS T is the set NF T of its normal forms The class of these extended logic programs resp TRSs will b e denoted by LPext resp TRSext Regularity Denition A prop erty P is said regular if B B P START B B P n n where START isanewnullary predicate symbol Using regularity will prove useful to elegantly shorten the description of the prop er ties we will use in this pap er likewell mo dedness for example and also the denition of the transforms since from nowon weidentify a goal with the corresp onding clause having the sp ecial symbol START in the head and analogously for TRSs we identify a term with the corresp onding rule having the sp ecial symbol START in the left hand side cf Subsection for the language setting Although this will not concern us it is worthwhile to notice that regularityisfar from b eing merely a syntactic sugaring to ol but has an imp ortance for its own see Mar Mo des and Well Mo dedness Denition A mode for a nary predicate p is a map from fng to fin outg A moding is a map asso ciating to every predicate p a mo de for it An argument p osition of a mo ded predicate is therefore said input output if it is mapp ed by the mo de into in out For every predicate pthenumb er of its arguments ie the arity input p ositions and output p ositions will b e denoted resp ectively by p p and p Moreover we adopt the convention to write ps t to denote in out a mo ded atom p having its
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages19 Page
-
File Size-