I ate some tau
I ate some tau

Reputation: 115

State defined by logical NOTs in Prolog

How do I make a logical NOT in a predicate?
If I wanted to define a state dependent on three conditions, it might look like:

test(A, B, C) :- cond(A), cond(B); cond(C).  

How would you define a state to be NOT A and NOT B and NOT C?

Upvotes: 0

Views: 46

Answers (1)

CapelliC
CapelliC

Reputation: 60004

Plain reading of your condition (note: will work as expected, under the restrictive conditions of Prolog - negation by failure - only if A,B,C are instantiated)

test(A,B,C) :- \+ cond(A), \+ cond(B), \+ cond(C).

that's equivalent (Boolean algebra applied to negation):

test(A,B,C) :- \+ (cond(A) ; cond(B) ; cond(C)).

Upvotes: 1

Related Questions