Post Reply 
Happy Pi Day!
03-14-2017, 01:14 AM
Post: #1
Happy Pi Day!
[Image: PiDay_zpsagymwcsu.jpg]

Code:

%%HP: T(3)A(R)F(.);
DIR
  PId
  \<< PUSH RAD -105 CF -3 CF DUP .653 * 1.74 + IP R\->I DUP 2 MOD + DUP 4 * OVER DUPDUP 1 - 1
    FOR i i SQ SWAP / PICK3 + ROT SWAP -1
    STEP INV NIP UNROT + 1 - 3 0 UNROT
    FOR i i INV i 2 - INV - + -4
    STEP - 4 * EXPAND \->STR "/" " " SREPL DROP "'" "" SREPL DROP OBJ\-> DUP SIZE R\->I ALOG OVER - PICK3 * SWAP IQUOT + \->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + 1 ROT 2 + SUB POP
  \>>
  PIn
  \<< PUSH RAD -105 CF -3 CF DUP 4 * OVER DUPDUP 1 - 1
    FOR i i SQ SWAP / PICK3 + ROT SWAP -1
    STEP INV NIP UNROT + 1 - 3 0 UNROT
    FOR i i INV i 2 - INV - + -4
    STEP - 4 * EXPAND \->STR "/" " " SREPL DROP "'" "" SREPL DROP OBJ\-> DUP SIZE R\->I UNROT PICK3 ALOG OVER - PICK3 * SWAP IQUOT + \->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + 1 ROT .8 * 2 + SUB POP
  \>>
  PIdLF
  \<< PUSH RAD -105 CF -3 CF DUP 2 + 'DIGITS' STO .653 * 1.74 + IP R\->I DUP 2 MOD + DUP 4 * OVER DUPDUP 1 - 1
    FOR i i SQ SWAP FDIV PICK3 FADD ROT SWAP -1
    STEP FINV NIP UNROT + 1 - 3 0 UNROT
    FOR i i FINV i 2 FSUB FINV FSUB FADD -4
    STEP FSUB 4 FMULT ZZ\<-\->F DROP \->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + DUP SIZE 1 - 1 SWAP SUB POP
  \>>
  PiM
  \<< PUSH RAD -105 CF -3 CF RAD DUP 2 / 5 DUP2 LOG / \->NUM CEIL 2 * 1 - R\->I ATN1X 16 * 239 ROT OVER LOG / \->NUM CEIL 2 * 1 - R\->I ATN1X 4 * - EXPAND \->STR "/" " " SREPL DROP "'" "" SREPL DROP OBJ\-> DUP SIZE R\->I ALOG OVER - PICK3 * SWAP IQUOT + \->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + 1 ROT 2 + SUB POP
  \>>
  ATN1X
  \<< -1 UNROT 1 4 ROLLD OVER SQ PICK3 INV 4 ROLLD UNROT 3 SWAP
    FOR i OVER * DUP i * INV 5 PICK * 4 ROLL + UNROT 5 ROLL 4 ROLLD 2
    STEP DROP2 UNROT DROP2
  \>>
  PiMlf
  \<< PUSH RAD -105 CF -3 CF RAD DUP 2 + 'DIGITS' STO 2 / 5 DUP2 LOG / \->NUM CEIL 2 * 1 - R\->I ATN1Xlf 16 FMULT 239 ROT OVER LOG / \->NUM CEIL 2 * 1 - R\->I ATN1Xlf 4 FMULT FSUB ZZ\<-\->F DROP \->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + DUP SIZE 1 - 1 SWAP SUB POP
  \>>
  ATN1Xlf
  \<< -1 UNROT 1 4 ROLLD OVER SQ PICK3 FINV 4 ROLLD UNROT 3 SWAP
    FOR i OVER FMULT DUP i * FINV 5 PICK FMULT 4 ROLL FADD UNROT 5 ROLL 4 ROLLD 2
    STEP DROP2 UNROT DROP2
  \>>
  DIGITS 52
END
Find all posts by this user
Quote this message in a reply
03-14-2017, 06:17 AM
Post: #2
RE: Happy Pi Day!
Directing your attention to the post below, which will let you calculate up to 4.915 digits of Pi using41 MCODE.....

http://www.hpmuseum.org/forum/thread-7864.html

Module image is included.
Find all posts by this user
Quote this message in a reply
03-14-2017, 08:22 AM
Post: #3
RE: Happy Pi Day!
Estimation of PI on HP15C with Monte Carlo simulation: DropBox link (pdf)

Csaba
Find all posts by this user
Quote this message in a reply
03-14-2017, 12:47 PM
Post: #4
RE: Happy Pi Day!
You know, just as I was driving to work this morning, I thought, damn, I should have grabbed my 82240 on the way out and printed a few hundred digits of pi with my 48SX!

Guess I'll go dig through the software library and see what I can do with my DM41L.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-14-2017, 01:06 PM
Post: #5
RE: Happy Pi Day!
Happy Pi Day 2017! Cool program, Gerson!

Next year should everything work out, I'll be celebrating my 41st birthday (I'm 40 today) with an HP 41C.


Attached File(s) Thumbnail(s)
   
Visit this user's website Find all posts by this user
Quote this message in a reply
03-14-2017, 01:22 PM
Post: #6
RE: Happy Pi Day!
(03-14-2017 01:06 PM)Eddie W. Shore Wrote:  Happy Pi Day 2017! Cool program, Gerson!

Next year should everything work out, I'll be celebrating my 41st birthday (I'm 40 today) with an HP 41C.

Eddie, I wish you a nice and cheerful day and may all your goals come true!

Jose Mesquita
RadioMuseum.org member

Find all posts by this user
Quote this message in a reply
03-14-2017, 01:24 PM
Post: #7
RE: Happy Pi Day!
Thank you Gerson!
Visit this user's website Find all posts by this user
Quote this message in a reply
03-14-2017, 03:50 PM (This post was last modified: 03-14-2017 07:34 PM by Gerson W. Barbosa.)
Post: #8
RE: Happy Pi Day!
(03-14-2017 01:24 PM)Eddie W. Shore Wrote:  Thank you Gerson!

You are most welcome, Eddie!

(03-14-2017 01:06 PM)Eddie W. Shore Wrote:  Next year should everything work out, I'll be celebrating my 41st birthday (I'm 40 today) with an HP 41C.

Happy birthday, as well! Since last year's Pi Approximation Day I'm Fib(10) years old. I wish all of us here to celebrate many and many Pi Days and Fib(11) birthdays one day :-)

Gerson.

Edited to add a forgotten verb between a pronoun and an adverb and to remove a definite article. I don't want to sound – or read – "awkward" :-)
Find all posts by this user
Quote this message in a reply
03-14-2017, 05:07 PM (This post was last modified: 03-16-2017 12:03 AM by Gerson W. Barbosa.)
Post: #9
RE: Happy Pi Day!
Thank you all for the Pi-related links and comments!

The first program in the directory, PId, computes d digits of π using the simple formula

\[\pi=4\cdot \arctan (1)\]

Arctan(1) is calculated using the formula previously presented here,

\[\frac{\pi }{4}= 1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\cdots +\frac{1}{2n-3}-\frac{1}{2n-1}+\frac{1}{4n+\frac{1^{2}}{n+\frac{2^{2}}{4n+\frac{3^{2}}{n+\frac{4^{2}}{4n+...​ }}}}}\]

using n equal number of terms of the regular series and of the continued fraction. The second program (PIn) computes the sum of such n terms. Its slowness for large number of digits or terms is due to the limitation of the HP-49G/50g when dealing with the resulting very long algebraic expression before it is eventually expanded. Freeing more memory might help.

The third program, PIdLF, is a LongFloat Library version of PId.

PiM and PiMlf, its equivalent LongFloat version, compute π using Machin's formula:

\[\pi = 16\cdot \arctan \frac{1}{5}-4\cdot \arctan \frac{1}{239}\]

That's the same formula used by William Shanks to compute π about 150 years ago, after spending 15 years in the task, done by hand, without using any computing devices whatsoever. The last 180 digits being wrong is not impressive, the first 527 digits being correct is. That's why we have used two different methods. As we can see, but for for a rounding in the last digits in the fourth printing, all digits match.

Gerson.
Find all posts by this user
Quote this message in a reply
03-15-2017, 02:53 AM
Post: #10
RE: Happy Pi Day!
piball
Find all posts by this user
Quote this message in a reply
03-15-2017, 11:04 AM
Post: #11
RE: Happy Pi Day!
355/113 is enough for me B-)
Find all posts by this user
Quote this message in a reply
03-15-2017, 03:57 PM (This post was last modified: 03-15-2017 10:42 PM by Gerson W. Barbosa.)
Post: #12
RE: Happy Pi Day!
(03-15-2017 11:04 AM)franz.b Wrote:  355/113 is enough for me B-)

That's perhaps the most efficient rational approximation for \(\pi\): six digits in a mnemonic sequence giving seven correct digits.

The 1762-digit fraction below gives only 707 digits (perhaps a few more) and is somewhat hard to memorize.

------------------------------

707

« PUSH RAD -105 CF -3 CF DUP .653 * 1.74 + IP R→I DUP 2 MOD + DUP 4 * OVER DUPDUP 1 - 1
FOR i i SQ SWAP / PICK3 + ROT SWAP -1
STEP INV NIP UNROT + 1 - 3 0 UNROT
FOR i i INV i 2 - INV - + -4
STEP - 4 * EXPAND →STR "'" "" SREPL ROT DROP2 POP
»

:s: 1274.5305 (time on my iPhone)

35471270118869764571868355345605539644932682747073948595148728173396218838668496​80716426124902558473273344718040678263223310007300548098446944940735563175195185​79323304238108709671904418651693017693336383731106603027004914829454445857328201​05924605428311002761716473437615659392155761487611060526868601273453231898921986​03346750895370582643794723222113030733123697513779494958569010520916965922261361​50912781934736718101804617138969374612667021145232878466424131101366141969361769​76029123163627319062908158192243507523352526680253139185385238035253759673955361​64753305772996193396743873266368301326861081810651321062825642235467130083886694​29978624344603656750671217335693097846544875989492305955191455496667840796358958​54318597270213456322812296404622832012961138994524991861828477269161456938399075​36641613518969979837287818614714737709619011495381477179300261556327556859088076​8
/
11290855954331929765162875991672337005763900233129789215007366526465816927928074​99910519051390719630100518054981495532402000479709747220290019459549698290971530​80519808598234473145589659408612308338495967787945281300419514221238758104012207​91617778874064429696755480283483475358841356899944430809069589392140510992481520​00826115469277539329220641057707652808895534744233006721848321578069349072611507​65976928124031425881129023075006910569280746723187915395363232463456021210395860​67513765201530999299014996124193701700437357615236050277051928851200804664427103​09230073374186050477298794155770558099350191823502206767887178212506347749784516​42170205919755951022290456573354203993293526964682167478504255902556770952397557​10260367678979941803636081060659736127271086039016609855284050676165107007788796​80847217941144275687554984641214388815408615188638900225501578409931091369249187​5

------------------------------

Edited to add a missing 's'.
Edited again per Valentin's observation below.
Find all posts by this user
Quote this message in a reply
03-15-2017, 08:56 PM
Post: #13
RE: Happy Pi Day!
.
Hi, Gerson:

(03-15-2017 03:57 PM)Gerson W. Barbosa Wrote:  
(03-15-2017 11:04 AM)franz.b Wrote:  355/113 is enough for me B-)

That's perhaps the most efficient rational approximation for \(\pi\): six digits in a mnemonic sequence giving six correct decimal places.


More like seven correct decimal places, not six: 3,1415929.. vs. 3,1415926...

In my so-so humble opinion, the very best \(\pi\) approximation (i.e.: the more correct digits using the less digits and operations) is by far:

          Ln(640320^3)/Sqrt(163) = 3,141592653589793016...

which gives 16 correct digits.

Regards.
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-15-2017, 10:50 PM (This post was last modified: 03-15-2017 10:58 PM by Gerson W. Barbosa.)
Post: #14
RE: Happy Pi Day!
(03-15-2017 08:56 PM)Valentin Albillo Wrote:  
(03-15-2017 03:57 PM)Gerson W. Barbosa Wrote:  That's perhaps the most efficient rational approximation for \(\pi\): six digits in a mnemonic sequence giving six correct decimal places.


More like seven correct decimal places, not six: 3,1415929.. vs. 3,1415926...

Hello, Valentin,

By decimal places I meant the ones at the right of the decimal point, but I have edited the post to avoid the ambiguity. Thanks!

Gerson.
Find all posts by this user
Quote this message in a reply
03-15-2017, 11:33 PM
Post: #15
RE: Happy Pi Day!
(03-14-2017 05:07 PM)Gerson W. Barbosa Wrote:  PiM and PiMlf, its equivalent LongFloat version, compute π using Machin's formula:

\[\pi = 16\cdot \arctan \frac{1}{5}+4\cdot \arctan \frac{1}{239}\]

I think that "+" should be a "-".

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
03-16-2017, 12:06 AM
Post: #16
RE: Happy Pi Day!
(03-15-2017 11:33 PM)Joe Horn Wrote:  
(03-14-2017 05:07 PM)Gerson W. Barbosa Wrote:  PiM and PiMlf, its equivalent LongFloat version, compute π using Machin's formula:

\[\pi = 16\cdot \arctan \frac{1}{5}+4\cdot \arctan \frac{1}{239}\]

I think that "+" should be a "-".

Fixed. Thanks!
Find all posts by this user
Quote this message in a reply
03-16-2017, 01:22 AM
Post: #17
RE: Happy Pi Day!
Base 16, each digit of Pi (or any arbitrary digit of Pi) can be computed independent of the others.

https://en.wikipedia.org/wiki/Bailey%E2%...fe_formula

Other formulae may be found here: https://www.carma.newcastle.edu.au/jon/pi-2010.pdf

Whether using quadratic or cubic or quartic convergence type formulae, computing a large number of digits of Pi take about the same time. The last step always needs more precision than any of the other steps.
Find all posts by this user
Quote this message in a reply
03-17-2017, 10:00 PM (This post was last modified: 03-17-2017 10:02 PM by EdS2.)
Post: #18
RE: Happy Pi Day!
(03-15-2017 08:56 PM)Valentin Albillo Wrote:  In my so-so humble opinion, the very best \(\pi\) approximation (i.e.: the more correct digits using the less digits and operations) is by far:

          Ln(640320^3)/Sqrt(163) = 3,141592653589793016...

which gives 16 correct digits.
Spectacular! Are you also aware of this 18 digit approximation?
    12/sqrt(190) * ln((2 sqrt 2 + sqrt 10)*(3+sqrt 10))
via
https://www.johndcook.com/blog/2012/10/0...oximation/
Find all posts by this user
Quote this message in a reply
03-18-2017, 02:17 AM (This post was last modified: 03-18-2017 02:19 AM by Gerson W. Barbosa.)
Post: #19
RE: Happy Pi Day!
(03-17-2017 10:00 PM)EdS2 Wrote:  
    12/sqrt(190) * ln((2 sqrt 2 + sqrt 10)*(3+sqrt 10))

Or, equivalently, using eight digits:

' √(18/95)*(LN(2)+2*(ASINH(2)+ASINH(3)))'                (45 bytes)

« 2 ASINH 3 ASINH + 2 * 2 LN + 18 95 /  √ * »            (55.5 bytes)


It doesn't compare to the previous one, though:

'3*LN(640320)/√163'                                      (33 bytes)

« 3 640320 LN * 163  √ / »                               (38 bytes)



This attempt needs twice more bytes for about the same accuracy:

'1/163*(69-EXP(-8/(1/163/401+1)))+e'                     (70 bytes)

« 163 INV DUP 401 / 1 + -8 SWAP / EXP 69 SWAP - * e + »  (65.5 bytes)
Find all posts by this user
Quote this message in a reply
03-18-2017, 03:43 AM
Post: #20
RE: Happy Pi Day!
(03-15-2017 03:57 PM)Gerson W. Barbosa Wrote:  
(03-15-2017 11:04 AM)franz.b Wrote:  355/113 is enough for me B-)
That's perhaps the most efficient rational approximation for \(\pi\): six digits in a mnemonic sequence giving seven correct digits.

Here's an even better one:

\(\frac{190187072856692307609014394471477033962159076831354633719252611556270433​96809635643200078081079293702997523451876888357413870030368533612856711580598677​02399073227994426905220194699766118756059055619036488502928002591}{6053842551464​20326102361023215940531716391478150345020739231253172134740688232476946000058713​77454979656144746826774641287402271754410094658714414873962680343513347328160666​3121381125761746030151344353855924025288111}\)

That's 433 digits (217 digits over 216 digits) that returns 435 digits of pi. Converting the above into a mnemonic is left as an exercise for the student. Smile

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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