I need to introduce a predicate that will let me negate atoms. So far I have neg(Premise) :- \+ Premise.
, which gives me following results:
?- assert(a).
true.
?- a.
true.
?- neg(a).
false.
?- neg(neg(a)).
true.
That makes sense and all is dandy, until I tried unification. For instance
[a,_] = [a,123].
returns true.
while
[a,_] = [neg(neg(a)),123].
returns false.
.
How can I solve this so that the neg(neg(X))
part is being evaluated or otherwise unified with X
(since they both are logically equivalent)? So basically, I need X=neg(a), a=neg(X).
to succeed.
Edit I found an explanation as to why not(not(<expression>))
is not equivalent to <expression>
in prolog. Since <expression>
succeeds, not(<expression>)
fails. When a goal fails the variables it instantiated get uninstantiated. (source, slide 14).
I'm still not sure how to get around this though.
neg(neg(a))
isn't doing what you might think. It's instantiatingPremise
withneg(a)
and then evaluating\+ neg(a).
ultimately determining the truth value ofneg
withneg(a)
given as a term. Your array example attempts to unifya
withneg(neg(a))
and fails because they are both fully instantiated terms that don't match. You'll need to be more clear on what you're trying to do in order to 'get around it'. – lurkerl(a).
holds, thenl(neg(neg(a)).
should succeed too. Does that make sense? – Milo Wielondekl(neg(neg(X))) :- l(X).
– lurkerl
for each predicate seems like not the most efficient solution. – Milo Wielondek