Counting primes, innovation



 Science > Physics > Counting primes, innovation

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: Science > Physics
User: ""
Date: 12 Mar 2005 04:26:10 PM
Object: Counting primes, innovation
Supposedly at times an idea can be important simply because it shows a
surprisingly *easy* way to do something already known where techniques
already exist. Now I've talked about what I call my prime counting
function before, but here's an explanation for laypeople, and then I
want to talk a bit about innovation and the math world.
You can count primes several ways. A nice and easy way is to count
composites and subtract off their number and 1 to get your count of
primes. Like up to 10 the even composites are found just by dividing
by 2, discarding any remainder and subtracting 1, like
10/2 = 5, and the 5 evens are 2, 4, 6, 8, and 10, so subtract 1, and
you have 4, for the evens
4, 6, 8, 10
and I figured that with the evens out of the way, to find those with 3
as a factor, you should skip evens, so next you have
9
as the only odd with 3 as a factor that's not even. So you have 5
composites, and subtract that from 10 and you get 5, and since 1 is not
considered prime, you subtract 1, and have 4, the count of primes,
where they are
2, 3, 5, and 7
and just now you just saw an idea fly by which is what makes my prime
counting function works, but I'm sure you missed it, so I'll give a
bigger example.
The even *composites* up to 25 are
4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24
while the odds that have 3 as a factor are
9, 15, 21
and the one remaining composite has 5 as a factor and it is
25
and the sum of composites is 15, and 25 - 15 = 10, and you subtract 1
for 1, as it's not prime, leaving you with 9 primes:
2, 3, 5, 7, 11, 13, 17, 19, 23
and in case you think I'm just playing silly games with you, let me
show you how Legendre's Method does it, as that's an old prime counting
method that mathematicians are taught.
It uses the same idea for evens, so you have
4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24
BUT, it take ALL the numbers up to 25 that have 3 as a factor, so you
have
6, 9, 12, 15, 18, 21, 24
and because you have numbers in both lists, Legendre's next finds all
that have 6 as a factor, so you have
6, 12, 18, 24
and subtracts them from the previous, so now you have
4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24
to give your count from the two previous lists.
That leaves 5 and Legendre's Method finds all the composites with 5 as
a factor, so you have
5, 10, 15, 20, 25
and then it take all the composites with 10, as a factor
10, 20
and all the composites with 15, as a factor, so you take
15
and subtract them out and now adds them back into the other list, so
the full list is
4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25
which is the same as before, but notice you had this subtracting out
and adding back in with Legendre's that wasn't mentioned in my
previous.
Mathematicians found that Legendre's Method was slow and clunky, hard
to work with as when you add more primes you get more and more
combinations. So they developed faster methods *from* Legendre's,
while one day a couple of years ago I started thinking about prime
numbers.
You see, I haven't gone to school as a mathematician and had never
cared about counting prime numbers before, so I didn't know about
Legendre's Method, and when I looked to count primes, I intuitively
looked to count the even composites first, and then the odds divisible
by 3, and so forth as I demonstrated.
I mathematicized that method and you get a couple of formulas.
I've given those formulas before when talking about my prime counting
function.
One is a fully mathematicized version that can find the initial primes
on its own, like you don't have to tell it that 3, and 5 are primes as
it will figure that out by recursion, and sci.math'ers have routinely
belittled that formula for being slow.
Now if you give it a list of primes, like how I demonstrated here,
where you know that 2, 3 and 5 are primes, like how Legendre's has a
list, it is quite fast, and is much faster than Legendre's Method.
However, several sci.math'ers have routinely said that my prime
counting function is just Legendre's Method.
Now then, how can a method that looks short and neat like you have
4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24
for the even composites, and
9, 15, 21
for the odd composites with 3 as a factor, and
25
for the remaining composite with 5 as a factor compare with a method,
which rather naively just gets a count for each prime and then corrects
itself, to the extent that for over TWO YEARS some very vocal math
people have proclaimed them to be the same method?
Well, people want to believe.
They want to believe that some guy claiming he has a major math
discovery and that mathematicians aren't treating it properly, must be
a nut.
They want to believe that people they trust don't lie to them.
They want to believe it's a sane world.
It turns out that I use a very simple and intuitive idea to count
primes, which is just so happens is not in any math textbooks that I'm
aware of, and I have looked quite a bit.
You can go yourself and do a web search on "prime counting" or "prime
counting function" and see if any links talk about a simple way to
count prime numbers which rather sensibly only counts the primes not
already counted, versus counting in extras to be subtracted back out.
Those of you who think you're brilliant mathematically, derive the
formulas that follow from doing the count as I do.
I'll admit that I'm puzzled that I get so much arguing about what I see
as simple techniques, and even more puzzled that the idea is new to me.
To date I've challenged and never seen anyone else capable of doing the
simple derivation, which puzzles me still more.
I will help you out. The main function I call dS(x,y) where it is the
count of composites that have y as a factor that do not have any primes
less than y as a factor.
For instance, as I showed dS(25, 3) = 3, and those composites are
9, 15, 21
and yes, it may puzzle some of you that you can simply get the answers
to that function without calculating, but you can.
Notice that if y is not prime then dS(x,y) will equal 0, as then there
will be some prime less than y for which each composite will have a
factor.
Like if y = 4, then, of course, every number that has 4 as a factor
will have 2 as a factor, so you see, all the composites with 4 as a
factor get counted with dS(x,2).
If you're really curious to see the full mathematicized formula, and to
see what I want some one of you to derive, check out
http://en.wikipedia.org/w/index.php?title=Prime_counting_function&oldid=9142249
and you will see it on that page as the p(x,y) function.
You can also check the current Wikipedia page on the prime counting
function to see how others try to explain.
Now then, if I have a simple idea I can explain this easily, why do
math people mostly call me names?
Well, innovation can be threatening. In the real world an innovative
idea can prove itself by building better mousetraps, as they say. But
in mathematics, mathematicians feel they have the capacity to decide,
as a group, what they think is important or not.
So, you see, in today's mathematical world, it doesn't matter how
brilliant you can show a result to be, even if you can explain it to
non-mathematicians, as the professionals believe they own the
discipline, and they don't have to answer to anyone--not you, not me,
not anyone.
So I'm stuck talking about my research a lot on Usenet, where
sci.math'ers often make fun of me.
You see, they can make fun of me, despite the correctness of my
mathematical results, and despite the real value of those results
because math society is a true democracy.
It's not about the truth in that society, but what the group decides is
the truth, as you can see here with a prime counting function, where I
found an innovative way to count prime numbers, and math people make
fun of me versus cheering that success.
James Harris
.

User: ""

Title: Re: Counting primes, innovation 12 Mar 2005 05:20:42 PM
wrote:

You see, they can make fun of me, despite the correctness of my
mathematical results, and despite the real value of those results
because math society is a true democracy.

Yeah, democracy sucks. That's why this country is a Constitutional
Republic and not a democracy.


It's not about the truth in that society, but what the group decides

is

the truth,

I bet you wish there was some form of Constitution for Mathematics to
protect your truth from the tyranny of democracy.

as you can see here with a prime counting function, where I
found an innovative way to count prime numbers, and math people make
fun of me versus cheering that success.

Think about that the next time you want to advocate the overthrow of
the Constitution by foreign powers.



James Harris

.

User: "Uncle Al"

Title: Re: Counting primes, innovation 12 Mar 2005 05:47:45 PM
wrote:
[snip crap]

James Harris

Your ignorance, incompetence, and psychosis are not of interest to the
world at large. Quite the contrary. You are not even an interesting
laughingstock.
Hey stooopid loud troll James "Always in error, never in doubt!"
Harris, put up or shut up. James Harris, King of the Primes! Where
are your sceptor and crown, delusional James Harris, your regal
clothes? Is a $20,000 prize no questions asked too small to justify
your submission of two little prime numbers? Or are you a psychotic
impotent gelding?
Hey stoopid loud troll James "Prime *****" Harris, a better man than
you has factored RSA-576. Pookie pookie.
http://www.rsasecurity.com/rsalabs/challenges/factoring/faq.html
http://www.rsasecurity.com/rsalabs/challenges/factoring/numbers.html
http://www.crank.net/harris.html
It's not every braying jackass who earns a whole page at crank.net
<http://groups.google.com/groups?selm=3c65f87.0212222034.d5959fd%40posting.google.com>
<http://groups.google.com/groups?selm=3c65f87.0212251249.4b69d7c5%40posting.google.com>
<http://groups.google.com/groups?&q=author%3Ajames+author%3Aharris+%22i+was+wrong>
--
Uncle Al
http://www.mazepath.com/uncleal/
(Toxic URL! Unsafe for children and most mammals)
http://www.mazepath.com/uncleal/qz.pdf
.

User: "C. Bond"

Title: Re: Counting primes, innovation 12 Mar 2005 05:52:48 PM
wrote:
[snip repost of previous expositions on prime counting]
It's customary, when one has already posted information on Usenet, to simply
provide a link to previous posts. It isn't really necessary to persist in starting
new threads with old information. Besides, you recently claimed you were going to
reduce the number of threads you start -- this one is completely unnecessary.
--
There are two things you must never attempt to prove: the unprovable -- and the
obvious.
--
Democracy: The triumph of popularity over principle.
--
http://www.crbond.com
.

User: "Jumby"

Title: Re: Counting primes, innovation 13 Mar 2005 12:39:29 AM
Blichhhh.......
.

User: "Christian Bau"

Title: Re: Counting primes, innovation 12 Mar 2005 06:36:55 PM
In article <1110666370.073219.299350@f14g2000cwb.googlegroups.com>,
wrote:

<snipped ***** explanation why Harris' method is different from
Legendre's Formula>

Just go to
http://mathworld.wolfram.com/LegendresFormula.html
Between equation (1) and (2) you find
"Taking a = pi (sqrt (x)), where pi (n) is the prime counting
function, gives phi (x, pi (sqrt (x))) = pi (x) - pi (sqrt (x) + 1..."
and equation (3) is the recurrence relation
"phi (x, a) = phi (x, a-1) - phi (x / p (a), a-1)"
.
User: ""

Title: Re: Counting primes, innovation 13 Mar 2005 08:42:39 AM
Christian Bau wrote:

In article <1110666370.073219.299350@f14g2000cwb.googlegroups.com>,
jstevh@msn.com wrote:

<snipped ***** explanation why Harris' method is different from
Legendre's Formula>

Notice the emotion and the heat of that emotion.


Just go to

http://mathworld.wolfram.com/LegendresFormula.html

Between equation (1) and (2) you find

"Taking a = pi (sqrt (x)), where pi (n) is the prime counting
function, gives phi (x, pi (sqrt (x))) = pi (x) - pi (sqrt (x) +

1..."


and equation (3) is the recurrence relation

"phi (x, a) = phi (x, a-1) - phi (x / p (a), a-1)"

However, I can explain by example, and then you can go to that site and
see the truth.
The sci.math'er who made that reply has lied about my work for over two
years now, and his energy in replying as much as he does to keep up his
position should tell you something.
Here's another example, and then you can go to the link he mentioned
and see if there's anything like it.
Counting up to 50 this time, my idea first gets the even composites:
4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38,
40, 42, 44, 46, 48, 50
and then gets the *odds* that have 3 as a factor:
9, 15, 21, 27, 33, 39, 45
where notice I don't bother with evens that have 3 as a factor, and
then you get the odds that don't have 3 as a factor that do have 5:
25, 35
and that leaves composites that have 7 as a factor, but none of the
smaller primes, where there is just one:
49
and notice that you have a rapidly shrinking count, from a sensible way
to count primes.
I just naturally and intuitively came to such a method when I started
thinking about counting primes, as it made sense to me.
But it's just a basic fact that Legendre's Method does not count that
way.
The mathematical formulas are somewhat complicated, which is why I now
use the simple demonstration of giving out the composites, as I need
something simple enough that you can tell when sci.math'ers like
Christian Bau are lying to you.
If you go to the link he gives, you'll see nothing like the sensible
counting method I used described.
It's complicated enough how Legendre's works with even such a simple
example as the count of composites up to and including 50 that I won't
show it in full here, but give you one example, which is how it handles
the composites with 3 as a factor.
If any sci.math'ers or others who claim that my work is old wish to
dispute that by giving a full demonstration with Legendre's, they are
free to do so, and *should* if they are trying to be honest.
I'll consider how it handles the composites that have 3 as a factor.
It takes ALL of them, so you have
6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48
and then it finds all the composites that have 6 as a factor
6, 12, 18, 24, 30, 36, 42, 48
and subtracts that number to correct the overcount.
For the count of 5 it does that for 10 and 15, and by doing so, it
subtracts out 30 *twice* as both 3 and 2 have it as a factor, so
there's another correction of an addition of 1.
For 7, it has to handle the counts for 2, 3, and 5 in varying
combinations, correcting for overcounts, repeatedly.
It is dizzyingly complicated to look at for even a simple example.
My feeling at this time is that sci.math'ers like Christian Bau and
others like David Ullrich, a math professor at Oklahoma State
University, got away with a rather basic lie because people would get
lost on the equations from the mathematicization.
Physicsts can understand that, as electromagnetic theory was worked out
by Faraday, and mathematicized by Maxwell, and Faraday couldn't
understand the mathematical equations.
So I'm going from the mathematicization, where sci.math'ers lie so
easily, to the idea so that people can see what the idea really is, and
also see that math people are in fact lying to them.
And lying quite boldly.
James Harris
.
User: "Uncle Al"

Title: Re: Counting primes, innovation 13 Mar 2005 05:04:12 PM
wrote:

[snip crap]
James Harris

Your ignorance, incompetence, and psychosis are not of interest to the
world at large. Quite the contrary. You are not even an interesting
laughingstock.
Hey stooopid loud troll James "Always in error, never in doubt!"
Harris, put up or shut up. James Harris, King of the Primes! Where
are your sceptor and crown, delusional James Harris, your regal
clothes? Is a $20,000 prize no questions asked too small to justify
your submission of two little prime numbers? Or are you a psychotic
impotent gelding?
Hey stoopid loud troll James "Prime *****" Harris, a better man than
you has factored RSA-576. Pookie pookie.
http://www.rsasecurity.com/rsalabs/challenges/factoring/faq.html
http://www.rsasecurity.com/rsalabs/challenges/factoring/numbers.html
http://www.crank.net/harris.html
It's not every braying jackass who earns a whole page at crank.net
<http://groups.google.com/groups?selm=3c65f87.0212222034.d5959fd%40posting.google.com>
<http://groups.google.com/groups?selm=3c65f87.0212251249.4b69d7c5%40posting.google.com>
<http://groups.google.com/groups?&q=author%3Ajames+author%3Aharris+%22i+was+wrong>
--
Uncle Al
http://www.mazepath.com/uncleal/
(Toxic URL! Unsafe for children and most mammals)
http://www.mazepath.com/uncleal/qz.pdf
.

User: "Albert van der Horst"

Title: Re: Counting primes, innovation 20 Mar 2005 11:35:58 AM
In article <1110724959.904728.143940@l41g2000cwc.googlegroups.com>,
<jstevh@msn.com> wrote:

Christian Bau wrote:

In article <1110666370.073219.299350@f14g2000cwb.googlegroups.com>,
jstevh@msn.com wrote:

<snipped ***** explanation why Harris' method is different from
Legendre's Formula>


Notice the emotion and the heat of that emotion.


Just go to

http://mathworld.wolfram.com/LegendresFormula.html

Between equation (1) and (2) you find

"Taking a = pi (sqrt (x)), where pi (n) is the prime counting
function, gives phi (x, pi (sqrt (x))) = pi (x) - pi (sqrt (x) +

1..."


and equation (3) is the recurrence relation

"phi (x, a) = phi (x, a-1) - phi (x / p (a), a-1)"


However, I can explain by example, and then you can go to that site and
see the truth.

The sci.math'er who made that reply has lied about my work for over two
years now, and his energy in replying as much as he does to keep up his
position should tell you something.

Here's another example, and then you can go to the link he mentioned
and see if there's anything like it.

Counting up to 50 this time, my idea first gets the even composites:

4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38,
40, 42, 44, 46, 48, 50

and then gets the *odds* that have 3 as a factor:

9, 15, 21, 27, 33, 39, 45

where notice I don't bother with evens that have 3 as a factor, and
then you get the odds that don't have 3 as a factor that do have 5:

25, 35

and that leaves composites that have 7 as a factor, but none of the
smaller primes, where there is just one:

49

and notice that you have a rapidly shrinking count, from a sensible way
to count primes.

Without further comment I post a small program in Pascal that
is on my site since 1995
http://home.hccnet.nl/a.w.m.van.der.horst/pipi.pas
The algorithm is again similar but not quite Legendre method.
DismissedBy(n,p) = Dleg(n,p) - Dleg(n,p-1)
Like the real mathematicians have pointed out, if you are serious
about prime counting you should supplement this with a sieve to
find the small primes.
I think it is a nice little program, but no reason for megalomanic
claims, or even a publication in print.
The explanation is more lucid then James's.
------------------------------------------------------
{ Copyright (c) 1995 by Albert van der Horst }
program pi;
uses Crt;
{ This program calculates how many primes there are less or equal a given
number. This function is called pi(n).
It only demonstrates the algorithm. The range allowed for the number `n'
is limited by the signed integers Pascal can handle: 32675.
It is based on a careful analysis of the Eratosthenes' sieve.
In the sieve numbers are dismissed because they are divisible by
prime numbers.
We will use the notion of "dismissing by".
A number is "dismissed by" a prime, if that prime is its smallest divider.
The numbers smaller than or equal to `n' are divided in disjunct sets
of numbers dismissed by a certain prime, and the number 1.
A large primes p<=n (in fact all primes larger than sqrt(n)) form such
a set with only one member. (The definition implies that a prime is
dismissed by itself.)
An example of the numbers <=17 and their dismissing primes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
- 2 3 2 5 2 7 2 3 2 11 2 13 2 3 2 17
By inspection we see that Dismiss(17,3) should return 3.
}
{ IsPrime is an auxiliary function that tells whether `n' is prime.
}
Function IsPrime( n: integer):boolean;
var
i: integer; { Just a counter }
begin
IsPrime := True;
if n>=4 then
for i:=2 to n do
if n/i<i then
exit
else if n mod i = 0 then
begin
IsPrime := False;
exit
end
end;
{ `DismissedBy' counts the numbers less than `n' dismissed by the prime `p'.
See explanation at the beginning.
}
Function DismissedBy( n,p: integer):integer;
var
nsmall: integer; { The amount of multiples of `p' <=n }
p2: integer; { a prime smaller than `p' }
d: integer; { return value, dismissed }
begin
nsmall := n div p;
if nsmall<p then
begin
DismissedBy :=1;
exit
end;
{ m is dismissed by p iff m div p is NOT dismissed by some p1 <p }
{ Start counting them }
d := nsmall; { `nsmall' multiples are all candidates }
{ Subtract all those dismissed by smaller primes }
for p2:=2 to p-1 do
if IsPrime(p2) then
d := d - DismissedBy( nsmall, p2 );
DismissedBy :=d
end;
{ Returns PI the number of primes smaller or equal to `N'
We may count the primes < N as follows.
Start with N-1 because all numbers except 1 could be primes.
Subtract all those dismissed by some prime except that prime
itself.
We may stop the loop at sqrt(n) because from then on,
DismissedBy(n,p2) = 1 . From then on, we subtract one but add one
again for the prime itself, so the running total does not change.
Alternatively you may think of dismissing as the process of sieving
using Erathosthenes' sieve, where you may stop at the sqrt(n).
Stopping at the root is the crux.
You could of course just test all numbers <N for primality
using IsPrime().
}
Function CountPr( N:integer ):integer;
var r:integer; { result }
var p:integer; { running prime }
begin
r := N-1; { All except one are prime candidates }
for p:=2 to n do
if p*p>n then
begin
CountPr := r;
exit
end
else if IsPrime(p) then
begin
r := r - DismissedBy( n, p );
r := r+1; { Correct: the prime itself was also dismissed }
end;
CountPr := r;
end;
var N : integer;
begin {countpr}
repeat
Writeln('Give a number ...');
read(N);
Writeln('The number of primes <=',N,' is ',
CountPr(N) );
until N=0;
end.
------------------------------------------------------

James Harris

--
--
Albert van der Horst,Oranjestr 8,3511 RA UTRECHT,THE NETHERLANDS
One man-hour to invent,
One man-week to implement,
One lawyer-year to patent.
.
User: "Vivian McPhail"

Title: Re: Counting primes, innovation 02 Apr 2005 02:45:22 AM
In Haskell:
\begin{code}
divides :: Integer -> Integer -> Bool
divides x y = mod y x == 0
remove_multiples :: Integer -> [Integer] -> [Integer]
remove_multiples n [] = []
remove_multiples n (h:t)
| divides n h = remove_multiples n t
| otherwise = h : (remove_multiples n t)
sieve :: [Integer] -> [Integer]
sieve [] = []
sieve (h:t) = h : (sieve (remove_multiples h t))
primes :: [Integer]
primes = sieve [2..]
{- The number of primes less than or equal to a number -}
primes_lt :: Integer -> Integer
primes_lt n = length [ x | x <- primes, x <= n]
\end{code}
"Albert van der Horst" <albert@spenarnc.xs4all.nl> wrote in message
news:idnvjy.a3o@spenarnc.xs4all.nl...

In article <1110724959.904728.143940@l41g2000cwc.googlegroups.com>,
<jstevh@msn.com> wrote:

Christian Bau wrote:

In article <1110666370.073219.299350@f14g2000cwb.googlegroups.com>,
jstevh@msn.com wrote:

<snipped ***** explanation why Harris' method is different from
Legendre's Formula>


Notice the emotion and the heat of that emotion.


Just go to

http://mathworld.wolfram.com/LegendresFormula.html

Between equation (1) and (2) you find

"Taking a = pi (sqrt (x)), where pi (n) is the prime counting
function, gives phi (x, pi (sqrt (x))) = pi (x) - pi (sqrt (x) +

1..."


and equation (3) is the recurrence relation

"phi (x, a) = phi (x, a-1) - phi (x / p (a), a-1)"


However, I can explain by example, and then you can go to that site and
see the truth.

The sci.math'er who made that reply has lied about my work for over two
years now, and his energy in replying as much as he does to keep up his
position should tell you something.

Here's another example, and then you can go to the link he mentioned
and see if there's anything like it.

Counting up to 50 this time, my idea first gets the even composites:

4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38,
40, 42, 44, 46, 48, 50

and then gets the *odds* that have 3 as a factor:

9, 15, 21, 27, 33, 39, 45

where notice I don't bother with evens that have 3 as a factor, and
then you get the odds that don't have 3 as a factor that do have 5:

25, 35

and that leaves composites that have 7 as a factor, but none of the
smaller primes, where there is just one:

49

and notice that you have a rapidly shrinking count, from a sensible way
to count primes.


Without further comment I post a small program in Pascal that
is on my site since 1995
http://home.hccnet.nl/a.w.m.van.der.horst/pipi.pas
The algorithm is again similar but not quite Legendre method.
DismissedBy(n,p) = Dleg(n,p) - Dleg(n,p-1)

Like the real mathematicians have pointed out, if you are serious
about prime counting you should supplement this with a sieve to
find the small primes.

I think it is a nice little program, but no reason for megalomanic
claims, or even a publication in print.

The explanation is more lucid then James's.

------------------------------------------------------

{ Copyright (c) 1995 by Albert van der Horst }

program pi;

uses Crt;

{ This program calculates how many primes there are less or equal a given
number. This function is called pi(n).
It only demonstrates the algorithm. The range allowed for the number `n'
is limited by the signed integers Pascal can handle: 32675.
It is based on a careful analysis of the Eratosthenes' sieve.
In the sieve numbers are dismissed because they are divisible by
prime numbers.
We will use the notion of "dismissing by".
A number is "dismissed by" a prime, if that prime is its smallest

divider.

The numbers smaller than or equal to `n' are divided in disjunct sets
of numbers dismissed by a certain prime, and the number 1.
A large primes p<=n (in fact all primes larger than sqrt(n)) form such
a set with only one member. (The definition implies that a prime is
dismissed by itself.)
An example of the numbers <=17 and their dismissing primes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
- 2 3 2 5 2 7 2 3 2 11 2 13 2 3 2 17
By inspection we see that Dismiss(17,3) should return 3.

}

{ IsPrime is an auxiliary function that tells whether `n' is prime.
}

Function IsPrime( n: integer):boolean;
var
i: integer; { Just a counter }

begin
IsPrime := True;
if n>=4 then
for i:=2 to n do
if n/i<i then
exit
else if n mod i = 0 then
begin
IsPrime := False;
exit
end
end;

{ `DismissedBy' counts the numbers less than `n' dismissed by the prime

`p'.

See explanation at the beginning.
}
Function DismissedBy( n,p: integer):integer;
var
nsmall: integer; { The amount of multiples of `p' <=n }
p2: integer; { a prime smaller than `p' }
d: integer; { return value, dismissed }
begin
nsmall := n div p;
if nsmall<p then
begin
DismissedBy :=1;
exit
end;

{ m is dismissed by p iff m div p is NOT dismissed by some p1 <p }
{ Start counting them }
d := nsmall; { `nsmall' multiples are all candidates }

{ Subtract all those dismissed by smaller primes }
for p2:=2 to p-1 do
if IsPrime(p2) then
d := d - DismissedBy( nsmall, p2 );

DismissedBy :=d
end;

{ Returns PI the number of primes smaller or equal to `N'
We may count the primes < N as follows.
Start with N-1 because all numbers except 1 could be primes.
Subtract all those dismissed by some prime except that prime
itself.
We may stop the loop at sqrt(n) because from then on,
DismissedBy(n,p2) = 1 . From then on, we subtract one but add one
again for the prime itself, so the running total does not change.
Alternatively you may think of dismissing as the process of sieving
using Erathosthenes' sieve, where you may stop at the sqrt(n).

Stopping at the root is the crux.
You could of course just test all numbers <N for primality
using IsPrime().
}

Function CountPr( N:integer ):integer;
var r:integer; { result }
var p:integer; { running prime }

begin
r := N-1; { All except one are prime candidates }

for p:=2 to n do
if p*p>n then
begin
CountPr := r;
exit
end
else if IsPrime(p) then
begin
r := r - DismissedBy( n, p );
r := r+1; { Correct: the prime itself was also dismissed }
end;

CountPr := r;
end;

var N : integer;

begin {countpr}
repeat
Writeln('Give a number ...');
read(N);
Writeln('The number of primes <=',N,' is ',
CountPr(N) );
until N=0;
end.
------------------------------------------------------


James Harris





--
--
Albert van der Horst,Oranjestr 8,3511 RA UTRECHT,THE NETHERLANDS
One man-hour to invent,
One man-week to implement,
One lawyer-year to patent.

.





  Page 1 of 1

1

 


Related Articles
JSH: But why? Questioning primes.
Mathforge.net :: FermiLab, Escultura, Twin Primes and the Deadly Rooms of Death
testing primes with dedanoe's method of reductive reminders -- never faster ad never better
Closing the Gap on Twin Primes
#161 comparing the world's tiniest Primes with the world's largest
De facto censorship, counting primes
Re: infinitude of quad, hex, deca primes; even number metric Re: one page proof of the Infinitude of Twin Primes
Primes issue, significant problem
About random, primes and statistics
#8# new book "Correcting Present Day Mathematics and Setting...." (8) proving Infinitude of Twin Primes and other proofs
Re: Counting primes, full story?
Re: Counting primes, full story?
Difference equations, primes, physics' dreams
Primes, Palindromes, and Pyramids
Quantum Gravity 155.3: Generalization to Primes and Quantum Hamiltonians by H. C. Rosu
 

NEWER

pg.1612     pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER