Post Reply 
Monte-Carlo Pi
01-19-2022, 09:07 PM (This post was last modified: 01-22-2022 10:03 AM by Gerson W. Barbosa.)
Post: #19
RE: Monte-Carlo Pi
(01-11-2022 01:11 PM)J-F Garnier Wrote:  
(01-11-2022 11:37 AM)Ángel Martin Wrote:  I'm putting together a (very humble) RANDOM ROM with a (biased) selection of RNG-related programs and MCODE functions. I'd like to include a Monte-Carlo based calculation of pi, which I *think* has already been published in the forum but can't locate anymore. Any pointers to that reference will be appreciated...

You may have a look at the work of our friend Mike (Stgt) here (copy and edit the link).

Mike (Stgt) has written another HP-41CX program that computes only one random number per iteration, but it requires his VORANOGE (Voyagers' Pseudorandom Number Generator) module. His equivalent HP-15C program might illustrate the method, though:

Code:

001- LBL A
002- STO I
003- 0
004- STO RAN#
005- FIX 0
006- LBL 1 
007- RCL RAN#
008- RAN#
009- /
010- RND
011- 2
012- /
013- FRAC
014- +
015- DSE I
016- GTO 1
017- FIX 9
018- x<>y
019- /
020- 8
021- *
022- 1
023- +
024- RTN

1356 f A -> 3.141592920 ( ~10s, HP-15C LE)

Update:

Mike is interested neither in Pi nor in the Monte Carlo method. His motivation is finding the fastest possible implementations. I think he has succeeded, judging by his solutions for both the HP-41CX plus VORANOGE module and the HP-15C:

Code:


01•LBL "PIMC"
02 STO 01
03 CLX
04 STO 00
05 RCL 01
06 ENTER^
07•LBL 01
08 RCL 00
09 RN
10 X^2
11 STO 00
12 +
13 INT
14 -
15 DSE Y
16 GTO 01
17 RCL 01
18 /
19 4
20 *
21 END

2187000 CPU cycles for input 1E3 if PR detached and VORANOGE on page 8.

Code:


  1-42,21,11  LBL A
  2-   44 25  STO I
  3-       0  0      ; no need to square this one
  4-   44  0  STO 0
  5-      34  x<>y
  6-      36  ENTER^
  7-42,21, 0  LBL 0
  8-   45  0  RCL 0  ; previous RN^2
  9-   42 36  RAN#   ; get a new RN
 10-   43 11  x^2
 11-   44  0  STO 0  ; save for future use
 12-      40  +
 13-   43 44  INT
 14-      30  -      ; hit-=1 if outside
 15-42, 5,25  DSE I
 16-   22  0  GTO 0
 17-      34  x<>y
 18-      10  /
 19-       4  4
 20-      20  *

3842552 CPU counts for input 1E3

This should run also on the HP-11C as RCL RAN# is not needed.

We can do some cheating to get an excellent result on the original HP-15C in a reasonable time by choosing proper seed and number of points:

14 STO RAN#

452 f A -> 3.141592920 (7m34s, HP-15C)
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: 2 Guest(s)