1
votes

I am trying to establish a relationship model in Prolog but the sister relationship turns out to be a fail. I am wondering what a good solution would be to this. I am a beginner and this is my first programme, any help is welcome.

man(adam).
man(peter).
man(paul).
man(carlos).
man(willem).

woman(marry).
woman(eve).
woman(greta).
woman(lisa).

parent(adam, peter). 
parent(eve, peter).
parent(adam, paul).
parent(marry, paul).
parent(adam, willem).
parent(adam, lisa).
parent(eve, willem).
parent(eve, lisa).
parent(greta, adam).
parent(carlos, adam).

father(F, C) :-
   man(F),
   parent(F, C).

mother(M,C) :-
   woman(M),
   parent(M, C).

grandparent(P, C):-
   parent(P, K),
   parent(K, C).

sister(x,y) :-
   woman(x),
   mother(m, x),
   father(f, x),
   mother(m, y),
   father(f, y).
1
yes, it was. quite a cool language!Jorne De Blaere
Yes it is :p pattern-matching is the coolest assignment I've had in prolog (for example: solve sudokus). Also, add the "homework" tagkeyser

1 Answers

3
votes

You need to use upper case letters for the variables in your sister\2 predicate. In your code you have lower case letters, which are atoms, so this will always fail unless you have people called x,y,f and m.

Also, add X \= Y to prevent X being her own sister.