### Author Topic: How I wish I could calculate pi...  (Read 1825 times)

0 Members and 1 Guest are viewing this topic.

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### How I wish I could calculate pi...
« on: May 04, 2015, 01:27:55 pm »
...in vanilla TI-BASIC. To a precision of more than 15 places.

Well, with the help of Jeremy Gibbons and myself, now there's hope!

This program is as fast as I could make it (though not too fast...this ain't Asm), and I welcome any improvements on size and speed. It uses simulated arbitrary precision arithmetic with lists. I have verified it for 100 digits, and the algorithm itself has been verified for 1,000 digits in Haskell.

Code is as follows:

PICALC.8xp
Code: [Select]
{1→ʟQ{180→ʟR{60→ʟT2→IClrHome501→D"CHANGE THE ABOVE NUMBER TO CALCULATE MORE OR LESS DIGITS"?→Str1For(J,1,DOutput(1,1,Str1Output(8,1,J"ABOVE FOR TESTING3(3I+1)(3I+2→U5ʟT→L1prgmAADJUSTL1→L35ʟR→L1prgmAADJUSTL1→L2(27I-12)ʟQ→L1prgmAADJUSTL1+L2→L1prgmAADJUSTL3→L2prgmADIVIDEθ→YStr1+sub("0123456789",Y+1,1→Str1(5I-2)ʟQ→L1prgmAADJUSTL1→L2YʟT→L1prgmAADJUSTL2-L1+ʟR→L1prgmAADJUST10UL1→L1prgmAADJUSTL1→ʟR10I(2I-1)ʟQ→L1prgmAADJUSTL1→ʟQUʟT→L1prgmAADJUSTL1→ʟTI+1→IEndAADJUST.8xp
Code: [Select]
DelVar BDelVar C1→ARepeat B or A>dim(L1C+L1(A→L1(AIf not(AnsA=dim(L1)+1-sum(int(1/(1+cumSum(abs(seq(L1(Z),Z,dim(L1),1,-1→Bint(10^(7)⁻¹Ans→CIf 0>L1(A-10^(7)Ans+L1(A→L1(A10^(7)fPart(10^(7)⁻¹L1(A→L1(AA+1→AIf C and Ans>dim(L1Then0→L1(A1+dim(ʟQ→dim(ʟQAns→dim(ʟRAns→dim(ʟTAns→dim(L2Ans→dim(L3EndEndACOMPARE.8xp
Code: [Select]
DelVar Gdim(L1→ARepeat G or A<1(L1(A)>L2(A))-(L1(A)<L2(A→GA-1→AEndADIVIDE.8xp
Code: [Select]
DelVar θprgmACOMPAREWhile G≥0Output(6,1," Output(6,1,θ"ABOVE FOR TESTINGL1-L2→L1prgmAADJUSTθ+1→θprgmACOMPAREEnd
« Last Edit: May 06, 2015, 08:18:38 pm by JWinslow23 »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### Sorunome

• Fox Fox Fox Fox Fox Fox Fox!
• Support Staff
• LV13 Extreme Addict (Next: 9001)
• Posts: 7920
• Rating: +374/-13
• Derpy Hooves
##### Re: How I wish I could calculate pi...
« Reply #1 on: May 04, 2015, 01:56:51 pm »
This sound awesome!
Would you mind explaining some logic behind it / posting the Haskel program?
 THE GAMEAlso, check out my websiteIf OmnomIRC is screwed up, blame me!Click here to give me an internet!

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: How I wish I could calculate pi...
« Reply #2 on: May 04, 2015, 02:14:58 pm »
This sound awesome!
Would you mind explaining some logic behind it / posting the Haskel program?
All the logic is explained in the paper linked at the top. The program I am referring to is the last program listed in the paper:
Code: [Select]
> piG3 = g(1,180,60,2) where> g(q,r,t,i) = let (u,y)=(3*(3*i+1)*(3*i+2),div(q*(27*i-12)+5*r)(5*t))> in y : g(10*q*i*(2*i-1),10*u*(q*(5*i-2)+r-y*t),t*u,i+1)I'm not a math wizard or anything , but I think it's based off of this series for pi:
$\pi = 3+\frac{1\times1}{3\times4\times5}\times(8+\frac{2\times3}{3\times7\times8}\times(\cdots5i-2+\frac{i(2i-1)}{3(3i+1)(3i+2)}\times\cdots))$
And it views that as an infinite composition of linear fractional transforms. The program also has an optimization based off a conjecture that has not yet been fully proven, but it has been verified to hold for calculation of the first 1,000 digits.

Hope I helped! Check the paper for more: this guy knows more about the subject than I ever would hope to tell you .

Of course, if you don't mind a previous commitment to the number of digits calculated, I have one that fits entirely within the precision of the calculator's numbers... that one fails before the first 0 and I don't know why
« Last Edit: May 04, 2015, 07:25:46 pm by JWinslow23 »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: How I wish I could calculate pi...
« Reply #3 on: May 06, 2015, 08:16:57 pm »
I have new code! With this one, I tested that the maximum amount of digits it can supply on a fully RAM cleared calculator is 377, and this is done so in 3 hours 45 minutes. (don't worry, it doesn't go at the speed of 1.675 minutes per digit...it just gets slower with digits calculated, as expected)

Code is as follows:

PICALC.8xp
Code: [Select]
SetUpEditor Q,T,R{1->|LQ{60->|LT3Ans->|LRClrHome377->D"?->Str1For(J,2,D+1Output(1,1,Str1Output(6,1," Output(8,1,J-15|LT->L1prgmAADJUSTL1->L2(27J-12)|LQ+5|LR->L1prgmAADJUSTprgmADIVIDEStr1+sub("0123456789",theta+1,1->Str130((5J-2)|LQ-theta|LT+|LR->L1prgmAADJUST(3J+1)L1->L1prgmAADJUST(3J+2)L1->L1prgmAADJUSTL1->|LR10J(2J-1)|LQ->L1prgmAADJUSTL1->|LQ3(3J+1)|LT->L1prgmAADJUST(3J+2)L1->L1prgmAADJUSTL1->|LTEndAADJUST.8xp
Code: [Select]
DelVar CFor([recursiven],1,dim(L1C+L1([recursiven]->|Nint(Ans|E~7->C|N-Ans|E7->L1([recursiven]EndIf CC->L1([recursiven]dim(L1->dim(L2Ans->dim(|LQAns->dim(|LRAns->dim(|LTACOMPARE.8xp
Code: [Select]
1+dim(L1->ARepeat Ans or A<2A-1->A(L1(A)>L2(A))-(L1(A)<L2(AEndADIVIDE.8xp
Code: [Select]
DelVar thetaprgmACOMPAREWhile Ans>=0Output(6,1," Output(6,1,thetaL1-L2->L1prgmAADJUSTtheta+1->thetaprgmACOMPAREEnd
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: How I wish I could calculate pi...
« Reply #4 on: June 02, 2015, 06:12:49 pm »
Bump.

Even newer code. Now, no divide program. Also a bit faster.

SetUpEditor Q,T,R{1->|LQ{60->|LT3Ans->|LRClrHomeOutput(7,1,"CLEAR TO EXIT.  #    NEXT: 0..."?->Str12->I%Repeat getKey=45If 1<length(Str1Then"    If not(fPart((length(Str1)-2)/16Output(6,1,Ans+Ans+Ans+Ans2+16int((length(Str1)-82)/16)(98<=length(Str1Output(1,1,sub(Str1,Ans,length(Str1)+1-AnsEndOutput(8,2,I%-2Output(8,12,05|LT->L1prgmAADJUSTL1->L2(9I%-4)|LQ->L1prgmAADJUST3L1+5|LR->L1prgmAADJUST0->PVprgmACOMPAREWhile Ans>=0PV+1->PVOutput(8,12,PVL1-L2->L1prgmAADJUSTprgmACOMPAREEndsub("0123456789",PV+1,1If I%=2Ans+".Str1+Ans->Str1(5I%-2)|LQ+|LR-PV|LT->L1prgmAADJUST30L1->L1prgmAADJUSTIf I%<33Then9I%^^2+9I%+2Else(3I%+1)L1->L1prgmAADJUST3I%+2EndAnsL1->L1prgmAADJUSTL1->|LR10I%|LQ->L1prgmAADJUST(2I%-1)L1->L1prgmAADJUSTL1->|LQ3|LT->L1prgmAADJUSTIf I%<33Then9I%^^2+9I%+2Else(3I%+1)L1->L1prgmAADJUST3I%+2EndAnsL1->L1prgmAADJUSTL1->|LTI%+1->I%EndClrHomesub(Str1,2,length(Str1)-1->Str1Disp "# OF DIGITS:","DIGITS STORED IN","Str1Output(1,14,I%-2AADJUST.8xp
If min(L1)>0 and |E10>=max(L1Return0->PMTFor([recursiven],1,dim(L1PMT+L1([recursiven]->|Nint(|N|E~10->PMT|N-PMT|E10->L1([recursiven]EndIf not(PMTReturn[recursiven]->dim(L2Ans->dim(|LQAns->dim(|LRAns->dim(|LTPMT->L1(AnsACOMPARE.8xp
1+dim(L1->|NRepeat Ans or |N=1|N-1->|NL1(|N)-L2(|NEnd