Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Not equal" sign in Visual Prolog?

I can't find any documentation on "not equal" sign in Visual Prolog. Please provide the right solution of this problem:

class predicates         sister : (string Person, string Sister) nondeterm(o,o).     clauses         sister(Person, Sister) :-             Person [not-equal-sign] Sister,             parent(Person, Parent),             parent(Sister, Parent),             woman(Sister). 
like image 985
Egor Avatar asked Sep 20 '11 12:09

Egor


People also ask

What does =:= mean in Prolog?

=:= expression is meaning of exactly equal. such as in JavaScript you can use === to also see if the type of the variables are same. Basically it's same logic but =:= is used in functional languages as Prolog, Erlang.

How do you check if two variables are equal in Prolog?

The conjunct X=Y first unifies the variables X and Y . Thus when the second conjunct X==Y is evaluated, the two variables are exactly the same Prolog object, and the second conjunct succeeds as well.

How do you compare characters in Prolog?

string2(ikra). go:- write("Enter your name"), nl, read(X),nl, string1(Y), X=@=Y,nl, write("Matched"); write("not Matched"),go2. /*Another way to*/ go2:- string1(A), string2(B), A=@=B,nl, write("Matched"); write("not Matched").


2 Answers

I don't know what do you mean by "not equal" (does not unify?), but you could try these:

X \= Y not(X = Y) \+ (X = Y) 
like image 179
Kaarel Avatar answered Oct 04 '22 11:10

Kaarel


Documentation for the second variant pointed out by Kaarel can be found in this Visual Prolog reference page.

However the problem with your code goes a little deeper. You need to wait for testing of non-equality until both terms Person and Sister are bound, so rearrange things like this:

    sister(Person, Sister) :-         parent(Person, Parent),         parent(Sister, Parent),         not(Person = Sister),         woman(Sister). 

There is also syntax for an infix operator "<>" which means distinct (or different). Once the two terms are bound this should give the same result as checking whether the terms cannot be unified, which is what the above construction does.

like image 22
hardmath Avatar answered Oct 04 '22 12:10

hardmath