next up previous contents index
Next: 5.2.4 Potential Pitfalls in Up: 5.2.3 Interaction Between Prolog Previous: 5.2.3.0.1 Cuts and Tabling   Contents   Index


5.2.3.0.2 Subsumption-Based Tabling and Meta-Logical Predicates

Meta-logical predicates like var/1 can be used to alter the choices made during an evaluation. However, this is dangerous when used in conjunction with a paradigm that assumes that if a specific relation holds -- e.g., p(a) -- then a more general query -- e.g., p(X) -- will reveal this fact.

Example 5.2.4   Consider the following simple program
        p(X) :- var(X), X = a.
to which the queries
        ?- p(X).
        ?- p(a).
are posed. Let us compare the outcome of these queries when p/1 is (1) a Prolog predicate, (2) a variant-tabled predicate, and (3) a subsumptive-tabled predicate.

Both Prolog and variant-based tabling yield the same solutions: X = a and no, respectively. Under subsumption-based tabling, the query ?-$\;$p(X). likewise results in the solution X = a. However, the query ?-$\;$p(a). is subsumed by the tabled subgoal p(X) -- which was entered into the table when that query was issued -- resulting in the incorrect answer yes.$\Box$

As this example shows, incorrect answers can result from using meta-logical with subsumptive predicates in this way.


next up previous contents index
Next: 5.2.4 Potential Pitfalls in Up: 5.2.3 Interaction Between Prolog Previous: 5.2.3.0.1 Cuts and Tabling   Contents   Index
Terrance Swift 2007-10-05