Objectives:
In this tutorial, we discuss the Prime Number Theorem
and a Maple program that illustrates the results of the Prime Number Theorem.
In addition, the Maple command evalf is
discussed and used in the program. After working through these materials, the
student will understand the content of the Prime Number Theorem and will be
able to use the evalf command in a Maple
program.
The Prime Number Theorem.
If A(n)
is the number of primes less than or equal to n
, then the Prime Number Theorem states that the quotient
A(n)/n is asymptotically
equal to l/ln(n) .
The following Maple program lets us investigate this theorem.
|
> pnt:= proc(n)
> local i, num;
> num:= 0;
> for i from 2 to n do
> if isprime(i) then
num:= num + 1
> fi;
> od;
> print(num, evalf(num/n),evalf(1/ln(n)));
> end;
|
Comments on the program:
- This program defines a function which we have called pnt.
The first line of the program, pnt:= proc(n),
defines the name of the program and indicates that it is a procedure
which can be thought of as another name for a function. The n
is the name of the variable that represents an element of the domain of pnt.
- The second line, local i, num;,
tells the program that we are defining new variables called i
and num. These are local variables
which means that the value of i and
num that
are assigned by the program are only valid in this program.
- The third line, num:= 0;,
sets the value of the variable num
equal to 0. num
will contain the number of primes that we find.
- The fourth line, for
i from 2 to n do, tells Maple to start with
the value of i
= 2. This command tells Maple that as long as i
is less than or equal to n, execute what
follows the do statement up to the od;
statement. As will be noted below the value of i
will change there. When i becomes greater
than n, Maple drops out of the loop to the
line following the od; statement. Mathematically,
we will be checking every integer between 2 and n
to see if it is prime.
- The fifth line, if isprime(i) then num:= num + 1
, tells Maple that if i is prime then Maple
is to add 1 to the current value of num
and store the answer in num. If i
is not prime then the program moves to the next line.
- The sixth line, fi;, tells Maple that
this is the end of the if .. then .. statement.
- The seventh line, od;, tells Maple that
this is the end of the for .. from .. to .. do
statement. When Maple reaches this statement, the variable i
is increased by 1.
- The eight line, print(num, evalf(num/n),evalf(1/ln(n)));,
tells Maple to print three numbers:
- num - the number of primes less than
or equal to n,
- evalf(num/n) - evalf
converts the fraction num/n to a floating
point number or decimal, and
- evalf(1/ln(n)) - evalf
evaluates the reciprocal of the natural log of n
as a floating point number or decimal.
- The ninth line, end:, indicates to Maple
that this is the end of the program.
To test our function, we type
|
> pnt(1000);
|
There are 168 prime numbers less than 1000 and the program calculates 168/1000
= .168 and 1/ln(1000) =.1447648273.
References.
- Courant and Robbins,
pp. 27-30