Linear tabling and the strategies

B-Prolog employs a tabling mechanism, called linear tabling [21], which relies on iterative computation rather than suspension to compute fixpoints. In linear tabling, a cluster of inter-dependent subgoals as represented by a top-most looping subgoal is iteratively evaluated until no subgoal in it can produce any new answers.

B-Prolog supports two answer consumption strategies: lazy and eager. The lazy strategy allows a cluster of subgoals to return answers only after the fixpoint has been reached, and the eager strategy consumes answers while they are produced.

The lazy consumption strategy is suited for finding all answers because of the locality of search. So, for example, when the subgoal p(Y) is encountered in the goal ``p(X),p(Y)'', the subtree for p(X) must have been explored completely. For certain applications such as planning it is unreasonable to find all answers either because the set is infinite or because only one answer is needed. For example, for the goal ``p(X),!,q(X)'' the lazy strategy produces all the answers for p(X) even though only one is needed.

The lazy strategy is adopted by default, but you can change the strategy to eager for a predicate or for all the predicates in a program. The declaration

      :-eager_consume P/N.
changes the strategy to eager for P/N and the declaration
      :-eager_consume.
changes the strategy to eager for all the predicates in the program.



Subsections
Neng-Fa Zhou 2011-05-12