Search code examples
prolog

Defining facts within prolog rules


I am trying to translate the following statement into prolog:

"For all X, if X has a child who has a sister then X has two children."

I have defined the following rule:

has_two_children(X) :-
    parent(X,Y),
    sister(Y,_Z).

when I run it, I get:

"procedure `sister(A,B)' does not exist
 Reachable from:
      has_two_children(A)"

I have defined a parent relation separately, but I have not defined a sister relation separately. But this is puzzling to me. I was expecting it to just say false. What if no one i'm interested in has a sister? In that case, there's nothing I can put for the sister relation. Must I define the sister relation outside the rule?


Solution

  • What if no one i'm interested in has a sister? In that case, there's nothing I can put for the sister relation.

    You can put:

    sister(_, _) :- false.