Next: Recursive Arithmetic
Up: No Title
Previous: No Title
In one of the examples we looked at :
nice :-
sunny,
not_windy.
- This is really cheating
- How do we represent the not case
- Use the built in procedure not with one argument (not/1)
- So the goal, not(windy) succeeds if the goal windy fails
- It is possible that the goal is composed of sub-goals,
for instance :
not((windy, cold;hot)).
although the arity is still 1 : goals are combined using and, or
primitives
- Not : implements negation as the failure of proving that the
goal is true
- Prolog assumes that everything defined in a program, or what can be
derived from it is true : else : everything false - this is the
closed world assumption. Hence,
not(clever(user))
it answers yes - even though there is no rule about the user
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)).
- In this case, the order of the rules is also important

Figure 1: A track event
- Want to define a relation better, for which,
better(X,Y) is true if X finished the race before Y
- X is also better than Y, if X reached the winning post before
Z, and Z reached the winning post before Y
- Could be numerous others between X and Y
- Need a more general model
- Need to consider two main cases
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).
- Recursive procedure - with a base case and a
general definition
Next: Recursive Arithmetic
Up: No Title
Previous: No Title
Omer F Rana
Fri Feb 14 20:23:31 GMT 1997