$=

Negation by failure

\prologindex{negation by failure} \prologindex{\it not} Prolog does not support ordinary negation. Instead Prolog supports what is called negation by failure. Some caution is necessary when using negation in Prolog, since when calling not( p(X) ), for some predicate p with X unbound, X will remain unbound. As an example of the use of negation consider the predicate canfly. \pprog{}{ canfly(X) :- bird(X), not( penguin(X) ). } This definition states that an animal can fly if it is a bird but not a penguin. A straightforward way to implement the use of not to check for an exceptional condition is given in the clauses for canfly below. \pprog{canfly}{
    canfly(X) :- penguin(X), !, fail.
    canfly(X) :- bird(X).
  
} Dynamically, the occurrence of a cut in the first clause enforces that there is no alternative to failure once it is established that the animal in question is a penguin. Making use of what we will introduce later as a meta-programming facility we can implement the (meta) predicate not according to the pattern outlined above as follows. \pprog{not}{ .ds not.pl } In effect, these clauses state that the goal
not(X) fails if the goal X is successfully evaluated and that the goal not(X) will succeed otherwise. Notice that the goal not(X) will not terminate if the goal X does not terminate.