Creating digits of pi

02062018, 12:24 AM
Post: #1




Creating digits of pi
Yes, this old chestnut again. Except my guuglefoo has foo'ed and I can't find anything in HP50g that's relevant. Put simply, I want to have a procedure that generates x digits of PI starting from an offset, i.e. 1:offset, 2:digit_count. An example would be ten digits of PI starting from the 49,238th position.
I don't know of good programs that can generate only a subset of digits, only of programs that can generate x digits of PI as a string (PI50G being one example I came across). Does anyone have a good pointer to what I'd like? (Need is a strong word, perhaps desire just for the sake of it). (Post 168) Regards, BrickViking HP50g Casio fx9750G+ Casio fx9750GII (SH4a) 

02062018, 01:38 AM
Post: #2




RE: Creating digits of pi
There *is* a way of directly calculating the Nth digit of pi (without generating all the previous digits) but only in hex. Nobody to date has discovered a way of doing it for pi in base 10.
X<> c Joe 

02062018, 09:24 PM
Post: #3




RE: Creating digits of pi
(02062018 01:38 AM)Joe Horn Wrote: There *is* a way of directly calculating the Nth digit of pi (without generating all the previous digits) but only in hex. Nobody to date has discovered a way of doing it for pi in base 10. Why not just convert the hex to decimal? Tom L DM42 SN: 00025 (Beta) SN: 00221 (Production) 

02062018, 10:38 PM
Post: #4




RE: Creating digits of pi
(02062018 09:24 PM)toml_12953 Wrote: Why not just convert the hex to decimal? That's not the easiest thing in the world for an inexperienced user like me. I can certainly convert integers, but converting stuff to the right of the hexadecimal point is quite a bit beyond me; though I do understand it uses powers of two, it uses them in a fractional way, i.e. a^½ (SQR()), a^(¼) (fourth root) and so on. The problem actually goes deeper than this though. Converting a fractional power of 16 is only half the issue, and would still result in multiple decimal digits as a result, not the single digit sequence I was after. Let's consider the second hex digit as an example: \[ \{ 1/256 .. 255/256 \} \notin \{ 1/16 .. 15/16 \} \] 1/256 = 3.90625E3, 2/256 = 7.8125E3 … That's six digits and a decimal point, just for the first hex decimal. (Post 169) Regards, BrickViking HP50g Casio fx9750G+ Casio fx9750GII (SH4a) 

02072018, 10:30 PM
Post: #5




RE: Creating digits of pi
LOL, this topic makes my brain hurt.
Thanx !!! 2speed HP41CX,int2XMEM+ZEN, HPIL+DEVEL, HPIL+X/IO, I/R, 82143, 82163, 82162 25,35,45,55,65,67,70,80 

02082018, 02:59 AM
(This post was last modified: 02082018 03:13 AM by Valentin Albillo.)
Post: #6




RE: Creating digits of pi
(02062018 01:38 AM)Joe Horn Wrote: There *is* a way of directly calculating the Nth digit of pi (without generating all the previous digits) but only in hex. Nope. It also works for base 2 as well. Quote: Nobody to date has discovered a way of doing it for pi in base 10. It can be proved that there's no formula in base 10 for Pi like the one for bases 16 and 2. There are base10 formulas for many other constants but not for Pi. See A compendium of BBPtype formulas. V. . 

02082018, 04:22 AM
Post: #7




RE: Creating digits of pi
(02072018 10:30 PM)TASP Wrote: LOL, this topic makes my brain hurt. And I thought I had it tough! I had to google for the set theory symbols for "not in a set", I haven't done this sort of thing since 1984! So far, the only way I've found to partially solve my problem is: generate all N digits of pi with PI50G from 3.14...., keeping the last x digits. I think that's the only feasible way to do it, and is infeasible after a certain number of N, at least on a 50G. It would be larger for calculators with more storage such as the Prime—assuming a PI50G equivalent on that platform, but would still eventually run into problems. (Post 171) Regards, BrickViking HP50g Casio fx9750G+ Casio fx9750GII (SH4a) 

02082018, 12:26 PM
Post: #8




RE: Creating digits of pi
(02082018 04:22 AM)brickviking Wrote: ... on that platform, but would still eventually run into problems. A little 'look ahead' on another platform (slow laptop using REXX, an interpreter language) showing the last 30 digits, time elapsed in seconds, iterations, and method. requested 500 digits: ...673518857527248912279381830118358 4.056000 1643 Newton ...673518857527248912279381830119702 1.248000 1034 MadhavaLeibniz ...673518857527248912279381830119702 0.905000 516 MadhavaLeibniz mod ...673518857527248912279381830119104 4.399000 826 Vieta ...673518857527248912279381830119192 5.975000 825 x*Atan(y) ...673518857527248912279381830119497 0.078000 9 BrentSalamin ...673518857527248912279381830120747 0.109000 4 Borwein&Borwein ...673518857527248912279381830119494 1.202000 411 BaileyBorweinPlouffe requested 5000 digits: ...441842631298608099888687413260483 9.173000 12 BrentSalamin ...441842631298608099888687413257076 12.355000 6 Borwein&Borwein ...441842631298608099888687413260456 1169.175000 4146 BaileyBorweinPlouffe So up to some of the very last digits the different methods' results are the same (Whew!). But with different effort. So the method of BrentSalamin requires within the loop a sqare root and Borwein&Borwein the forth root to the requested precission. Currently I use a root fining process as I had no time yet if a CORDIClike way up to 5000 digits and more woud i) be possible and ii) be an effective gain in speed. Ciao.....Mike 

02082018, 01:02 PM
Post: #9




RE: Creating digits of pi
(02082018 02:59 AM)Valentin Albillo Wrote:(02062018 01:38 AM)Joe Horn Wrote: There *is* a way of directly calculating the Nth digit of pi (without generating all the previous digits) but only in hex. So what good is it in base 16? What use does it have? Can you calculate areas or volumes with it? Tom L DM42 SN: 00025 (Beta) SN: 00221 (Production) 

02082018, 03:39 PM
Post: #10




RE: Creating digits of pi
(02082018 01:02 PM)toml_12953 Wrote: So what good is it in base 16? What use does it have? Can you calculate areas or volumes with it? Wrong question. Since 2016 Pi is known to more than 22*10^12 digits, so if you knew the distance of the transNeptunian object (134340) Pluto precisely and it would travel on a perfect circle you could calculate its orbit exactly to subatomic dimensions. So what good is it? Even 35 decimal places (Ludolph van Ceulen, 1610) are far away from workaday tasks. The goal is, have a formula that works and have an apparatus that works fast with this formula. The goal behind this is a) hours of fun, b) get workaday tasks done in almost no time. Ciao.....Mike 

02082018, 03:50 PM
Post: #11




RE: Creating digits of pi
(02082018 03:39 PM)Mike (Stgt) Wrote:(02082018 01:02 PM)toml_12953 Wrote: So what good is it in base 16? What use does it have? Can you calculate areas or volumes with it? Fun? I just don't see fun in calculating something useless. Of course I'm an engineer, not a mathematician so anything theoretical has little or no interest for me. Tom L DM42 SN: 00025 (Beta) SN: 00221 (Production) 

02082018, 06:58 PM
Post: #12




RE: Creating digits of pi
(02082018 03:50 PM)toml_12953 Wrote: Fun? I just don't see fun in calculating something useless. Of course I'm an engineer, not a mathematician so anything theoretical has little or no interest for me. Fun is something emotional, and emotions are known to lower the IQ fast and considerable to 50 or so. Strange enough, as for humans the drive to understand something is stronger than sex drive, it is said. So the mainly motivation for many scientists could be just the joy of "now I know", quite possible that an engineer is trained diversely, think and think different nothing but slogans, fun at work something useless. With hindsight worthles 'trouble and sorrow'. Ciao.....Mike 

02082018, 07:33 PM
Post: #13




RE: Creating digits of pi
(02082018 06:58 PM)Mike (Stgt) Wrote: Fun is something emotional, and emotions are known to lower the IQ fast and considerable to 50 or so. Strange enough, as for humans the drive to understand something is stronger than sex drive, it is said. So the mainly motivation for many scientists could be just the joy of "now I know", quite possible that an engineer is trained diversely, think and think different nothing but slogans, fun at work something useless. With hindsight worthles 'trouble and sorrow'. Now when I see one of my circuits in a spacecraft perform perfectly, I do find that fun so I'm not criticizing how anyone finds fun but just saying that for me, calculating for it's own sake isn't fun. À chacun ses goûts! Tom L DM42 SN: 00025 (Beta) SN: 00221 (Production) 

02082018, 09:25 PM
Post: #14




RE: Creating digits of pi
(02082018 03:50 PM)toml_12953 Wrote: Of course I'm an engineer, not a mathematician so anything theoretical has little or no interest for me.I have no intention to be polemic, anyway the above sentence sounds to me like "I'm a driver I don't need to know how the engine in my car or drivetrain in my bike works." And while that is completely legit, knowing the tools that one uses a bit better is nothing bad, rather it should improve the results at the end. Wikis are great, Contribute :) 

02082018, 11:48 PM
(This post was last modified: 02082018 11:49 PM by Gerson W. Barbosa.)
Post: #15




RE: Creating digits of pi
(02082018 12:26 PM)Mike (Stgt) Wrote:(02082018 04:22 AM)brickviking Wrote: ... on that platform, but would still eventually run into problems. MadhavaLeibniz is interesting, especially because it's from the XIVth century. And yet we can use it on the HP50g to compute 500 digits, if we are not in a hurry: 500 « 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 FXND DUP SIZE R>I ALOG OVER  PICK3 * SWAP IQUOT + >STR DUP HEAD 51 FC? { "." } { "," } IFTE + SWAP TAIL + 1 ROT 2 + SUB POP » TEVAL > 2: "3. 1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 8214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196 4428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273 7245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094 3305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912" 1: s:21533.1807 21533 seconds on my HP50g (almost 6 hours!) This is much longer than it should be, as I am using no external longfloat library (only the builtin Long Int in UserRPL). By using an arbitrary precision library, the running time might be significantly decreased. Quoting from the Wikipedia article on Madhava of Sangamagrama: Quote:This text attributes most of the expansions to Madhava, and gives the following infinite series expansion of π, now known as the MadhavaLeibniz series: Perhaps that Wikipedia article should be updated. The next correction terms are Rn = (4n^3 + 13n)/(16n^4 + 56n^2 +9), Rn = (4n^4 + 29n^2 + 16)/(16n^5 + 120n^3 + 89n) and Rn = (16n^5 + 216n^3 + 389n)/(64n^6 + 880n^4 + 1756n^2 + 225) Madhava's correction terms are simply the first three approximants to the continued fraction in the following expression, from an old thread: \[\frac{\pi }{4}= 1\frac{1}{3}+\frac{1}{5}\frac{1}{7}+\cdots +\frac{1}{2n3}\frac{1}{2n1}+\frac{1}{4n+\frac{1^{2}}{n+\frac{2^{2}}{4n+\frac{3^{2}}{n+\frac{4^{2}}{4n+... }}}}}\] From observation, 2*d/3 terms of the series and the corresponding correction term (or the evaluation of the same number of terms of the continued fraction) are necessary to obtain d correct decimal places of π. 

02092018, 02:01 AM
Post: #16




RE: Creating digits of pi
(02082018 11:48 PM)Gerson W. Barbosa Wrote: MadhavaLeibniz is interesting, [...] Seems I confused by so many formulas. What you quote is the MadhavaLeibniz formula. In contrast what I use is a more rapidly converging series also from Madhava. Code: s = 1 To reduce the loop overhead I merged two steps (what results in a remarkable gain on my system): Code: s = 1 BTW, instead of tantalizing your real machine for 6 hrs, I suggest a well known emulator of it. Recently I set it to authentic speed for some reason, and I am so glad I can switch it back to full speed. Could help in this case too. Ciao.....Mike 

02092018, 02:42 AM
Post: #17




RE: Creating digits of pi
(02092018 02:01 AM)Mike (Stgt) Wrote:(02082018 11:48 PM)Gerson W. Barbosa Wrote: MadhavaLeibniz is interesting, [...] You're still limited to the precision of a variable (Pi), right? How would you go beyond 12 or 13 digits? If you can't, why go to all that trouble to get a number you can get with a single command. That's not a rhetorical question, I'd really like to know. Tom L DM42 SN: 00025 (Beta) SN: 00221 (Production) 

02092018, 12:08 PM
Post: #18




RE: Creating digits of pi
(02092018 02:42 AM)toml_12953 Wrote: You're still limited to the precision of a variable (Pi), right? How would you go beyond 12 or 13 digits? Sorry, I did not mention that you should take it as pseudocode only. Well, it is REXX what I boiled down to the essential loop. So a 'minor' detail went up in smoke: numeric digits 500 what sets precision of all variables and has its effect on the loop end criterion DO..UNTIL m = m + n what is  I confess  an awesome concealment or simple substitution of the compare n/m < epsilon (I quit the loop when it has no influence on the result any more). How to run REXX? Try Regina, or fast brexx from CERN, or Open Object Rexx (I used it for a HP7470A simulation), or NetRexx, or  very outstanding  get a mainframe under Hercules on your machine (which could be a Raspberry Pi  tested, works). Ciao.....Mike 

02092018, 12:43 PM
Post: #19




RE: Creating digits of pi
(02092018 12:08 PM)Mike (Stgt) Wrote:(02092018 02:42 AM)toml_12953 Wrote: You're still limited to the precision of a variable (Pi), right? How would you go beyond 12 or 13 digits? Ah! That explains it. Please excuse my obtuseness. Tom L DM42 SN: 00025 (Beta) SN: 00221 (Production) 

02092018, 12:54 PM
(This post was last modified: 02092018 01:13 PM by toml_12953.)
Post: #20




RE: Creating digits of pi
(02092018 12:08 PM)Mike (Stgt) Wrote:(02092018 02:42 AM)toml_12953 Wrote: You're still limited to the precision of a variable (Pi), right? How would you go beyond 12 or 13 digits? Here's a version in Decimal BASIC interpreter that returns 1000 digits before you can remove your finger from the Enter key on a 4.2 GHz Core i7: (PI is a reserved word in Decimal BASIC) Wait a second. That was fun. I didn't just have fun did I? No, not me. I refuse to have fun. Code: OPTION ARITHMETIC DECIMAL_HIGH ! 1000 digits precision Tom L DM42 SN: 00025 (Beta) SN: 00221 (Production) 

« Next Oldest  Next Newest »

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