Skip to content

Commit c8ab9c0

Browse files
committed
new file: Math/gregory_coefficients.sf
1 parent cf345af commit c8ab9c0

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

Math/gregory_coefficients.sf

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/ruby
2+
3+
# Author: Daniel "Trizen" Șuteu
4+
# Date: 24 February 2018
5+
# https://github.com/trizen
6+
7+
# A new recurrence for computing the logarithmic numbers (also known as Gregory coefficients).
8+
9+
# Formula:
10+
# a(0) = 1
11+
# a(n) = Sum_{k=0..n-1} (-1)^(n - k + 1) * a(k) / (n - k + 1)
12+
13+
# See also:
14+
# https://oeis.org/A002206 (numerators)
15+
# https://oeis.org/A002207 (denominators)
16+
17+
# Wikipedia:
18+
# https://en.wikipedia.org/wiki/Gregory_coefficients
19+
20+
func a((0)) { 1 }
21+
22+
func a(n) is cached {
23+
sum(^n, {|k| (-1)**(n - k + 1) * a(k) / (n - k + 1) })
24+
}
25+
26+
for n in (0..30) {
27+
printf("L(%2d) = %40s / %s\n", n, a(n) -> nude)
28+
}
29+
30+
__END__
31+
L( 0) = 1 / 1
32+
L( 1) = 1 / 2
33+
L( 2) = -1 / 12
34+
L( 3) = 1 / 24
35+
L( 4) = -19 / 720
36+
L( 5) = 3 / 160
37+
L( 6) = -863 / 60480
38+
L( 7) = 275 / 24192
39+
L( 8) = -33953 / 3628800
40+
L( 9) = 8183 / 1036800
41+
L(10) = -3250433 / 479001600
42+
L(11) = 4671 / 788480
43+
L(12) = -13695779093 / 2615348736000
44+
L(13) = 2224234463 / 475517952000
45+
L(14) = -132282840127 / 31384184832000
46+
L(15) = 2639651053 / 689762304000
47+
L(16) = -111956703448001 / 32011868528640000
48+
L(17) = 50188465 / 15613165568
49+
L(18) = -2334028946344463 / 786014494949376000
50+
L(19) = 301124035185049 / 109285437800448000
51+
L(20) = -12365722323469980029 / 4817145976189747200000
52+
L(21) = 8519318716801273673 / 3549475982455603200000
53+
L(22) = -1232577428602510264423 / 547454472117564211200000
54+
L(23) = 530916160966849 / 250639102771200000
55+
L(24) = -101543126947618093900697699 / 50814724101952310083584000000
56+
L(25) = 439498633365840119748791 / 232561666370491121664000000
57+
L(26) = -64252172543850268483123097 / 35869217013142807117824000000
58+
L(27) = 928685729779901399375 / 545814099444746491527168
59+
L(28) = -1718089509598695642524656240811 / 1061011439248764234545233920000000
60+
L(29) = 5150046951561533494311 / 3335806532892753920000000
61+
L(30) = -44810233755305010150728029810063187 / 30391611665841602734313680404480000000

Math/motzkin_triangle.sf

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ __END__
5555
1 10 54 200 560 1242 2235 3288 3915 3610 2188
5656
1 11 65 264 814 2002 4037 6765 9438 10813 9713 5798
5757

58-
=> Sum of the row of Motzkin's triangle:
58+
=> Sum of the rows of Motzkin's triangle:
5959
[1, 2, 5, 13, 35, 96, 267, 750, 2123, 6046, 17303, 49721, 143365, 414584, 1201917]
6060
[1, 2, 5, 13, 35, 96, 267, 750, 2123, 6046, 17303, 49721, 143365, 414584, 1201917]

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ A simple collection of Sidef scripts.
105105
* [Generalized continued fraction parts iter](./Math/generalized_continued_fraction_parts_iter.sf)
106106
* [Generalized fibonacci closed-form](./Math/generalized_fibonacci_closed-form.sf)
107107
* [Generalized fibonacci closed-form 2](./Math/generalized_fibonacci_closed-form_2.sf)
108+
* [Gregory coefficients](./Math/gregory_coefficients.sf)
108109
* [Harmonic numbers from powers](./Math/harmonic_numbers_from_powers.sf)
109110
* [Harmonic numbers from powers simple](./Math/harmonic_numbers_from_powers_simple.sf)
110111
* [Harmonic prime powers](./Math/harmonic_prime_powers.sf)

0 commit comments

Comments
 (0)