123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #!/usr/bin/ruby
- # Author: Daniel "Trizen" Șuteu
- # Date: 23 February 2018
- # https://github.com/trizen
- # A new recurrence for computing Cauchy numbers of the first type.
- # (also known as Bernoulli numbers of the second kind)
- # Formula:
- # a(0) = 1
- # a(n) = Sum_{k=0..n-1} (-1)^(n - k + 1) * a(k) / (n - k + 1)
- # Which gives us the nth-Cauchy number, C_n, as:
- # C_n = a(n) * n!
- # See also:
- # https://oeis.org/A006232 (numerators)
- # https://oeis.org/A006233 (denominators)
- func a((0)) { 1 }
- func a(n) is cached {
- sum(^n, {|k| (-1)**(n - k + 1) * a(k) / (n - k + 1) })
- }
- for n in (0..30) {
- printf("C(%2d) = %40s / %s\n", n, a(n)*n! -> nude)
- }
- __END__
- C( 0) = 1 / 1
- C( 1) = 1 / 2
- C( 2) = -1 / 6
- C( 3) = 1 / 4
- C( 4) = -19 / 30
- C( 5) = 9 / 4
- C( 6) = -863 / 84
- C( 7) = 1375 / 24
- C( 8) = -33953 / 90
- C( 9) = 57281 / 20
- C(10) = -3250433 / 132
- C(11) = 1891755 / 8
- C(12) = -13695779093 / 5460
- C(13) = 24466579093 / 840
- C(14) = -132282840127 / 360
- C(15) = 240208245823 / 48
- C(16) = -111956703448001 / 1530
- C(17) = 4573423873125 / 4
- C(18) = -30342376302478019 / 1596
- C(19) = 56310194579604163 / 168
- C(20) = -12365722323469980029 / 1980
- C(21) = 161867055619224199787 / 1320
- C(22) = -20953816286242674495191 / 8280
- C(23) = 4380881778942163832799 / 80
- C(24) = -101543126947618093900697699 / 81900
- C(25) = 192060902780872132330221667 / 6552
- C(26) = -1092286933245454564213092649 / 1512
- C(27) = 2075032177476967189228515625 / 112
- C(28) = -1718089509598695642524656240811 / 3480
- C(29) = 1092041494691940355778302728249 / 80
- C(30) = -44810233755305010150728029810063187 / 114576
|