Post Reply 
[VA] SRC #013 - Pi Day 2023 Special
04-01-2023, 11:39 PM
Post: #32
RE: [VA] SRC #013 - Pi Day 2023 Special
  
Hi, all,

To end this thread, there's the subject of finding values of N which result in an approximation to \(\pi\) much closer than what would be statistically expected. Of course, the larger N, the better the appoximation on the long run, but perhaps there are values of N which defy the odds and result in unexpectedly close approximations.

To settle the matter, this 179-byte 4-liner finds them up to a given maximum N very, very quickly, listing all successive record-breakers:
    1  DESTROY ALL @ INPUT N @ SETTIME 0 @ INTEGER M(N) @ MAT M=CON @ P=2 @ WHILE P<=N @ S=P*P
    2  FOR K=S TO N STEP S @ M(K)=0 @ NEXT K @ P=FPRIM(P+1) @ END WHILE @ V=10 @ S=7
    3  FOR T=11 TO N @ S=S+(M(T)#0) @ X=SQR(6*T/S) @ Y=ABS(PI-X) @ IF Y<V THEN V=Y @ DISP T;X;V
    4  NEXT T @ DISP "OK";TIME
Let's find all record-breakers for N up to 30,000 (requires ~ 90 Kb of RAM):
    >RUN ->  ? 30000

         N       Pi Approx.       |Error|
       -------- -----------------------------
       (smallest values, which result in irrelevant approximations, not listed)     
          28   3.14362099197   0.00202833838
         153   3.14180962853   0.00021697494
         426   3.14145282771   0.00013982588
         862   3.14169206124   0.00009940765
         931   3.14153751379   0.00005513980
         936   3.14164722334   0.00005456975
         982   3.14155164428   0.00004100931
        1033   3.14156437967   0.00002827392
        1061   3.14161860223   0.00002594864
        1135   3.14158641730   0.00000623629
        1186   3.14159601478   0.00000336119
        2094   3.14159185312   0.00000080047
        5147   3.14159305181   0.00000039822
        5374   3.14159277156   0.00000011797
        7241   3.14159270516   0.00000005157
       14709   3.14159260812   0.00000004547
       25684   3.14159262180   0.00000003179


    OK timing (go71b: 23.37", Emu71/Win: 3.06", physical HP-71B: 49' 51")
Adding up more RAM to a virtual/physical HP-71B, we can go further, say up to N = 100,000 using ~300 Kb. We obtain the following additional record-breakers:
       65623   3.14159266166   0.00000000807
       67490   3.14159265758   0.00000000399
       89440   3.14159265330   0.00000000029

The above list of record-breakers would seem to end the discussion, but there's something which doesn't look good, the fact that there are several series of them which feature very close N and errors, such as these:
    931 3.14153751379 0.00005513980
    936 3.14164722334 0.00005456975
    982 3.14155164428 0.00004100931
looking almost redundant, as they're not that different.

It would seem preferable to find and list only those record-breakers which are a significant improvement over their predecessors, where "significant improvement" obeys some suitable criterium, and this 6-liner implements just that:
    1  DESTROY ALL @ INPUT N @ SETTIME 0 @ INTEGER M(N) @ MAT M=CON @ P=2 @ WHILE P<=N @ S=P*P
    2  FOR K=S TO N STEP S @ M(K)=0 @ NEXT K @ P=FPRIM(P+1) @ END WHILE @ U=1 @ V=10 @ Q=1 @ S=7
    3  FOR T=11 TO N @ S=S+(M(T)#0) @ X=SQR(6*T/S) @ Y=ABS(PI-X) @ IF Y>=V THEN 6
    4  W=T/Q @ Z=V/Y @ H=(Z-1)/(W-1) @ IF H<3 THEN 6
    5  Q=T @ V=Y @ DISP T;X;V;FNR(Z,3);FNR(W,3);FNR(H,3)
    6  NEXT T @ DISP "OK";TIME @ DEF FNR(N,D)=IROUND(10^D*N)/10^D
    >RUN ->  ? 30000

         N       Pi Approx.       |Error|      Epre/E  N/Npre    Merit
       -------- -------------------------------------------------------
       (smallest values, which result in irrelevant approximations, not listed)   
        1135   3.14158641730   0.00000623629  325.248  40.536    8.201
        1186   3.14159601478   0.00000336119    1.855   1.045   19.036
        2094   3.14159185312   0.00000080047    4.199   1.766    4.178 
        5374   3.14159277156   0.00000011797    6.785   2.566    3.693
        7241   3.14159270516   0.00000005157    2.288   1.347    3.706


    OK timing (go71b: 25.4", Emu71/Win: 3.33", physical HP-71B: 54' 11")
Again, using more RAM we can search up to, say, N = 100,000 and we get two more:
       67490   3.14159265758   0.00000000399    2.023   1.028   35.942
       89440   3.14159265330   0.00000000029   13.759   1.325   39.229
      
Why do we exclude, e.g. 5,147 from the list ? Because 5,147 's error is 2.010x smaller than its predecessor's, 2,094, but at the cost of 2.458x larger N, so it's no real improvement over 2,094 and doesn't really pay off having to waste so much more time for such a meager improvement. Thus, its merit factor is too low, doesn't meet the suitability criterium and is excluded from the list; these are the relevant numbers:
    2094  3.14159185312  0.00000080047  4.199  1.766  4.178
    5147  3.14159305181  0.00000039822  2.010  2.458  0.693
and the same goes for all other omitted values. Only the ones which result in a marked improvement as per the criterium are deemed worthy to be listed.

Finally, we can do the search for N much greater than 100,000, up to 1,500,000 and beyond by using boolean operators and variables and I've written such a version of this program implementing them, but that's left to the reader as an exercise ... Smile

Thanks to all of you who participated, much appreciated and I hope you enjoyed it all.

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
Post Reply 


Messages In This Thread
RE: [VA] SRC #013 - Pi Day 2023 Special - Valentin Albillo - 04-01-2023 11:39 PM



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