combin
Lightweight implementation of various combinatorics routines (Under construction!).
Current routines offered:
- Combinatorial number system ranking/unranking (
rank_to_combandcomb_to_rank) - Binomial coefficient inversion (
inverse_choose)
Installation
combin is on PyPI and can be installed with the usual command:
python -m pip install combin
If this fails for your system, please file an issue.
Usage
combin supports fast bijections to the combinatorial number system.
from combin import comb_to_rank, rank_to_comb
## Fix k-combinations of an n-set
n = 10 # universe size
k = 3 # size of each combination
## Ranks each 3-tuple into its index in the combinatorial number system
C = combinations(range(n), k) # from itertools
R = comb_to_rank(C, order='lex', n = n)
print(R)
# [0, 1, 2, ..., 119]
## If a generator is given, the default return type is a list
assert R == list(range(120))
# True
## Alternatively, combin has native support for NumPy arrays
C = np.fromiter(combinations(range(n), k), dtype=(np.int16, k))
assert np.all(comb_to_rank(C, order='lex', n=n) == np.arange(comb(n,k)))
# True
## An alternative bijection can also be chosen, such as the colexicographical order
## Note the colex order doesn't require the universe size (n)
print(comb_to_rank(C, order='colex'))
# [0, 1, 4, ..., 119]
## Unranking is just as easy: just supply n, k, and the order
R = np.arange(comb(n,k))
C_lex = rank_to_comb(R, k=k, n=n, order='lex')
print(f"Equal? {np.all(C_lex == C)}, combs: {C_lex}")
# Equal? True, combs: [[0, 1, 2], [0, 1, 3], [0, 1, 4], ..., [6, 8, 9], [7, 8, 9]]
## Uniformly sampling from k-combinations becomes trivial
ind = np.random.choice(range(comb(n,k)), size=10, replace=False)
random_combs = rank_to_comb(ind, k=k, order='colex')
# [[2, 7, 8], [1, 4, 6], ...]
Metadata
Release files for combin 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| combin-0.1.7.tar.gz | 63.4 kB | Details |
Built distributions (wheels)
Total release size: 2.6 MB
Release files / combin-0.1.7.tar.gz
| Download URL | combin-0.1.7.tar.gz |
|---|---|
| Size | 63.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d93774133750b697cd39c591443598c2d5f67e248fe4211403d12f422ae4e34
|
|
BLAKE2b-256 checksum How to use checksums |
043c01c6ba29e79165f94f4a4ca6c36be370e5b774ea2be3fe29432bedead71f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp312-cp312-win_amd64.whl
| Download URL | combin-0.1.7-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 119.8 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
efea6433c7eaf89063d0584fdef227036193adcb1bda2a8a212d43c92edeb89c
|
|
BLAKE2b-256 checksum How to use checksums |
4bc6f17a07f2f181e605507b0fed2994e3c0c948a09dd020bf3cc7102e5fb9d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | combin-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 157.9 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
218fa205505416fdff32a033ae01b6820000bd1c197ae4aef1676e073b8261bf
|
|
BLAKE2b-256 checksum How to use checksums |
9aa1b54b38df8ccfcb96426d2d684fe5bed54a5ed9e732e93da223d370a00b6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | combin-0.1.7-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 115.7 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1ef9c6559b76c9ac004594ea7f0c3a92e3bfec637547a632ffd013547943dda3
|
|
BLAKE2b-256 checksum How to use checksums |
e92a074cee3272b13463340ca105c12adbda71f40a4fb5ed2c915f74862b2dc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp312-cp312-macosx_10_9_x86_64.whl
| Download URL | combin-0.1.7-cp312-cp312-macosx_10_9_x86_64.whl |
|---|---|
| Size | 121.7 kB |
| Tags | CPython 3.12 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
5258a5f4f75a719a625455eb899795174c886e8f240f8a02da3ece267d3a91c4
|
|
BLAKE2b-256 checksum How to use checksums |
6542e10fd6144f372a5cfa24f21252f95ac8197bda1276e5d3441239d3e9d95c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp311-cp311-win_amd64.whl
| Download URL | combin-0.1.7-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 120.7 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
31df8ba5b4ba9437deee80cd33b86b487e38d758388503c95b22fec708504c25
|
|
BLAKE2b-256 checksum How to use checksums |
9b98b930d2b79de7b44459acaa3fb7b6c1cc8d8e57d8b056fbff180446a85c6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | combin-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 159.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
d288682df7b68fc3dc26c44d8a3c364720a24c8715a354dd7f4e8499cdb69878
|
|
BLAKE2b-256 checksum How to use checksums |
d20f90b22540dfb5e7bf265e4ae03e9ab970e1f20f31fe69c1f68d4d81a43bc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | combin-0.1.7-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 116.3 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dfc181d483ee4cc3b0e90c0e4cf16cec0a3eaf5f457d0783b2ea393c22fc0263
|
|
BLAKE2b-256 checksum How to use checksums |
20ff2d23bd9e62bbacb1e7b86eb52d55d4493546c131a01648190d64969ba38c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp311-cp311-macosx_10_9_x86_64.whl
| Download URL | combin-0.1.7-cp311-cp311-macosx_10_9_x86_64.whl |
|---|---|
| Size | 122.3 kB |
| Tags | CPython 3.11 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
a3e0142509068c7c1f8cd60fce35c31c5dcbed08cd89cf274352d2892c101058
|
|
BLAKE2b-256 checksum How to use checksums |
ac612ad574c7e9c5d688bb4ff42f92577d0987f1b610ae35e83d68e2a9fe625b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp310-cp310-win_amd64.whl
| Download URL | combin-0.1.7-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 118.4 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7f59405ba63975bb829dc11d3dd200cbf5dd4dcb38e1953d2619d1a5415f6632
|
|
BLAKE2b-256 checksum How to use checksums |
87d9759989f57347431ad3e760ce8889c9521275654872f72d4173e3596046f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | combin-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 157.9 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
5917120a57a5b7e27581753e9ee3012d742bf0b4bbf7825093c6cac44a566c7a
|
|
BLAKE2b-256 checksum How to use checksums |
3708142717f7b789f450df8e427586ab0f5a9e736afd463df5cc8367967b9060
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | combin-0.1.7-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 115.2 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7ea1f37d312ae4d119c58c191d55b14daedd8cad6b6df39e3bed5dd2514ad39b
|
|
BLAKE2b-256 checksum How to use checksums |
864142ad6b171b9397086abf44746bc29af4340c66044b1b06dc601b2e62e5d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp310-cp310-macosx_10_9_x86_64.whl
| Download URL | combin-0.1.7-cp310-cp310-macosx_10_9_x86_64.whl |
|---|---|
| Size | 120.8 kB |
| Tags | CPython 3.10 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
c796141355a1f480133cfed5a1566f2a20814f8b4bbf66deb41a129011087edd
|
|
BLAKE2b-256 checksum How to use checksums |
91d3d0c69be882148415abb265d4d6210ca7f366771be3a68157de73cefee8c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp39-cp39-win_amd64.whl
| Download URL | combin-0.1.7-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 118.4 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
52153101951bf337ac10d0eef4a89684b39d45b48191fc2fb158af75a88337f3
|
|
BLAKE2b-256 checksum How to use checksums |
12cbaf732aecf8bb62407fbf4386504a5417d59149a9124d442715a683e3481a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | combin-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 159.7 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
ba5e675e00d8f8013f2d69e6bfc66b87fb8ac19b65a44eee3afc8bc10b604583
|
|
BLAKE2b-256 checksum How to use checksums |
e634d13a257032a7e0bee201e12c170c4d5e53fa005ba6c8c02969e7b7666e22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp39-cp39-macosx_11_0_arm64.whl
| Download URL | combin-0.1.7-cp39-cp39-macosx_11_0_arm64.whl |
|---|---|
| Size | 115.3 kB |
| Tags | CPython 3.9 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9a865cf3a3eb3b1c266bc73ab57f251ce5f09a71cd68b01facab09d65bc4e89f
|
|
BLAKE2b-256 checksum How to use checksums |
8a2172d3b38f3a91f7210cb0cd7a1601b66fba8e821438c486a7693d03257249
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp39-cp39-macosx_10_9_x86_64.whl
| Download URL | combin-0.1.7-cp39-cp39-macosx_10_9_x86_64.whl |
|---|---|
| Size | 120.8 kB |
| Tags | CPython 3.9 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
c5aad089412e2042852d9bac787047a2d53c23d8224d53176406cb42ee51cf2f
|
|
BLAKE2b-256 checksum How to use checksums |
d3372f9d247ae26b4b56f7f1263b8cddd69760b9429806147d31335aac1ba755
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp38-cp38-win_amd64.whl
| Download URL | combin-0.1.7-cp38-cp38-win_amd64.whl |
|---|---|
| Size | 118.3 kB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
355dccfbf10bbd518b323f8a2444c2866aac643ce3734f458a1356e47ac1ca52
|
|
BLAKE2b-256 checksum How to use checksums |
8574c4f163ee87adfef9d99a6d802c6e606dedef0c1d1141e985bbbb37ff1b72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | combin-0.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 158.9 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
4e5cde574cfd5348fe25d79b07c70a4dad4e0cb6a8381c9c7c00566e01ef978f
|
|
BLAKE2b-256 checksum How to use checksums |
3e01292f0244c0d560f7342f2d8ab551af6017ffbd45f81aac737acad7a553f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp38-cp38-macosx_11_0_arm64.whl
| Download URL | combin-0.1.7-cp38-cp38-macosx_11_0_arm64.whl |
|---|---|
| Size | 115.2 kB |
| Tags | CPython 3.8 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
87588efbd5ec1cfd277ff44d83043dce4a905f1ffb180543f9475e8a78b978d4
|
|
BLAKE2b-256 checksum How to use checksums |
a839208259e68a67beef52f77ffd1fc9ddcf27bfcfaf33d4763a044ab19eaf1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / combin-0.1.7-cp38-cp38-macosx_10_9_x86_64.whl
| Download URL | combin-0.1.7-cp38-cp38-macosx_10_9_x86_64.whl |
|---|---|
| Size | 120.8 kB |
| Tags | CPython 3.8 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
0b71b5715ca33efb3bf1162361382ada5a6fd4af569f7b797f152688f556dfa2
|
|
BLAKE2b-256 checksum How to use checksums |
5cbb3b1eb9bbc349c5cd99ecf59a042af520c568b5c7dac5c78b76025d013986
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|