[VA] SRC #012a - Then and Now: Probability
|
11-04-2022, 03:31 PM
(This post was last modified: 11-04-2022 03:38 PM by DavidM.)
Post: #86
|
|||
|
|||
RE: [VA] SRC #012a - Then and Now: Probability
(11-02-2022 10:56 PM)Valentin Albillo Wrote:Gjermund Skailand Wrote:This has been a very interesting thread. This is a sys-rpl version for HP50g of CReth SRC12a. On an actual HP50g the calculation time for the 30 60 problem is 5 min 21sec. p= 9.51234350207E-6 There were a few typos in Gjermund's posted SysRPL code. I've made some corrections to his version below to produce a program which appears to give the proper results, so hopefully I haven't introduced any new bugs in the process. I can confirm that his code produces the correct real result for 30-60 input in about 317 seconds on my physical 50g. His version is really a hybrid mix of SysRPL, Saturn+ (the plus is important here), and even embedded UserRPL. The main "get" and "put" commands for arrays in SysRPL require that the index given for the element in question is expressed as a single binary integer. So "x,y" must be converted to a single integer representing the linear index of the element as if the array were actually a vector. In particular, PULLREALEL and PUTREALEL are the commands which do the dirty work of recalling and storing the array elements. Given that this program (along with the others, of course) depends very heavily on array indexing, anything that can speed up the conversion of x-y coordinates to a single vector index will have a substantial impact on the runtime. Gjermund has a single subroutine for this conversion ("Tind"), which I suspect he originally wrote in standard SysRPL. Given that it is a critical routine, re-coding that in Saturn assembly made good sense. Not only is it running at Saturn speed, though, he also used a "Saturn+" opcode for squaring a 5-nibble integer. This allows squaring the value in 1 assembly step instead of having to call a subroutine for that purpose. That opcode is only available on the ARM-based RPL calcs, but speeds up the conversion of x,y coordinates into a single index noticeably. Combine the above with the usual speed increase of SysRPL over UserRPL and you've got a significantly faster program than the original UserRPL version that C.Ret posted. Here's Gjermund's program with the typos corrected: !RPL !NO CODE !JAZZ :: CK2NOLASTWD CK&DISPATCH2 #11 :: COERCE2 ' CODE GOSBVL POP2# RSTK=C SAVE B=A.A A*A.A A-B.A ASRB.A C=RSTK A+C.A GOSBVL PUSH#ALOOP ENDCODE 3PICK DUP 3PICK EVAL SWAP 2 SWAPOVER {{ r s d m Tind ii }} r #1+_ONE_DO (i) * INDEX @ #1+_ONE_DO (j) INDEX@ #1+_ONE_DO (j) ( ***CORRECTION*** ) 3 DUP INDEX@ #1<> ?SKIP #1- JINDEX@ INDEX@ #<> ?SKIP #1- JINDEX@ r #<> ?SKIP #1- * UNCOERCE %/ UNCOERCE2 %/ ( ***CORRECTION*** ) LOOP (j) LOOP (i) d UNCOERCE ONE{}N FPTR2 ^XEQ>ARRY DUP %0 xCON %1 BINT1 PUTREALEL s #1+_ONE_DO (k) INDEX@ #>$ BIGDISPROW1 2DUP m m 2GETEVAL DUP4UNROLL TOTEMPOB (n) #1+_ONE_DO (q) SWAP INDEX@ PULLREALEL ROT INDEX@ PULLREALEL ROT %* 4UNROLL LOOP (q) 2DROP UNCOERCE ONE{}N x>ARRY m #1+_ONE_DO (i) INDEX@ #2 #/ #+ #1+_ONE_DO (j) JINDEX@ INDEX@ 2GETEVAL PULLREALEL %CHS JINDEX@ TOTEMPOB !ii 1 JINDEX@ #1- #MAX JINDEX@ #1+ m #MIN #1+ SWAP DO (a) * 1 JINDEX@ INDEX@ ii #> ?SKIP #1- MAX 1 JINDEX@ INDEX@ ii #> ?SKIP #1- #MAX ( ***CORRECTION*** ) * JINDEX@ ii INDEX@ #> ?SKIP #1+ INDEX@ MIN JINDEX@ ii INDEX@ #> ?SKIP #1+ INDEX@ #MIN ( ***CORRECTION*** ) #1+SWAP DO (b) SWAP JINDEX@ INDEX@ 2GETEVAL PULLREALEL ROT %+ LOOP (b) LOOP (a) ROT JINDEX@ INDEX@ 2GETEVAL 3PICKSWAP PUTREALEL * JINDEX@ #1+ INDEX@ #- JINDEX@ DUP #1+ INDEX@ #- ( ***CORRECTION*** ) 2GETEVAL ROTSWAP PUTREALEL SWAP LOOP (j) LOOP (i) DROP m DUP r #>=_ ?SKIP #1+ !m LOOP (k) SWAP %0 xCON r 1 2GETEVAL UNCOERCE xDO %1 xPUTI xUNTIL % -64 xFS? xENDDO xDROP xDOT %6 s UNCOERCE x^ x/ ABND ; ; @ |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 17 Guest(s)