Sunday, November 13, 2016

TI-89 and HP Prime: Approximation Digits of π to Lots of Digits

TI-89 and HP Prime:  Approximation Digits of π to Lots of Digits 

Ways to find digits of π

Four steps with a calculator with CAS, which allows computation with large integers:

1.  Take a series and multiply each term by 10^n, where n is the number of digits desired. The exact form of each calculation 
2. Take the integer portion of the sum. Make any adjustments when necessary. 
3. Convert the sum to a string.  Insert a decimal point when appropriate. 
4. Return the answer as a string. 

There are three methods that are demonstrated, one routine is presented for the TI-89 and the HP Prime.  All programs presented takes two arguments: n number of digits, m is the number of iterations. Remember that m must be sufficiently high to get an accurate computation of π. 

In the TI-89 programs, (C) marks a comment.  All HP Prime programs on this blog entry are to be run in CAS mode (make sure CAS is checked when creating the program).  

Keep in mind the HP Prime is significantly faster than the TI-89.  

Newton/Euler - newpi

π = 2 * Σ ( 2^k * (k!)^2 / (2*k + 1)!, k, 0, infinity)

TI-89 Program newpi
newpi(n,m)
(C) Newton/Euler π 
Local s,k,t
(C) initialize
0 → t
(C) loop
For k,0,m
t + exact( 10^n * 2^k * (k!)^2 / ( (2*k + 1)! ) ) → t
EndFor
iPart(2*t) → t
string(t) → s
left(s,1) & "." & right(s,n) → s
Disp s
EndPrgm

HP Prime CAS Program newpi
#cas
newpi(n,m):=
BEGIN
LOCAL t,k,s;
// Netwon/Euler π 
// 2016-11-13 EWS
t:=0;
FOR k FROM 0 TO m DO
t:= t + exact( 10^n * 2^k * (k!)^2 /  ( (2*k + 1)! ));
END;
t:= IP(2*t);
// string, left, right 
// must be in lower case
s:= string(t);
s:= left(s,1) + "." + right(s,n);
return s;
END;
#end

newpi(20, 175) returns "3.14159265358979323846"

Arctangent - arctanpi

π = Σ ( 2^(k+1) / ( COMB(2*k, k) * (2*k +1) ), k, 0, infinity)

TI-89 Program arctanpi
arctanpi(n,m)
(C) Arctan π 
Local s,k,t
(C) initialize
0 → t
(C) loop
For k,0,m
t + exact( 10^n * 2^(k + 1) / ( nCr(2*k,k) * (2*k+1) ) ) → t
EndFor
iPart(t) → t
string(t) → s
left(s,1) & "." & right(s,n) → s
Disp s
EndPrgm

HP Prime CAS Program arctanpi
#cas
arctanpi(n,m):=
BEGIN
LOCAL t,k,s;
// Arctan π 
// 2016-11-13 EWS
t:=0;
FOR k FROM 0 TO m DO
t:= t + exact( 10^n * 2^(k+1)/(COMB(2*k,k) * (2*k + 1)));
END;
t:= IP(t);
// string, left, right 
// must be in lower case
s:= string(t);
s:= left(s,1) + "." + right(s,n);
return s;
END;
#end

arctanpi(25, 200) returns "3.1415926535897932384626433"

Bailey-Borwein-Plouffe Formula (BBP) - bbppi

π = Σ ( 1/16^k * ( 4/(8*k +1) - 2/(8*k + 4) - 1/(8*k + 5) - 1/(8*k + 6) ), k, 0, infinity)

TI-89 Program bbppi
bbppi(n,m)
(C) BBP π 
Local s,k,t
(C) initialize
0 → t
(C) loop
For k,0,m
t + exact( 10^n/16^k * ( 4/(8*k + 1) - 2/(8*k + 4) - 1/(8*k + 5) - 1/(8*k + 6) ) ) → t
EndFor
iPart(t) → t
string(t) → s
left(s,1) & "." & right(s,n) → s
Disp s
EndPrgm

HP Prime CAS Program bbppi
#cas
bbppi(n,m):=
BEGIN
LOCAL t,k,s;
// Netwon/Euler π 
// 2016-11-13 EWS
t:=0;
FOR k FROM 0 TO m DO
t:= t + exact( 10^n/16^k * ( 4/(8*k + 1) - 2/(8*k + 4) - 1/(8*k + 5) 
- 1/(8*k + 6) ) );
END;
t:= IP(t);
// string, left, right 
// must be in lower case
s:= string(t);
s:= left(s,1) + "." + right(s,n);
return s;
END;
#end

bbppi(25,200) returns "3.1415925635897932846"


Source:  Wikipeida.  "Approximations of π"  https://en.m.wikipedia.org/wiki/Approximations_of_π. Retrieved November 12, 2016

This blog is property of Edward Shore, 2016. 

Spotlight: Sharp EL-5200

  Spotlight: Sharp EL-5200 As we come on the 13 th (April 16) anniversary of this blog, I want to thank you. Blogging about mathematic...