I have the following facts in the knowledge base:
line(a,b). -- denotes the line determined by point a and b
line(c,d). -- denotes the line determined by point c and d
lineEqual(line(a,b),line(c,d)) -- denotes the length of two lines are equal
I want to have another rule that can swap around the two arguments of lineEqual/2:
lineEqual(line(C, D), line(A, B)):-
lineEqual(line(A,B),line(C,D)).
Unfortunately the rule will create an infinity loop in Prolog. Any other idea?
Thanks for the update. Not sure if I understood your last rule:
transitiveSymmetricRelPath(L1, L2, IntermediateNodes) :- symmetricRel(L1, L3),
\+member(L3, IntermediateNodes),
transitiveSymmetricRelPath(L1, L2, [L3 | IntermediateNodes]).
I can imagine every time it tries to strip off the head node if it happens to be linked with both L1 and L3, right? So if we end up with an empty list then we can use this rule:
transitiveSymmetricRel(L1, L2) :- transitiveSymmetricRelPath(L1, L2, []).
But the bit I am not really getting is where do you get an nonempty list of intermediate nodes of transitiveSymmetricRelPath/3 to start with. I've actually tried your code with the given fact rel(a,b). rel(a,c). and it does not return transitiveSymmetricRel(b,c), neither does it return transitiveSymmetricRel(c,b). Could you please have a look into it?
Thanks a lot!
Edited: I've got it working by modifying your rule like:
transitiveSymmetricRelPath(L2, L3, IntermediateNodes) :- symmetricRel(L1, L3),
\+member(L3, IntermediateNodes),
transitiveSymmetricRelPath(L1, L2, [L3 | IntermediateNodes]).
Thanks for your suggestion anyway.