0
votes

sibling(X, Y):- father(Z, X), father(Z, Y), not (X=Y).

sister(X, Y):- father(Z, X), father(Z, Y), female(X).

brother(X, Y):- father(Z, X), father(Z, Y), male(X).

enter image description here

i'm having a bit problem with using the not function. i've tried not X=Y. but to no avail, the sibling rule still produce error.

if i were to delete the not x=y, the output will be a bit kind of "ugly". how should i write the not function?

2
You could write X\=Y or even better use iso predicate dif/2 and write : dif(X,Y).coder
thank you very much sir. I got the correct output. :)CheekyChibi

2 Answers

1
votes

The ISO predicate implementing not provable is called (\+)/1.

However, as @coder explains in the comments, it is much better to use dif/2 to express that two terms are different.

dif/2 is a pure predicate that works correctly in all directions, also if its arguments are not yet instantiated.

For example, with (\+)/1, we get:

?- \+ (X = Y ).
false.

No X and Y exist that satisfy this goal, right? Wrong:

?- X = a, Y = b, \+ (X = Y ).
X = a,
Y = b.

In contrast, with dif/2:

?- dif(X, Y).
dif(X, Y).

and in particular:

?- X = a, Y = b, dif(X, Y).
X = a,
Y = b.

See for more information. dif/2 is with us since the very first Prolog system. I strongly recommend you use it.

0
votes

SWI Prolog has no notoperator. it can be used as a regular compound term, e.i. not(X).

It must be no space between functor and open parenthesis:

foo( argument list ).

This is the cause of the error.

SWI Prolog suggests ISO-standard replacement for not/1: (\+)/1