Almkvist-Giullera formula for pi: Difference between revisions

Realize in F#
(→‎{{header|JavaScript}}: Add implementation)
(Realize in F#)
Line 424:
</pre>
 
=={{header|F_Sharp|F#}}==
This task uses [[Isqrt_(integer_square_root)_of_X#F.23]]
<lang fsharp>
// Almkvist-Giullera formula for pi. Nigel Galloway: August 1th., 202
let factorial(n:bigint)=MathNet.Numerics.SpecialFunctions.Factorial n
let fN g=(532I*g*g+126I*g+9I)*(factorial(6I*g))/(3I*(factorial g)**6)
[0..9]|>Seq.iter(bigint>>fN>>(*)32I>>printfn "%A\n")
let _,n=Seq.unfold(fun(n,g)->let n=n*(10I**6)+fN g in Some(Isqrt((10I**(145+6*(int g)))/(32I*n)),(n,g+1I)))(0I,0I)|>Seq.pairwise|>Seq.find(fun(n,g)->n=g)
printfn $"""pi to 70 decimal places is %s{(n.ToString()).Insert(1,".")}"""
</lang>
{{out}}
<pre>
96
5122560
190722470400
7574824857600000
312546150372456000000
13207874703225491420651520
567273919793089083292259942400
24650600248172987140112763715584000
1080657854354639453670407474439566400000
47701779391594966287470570490839978880000000
 
pi to 70 decimal places is 3.14159265358979323846264338327950288419716939937510582097494459230781640
</pre>
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
2,171

edits