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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. The sixth line, fi;, tells Maple that this is the end of the if .. then .. statement.
  7. 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.
  8. The eight line, print(num, evalf(num/n),evalf(1/ln(n)));, tells Maple to print three numbers:
  9. The ninth line, end:, indicates to Maple that this is the end of the program.

To test our function, we type

  > pnt(1000);

[Maple Math]

There are 168 prime numbers less than 1000 and the program calculates 168/1000 = .168 and 1/ln(1000) =.1447648273.


References.

  1. Courant and Robbins, pp. 27-30