Chris Pollett >
Students > [Bio] [Del1] [Del2] |
Harini's Tabling Demo/* File: Superior.P ** Author: Harini Rao ** ** Tabling is one of the two ways of evaluating predicates in XSB. In tabling, the implementation keeps track of all calls to tabled predicates, or tabled subgoals. Whenever a new tabled subgoal is called, a check is first made to see whether it is in the table. If so, the subgoal is resolved against answers in the table; ** ** If not, it is entered into the table and resolved against program clauses. When an answer to a tabled subgoal is derived, a check is made against the table for to see if the answer is there. If the answer is not in the table, the answer is added and scheduled to be returned to all instances where has been called; ** ** If the answer is already in the table, the evaluation simply fails and backtracks to generate more answers. ** */ :- table superior/2. superior(X,Y) :- supervise(X,Y). superior(X,Y) :- supervise(X,Z), superior(Z,Y). supervise(jennifer,ahmad). supervise(james,jennifer). supervise(franklin,john). supervise(franklin,ramesh). supervise(franklin,joyce). supervise(jennifer,alicia). supervise(james,jennifer). supervise(james,franklin). |