Subject: Re: handling small numbers (fwd)

From: Nicos Angelopoulos <[email-masked]>
Date: Fri, 5 May 2000 11:25:48 +0100

On Thu, 4 May 2000, Tim Menzies wrote:

> tried that. my gcd(2,200000,X)
> takes an unacceptable amount of time to termiante.
> 
> you got a fast gcd?
> 
> 
> 

	for the little i know, 
	the standard algorithm is the Euclidean one, 

	here is my trivial implementation of it 

	i have used it extensively with very large quotients 
	and it seems to cope well

	i think gcd/2 sounds like a good candidate for
	a built-in function

?- statistics( cputime, Start ), gcd(2,200000,X), statistics( cputime, End
).

Start = 0.16
X = 2
End = 0.16 ;

No
?- 

	hope i didnt misread your email,

nicos

++++

gcd( M, N, C ) :-
        ( N =:= 0 -> C is M
                  ;  NewN is M mod N,
                     gcd( N, NewN, C )
        ).