Re: [q-lang-users] Problem using function "isprime"
Brought to you by:
agraef
From: <Dr....@t-...> - 2004-10-09 12:06:50
|
we...@gm... wrote: > ==> isprime 1000003; > isprime 1000003 > > It shouldn't be a problem to determine that 1000003 is a prime? Well, this uses GMP's probabilistic prime test (Miller-Rabin algorithm), which may fail (in which case the Q function also fails). As a remedy, you can try to increase the clib::ISPRIME_REP value, or add your own test which catches the few cases when the Miller-Rabin test fails. See the chapter on "Clib", Section "Additional Integer Functions" in the manual for details. Here's a suitable definition which you can add to your program, copied straight from the docs: isprime N:Int = true if N = 2; = false if N and 1 = 0; // even number = try_div 3 (intsqrt N) N otherwise; try_div L M N = true if L > M; = false if N mod L = 0; = try_div (L+2) M N otherwise; -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikwissenschaft.uni-mainz.de/~ag |