Examples
User documentation
Here are some basic combinatorial functions.
Operations
Counting integer partitions:
NumPartitions(n)
computes number of partitions ofn
, i.e. how many distinct ways to writen
as a sum of positive integers (error ifn
is negative)
Random subsets and random tuples:
RandomSubsetIndices(n)
-- returns a random subset of {0,1,2...,n-1}RandomSubsetIndices(n,r)
-- returns a sizer
random subset of {0,1,2...,n-1
}RandomTupleIndices(n,r)
-- returns a randomr
-tuple from {0,1,2,...,n-1
} Notes:- the parameter
n
indicates the range {0,1,2,...,n-1
} so that the integers produced are valid indices into a C++ vector of sizen
. - the result is of type
vector<long>
- the sampling is from a uniform distribution
Maintainer documentation
The algorithm for RandomSubsetIndices(n,r)
was taken from the
Wikipedia page on "Reservoir Sorting".
Bugs, shortcomings and other ideas
Ugly fn names RandomSubsetIndices
and RandomTupleIndices
Main changes
2015
- June (v0.99536): first version