Ticket #149 (closed defect)

Opened 5 years ago

Last modified 5 years ago

The prim predicate is not accurate

Reported by: mathk Owned by: soegaard
Priority: minor Milestone:
Component: soegaard/math.plt Keywords:
Cc: Version: (1 3)
Racket Version: 4.1.4

Description

Hi,

I have use the prim? predicate to build a list of prime number. It turn out that I have mush more "prime" than expected when I ask for all prime bellow 105.

Change History

in reply to: ↑ description   Changed 5 years ago by soegaard

  • status changed from new to closed

Replying to mathk:

I have use the prim? predicate to build a list of prime number.
It turn out that I have mush more "prime" than expected when I ask for all prime bellow 105.

I tried calculating the number of primes below various n, and the results matches Mathematica.
Can you post your code?

#lang scheme
(require (planet soegaard/math:1:3/math))

(define (count-primes-below n)

(let loop ([c 0]

[i 1])

(if (<= i n)

(if (prime? i)

(loop (+ c 1) (+ i 1))
(loop c (+ i 1)))

c)))

(map (lambda (n) (list n (count-primes-below n)))

(list 10 100 1000 10000 100000 1000000))

((10 4)

(100 25)
(1000 168)
(10000 1229)
(100000 9592)
(1000000 78498))

; => ((10 4)

(100 25)
(1000 168)
(10000 1229)
(100000 9592)
(1000000 78498))

; From Mathematica

In[1]:= PrimePi?[1000]
Out[1]= 168

In[3]:= PrimePi?[10000]
Out[3]= 1229

In[4]:= PrimePi?[100000]
Out[4]= 9592

In[5]:= PrimePi?[1000000]
Out[5]= 78498

  Changed 5 years ago by soegaard

  • status changed from closed to reopened

  Changed 5 years ago by soegaard

  • status changed from reopened to needinfo

  Changed 5 years ago by soegaard

  • status changed from needinfo to closed
Note: See TracTickets for help on using tickets.