The Museum of HP Calculators

HP Forum Archive 17

[ Return to Index | Top of Index ]

Computing many digits of Pi
Message #1 Posted by Juan Pablo Martinez (Spain) on 11 Sept 2007, 6:36 a.m.

This subject was dealt with the year 2004 by Gene Wright (HP Forum Archives 14). As a newcomer, I only now have noticed the archive. It is said there that there are two programs to compute many digits of pi with the TI-95 calculator, one by Hewlet Ladd (1987) and another by Palmer Hanson (2004). Some members asked then for the Hanson listing, but he answered that was not ready to type the 750 steps by hand, and that he would send an attached copy of the printed listing if the interested people supply him his e-mail address. Well, I would like also to have this listing and that by Hewlet Ladd. Can anyone supply these listings?. In the same archive is a post by Gordon Dyer showing a program to compute pi on a HP-42. However, the program gives only 11 digits. Does anyone know a similar program for the same calculator but computing as many digits as possible? Does anyone know a similar arbitrary precisión program to compute many digits of pi on any calculator (HP or other brands) using only the Machin arctangent formula (pi = 16/arctg (5) - 4/arctg (239))? Many thanks in advance

      
Re: Computing many digits of Pi
Message #2 Posted by Jeff O. on 11 Sept 2007, 8:52 a.m.,
in response to message #1 by Juan Pablo Martinez (Spain)

Katie Wasserman used the formula:

Pi = 20 * arctan(1/7) + 8 * arctan(3/79)

to calculate 96 (correct) digits of pi on a 32SII as described in this article. I would think it would be relatively straight-forward to convert her program to run on the 42S. I've been meaning to convert it to run on the 35s. (That is, thinking “gee, I wonder if Katie’s program could be converted to the 35s, and if so, how many digits could it calculate.”) Katie's program saves 9 digits of pi in each 12-digit register, so with 800 registers, each capable of holding three 12-digit numbers, it should be possible to get 21,600 digits. (Assuming the program would fit with that many data registers allocated. Seems like it ought to, since the original fit in the very limited memory of the 32SII, but I have not really checked to see.)

            
Re: Computing many digits of Pi
Message #3 Posted by Katie Wasserman on 11 Sept 2007, 9:54 p.m.,
in response to message #2 by Jeff O.

The program for the 32Sii needs some modification in order to extend it for many more registers. The 9 digits/register was necessary to avoid overflows when just 99 digits are computed. You'll probably need to cut back to 6 digits/register if you're going put this on the 35s and try for 10000+ digits. More to the point, the run time goes up roughly as the square of the number of digits and the 35s isn't much faster than the 32sii so it's going to take.... let's see.....

11 (minutes for around 100 digits) * 9/6 (number of digits per register correction * 100^2 (100 times more digits that go as the square) = ......

pretty close to forever!

The 35s just isn't fast enough to do much useful calculation with all those registers. Even a good (NlogN) sorting routine would likely take longer than anyone would want to wait.

-Katie

                  
Re: Computing many digits of Pi
Message #4 Posted by Juan Pablo Martinez (Spain) on 12 Sept 2007, 8:38 a.m.,
in response to message #3 by Katie Wasserman

Many thanks Katie

Of course, you are right. Your program is a little wonder, but I know that to compute over a few thousands of digits on any calculator a long job if using classical algorithms linked to trigonometric formulas. I am not sure if the translation to other calculators deserves trying.

Thanks anyway

                  
Re: Computing many digits of Pi
Message #5 Posted by Jeff O. on 12 Sept 2007, 9:32 p.m.,
in response to message #3 by Katie Wasserman

Quote:
More to the point, the run time goes up roughly as the square of the number of digits and the 35s isn't much faster than the 32sii so it's going to take.... let's see.....pretty close to forever!
I did not realize this about the technique you implemented on the 32sII. I guess I should have studied it a bit before flippantly postulating about computing 20,000+ digits on the 35s.

(I probably should have realized. After all, if calculating pi was easy, it would not have worked as an effective method to drive a malevolent entity from the computer of the Enterprise. I sure hope that Spock was the only one authorized to instruct the computer to use all resources, to the exlusion of all other processes if I recall correctly, for a particular task.)

                        
Re: Computing many digits of Pi
Message #6 Posted by Katie Wasserman on 14 Sept 2007, 9:47 a.m.,
in response to message #5 by Jeff O.

There are methods for computing pi that converge quadratically, of course they are also grow linearly with the number of digits required. So, they're ultimate convergence is N*Log(N). I'm not sure if Spock was aware of these methods when he issued his command, but he still would have gotten his intended result -- to be expected from "the best first officer in the fleet" to quote Dr. McCoy.

            
Re: Computing many digits of Pi
Message #7 Posted by Juan Pablo Martinez (Spain) on 12 Sept 2007, 8:24 a.m.,
in response to message #2 by Jeff O.

Many thanks. Katie's program is wonderful given the small amount of memory of the HP-32. I will try to translate it to TI-95. However, it does not use the Machin's formula, but one of the many related ones.

      
Re: Computing many digits of Pi
Message #8 Posted by Vieira, Luiz C. (Brazil) on 11 Sept 2007, 9:00 a.m.,
in response to message #1 by Juan Pablo Martinez (Spain)

Ola, Juan; ¿que tal?

I'd sugget trying these threads (in addition to Jeff´s):

Yet another not quite pi puzzle
560 Digits of PI in the HP41
Computing PI -- a simple programming problem (Katie's post, mentioned by Jeff)
CALCULATING MANY DIGITS OF PI (This one you have already read, sorry...)

I guess you may find what you need.

Cheers.

Luiz (Brazil)

Edited: 11 Sept 2007, 9:06 a.m.

            
Re: Computing many digits of Pi
Message #9 Posted by Juan Pablo Martinez (Spain) on 12 Sept 2007, 8:29 a.m.,
in response to message #8 by Vieira, Luiz C. (Brazil)

Muito obrigado, Luiz I have followed your links. Either i knew them already or these are not useful for my purpose. Thanks again

Juan Pablo

      
Re: Computing many digits of Pi
Message #10 Posted by Bill (Smithville, NJ) on 11 Sept 2007, 10:00 a.m.,
in response to message #1 by Juan Pablo Martinez (Spain)

Here's some more interesting forum message links for calculating PI on both the HP-41 and the HP-42:

announcing "deep pi"

Deep PI - On a 42S

Deep Pi on the HP-41cx

Deep Pi - 42S - Some Results

Another Slice of PI

One more slice of PI

Have Fun,

Bill

            
Re: Computing many digits of Pi
Message #11 Posted by Juan Pablo Martinez (Spain) on 12 Sept 2007, 8:40 a.m.,
in response to message #10 by Bill (Smithville, NJ)

Many thanks, Bill

The links are very useful. I am astonished of the cleverness of the deep.pi program. It would be nice to know used

      
Re: Computing many digits of Pi
Message #12 Posted by Etienne Victoria on 11 Sept 2007, 5:19 p.m.,
in response to message #1 by Juan Pablo Martinez (Spain)

Hi Juan Pablo!

The following vintage program in french gives 128 digits of PI:

Que j'aime à faire apprendre ce nombre utile aux sages !	3 1 4 1 5 9 2 6 5 3 5
Immortel Archimède, artiste ingénieur,	         8 9 7 9
Qui de ton jugement peut priser la valeur ?	 3 2 3 8 4 6 2 6
Pour moi, ton problème eut de pareils avantages.4 3 3 8 3 2 7 9
Jadis, mystérieux, un problème bloquait	        5 0 2 8 8
Tout l'admirable procédé, l'œuvre grandiose	4 1 9 7 1 6 9
Que Pythagore découvrit aux anciens Grecs.	3 9 9 3 7 5
0 quadrature ! Vieux tourment du philosophe	1 0 5 8 2 9
Insoluble rondeur, trop longtemps vous avez	9 7 4 9 4 4
Défié Pythagore et ses imitateurs.                      5 9 2 3 0
Comment intégrer l'espace plan circulaire ?	7 8 1 6 4 0
Former un triangle auquel il équivaudra ?	        6 2 8 6 2 0
Nouvelle invention : Archimède inscrira	        8 9 9 8
Dedans un hexagone ; appréciera son aire	        6 2 8 0 3 4
Fonction du rayon. Pas trop ne s'y tiendra :	8 2 5 3 4 2 1 1 7
Dédoublera chaque élément antérieur ;	        0 6 7 9
Toujours de l'orbe calculée approchera ;	        8 2 1 4 8 0
Définira limite ; enfin, l'arc, le limiteur	        8 6 5 1 3 2 8
De cet inquiétant cercle, ennemi trop rebelle	2 3 0 6 6 4 7
Professeur, enseignez son problème avec zèle	0 9 3 8 4 4

It should run in less one minute on a well trained brain :-))

Cheers.

Etienne

            
Re: Computing many digits of Pi
Message #13 Posted by Juan Pablo Martinez (Spain) on 12 Sept 2007, 8:47 a.m.,
in response to message #12 by Etienne Victoria

You are right, Etienne. This is perhaps the fastest algorithm, but it is rather difficult to implement it in a calculator. I knew already the poem by heart, but only the first lines, about 60 digits. There is plenty of similar texts in different languages, helping to memorize even 1000 digits of pi. Of course, there is still a faster algorithm, to look at the many existing printed values, to look in the web for any of the several pi pages, or to use any of the available multiprecision programs, either Derive, Maple, Mathematica, etc. However, none of these ways has much to do with calculators. Many thanks

      
Re: Computing many digits of Pi
Message #14 Posted by Palmer O. Hanson, Jr. on 12 Sept 2007, 3:58 p.m.,
in response to message #1 by Juan Pablo Martinez (Spain)

I have a pasteup available for my 2004 program for the TI-95. It is a conversion of the TI-59 program by Bob Fruit which appeared in V7N4/5P27 ff of TI PPC Notes. Since you keep your e-mail address private you will have to send your address to me at pohmwh@earthlink.net if you want a copy. I haven't figured out how to attach anything to the secure communication through the museum.

I have not found a pasteup of the Hewlett Ladd program for the TI-95. It is a convwersion of the Science et Vie program for the TI-59 which appeared in V8N3P8-9 of TI PPC Notes. For a translation of the Science et Vie article go to V8N4P21-24 of TI PPC Notes.

            
Re: Computing many digits of Pi
Message #15 Posted by Xerxes on 12 Sept 2007, 5:05 p.m.,
in response to message #14 by Palmer O. Hanson, Jr.

It would be nice, If you can send me the TI-95 version too. Thank you.

            
Re: Computing many digits of Pi
Message #16 Posted by Juan Pablo Martinez (Spain) on 13 Sept 2007, 4:49 a.m.,
in response to message #14 by Palmer O. Hanson, Jr.

Many, many thanks! Finally I managed to contact you. I did not realize that my e-mail address was kept private. Here is it: jpmr...ipe.csic.es (with the @ sign instead the dots). I would be very grateful if you send me the paste. Besides several HP calculators I still own and use an old TI95. I wonder if your program could be changed to allow the use of either supplementary memory modules up to 32 K or even data recorded in magnetic tape.

Thanks again

                  
Re: Computing many digits of Pi
Message #17 Posted by Palmer O. Hanson, Jr. on 13 Sept 2007, 9:14 a.m.,
in response to message #16 by Juan Pablo Martinez (Spain)

I have the 2004 program in an 8K RAM module. I don't think I ever had it on tape since my tape reader isn't working.

I sort of remember having the Hewlett Ladd program on tape but I haven't been able to find it. It is not on a RAM module. I have found a reference in which Hewlett indicated that his program was a translation of a TI-59 program from V8N4P26 of TI PPC Notes, that it was only 296 bytes and would calculate up to 1573 digits.

      
Re: Computing many digits of Pi
Message #18 Posted by Egan Ford on 18 Sept 2007, 10:35 p.m.,
in response to message #1 by Juan Pablo Martinez (Spain)

Using the Spigot Algorithm from Pi Unleashed + HPGCC I can compute 15000 digits of PI in 412 seconds on my 50g. If you are interested I can send you the binary so that you do not need to compile and install the ARM Toolbox. NOTE: Real 50g/49g+ required.

To use:

15000 pidf
Output to stack:
bytes used: 210056
   time(s): 412
    digits: 15000
  digits/s: 36.41
SD card will have file PIDIGITS.TXT with the output formatted with 32 digits/line, recall to stack with:
3:PIDIGITS.TXT RCL
Up Arrow VIEW to see all digits.

NOTE: HPGCC binaries can be large. Best to store on SD card and run with:

3:pidf EVAL
Put that in a small UserRPL script and save to main memory.

You can hold down any key (but ON) to stop the run and collect partial output. When done exit with ON.

/*
pidf.c

Get n from stack and compute n number of pi digits using Spigot method from Pi Unleashed by Jorg Arndt & Christoph Haenel.

Mem allocated = ((n/4)+1)*14 * 4 bytes

Return to stack statistics, e.g.

(n=5000):

bytes used: 70056 time(s): 46 digits: 5000 digits/s: 108.70

(n=15000):

bytes used: 210056 time(s): 412 digits: 15000 digits/s: 36.41

Only HP specific comments, read book for algorithm details.

*/

#include <hpgcc49.h> //the standard HP lib

int main(void){ int *a; int b; int c; int d = 0; int e = 0; int f = 10000; int g; int h = 0; int start; int end; int cc = 0; char buf[40]; int ndigits; FILE *fh; char *filename = "pidigits.txt";

sys_slowOff(); //max speed clear_screen(); //clear the screen

if((fh = fopen(filename,"w"))) { } else { printf("Error opening %s\n",filename); beep(); sys_slowOn(); //normal speed WAIT_CANCEL; //loop until ON pressed return(1); }

ndigits = sat_pop_zint_llong(); //get ndigits from stack, must be int > 0 if(ndigits > 0) { } else { printf("Number of PI digits must be an\ninteger > 0!\n"); beep(); sys_slowOn(); //normal speed WAIT_CANCEL; //loop until ON pressed return(1); } c=(ndigits/4+1)*14; a=malloc(c*sizeof(*a));

start = sys_RTC_seconds(); //get start time in seconds since 1/1/1970 while ((b=c-=14) > 0) { //logic, compute 4 digits of pi at a time then display while(--b > 0) { d *= b; if (h == 0) d += 2000 * f; else d += a[b] * f; g=b+b-1; a[b] = d % g; d /= g; } printf("%04d", e + d/f); fprintf(fh,"%04d", e + d/f); cc+=4; if(cc % 32 == 0) { printf("\n"); fprintf(fh,"\n"); } if(keyb_isAnyKeyPressed()) //hold any key to stop, do not use ON break; d = e = d % f; h = 4; } end = sys_RTC_seconds(); //get end time in seconds since 1/1/1970 fprintf(fh,"\n"); fclose(fh); printf("\n\n");

sprintf(buf,"bytes used: %d",(ndigits/4+1)*14*(int)sizeof(*a)); printf("%s\n",buf); sat_stack_push_string(buf); //push string to stack

sprintf(buf,"time(s): %d",end-start); printf(" %s\n",buf); sat_stack_push_string(buf); //push string to stack

sprintf(buf,"digits: %d",cc); printf(" %s\n",buf); sat_stack_push_string(buf); //push string to stack

if(end-start == 0) sprintf(buf,"digits/s: NAN"); else sprintf(buf,"digits/s: %.2f",(float)cc/(float)(end-start)); printf(" %s",buf); sat_stack_push_string(buf); //push string to stack

beep(); sys_slowOn(); //normal speed WAIT_CANCEL; //loop until ON pressed return(0); }

Edited: 24 Sept 2007, 11:37 a.m. after one or more responses were posted

            
Re: Computing many digits of Pi
Message #19 Posted by Rodger Rosenbaum on 19 Sept 2007, 8:02 a.m.,
in response to message #18 by Egan Ford

I have a xerox of an old paper about the computation of Pi, titled "Some Comments on a NORC Computation of Pi". I think the paper dates from around 1956.

The authors say in the first paragraph:

"Among the problems suggested as demonstration routines for the NORC (Naval Ordnance Research Computer) was the calculation of Pi to a large number of digits. In 1949, Pi was calculated to 2035 digits on the ENIAC. The present computation on the NORC, which was carried out by the authors at the Watson Scientific Computing Laboratory, produced 3089 digits. This limit was chosen since the entire calculation could be contained in the NORC's high speed memory (2000 locations). The program was designed to produce any number of digits up to this limit."

They say that the computation took 13 minutes.

I wonder what kind of memory the NORC had? All of "2000 locations". And how much power was consumed during the computation?

In 2007, using the power provided by a few penlight cells, Pi can be computed to 15,000 digits in about 7 minutes. On a pocket sized computer with over 200,000 memory "locations"!

Mathematica keeps the first 10,000 digits of Pi pre-calculated and stored in memory. So if a calculation needs up to 10,000 digits, there's no delay in calculating them; they're just fetched from memory.

If more digits are needed, they're calculated using the Chudnovsky formula. On my laptop, Mathematica takes 3.5 seconds to calculate 1,000,000 digits of Pi, and 58 seconds to calculate 10,000,000 digits. And, no doubt, using far less power than the ENIAC or NORC did.

This is progress.

                  
Re: Computing many digits of Pi
Message #20 Posted by Egan Ford on 19 Sept 2007, 9:38 a.m.,
in response to message #19 by Rodger Rosenbaum

The Spigot method isn't the fastest. But it is small, does not require MP or FP math (integers only), and you get to watch the action.

If I have time I'll try out Chudnovsky.

            
Re: Computing many digits of Pi
Message #21 Posted by Juan Pablo Martinez (Spain) on 24 Sept 2007, 4:11 a.m.,
in response to message #18 by Egan Ford

Many thanks for your advice. Do you know if the program can be run also in a HP-49g?(not a HP-49g+)

Juan Pablo

                  
Re: Computing many digits of Pi
Message #22 Posted by Egan Ford on 24 Sept 2007, 10:58 a.m.,
in response to message #21 by Juan Pablo Martinez (Spain)

AFAIK, the 49g uses the Saturn CPU. You need an ARM-based unit (49g+/50g).


[ Return to Index | Top of Index ]

Go back to the main exhibit hall