Exercise 1.24
Imports: [[Chapter 1.2]] fast-prime?, [[Exercise 1.22]] search-for-primes
(define (search-for-primes p? a b)
(define (iter a b)
(when (<= a b)
(timed-prime-test p? a)
(iter (+ a 2) b)))
(iter (if (odd? a) a (+ a 1)) b))
(define (prime? n) (fast-prime? n 100))
(string-contains?
(capture-output (search-for-primes prime? 6 10))
"7 *** ")
=> #t
\(A =\) time for 3 primes greater than 1,000.
\(B =\) time for 3 primes greater than 10,000. \((0.988A < B < 1.196A)\)
\(C =\) time for 3 primes greater than 100,000. \((0.893B < C < 1.294B)\)
\(D =\) time for 3 primes greater than 1,000,000. \((0.891C < D < 1.453C)\)
; 1000003 *** .005592823028564453
; 1000033 *** .004972934722900391
; 1000037 *** .0043179988861083984
Since the Fermat test has \(\Theta(\log n)\) growth, time to test primes near 1,000,000 is only a bit greater than for primes near 1,000. The tests show this: for each additional order of magnitude of the primes, the time required increases by a small, constant amount. Specifically, primes that are 10 times larger take about 1 millisecond longer. These results may be dependent on the choice of 100 as the second argument to fast-prime?.