Post Reply 
Monte-Carlo Pi
01-12-2022, 05:33 PM (This post was last modified: 01-12-2022 05:46 PM by C.Ret.)
Post: #9
RE: Monte-Carlo Pi
Csaba Tizedes ' Wrote:  HP-15C version

Thanks for the link, this publication trigger my curiosity and inspire me a few line of code.

(01-12-2022 10:18 AM)ttw Wrote:  A big speedup is possible through skipping the square root.

Another trick is to run batches of size 113.

Yes, speedup is possible through skipping the square root and the test as well.

Making batch of any size spare a lot of time skipping all the numerous intermediate displays.
But why a size of 113 ?

Didn't the batch of hundreds or thousands spare more ?

The following codes may be of interest for HP-15C's owners volunteers to experiment that optimization.

I still being in doubt concerning the usefulness of the rectangular to polar conversion. of course, this instruction spare a few steps and bytes in the code. But, since it also compute the angle from trigonometric functions based on CORDIC algorithm...

Taken with a dreadful doubt and in order to be clear about it; I carried out a small experiment using my HP-15C:

I entered the two codes which are similar in principle. Only difference is the use of the direct rectangular to polar conversion instruction or the computation of the sum of the two squares.
In both version, the dots are drawn at random using two RAN# instructions.

Usage:
At first use:
Please clear register (pressing f CLEAR REG ) since any use of the code add a batch of random drawn and display current approximation of PI.
Registers R0 contains the count of dots in the first quadrant circle and R1 contains the total count of dot's drawn.
The register I is only use as a counter in the main loop (based on a DSE instruction).

For each further use:
Input size of the batch and start the program by pressing the R/S key.
Eventually for the really first use or in case of an interrupted previous use, be sure to restart at the beginning by pressing g RTN or any appropriate instruction (GTO CH 000 , f CLEAR PGRM in RUN mode, or add a user-key-label to the code).


VERSION#1
Code:
001- STO+0  STO+1  STO I
004- f LBL 0
005-    f RAN#  f RAN#  g →P  g INT  STO-0  f DSE I  GTO 0
012-  4  RCL*0  RCL/1
This version is the shortest code, but a batch of size 100 need 3'04" to complete on my HP-15C

VESION#2
Code:
001- STO+0  STO+1  STO I
004- f LBL 0
005-    f RAN#  ENTER  *  f RAN#  ENTER  *  +  g INT  STO-0  f DSE I  GTO 0
016-  4  RCL*0  RCL/1
This longer version is about 31.5% faster than the shortest, since a batch of size 100 need only 2'06" to complete.

So I regret to announce to the whole community, that despite its elegance and sobriety, the idea of using the conversion →P instruction is not the most efficient and that nothing beats a good calculation conventionally placed in the operational stack.
If its true on a HP-15C, it is certainly the same on other models or brands ?

However, I still have some doubts about the effectiveness of my method and the possible existence of a bias related to my somewhat brutal way of counting ... Maybe? Peut-être ?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Monte-Carlo Pi - Ángel Martin - 01-11-2022, 11:37 AM
RE: Monte-Carlo Pi - Albert Chan - 01-11-2022, 12:19 PM
RE: Monte-Carlo Pi - Andres - 01-11-2022, 12:51 PM
RE: Monte-Carlo Pi - J-F Garnier - 01-11-2022, 01:11 PM
RE: Monte-Carlo Pi - Gerson W. Barbosa - 01-19-2022, 09:07 PM
RE: Monte-Carlo Pi - Ángel Martin - 01-29-2022, 10:37 AM
RE: Monte-Carlo Pi - Gerson W. Barbosa - 01-29-2022, 02:58 PM
RE: Monte-Carlo Pi - KeithB - 01-11-2022, 02:12 PM
RE: Monte-Carlo Pi - ttw - 01-12-2022, 10:18 AM
RE: Monte-Carlo Pi - Dave Shaffer - 01-13-2022, 03:30 AM
RE: Monte-Carlo Pi - Csaba Tizedes - 01-11-2022, 05:40 PM
RE: Monte-Carlo Pi - C.Ret - 01-12-2022 05:33 PM
RE: Monte-Carlo Pi - Ángel Martin - 01-12-2022, 01:50 PM
RE: Monte-Carlo Pi - ttw - 01-13-2022, 01:04 AM
RE: Monte-Carlo Pi - C.Ret - 01-13-2022, 06:14 PM
RE: Monte-Carlo Pi - KeithB - 01-13-2022, 01:58 PM
RE: Monte-Carlo Pi - Gerson W. Barbosa - 01-13-2022, 10:10 PM
RE: Monte-Carlo Pi - Ángel Martin - 01-14-2022, 09:03 AM
RE: Monte-Carlo Pi - C.Ret - 01-14-2022, 05:53 PM
RE: Monte-Carlo Pi - Gerson W. Barbosa - 01-14-2022, 08:31 PM
RE: Monte-Carlo Pi - Joe Horn - 01-15-2022, 05:52 AM



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