# Thread: What is pi(x)?

1. ## What is pi(x)?

I was looking into prime numbers and i keep coming upon pi(x). Specifically How many primes are there?. It is obvious that they arent multiplying pi*x. So what are they doing? Im only in trig so please explain it in basic terms.

Thanks!

2. If you scroll down a bit, it defines the function for you ...

$\displaystyle \pi (x)$ = The number of primes less than or equal to $\displaystyle x$

So for example, $\displaystyle \pi (10) = 4$ because there are 4 primes less than or equal to 10 (2, 3, 5, and 7).

3. Originally Posted by o_O
If you scroll down a bit, it defines the function for you ...

$\displaystyle \pi (x)$ = The number of primes less than or equal to $\displaystyle x$

So for example, $\displaystyle \pi (10) = 4$ because there are 4 primes less than or equal to 10 (2, 3, 5, and 7).
Yes, however I want to be able to calculate how many prime numbers there are below a set number.

Such as how would I go about finding how many primes are below 46,000?

4. Originally Posted by Leelguy
Yes, however I want to be able to calculate how many prime numbers there are below a set number.

Such as how would I go about finding how many primes are below 46,000?
You could find them all and count them, other than that you will need one of the approximations for $\displaystyle \pi(x)$, look at the Wikipedia page for a start.

(by the way $\displaystyle \pi(46000)=4761$)

CB

5. Li(x) is the best approximation and it has been proven that it asymptotically approaches pi(x), however Littlewood proved (in 1914?) that while for small n (n < 10^300) Li(x)-pi(x)>0, Li(x)-pi(x) changes signs infinitely many times as n --> infinity.

Maple has the Li function built in.

6. Originally Posted by CaptainBlack
You could find them all and count them, other than that you will need one of the approximations for $\displaystyle \pi(x)$, look at the Wikipedia page for a start.

(by the way $\displaystyle \pi(46000)=4761$)

CB
Yes i have looked at that article and I know that it contains what I am looking for, however I havent taken calculus and I dont understand how they are displaying the formulas. Could you explain it in a way that someone in trig could understand it?

You say that "$\displaystyle \pi(46000)=4761$", but what steps did you go through to get that? I know that it isnt pi*46000.

7. Originally Posted by Leelguy
Yes i have looked at that article and I know that it contains what I am looking for, however I havent taken calculus and I dont understand how they are displaying the formulas. Could you explain it in a way that someone in trig could understand it?

You say that "$\displaystyle \pi(46000)=4761$", but what steps did you go through to get that? I know that it isnt pi*46000.
$\displaystyle \pi(46000)=4761$ isn't something you can calculate exactly with a formula. You can only approximate it using the log integral, Li(n) ($\displaystyle Li(46000)=4795$, which is only a 0.7% error), and the larger the number, the more accurate (percentage-wise) the approximation will be. For example, $\displaystyle Li(100)=30$ and $\displaystyle \pi(100)=25$, for a 17% error. $\displaystyle Li(1000)=178$ and $\displaystyle \pi(1000)=168$, for a 5% error. $\displaystyle Li(1000000)=78628$ and $\displaystyle \pi(1000000)=78498$, for a 0.2% error. All of those calculations were done using Maple 12. The command for finding $\displaystyle \pi(n)$ in Maple is "nops(select(isprime, [$(1..n)]))". Li(n) in Maple is just "Li(n)". If you don't understand calculus, you won't understand the meaning behind the log integral, Li(n). Just know it as the best approximation for$\displaystyle \pi(n)$. There is no particular reason for using the notation$\displaystyle \pi(n)$either. There are only a limited number of letters, and they have to be recycled eventually. 8. Originally Posted by redsoxfan325$\displaystyle \pi(46000)=4761$isn't something you can calculate exactly with a formula. You can only approximate it using the log integral, Li(n) ($\displaystyle Li(46000)=4795$, which is only a 0.7% error), and the larger the number, the more accurate (percentage-wise) the approximation will be. For example,$\displaystyle Li(100)=30$and$\displaystyle \pi(100)=25$, for a 17% error.$\displaystyle Li(1000)=178$and$\displaystyle \pi(1000)=168$, for a 5% error.$\displaystyle Li(1000000)=78628$and$\displaystyle \pi(1000000)=78498$, for a 0.2% error. All of those calculations were done using Maple 12. The command for finding$\displaystyle \pi(n)$in Maple is "nops(select(isprime, [$(1..n)]))". Li(n) in Maple is just "Li(n)".

If you don't understand calculus, you won't understand the meaning behind the log integral, Li(n). Just know it as the best approximation for $\displaystyle \pi(n)$. There is no particular reason for using the notation $\displaystyle \pi(n)$ either. There are only a limited number of letters, and they have to be recycled eventually.
I actually have to recreate this method for finding how many primes are in a number for a programming class. Because of that, using Maple wont help me. Isnt there a mathematical formula of some sorts that I could use to find the amount of primes in a number?

9. The following is NOT HTML code. It was the only way I could get the forum to preserve the indentations needed for Python, which is the language this is written in.

[html]primes = [2]
p=1
i=3
n=input("Up to what number? ")
while i<=n:
for j in primes:
if i%j==0:
break
else:
if j==primes[len(primes)-1]:
primes.append(i)
p=p+1
i=i+1
print ""
print "Number of Primes: " + p[/html]

This code is not very efficient (it takes almost 1 minute for n=100000, compared to about 3 seconds on Maple), but it should at least point you in the right direction.

10. Originally Posted by redsoxfan325
The following is NOT HTML code. It was the only way I could get the forum to preserve the indentations needed for Python, which is the language this is written in.

[html]primes = [2]
p=1
i=3
n=input("Up to what number? ")
while i<=n:
for j in primes:
if i%j==0:
break
else:
if j==primes[len(primes)-1]:
primes.append(i)
p=p+1
i=i+1
print ""
print "Number of Primes: " + p[/html]This code is not very efficient (it takes almost 1 minute for n=100000, compared to about 3 seconds on Maple), but it should at least point you in the right direction.
But it appears that you are just looping through counting each prime. This makes it very inefficient for counting large numbers, and multiple ones at a time (which is what im doing). I had thought that there was a formula used to find the number of prime numbers?

11. I'm not too great at programming, but I would suggest that you check out the Sieve of Eratosthenes. It's supposedly efficient for n<10,000,000.

12. Originally Posted by Leelguy
Yes i have looked at that article and I know that it contains what I am looking for, however I havent taken calculus and I dont understand how they are displaying the formulas. Could you explain it in a way that someone in trig could understand it?

You say that "$\displaystyle \pi(46000)=4761$", but what steps did you go through to get that? I know that it isnt pi*46000.
As I said before it is the number of primes less than or equal to 46000, and as I suggested I counted them.

My Euler code to find the primes less than or equal to some limit is:

Code:
function primes(n)
##
##  function returns a row vector containing the primes
##  less than or equal n
##
##  (c) Xxx Xxxxxx 1997 rewritten 2004 using MATLAB seive alg
##

if size(n)!=[1,1]
"n must be a scalar"
rv=[];
return rv;
endif

p=[1:2:n];
q=length(p);
p(1)=2;

for k=3 to sqrt(n) step 2
if p((k+1)/2)
p(((k*k+1)/2):k:q)=0;
endif
end;

rv=p(nonzeros(p>0));
return rv;

endfunction
Then to find the number one just uses:

Code:
pp=primes(n);
np=length(pp)
CB