General
Material
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

Negation (cont.)

Consider the following two knowledge bases. The only difference is the order of the two goals in the body of the rule.

  • kb.day1.not1.pl
    magical(norbert).
    magical(buckbeat).
    magical(ssss).
    dementor(ssss).
    like(harry,X) :- magical(X), not(dementor(X)).
    	    
  • kb.day1.not2.pl
    magical(norbert).
    magical(buckbeat).
    magical(ssss).
    dementor(ssss).
    like(harry,X) :- not(dementor(X)), magical(X).
    	    
Logically, the order of the goals should not make a difference. For all X, if X is magical and not a dementor, then Harry likes it means the same as for all X, if X is not a dementor and is magical, then Harry likes it..

However, check out what happens if you ask the query like(harry,X). You haven't learned anything about how the Prolog interpreter goes about finding an answer. We will discuss that tomorrow and then you will be able to explain why Prolog is answering differently when the first knowledge base is loaded then when the second knowledge base is loaded. For the moment, just remember to be a bit careful when using not --- it may not do exactly what you think it should do.

Back to the practical session of day 1.