1
votes

I am trying to get a simple family tree to work with Prolog using a maximum of 3 facts being allowed, however I can't seem to be able to define my sister as the child of my parents. Here is what I've wrote:

father(dad,me).
mother(mom,me).
siblings(me,sis).

parents(X,Z):-father(X,Z).
parents(Y,Z):-mother(Y,Z).
child(Z,X):-siblings(Z,Z2),parents(X,Z).
child(Z,Y):-siblings(Z,Z2),parents(Y,Z).
child(Z2,X):-siblings(Z,Z2),parents(X,Z).
child(Z2,Y):-siblings(Z,Z2),parents(Y,Z).
son(Z,X):-siblings(Z,Z2),parents(X,Z).
daughter(Z2,X):-siblings(Z,Z2),parents(X,Z).
brother(Z,Z2):-siblings(Z,Z2).
sister(Z2,Z):-siblings(Z,Z2).

and when I type in father(ZFather,ZChild) in Prolog, it only shows me as the child and not my sis. I know I haven't defined it in facts, but I tried to do so in rules with child(Z2,X) and child(Z2,Y) meaning that Z2 is my sis.

Helps will be appreciated.

1

1 Answers

2
votes

Your predicate father/2 only describes one solution. If you want it to describe more but do not want to add further facts, you could add a rule for father:

father(F,C) :-
   dif(X,C),
   siblings(X,C),
   father(F,X).

If you query the predicate now:

   ?- father(X,Y).
X = dad,
Y = me ? ;
X = dad,
Y = sis ? ;
no

However, logically speaking, this is not a very clean way to do it. After all it is possible that siblings only share the same mother (or in general: just one parent). It would be better to not restrict yourself to only 3 facts.