The problem with the family(X,Y) :- family(Y,X).
lies in the fact that it unconditionally unites with itself at each level and continues recursively; there is no exit condition from this recursion.
You must swap the argument at a higher level:
family(X,Y) :- is_family(X,Y); is_family(Y,X). is_family(X,Y) :- married(X,Y); relative(X,Y); father_son(X,Y).
Alternatively, you can make the basic rules below symmetrical, where that makes sense:
is_married(X,Y) :- married(X,Y); married(Y,X). is_relative(X,Y) :- relative(X,Y); relative(Y,X).
Now you can rewrite the family
rule as follows:
family(X,Y) :- is_married(X,Y); is_relative(X,Y); father_son(X,Y); father_son(Y,X).
source share