|Did you know ...||Search Documentation:|
|Tabled execution (SLG resolution)|
This chapter describes SWI-Prolog's support for Tabled execution for one or more Prolog predicates, also called SLG resolution. Tabling a predicate provides two properties:
Tabling is particularly suited to simplify inference over a highly entangled set of predicates that express axioms and rules in a static (not changing) world. When using SLD resolution for such problems, it is hard to ensure termination and avoid frequent recomputation of intermediate results. A solution is to use Datalog style bottom-up evaluation, i.e., applying rules on the axioms and derived facts until a fixed point is reached. However, bottom-up evaluation typically derives many facts that are never used. Tabling provides a goal oriented resolution strategy for such problems and is enabled simply by adding a table/1 directive to the program.
The Fibonacci sample code is not correct, since the most general query
?- fib(X, Y). incorrectly succeeds with only a single solution, although there are infinitely many which are produced when using the predicate in different modes.
One correct solution is to throw instantiation errors if the query is more general than those that the system can handle correctly.