-
Notifications
You must be signed in to change notification settings - Fork 0
/
nth_root_good_rational_approximations.sf
52 lines (41 loc) · 2.43 KB
/
nth_root_good_rational_approximations.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
51
52
#!/usr/bin/ruby
# Formula for computing good rational approximations to the n-th root of a number.
func f (N, r) {
var (m, R) = irootrem(N, r)
(m, R, func (n) is cached {
return 0 if (n <= r-2)
return 1 if (n == r-1)
sum(1..r, {|j|
binomial(r, j) * m**(r-j) * R**(j-1) * __FUNC__(n-j)
})
}
)
}
var (m, R, g) = f(12, 3) # approximations for 12^(1/3)
for n in (1..20) {
var x = g(n)
var y = g(n+1)
var t = (m + R*(x/y))
printf("%20s / %-20s =~ %s\n", t.nude, t.as_dec)
}
__END__
2 / 1 =~ 2
7 / 3 =~ 2.33333333333333333333333333333333333333333333333
16 / 7 =~ 2.28571428571428571428571428571428571428571428571
332 / 145 =~ 2.28965517241379310344827586206896551724137931034
1147 / 501 =~ 2.28942115768463073852295409181636726546906187625
1321 / 577 =~ 2.28942807625649913344887348353552859618717504333
54770 / 23923 =~ 2.28942858337165071270325628056681854282489654308
189235 / 82656 =~ 2.28942847464188927603561749903213317847464188928
145294 / 63463 =~ 2.28942848588941588011912452925326568236610308369
9036056 / 3946861 =~ 2.28942848506699374515596064822146004128344018196
31220341 / 13636740 =~ 2.28942848510714437614855163330825402552222891982
553174 / 241621 =~ 2.28942848510684087889711573083465427260047760749
1490785262 / 651160441 =~ 2.28942848510663748997614552570769574744482980655
5150789707 / 2249814633 =~ 2.2894284851066661188348666945486970703688191364
11864277296 / 5182200437 =~ 2.28942848510666358079348832411825139136354096217
245952514832 / 107429656105 =~ 2.28942848510666374156313324819611270969170901452
849786829867 / 371178586881 =~ 2.28942848510666373577119356984020210953328525666
17170091683 / 7499728336 =~ 2.2894284851066637355596076086988546087517909262
40577701627550 / 17723943722863 =~ 2.28942848510666373562258308304493671870237388535
140199405779275 / 61237731028206 =~ 2.28942848510666373561557077732398691673928325376