I don't understand how to remove the infinite loop.When trying to find ancestors.
spouse(george,mel).
spouse(mel,george).
parent(george,elizabeth).
parent(george,margaret).
spouse(elizabeth,philip).
spouse(philip,elizabeth).
parent(elizabeth,charles).
parent(spencer,diana).
spouse(diana,charles).
spouse(charles,diana).
parent(X,Y):-spouse(X,Z),parent(Z,Y).
ancestor(X,Y):-parent(X,Y).
ancestor(X,Y):-parent(X,Z),ancestor(Z,Y).
Prolog seems to go in an infinite loop due to the first rule. I would really like to avoid hardcoding the facts like I had to for spouse(reflexive relation). But I can't seem to figure out how this problem is similar to other problems regarding transitive relations.