Section 21.4 A Slice of the Prime Number Theorem
Subsection 21.4.1 Functions to know
First, we'll review the main function. Think of the prime counting function

Definition 21.4.3.
We call the function given by this formula Chebyshev's theta function:
Sage note 21.4.4. Python can do math too.
We include an interactive version so you can see the code.
xxxxxxxxxx
def theta(x): return sum(math.log(p) for p in prime_range(1,floor(x)+1))
def _(n=100):
show(plot(theta,1,n))
The syntax math.log
is referring to Python's builtin calculation of the natural logarithm, accessible in the math
module. This is sometimes faster and easier to use than Sage's more powerful capabilities, because if you put an integer in Sage's logarithm, it will normally not approximate it. All we want here is an easy approximation, so this should be faster.

xxxxxxxxxx
def theta(x): return sum(math.log(p) for p in prime_range(1,floor(x)+1))
def pnt(n): return prime_pi(n)*log(n)/n
def pntli(n): return prime_pi(n)/Li(n)
def thox(n): return theta(n)/n
def _(end=100000,PNT=['log','Li']):
P = plot(1,(1,end),color='black')
P += plot(thox,(1,end),legend_label='Chebyshev Theta')
if PNT == "log":
P += plot(pnt,(1,end),color='red',legend_label='Prime Number Theorem')
if PNT == "Li":
P += plot(pntli,(1,end),color='red',legend_label='Prime Number Theorem')
show(P)
Proposition 21.4.6.
If the Prime Number Theorem is true, then it is also true that
Proof.
The rest of this section is the proof.
Subsection 21.4.2 Getting a formula with sleights of hand
In order to prove this implication, we will first need a formula telling us more aboutDefinition 21.4.7.
We let
Another way to say this is

prime_pi(x)-prime_pi(x-1)
.
For convenience we write The difference which appears in the the sum in the immediately preceding
formula can be considered as an integral,We have that
is constant on the interval and in particular on any given interval so it may be factored out of any integral from toWe can rearrange and add sums and integrals as usual.
Note that
so the second extra term is zero.
Subsection 21.4.3 Finish the proof
We can divide the formula
xxxxxxxxxx
def _(top=(16,[n^2 for n in [2..10]])):
f(x)=1/log(x)
P=plot(f,1,top+1)
P += line([(2,0),(2,f(2)),(math.sqrt(top),f(2)), (math.sqrt(top),0)], rgbcolor='black')
P += line([(math.sqrt(top),f(math.sqrt(top))), (top,f(math.sqrt(top))),(top,0)], rgbcolor='black')
P += line([(2,0),(2,f(2)),(2+(math.sqrt(top)-2)/top,f(2)), (2+(math.sqrt(top)-2)/top,0)], rgbcolor='red')
P += line([(math.sqrt(top),f(math.sqrt(top))), (math.sqrt(top)+(top-math.sqrt(top))/top, f(math.sqrt(top))), (math.sqrt(top) + (top-math.sqrt(top))/top,0)], rgbcolor='red')
P.show(ymax=2)