-
-
30 Oct 2019 16:09:23 UTC
- Distribution: Math-Counting
- Module version: 0.1307
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (0)
- Testers (375 / 0 / 0)
- Kwalitee
Bus factor: 1- 96.55% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (14.63KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
NAME
Math::Counting - Combinatorial counting operations
VERSION
version 0.1307
SYNOPSIS
Academic
use Math::Counting ':student'; printf "Given n=%d, k=%d:\nF=%d\nP=%d\nC=%d\n", $n, $k, factorial($n), permutation($n, $k), combination($n, $k);
Engineering
use Math::Counting ':big'; printf "Given n=%d, k=%d, r=%d:\nF=%d\nP=%d\nD=%d\nC=%d\n", $n, $k, $r, bfact($n), bperm($n, $k, $r), bderange($n), bcomb($n, $k, $r);
DESCRIPTION
Compute the factorial, number of permutations, number of derangements and number of combinations.
The
:big
functions are wrappers around "bfac" in Math::BigInt with a bit of arithmetic between.The student versions exist to illustrate the computation "in the raw" as it were. To see these computations in action, Use The Source, Luke.
FUNCTIONS
factorial
$f = factorial($n);
Return the number of arrangements of n, notated as
n!
.This function employs the algorithmically elegant "student" version using real arithmetic.
bfact
$f = bfact($n);
Return the value of the function "bfac" in Math::BigInt, which is the "Right Way To Do It."
permutation
$p = permutation($n, $k);
Return the number of arrangements, without repetition, of k elements drawn from a set of n elements, using the "student" version.
bperm
$p = bperm($n, $k, $r);
Return the computations:
n^k # with repetition $r == 1 n! / (n-k)! # without repetition $r == 0
bderange()
"A derangement is a permutation in which none of the objects appear in their "natural" (i.e., ordered) place." -- wolfram under "SEE ALSO"
Return the computation:
!n = n! * ( sum (-1)^k/k! for k=0 to n )
combination
$c = combination($n, $k);
Return the number of ways to choose k elements from a set of n elements, without repetition.
This is algorithm expresses the "student" version.
bcomb
$c = bcomb($n, $k, $r);
Return the combination computations:
(n+k-1)! / k!(n-1)! # with repetition $r == 1 n! / k!(n-k)! # without repetition $r == 0
TO DO
Provide the gamma function for the factorial of non-integer numbers?
SEE ALSO
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
http://www.mathsisfun.com/combinatorics/combinations-permutations-calculator.html
http://mathworld.wolfram.com/Derangement.html
Naturally, there are a plethora of combinatorics packages available, take your pick:
Algorithm::Combinatorics, Algorithm::Loops, Algorithm::Permute, Games::Word, List::Permutor, Math::Combinatorics, Math::GSL::Permutation, Math::Permute::List, String::Glob::Permute
CREDITS
Special thanks to:
* Paul Evans
* Mike Pomraning
* Petar Kaleychev
* Dana Jacobsen
AUTHOR
Gene Boggs <gene@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install Math::Counting, copy and paste the appropriate command in to your terminal.
cpanm Math::Counting
perl -MCPAN -e shell install Math::Counting
For more information on module installation, please visit the detailed CPAN module installation guide.