Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to negate in Prolog

Tags:

prolog

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

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

However, in GNU Prolog I get the following error:

| ?- mother(lina, julia).
uncaught exception: error(existence_error(procedure,not/1),mother/2)
| ?- 
like image 598
lowerkey Avatar asked Apr 13 '12 13:04

lowerkey


2 Answers

\+/1 is the ISO Prolog predicate to "negate". Note that "negate" means here not provable at that point.

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

like image 145
m09 Avatar answered Sep 22 '22 11:09

m09


The solution is actually in the exercise file on that page:

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

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

like image 22
Volker Stolz Avatar answered Sep 19 '22 11:09

Volker Stolz