multivariate_gamma_function.pl 532 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 03 October 2017
  4. # https://github.com/trizen
  5. # A simple implementation of the multivariate gamma function.
  6. # See also:
  7. # https://en.wikipedia.org/wiki/Multivariate_gamma_function
  8. use 5.014;
  9. use warnings;
  10. use Math::AnyNum qw(pi gamma);
  11. sub multivariate_gamma {
  12. my ($n, $p) = @_;
  13. my $prod = 1;
  14. foreach my $j (1 .. $p) {
  15. $prod *= gamma($n + (1 - $j) / 2);
  16. }
  17. $prod * pi**($p * ($p - 1) / 4);
  18. }
  19. say multivariate_gamma(10, 5); # means: gamma_5(10)