Post Reply 
Programming Exercise (HP-15C, 15C LE - and others)
04-01-2014, 02:57 AM
Post: #75
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-31-2014 10:13 PM)DavidM Wrote:  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.

There was a mistake in my reply to Werner which has now been fixed (14 minutes 59 seconds, not 14.59 seconds, which means the two terms at a time version might take about 8 minutes). The HP-42S can never be faster than the HP 50g. Sorry for the confusion!

98.85 seconds on my HP-48GX, and 46.97 seconds on my HP 50g, timed with TEVAL:

Code:

%%HP: T(3)A(D)F(,);
\<< TICKS 0 ROT DUP 2
/ 1 SWAP
  START DUP DUP 1 -                         ; on the HP 50g, DUPDUP
* INV ROT + SWAP 2
-
  NEXT DROP TICKS
ROT - B\->R 8192 /
\>>

Gerson.
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) - Gerson W. Barbosa - 04-01-2014 02:57 AM



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