Information System Vol. 17,No.1,pp. 17-31, 1992 Printed in Great Britain. 0306-4379/92 S5.00 + 0.00 Pergamon Press plc SAFE COMPUTATION OF THE WELL-FOUNDED SEMANTICS OF DATALOG QUERIES N. LEONE? and P. RULLO CRAI, 87036 Rende, Italy zyxwvutsrqponmlkjihgfedcbaZYXWVUTS (Received 3 April 1991; in revised form 18 October 1991) Abstract-A Datalog program (abbreviated to “program” hereafter) is a set of function-free logic rules allowing negation in their bodies. It is customary to see a program as composed of two parts: a set of rules (the Intentional Database, IDB for short) and a set of facts stored as tuples of a relational database (the Extentional Database, EDB for short). The well-founded semantics assigns to every program a (possibly partial) model to be thought of as the meaning of the program. Although the well-founded computation is effective for (function-free) programs, it is worth noting that the construction of the greatest unfounded set results in a very demanding task when large EDBs are considered (data-intensive applications). In this paper we describe a method for the evaluation of the well-founded semantics of Datalog queries that allows us to construct answers without having to compute the whole greatest unfounded set. The key idea is that of restricting the computation of false facts to only those that are “relevant” to draw positive conclusions. We call this set of facts the Greatest Useful Unfounded Set (GUUS), from which the choice of the name GUUS merhod. The method is shown to be sound and complete w.r.t. any Datalog query. A main advantage of the proposed approach is that of resulting efficiently implementable for a meaningful class of programs. The syntactic structure of such programs guarantees that the greatest useful unfounded set can be safely (and efficiently) computed as the least fixpoint of the immediate consequence operator applied to a suitable rewritten program. Key words: Deductive databases, negation, well-founded semantics, query evaluation 1. INTRODUCTION Much recent work has concentrated on the definition of the well-founded semantics of logic programs [l-3]. The reason for that is the observation that there are useful and interesting logic programs that are not zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA stratiJied [4] (or even not 1ocaZly stratified [5,6]) for which a clear and unambiguous semantics exists. The most famous example is given by the win program [7] m (4 b) w(X) + m(X Y), lW(Y) describing a game where one wins if the opponent has no moves. It is easy to verify that the program is not locally stratified; however, it has a clear intended semantics (the winner is obviously a). This example shows the need of investigating ways to define a declarative (and possibly procedural) semantics of programs containing recursive negation, thus going beyond the simple class of stratified programs. The well-founded semantics of logic programs has been first defined in [l]. Here, the basic notion is that of unfounded set and the well-founded model is defined as the limit of a sequence involving unfounded sets. Every program has a (possibly partial) well-founded model. In particular, every locally stratified program has a total well-founded model coinciding with its perfect model [6]. Also weakly strutzjied programs [2] are characterized by a total well-founded semantics. In [8] it is shown that the well-founded semantics is equivalent to suitable forms (3-valued) of the four major non-monotonic formalisms (Circumscription, Closed World Assumption, Autoepistemic Logic and Default Logic). The computation of the well-founded semantics can be efficiently performed for stratified programs, where the immediate consequence operator only is needed. For a subclass of weakly ~To whom correpondence should be addressed 17