% ================================================================= % == == % == An Introduction to ARTIFICIAL INTELLIGENCE == % == Janet Finlay and Alan Dix == % == UCL Press, 1996 == % == == % ================================================================= % == == % == mathematical utilities == % == == % == Prolog example, Alan Dix, August 1996 == % == == % ================================================================= % max/3, min/3, fdiv/3, round/2 min(N,M,N) :- N =< M. min(N,M,M) :- N > M. max(N,M,N) :- N >= M. max(N,M,M) :- N < M. % some Prologs don't handle floating point division. % choose the definition which works best on your implementation % fdiv(Num,Den,Res) :- Res is Num/Den. fdiv(Num,Den,Res) :- Res is ((Num*1000000.0)/Den)*0.000001. % the definition of round/2 relies on / always giving integer result % this is likely to be very dependent on the way your Prolog works, % so you may need to redefine this. round(X,N) :- N is (X+0.499)/1.