cauchy_numbers_of_first_type.pl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 09 February 2018
  4. # https://github.com/trizen
  5. # A new algorithm for computing the Cauchy numbers of first type.
  6. # See also:
  7. # https://oeis.org/A006232 (numerators)
  8. # https://oeis.org/A006233 (denominators)
  9. use 5.010;
  10. use strict;
  11. use warnings;
  12. use Math::AnyNum qw(:overload factorial);
  13. sub cauchy_numbers {
  14. my ($n) = @_;
  15. my @C = (1);
  16. foreach my $i (1 .. $n) {
  17. foreach my $k (0 .. $i - 1) {
  18. $C[$i] -= $C[$k] / ($i - $k + 1);
  19. }
  20. }
  21. map { (-1)**$_ * $C[$_] * factorial($_) } 0 .. $#C;
  22. }
  23. my @cauchy = cauchy_numbers(30);
  24. foreach my $i (0 .. $#cauchy) {
  25. printf "C(%2d) = %40s / %s\n", $i, $cauchy[$i]->nude;
  26. }
  27. __END__
  28. C( 0) = 1 / 1
  29. C( 1) = 1 / 2
  30. C( 2) = -1 / 6
  31. C( 3) = 1 / 4
  32. C( 4) = -19 / 30
  33. C( 5) = 9 / 4
  34. C( 6) = -863 / 84
  35. C( 7) = 1375 / 24
  36. C( 8) = -33953 / 90
  37. C( 9) = 57281 / 20
  38. C(10) = -3250433 / 132
  39. C(11) = 1891755 / 8
  40. C(12) = -13695779093 / 5460
  41. C(13) = 24466579093 / 840
  42. C(14) = -132282840127 / 360
  43. C(15) = 240208245823 / 48
  44. C(16) = -111956703448001 / 1530
  45. C(17) = 4573423873125 / 4
  46. C(18) = -30342376302478019 / 1596
  47. C(19) = 56310194579604163 / 168
  48. C(20) = -12365722323469980029 / 1980
  49. C(21) = 161867055619224199787 / 1320
  50. C(22) = -20953816286242674495191 / 8280
  51. C(23) = 4380881778942163832799 / 80
  52. C(24) = -101543126947618093900697699 / 81900
  53. C(25) = 192060902780872132330221667 / 6552
  54. C(26) = -1092286933245454564213092649 / 1512
  55. C(27) = 2075032177476967189228515625 / 112
  56. C(28) = -1718089509598695642524656240811 / 3480
  57. C(29) = 1092041494691940355778302728249 / 80
  58. C(30) = -44810233755305010150728029810063187 / 114576