Post Reply 
Leibniz formula for π on HP 35s
05-06-2020, 02:45 PM
Post: #1
Leibniz formula for π on HP 35s
I got inspired by this vintage computer race to use the slow-converging alternating Leibnitz series method to approximate π.

It's a few years old, but in the video an HP 9825B from 1980 takes 60 seconds to compute π to four decimal places, while an Android Fairphone 2 from 2015 takes 6 seconds to make the same computation. The HP was programmed in HPL; the Android in Python. Obviously the 2.26 GHz droid could run a lot faster, but it's running an interpreted language with lots of overhead.

How well can the underpowered 33 kHz processor in the HP 35s perform in RPN? My first attempt took 4 minutes and 45 seconds, but this program, my fifth revision, is 28 instructions long and takes 2 minutes and 40 seconds (160 seconds) to calculate 4 digits of π on the HP 35s:

Code:

L001    LBL L
L002    0
L003    STO P
L004    1
L005    STO L
L006    0.84501
L007    STO Z
L008    RCL L
L009    1/x
L010    RCL L
L011    2
L012    +
L013    1/x
L014    -
L015    STO+ P
L016    4
L017    STO+ L
L018    ISG Z
L019    GTO L008
L020    RCL P
L021    0.78525
L022    x>y?
L023    GTO L006
L024    4
L025    RCLx P
L026    2
L027    RCL+ L
L028    RTN

Controlling for clockspeed, that's 68x more efficient than the HP 9825B and 2750x more efficient than the smartphone! Of course, I'm cheating a little by running four loops of precisely 845 iterations, but even with a less arbitrary/optimized value of 1000, it's almost as fast.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Leibniz formula for π on HP 35s - lipoff - 05-06-2020 02:45 PM



User(s) browsing this thread: 1 Guest(s)