Post Reply 
Programming Exercise (HP-15C, 15C LE - and others)
03-31-2014, 10:13 PM
Post: #74
RE: Programming Exercise (HP-15C, 15C LE - and others)
I was impressed with the timings seen on the 42s and 34s using the "two terms at a time" approach. I didn't think a 50g would do as well, so I thought I'd give it a shot to see what might happen.

UserRPL version:
Code:

\<<
   TICKS
   0

   10000.
   1.
   FOR n
      n DUP 1. - * INV
      +
   -2. STEP

   TICKS ROT - B\->R 8192. /
\>>
Final Value: 0.69309718306
Avg. of 5 runs: 42.745 seconds


I was curious as to how different a SysRPL version of this might be, so I tried the following. I've added comments to (hopefully) make it a bit easier to follow the logic.
SysRPL:
Code:

RPL

DEFINE   TotalLAMs         BINT3
DEFINE   RCL_StartTime     3GETLAM
DEFINE   STO_n             2PUTLAM
DEFINE   RCL_n             2GETLAM
DEFINE   STO_sum           1PUTLAM
DEFINE   RCL_sum           1GETLAM

::
   ( no args required )
   CK0NOLASTWD

   ( place local vars on stack )
   SysTime     ( StartTime )
   %% 10000    ( n )
   %%0         ( sum )

   ( bind local vars )
   NULLLAM TotalLAMs NDUPN DOBIND

   ( loop counter - do [n/2] times )
   RCL_n %%>% COERCE #2/

   ( main loop )
   #1+_ONE_DO (DO)

      ( determine current expression value )
      RCL_n DUP %%1 %%- %%* %%1/

      ( add value to running sum )
      RCL_sum %%+ STO_sum

      ( decrement n by 2 )
      RCL_n %%2 %%- STO_n

   LOOP

   ( convert extended real to user real )
   RCL_sum %%>%

   ( determine run time )
   SysTime RCL_StartTime bit- HXS>% % 8192 %/

   ( release local var bindings )
   ABND
;
Final Value: 0.69309718306
Avg. of 5 runs: 20.318 seconds

Not surprisingly, the SysRPL version was noticeably faster. But still not as good as the 42s/34s versions.

Besides the speed difference, the SysRPL version also affords the opportunity to see the 15-digit result of the sum if you don't do the final conversion:
0.693097183059944 (it actually displays as "6.93097183059944E-1"). "Extended Reals" are of no use outside the context of a running SysRPL code object, but it's nice to see all the digits that were retained in the calculations.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming Exercise (HP-15C, 15C LE - and others) - DavidM - 03-31-2014 10:13 PM



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