Abstract 1 Introduction - CiteSeerX

10 downloads 8439 Views 229KB Size Report
The Underlying Search for Magic Templates and ... Email: [email protected]. Abstract .... As with OLDT-resolution, we will not discuss Magic Templates in full gen-.
The Underlying Search for Magic Templates and Tabulation Roland Bol

Technische Universiteit Eindhoven HG 8.88, P.O.Box 513 NL 5600 MB Eindhoven, Netherlands Email:[email protected]

Lars Degerstedt

IDA, Linkoping University S-581 83 Linkoping, Sweden Email: [email protected]

Abstract The main aim of this paper is to present a framework for tabulated SLDresolution that allows a strict separation between search space and search. We introduce the notion of a search forest to model the search space, and we de ne what we understand by a search strategy for it. We present some basic search strategies and discuss how a particular tabulation technique, OLDT-resolution, and a particular transformation technique, Magic Templates, relate to our approach. This comparison also reveals an inherent di erence between the tabulation and the transformation approach.

1 Introduction Resolution is the main technique used by query answering systems for logic programs. It can be applied in two di erent ways, usually called \bottomup" and \top-down". The top-down methods are perhaps the most intuitive ones, because their starting point is the query: they are goal-oriented . As a result they will not compute irrelevant facts, but intermediate results that are needed several times can be computed again and again, e.g., in SLDresolution [11]. The well-known SLD-tree provides a nice separation between the search space : what has to be computed, and search strategies : the order of the computation. SLD-resolution is complete, i.e., all correct answers are represented in an SLD-tree. Thus an interpreter that applies a complete search strategy will indeed produce all answers. Unfortunately, such interpreters are very inecient. A more ecient and widely used search strategy (e.g., in Prolog) is depth- rst search. However, this search strategy bears a high risk of incompleteness because of its weak termination properties . This largely disquali es SLD-resolution for those classes of programs for which terminating query answering procedures exist. 1

One such class consists of the deductive databases , also called functionfree logic programs, which include Datalog programs. For these programs, bottom-up computation is more popular because it always terminates. This does not mean that it is also ecient: as the basic method is not goaloriented , it is possible that lots of irrelevant facts are computed. On the other hand, each fact is only computed once. Several improved query answering methods have been introduced, aiming on the one hand at a goal-oriented search for answers as in SLD-resolution, on the other hand at good termination properties and eciency in general. We can divide these methods in two groups. One idea is to perform a bottomup computation, but on a transformed program [1]. The transformation depends on the query and introduces goal-orientedness. One such method is known as \Magic Templates" [16]. The other idea is to add so-called tabulation [20] (memo-ing [6], lemma resolution [21]) to SLD-resolution. In its simplest form, this involves storing intermediate results (lemmas) in a table, and looking up these tabled results instead of recomputing them. In this way, both the termination properties (the method is terminating for all deductive databases) and the general eciency (avoiding recomputation of results) of SLD-resolution can be improved considerably. Bottom-up computation on a transformed program is conceptually diverging from SLD-resolution, while tabulation is not. Also, the transformed program introduces its own search space with new relations, thus hiding the search space of the original program. However, it is shown in [2, 18] that the two methods perform essentially the same computation (modulo some small details, which we will see later): both methods are \equally" goal-oriented. A disadvantage common to both methods is that their current formulation does not separate the search space from the search strategy. Certainly, constructions have been de ned that \look like" a search space, especially for tabulation methods, but a closer inspection shows that these \search spaces" depend on the search strategy; thus there is no real separation between them. The main aim of this paper is to present a framework for tabulated SLDresolution that (re)introduces the separation between search space and search . Our framework will clarify the relation between tabulated top-down computation and \magic" bottom-up computation. Moreover, it will facilitate the analysis of their behavior, in particular the prediction and explanation of their incompletenesses, if any. The plan of this paper is as follows. In Section 2 we give the traditional presentation of OLDT-resolution [20], a speci c variant of tabulated SLDresolution. In Section 3, we present the Magic Templates transformation and the related bottom-up computation. We also give an alternative characterization of the resulting computation by what we call deduction sets : a set of statements is expanded until it includes the (atomic) query. These statements are all consequences of the program and relevant to the query, but they are clauses, not just facts. In Section 4.1, deduction sets serve as the starting point for an infor-

mal presentation of our formalism: by adding some structure on top of the clauses, we obtain a search forest . In Section 4.2 we give a formal, declarative de nition of the search forest. A search forest contains all answers produced by ordinary SLD-resolution, which implies its completeness. Search forests are also sound, and nite for function-free programs. Section 5 is devoted to a study of various search strategies within our framework. We de ne a search sequence as a sequence of partial search forests in which each forest contains the previous ones and is contained in the complete forest. One can say that a search strategy is complete (for a particular case) if the \limit" of the corresponding search sequence is the complete forest. In Section 6, we show how OLDT-resolution can be seen as a partial description of a search strategy (or, equivalently, as a family of search strategies) for the search forest. This also shows that the search sequences of our framework allow ner distinctions between di erent implementations than construction sequences of OLDT-trees. All proofs can be found in the full version of the paper [?]. Without loss of generality, we shall assume throughout the paper that the initial query is atomic.

2 Tabulation { traditional presentation The main idea of OLDT-resolution [20] is to build a table during the search of an OLD-tree (i.e., an SLD-tree constructed using the leftmost computation rule). In the table we store answers obtained for subgoals. These answers are to be used later, where ordinary OLD-resolution would recompute that subgoal. Thus, the table consists of entries for atoms, with the answers so far computed in the OLD-tree. We add answers to these entries whenever we nd a (sub)refutation of an atom in the tree. Thus it is important that, when an atom is selected in a goal, it is resolved completely before any other atom is selected, in order to avoid \mixing" the answers for the two atoms. In other words, the computation rule must be local [21]. The leftmost computation rule satis es this property. OLDT-resolution formalizes this idea in the following way1. An OLDTstructure is a triple consisting of an OLDT-tree, a solution table, and a lookup table. In the OLDT-tree, every node is labeled as either a solution node, meaning that the selected atom in the node will serve as the producer of solutions, or as a lookup node, meaning that the selected atom will be solved elsewhere, and that answers for it will be imported (looked up). Answers are computed only once: if an atom B is selected in a solution node G, then 1 Actually, this presentation is somewhat simpli ed. For example, one may choose to

store and use lemmas only for certain predicates, while others are treated as in ordinary SLD-resolution. Also, in some situations, the system may try to prove a lemma that is strictly more general than any of the occurring subgoals (term-depth abstraction or subgoal generalization).

every node G0 in which a variant of B is selected, must be a lookup node that receives its answers from G. The information contained in the tables is in fact redundant, and will not be discussed here. De nition 2.1 [OLDT-tree]. Let P be a program and A an atomic query. The initial OLDT-tree for P and A, T0, consists of the singleton tree with a solution node A. From an OLDT-tree Ti , we can obtain a new OLDT-tree Ti+1 as an immediate extension of Ti, by either using all applicable program clauses to add children to a leaf labeled as a solution node in Ti, or by using an answer from a solution node to add a new child to a corresponding lookup node (internal or leaf). In both cases, the new node(s) are labeled as solution node or lookup node|solution node if a variant of its selected atom has not been selected before somewhere in T , lookup node otherwise. An OLDT-tree is maximal if it has no immediate extensions. The sequence T0; T1; T2; : : : is called a construction sequence if it is in nite or ends in a maximal OLDT-tree. Example 2.1 Let P1 be the program p(X)