Jump to content

Continued fraction: Difference between revisions

Line 978:
===The Functions===
<lang fsharp>
// I provide threefour functions:-
// cf2S general purpose continued fraction to sequence of float approximations
// cN2S Normal continued fractions (a-series always 1)
// cfSqRt uses cf2S to calculate sqrt of float
// π takes a sequence of b values returning the next until the list is exhausted after which it injects infinity
// Nigel Galloway: December 19th., 2018
let cf2S α β=let n0,g1,n1,g2=β(),α(),β(),β()
Line 987 ⟶ 988:
let cN2S = cf2S (fun()->1M)
let cfSqRt n=(cf2S (fun()->n-1M) (let mutable n=false in fun()->if n then 2M else (n<-true; 1M)))
let π n=let mutable π=n in (fun ()->match π with h::t->π<-t; h |_->9999999999999999999999999999M)
</lang>
===The Tasks===
Line 1,058 ⟶ 1,060:
</pre>
<lang fsharp>
let π()pi =let mutableπ π=[3M;7M;15M;1M;292M;1M;1M;1M;2M;1M;3M;1M;14M;2M;1M;1M;2M;2M;2M;2M]
cN2S (π())pi |> Seq.take 10 |> Seq.pairwise |> Seq.iter(fun(n,g)->printfn "%1.14f < π < %1.14f" (min n g) (max n g))
(fun ()->match π with h::t->π<-t; h |_->9999999999999999999999999999M)
cN2S (π()) |> Seq.take 10 |> Seq.pairwise |> Seq.iter(fun(n,g)->printfn "%1.14f < π < %1.14f" (min n g) (max n g))
</lang>
{{out}}
2,172

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.