Just recently I stumbled across Katie Wasserman's fine article
99 Digits of PI on an HP 32SII
which I apreciated a lot. It made me have a look again at the different algorithms to calculate
Pi. After implementing a RPN-version of the Gauss AGM algorithm for the 35s I was curious on
how to do the ALG-version. Here's the result of both:
RPN ALG(inspired by algorithm 7.5 from Arndt & Haenel, Pi-unleashed)G001 LBL G H001 LBL H
G002 1 H002 1>A
G003 STO A H003 3>I
G004 3 H004 SQRT(0.5>P>S)>B
G005 STO I H005 S-SQ(A-B)*P>S
G006 0.5 H006 2*P>P
G007 STO P H007 (A+B)/2
G008 STO S H008 SQRT(A*B)>B
G009 SQRT H009 REGY>A
G010 STO B H010 DSE I
G011 RCL- A H011 GTO H005
G012 x2 H012 SQ(A+B)/(2*S)
G013 RCL* P H013 RTN
G014 STO- S
G015 RCL A LN=115
G016 RCL+ B
G017 2
G018 STO* P
G019 /
G020 x<> A
G021 RCL* B
G022 SQRT
G023 STO B
G024 DSE I
G025 GTO G011
G026 RCL+ A
G027 x2
G028 RCL/ S
G029 2
G030 /
G031 RTNLN=100
Now if you run both variants you will find that H is about 4 times slower than G.
Also H seems to use more memory than G. On the other hand H might be easier to
read. But you have to scroll to be able to read the whole lines.
What I don't understand is why is H so slow? I mean both are kind of slow but H
is realy bad. Hey, there are only 3 iterations and it takes about 4 seconds!
Being curious about the performance I implemented the same algorithm for my 11c as well:
01 LBL A 21 SQRTNot to my surprise it's considerably slower taking about twice the time of H.
02 3 22 x<>y
03 STO I 23 R^
04 2 24 x2
05 1/x 25 RCL 1
06 STO 0 26 *
07 STO 1 27 STO- 0
08 SQRT 28 RDN
09 ENTER 29 2
10 ENTER 30 STO* 1
11 ENTER 31 /
12 1 32 DSE
13 LBL 0 33 GTO 0
14 - 34 +
15 R^ 35 x2
16 LSTx 36 RCL 0
17 + 37 /
18 R^ 38 2
19 LSTx 39 /
20 * 40 RTN
But when I ran the same program on a 42s I was amazed: Though it's slower than G
it beats H by far.
Twenty years later and not much improvement concerning the speed! Does anybody
know why? Is it so difficult to construct a fast calculator?
I must admit that I'm quiet happy with the 35s in spite of the issues already
mentioned in this forum. But I'd really like to have a calculator that is fast,
e.g. counts to a million in less than a second.
In other interpreted languages it's possible:
> time perl -e 'for ($i=0; $i<1e6; $i++) {}'real 0m0.219s
user 0m0.199s
sys 0m0.003s
So why can't we have that in a calculator as well?
Thomas