{"id":19268389,"url":"https://github.com/permutatriangle/comb_spec_searcher","last_synced_at":"2025-04-21T19:33:26.460Z","repository":{"id":37774064,"uuid":"121520109","full_name":"PermutaTriangle/comb_spec_searcher","owner":"PermutaTriangle","description":"a Python library for combinatorial exploration","archived":false,"fork":false,"pushed_at":"2024-05-21T07:48:41.000Z","size":67382,"stargazers_count":11,"open_issues_count":7,"forks_count":1,"subscribers_count":11,"default_branch":"develop","last_synced_at":"2024-10-31T23:04:14.991Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://permutatriangle.github.io/papers/2019-02-27-combex.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PermutaTriangle.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-02-14T14:30:56.000Z","updated_at":"2023-10-05T05:58:52.000Z","dependencies_parsed_at":"2024-03-04T15:11:37.495Z","dependency_job_id":null,"html_url":"https://github.com/PermutaTriangle/comb_spec_searcher","commit_stats":{"total_commits":1450,"total_committers":21,"mean_commits":69.04761904761905,"dds":0.5434482758620689,"last_synced_commit":"d84b869f88d4bc53f21c5a6256f0d51eaa111041"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PermutaTriangle%2Fcomb_spec_searcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PermutaTriangle%2Fcomb_spec_searcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PermutaTriangle%2Fcomb_spec_searcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PermutaTriangle%2Fcomb_spec_searcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PermutaTriangle","download_url":"https://codeload.github.com/PermutaTriangle/comb_spec_searcher/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223876367,"owners_count":17218389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T20:16:07.182Z","updated_at":"2024-11-09T20:16:07.840Z","avatar_url":"https://github.com/PermutaTriangle.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Combinatorial Specification Searcher\n====================================\n.. image:: https://travis-ci.org/PermutaTriangle/comb_spec_searcher.svg?branch=master\n    :alt: Travis\n    :target: https://travis-ci.org/PermutaTriangle/comb_spec_searcher\n.. image:: https://img.shields.io/coveralls/github/PermutaTriangle/comb_spec_searcher.svg\n    :alt: Coveralls\n    :target: https://coveralls.io/github/PermutaTriangle/comb_spec_searcher\n.. image:: https://img.shields.io/pypi/v/comb_spec_searcher.svg\n    :alt: PyPI\n    :target: https://pypi.python.org/pypi/comb_spec_searcher\n.. image:: https://img.shields.io/pypi/l/comb_spec_searcher.svg\n    :target: https://pypi.python.org/pypi/comb_spec_searcher\n.. image:: https://img.shields.io/pypi/pyversions/comb_spec_searcher.svg\n    :target: https://pypi.python.org/pypi/comb_spec_searcher\n.. image:: http://img.shields.io/badge/readme-tested-brightgreen.svg\n    :alt: Travis\n    :target: https://travis-ci.org/PermutaTriangle/comb_spec_searcher\n.. image:: https://requires.io/github/PermutaTriangle/comb_spec_searcher/requirements.svg?branch=master\n     :target: https://requires.io/github/PermutaTriangle/comb_spec_searcher/requirements/?branch=master\n     :alt: Requirements Status\n.. image:: https://zenodo.org/badge/121520109.svg\n   :target: https://zenodo.org/badge/latestdoi/121520109\n\nThe ``comb_spec_searcher`` package contains code for combinatorial\nexploration.\n\nIf this code is useful to you in your work, please consider citing it. To generate a\nBibTeX entry (or another format), click the \"DOI\" badge above and locate the \"Cite As\"\nsection.\n\nInstalling\n----------\n\nTo install ``comb_spec_searcher`` on your system, run:\n\n.. code:: bash\n\n       pip install comb_spec_searcher\n\nIt is also possible to install comb_spec_searcher in development mode to\nwork on the source code, in which case you run the following after\ncloning the repository:\n\n.. code:: bash\n\n       ./setup.py develop\n\nCombinatorial exploration\n-------------------------\n\nA (combinatorial) class is a set of objects with a notion of size such\nthat there are finitely many objects of each size. One of the primary\ngoals of enumerative combinatorics is to count how many objects of each\nsize there are in a class. One method for doing this is to find a\n(combinatorial) specification, which is a collection of (combinatorial)\nrules that describe how to build a class from other classes using\nwell-defined constructors. Such a specification can then be used to\ncount the number of objects of each size.\n\n*Combinatorial exploration* is a systematic application of strategies to\ncreate rules about a class of interest, until a specification can be\nfound. This package can be used to perform this process automatically.\nSee the `Combinatorial Exploration\nproject \u003chttps://permutatriangle.github.io/papers/2019-02-27-combex.html\u003e`__\nand `Christian Bean’s PhD\nthesis \u003chttps://opinvisindi.is/handle/20.500.11815/1184\u003e`__ for more details.\n\nThe remainder of this README will be an example of how to use this\npackage for performing combinatorial exploration on a specific class,\nnamely words avoiding consecutive patterns.\n\nAvoiding consecutive patterns in words\n--------------------------------------\n\nA word ``w`` over an alphabet ``Σ`` is a string consisting of letters\nfrom ``Σ``. We say that ``w`` contains the word ``p`` if there is a\nconsecutive sequence of letters in ``w`` equal to ``p``. We say ``w``\navoids ``p`` if it does not contain ``p``. In this context, we call\n``p`` a pattern. In ``python``, this containment check can be checked\nusing ``in``.\n\n.. code:: python\n\n   \u003e\u003e\u003e from comb_spec_searcher import CombinatorialObject\n\n   \u003e\u003e\u003e class Word(str, CombinatorialObject):\n   ...     def size(self):\n   ...         return str.__len__(self)\n\n   \u003e\u003e\u003e w = Word(\"acbabcabbb\")\n   \u003e\u003e\u003e p = Word(\"abcab\")\n   \u003e\u003e\u003e p in w\n   True\n\nFor an alphabet ``Σ`` and a set of patterns ``P`` we define ``Σ*(P)`` to\nbe the set of words over ``Σ`` that avoid every pattern in ``P``. These\nare the classes that we will count. Of course, these all form regular\nlanguages, but it will serve as a good example of how to use the\n``comb_spec_searcher`` package.\n\nThe first step is to create the classes that will be used for\ndiscovering the underlying structure of the class of interest. In this\ncase, considering the prefix of the words is what we need. We then\ncreate a new python ``class`` representing this that inherits from\n``CombinatorialClass`` which can be imported from\n``comb_spec_searcher``.\n\n.. code:: python\n\n   \u003e\u003e\u003e from comb_spec_searcher import CombinatorialClass\n\n\n   \u003e\u003e\u003e class AvoidingWithPrefix(CombinatorialClass[Word]):\n   ...     def __init__(self, prefix, patterns, alphabet, just_prefix=False):\n   ...         self.alphabet = frozenset(alphabet)\n   ...         self.prefix = Word(prefix)\n   ...         self.patterns = frozenset(map(Word, patterns))\n   ...         self.just_prefix = just_prefix # this will be needed later\n\nInheriting from ``CombinatorialClass`` requires you to implement a few\nfunctions for combinatorial exploration: ``is_empty``, ``to_jsonable``,\n``__eq__``, ``__hash__``, ``__repr__``, and ``__str__``.\n\nWe will start by implementing the dunder methods (the ones with double\nunderscores) required. The ``__eq__`` method is particularly important\nas the ``CombinatorialSpecificationSearcher`` will use it to recognise\nif the same class appears multiple times.\n\n.. code:: python\n\n   ...     # The dunder methods required to perform combinatorial exploration\n   ...\n   ...     def __eq__(self, other):\n   ...         return (self.alphabet == other.alphabet and\n   ...                 self.prefix == other.prefix and\n   ...                 self.patterns == other.patterns and\n   ...                 self.just_prefix == other.just_prefix)\n   ...\n   ...     def __hash__(self):\n   ...         return hash(hash(self.prefix) + hash(self.patterns) +\n   ...                     hash(self.alphabet) + hash(self.just_prefix))\n   ...\n   ...     def __str__(self):\n   ...         prefix = self.prefix if self.prefix else '\"\"'\n   ...         if self.just_prefix:\n   ...             return \"The word {}\".format(prefix)\n   ...         return (\"Words over {{{}}} avoiding {{{}}} with prefix {}\"\n   ...                 \"\".format(\", \".join(l for l in self.alphabet),\n   ...                           \", \".join(p for p in self.patterns),\n   ...                           prefix))\n   ...\n   ...     def __repr__(self):\n   ...         return \"AvoidingWithPrefix({}, {}, {}\".format(repr(self.prefix),\n   ...                                                       repr(self.patterns),\n   ...                                                       repr(self.alphabet))\n\nPerhaps the most important function to be implemented is the\n``is_empty`` function. This should return ``True`` if there are no\nobjects of any size in the class, otherwise ``False``. If it is not\ncorrectly implemented it may lead to tautological specifications. For\nexample, in our case the class is empty if and only if the prefix\ncontains a pattern to be avoided.\n\n.. code:: python\n\n   ...     def is_empty(self):\n   ...         return any(p in self.prefix for p in self.patterns)\n\nThe final function required is ``to_jsonable``. This is primarily for\nthe output, and only necessary for saving the output. It should be in a\nformat that can be interpretated by ``json``. What is important is that\nthe ``from_dict`` function is written in such a way that for any class\n``c`` we have ``CombinatorialClass.from_dict(c.to_jsonable()) == c``.\n\n.. code:: python\n\n   ...     def to_jsonable(self):\n   ...         return {\"prefix\": self.prefix,\n   ...                 \"patterns\": tuple(sorted(self.patterns)),\n   ...                 \"alphabet\": tuple(sorted(self.alphabet)),\n   ...                 \"just_prefix\": int(self.just_prefix)}\n   ...\n   ...     @classmethod\n   ...     def from_dict(cls, data):\n   ...         return cls(data['prefix'],\n   ...                    data['patterns'],\n   ...                    data['alphabet'],\n   ...                    bool(int(data['just_prefix'])))\n\nWe also add some methods that we will need to get the enumerations of the\nobjects later.\n\n.. code:: python\n\n   ...     def is_atom(self):\n   ...        \"\"\"Return True if the class contains a single word.\"\"\"\n   ...        return self.just_prefix\n   ...\n   ...     def minimum_size_of_object(self):\n   ...        \"\"\"Return the size of the smallest object in the class.\"\"\"\n   ...        return len(self.prefix)\n\nOur ``CombinatorialClass`` is now ready. What is left to do is create\nthe strategies that the ``CombinatorialSpecificationSearcher`` will use\nfor performing combinatorial exploration. This is given in the form of a\n``StrategyPack`` which can be imported from ``comb_spec_searcher`` that\nwe will populate in the remainder of this example.\n\n.. code:: python\n\n   \u003e\u003e\u003e from comb_spec_searcher import AtomStrategy, StrategyPack\n   \u003e\u003e\u003e pack = StrategyPack(initial_strats=[],\n   ...                     inferral_strats=[],\n   ...                     expansion_strats=[],\n   ...                     ver_strats=[AtomStrategy()],\n   ...                     name=(\"Finding specification for words avoiding \"\n   ...                           \"consecutive patterns.\"))\n\nStrategies are functions that take as input a class ``C`` and produce\nrules about ``C``. The types of strategies are as follows: -\n``initial_strats``: yields rules for classes - ``inferral_strats``:\nreturns a single equivalence rule - ``expansion_strats``: yields rules\nfor classes - ``ver_strats``: returns a rule when the count of a class\nis known.\n\nIn our pack we have already added the AtomStrategy. This will verify any\ncombinatorial class that is an atom, in particular this is determined by the\n``is_atom`` method we implemented on ``CombinatorialClass``. To get the\nenumeration at the end, the strategy also uses the method\n``minimum_size_of_object`` on ``CombinatorialClass``. As we've implemented\nthese two methods already, we are free to use the ``AtomStrategy``.\n\nNow we will create our first strategy. Every word over the alphabet ``Σ``\nstarting with prefix ``p`` is either just ``p`` or has prefix ``pa`` for some\n``a`` in ``Σ``. This rule is splitting the original into disjoint subsets. We\ncall a rule using disjoint union a ``DisjointUnionStrategy``. Although in this\ncase thereis a unique rule created by the strategy, strategies are assumed to\ncreate multiple rules, and as such should be implemented as generators.\n\n.. code:: python\n\n   \u003e\u003e\u003e from comb_spec_searcher import DisjointUnionStrategy\n\n\n   \u003e\u003e\u003e class ExpansionStrategy(DisjointUnionStrategy[AvoidingWithPrefix, Word]):\n   ...     def decomposition_function(self, avoiding_with_prefix):\n   ...        if not avoiding_with_prefix.just_prefix:\n   ...           alphabet, prefix, patterns = (\n   ...                 avoiding_with_prefix.alphabet,\n   ...                 avoiding_with_prefix.prefix,\n   ...                 avoiding_with_prefix.patterns,\n   ...           )\n   ...           children = [AvoidingWithPrefix(prefix, patterns, alphabet, True)]\n   ...           for a in alphabet:\n   ...                 ends_with_a = AvoidingWithPrefix(prefix + a, patterns, alphabet)\n   ...                 children.append(ends_with_a)\n   ...           return tuple(children)\n   ...\n   ...     def formal_step(self):\n   ...        return \"Either just the prefix, or append a letter from the alphabet\"\n   ...\n   ...     def forward_map(self, avoiding_with_prefix, word, children=None):\n   ...        \"\"\"\n   ...        The backward direction of the underlying bijection used for object\n   ...        generation and sampling.\n   ...        \"\"\"\n   ...        assert isinstance(word, Word)\n   ...        if children is None:\n   ...           children = self.decomposition_function(avoiding_with_prefix)\n   ...           assert children is not None\n   ...        if len(word) == len(avoiding_with_prefix.prefix):\n   ...           return (word,) + tuple(None for i in range(len(children) - 1))\n   ...        for idx, child in enumerate(children[1:]):\n   ...           if word[: len(child.prefix)] == child.prefix:\n   ...                 return (\n   ...                    tuple(None for _ in range(idx + 1))\n   ...                    + (word,)\n   ...                    + tuple(None for _ in range(len(children) - idx - 1))\n   ...                 )\n   ...\n   ...     def __str__(self):\n   ...        return self.formal_step()\n   ...\n   ...     def __repr__(self):\n   ...        return self.__class__.__name__ + \"()\"\n   ...\n   ...     @classmethod\n   ...     def from_dict(cls, d):\n   ...        return cls()\n\n\nThe final strategy we will need is one that peels off much as possible\nfrom the front of the prefix ``p`` such that the avoidance conditions\nare unaffected. This should then give a rule that is a cartesian product\nof the part that is peeled off together with the words whose prefix is\nthat of the remainder of the original prefix. We call rules whose\nconstructor is cartesian product a ``DecompositionRule``.\n\n.. code:: python\n\n   \u003e\u003e\u003e from comb_spec_searcher import CartesianProductStrategy\n\n\n   \u003e\u003e\u003e class RemoveFrontOfPrefix(CartesianProductStrategy[AvoidingWithPrefix, Word]):\n   ...     def decomposition_function(self, avoiding_with_prefix):\n   ...        \"\"\"If the k is the maximum size of a pattern to be avoided, then any\n   ...        occurrence using indices further to the right of the prefix can use at\n   ...        most the last k - 1 letters in the prefix.\"\"\"\n   ...        if not avoiding_with_prefix.just_prefix:\n   ...           safe = self.index_safe_to_remove_up_to(avoiding_with_prefix)\n   ...           if safe \u003e 0:\n   ...                 prefix, patterns, alphabet = (\n   ...                    avoiding_with_prefix.prefix,\n   ...                    avoiding_with_prefix.patterns,\n   ...                    avoiding_with_prefix.alphabet,\n   ...                 )\n   ...                 start_prefix = prefix[:safe]\n   ...                 end_prefix = prefix[safe:]\n   ...                 start = AvoidingWithPrefix(start_prefix, patterns, alphabet, True)\n   ...                 end = AvoidingWithPrefix(end_prefix, patterns, alphabet)\n   ...                 return (start, end)\n   ...\n   ...     def index_safe_to_remove_up_to(self, avoiding_with_prefix):\n   ...        prefix, patterns = (\n   ...           avoiding_with_prefix.prefix,\n   ...           avoiding_with_prefix.patterns,\n   ...        )\n   ...        # safe will be the index of the prefix in which we can remove upto without\n   ...        # affecting the avoidance conditions\n   ...        m = max(len(p) for p in patterns) if patterns else 1\n   ...        safe = max(0, len(prefix) - m + 1)\n   ...        for i in range(safe, len(prefix)):\n   ...           end = prefix[i:]\n   ...           if any(end == patt[: len(end)] for patt in patterns):\n   ...                 break\n   ...           safe = i + 1\n   ...        return safe\n   ...\n   ...     def formal_step(self):\n   ...        return \"removing redundant prefix\"\n   ...\n   ...     def backward_map(self, avoiding_with_prefix, words, children=None):\n   ...        \"\"\"\n   ...        The forward direction of the underlying bijection used for object\n   ...        generation and sampling.\n   ...        \"\"\"\n   ...        assert len(words) == 2\n   ...        assert isinstance(words[0], Word)\n   ...        assert isinstance(words[1], Word)\n   ...        if children is None:\n   ...           children = self.decomposition_function(avoiding_with_prefix)\n   ...           assert children is not None\n   ...        yield Word(words[0] + words[1])\n   ...\n   ...     def forward_map(self, comb_class, word, children=None):\n   ...        \"\"\"\n   ...        The backward direction of the underlying bijection used for object\n   ...        generation and sampling.\n   ...        \"\"\"\n   ...        assert isinstance(word, Word)\n   ...        if children is None:\n   ...           children = self.decomposition_function(comb_class)\n   ...           assert children is not None\n   ...        return Word(children[0].prefix), Word(word[len(children[0].prefix) :])\n   ...\n   ...     @classmethod\n   ...     def from_dict(cls, d):\n   ...        return cls()\n   ...\n   ...     def __str__(self):\n   ...        return self.formal_step()\n   ...\n   ...     def __repr__(self):\n   ...        return self.__class__.__name__ + \"()\"\n\nWith these three strategies we are now ready to perform combinatorial\nexploration using the following pack.\n\n.. code:: python\n\n   \u003e\u003e\u003e pack = StrategyPack(initial_strats=[RemoveFrontOfPrefix()],\n   ...                     inferral_strats=[],\n   ...                     expansion_strats=[[ExpansionStrategy()]],\n   ...                     ver_strats=[AtomStrategy()],\n   ...                     name=(\"Finding specification for words avoiding \"\n   ...                           \"consecutive patterns.\"))\n\nFirst we need to create the combinatorial class we want to count. For\nexample, consider the words over the alphabet ``{a, b}`` that avoid\n``ababa`` and ``babb``. This class can be created using our initialise\nfunction.\n\n.. code:: python\n\n   \u003e\u003e\u003e prefix = ''\n   \u003e\u003e\u003e patterns = ['ababa', 'babb']\n   \u003e\u003e\u003e alphabet = ['a', 'b']\n   \u003e\u003e\u003e start_class = AvoidingWithPrefix(prefix, patterns, alphabet)\n\nWe can then initialise our ``CombinatorialSpecificationSearcher``, and\nuse the ``auto_search`` function which will return a\n``CombinatorialSpecification`` assuming one is found (which in this case always\nwill).\n\n.. code:: python\n\n   \u003e\u003e\u003e from comb_spec_searcher import CombinatorialSpecificationSearcher\n\n\n   \u003e\u003e\u003e searcher = CombinatorialSpecificationSearcher(start_class, pack)\n   \u003e\u003e\u003e spec = searcher.auto_search()\n   \u003e\u003e\u003e # spec.show() will display the specification in your browser\n\nNow that we have a ``CombinatorialSpecification``, the obvious\nthing we want to do is find the generating function for the class that\ncounts the number of objects of each size. This can be done by using the\n``get_genf`` methods on ``CombinatorialSpecification``.\n\nFinally, in order to get initial terms, you will also need to implement\nthe ``objects_of_size`` function which should yield all of the objects\nof a given size in the class.\n\n.. code:: python\n\n   \u003e\u003e\u003e from itertools import product\n\n   \u003e\u003e\u003e def objects_of_size(self, size):\n   ...     \"\"\"Yield the words of given size that start with prefix and avoid the\n   ...     patterns. If just_prefix, then only yield that word.\"\"\"\n   ...     def possible_words():\n   ...         \"\"\"Yield all words of given size over the alphabet with prefix\"\"\"\n   ...         if len(self.prefix) \u003e size:\n   ...            return\n   ...         for letters in product(self.alphabet,\n   ...                                 repeat=size - len(self.prefix)):\n   ...             yield Word(self.prefix + \"\".join(a for a in letters))\n   ...\n   ...     if self.just_prefix:\n   ...         if size == len(self.prefix) and not self.is_empty():\n   ...             yield Word(self.prefix)\n   ...         return\n   ...     for word in possible_words():\n   ...         if all(patt not in word for patt in self.patterns):\n   ...             yield word\n   \u003e\u003e\u003e AvoidingWithPrefix.objects_of_size = objects_of_size\n\nWith these in place if we then call the ``get_genf`` function\n\n.. code:: python\n\n   \u003e\u003e\u003e spec.get_genf()\n   -(x + 1)*(x**2 - x + 1)**2*(x**2 + x + 1)/(x**6 + x**3 - x**2 + 2*x - 1)\n\nwe see that the the generating function is\n``F = -(x**7 + x**5 + x**4 + x**3 + x**2 + 1)/(x**6 + x**3 - x**2 + 2*x - 1)``.\n\nMoreover, we can get directly the number of objects by size with the method\n`count_objects_of_size`.\n\n.. code:: python\n\n   \u003e\u003e\u003e [spec.count_objects_of_size(i) for i in range(11)]\n   [1, 2, 4, 8, 15, 27, 48, 87, 157, 283, 511]\n\nYou can now try this yourself using the file ``example.py``, which can\ncount any set of words avoiding consecutive patterns.\n\nNow we will demonstrate how a bijection can be found between classes.\nWe will first need a couple of imports.\n\n.. code:: python\n\n   \u003e\u003e\u003e from comb_spec_searcher.bijection import ParallelSpecFinder\n   \u003e\u003e\u003e from comb_spec_searcher.isomorphism import Bijection\n\nWe start by defining our two classes that we wish to find a bijection between.\n\n.. code:: python\n\n   \u003e\u003e\u003e prefix1 = ''\n   \u003e\u003e\u003e patterns1 = [\"00\"]\n   \u003e\u003e\u003e alphabet1 = ['0', '1']\n   \u003e\u003e\u003e class1 = AvoidingWithPrefix(prefix1, patterns1, alphabet1)\n   \u003e\u003e\u003e prefix2 = ''\n   \u003e\u003e\u003e patterns2 = [\"bb\"]\n   \u003e\u003e\u003e alphabet2 = ['a', 'b']\n   \u003e\u003e\u003e class2 = AvoidingWithPrefix(prefix2, patterns2, alphabet2)\n\nTo find a bijection we expand the universe given a pack for both classes\nand try to construct specifications that are parallel.\n\n.. code:: python\n\n   \u003e\u003e\u003e searcher1 = CombinatorialSpecificationSearcher(class1, pack)\n   \u003e\u003e\u003e searcher2 = CombinatorialSpecificationSearcher(class2, pack)\n\nWe get two parallel specs if successful, ``None`` otherwise.\n\n.. code:: python\n\n   \u003e\u003e\u003e specs = ParallelSpecFinder(searcher1, searcher2).find()\n\nWe then construct the bijection from the parallel specifications.\n\n.. code:: python\n\n   \u003e\u003e\u003e bijection = Bijection.construct(*specs)\n\nWe can use the `Bijection` object to map (either way) sampled objects\nfrom the sepcifications.\n\n.. code:: python\n\n   \u003e\u003e\u003e for i in range(10):\n   ...     for w in bijection.domain.generate_objects_of_size(i):\n   ...         assert w == bijection.inverse_map(bijection.map(w))\n   ...     for w in bijection.codomain.generate_objects_of_size(i):\n   ...         assert w == bijection.map(bijection.inverse_map(w))\n   ...\n\nWhether we find a bijection or not (when one exists) is highly\ndependent on the packs chosen.\n\nCiting\n######\n\nIf you found this library helpful with your research and would like to cite us,\nyou can use the following `BibTeX`_ or go to `Zenodo`_ for alternative formats.\n\n.. _BibTex: https://zenodo.org/record/4944021/export/hx#.YMcpIC2l30o\n\n.. _Zenodo: https://doi.org/10.5281/zenodo.4944020\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermutatriangle%2Fcomb_spec_searcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpermutatriangle%2Fcomb_spec_searcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermutatriangle%2Fcomb_spec_searcher/lists"}