Post Reply 
Fun with Primes (Sum, Reciprocal Sum, Reciprocal Product)
10-23-2016, 04:14 AM
Post: #1
Fun with Primes (Sum, Reciprocal Sum, Reciprocal Product)
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
Code:
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
Code:
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
Code:
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
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: