Well i'm just wondering why does it work, where prolog loose variable.
?- \+ \+ member(X,[a]),X=b.
X=b.
Where X=a. automagicly vanished.
Well i'm just wondering why does it work, where prolog loose variable.
?- \+ \+ member(X,[a]),X=b.
X=b.
Where X=a. automagicly vanished.
\+/1
is not "not" in the logical sense, but is implemented through "negation as failure". That means, \+ Goal
succeeds iff Goal
fails.
Think of \+/1
as being implemented as:
\+(Goal) :- Goal -> fail ; true.
As you can see, in both cases can no variable in Goal
become bound. In the "if" branch, any binding will be undone by backtracking, and in the "else" branch, no variable will have been become bound anyway.
In your example, member(X,[a]
succeeds by binding X
to a
. This will have \+ member(X,[a])
fail, and so \+\+ member(X,[a])
succeeds because of this failure. Due to the intermediate failure, X
will not be bound to a
.
the (\+)/1
operator in prolog is supposed to stand for not provable but corresponds to the older (not)/1
operator. So basically what you are doing here is:
not not member(X, [a]), X = b.
EDIT
If X
is a list that contains a
, the double negation of member(X, [a])
will have the same result as member(X, [a])
without any negations. X = b
, just binds b
to the list X
.
Also here is a link I had bookmarked that has a list of all Prolog predicates and their meanings.
Hope this helps