Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top