users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: General question about better documentation and specific question


From: Violetta Cavalli-Sforza
Subject: Re: General question about better documentation and specific question
Date: Sat, 1 Dec 2001 19:05:56 -0800 (PST)

Thank you. One more question and then I'll stop asking for a while.
I have the following database of facts and rules. 

/* rules */
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).

sibling(X,Y) :- mother(M,X), mother(M,Y),
                father(F,X), father(F,Y),
                X \= Y. 

cousin(X,Y) :- parent(U,X), parent(V,Y), sibling(U,V).

not(P) :- P, !, fail ; true.

can_marry(X,Y) :- X \= Y, not(sibling(X,Y)), not(cousin(X,Y)).


/* facts */
father(albert,jeffrey).
father(albert,george).
father(john,mary).
father(john,tina).
father(george,cindy).
father(george,victor).
father(jeffrey,ann). 
mother(alice,jeffrey).
mother(alice,george).
mother(sue,mary).
mother(sue,tina).
mother(mary,cindy).
mother(mary,victor).
mother(pam,ann). 

I can use the rule can_marry to get yes/no answers if I specify the
arguments to the predicate to be specific atoms, but I just get a "no"
answer if I leave one or both arguments as variables.  
>From tracing, I suspect it has to do with binding X and Y with the 
\= in the first conjunct of the body, and also with the not predicate I'm
defining (though this definition comes straight out of Clocksin and
Mellish).  Tracing shows that effectively no variable bindings really get
made.  See the trace below.  
Any comments as to why?  Any suggestions on how to get this rule working
for variables?

Thanks again.  
Violetta


========================

Trace:

can_marry(X,Y) :- X \= Y, not(sibling(X,Y)), not(cousin(X,Y)).

/*
{trace}
| ?- can_marry(X,Y).
      1    1  Call: can_marry(_15,_16) ?
      2    2  Call: _15\=_16 ?
      3    3  Call: _15=_16 ?
      3    3  Exit: _15=_15 ?
      2    2  Fail: _15\=_16 ?
      1    1  Fail: can_marry(_15,_16) ?
*/

========================
Changing the position of the X \= Y in the rule doesn't fare
much better

can_marry(X,Y) :- not(sibling(X,Y)), X \= Y, not(cousin(X,Y)).

/*
{trace}
| ?- can_marry(X,Y).
      1    1  Call: can_marry(_15,_16) ?
      2    2  Call: not(sibling(_15,_16)) ?
      3    3  Call: '$call'(sibling(_15,_16),not,1,true) ?
      4    4  Call: sibling(_15,_16) ?
      5    5  Call: mother(_167,_15) ?
      5    5  Exit: mother(alice,jeffrey) ?
      6    5  Call: mother(alice,_16) ?
      6    5  Exit: mother(alice,jeffrey) ?
      7    5  Call: father(_217,jeffrey) ?
      7    5  Exit: father(albert,jeffrey) ?
      8    5  Call: father(albert,jeffrey) ?
      8    5  Exit: father(albert,jeffrey) ?
      9    5  Call: jeffrey\=jeffrey ?
     10    6  Call: jeffrey=jeffrey ?
     10    6  Exit: jeffrey=jeffrey ?


On Sun, 2 Dec 2001, Salvador Abreu wrote:

> > /afs/sfsu.edu/f1/vcs/Prolog/family.pg:20 warning: discontiguous predicate
> > father/2 - clause ignored
>       [...]
> 
> > When I rearrange the facts so that all the father facts are contiguous > 
> > and all the mother facts are continguous, i.e.,
>       [...]
> > there is no problem.  Why is it doing this?
> 
> I'd say it's got to do with the compiler nature of gprolog: a set of
> clauses for the same predicate is viewed as a "procedure", which must be
> defined in one block.
> 
> This can be worked around by declaring the predicate as discontiguous,
> in this case its clauses would have to be preceded by the directive:
> 
> :- discontiguous([father/2, mother/2]).
> 
> This is an ISO Prolog feature, so it's not specific to GNU Prolog.  I
> guess most books predate the standard, so they may suggest different
> approaches.
> 
> Check the gprolog manual, around page 44 (chapter on Directives...)
> 
> > In general, can someone point me to a better source of information
> > than the manual that is available from the web page for information
> > about how to use this environment, syntax expected, and a richer
> > set of examples?  
> 
> Shapiro and Sterling's "The Art of Prolog" is a very good book, if a
> little old.
> 
> IIRC the programming examples are fairly close to what you'll have to do
> using GNU Prolog.
> 
> Best,
> Salvador
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]