DCstar
DCstar

Reputation: 13

Asymmetric binary relations, my code is not working good

This is my code:

binary_relations(x,y) .
binary_relations(y,z) .

asymmetric :-
  not(symmetric) .

symmetric :-
  binary_relations(X,Y) ,
  binary_relations(Y,X) .

Everything is true and program is working in good way, but if I write:

binary_relations(x,y).
binary_relations(y,y).
binary_relations(y,z).

Program is false.

What I need to do is asymmetric binary relations as you can see. Anybody help? How can I figure out this situation?

For start you have to write: asymmetric.

Upvotes: 0

Views: 202

Answers (1)

Tudor Berariu
Tudor Berariu

Reputation: 4910

Consider the following knowledge base that explicitly describes three binary relations r1/2, r2/2 and r3/3.

r1(a,a).
r1(a,b).
r1(b,a).
r1(a,c).
r1(c,a).

r2(a,b).
r2(a,c).

r3(a,a).
r3(b,a).
r3(a,c).

It is obvious to see that r1/2 is symmetric, r2/2 and r3/2 are both antisymmetric and r2/2 is the only asymmetric of the three.

Let's try to express that in natural language and then using logic. A relation R is symmetric if two objects X,Y such that R(X,Y) is true, but R(Y,X) is false do not exist.

symmetric(R):-
    \+ (call(R, X, Y), \+ call(R, Y, X)).

A relation R is asymmetric if there are no two objects (not necessarily distinct) such that both R(X,Y) and R(Y,X) are true.

asymmetric(R):-
    \+ (call(R, X, Y), call(R, Y, X)).

And third, a relation R is antisymmetric if both R(X,Y) and R(Y,X) being true implies that X and Y are the same entity (in other words: there are no two distinct objects X, Y such that both R(X,Y) and R(Y,X) are true).

antisymmetric(R):-
    \+ (call(R, X, Y), call(R, Y, X), Y \== X).

And some queries:

?- symmetric(r1).
true.

?- symmetric(r2).
false.

?- symmetric(r3).
false.

?- asymmetric(r1).
false.

?- asymmetric(r2).
true.

?- asymmetric(r3).
false.

?- antisymmetric(r1).
false.

?- antisymmetric(r2).
true.

?- antisymmetric(r3).
true.

Upvotes: 1

Related Questions