Question

How can i define that two variables are not equal in Prolog? For example :

z is X and Y parent

X is male and Y is female

Now i want find sisters or brothers. But Prolog result is:

Y sister Y when parent have one child and not have X

Now i want define:

different(X,y).

I think old or other version of Visual Prolog have "different" in library but i dont find this in new Visual Prolog. What can i do?

Was it helpful?

Solution

define two variables are not equal in Prolog:

X \= Y
not(X = Y)
\+ (X = Y)

OTHER TIPS

Equivalence in Prolog is ==/2. This is also defined between variables. It specifically does not unify two different variables as =/2 would.

Some simple examples:

?- X = Y.
X = Y.
?- X == Y.
false.

And:

?- X = X.
true.
?- X == X.
true.

Since you specifically ask for equality between variables, I am wondering whether you are asking for something more than equivalence. Equality is sometimes defined as equivalence under substitution. So that a = b implies f(..., a, ...) = f(..., b, ...).

In Prolog this seems to be the case as well:

?- f(a, B1, c) = f(a, B2, c).
B1 = B2.
?- f(a, B1, c) == f(a, B2, c).
false.

And:

?- f(a, B, c) = f(a, B, c).
true.
?- f(a, B, c) == f(a, B, c).
true.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top