0.3.0
Added
count_partitions/1andnth_partition/2count_selections/2andnth_selection/3count_permuted_combinations/2andnth_permuted_combination/3count_cartesian_product/1andnth_cartesian_product/2combinations_with_replacement/2,count_combinations_with_replacement/2andnth_combination_with_replacement/3SComb.Sequence, the type of whatpermutations/1,combinations/2,subsets/1,selections/2,partitions/1,combinations_with_replacement/2,permuted_combinations/2andcartesian_product/1return. It is anEnumerablethat knows its size and finds an element by index, soEnum.count/1,Enum.at/2,Enum.slice/2,Enum.random/1and similar do not generate the elements before it. Inputs of more than 2000 elements, or 200 for partitions, are streamed as before
Changed
- The functions above return a
SComb.Sequencerather than aStreamor a list. They are still enumerable, but code that relies on the exact type of the result, for exampleis_list/1, will no longer work combinations/2returns the combinations in colexicographic order, by the last value they hold, socombinations(1..4, 2)returns[[1, 2], [1, 3], [2, 3], [1, 4], [2, 4], [3, 4]]. Consecutive combinations then share the end of their lists, which makes generating them about four times faster.subsets/1returns the subsets of each size in this order, andcombinations_with_replacement/2andpermuted_combinations/2follow it, as do thenth_*functions of all of thesepartitions/1returns the partitions in a different order, and the blocks of a partition are ordered by the last element they hold:nth_partition(1..3, 2)is[[2], [1, 3]]where it was[[1, 3], [2]]. Consecutive partitions then share the end of their lists, which makes generating them somewhat faster- The
:minand:maxlimits ofpartitions/2are applied while the partitions are generated, sopartitions(1..40, min: 39)does not go through every partition of 40 elements
0.2.0
Added
permuted_combinations/2, every permutation of every combination ofkelementspartitions/2accepts:minand:maxoptions limiting the number of blocks, as in the Clojuremath.combinatoricslibrary
Fixed
- The
nth_*functions raised aKeyErrorinstead ofEnum.OutOfBoundsErrorfor an index out of bounds
0.1.0
Changes since 0.0.2:
Added
cartesian_product/1, the cartesian product of any number of enumerablesnth_subset/2SComb.Math.binomial/2andSComb.Math.multinomial/1- Package metadata and documentation for publishing on Hex
Changed
- Renamed from Comb to SComb, for streaming combinatorics: the package is now
scomband the modulesSCombandSComb.Math, as the namecombis taken on Hex - Every function now has a dedicated algorithm, instead of filtering the
results of a naive one:
permutations/1uses a successor algorithm that handles repeated elements directly, rather than generating and discarding duplicatescount_combinations/2,count_subsets/1,nth_combination/3,nth_subset/2,nth_permutation/2,drop_permutations/2andpermutation_index/1compute their result without generating the elements before itcombinations/2,subsets/1,partitions/1andselections/2are generated lazily
- Repeated elements no longer need to be next to each other:
combinations([1, 2, 1], 2)returns[[1, 2], [1, 1]]rather than[[1, 2], [1, 1], [2, 1]]. Where repeated elements are not next to each other, results may come in a different order than before selections/2selects each distinct element once, soselections([1, 1], 1)returns[[1]]- The partitions of an input with repeated elements come in a different order,
and their blocks are ordered differently:
partitions([1, 1, 2])now returns[[1, 2], [1]]where it returned[[1], [1, 2]]. The partitions of distinct elements are unchanged up to 3 elements - The
nth_*functions accept a negative index, counting from the end SComb.Math.factorial/1raises for negative numbers rather than never returning
Removed
Comb.TablePermutationsandComb.ListAnalyzer, which were internal- The naive reference implementations and the benchmark task, now
scomb.benchmark, moved tobench/, and are no longer part of the package