Skip to main content

A Pythonic package for combinatorics

Project description

Combi is a Pythonic package for combinatorics.

Combi lets you explore spaces of permutations and combinations as if they were Python sequences, but without generating all the permutations/combinations in advance. It lets you specify a lot of special conditions on these spaces. It also provides a few more classes that might be useful in combinatorics programming.

Combi documentation: https://combi.readthedocs.org/en/stable/

Combi on GitHub: https://github.com/cool-RR/combi

Combi on PyPI: https://pypi-hypernode.com/pypi/combi

Changelog: https://combi.readthedocs.org/en/stable/changelog.html

Basic usage

Use PermSpace to create a permutation space:

>>> from combi import *
>>> perm_space = PermSpace('meow')

It behaves like a sequence:

>>> len(perm_space)
24
>>> perm_space[7]
<Perm: ('e', 'm', 'w', 'o')>
>>> perm_space.index('mowe')
3

And yet the permutations are created on-demand rather than in advance.

Use CombSpace to create a combination space, where order doesn’t matter:

>>> comb_space = CombSpace(('vanilla', 'chocolate', 'strawberry'), 2)
>>> comb_space
<CombSpace: ('vanilla', 'chocolate', 'strawberry'), n_elements=2>
>>> comb_space[2]
<Comb, n_elements=2: ('chocolate', 'strawberry')>
>>> len(comb_space)
3

For more details, try the tutorial or see the documentation contents.

Features

  • PermSpace lets you explore a space of permutations as if it was a Python sequence.

    • Permutations are generated on-demand, so huge permutation spaces can be created easily without big memory footprint.

    • PermSpace will notice if you have repeating elements in your sequence, and treat all occurences of the same value as interchangable rather than create redundant permutations.

    • A custom domain can be specified instead of just using index numbers.

    • You may specify some elements to be fixed, so they’ll point to the same value in all permutations. (Useful for limiting an experiment to a subset of the original permutation space.)

    • Permutation spaces may be limited to a certain degree of permutations. (A permutation’s degree is the number of transformations it takes to make it.)

    • k-permutations are supported.

    • You may specify a custom type for the generated permutations, so you could implement your own functionality on them.

  • CombSpace lets you explore a space of combinations as if it was a Python sequence.

  • MapSpace is like Python’s built-in map, except it’s a sequence that allows index access.

  • ProductSpace is like Python’s itertools.product, except it’s a sequence that allows index access.

  • ChainSpace is like Python’s itertools.chain, except it’s a sequence that allows index access.

  • SelectionSpace is a space of all selections from a sequence, of all possible lengths.

  • The Bag class is a multiset like Python’s collections.Counter, except it offers far more functionality, like more arithmetic operations between bags, comparison between bags, and more. (It can do that because unlike Python’s collections.Counter, it only allows natural numbers as keys.)

  • Classes FrozenBag, OrderedBag and FrozenOrderedBag are provided, which are variations on Bag.

Requirements

Installation

Use pip to install Combi:

$ pip install combi

Community

Combi on GitHub: https://github.com/cool-RR/combi Feel free to fork and send pull requests!

There are three Combi groups, a.k.a. mailing lists:


Combi was created by Ram Rachum. I provide Development services in Python and Django.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

combi-1.1.1.tar.gz (485.3 kB view details)

Uploaded Source

Built Distributions

combi-1.1.1-py3-none-any.whl (250.6 kB view details)

Uploaded Python 3

combi-1.1.1-py2-none-any.whl (311.1 kB view details)

Uploaded Python 2

File details

Details for the file combi-1.1.1.tar.gz.

File metadata

  • Download URL: combi-1.1.1.tar.gz
  • Upload date:
  • Size: 485.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for combi-1.1.1.tar.gz
Algorithm Hash digest
SHA256 bc72ae2c65d39ccd790296dfbce386254cb5dd2b09cc2de6a23f2813cb00168e
MD5 36a5dea6d6143b62c5b32e52de13a1da
BLAKE2b-256 b698d1d5a3ffc7006a2e083accff77ec008b2f42ae54a0e88f7c37dcb381cc02

See more details on using hashes here.

File details

Details for the file combi-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for combi-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81fc4f9eae29285be04815cb2950ef0540cc10682bdd324112b94fafa0e6de9a
MD5 5067b331e8ce035cc7470394dc76da2e
BLAKE2b-256 ce9ed3a472fa9706545e7fe143311dc7a098ae22118d35770e84cf2c075b941a

See more details on using hashes here.

File details

Details for the file combi-1.1.1-py2-none-any.whl.

File metadata

File hashes

Hashes for combi-1.1.1-py2-none-any.whl
Algorithm Hash digest
SHA256 f4aa44152b8c2de8a50b6818201d7cde2e68b824d109eb8b47431ca15ed10661
MD5 cc4443aa11e1d9123b63847ccc9e1cf7
BLAKE2b-256 97d574d386dfd93bdb48364e07a32c1568b6f2aeb81880c8429053c80435a5ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page