-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharmonic_numbers_of_k-th_order.sf
26 lines (21 loc) · 1.23 KB
/
harmonic_numbers_of_k-th_order.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
#!/usr/bin/ruby
# Formula in terms of the Harmonic numbers, due to Conway and Guy (1996), for computing the Harmonic numbers of the k-th order.
# See also:
# https://mathworld.wolfram.com/HarmonicNumber.html
func harmonic_kth_order(n, k) {
binomial(n + k - 1, k - 1) * (harmonic(n + k - 1) - harmonic(k - 1))
}
for k in (1..10) {
say "H^(#{k}) = #{10.of {|n| harmonic_kth_order(n, k) }}"
}
__END__
H^(1) = [0, 1, 3/2, 11/6, 25/12, 137/60, 49/20, 363/140, 761/280, 7129/2520]
H^(2) = [0, 1, 5/2, 13/3, 77/12, 87/10, 223/20, 481/35, 4609/280, 4861/252]
H^(3) = [0, 1, 7/2, 47/6, 57/4, 459/20, 341/10, 3349/70, 3601/56, 42131/504]
H^(4) = [0, 1, 9/2, 37/3, 319/12, 743/15, 2509/30, 2761/21, 32891/168, 35201/126]
H^(5) = [0, 1, 11/2, 107/6, 533/12, 1879/20, 2131/12, 25961/84, 28271/56, 395243/504]
H^(6) = [0, 1, 13/2, 73/3, 275/4, 1627/10, 20417/60, 22727/35, 323171/280, 348911/180]
H^(7) = [0, 1, 15/2, 191/6, 1207/12, 15797/60, 18107/30, 263111/210, 288851/120, 312875/72]
H^(8) = [0, 1, 17/2, 121/3, 1691/12, 2021/5, 30233/30, 237371/105, 261395/56, 567835/63]
H^(9) = [0, 1, 19/2, 299/6, 763/4, 11899/20, 96163/60, 108175/28, 477745/56, 8842385/504]
H^(10) = [0, 1, 21/2, 181/3, 3013/12, 25381/30, 9795/4, 44185/7, 831225/56, 8161705/252]