Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog programming - simple negative query

Tags:

prolog

My database is:

eat(magi,limo).
eat(nona,banana).

How do I ask: "Who's not eating limo?" This:

eat(X,not(limo)).

Doesn't work. :(

like image 204
Ned Avatar asked Jun 17 '26 20:06

Ned


1 Answers

First of all limo is a symbol and you can't negate symbols. What you want to do is negate the predicate, i.e. not(eat(X, limo)).

However this still does not give you nona as a result. Why not? Well there are infinitely many values X for which eat(X, limo) will be false. The system needs more information than "X does not eat limo" to know which one you want. Instead we need to ask for an X such that "X eats something, but X does not eat limo". This leads us to the following query:

eat(X,Y), not(eat(X, limo)).

Which gives us nona as the solution for X.

like image 102
sepp2k Avatar answered Jun 19 '26 19:06

sepp2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!