Den tor. 11. jul. 2019 kl. 15.40 skrev Bob Heffernan < bob.heffer...@gmail.com>:
> On 19-07-11 09:31, James Geddes wrote: > > Indeed, I would have thought that the calculation time would be > > entirely dominated by the test for primality, and especially what > > happens once the candidate primes are bigger than 2^64 and can no > > longer be represented by a single word. > > I assume that you are right. The isprime procedure in my python code is > the one from sympy (I didn't bother to include the import line in my > previous email). I believe that sympy uses the C library GMP. > The prime? procedure in my Racket code is that from > the math/number-theory library. > > I don't know anything about sympy, but I seem to recall that Python > libraries for these sorts of things often rely on fast routines written > in C. I suppose it might be interesting to implement the same > prime-checking in both Python and Racket and *then* compare speeds. > If you want, you can use the prime test from GMP from Racket too. #lang racket (require gmp) (define repetitions 25) ; manual says values between 15 and 50 are reasonable. (define (is-prime? n) (case (mpz_probab_prime_p (mpz n) repetitions) [(2) #t] [(1) 'probably] [(0) #f])) (for/list ([n (in-range 2 100)] #:when (is-prime? n)) n) See https://docs.racket-lang.org/gmp/index.html?q=gmp and https://gmplib.org/manual/Number-Theoretic-Functions.html for more information. /Jens Axel -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CABefVgxUZGtXUD8%2Bq5XS%3DTyQWO%2BWLgZNsm12LALbVviVPkwc-Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.