Re: equivalentClass
- From: Chip Eastham <hardmath@xxxxxxxxx>
- Date: Fri, 23 Nov 2007 09:53:08 -0800 (PST)
On Nov 23, 9:17 am, a...@xxxxxx wrote:
On 23 ÎÏÑÂ, 07:59, Chip Eastham <hardm...@xxxxxxxxx> wrote:
simple(a,b).
simple(b,c).
simple(b,d).
simple(d,e).
If you can provide bound values for the first and
second arguments, a transitive closure can be coded
as:
tc(A,B) :- tClosure([A],B).
tClosure([A|_],A).
tClosure([H|T],B) :-
(simple(H,X);simple(X,H)),
not(member(X,[H|T])),
tClosure([X,H|T],B).
Thank you for answer. The idea is clear, however, the rule tClosure([A|
_],A). doesn't lead to variable unification...
I think what you're saying is that you get no satisfactory
results from calling tc(A,B) with both arguments unbound.
You can try calling tc(A,B) with just the first argument
bound, e.g. preceding the call to tc/2 with a generator
of arguments like member(A,[a,b,c,d,e]).
The particular example you gave had directed edges that
formed a strict hierarchy. In such a case the directed
paths cannot form loops, and the code accordingly can
prevent looping in a simpler way. But I gave the more
general solution because it seemed that may be your
question.
regards, chip
.
- References:
- equivalentClass
- From: alp
- Re: equivalentClass
- From: Chip Eastham
- Re: equivalentClass
- From: alp
- equivalentClass
- Prev by Date: Re: equivalentClass
- Next by Date: Re: Issues with Best-first Search on Bratko's book
- Previous by thread: Re: equivalentClass
- Next by thread: Issues with Best-first Search on Bratko's book
- Index(es):