cauchy_numbers_of_first_type_recurrence.sf 2.3 KB

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