0

I am new to prolog and would like to have some advice.

I have some facts:

male(tom).
male(james).
male(john).
female(elly).
female(joanne).
female(evonne).
brother(john,tom).
brother(john,joanne).
sister(elly,joanne).
parent_of(evonne,john).
parent_of(james,john).

Is is possible to define a parent_of rule without using sister and brother?

Daniel Lyons
  • 22,421
  • 2
  • 50
  • 77
user1771844
  • 43
  • 1
  • 9
  • 1
    possible duplicate of [Prolog Parent relation using only brother and sister rules](http://stackoverflow.com/questions/15714834/prolog-parent-relation-using-only-brother-and-sister-rules) – Daniel Lyons Apr 05 '13 at 16:56
  • that one is use sister and brother to define parent of i dont want that – user1771844 Apr 06 '13 at 05:36

1 Answers1

0

at first you should have some parent_of facts as the core of parental relation. then you can expand this relation by attaching someone to a one of the facts as a child or as a parent. so you need to use a siblings/2 rule if you want to attach a child, or a couples/2 rule if you want to attach a parent.

%if you want to attach a child by 'siblings' relation
parent_of_rule(X, Y) :-
        parent_of(X, Z),
        siblings(Z, Y).
%if you want to attach a parrent by 'couples' relation
parent_of_rule(X, Y) :-
        parent_of(Z, Y),
        couples(X, Z).

i don't think it's possible to have a parent_of_rule rule without the use of a third party relation.

VahidM
  • 287
  • 1
  • 2
  • 14
  • i have define the rules of siblings ,spouse, son, daughter,father and mother. However i encounter a infinite loop between them. I will go try this and see. – user1771844 Apr 06 '13 at 07:40
  • you're right. easily you can change the name of the rule to allow transitivity and avoid infinite loop. you can also use a cut. – VahidM Apr 06 '13 at 17:18