Every error this module throws is CombinatoricsInvalidInputError, with a code from a closed, exported list. Branch on the code; the message is for people.
Measured by the suite in packages/combinatorics/__tests__/bench. The numbers come from one machine, so run the suite on yours before deciding on speed alone.
Use knotkit/combinatorics for this task. If Knotkit is missing, follow https://knotkit.jkomyno.dev/getting-started.md#install-from-source. Import from 'knotkit/combinatorics'.
Exports:
- `factorial` → `bigint`: Permutations of all n items.
- `logFactorial` → `number`: Natural logarithm of n factorial for any non-negative safe integer n.
- `binomialCoefficient` → `bigint`: Combinations of k from n items.
- `logBinomialCoefficient` → `number`: Natural logarithm of the number of combinations of k from n items, including when n is far larger than k.
- `stirlingFirstKind` → `bigint`: Permutations of n items with k cycles, the unsigned Stirling number of the first kind.
- `stirlingFirstKindRow` → `readonly bigint[]`: Permutations of n items for each cycle count from 0 to n.
- `logStirlingFirstKind` → `number`: Natural logarithm of the number of permutations with k cycles.
- `stirlingSecondKind` → `bigint`: Partitions of n items into k non-empty blocks.
- `stirlingSecondKindRow` → `readonly bigint[]`: Partitions of n items for each non-empty block count from 0 to n.
- `logStirlingSecondKind` → `number`: Natural logarithm of the number of partitions into k non-empty blocks.
- `bellNumber` → `bigint`: Set partitions across all block counts.
- `logBellNumber` → `number`: Natural logarithm of the number of set partitions across all block counts.
Use something else when:
- list the permutations or combinations themselves → a generator that enumerates permutations or combinations
- simulate selecting items without replacement → knotkit/sampling
Errors are CombinatoricsInvalidInputError with a `code` property. Branch on `error.code`, never on the message.
Full page: https://knotkit.jkomyno.dev/modules/combinatorics.md
Types: node_modules/knotkit/combinatorics/ and https://knotkit.jkomyno.dev/reference/knotkit/combinatorics/