next up previous
Next: Recursive Arithmetic Up: No Title Previous: No Title

Dealing with NOT

In one of the examples we looked at :

nice :-
  sunny,
  not_windy.

If I have the simple database of facts :

tel(james, 465676).
tel(mark, 332312).
tel(helen, 766786).

Then we can pose questions (queries) to Prolog in a number of different ways :

tel(mark, N)
N = 332312
yes 

tel(helen, 766786)
yes

tel(Name, 766786)
Name = helen
yes

tel(Name,Num)
Name=james
Num=465676 ;
Name=mark
Num= 332312;
...
no

Hence, the idea of obtaining information, using the reverse way. For instance, in arithmetic :

X is 2 + 18 / 5
X = 5.6
cannot say
5.6 is A + B / C  

however
X = 2 + 18 / 5
and 
A + B / C = 2 + 5 / 6
A = 2
B = 5
C = 6

Similarly, the use of the predicate not also prevents using procedures in different ways. We can, for instance, use the procedure

has_no_children(X) :- 
  not( child(_,X)).

only to check whether a certain person has no children, but cannot use it to find these people. An additional condition has to be introduced into the rule, to force X to be instantiated before executing the not( child(_,X)) goal. Hence :

has_no_children(X) :- 
  person(X),
  not( child( _,X)).

  figure40
Figure 1: A track event

better(X,Y) :-
  before(X,Y).

better(X,Y) :-
  before(X,Z),
  better(Z,Y).

before(tom, tim).
before(tim, jack).
before(jack, jim).
before( jim,john).


next up previous
Next: Recursive Arithmetic Up: No Title Previous: No Title

Omer F Rana
Fri Feb 14 20:23:31 GMT 1997