1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/usr/bin/perl
- # Author: Daniel "Trizen" Șuteu
- # Date: 09 February 2018
- # https://github.com/trizen
- # A new algorithm for computing the Cauchy numbers of first type.
- # See also:
- # https://oeis.org/A006232 (numerators)
- # https://oeis.org/A006233 (denominators)
- use 5.010;
- use strict;
- use warnings;
- use Math::AnyNum qw(:overload factorial);
- sub cauchy_numbers {
- my ($n) = @_;
- my @C = (1);
- foreach my $i (1 .. $n) {
- foreach my $k (0 .. $i - 1) {
- $C[$i] -= $C[$k] / ($i - $k + 1);
- }
- }
- map { (-1)**$_ * $C[$_] * factorial($_) } 0 .. $#C;
- }
- my @cauchy = cauchy_numbers(30);
- foreach my $i (0 .. $#cauchy) {
- printf "C(%2d) = %40s / %s\n", $i, $cauchy[$i]->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
|