An unexpected result involving sums of random numbers
|
03-04-2023, 04:29 PM
Post: #21
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
(03-04-2023 03:09 PM)Gil Wrote: And Barbosa's program on EMU48, with Samsung A53: Obrigado, Gil! You can save 100000 additions by not incrementing the counter after the first RAND in each iteration. Also, local variables are evaluated faster than global variables. Try to use only the stack for more speed, especially on not emulated calculator (48G/GX and earlier). Additional optimization in the main loop would make it a bit faster. It appears iHP48 emulates the HP-48GX faster than the HP50g: « 0 DUP2 NOT SWAP START RAND DO RAND + SWAP 1 + SWAP DUP UNTIL 1 > END DROP NEXT SWAP / 1 + » 'X' STO « TIME 1 RDZ 100000 X TIME ROT HMS- » EVAL -> 2: 2.71959 1: 0.00153468 |
|||
03-04-2023, 05:47 PM
(This post was last modified: 03-04-2023 05:48 PM by Gil.)
Post: #22
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
Thanks, obrigado.
Minha última versão, com UNTIL « TIME 1. RDZ 0. 0. 1. 100000. START WHILE DUP 1. <= REPEAT RAND + SWAP 1. + SWAP END DROP 0. NEXT DROP 1000000. / TIME ROT HMS- » ... antes de descobrir a sua, Gérson, bem mais eficiente — que nunca conta, na soma das tentativas, o primeiro número aleatório, que você só acrescenta no final das contas. Nice too how you used 0 0 and changed one of the two zeroes to 1 for the loop from 1 to 100 000. The DUP2 was nice to get the 0 and keep track, in one step, of the initial 100000 for the final average (division). |
|||
03-04-2023, 06:54 PM
Post: #23
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
Using the 'X' program together with
« TIME 1 RDZ 100000 X TIME ROT HMS- » EVAL I get with EMU48 on my phone, exact mode, 2.71959 .0045309937 —> 45s, a huge difference in comparison to your 15s (3× your time). Strange? |
|||
03-04-2023, 06:57 PM
Post: #24
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
(03-04-2023 05:47 PM)Gil Wrote: Minha última versão, com UNTIL Por outro lado, você usa RAND somente uma vez, o que pode ser importante quando a intenção for minimizar o tamanho. Tive que fazer daquele jeito porque na 42S estava demorando mais de um minuto para 252 iterações. A propósito, WHILE REPEAT END usa 5 bytes a mais que DO UNTIL END. (On the other hand yours has only one instance of RAND, which might be important if you’re optimizing it for size. I only did it that way because 252 iterations were taking more than one minute on the 42S. By the way, WHILE REPEAT END takes up 22.5 bytes while DO UNTIL END takes up only 17.5). Your program is significantly faster now, congratulations! (only a minor typo, 1000000 instead of 100000). |
|||
03-04-2023, 07:17 PM
Post: #25
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
(03-04-2023 06:54 PM)Gil Wrote: Using the 'X' program together with I’ve been using iHP48 on an iPhone: CALCULATOR Model: HP48GX ROM: /ROMs/HP48GX/rom.48g When I change to model HP50g it takes close to one minute. |
|||
03-04-2023, 07:25 PM
Post: #26
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
(03-04-2023 02:29 PM)Albert Chan Wrote: We expected E*0.5 ≈ S. Here, expected counts estimated with 2S is better than E. 2S is better estimate than E because *all* generated random numbers are included. Mean of *all* random numbers = 0.5 is very very good (2 = 1/0.5) Bonus, increase in accuracy may also comes with speedup. (loops counting not needed) |
|||
03-04-2023, 09:48 PM
(This post was last modified: 03-04-2023 10:00 PM by Gil.)
Post: #27
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
As suggedted by Barbosa, I selected the model HP48 (instead of HP49-50G) from EMU48.
With exact Barbosa's programs and the above selected model, the elapsed time is now only 11.9s. However, to try and have better results with model HP49-HP50 from EMU48, I selected approximate mode and put a point (dot) after the digits to transform them from integers into reals. Then, the elapsed time is 12.0s, still a wee bit "worse" than HP48 (from EMU48). |
|||
03-04-2023, 11:28 PM
Post: #28
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
(03-04-2023 09:48 PM)Gil Wrote: However, to try and have better results with model HP49-HP50 from EMU48, I selected approximate mode and put a point (dot) after the digits to transform them from integers into reals. Then, the elapsed time is 12.0s, still a wee bit "worse" than HP48 (from EMU48). Down to 15.0576s here, timed with TEVAL. It turns out that I had set the 50g model to approximate mode but forgot to edit the program to change the integer constants into real. It’s been a long time since last time I used my 50g, so this’s been useful to dust it off if anything else. |
|||
03-12-2023, 02:09 AM
(This post was last modified: 03-12-2023 02:09 AM by Eddie W. Shore.)
Post: #29
|
|||
|
|||
RE: An unexpected result involving sums of random numbers
Modifying Gerson's program on the Swiss Micros DM42:
Code:
The program starts with assigning a seed of (Time Code + Date Code) as the seed and a random integer up to 10,000 as X. At first the average of the results seem to conjugate towards e, but the trials, it appears the limit may be a different constant: n = 30 Mean = 2.71830158802 (about 2E-5 from e) St.Dev = 0.0235108873611 n = 42 Mean = 2.71845315567 (about 1.17E-4 from e) St.Dev = 0.0201541663394 n = 54 Mean = 2.71967147586 (about 1.38E-3 from e) St.Dev = 0.019176372560 The samples were taken on March 11, 2023 around 5:30 PM to 5:45 PM (1730 to 1745) Pacific Standard Time. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)