Saturday, October 22, 2016

HP Prime: Fun with Primes

HP Prime:  Fun with Primes

Prime Numbers

A positive integer is a prime number if there the only integers that can divide that number evenly (without remainder) is 1 and itself.

Fun facts:

*  1 is not a prime number.
*  2 is the only even prime number.
*  5 is the only prime number that ends in 5. 
*  No prime number has a 0, 4, 6, or 8 as the last digit.

Sum of the Fist n Primes

Let p be a prime number.  That is, p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, …}

The sum of the first prime numbers is:  Σ p_k from k = 1 to n

HP Prime Program SPRIMES:  Sum of the First n Primes
EXPORT SPRIMES(n)
BEGIN
// 2016-10-22 EWS
// Sum of the first n primes

LOCAL t,p,k;

IF n≤1 THEN
RETURN 2;
ELSE
t:=2;
p:=2;

FOR k FROM 2 TO n DO
p:=CAS.nextprime(p);
t:=p+t;
END;

RETURN t;
END;
END;




Sum of the First n Prime Reciprocals

Σ 1/(p_k) from k = 1 to n


HP Prime Program ISPRIMES:  Sum of first n Prime Reciprocals
EXPORT ISPRIMES(n)
BEGIN
// 2016-10-22
// Sum of reciprocal of primes

LOCAL t,p,k;
n:=IP(n);

IF n≤1 THEN
RETURN 2;
ELSE
t:=2¯¹;
p:=2;

FOR k FROM 2 TO n DO
p:=CAS.nextprime(p);
t:=p¯¹+t;
END;

RETURN t;
END;


END;

It does not appear that there series of sums do not converge as n approaches ∞ (infinity).

ISPRIMES(25) returns 1.80281720104
ISPRIMES(50) returns 1.96702981491
ISPRIMES(100) returns 2.10634212145
ISPRIMES(10000) returns 2.70925824876



Product of the First n Prime Reciprocals

Π 1/(p_k) from k = 1 to n

HP PRIME Program IPPRIMES
EXPORT IPPRIMES(n)
BEGIN
// 2016-10-22
// Product of reciprocal of primes

LOCAL t,p,k;
n:=IP(n);

IF n≤1 THEN
RETURN 2;
ELSE
t:=2¯¹;
p:=2;

FOR k FROM 2 TO n DO
p:=CAS.nextprime(p);
t:=p¯¹*t;
END;

RETURN t;
END;
END;

Unlike ISPRIMES, IPPRIMES approaches 0 as n approaches ∞.

IPPRIMES(25) returns 4.33732605429E-37
IPPRIMES(50) returns 5.24156625851E-92
IPPRIMES(100) returns 2.12227225409E-220
IPPRIMES(10000) returns 0



This blog is property of Edward Shore, 2016.



No comments:

Post a Comment

HP Prime and Casio fx-CG50: Trapezoid Midsegment, Height, Area

HP Prime and Casio fx-CG50:  Trapezoid Midsegment, Height, Area The program TRAPEZ calculates the following: Midsegment leng...