I am trying to create a knowledge base. My problem has terminal/1
and connected/2
and I have defined the following rule:
connected(X,Y) :- connected(Y,X).
For reasons I now understand (I think), this went into an infinite recursion.
Then, I tried search SO and found this question: Alternative to express "Commutativity" in Prolog? . Based on the answers provided, I tried to change my above fact to the following:
connected(X, Y) :- is_connected(Y, X) /\ is_connected(X, Y).
is_connected(X, Y) :- terminal(X) /\ terminal(Y) /\ connected(X , Y).
However, this doesn't give me the results I was hoping for. If I define a rule connected(t1,t7)
, I am hoping to get yes
if I ask the question connected(t7,t1)
.