Definite programs, also called Horn Clause Programs, are Prolog
programs without negation or aggregation. In XSB, this means without
the \+/1, fail_if/1, not/1, tnot/1 or aggregation
operators. Consider the Prolog program
path(X,Y) :- path(X,Z), edge(Z,Y). path(X,Y) :- edge(X,Y). |
A number of approaches have been developed to address this problem by
reusing partial answers to the query path(1,Y)
[24,56,4,58,59]. The ideas behind these
algorithms can be described in the following manner. Calls to tabled
predicates, such as path(1,Y) in the above example, are stored
in a searchable structure together with their proven instances. This
collection of tabled subgoals paired with their answers,
generally referred to as a table, is consulted whenever a new
call,
, to a tabled predicate is issued. If
is sufficiently
similar to a tabled subgoal
, then the set of answers,
,
associated with
may be used to satisfy
.
In such instances,
is resolved against the answers in
, and
hence we refer to
as a consumer of
(or
). If there is no such
, then
is entered into
the table and is resolved against program clauses as in
Prolog -- i.e., using SLD resolution. As each answer is derived
during this process, it is inserted into the table entry associated
with
if it contains information not already in
. We hence
refer to
as a generator, or
producer, as resolution of
in this manner produces the answers stored in its table entry. If
the answer is in fact added to this set, then it is additionally
scheduled to be returned to all consumers of
. If instead it is
rejected as redundant, then the evaluation simply fails and backtracks
to generate more answers.
Notice that since consuming subgoals resolve against unique answers rather than repeatedly against program clauses, tabling will terminate whenever
Predicates can be declared tabled in a variety of ways. A common form
is the compiler directive