transitive closure


csaba1 (csaba1@umbc.edu)
Wed, 5 Mar 2003 10:08:35 -0500


Hi,

The transitive closure has to be modified to work for the ancestor
relationship
the following way:

closure(R)(X,Y) :- R(X,Y).
closure(R)(X,Y) :- R(Z,Y),closure(R)(X,Z).

this will translate to
ancestor(X,Y) :- parent(X,Y). (if X is parent of Y, X is Y's ancestor)
ancestor(X,Y) :- parent(Z,Y),ancestor(X,Z). (find Y's parent first, then check
if X is the ancestor of Y's parent)

I really don't know why the original definition does not work. Any ideas?
(I always thought this "fixed" version was more intutitive anyways)

BTW. I am not getting any e-mails sent to the class mailing list (I read the
question on the website). Anybody else has this problem?

Csaba



This archive was generated by hypermail 2.0b3 on Wed Mar 05 2003 - 10:11:36 EST