-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviete-like_formulas.sf
50 lines (39 loc) · 1.21 KB
/
viete-like_formulas.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/ruby
#
## Viète-like formulas:
#
# a(c) = {
# f(0) = 0
# f(n) = sqrt(c + f(n-1))
# d = (1 + sqrt(1 + 4*c))/2
# Limit_{n -> Infinity} (2*d)^n * d - (2*d)^n * f(n)
# }
# Closed-forms:
# a(1) = 2*P where P is the Paris constant (https://oeis.org/A105415)
# a(2) = pi^2/4
# See also:
# https://en.wikipedia.org/wiki/Vi%C3%A8te%27s_formula
local Number!PREC = 1024.numify
const n = 100
func a(c) {
func f(n) {
n == 0 ? 0 : sqrt(c + f(n-1))
}
var d = (1 + sqrt(1 + 4*c))/2
var t = ((2*d)**n * d - ((2*d)**n * f(n)))
return t
}
for c in (1..10) {
say ("a(#{c}) = ", a(c).as_dec(48))
}
__END__
a(1) = 2.19728392878831297146933783468719242174669679222
a(2) = 2.46740110027233965470862274996903778382842485181
a(3) = 2.72432397395262808042738254231361436370470931728
a(4) = 2.95697498038250320240181341327815809572441049058
a(5) = 3.16942068660729603631214225411774841781355055152
a(6) = 3.36565753974384094582778152437432384197290834457
a(7) = 3.54871470954831491531526350481479738940975906022
a(8) = 3.72084501177716618448006573526170234977853589736
a(9) = 3.88375012406073194374765723289729464351431116217
a(10) = 4.03874313819098595611125546305106699051058830246