Post Reply 
[VA] SRC #016 - Pi Day 2024 Special
03-14-2024, 06:20 PM
Post: #1
[VA] SRC #016 - Pi Day 2024 Special
      
Hi, all,
     
Once again, today it's March, 14 aka \(\pi\) Day, so
 
Happy \(\pi\) Day 2024 and Welcome to SRC #16 - Pi Day 2024 Special

As always, this SRC #16 is intended to commemorate this super-ubiquitous constant, \(\pi\). I've been posting a number of threads over the years about \(\pi\) Day, these are the four previous ones: This time I'm featuring a potpourri of \(\pi\) appearances, most of them rare and/or unexpected for your visual and mathematical enjoyment once you've created and run the (mostly very simple) pertinent code on your favorite vintage calculator, preferably an HP model.

In due time I'll post my original code for the HP-71B and/or HP-42S/Free42, once you've had the opportunity to work on them for a few days. Oh, and sorry, no cake this time, we've ran out of cake !  Smile
    Note: No hard rules, post here whatever you want as long as it's on topic and NO CODE PANELS, but I'd appreciate it if you'd use vintage HP calcs (physical/virtual,) otherwise I might consider you kinda clueless as far as programming vintage HP calcs is concerned.

1. First appearance

First of all:  what do I consider a rare \(\pi\) appearance ? Well, broadly speaking mostly any unexpected appearances of \(\pi\) having nothing to do with circles or other geometric matters (including arc lengths, areas, volumes, etc.,) such as e.g. the one shown by this 2-line, 69-byte HP-71B program:

      1  DESTROY ALL @ RANDOMIZE 260 @ FIX 4 @ INPUT K
      2  N=0 @ FOR I=1 TO K @ N=N-MOD(IROUND(RND/RND),2) @ NEXT I @ DISP 1-4*N/K


      >RUN


              ? 1E5   ->  3.1416

That said. let's begin with the first appearance:

Solve this equation for x in [1, 6]. Post both result and code or keystroke sequence.

      [Image: pI%2003.jpg]

2. Second appearance

You can get a nice approximation to the value of \(\pi\) (exact as the number of tries goes to infinity) by following these simple steps. First set Count to zero and select a number of tries N, then:
    1. Choose two random integers A and B in [1, N].

    2. Check if they are co-prime, i.e. they have no common factors, in which case increment Count.

    Keep on performing steps 1 and 2 for N tries, then:

    3. Output [Image: SRC-13-1-1-tuorjj.jpg]

Post both code and results. My original solution is a 3-line, 102-byte HP-71B program which outputs the resulting values for N=10, 100, 1000, ..., one million tries.

3. Third appearance

Solve this equation for x, where \(\phi\) is the Golden Ratio = (1+√5)/2. Post both result and code or keystroke sequence:

     [Image: Pi%20phi%20b.jpg]

My original solution is a 2-line, 91-byte HP-71B program which outputs the resulting values of x for 10, 100, 1000, ..., 100,000 terms in the infinite product, and also a 2-line command line sequence which solves for x by using 100,000 terms straight away.

4. Fourth appearances

Although \(\pi\) can't appear in its entirety within an irrational algebraic number (because \(\pi\) is transcendental and thus not the root of a non-zero polynomial of finite degree with rational coefficients,) \(\pi\)'s prefixes of any length (first N digits of \(\pi\) for finite N) do actually appear inside irrational numbers, square roots for instance, like these:
    ● The 7-long prefix 3141592 appears in:

         3485  =  59.033888...4733453141592349004..  at decimal 822
         26401 = 162.483845...1905663141592268465..  at decimal  69
         82777 = 287.709923...3523123141592695866..  at decimal  45
       (8-long, actually !)
       
    ● The 10-long (rounded) prefix 3141592654 appears in:

         2424609  = 1557.115602...6896933141592654600235..  at decimal 170
         40850970 = 6391.476355...4838773141592654698929..  at decimal 112
See if you can find other appearances of assorted \(\pi\)'s prefixes in various irrationals (not necessarily square roots, logs or trigs would do too.) The smaller the argument and the earlier the appearance, the better. Post your best findings here (and yes, you can use whatever hardware/software, posting code's not mandatory.)

5. Fifth appearances

As stated above, \(\pi\) can't be a root of polynomial equations with rational coefficients but that doesn't prevent \(\pi\)'s prefixes of arbitrary finite length from appearing as roots of particular equations, e.g.:

Solve the following equations, either using a program or directly from the keyboard. Remember, don't post just the result, include also the code or keystroke sequence:
  • Polynomial equations:

          4 x3 - 22 x2 + 29 x + 2 = 0

          9 x4 - 19 x3 + 28 x2 - 70 x - 344 = 0
          
    See if you can find similar polynomial equations with roots even closer to \(\pi\). The smaller the degree and the size of the coefficients, the better.
          
  • Fermat-like:

          2063x + 8093x = 8128x

          1198x + 4628x = 4649x
          
  • Transcendental equation (where Γ is the Gamma function):

           Γ ln(7 x5/19) = 16
      
6. Sixth appearance

Given the following recurrence, with x0 = 0 and { } denoting the fractional part function,

      [Image: Pi%20recurrence.jpg]

write a program to compute its succesive terms x1, x2, x3, .. and for each term output in hexadecimal the value of

      dn = IP(16 xn )    ,   where IP is the integer part function,

then manually check whether each dn matches the nth hexadecimal digit of \(\pi\)'s fractional part, and if they do then maybe, just maybe, this recurrence quite unexpectedly produces \(\pi\)'s hex digits one at a time, as do spigot algorithms !

For example, the first 50 hex digits of \(\pi\)'s fractional part are

      3.243F6A8885 A308D31319 8A2E037073 44A4093822 299F31D008

so your program should output:  2  4  3  F  6  A  8  8  8 ..

Try and output as many correct hex digits as possible, which will depend on your model's range (10-digit, 12-digit, ..) and/or whether your code uses/implements multiprecision arithmetic or not.

My original solution consists of a 3-line, 112-byte HP-71B program which correctly produces the first 9 hex digits above, and a 49-step, 89-byte HP-42S program which when run on Free42 Decimal produces the first 26 correct hex digits.

7. Seventh appearance

Let x be the only real root of

      x3 - 6 x2 + 4 x - 2 = 0

Compute ln(x24 - 24) ÷ H, where H is the number of hours in a week minus five.

My original solution is a one-line command-line BASIC expression for the HP-71B as well as a 15-step, 28-byte RPN Solver program for the HP-42S or Free42.



Well, that's all for now.

If I see interest, I'll post in a few days my original solutions, including results, code (or keystroke sequences) and relevant comments.

My code is for the HP-71B and/or the HP-42S/Free42 but you might consider posting RPN, RPL, SysRPL or 71FORTH/Assembler code as well.

V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
03-14-2024, 10:53 PM
Post: #2
RE: [VA] SRC #016 - Pi Day 2024 Special
Hello, Valentín,

Thanks for yet another SRC Pi Day Special!

Nice and interesting topics, as always, but I hope you don’t mind if I take only number 5 this time.

The easiest way to solve polynomial equations on the hp 50g is using the Polynomial Root Solver (PROOT, available also on the HP-71B). On the hp 50g:

[ 4 -22 29 2 ] PROOT 3 GET
-> 3.14159299564

[ 9 -19 28 -70 -344 ] PROOT 4 GET
-> (3.1415926538,0)

I’ll take the opportunity to present my own polynomial equation of that kind:

x^7 + 2x^6 + 3x^5 + 4x^4 + 3x^3 + 2x^2 + x - 19100/3 = 0

That’s a 7th-degree polynomial equation, but on the other hand the sizes of the coefficients of x are quite small, increasing from 1 to 4 and then down to 1 again. The closeness of the real root to π is similar to that of the previous 4th-degree polynomial equation.

[ 1 2 3 4 3 2 1 '-19100/3' ] PROOT 1 GET
-> (3.14159265373,0)

This stems from the observation that π(1 + π + π^2+ π^3)^2 ≈ 19100/3

Best regards,

Gerson
Find all posts by this user
Quote this message in a reply
03-16-2024, 02:13 AM (This post was last modified: 03-16-2024 06:57 AM by C.Ret.)
Post: #3
RE: [VA] SRC #016 - Pi Day 2024 Special
      
Bonjour à toutes et à tous.

Happy \(\pi\) Day 2024 !

This is my humble participation to SRC #16 - Pi Day 2024 Special

1. First appearance
[Image: pI%2003.jpg]
I am trying hard to solve this equation with my HP-15C, hoping that numeric integration, solver and hyperbolic trigonometric are of any use.

My obviously perfectible solution is a three step algorithm:
  1. Grab yourHP-15C and power it up.
    From far the easiest and fastest part of the proposed solution.
    Make sure you wake up your HP-15C in radian trigonometric mode and properly format its display.
    ON
    g RAD
    f FIX 8
    g P/R
    f CLEAR PRGM
  2. Compute the left side integral
    The left side of the equation is a constant, I need a short program to compute the integral: \( R0 = \int_{0}^{1}\frac{{tan^{-1}(tanh^{-1}(x))}}{x}\: \mathrm{d}x \)

    After entering this short code:
    001-42,21, 0   f LBL 0
    002-43,22,25   g HYP-¹ TAN
    003- 43 25   g TAN-¹
    004-   34     x⇋y
    005-   10      ÷
    006- 43 32   g RTN


    The value of this left side integral may be compute and store in register R0.
    0 ENTER 1 ∫yx 0
         ... Running ... 
         1.02576051
    STO 0
  3. Solve for a value of x that balance the equation
    \( R1=x\cdot\left( ln(\Gamma(\frac{1}{x}))-ln(\Gamma(\frac{1}{2}+\frac{1}{x}))-\frac{1}{2}\cdot ln\,x\right)=x\cdot ln\left(\frac{\Gamma(1/x)}{\Gamma(1/x+0.5)\cdot\sqrt{x}}\right) \)
    The right side of the equation may be code in memory as the following program :

    007-42,21, 1   f LBL 1
    008-    15    1/x
    009-    1     1
    010-    30    -
    011-  42 0   f x!
    012-  43 36  g LST x
    013-    48    .
    014-     5    5
    015-    40    +
    016-  42 0   f x!
    017-    10    ÷
    018-    34    x⇋y
    019-    11    √x
    020-    10    ÷
    021-  43 12  g LN   
    022-    20    ×
    023-45,30, 0    RCL-0
    024-  43 32  g RTN


    The expected result may be display using the solver and store in register R1.
    1 ENTER 6 SOLVE 1
         ... Running ...
          3.14159265
    STO 1


Currently looking for the calculator I may used for the next appearance.

Thanks to Valentin for this nice PI-day special !
Find all posts by this user
Quote this message in a reply
03-16-2024, 11:13 AM (This post was last modified: 03-16-2024 11:15 AM by J-F Garnier.)
Post: #4
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-14-2024 06:20 PM)Valentin Albillo Wrote:  what do I consider a rare \(\pi\) appearance ? Well, broadly speaking mostly any unexpected appearances of \(\pi\) having nothing to do with circles or other geometric matters (including arc lengths, areas, volumes, etc.,)

The most memorable unexpected appearance of pi for me was with the expression: sum(n=1 to Inf,1/n²) = \(\pi\)²/6.
So simple ...


Quote:let's begin with the first appearance:

Solve this equation for x in [1, 6]. Post both result and code or keystroke sequence.

      [Image: pI%2003.jpg]

Here is my keystroke sequence on the 71B, with my Math 2B to save a few keystrokes:

>A=INTEG(0,1,1E-10,ATAN(ATANH(IX))/IX)
>FROOT(1,6,FX*(LN(GAMMA(1/FX))-LN(GAMMA(1/2+1/FX))-LN(FX)/2)-A)
3.14159265358


J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
03-16-2024, 02:34 PM
Post: #5
RE: [VA] SRC #016 - Pi Day 2024 Special
Given N, this program calculates the value for the "Second appearance", I no longer have the HP-50g, so I ran it in an emulator.
«
0. 1 PICK3
START
RAND RAND 2 →LIST PICK3 * 1 ADD IP EVAL GCD 1 == +
NEXT / 6 * √
»

I set RDZ to 0.5 one time before running the program.

For N=10: 3.46410161514
For N=100: 3.08606699924
For N=1000: 3.19166997285
For N=10000: 3.14037146511
For N=100000: 3.14975602148
For N=1000000: 3.1401805004

For the last value, the program ran for almost 25 minutes and only the first 3 digits are accurate.
Find all posts by this user
Quote this message in a reply
03-16-2024, 03:58 PM (This post was last modified: 03-16-2024 05:20 PM by Gerson W. Barbosa.)
Post: #6
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-16-2024 02:34 PM)Juan14 Wrote:  Given N, this program calculates the value for the "Second appearance", I no longer have the HP-50g, so I ran it in an emulator.
«
0. 1 PICK3
START
RAND RAND 2 →LIST PICK3 * 1 ADD IP EVAL GCD 1 == +
NEXT / 6 * √
»

I set RDZ to 0.5 one time before running the program.

For N=10: 3.46410161514
For N=100: 3.08606699924
For N=1000: 3.19166997285
For N=10000: 3.14037146511
For N=100000: 3.14975602148
For N=1000000: 3.1401805004

For the last value, the program ran for almost 25 minutes and only the first 3 digits are accurate.

Mine is still running for 20 minutes or so. I guess it’ll take a bit longer than yours as I missed your optimization.

« 1 6
FOR n n ALOG 0 1 PICK3
START n ALOG DUP RAND * 1 + IP SWAP RAND * 1 + IP GCD 1 == { 1 + } IFT
NEXT SWAP 6. * SWAP / √
NEXT
»


I’ve used 1 RDZ. Still waiting for the results as I post this.

Gerson.

P.S.: It took about one and a half hour, but I’ve finally obtained the results. Some optimizations are definitely required.

2.92770021885
3.27326835354
3.17553674414
3.14476811662
3.14494955129
3.14146631543
Find all posts by this user
Quote this message in a reply
03-16-2024, 04:56 PM (This post was last modified: 03-16-2024 08:21 PM by C.Ret.)
Post: #7
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-16-2024 11:13 AM)J-F Garnier Wrote:  Here is my keystroke sequence on the 71B, with my Math 2B to save a few keystrokes:

Nice, the method strangely match the method I used on my HP-15C.

You didn't indicate that you put your highly extended HP-71B in RADIANS trigonometric mode. Or isn't it necessary by using the top version of all the Math's module ?

Since, I only own the former Math 1A version, I get an erroneous result when omitting to set trigonometric mode right.


>RADIANS
>A=INTEGRAL(0,1,1E-8,ATAN(ATANH(IVAR))/IVAR)
            1.02576050997
>P=FNROOT(1,6,FVAR*LOG(GAMMA(1/FVAR)/GAMMA(1/FVAR+.5)/SQR(FVAR))-A)
            3.14159265196


And since I have my HP-71B in hands, I modestly present you my attempt for the second apparence:

It is a (too long to edit) one-liner:
10 WHILE K<N @ K=K+1 @ C=C+(PGCD(CEIL(N*RND),CEIL(N*RND))=1) @ END WHILE @ DISP SQR(6*N/C);N @ N=10*N @ RUN


>DESTROY ALL
>N=1
[RUN]
2.44948974278  1
2.73861278753  10
3.03821810125  100
3.12347523777  1000
3.14502731861  10000
3.14037146511  100000


The appearance isn't efficient at all, perhaps my code is wrong !?
I may have use 1+IP(N*RND) instead of the CEIL functions.
Find all posts by this user
Quote this message in a reply
03-16-2024, 06:09 PM
Post: #8
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-14-2024 06:20 PM)Valentin Albillo Wrote:  Solve this equation for x, where \(\phi\) is the Golden Ratio = (1+√5)/2. Post both result and code or keystroke sequence:

     [Image: Pi%20phi%20b.jpg]

This is my take with 10^5 terms:
>P=1 @ FOR N=1 TO 1E5 @ P=P*(1-1/N/N/100) @ NEXT N @ DISP 5*2/(1+SQR(5))/P
3.14159235271

Using more terms takes too long, even in Emu71, and doesn't improve the result so much.

While experimenting a bit, I found a few interesting similar expressions:

>P=1 @ FOR N=1 TO 1E5 @ P=P*(1-1/N/N/4) @ NEXT N @ DISP 2/P
3.14158479717

>P=1 @ FOR N=1 TO 1E5 @ P=P*(1-1/N/N/36) @ NEXT N @ DISP 3/P
3.14159181273

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
03-17-2024, 01:45 AM
Post: #9
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-16-2024 04:56 PM)C.Ret Wrote:  And since I have my HP-71B in hands, I modestly present you my attempt for the second apparence:

It is a (too long to edit) one-liner:
10 WHILE K<N @ K=K+1 @ C=C+(PGCD(CEIL(N*RND),CEIL(N*RND))=1) @ END WHILE @ DISP SQR(6*N/C);N @ N=10*N @ RUN


>DESTROY ALL
>N=1
[RUN]
2.44948974278  1
2.73861278753  10
3.03821810125  100
3.12347523777  1000
3.14502731861  10000
3.14037146511  100000


The appearance isn't efficient at all, perhaps my code is wrong !?
I may have use 1+IP(N*RND) instead of the CEIL functions.

As far I can see there’s nothing wrong with your code. Also, CEIL(N*RND) is more compact than 1+IP(N*RND).

Here’s another RPL program for the hp 50g using yours and Juan’s ideas:

« 0 DUP 5
FOR k k DUPDUP ALOG SWAP I→R SIGN + SWAP 1 + ALOG DUP UNROT
FOR n RAND OVER * CEIL RAND PICK3 * CEIL GCD 1 == ROT + SWAP
NEXT 6. * OVER / √ SWAP
NEXT DROP
»

1 RDZ TEVAL

->

2.92770021885
3.21633760451
3.18088727321
3.15074602744
3.14505324234
3.14173762276
:s: 851.5912


(time on the iHP48 emulator)
Find all posts by this user
Quote this message in a reply
03-17-2024, 10:23 AM (This post was last modified: 03-17-2024 10:28 AM by J-F Garnier.)
Post: #10
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-14-2024 06:20 PM)Valentin Albillo Wrote:  Solve the following equations, either using a program or directly from the keyboard. Remember, don't post just the result, include also the code or keystroke sequence:
  • Fermat-like:

          2063x + 8093x = 8128x

          1198x + 4628x = 4649x

I like these two ones!

Here we are with \(\pi\) approximations, not exact value given by infinite series.

On the 71b:

>FROOT(1,6,2063^FX+8093^FX-8128^FX)
3.14159265353

>FROOT(1,6,1198^FX+4628^FX-4649^FX)
3.14159265363

Let's check the first equation on Free42:
LBL "P5"
MVAR "X"
2063
RCL "X"
Y^X
8093
RCL "X"
Y^X
+
8128
RCL "X"
Y^X
-
RTN

Solve it between 1 and 6, result is: 3.141592653590...
Not bad, almost correct to 13 digits.

Or in the other way:
PI , STO "X" , XEQ "P5" , result = 0.019368999924...

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
03-17-2024, 01:35 PM
Post: #11
RE: [VA] SRC #016 - Pi Day 2024 Special
For the ‘Third appearance’ this program calculates the first 50,000 terms of the infinite product.
«
1 1. 50000
FOR j
j SQ 100 * INV 1 SWAP - *
NEXT 1 5. √ + * 10 SWAP /
»

it returns 3.14159203861
Find all posts by this user
Quote this message in a reply
03-17-2024, 04:05 PM (This post was last modified: 03-17-2024 04:23 PM by Gerson W. Barbosa.)
Post: #12
RE: [VA] SRC #016 - Pi Day 2024 Special
3rd, on the hp 50g emulator:

'5/((1+√5)/2*EXP(∑(n=1,50000,
LNP1(-(1/(100*n^2))))))' EVAL


->

3.14159202448

As a comparison, the actual 12-digit result should be 3.14159202528

P. S.: For n = 100000, per the requirement:

3.14159233344
Find all posts by this user
Quote this message in a reply
03-17-2024, 04:49 PM (This post was last modified: 03-17-2024 04:52 PM by C.Ret.)
Post: #13
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-17-2024 01:45 AM)Gerson W. Barbosa Wrote:  
(03-16-2024 04:56 PM)C.Ret Wrote:  10 WHILE K<N @ K=K+1 @ C=C+(PGCD(CEIL(N*RND),CEIL(N*RND))=1) @ END WHILE @ DISP SQR(6*N/C);N @ N=10*N @ RUN

>DESTROY ALL
>N=1
[RUN]
2.44948974278  1
2.73861278753  10
3.03821810125  100
3.12347523777  1000
3.14502731861  10000
3.14037146511  100000 (~ 3 hrs later)
3.14218220193  1000000 (~ 27 hrs later)

As far I can see there’s nothing wrong with your code. Also, CEIL(N*RND) is more compact than 1+IP(N*RND).

Thanks your attention. It was a useful observation that encourage me to go further.

Confident, I kept my HP-71B running over. I just get the last appearance exactly 30 hours after launching the programme at last Friday night. Now my WE is over.

How a wonderful machine! This HP-71B still running like a young crazy horse the all day and night after 37 years of services.

The next appearance is expected in no less than 243 hrs (10 days). I will stop it now and leave it to rest for a while Smile
Find all posts by this user
Quote this message in a reply
03-17-2024, 05:21 PM
Post: #14
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-17-2024 04:05 PM)Gerson W. Barbosa Wrote:  3rd, on the hp 50g emulator:

'5/((1+√5)/2*EXP(∑(n=1,50000,
LNP1(-(1/(100*n^2))))))' EVAL


->

3.14159202448

As a comparison, the actual 12-digit result should be 3.14159202528

P. S.: For n = 100000, per the requirement:

3.14159233344

This is a nice use of both the 50G's summation function and the log function.
A similar code on the 71b gives:
>S=0 @ FOR N=1 TO 1E5 @ S=S+LOGP1(-1/N/N/100) @ NEXT N @ DISP 5*2/(1+SQR(5))/EXP(S)
3.14159233937
The ∑ function probably accumulates the sum with extended 15-digit accuracy, thus a slightly different result.
We can improve a little bit the 71B's code by summing backward:
>S=0 @ FOR N=1E5 TO 1 STEP -1 @ S=S+LOGP1(-1/N/N/100) @ NEXT N @ DISP 5*2/(1+SQR(5))/EXP(S)
3.14159233943

and this is the value I get with Free42 (to 12 digits). But at the end this doesn't improve the approximation of pi.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
03-17-2024, 05:38 PM (This post was last modified: 03-18-2024 12:05 AM by DavidM.)
Post: #15
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-16-2024 03:58 PM)Gerson W. Barbosa Wrote:  P.S.: It took about one and a half hour, but I’ve finally obtained the results. Some optimizations are definitely required.

When I saw "for N=10, 100, 1000, ..., one million tries", I knew right away that I wasn't going to attempt a straight User RPL solution, mainly because I knew that it was highly unlikely to perform well enough to provide a result before I lost patience with the exercise. Even an empty (User) RPL loop of 1 million iterations takes about 21 minutes on an actual 50g. Start adding code to the loop, and the execution time grows substantially.

The following is my attempt at Appearance 2 using a System RPL/Saturn+ assembly approach. The Saturn code takes advantage of the % (MOD) operator which doesn't exist in real Saturn implementations, so this is only compatible with the ARM-based RPL systems.

!NO CODE
!RPL
::
  CK0NOLASTWD                             ( no arguments expected )
  TEN                                     ( initial N as system binary )
  SIX ZERO_DO                             ( outer loop; count: 6 ) 
    DUP UNCOERCE                          ( make copy of N, convert to real for calculations )
    ZERO                                  ( initial Count as system binary )
    3PICK ZERO_DO                         ( inner loop; count: N )
      OVER %RAN %* %CEIL                  ( first random integer )
      3PICK %RAN %* %CEIL                 ( second random integer )
      COERCE2                             ( convert both numbers to system binary )

      CODE
        GOSBVL POP2# R0=C A               % this Saturn+ code block calculates the GCD
        GOSBVL SAVPTR C=R0 A              % of two system binary numbers in SL1 and SL2      
        { ?C=0 A EXIT D=C A A=A%C A
          C=A A A=D A UP }                % the result is left in SL1 on exit      
        GOVLNG PUSH#ALOOP
      ENDCODE

      #1= IT #1+                          ( if GCD is 1 [ie. integers are coprime], increment Count )
    LOOP
    UNCOERCE %6 ROT %* SWAP %/ %SQRT      ( SQRT[6N/Count] )
    OVER #>$ >TAG                         ( tag the current result with N )
    SWAP #10*                             ( N=N*10 )
  LOOP
  DROP                                    ( N no longer needed )
;
@


Bytes: 130
Checksum: 8E9Bh

Sample output using 0.5 RDZ to seed the PRNG:

     10: 3.46410161514
    100: 3.08606699924
   1000: 3.19166997285
  10000: 3.14037146511
 100000: 3.14975602147
1000000: 3.14017791967


Time: 46.3s (Emu48 on desktop computer)
11851s (real 50g)
Find all posts by this user
Quote this message in a reply
03-17-2024, 08:31 PM (This post was last modified: 03-17-2024 08:53 PM by jonakeys.)
Post: #16
RE: [VA] SRC #016 - Pi Day 2024 Special
What a great way to honor Pi Day! These are some challenges. So thank you Valentin.

I've started to focus on the fifth appearances using the HP-15C CE. The found answers for the polynomials and the transcendental and the keystrokes are as follows:
  • 4 x3 - 22 x2 + 29 x + 2 = 0 x = 3.141592996
  • 9 x4 - 19 x3 + 28 x2 - 70 x - 344 = 0 x = 3.141592654
  • Γ ln(7 x5/19) = 16 x = 3.141592654

* Polynomial equations
Using Horner's Method to rewrite
** 4 x3 - 22 x2 + 29 x + 2 = 0
x = 3.141592996
| 000 | *Keystrokes* | *Key Codes* |
| 001 | f LBL 0 | 42,21,0 |
| 002 | ENTER | 36 |
| 003 | ENTER | 36 |
| 004 | ENTER | 36 |
| 005 | 5 | 5 |
| 006 | . | 48 |
| 007 | 5 | 5 |
| 008 | - | 30 |
| 009 | 4 | 4 |
| 010 | x | 20 |
| 011 | x | 20 |
| 012 | 2 | 2 |
| 013 | 9 | 9 |
| 014 | + | 40 |
| 015 | x | 20 |
| 016 | 2 | 2 |
| 017 | + | 40 |
| 018 | g RTN | 43,32 |
#+tblfm: $1=@#-1;%03d

** 9 x4 - 19 x3 + 28 x2 - 70 x - 344 = 0
x = 3.141592654
| 000 | *Keystrokes* | *Key Codes* |
| 001 | f LBL 0 | 42,21,0 |
| 002 | ENTER | 36 |
| 003 | ENTER | 36 |
| 004 | ENTER | 36 |
| 005 | 9 | 9 |
| 006 | x | 20 |
| 007 | 1 | 1 |
| 008 | 9 | 9 |
| 009 | - | 30 |
| 010 | x | 20 |
| 011 | 2 | 2 |
| 012 | 8 | 8 |
| 013 | + | 40 |
| 014 | x | 20 |
| 015 | 7 | 7 |
| 016 | 0 | 0 |
| 017 | - | 30 |
| 018 | x | 20 |
| 019 | 3 | 3 |
| 020 | 4 | 4 |
| 021 | 4 | 4 |
| 022 | - | 30 |
| 023 | g RTN | 43,32 |
#+tblfm: $1=@#-1;%03d

* Transcendental equation
** Γ ln(7 x5/19) = 16
x = 3.141592654
| 000 | *Keystrokes* | *Key Codes* |
| 001 | f LBL 0 | 42,21,0 |
| 002 | 5 | 5 |
| 003 | y^x | 14 |
| 004 | 7 | 7 |
| 005 | x | 20 |
| 006 | 1 | 1 |
| 007 | 9 | 9 |
| 008 | ÷ | 10 |
| 009 | LN | 43,12 |
| 010 | 1 | 1 |
| 011 | - | 30 |
| 012 | x! | 42,0 |
| 013 | 1 | 1 |
| 014 | 6 | 6 |
| 015 | - | 30 |
| 016 | g RTN | 43,32 |
#+tblfm: $1=@#-1;%03d


edit: remove code panel since it's not allowed

/ Jonathan
HP 15C CE, HP 35S, HP Prime G2, Casio Graph 90+E, TI Nspire CX, TI 83, TI 84+, TI 84+ CE
Visit this user's website Find all posts by this user
Quote this message in a reply
03-17-2024, 08:59 PM
Post: #17
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-17-2024 05:38 PM)DavidM Wrote:  
(03-16-2024 03:58 PM)Gerson W. Barbosa Wrote:  P.S.: It took about one and a half hour, but I’ve finally obtained the results. Some optimizations are definitely required.

When I saw "for N=10, 100, 1000, ..., one million tries", I knew right away that I wasn't going to attempt a straight User RPL solution, mainly because I knew that it was highly unlikely to perform well enough to provide a result before I lost patience with the exercise. Even an empty (User) RPL loop of 1 million iterations takes about 21 minutes on an actual 50g. Start adding code to the loop, and the execution time grows substantially.



Time: 46.3s (Emu48 on desktop computer)
xxxxxs (real 50g) (to be filled in after current run completes, estimate: 3.25 hours)

That ran together with other concurrent tasks on my smartphone. In order to be fair, I repeated the run after disabling automatic screen lock and making sure the emulator was the only application running until completion. Now it took 1755.7s, barely half an hour. My second program elsewhere in this thread, running under the same conditions, took 841.6s, that is, less than 15 minutes. On the first program the counter was reset at the beginning of each decade; on the second program it was reset only in the beginning of the program, so past decade data could be used cumulatively on the next ones. This implied in about 11.11% speedup. Some additional 35% with obtained just by the use of CEIL, like C. Ret did, instead of INT with additional arguments. Another 3 or 4 percent were obtained by avoiding IF as in Juan’s program. The list processing of the pair of random numbers would take a little longer, according to my tests, so I let that behind. Overall about 50% faster than my first program, nothing that compares to your 18+ speedup when compared to my optimized program, though. Well done!

Gerson.
Find all posts by this user
Quote this message in a reply
03-17-2024, 10:44 PM (This post was last modified: 03-17-2024 10:46 PM by johnb.)
Post: #18
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-14-2024 06:20 PM)Valentin Albillo Wrote:  First of all:  what do I consider a rare \(\pi\) appearance ? Well, broadly speaking mostly any unexpected appearances of \(\pi\) having nothing to do with circles or other geometric matters (including arc lengths, areas, volumes, etc.,) ...

LOL! Here's another unexpected appearance of \(\pi\) ...

Back in the 1990's, I worked in the development department of a major Enterprise Resource Planning software firm. The organization was fairly flat so that I and most of my peers reported directly to the VP for new systems, and we self-managed. One day I was in his office talking with him about how he interfaced to upper management, and he informed me that over several years of empirical data gathering, he'd discovered most software engineers' estimates were off by a factor of somewhere between 3.1 and 3.15. He had no explanation for the cause of this value being so bizarrely close to \(\pi\), but he said "what works, works, so I multiply all my subordinates' estimates by pi before submitting them outside my organization, and it's never let me down so far."

So...

Apparently, the minds of most software engineers have something circular in their reasoning?

Daily drivers: 15c, 32sII, 35s, 41cx, 48g, WP 34s/31s. Favorite: 16c.
Latest: 15ce, 48s, 50g. Gateway drug: 28s found in yard sale ~2009.
Find all posts by this user
Quote this message in a reply
03-18-2024, 02:30 AM
Post: #19
RE: [VA] SRC #016 - Pi Day 2024 Special
All the funny Pi stuff connects with a circle, not necessarily directly from a circle, but maybe through angles.

https://arxiv.org/pdf/2403.09754.pdf

2/pi=sqrt(1/2)sqrt(1/2+1/2sqrt(1/2))sqrt(1/2+1/2sqrt(1/2+1/2sqrt(1/2)))...

Better pictures and explanation:
https://mathworld.wolfram.com/NestedRadical.html
Find all posts by this user
Quote this message in a reply
03-18-2024, 04:40 PM
Post: #20
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-17-2024 08:59 PM)Gerson W. Barbosa Wrote:  ...Overall about 50% faster than my first program, nothing that compares to your 18+ speedup when compared to my optimized program, though. Well done!

I would submit that this is a good example of when code performance overshadows code brevity. Yes, my program is a bit bulkier than the others, but I believe the performance is more important here than shaving off a few more bytes of code.

That said, I did intentionally decide to use COERCE2 instead of two individual COERCE steps. The COERCE2 version is very slightly slower, but I was willing to pay the ~1 second runtime price for the shorter version.

If the past is any predictor of the future, I'm sure that Valentin's version will be speedy in addition to the already-published 102 byte count. Smile
Find all posts by this user
Quote this message in a reply
Post Reply 




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