1

I got the following promblem:
the following facts and predicates are defined:

father(avr, yit).
male(avr).
married(avr, sara).
father(yit, yaak).
married(rivka, yit).
father(yaak, yosef).
mother(rachel, yosef).
father(yaak, levi).
mother(leaa, levi).
mother(zilpa, gad).
father(yaak, dan).
mother(bilhaa, dan).
father(yosef, menashe).
father(yosef, ephraim).

are_married(X,Y) :- married(X,Y).
are_married(X,Y) :- married(Y,X).

I defined the following predicates:

married(X,Y) :- mother(X,Z) , father(Y,Z).
mother(X) :- are_married(X,Y) , father(Y,_).

now, the promblem is that mother is defined by marriage, and marriage is defined by being a mother - the result is an infinite loop, and the program crashes.
how can I prevent the infinite loop? is there a way to tell a predicate not to use a different predicate?

elyashiv
  • 3,623
  • 2
  • 29
  • 52
  • No, just use different name. This was recently asked and answered, just [browse here](http://stackoverflow.com/questions/tagged/prolog) through some recent questions, and [here](http://stackoverflow.com/tags/prolog/new) through answers. – Will Ness May 02 '13 at 09:05
  • possible duplicate of [left\_of exercise from The Art Of Prolog](http://stackoverflow.com/questions/16325238/left-of-exercise-from-the-art-of-prolog) – Will Ness May 02 '13 at 09:05

1 Answers1

1

Why do you need to re-write mother ?

Just skip the

mother(X) :- are_married(X,Y) , father(Y,_).

Because you already have a (Data Definition) as mother.