From e3ec0515274acddf1e7a53d8d179f98b681f3f92 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Mon, 15 Jun 2015 23:02:39 -0700 Subject: [PATCH] math.primes: fix "11 >bignum prime?". --- basis/math/primes/primes-tests.factor | 2 ++ basis/math/primes/primes.factor | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/basis/math/primes/primes-tests.factor b/basis/math/primes/primes-tests.factor index 22d3bcc7ba..d5d1cb2f32 100644 --- a/basis/math/primes/primes-tests.factor +++ b/basis/math/primes/primes-tests.factor @@ -39,3 +39,5 @@ IN: math.primes.tests [ 5 t { 14 14 14 14 14 } ] [ 5 15 unique-primes [ length ] [ [ prime? ] all? ] [ [ log2 ] map ] tri ] unit-test + +{ t t } [ 11 dup >bignum [ prime? ] bi@ ] unit-test diff --git a/basis/math/primes/primes.factor b/basis/math/primes/primes.factor index f0b4e57a99..642f8ef8e4 100644 --- a/basis/math/primes/primes.factor +++ b/basis/math/primes/primes.factor @@ -9,12 +9,13 @@ IN: math.primes fixnum $[ 8999999 sieve ] marked-unsafe? ; inline : (prime?) ( n -- ? ) dup 8999999 <= [ look-in-bitmap ] [ miller-rabin ] if ; -: simple? ( n -- ? ) { [ even? ] [ 3 divisor? ] [ 5 divisor? ] } 1|| ; +: simple? ( n -- ? ) + { [ even? ] [ 3 divisor? ] [ 5 divisor? ] } 1|| ; PRIVATE> @@ -37,10 +38,12 @@ PRIVATE> : ( low high -- range ) [ 3 max dup even? [ 1 + ] when ] dip 2 ; -! In order not to reallocate large vectors, we compute the upper bound -! of the number of primes in a given interval. We use a double inequality given -! by Pierre Dusart in http://www.ams.org/mathscinet-getitem?mr=99d:11133 -! for x > 598. Under this limit, we know that there are at most 108 primes. +! In order not to reallocate large vectors, we compute the upper +! bound of the number of primes in a given interval. We use a +! double inequality given by Pierre Dusart in +! http://www.ams.org/mathscinet-getitem?mr=99d:11133 for x > +! 598. Under this limit, we know that there are at most 108 +! primes. : upper-pi ( x -- y ) dup log [ / ] [ 1.2762 swap / 1 + ] bi * ceiling ;