Re: mutual rules: if brother(a,b) then brother(b,a)
From: Bart Demoen (bmd_at_cs.kuleuven.ac.be)
Date: 05/21/04
- Next message: Andrey Rybalchenko: "Print depth (or width?)"
- Previous message: RMM: "Re: mutual rules: if brother(a,b) then brother(b,a)"
- In reply to: RMM: "Re: mutual rules: if brother(a,b) then brother(b,a)"
- Next in thread: RMM: "Re: mutual rules: if brother(a,b) then brother(b,a)"
- Reply: RMM: "Re: mutual rules: if brother(a,b) then brother(b,a)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 21 May 2004 13:31:26 +0200
RMM wrote:
> Two points:
>
> Firstly is the relation symmetric or commutative?
symmetric (I used the word commutative in an earlier post in this
tread - that was wrong as other people pointed out)
>
> To stop infinite looping in search, keep a list of the instantiations
> and guard the above expression as:
>
> brother(X,Y):-
> var(X), % if X is a variable we are doing a search
> brother(Y,X), % is there a solution
> test(brother(Y,X)),!,fail. % we've seen it before so abandon
> brother(X,Y):-brother(Y,X).
>
> when you use the search version of brother/2 e.g. brother(X,fred) make
> sure you assert the solution into the database by writing:
>
> brother(X,Y),assertz(test(brother(X,Y)),...
>
> don't forget to declare
> :-dynamic test/1.
>
> if you might search on Y e.g. brother(fred,Y) then you will need to
> add another suitable clause.
It is not clear to me what you mean: if I add two facts to the clauses
above,
brother(fred,jan).
brother(jan,fons).
and ask the query
?- brother(X,fred),assertz(test(brother(X,fred)).
I get an infinite loop.
Similar for queries like ?- brother(mary, ann).
Could you please elaborate ? Thanks.
Cheers
Bart Demoen
- Next message: Andrey Rybalchenko: "Print depth (or width?)"
- Previous message: RMM: "Re: mutual rules: if brother(a,b) then brother(b,a)"
- In reply to: RMM: "Re: mutual rules: if brother(a,b) then brother(b,a)"
- Next in thread: RMM: "Re: mutual rules: if brother(a,b) then brother(b,a)"
- Reply: RMM: "Re: mutual rules: if brother(a,b) then brother(b,a)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]