From nangelop@csd.abdn.ac.uk  Fri May  5 12:25:41 2000
Received: from pigeon.csd.abdn.ac.uk (root@pigeon.csd.abdn.ac.uk [139.133.200.15])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id MAA13000
	for <prolog@swi.psy.uva.nl>; Fri, 5 May 2000 12:25:41 +0200 (MET DST)
Received: from kea (nangelop@kea [139.133.200.24])
	by pigeon.csd.abdn.ac.uk (8.9.3/8.9.3) with ESMTP id LAA14525
	for <prolog@swi.psy.uva.nl>; Fri, 5 May 2000 11:25:48 +0100 (BST)
Date: Fri, 5 May 2000 11:25:48 +0100
From: Nicos Angelopoulos <nangelop@csd.abdn.ac.uk>
To: prolog@swi.psy.uva.nl
Subject: Re: handling small numbers (fwd)
Message-ID: <Pine.SGI.4.21.0005051125130.170424-100000@kea.csd.abdn.ac.uk>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII



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 )
        ).



