How to deny in Prolog

I am new to PROLOG and am at the very beginning of the exercises on this page . Given the rules of parent (X, Y) and male (X), I am trying to define the rule mother (X, Y) as

mother(X, Y) :- not(male(X)), parent(X, Y). 

However, the following error appears in GNU Prolog:

 | ?- mother(lina, julia). uncaught exception: error(existence_error(procedure,not/1),mother/2) | ?- 
+6
source share
2 answers

\+/1 is the ISO Prolog predicate for negation. Note that β€œdeny” means not provable at this point.

You can refer to this excellent @false answer for more information on the subject

+8
source

The solution is actually located in the exercise file on this page:

 female(X) :- \+ male(X). 

As @Mog said, negation is a unary operator \+ .

+3
source

Source: https://habr.com/ru/post/913132/


All Articles