1
votes

So I have just started programming in PROLOG (SWI distribution). I have good logic bases and I am familiar with facts, rules, quantification and all that vocabulary.

As far as I know, you can define a fact such as:

married(a,b).

And I know that if you make a query like:

?: married(X,b).

The answer will be "a". My question is, if I wanted to make a rule that used the fact previously declared, it will consider that "a is married to b", but will it consider that "b is married to a" or do I have to declare another fact like:

married(b,a).

for it to work? Same for any kind of bilateral relationship that can be represented as a fact.

1
What is cuantificators?Guy Coder
Maybe I wrote it wrong (sorry for my english!). I mean predicate logic "cuantificators?" such as Exists(X) or ForAll(X).Julian Garcia
No need to apologize for your English. I am sure I don't know your language. Is quantification the correct word?Guy Coder
Yes, that's it. Thank you.Julian Garcia

1 Answers

5
votes

Do you mean if the relation is automatically symmetric? Then no - suppose you have a directed graph with edge(a,b), then you would not want the other direction edge(b,a) to be inferred. Also, what about relations of arity greater than 2?

You can always create the symmetric closure of a predicate as:

r_sym(X,Y) :-
  r(X,Y).
r_sym(X,Y) :-
  r(Y,X).

Using a new predicate name prevents infinite derivation chains r(X,Y) -> r(Y,X) -> r(X,Y) -> .....