next up previous
Next: Back to Lists Up: No Title Previous: Dealing with NOT

Recursive Arithmetic

Consider the definition of check numbers from a previous lecture. Another important definition, is of the factorial function :

0! = 1
n! = n*(n-1)!

factorial(0,1).

factorial(N,F) :-
   N > 0,
   N1 is N-1,
   factorial(N1, F1),
   F is N * F1.

Possible to extend the definition of our racers with the use of a third argument, which encapsulates time - therefore

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

better(X,Y,T) :-
 before(X, Z, T1),
 better(Z, Y, T2),
 T is T1 + T2.



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