Gene Boggs > Math-Counting > Math::Counting

Download:
Math-Counting-0.0905.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.0905   Source  

NAME ^

Math::Counting - Combinatorial counting operations

SYNOPSIS ^

  use Math::Counting ':student'; # Logical, Academic
  printf "Given n=%d and r=%d:\nFact=%d\nPerm=%d\nComb=%d\n",
    $n, $r, factorial($n), permutation($n, $r), combination($n, $r);

  use Math::Counting ':big'; # Engineering, Reality
  printf "n=%d, r=%d:\nBig F=%d\n Big P=%d\nBig C=%d\n",
    $n, $r, bfact($n), bperm($n, $r), bcomb($n, $r);

DESCRIPTION ^

Compute the factorial, number of permutations and number of combinations for either engineers or CS students.

The engineer (i.e. :big) version is a "thin wrapper" around "bfac" in Math::BigInt, and a bit of arithmatic.

The student version exists to illustrate the computation.

FUNCTIONS ^

factorial

  $f = factorial($n);

Return the number of arrangements of n according to the algorithmically elegant "student" version using real arithmetic.

bfact

  $f = bfact($n);

Return the value of the "bfac" in Math::BigInt function, which is the "Right Way To Do It."

permutation

  $p = permutation($n, $r);

Return the number of arrangements of r elements drawn from a set of n elements. nPn is the same as n!. This function employs the "student" version.

bperm

  $p = bperm($n, $r);

Return the Math::BigInt computation: n!/(n-r)!

combination

  $c = combination($n, $r);

Return the number of ways to choose r elements from a set of n elements using the "student" version."

bcomb

  $c = bcomb($n, $r);

Return the Math::BigInt computation: n!/r!(n-r)!

TO DO ^

Figure out how to allow the use of different Math::BigInt variations, like GMP.

Provide the gamma function for the factorial of non-integer numbers?

SEE ALSO ^

"bfac" in Math::BigInt

Higher Order Perl by Mark Jason Dominus (http://hop.perl.plover.com).

Mastering Algorithms with Perl by Orwant, Hietaniemi & Macdonald (http://www.oreilly.com/catalog/maperl).

http://en.wikipedia.org/wiki/Factorial

http://en.wikipedia.org/wiki/Permutation

http://en.wikipedia.org/wiki/Combination

Naturally, there are a plethora of combinatorics packages available, take your pick:

Algorithm::Combinatorics, Algorithm::Loops, Algorithm::Permute, CM::Group::Sym, CM::Permutation, Games::Word, List::Permutor, Math::Combinatorics, Math::GSL::Permutation, Math::Permute::List, String::Glob::Permute, String::OrderedCombination

CREDITS ^

Special thanks to:

* Paul Evans

* Mike Pomraning

AUTHOR AND COPYRIGHT ^

Gene Boggs <gene@cpan.org>

Copyright 2012, Gene Boggs, All Rights Reserved.

LICENSE ^

This program is free software; you can redistribute or modify it under the same terms as Perl itself.

syntax highlighting: