Apéry's constant: Difference between revisions

→‎{{header|F_Sharp|F#}}: Added Bonus 4th. way as a continued fraction
(Realize in F#)
(→‎{{header|F_Sharp|F#}}: Added Bonus 4th. way as a continued fraction)
Line 60:
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581
</pre>
===Bonus 4th. way as a continued fraction===
I extend [[Continued fraction#Ap%C3%A9ry's_constant]] to provide the 101 digits required here. This method requires 31 iterations to provide the 101 digits, not quite as good as Wedeniwski but much better than the other 2. This method has historic interest as Apéry used it to prove that this number is irrational.
<syntaxhighlight lang="fsharp">
let cf2br α β=let n0,g1,n1,g2=β(),α(),β(),β()
seq{let (Π:BigRational)=g1/n1 in yield n0+Π; yield! Seq.unfold(fun(n,g,Π)->let a,b=α(),β() in let Π=Π*g/n in Some(n0+Π,(b+a/n,b+a/g,Π)))(g2+α()/n1,g2,Π)}
let aπ()=let mutable n=0N in (fun ()->n<-n+1N; -(BigRational.Pow(n,6)))
let bπ()=let mutable n=0N in (fun ()->n<-n+1N; (2N*n-1N)*(17N*n*n-17N*n+5N))
cf2br (aπ()) (bπ())|>Seq.skip 31|>Seq.take 1|>Seq.iter(fun n->let n=6N/n in let n,g=fG (n.Numerator) (n.Denominator) 100 in printf $"%d{n}."; g|>Seq.iter(printf "%d"); printfn "")
</syntaxhighlight>
{{out}}
<pre>
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581
</pre>
 
=={{header|J}}==
 
2,171

edits