All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Baking the best pie (Posted on 2012-11-02)
Find a p/q fraction(fractions?)that gives more exact digits of pi(3.1415926535..etc) than the number of digits of p and q combined.

Feel free to comment on "pi" approximations.

Comments: ( Back to comment list | You must be logged in to post comments.)
 more Comment 2 of 2 |

The program uses a variation of the Euclidean Algorithm for finding the greatest common divisor. Of course with pi/1 there's no such thing:

`3.14159265358979 =    1*pi   +01                =    0*pi   +10.14159265358979 =    1*pi   -30.00885142487    =   -7*pi  +220.00882128054    =  106*pi -3330.00003014433    = -113*pi +355`

At each stage a number on the left is divided into the number above it, with the remainder place below it. The quotient is used to multiply the numbers on the divisor line and subtract from the numbers above. For example, as the 1 is above 0.14159265358979, the quotient is 7 and the remainder is 0.00885142487 as 7*0.14159265358979 + 0.00885142487 = 1. The 7 then is multiplied by the 1*pi - 3 and added to the 0*pi + 1 to get -7*pi + 22.

10    point 100:kill "pimain.txt"
11    open "pimain.txt" for output as #2
20    Ratio=#pi
30    Rat=cutspc(str(Ratio))
40    Dn=Ratio:Dr=1
50    D1=1:N1=0
60    D2=0:N2=1
70    Cntnue=1
80    while Cntnue
85     Prevden=Den:Prevnum=Num
90     Q=int(Dn/Dr)
100     R=Dn-Q*Dr
110     Den=D1-Q*D2
120     Num=N1-Q*N2
130     Dn=Dr
140     Dr=R
150     D1=D2:N1=N2
160     D2=Den:N2=Num
170     D=cutspc(str(abs(D2)))
180     N=cutspc(str(abs(N2)))
190     Den=abs(Den)
200     Num=abs(Num)
210     Ld=len(D):Ln=len(N):La=Ld+Ln
220     Precpi=int(Ratio*10^La+0.5)
230     Precapp=int((Num/Den)*10^La+0.5)
240     if Precpi=Precapp then
250       :print N;"  ";D:print Num/Den;
255       :print #2,N;"  ";D:print #2,Num/Den;
260       :if Precpi=Precapp then
261         :print "*";La;La+1:print Ratio
262         :print #2,"*";La;La+1:print #2,Ratio:else print:print #2,:endif
280       :repeat
290         :A=inkey
300       :until A>""
310       :if A=chr(27) then end
330    wend

produces the report shown below. Each entry starts with a numerator and denominator, separated by two spaces. Then appears the decimal result of that division an asterisk and the number of invested digits (length of numerator plus length of denominator), and the requisite number that's one higher. Pi itself is listed below it for comparison. The blank at the beginning of the comparison lines as well as the decimal point add up to the same as the two blanks separating numerator from denominator, so the point of match can be seen.

The method used is keeping track of the Euclidean algorithm for finding gcd, except that one of the numbers is irrational and so the algorithm never terminates, but rather provides the equivalent of successive levels of continued fractions. Levels whose decimal values do not exceed the number of digits used are not reported.

So, starting with the famous 355/113, and continuing with the next, 8958937768937/2851718461558:

(when the numbers get larger, I've split the fraction into two separate lines.)

`355 / 113 3.1415929203539823008849557522123893805309734513274336283185840707964601769911504424778761061946902654867256637168141592920353982300884955752212389380530973451327433628318584070796460176991150442477876106194690265486725663716814159292035398230088495575221238938053097345132743362831858407079646017699115044247787610619469026548672566371681415929203539823008849557522123893805309734513274336283185840707964601769911504424778761061946902654867256637168141592920353982300884955752212389 * 6  7  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`8958937768937 / 2851718461558 3.1415926535897932384626433755579089041211936213994912870394620143506446220647236259161293891623054583323516781941356459759132967037451108464490976788894882057502188962374493868030906022050945526244069293611733340798628296229403064731218251169423634014010618076993286720192027402992938267172770687799532380348769966379014986066154178385804533479408250153516888992197598268573869630020177769031436236468105741259847669225087995309085632285188694573894231429098645114309184263549737275 * 26  27  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`2646693125139304345 / 842468587426513207 3.1415926535897932384626433832795028841830621840162837701327737089604028993736402938143619911858081000240727721900875394085469325114691363614258229535245106527373097276033470664320449241415175422277550524476496215877302025556482374306389115129829259635153970566471495126394114371360858744453211503100550976820330464629392989736622108005215415073506118265704267457005129585118890094830755641424527427682811345415236893919894684108271584942465221055436513363651205074986098317340589134 * 37  38  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`4427007044615115050034854648525685871587 / 1409160108506276783085718440252375099653 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089955187427795323388745665125494825757227764837381643103645109330805000340658879213657072446032788131408687576928568340291042591144938668089750032121362005640630719399215939192847565719268050961155887766297675470884272834197900285813703965734859348272703524955890062120494328036984015137015243344412052972473486447286562942250017742643754161081904089364585251124472060402964057554794378435279505455900004 * 80  81  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`716918301303787149323038550270812273699415  ------------------------------------------228202182891085034903619974895950891885862 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986284526006268227847020192484587677968721215336010038328201000980443137011772439857703609622200180139707922160040281556823604228487742140682763292725677078623609901859535408786400817768061908324479783335745720181743427847660340305440757444032495338804126122654649718005459496818839633338174109596503114654996935257610944518788142009721738547866985544705364900555266352337838700833645364452042800163588 * 84  85  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`2635622779696759818963956926355997625653382829357706805515232 -------------------------------------------------------------838944787028681613144502774660896402692975681322322888764935 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066471270256713095079085079205267986489412777727850696636634883031453455841227877742734122271780523413816105896070444933892757527388409188865381017545638545924531707833314354723787731565843461940707355049133742930622210353150043747024651351441464616678745447806972154360546607388011306353939053660669643830300772028071033661940491251341665502776950572694133404267247 * 121  122  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`2805566453916402616788439453817210917066487546495895963005320692551644  ----------------------------------------------------------------------893039538627191313089158596549606265611472858084463970643690535852361 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317467109377897466995990438428615086735614780571410974213712178223335069186341326937051731516387222330963757171542694362219531525683813416160849678201209621257541948834810149012884061965666486373238743525887815306497368183197720139705424604488937416349644948964844223263165758568539158083836861414985773497590048876170923228754107578324844791668 * 139  140  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`3103448995291663782826682198062590944849741419660647166245138225197243430479387308952790481796734804918099  987858496468489010389754786152989268495055922473506859285063463155440686602872966161674984095951267279994 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109757272312596394960513719633653668314743560534940722964652602506197978508674513553113450759514993421325704967891345066554468821655793064871833771736507602868742496797610211330717870985011691512259974730409072134749822269979410206481922784096814392790071533877135475435561729 * 211  212  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`47449023823422717451594836169381198840134089164995011450245185618387776847176840854174067173766596944222479515740143273879768480709913455315809719544718248  --------------------------------------------------------------------------------------------15103493372765657274145753764324412346673615736564990480645229502691940095166708783466819743670409392336434093031760588386010342390699617474201564040715683 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870065962823440683639668452988015631426519958144185314428550512110486986061407071154782048684180282343563176657689171279771314709682481659173989514993543687770201170429641606333 * 310  311  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`77218763012947875896260141387840895765153098957286926771357228264887299556186982943500813316212472213986140712514080026085407837427744538953978747384035299651938205659975967084875142  --------------------------------------------------------------------------------------------24579495665904543209946128434289376762773577955494612000751764626667288353060618721856236143577512620383065677240123054405331058082350247359723783112680144917419709890757846695677215 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113024263310275039175858003600010433716538298021833191646274791996554461236692083702381530432844340310527797778725292668 * 364  365  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`8452289645093648572854510446837444712810135706567256315984593131894585981221350842501104680589855218813960495808474564320698098114934611583182759111943606351763151405582501444724745992482165813705867717921079545509  --------------------------------------------------------------------------------------------2690447354922191726452862341736386948549121339501185061542644751817189058984579561476190981895357103211942547095554118627877286348144047904875382264957560260867163990127782505292095264012421812368972205650281709434 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861204517628927987642127201718809489527691718639340288218 * 428  429  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`1901870728566923076090143944714770339621590768313546337192526115562704339680963564320007808107929370299752345187688835741387003036853361285671158059867702399073227994426905220194699766118756059055619036488502928002591  --------------------------------------------------------------------------------------------605384255146420326102361023215940531716391478150345020739231253172134740688232476946000058713774549796561447468267746412874022717544100946587144148739626803435133473281606663121381125761746030151344353855924025288111 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819324804646961879790707507019889940680942867384216 * 433  434  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`829811339066982130876058198968068410862650851015911973311226612700024485057349312961541969285196267406861823954979198922192105880351220076032665770174257080550463817983221086166360145838459204571042537355859890994714178639  --------------------------------------------------------------------------------------------264137152892430011699969916696643139695705442190816743007777612090652217173046962095469671017596981860796907631670496695516884285848965487333467142874468050234307173796701062864498309627509956854801151282493814161519811988 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931045335000516759458184301504896794805256 * 444  445  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`508239685501559807293084935851128442030769369296518599661444679177836287511429446251774461949809485175658215343577801278333998680876300795076100714009635384445119316669975702361861604328893720772564173289552095512449550742383  --------------------------------------------------------------------------------------------161777716446087068182119281713961832493697624026118952133686196582342261332207690917434237379920519659486003859262368656716405017273277436165739558427276397315380418261658678024905270494976424810609602571991742445112723313661 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185484779419325170732666655361289588 * 450  451  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248 `
`23072768944253239911774922829583808268526123351277548998476653810023371350764106937937225390616798314417955779651817110591913712157049531783381616544834809563516491649949487546463610128540948982550561408502447307624638576097797181979279  --------------------------------------------------------------------------------------------7344290456590148849947776191163285657336470355757350466365148581561355511203197708226259974745420768492256234677274748391829647386340326796205757621116092961565506136903907661631231409829601983610983435411476944453990444375332500581033 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567352250986225 * 471  472  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248  `

In fact, the investment of 433 digits yields 435 significant digits of pi, a gain of 2 ins
tead of just 1, and almost has another (and would have if truncated rather than rounded).
This seems to be the only such case in the above report.

 Posted by Charlie on 2012-11-02 11:56:59

 Search: Search body:
Forums (0)