From: Edward S. <esc...@ce...> - 2016-02-16 16:43:15
|
Hi all, I am experiencing some strange behavior when I combine tabling and dif/2. Here's a very simple prolog program for computing transitivity: % 1, 2 and 3 are on the same class. same(1, 2). same(1, 3). % 4, 5, and 6 are the same class. same(4, 5). same(4, 6). :- table ruleSame/2. % Root from real facts. ruleSame(X, Y) :- same(X, Y). % Commutative. ruleSame(X, Y) :- dif(X, Y), ruleSame(Y, X). % Transitive. ruleSame(X, Y) :- dif(X, Y), dif(Y, Z), dif(X, Z), ruleSame(X, Z), ruleSame(Z, Y). Basic facts are ok: ?- ruleSame(1,2). yes ?- ruleSame(1,3). yes ?- ruleSame(2,3). yes But then some unexpected facts are generated... ?- ruleSame(2,4). yes If I debug the evaluation of these facts, I get an extremely long trace. If I move the dif sub-goals after the ruleSame sub-goals, the program works as expected. Is this a bug? I think it is, but hopefully I haven't overlooked something. It seems like maybe the deferred goals from dif/2 are interacting with tabling in a non-trivial way. I tested this both on YAP 6.2.2 and the current development git branch of 6.3. Both had the same behavior. Thanks for any help, Ed |