Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/coset_table.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/fp_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/free_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/galois.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/generators.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/graycode.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/group_constructs.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/group_numbers.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/homomorphisms.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/named_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/partitions.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/pc_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/polyhedron.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/prufer.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/rewritingsystem.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/rewritingsystem_fsm.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/schur_number.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/subsets.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/tensor_can.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/testutil.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/__pycache__/util.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/group_numbers.pyAdded+296
- lib/python3.12/site-packages/sympy/combinatorics/partitions.pyAdded+745
- lib/python3.12/site-packages/sympy/combinatorics/rewritingsystem.pyAdded+453
- lib/python3.12/site-packages/sympy/combinatorics/tests/__init__.pyAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_coset_table.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_fp_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_free_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_galois.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_generators.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_graycode.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_group_constructs.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_group_numbers.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_homomorphisms.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_named_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_partitions.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_pc_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_perm_groups.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_permutations.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_polyhedron.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_prufer.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_rewriting.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_schur_number.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_subsets.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_tensor_can.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_testutil.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_util.cpython-312.pycAdded
- lib/python3.12/site-packages/sympy/combinatorics/tests/test_coset_table.pyAdded+825
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296from itertools import chain, combinations
from sympy.external.gmpy import gcdfrom sympy.ntheory.factor_ import factorintfrom sympy.utilities.misc import as_int
def _is_nilpotent_number(factors: dict) -> bool: """ Check whether `n` is a nilpotent number. Note that ``factors`` is a prime factorization of `n`.
This is a low-level helper for ``is_nilpotent_number``, for internal use. """ for p in factors.keys(): for q, e in factors.items(): # We want to calculate # any(pow(q, k, p) == 1 for k in range(1, e + 1)) m = 1 for _ in range(e): m = m*q % p if m == 1: return False return True
def is_nilpotent_number(n) -> bool: """ Check whether `n` is a nilpotent number. A number `n` is said to be nilpotent if and only if every finite group of order `n` is nilpotent. For more information see [1]_.
Examples ========
>>> from sympy.combinatorics.group_numbers import is_nilpotent_number >>> from sympy import randprime >>> is_nilpotent_number(21) False >>> is_nilpotent_number(randprime(1, 30)**12) True
References ==========
.. [1] Pakianathan, J., Shankar, K., Nilpotent Numbers, The American Mathematical Monthly, 107(7), 631-634. .. [2] https://oeis.org/A056867
""" n = as_int(n) if n <= 0: raise ValueError("n must be a positive integer, not %i" % n) return _is_nilpotent_number(factorint(n))
def is_abelian_number(n) -> bool: """ Check whether `n` is an abelian number. A number `n` is said to be abelian if and only if every finite group of order `n` is abelian. For more information see [1]_.
Examples ========
>>> from sympy.combinatorics.group_numbers import is_abelian_number >>> from sympy import randprime >>> is_abelian_number(4) True >>> is_abelian_number(randprime(1, 2000)**2) True >>> is_abelian_number(60) False
References ==========
.. [1] Pakianathan, J., Shankar, K., Nilpotent Numbers, The American Mathematical Monthly, 107(7), 631-634. .. [2] https://oeis.org/A051532
""" n = as_int(n) if n <= 0: raise ValueError("n must be a positive integer, not %i" % n) factors = factorint(n) return all(e < 3 for e in factors.values()) and _is_nilpotent_number(factors)
def is_cyclic_number(n) -> bool: """ Check whether `n` is a cyclic number. A number `n` is said to be cyclic if and only if every finite group of order `n` is cyclic. For more information see [1]_.
Examples ========
>>> from sympy.combinatorics.group_numbers import is_cyclic_number >>> from sympy import randprime >>> is_cyclic_number(15) True >>> is_cyclic_number(randprime(1, 2000)**2) False >>> is_cyclic_number(4) False
References ==========
.. [1] Pakianathan, J., Shankar, K., Nilpotent Numbers, The American Mathematical Monthly, 107(7), 631-634. .. [2] https://oeis.org/A003277
""" n = as_int(n) if n <= 0: raise ValueError("n must be a positive integer, not %i" % n) factors = factorint(n) return all(e == 1 for e in factors.values()) and _is_nilpotent_number(factors)
def _holder_formula(prime_factors): r""" Number of groups of order `n`. where `n` is squarefree and its prime factors are ``prime_factors``. i.e., ``n == math.prod(prime_factors)``
Explanation ===========
When `n` is squarefree, the number of groups of order `n` is expressed by
.. math :: \sum_{d \mid n} \prod_p \frac{p^{c(p, d)} - 1}{p - 1}
where `n=de`, `p` is the prime factor of `e`, and `c(p, d)` is the number of prime factors `q` of `d` such that `q \equiv 1 \pmod{p}` [2]_.
The formula is elegant, but can be improved when implemented as an algorithm. Since `n` is assumed to be squarefree, the divisor `d` of `n` can be identified with the power set of prime factors. We let `N` be the set of prime factors of `n`. `F = \{p \in N : \forall q \in N, q \not\equiv 1 \pmod{p} \}, M = N \setminus F`, we have the following.
.. math :: \sum_{d \in 2^{M}} \prod_{p \in M \setminus d} \frac{p^{c(p, F \cup d)} - 1}{p - 1}
Practically, many prime factors are expected to be members of `F`, thus reducing computation time.
Parameters ==========
prime_factors : set The set of prime factors of ``n``. where `n` is squarefree.
Returns =======
int : Number of groups of order ``n``
Examples ========
>>> from sympy.combinatorics.group_numbers import _holder_formula >>> _holder_formula({2}) # n = 2 1 >>> _holder_formula({2, 3}) # n = 2*3 = 6 2
See Also ========
groups_count
References ==========
.. [1] Otto Holder, Die Gruppen der Ordnungen p^3, pq^2, pqr, p^4, Math. Ann. 43 pp. 301-412 (1893). http://dx.doi.org/10.1007/BF01443651 .. [2] John H. Conway, Heiko Dietrich and E.A. O'Brien, Counting groups: gnus, moas and other exotica The Mathematical Intelligencer 30, 6-15 (2008) https://doi.org/10.1007/BF02985731
""" F = {p for p in prime_factors if all(q % p != 1 for q in prime_factors)} M = prime_factors - F
s = 0 powerset = chain.from_iterable(combinations(M, r) for r in range(len(M)+1)) for ps in powerset: ps = set(ps) prod = 1 for p in M - ps: c = len([q for q in F | ps if q % p == 1]) prod *= (p**c - 1) // (p - 1) if not prod: break s += prod return s
def groups_count(n): r""" Number of groups of order `n`. In [1]_, ``gnu(n)`` is given, so we follow this notation here as well.
Parameters ==========
n : Integer ``n`` is a positive integer
Returns =======
int : ``gnu(n)``
Raises ======
ValueError Number of groups of order ``n`` is unknown or not implemented. For example, gnu(`2^{11}`) is not yet known. On the other hand, gnu(12) is known to be 5, but this has not yet been implemented in this function.
Examples ========
>>> from sympy.combinatorics.group_numbers import groups_count >>> groups_count(3) # There is only one cyclic group of order 3 1 >>> # There are two groups of order 10: the cyclic group and the dihedral group >>> groups_count(10) 2
See Also ========
is_cyclic_number `n` is cyclic iff gnu(n) = 1
References ==========
.. [1] John H. Conway, Heiko Dietrich and E.A. O'Brien, Counting groups: gnus, moas and other exotica The Mathematical Intelligencer 30, 6-15 (2008) https://doi.org/10.1007/BF02985731 .. [2] https://oeis.org/A000001
""" n = as_int(n) if n <= 0: raise ValueError("n must be a positive integer, not %i" % n) factors = factorint(n) if len(factors) == 1: (p, e) = list(factors.items())[0] if p == 2: A000679 = [1, 1, 2, 5, 14, 51, 267, 2328, 56092, 10494213, 49487367289] if e < len(A000679): return A000679[e] if p == 3: A090091 = [1, 1, 2, 5, 15, 67, 504, 9310, 1396077, 5937876645] if e < len(A090091): return A090091[e] if e <= 2: # gnu(p) = 1, gnu(p**2) = 2 return e if e == 3: # gnu(p**3) = 5 return 5 if e == 4: # if p is an odd prime, gnu(p**4) = 15 return 15 if e == 5: # if p >= 5, gnu(p**5) is expressed by the following equation return 61 + 2*p + 2*gcd(p-1, 3) + gcd(p-1, 4) if e == 6: # if p >= 6, gnu(p**6) is expressed by the following equation return 3*p**2 + 39*p + 344 +\ 24*gcd(p-1, 3) + 11*gcd(p-1, 4) + 2*gcd(p-1, 5) if e == 7: # if p >= 7, gnu(p**7) is expressed by the following equation if p == 5: return 34297 return 3*p**5 + 12*p**4 + 44*p**3 + 170*p**2 + 707*p + 2455 +\ (4*p**2 + 44*p + 291)*gcd(p-1, 3) + (p**2 + 19*p + 135)*gcd(p-1, 4) + \ (3*p + 31)*gcd(p-1, 5) + 4*gcd(p-1, 7) + 5*gcd(p-1, 8) + gcd(p-1, 9) if any(e > 1 for e in factors.values()): # n is not squarefree # some known values for small n that have more than 1 factor and are not square free (https://oeis.org/A000001) small = {12: 5, 18: 5, 20: 5, 24: 15, 28: 4, 36: 14, 40: 14, 44: 4, 45: 2, 48: 52, 50: 5, 52: 5, 54: 15, 56: 13, 60: 13, 63: 4, 68: 5, 72: 50, 75: 3, 76: 4, 80: 52, 84: 15, 88: 12, 90: 10, 92: 4} if n in small: return small[n] raise ValueError("Number of groups of order n is unknown or not implemented") if len(factors) == 2: # n is squarefree semiprime p, q = list(factors.keys()) if p > q: p, q = q, p return 2 if q % p == 1 else 1 return _holder_formula(set(factors.keys()))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745from sympy.core import Basic, Dict, sympify, Tuplefrom sympy.core.numbers import Integerfrom sympy.core.sorting import default_sort_keyfrom sympy.core.sympify import _sympifyfrom sympy.functions.combinatorial.numbers import bellfrom sympy.matrices import zerosfrom sympy.sets.sets import FiniteSet, Unionfrom sympy.utilities.iterables import flatten, groupfrom sympy.utilities.misc import as_int
from collections import defaultdict
class Partition(FiniteSet): """ This class represents an abstract partition.
A partition is a set of disjoint sets whose union equals a given set.
See Also ========
sympy.utilities.iterables.partitions, sympy.utilities.iterables.multiset_partitions """
_rank = None _partition = None
def __new__(cls, *partition): """ Generates a new partition object.
This method also verifies if the arguments passed are valid and raises a ValueError if they are not.
Examples ========
Creating Partition from Python lists:
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3]) >>> a Partition({3}, {1, 2}) >>> a.partition [[1, 2], [3]] >>> len(a) 2 >>> a.members (1, 2, 3)
Creating Partition from Python sets:
>>> Partition({1, 2, 3}, {4, 5}) Partition({4, 5}, {1, 2, 3})
Creating Partition from SymPy finite sets:
>>> from sympy import FiniteSet >>> a = FiniteSet(1, 2, 3) >>> b = FiniteSet(4, 5) >>> Partition(a, b) Partition({4, 5}, {1, 2, 3}) """ args = [] dups = False for arg in partition: if isinstance(arg, list): as_set = set(arg) if len(as_set) < len(arg): dups = True break # error below arg = as_set args.append(_sympify(arg))
if not all(isinstance(part, FiniteSet) for part in args): raise ValueError( "Each argument to Partition should be " \ "a list, set, or a FiniteSet")
# sort so we have a canonical reference for RGS U = Union(*args) if dups or len(U) < sum(len(arg) for arg in args): raise ValueError("Partition contained duplicate elements.")
obj = FiniteSet.__new__(cls, *args) obj.members = tuple(U) obj.size = len(U) return obj
def sort_key(self, order=None): """Return a canonical key that can be used for sorting.
Ordering is based on the size and sorted elements of the partition and ties are broken with the rank.
Examples ========
>>> from sympy import default_sort_key >>> from sympy.combinatorics import Partition >>> from sympy.abc import x >>> a = Partition([1, 2]) >>> b = Partition([3, 4]) >>> c = Partition([1, x]) >>> d = Partition(list(range(4))) >>> l = [d, b, a + 1, a, c] >>> l.sort(key=default_sort_key); l [Partition({1, 2}), Partition({1}, {2}), Partition({1, x}), Partition({3, 4}), Partition({0, 1, 2, 3})] """ if order is None: members = self.members else: members = tuple(sorted(self.members, key=lambda w: default_sort_key(w, order))) return tuple(map(default_sort_key, (self.size, members, self.rank)))
@property def partition(self): """Return partition as a sorted list of lists.
Examples ========
>>> from sympy.combinatorics import Partition >>> Partition([1], [2, 3]).partition [[1], [2, 3]] """ if self._partition is None: self._partition = sorted([sorted(p, key=default_sort_key) for p in self.args]) return self._partition
def __add__(self, other): """ Return permutation whose rank is ``other`` greater than current rank, (mod the maximum rank for the set).
Examples ========
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3]) >>> a.rank 1 >>> (a + 1).rank 2 >>> (a + 100).rank 1 """ other = as_int(other) offset = self.rank + other result = RGS_unrank((offset) % RGS_enum(self.size), self.size) return Partition.from_rgs(result, self.members)
def __sub__(self, other): """ Return permutation whose rank is ``other`` less than current rank, (mod the maximum rank for the set).
Examples ========
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3]) >>> a.rank 1 >>> (a - 1).rank 0 >>> (a - 100).rank 1 """ return self.__add__(-other)
def __le__(self, other): """ Checks if a partition is less than or equal to the other based on rank.
Examples ========
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3, 4, 5]) >>> b = Partition([1], [2, 3], [4], [5]) >>> a.rank, b.rank (9, 34) >>> a <= a True >>> a <= b True """ return self.sort_key() <= sympify(other).sort_key()
def __lt__(self, other): """ Checks if a partition is less than the other.
Examples ========
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3, 4, 5]) >>> b = Partition([1], [2, 3], [4], [5]) >>> a.rank, b.rank (9, 34) >>> a < b True """ return self.sort_key() < sympify(other).sort_key()
@property def rank(self): """ Gets the rank of a partition.
Examples ========
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3], [4, 5]) >>> a.rank 13 """ if self._rank is not None: return self._rank self._rank = RGS_rank(self.RGS) return self._rank
@property def RGS(self): """ Returns the "restricted growth string" of the partition.
Explanation ===========
The RGS is returned as a list of indices, L, where L[i] indicates the block in which element i appears. For example, in a partition of 3 elements (a, b, c) into 2 blocks ([c], [a, b]) the RGS is [1, 1, 0]: "a" is in block 1, "b" is in block 1 and "c" is in block 0.
Examples ========
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3], [4, 5]) >>> a.members (1, 2, 3, 4, 5) >>> a.RGS (0, 0, 1, 2, 2) >>> a + 1 Partition({3}, {4}, {5}, {1, 2}) >>> _.RGS (0, 0, 1, 2, 3) """ rgs = {} partition = self.partition for i, part in enumerate(partition): for j in part: rgs[j] = i return tuple([rgs[i] for i in sorted( [i for p in partition for i in p], key=default_sort_key)])
@classmethod def from_rgs(self, rgs, elements): """ Creates a set partition from a restricted growth string.
Explanation ===========
The indices given in rgs are assumed to be the index of the element as given in elements *as provided* (the elements are not sorted by this routine). Block numbering starts from 0. If any block was not referenced in ``rgs`` an error will be raised.
Examples ========
>>> from sympy.combinatorics import Partition >>> Partition.from_rgs([0, 1, 2, 0, 1], list('abcde')) Partition({c}, {a, d}, {b, e}) >>> Partition.from_rgs([0, 1, 2, 0, 1], list('cbead')) Partition({e}, {a, c}, {b, d}) >>> a = Partition([1, 4], [2], [3, 5]) >>> Partition.from_rgs(a.RGS, a.members) Partition({2}, {1, 4}, {3, 5}) """ if len(rgs) != len(elements): raise ValueError('mismatch in rgs and element lengths') max_elem = max(rgs) + 1 partition = [[] for i in range(max_elem)] j = 0 for i in rgs: partition[i].append(elements[j]) j += 1 if not all(p for p in partition): raise ValueError('some blocks of the partition were empty.') return Partition(*partition)
class IntegerPartition(Basic): """ This class represents an integer partition.
Explanation ===========
In number theory and combinatorics, a partition of a positive integer, ``n``, also called an integer partition, is a way of writing ``n`` as a list of positive integers that sum to n. Two partitions that differ only in the order of summands are considered to be the same partition; if order matters then the partitions are referred to as compositions. For example, 4 has five partitions: [4], [3, 1], [2, 2], [2, 1, 1], and [1, 1, 1, 1]; the compositions [1, 2, 1] and [1, 1, 2] are the same as partition [2, 1, 1].
See Also ========
sympy.utilities.iterables.partitions, sympy.utilities.iterables.multiset_partitions
References ==========
.. [1] https://en.wikipedia.org/wiki/Partition_%28number_theory%29 """
_dict = None _keys = None
def __new__(cls, partition, integer=None): """ Generates a new IntegerPartition object from a list or dictionary.
Explanation ===========
The partition can be given as a list of positive integers or a dictionary of (integer, multiplicity) items. If the partition is preceded by an integer an error will be raised if the partition does not sum to that given integer.
Examples ========
>>> from sympy.combinatorics.partitions import IntegerPartition >>> a = IntegerPartition([5, 4, 3, 1, 1]) >>> a IntegerPartition(14, (5, 4, 3, 1, 1)) >>> print(a) [5, 4, 3, 1, 1] >>> IntegerPartition({1:3, 2:1}) IntegerPartition(5, (2, 1, 1, 1))
If the value that the partition should sum to is given first, a check will be made to see n error will be raised if there is a discrepancy:
>>> IntegerPartition(10, [5, 4, 3, 1]) Traceback (most recent call last): ... ValueError: The partition is not valid
""" if integer is not None: integer, partition = partition, integer if isinstance(partition, (dict, Dict)): _ = [] for k, v in sorted(partition.items(), reverse=True): if not v: continue k, v = as_int(k), as_int(v) _.extend([k]*v) partition = tuple(_) else: partition = tuple(sorted(map(as_int, partition), reverse=True)) sum_ok = False if integer is None: integer = sum(partition) sum_ok = True else: integer = as_int(integer)
if not sum_ok and sum(partition) != integer: raise ValueError("Partition did not add to %s" % integer) if any(i < 1 for i in partition): raise ValueError("All integer summands must be greater than one")
obj = Basic.__new__(cls, Integer(integer), Tuple(*partition)) obj.partition = list(partition) obj.integer = integer return obj
def prev_lex(self): """Return the previous partition of the integer, n, in lexical order, wrapping around to [1, ..., 1] if the partition is [n].
Examples ========
>>> from sympy.combinatorics.partitions import IntegerPartition >>> p = IntegerPartition([4]) >>> print(p.prev_lex()) [3, 1] >>> p.partition > p.prev_lex().partition True """ d = defaultdict(int) d.update(self.as_dict()) keys = self._keys if keys == [1]: return IntegerPartition({self.integer: 1}) if keys[-1] != 1: d[keys[-1]] -= 1 if keys[-1] == 2: d[1] = 2 else: d[keys[-1] - 1] = d[1] = 1 else: d[keys[-2]] -= 1 left = d[1] + keys[-2] new = keys[-2] d[1] = 0 while left: new -= 1 if left - new >= 0: d[new] += left//new left -= d[new]*new return IntegerPartition(self.integer, d)
def next_lex(self): """Return the next partition of the integer, n, in lexical order, wrapping around to [n] if the partition is [1, ..., 1].
Examples ========
>>> from sympy.combinatorics.partitions import IntegerPartition >>> p = IntegerPartition([3, 1]) >>> print(p.next_lex()) [4] >>> p.partition < p.next_lex().partition True """ d = defaultdict(int) d.update(self.as_dict()) key = self._keys a = key[-1] if a == self.integer: d.clear() d[1] = self.integer elif a == 1: if d[a] > 1: d[a + 1] += 1 d[a] -= 2 else: b = key[-2] d[b + 1] += 1 d[1] = (d[b] - 1)*b d[b] = 0 else: if d[a] > 1: if len(key) == 1: d.clear() d[a + 1] = 1 d[1] = self.integer - a - 1 else: a1 = a + 1 d[a1] += 1 d[1] = d[a]*a - a1 d[a] = 0 else: b = key[-2] b1 = b + 1 d[b1] += 1 need = d[b]*b + d[a]*a - b1 d[a] = d[b] = 0 d[1] = need return IntegerPartition(self.integer, d)
def as_dict(self): """Return the partition as a dictionary whose keys are the partition integers and the values are the multiplicity of that integer.
Examples ========
>>> from sympy.combinatorics.partitions import IntegerPartition >>> IntegerPartition([1]*3 + [2] + [3]*4).as_dict() {1: 3, 2: 1, 3: 4} """ if self._dict is None: groups = group(self.partition, multiple=False) self._keys = [g[0] for g in groups] self._dict = dict(groups) return self._dict
@property def conjugate(self): """ Computes the conjugate partition of itself.
Examples ========
>>> from sympy.combinatorics.partitions import IntegerPartition >>> a = IntegerPartition([6, 3, 3, 2, 1]) >>> a.conjugate [5, 4, 3, 1, 1, 1] """ j = 1 temp_arr = list(self.partition) + [0] k = temp_arr[0] b = [0]*k while k > 0: while k > temp_arr[j]: b[k - 1] = j k -= 1 j += 1 return b
def __lt__(self, other): """Return True if self is less than other when the partition is listed from smallest to biggest.
Examples ========
>>> from sympy.combinatorics.partitions import IntegerPartition >>> a = IntegerPartition([3, 1]) >>> a < a False >>> b = a.next_lex() >>> a < b True >>> a == b False """ return list(reversed(self.partition)) < list(reversed(other.partition))
def __le__(self, other): """Return True if self is less than other when the partition is listed from smallest to biggest.
Examples ========
>>> from sympy.combinatorics.partitions import IntegerPartition >>> a = IntegerPartition([4]) >>> a <= a True """ return list(reversed(self.partition)) <= list(reversed(other.partition))
def as_ferrers(self, char='#'): """ Prints the ferrer diagram of a partition.
Examples ========
>>> from sympy.combinatorics.partitions import IntegerPartition >>> print(IntegerPartition([1, 1, 5]).as_ferrers()) ##### # # """ return "\n".join([char*i for i in self.partition])
def __str__(self): return str(list(self.partition))
def random_integer_partition(n, seed=None): """ Generates a random integer partition summing to ``n`` as a list of reverse-sorted integers.
Examples ========
>>> from sympy.combinatorics.partitions import random_integer_partition
For the following, a seed is given so a known value can be shown; in practice, the seed would not be given.
>>> random_integer_partition(100, seed=[1, 1, 12, 1, 2, 1, 85, 1]) [85, 12, 2, 1] >>> random_integer_partition(10, seed=[1, 2, 3, 1, 5, 1]) [5, 3, 1, 1] >>> random_integer_partition(1) [1] """ from sympy.core.random import _randint
n = as_int(n) if n < 1: raise ValueError('n must be a positive integer')
randint = _randint(seed)
partition = [] while (n > 0): k = randint(1, n) mult = randint(1, n//k) partition.append((k, mult)) n -= k*mult partition.sort(reverse=True) partition = flatten([[k]*m for k, m in partition]) return partition
def RGS_generalized(m): """ Computes the m + 1 generalized unrestricted growth strings and returns them as rows in matrix.
Examples ========
>>> from sympy.combinatorics.partitions import RGS_generalized >>> RGS_generalized(6) Matrix([ [ 1, 1, 1, 1, 1, 1, 1], [ 1, 2, 3, 4, 5, 6, 0], [ 2, 5, 10, 17, 26, 0, 0], [ 5, 15, 37, 77, 0, 0, 0], [ 15, 52, 151, 0, 0, 0, 0], [ 52, 203, 0, 0, 0, 0, 0], [203, 0, 0, 0, 0, 0, 0]]) """ d = zeros(m + 1) for i in range(m + 1): d[0, i] = 1
for i in range(1, m + 1): for j in range(m): if j <= m - i: d[i, j] = j * d[i - 1, j] + d[i - 1, j + 1] else: d[i, j] = 0 return d
def RGS_enum(m): """ RGS_enum computes the total number of restricted growth strings possible for a superset of size m.
Examples ========
>>> from sympy.combinatorics.partitions import RGS_enum >>> from sympy.combinatorics import Partition >>> RGS_enum(4) 15 >>> RGS_enum(5) 52 >>> RGS_enum(6) 203
We can check that the enumeration is correct by actually generating the partitions. Here, the 15 partitions of 4 items are generated:
>>> a = Partition(list(range(4))) >>> s = set() >>> for i in range(20): ... s.add(a) ... a += 1 ... >>> assert len(s) == 15
""" if (m < 1): return 0 elif (m == 1): return 1 else: return bell(m)
def RGS_unrank(rank, m): """ Gives the unranked restricted growth string for a given superset size.
Examples ========
>>> from sympy.combinatorics.partitions import RGS_unrank >>> RGS_unrank(14, 4) [0, 1, 2, 3] >>> RGS_unrank(0, 4) [0, 0, 0, 0] """ if m < 1: raise ValueError("The superset size must be >= 1") if rank < 0 or RGS_enum(m) <= rank: raise ValueError("Invalid arguments")
L = [1] * (m + 1) j = 1 D = RGS_generalized(m) for i in range(2, m + 1): v = D[m - i, j] cr = j*v if cr <= rank: L[i] = j + 1 rank -= cr j += 1 else: L[i] = int(rank / v + 1) rank %= v return [x - 1 for x in L[1:]]
def RGS_rank(rgs): """ Computes the rank of a restricted growth string.
Examples ========
>>> from sympy.combinatorics.partitions import RGS_rank, RGS_unrank >>> RGS_rank([0, 1, 2, 1, 3]) 42 >>> RGS_rank(RGS_unrank(4, 7)) 4 """ rgs_size = len(rgs) rank = 0 D = RGS_generalized(rgs_size) for i in range(1, rgs_size): n = len(rgs[(i + 1):]) m = max(rgs[0:i]) rank += D[n, m + 1] * rgs[i] return rank123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453from collections import dequefrom sympy.combinatorics.rewritingsystem_fsm import StateMachine
class RewritingSystem: ''' A class implementing rewriting systems for `FpGroup`s.
References ========== .. [1] Epstein, D., Holt, D. and Rees, S. (1991). The use of Knuth-Bendix methods to solve the word problem in automatic groups. Journal of Symbolic Computation, 12(4-5), pp.397-414.
.. [2] GAP's Manual on its KBMAG package https://www.gap-system.org/Manuals/pkg/kbmag-1.5.3/doc/manual.pdf
''' def __init__(self, group): self.group = group self.alphabet = group.generators self._is_confluent = None
# these values are taken from [2] self.maxeqns = 32767 # max rules self.tidyint = 100 # rules before tidying
# _max_exceeded is True if maxeqns is exceeded # at any point self._max_exceeded = False
# Reduction automaton self.reduction_automaton = None self._new_rules = {}
# dictionary of reductions self.rules = {} self.rules_cache = deque([], 50) self._init_rules()
# All the transition symbols in the automaton generators = list(self.alphabet) generators += [gen**-1 for gen in generators] # Create a finite state machine as an instance of the StateMachine object self.reduction_automaton = StateMachine('Reduction automaton for '+ repr(self.group), generators) self.construct_automaton()
def set_max(self, n): ''' Set the maximum number of rules that can be defined
''' if n > self.maxeqns: self._max_exceeded = False self.maxeqns = n return
@property def is_confluent(self): ''' Return `True` if the system is confluent
''' if self._is_confluent is None: self._is_confluent = self._check_confluence() return self._is_confluent
def _init_rules(self): identity = self.group.free_group.identity for r in self.group.relators: self.add_rule(r, identity) self._remove_redundancies() return
def _add_rule(self, r1, r2): ''' Add the rule r1 -> r2 with no checking or further deductions
''' if len(self.rules) + 1 > self.maxeqns: self._is_confluent = self._check_confluence() self._max_exceeded = True raise RuntimeError("Too many rules were defined.") self.rules[r1] = r2 # Add the newly added rule to the `new_rules` dictionary. if self.reduction_automaton: self._new_rules[r1] = r2
def add_rule(self, w1, w2, check=False): new_keys = set()
if w1 == w2: return new_keys
if w1 < w2: w1, w2 = w2, w1
if (w1, w2) in self.rules_cache: return new_keys self.rules_cache.append((w1, w2))
s1, s2 = w1, w2
# The following is the equivalent of checking # s1 for overlaps with the implicit reductions # {g*g**-1 -> <identity>} and {g**-1*g -> <identity>} # for any generator g without installing the # redundant rules that would result from processing # the overlaps. See [1], Section 3 for details.
if len(s1) - len(s2) < 3: if s1 not in self.rules: new_keys.add(s1) if not check: self._add_rule(s1, s2) if s2**-1 > s1**-1 and s2**-1 not in self.rules: new_keys.add(s2**-1) if not check: self._add_rule(s2**-1, s1**-1)
# overlaps on the right while len(s1) - len(s2) > -1: g = s1[len(s1)-1] s1 = s1.subword(0, len(s1)-1) s2 = s2*g**-1 if len(s1) - len(s2) < 0: if s2 not in self.rules: if not check: self._add_rule(s2, s1) new_keys.add(s2) elif len(s1) - len(s2) < 3: new = self.add_rule(s1, s2, check) new_keys.update(new)
# overlaps on the left while len(w1) - len(w2) > -1: g = w1[0] w1 = w1.subword(1, len(w1)) w2 = g**-1*w2 if len(w1) - len(w2) < 0: if w2 not in self.rules: if not check: self._add_rule(w2, w1) new_keys.add(w2) elif len(w1) - len(w2) < 3: new = self.add_rule(w1, w2, check) new_keys.update(new)
return new_keys
def _remove_redundancies(self, changes=False): ''' Reduce left- and right-hand sides of reduction rules and remove redundant equations (i.e. those for which lhs == rhs). If `changes` is `True`, return a set containing the removed keys and a set containing the added keys
''' removed = set() added = set() rules = self.rules.copy() for r in rules: v = self.reduce(r, exclude=r) w = self.reduce(rules[r]) if v != r: del self.rules[r] removed.add(r) if v > w: added.add(v) self.rules[v] = w elif v < w: added.add(w) self.rules[w] = v else: self.rules[v] = w if changes: return removed, added return
def make_confluent(self, check=False): ''' Try to make the system confluent using the Knuth-Bendix completion algorithm
''' if self._max_exceeded: return self._is_confluent lhs = list(self.rules.keys())
def _overlaps(r1, r2): len1 = len(r1) len2 = len(r2) result = [] for j in range(1, len1 + len2): if (r1.subword(len1 - j, len1 + len2 - j, strict=False) == r2.subword(j - len1, j, strict=False)): a = r1.subword(0, len1-j, strict=False) a = a*r2.subword(0, j-len1, strict=False) b = r2.subword(j-len1, j, strict=False) c = r2.subword(j, len2, strict=False) c = c*r1.subword(len1 + len2 - j, len1, strict=False) result.append(a*b*c) return result
def _process_overlap(w, r1, r2, check): s = w.eliminate_word(r1, self.rules[r1]) s = self.reduce(s) t = w.eliminate_word(r2, self.rules[r2]) t = self.reduce(t) if s != t: if check: # system not confluent return [0] try: new_keys = self.add_rule(t, s, check) return new_keys except RuntimeError: return False return
added = 0 i = 0 while i < len(lhs): r1 = lhs[i] i += 1 # j could be i+1 to not # check each pair twice but lhs # is extended in the loop and the new # elements have to be checked with the # preceding ones. there is probably a better way # to handle this j = 0 while j < len(lhs): r2 = lhs[j] j += 1 if r1 == r2: continue overlaps = _overlaps(r1, r2) overlaps.extend(_overlaps(r1**-1, r2)) if not overlaps: continue for w in overlaps: new_keys = _process_overlap(w, r1, r2, check) if new_keys: if check: return False lhs.extend(new_keys) added += len(new_keys) elif new_keys == False: # too many rules were added so the process # couldn't complete return self._is_confluent
if added > self.tidyint and not check: # tidy up r, a = self._remove_redundancies(changes=True) added = 0 if r: # reset i since some elements were removed i = min(lhs.index(s) for s in r) lhs = [l for l in lhs if l not in r] lhs.extend(a) if r1 in r: # r1 was removed as redundant break
self._is_confluent = True if not check: self._remove_redundancies() return True
def _check_confluence(self): return self.make_confluent(check=True)
def reduce(self, word, exclude=None): ''' Apply reduction rules to `word` excluding the reduction rule for the lhs equal to `exclude`
''' rules = {r: self.rules[r] for r in self.rules if r != exclude} # the following is essentially `eliminate_words()` code from the # `FreeGroupElement` class, the only difference being the first # "if" statement again = True new = word while again: again = False for r in rules: prev = new if rules[r]**-1 > r**-1: new = new.eliminate_word(r, rules[r], _all=True, inverse=False) else: new = new.eliminate_word(r, rules[r], _all=True) if new != prev: again = True return new
def _compute_inverse_rules(self, rules): ''' Compute the inverse rules for a given set of rules. The inverse rules are used in the automaton for word reduction.
Arguments: rules (dictionary): Rules for which the inverse rules are to computed.
Returns: Dictionary of inverse_rules.
''' inverse_rules = {} for r in rules: rule_key_inverse = r**-1 rule_value_inverse = (rules[r])**-1 if (rule_value_inverse < rule_key_inverse): inverse_rules[rule_key_inverse] = rule_value_inverse else: inverse_rules[rule_value_inverse] = rule_key_inverse return inverse_rules
def construct_automaton(self): ''' Construct the automaton based on the set of reduction rules of the system.
Automata Design: The accept states of the automaton are the proper prefixes of the left hand side of the rules. The complete left hand side of the rules are the dead states of the automaton.
''' self._add_to_automaton(self.rules)
def _add_to_automaton(self, rules): ''' Add new states and transitions to the automaton.
Summary: States corresponding to the new rules added to the system are computed and added to the automaton. Transitions in the previously added states are also modified if necessary.
Arguments: rules (dictionary) -- Dictionary of the newly added rules.
''' # Automaton variables automaton_alphabet = [] proper_prefixes = {}
# compute the inverses of all the new rules added all_rules = rules inverse_rules = self._compute_inverse_rules(all_rules) all_rules.update(inverse_rules)
# Keep track of the accept_states. accept_states = []
for rule in all_rules: # The symbols present in the new rules are the symbols to be verified at each state. # computes the automaton_alphabet, as the transitions solely depend upon the new states. automaton_alphabet += rule.letter_form_elm # Compute the proper prefixes for every rule. proper_prefixes[rule] = [] letter_word_array = list(rule.letter_form_elm) len_letter_word_array = len(letter_word_array) for i in range (1, len_letter_word_array): letter_word_array[i] = letter_word_array[i-1]*letter_word_array[i] # Add accept states. elem = letter_word_array[i-1] if elem not in self.reduction_automaton.states: self.reduction_automaton.add_state(elem, state_type='a') accept_states.append(elem) proper_prefixes[rule] = letter_word_array # Check for overlaps between dead and accept states. if rule in accept_states: self.reduction_automaton.states[rule].state_type = 'd' self.reduction_automaton.states[rule].rh_rule = all_rules[rule] accept_states.remove(rule) # Add dead states if rule not in self.reduction_automaton.states: self.reduction_automaton.add_state(rule, state_type='d', rh_rule=all_rules[rule])
automaton_alphabet = set(automaton_alphabet)
# Add new transitions for every state. for state in self.reduction_automaton.states: current_state_name = state current_state_type = self.reduction_automaton.states[state].state_type # Transitions will be modified only when suffixes of the current_state # belongs to the proper_prefixes of the new rules. # The rest are ignored if they cannot lead to a dead state after a finite number of transisitons. if current_state_type == 's': for letter in automaton_alphabet: if letter in self.reduction_automaton.states: self.reduction_automaton.states[state].add_transition(letter, letter) else: self.reduction_automaton.states[state].add_transition(letter, current_state_name) elif current_state_type == 'a': # Check if the transition to any new state in possible. for letter in automaton_alphabet: _next = current_state_name*letter while len(_next) and _next not in self.reduction_automaton.states: _next = _next.subword(1, len(_next)) if not len(_next): _next = 'start' self.reduction_automaton.states[state].add_transition(letter, _next)
# Add transitions for new states. All symbols used in the automaton are considered here. # Ignore this if `reduction_automaton.automaton_alphabet` = `automaton_alphabet`. if len(self.reduction_automaton.automaton_alphabet) != len(automaton_alphabet): for state in accept_states: current_state_name = state for letter in self.reduction_automaton.automaton_alphabet: _next = current_state_name*letter while len(_next) and _next not in self.reduction_automaton.states: _next = _next.subword(1, len(_next)) if not len(_next): _next = 'start' self.reduction_automaton.states[state].add_transition(letter, _next)
def reduce_using_automaton(self, word): ''' Reduce a word using an automaton.
Summary: All the symbols of the word are stored in an array and are given as the input to the automaton. If the automaton reaches a dead state that subword is replaced and the automaton is run from the beginning. The complete word has to be replaced when the word is read and the automaton reaches a dead state. So, this process is repeated until the word is read completely and the automaton reaches the accept state.
Arguments: word (instance of FreeGroupElement) -- Word that needs to be reduced.
''' # Modify the automaton if new rules are found. if self._new_rules: self._add_to_automaton(self._new_rules) self._new_rules = {}
flag = 1 while flag: flag = 0 current_state = self.reduction_automaton.states['start'] for i, s in enumerate(word.letter_form_elm): next_state_name = current_state.transitions[s] next_state = self.reduction_automaton.states[next_state_name] if next_state.state_type == 'd': subst = next_state.rh_rule word = word.substituted_word(i - len(next_state_name) + 1, i+1, subst) flag = 1 break current_state = next_state return word123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825from sympy.combinatorics.fp_groups import FpGroupfrom sympy.combinatorics.coset_table import (CosetTable, coset_enumeration_r, coset_enumeration_c)from sympy.combinatorics.coset_table import modified_coset_enumeration_rfrom sympy.combinatorics.free_groups import free_group
from sympy.testing.pytest import slow
"""References==========
[1] Holt, D., Eick, B., O'Brien, E."Handbook of Computational Group Theory"
[2] John J. Cannon; Lucien A. Dimino; George Havas; Jane M. WatsonMathematics of Computation, Vol. 27, No. 123. (Jul., 1973), pp. 463-490."Implementation and Analysis of the Todd-Coxeter Algorithm"
"""
def test_scan_1(): # Example 5.1 from [1] F, x, y = free_group("x, y") f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y]) c = CosetTable(f, [x])
c.scan_and_fill(0, x) assert c.table == [[0, 0, None, None]] assert c.p == [0] assert c.n == 1 assert c.omega == [0]
c.scan_and_fill(0, x**3) assert c.table == [[0, 0, None, None]] assert c.p == [0] assert c.n == 1 assert c.omega == [0]
c.scan_and_fill(0, y**3) assert c.table == [[0, 0, 1, 2], [None, None, 2, 0], [None, None, 0, 1]] assert c.p == [0, 1, 2] assert c.n == 3 assert c.omega == [0, 1, 2]
c.scan_and_fill(0, x**-1*y**-1*x*y) assert c.table == [[0, 0, 1, 2], [None, None, 2, 0], [2, 2, 0, 1]] assert c.p == [0, 1, 2] assert c.n == 3 assert c.omega == [0, 1, 2]
c.scan_and_fill(1, x**3) assert c.table == [[0, 0, 1, 2], [3, 4, 2, 0], [2, 2, 0, 1], \ [4, 1, None, None], [1, 3, None, None]] assert c.p == [0, 1, 2, 3, 4] assert c.n == 5 assert c.omega == [0, 1, 2, 3, 4]
c.scan_and_fill(1, y**3) assert c.table == [[0, 0, 1, 2], [3, 4, 2, 0], [2, 2, 0, 1], \ [4, 1, None, None], [1, 3, None, None]] assert c.p == [0, 1, 2, 3, 4] assert c.n == 5 assert c.omega == [0, 1, 2, 3, 4]
c.scan_and_fill(1, x**-1*y**-1*x*y) assert c.table == [[0, 0, 1, 2], [1, 1, 2, 0], [2, 2, 0, 1], \ [None, 1, None, None], [1, 3, None, None]] assert c.p == [0, 1, 2, 1, 1] assert c.n == 3 assert c.omega == [0, 1, 2]
# Example 5.2 from [1] f = FpGroup(F, [x**2, y**3, (x*y)**3]) c = CosetTable(f, [x*y])
c.scan_and_fill(0, x*y) assert c.table == [[1, None, None, 1], [None, 0, 0, None]] assert c.p == [0, 1] assert c.n == 2 assert c.omega == [0, 1]
c.scan_and_fill(0, x**2) assert c.table == [[1, 1, None, 1], [0, 0, 0, None]] assert c.p == [0, 1] assert c.n == 2 assert c.omega == [0, 1]
c.scan_and_fill(0, y**3) assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [None, None, 1, 0]] assert c.p == [0, 1, 2] assert c.n == 3 assert c.omega == [0, 1, 2]
c.scan_and_fill(0, (x*y)**3) assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [None, None, 1, 0]] assert c.p == [0, 1, 2] assert c.n == 3 assert c.omega == [0, 1, 2]
c.scan_and_fill(1, x**2) assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [None, None, 1, 0]] assert c.p == [0, 1, 2] assert c.n == 3 assert c.omega == [0, 1, 2]
c.scan_and_fill(1, y**3) assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [None, None, 1, 0]] assert c.p == [0, 1, 2] assert c.n == 3 assert c.omega == [0, 1, 2]
c.scan_and_fill(1, (x*y)**3) assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [3, 4, 1, 0], [None, 2, 4, None], [2, None, None, 3]] assert c.p == [0, 1, 2, 3, 4] assert c.n == 5 assert c.omega == [0, 1, 2, 3, 4]
c.scan_and_fill(2, x**2) assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [3, 3, 1, 0], [2, 2, 3, 3], [2, None, None, 3]] assert c.p == [0, 1, 2, 3, 3] assert c.n == 4 assert c.omega == [0, 1, 2, 3]
@slowdef test_coset_enumeration(): # this test function contains the combined tests for the two strategies # i.e. HLT and Felsch strategies.
# Example 5.1 from [1] F, x, y = free_group("x, y") f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y]) C_r = coset_enumeration_r(f, [x]) C_r.compress(); C_r.standardize() C_c = coset_enumeration_c(f, [x]) C_c.compress(); C_c.standardize() table1 = [[0, 0, 1, 2], [1, 1, 2, 0], [2, 2, 0, 1]] assert C_r.table == table1 assert C_c.table == table1
# E1 from [2] Pg. 474 F, r, s, t = free_group("r, s, t") E1 = FpGroup(F, [t**-1*r*t*r**-2, r**-1*s*r*s**-2, s**-1*t*s*t**-2]) C_r = coset_enumeration_r(E1, []) C_r.compress() C_c = coset_enumeration_c(E1, []) C_c.compress() table2 = [[0, 0, 0, 0, 0, 0]] assert C_r.table == table2 # test for issue #11449 assert C_c.table == table2
# Cox group from [2] Pg. 474 F, a, b = free_group("a, b") Cox = FpGroup(F, [a**6, b**6, (a*b)**2, (a**2*b**2)**2, (a**3*b**3)**5]) C_r = coset_enumeration_r(Cox, [a]) C_r.compress(); C_r.standardize() C_c = coset_enumeration_c(Cox, [a]) C_c.compress(); C_c.standardize() table3 = [[0, 0, 1, 2], [2, 3, 4, 0], [5, 1, 0, 6], [1, 7, 8, 9], [9, 10, 11, 1], [12, 2, 9, 13], [14, 9, 2, 11], [3, 12, 15, 16], [16, 17, 18, 3], [6, 4, 3, 5], [4, 19, 20, 21], [21, 22, 6, 4], [7, 5, 23, 24], [25, 23, 5, 18], [19, 6, 22, 26], [24, 27, 28, 7], [29, 8, 7, 30], [8, 31, 32, 33], [33, 34, 13, 8], [10, 14, 35, 35], [35, 36, 37, 10], [30, 11, 10, 29], [11, 38, 39, 14], [13, 39, 38, 12], [40, 15, 12, 41], [42, 13, 34, 43], [44, 35, 14, 45], [15, 46, 47, 34], [34, 48, 49, 15], [50, 16, 21, 51], [52, 21, 16, 49], [17, 50, 53, 54], [54, 55, 56, 17], [41, 18, 17, 40], [18, 28, 27, 25], [26, 20, 19, 19], [20, 57, 58, 59], [59, 60, 51, 20], [22, 52, 61, 23], [23, 62, 63, 22], [64, 24, 33, 65], [48, 33, 24, 61], [62, 25, 54, 66], [67, 54, 25, 68], [57, 26, 59, 69], [70, 59, 26, 63], [27, 64, 71, 72], [72, 73, 68, 27], [28, 41, 74, 75], [75, 76, 30, 28], [31, 29, 77, 78], [79, 77, 29, 37], [38, 30, 76, 80], [78, 81, 82, 31], [43, 32, 31, 42], [32, 83, 84, 85], [85, 86, 65, 32], [36, 44, 87, 88], [88, 89, 90, 36], [45, 37, 36, 44], [37, 82, 81, 79], [80, 74, 41, 38], [39, 42, 91, 92], [92, 93, 45, 39], [46, 40, 94, 95], [96, 94, 40, 56], [97, 91, 42, 82], [83, 43, 98, 99], [100, 98, 43, 47], [101, 87, 44, 90], [82, 45, 93, 97], [95, 102, 103, 46], [104, 47, 46, 105], [47, 106, 107, 100], [61, 108, 109, 48], [105, 49, 48, 104], [49, 110, 111, 52], [51, 111, 110, 50], [112, 53, 50, 113], [114, 51, 60, 115], [116, 61, 52, 117], [53, 118, 119, 60], [60, 70, 66, 53], [55, 67, 120, 121], [121, 122, 123, 55], [113, 56, 55, 112], [56, 103, 102, 96], [69, 124, 125, 57], [115, 58, 57, 114], [58, 126, 127, 128], [128, 128, 69, 58], [66, 129, 130, 62], [117, 63, 62, 116], [63, 125, 124, 70], [65, 109, 108, 64], [131, 71, 64, 132], [133, 65, 86, 134], [135, 66, 70, 136], [68, 130, 129, 67], [137, 120, 67, 138], [132, 68, 73, 131], [139, 69, 128, 140], [71, 141, 142, 86], [86, 143, 144, 71], [145, 72, 75, 146], [147, 75, 72, 144], [73, 145, 148, 120], [120, 149, 150, 73], [74, 151, 152, 94], [94, 153, 146, 74], [76, 147, 154, 77], [77, 155, 156, 76], [157, 78, 85, 158], [143, 85, 78, 154], [155, 79, 88, 159], [160, 88, 79, 161], [151, 80, 92, 162], [163, 92, 80, 156], [81, 157, 164, 165], [165, 166, 161, 81], [99, 107, 106, 83], [134, 84, 83, 133], [84, 167, 168, 169], [169, 170, 158, 84], [87, 171, 172, 93], [93, 163, 159, 87], [89, 160, 173, 174], [174, 175, 176, 89], [90, 90, 89, 101], [91, 177, 178, 98], [98, 179, 162, 91], [180, 95, 100, 181], [179, 100, 95, 152], [153, 96, 121, 148], [182, 121, 96, 183], [177, 97, 165, 184], [185, 165, 97, 172], [186, 99, 169, 187], [188, 169, 99, 178], [171, 101, 174, 189], [190, 174, 101, 176], [102, 180, 191, 192], [192, 193, 183, 102], [103, 113, 194, 195], [195, 196, 105, 103], [106, 104, 197, 198], [199, 197, 104, 109], [110, 105, 196, 200], [198, 201, 133, 106], [107, 186, 202, 203], [203, 204, 181, 107], [108, 116, 205, 206], [206, 207, 132, 108], [109, 133, 201, 199], [200, 194, 113, 110], [111, 114, 208, 209], [209, 210, 117, 111], [118, 112, 211, 212], [213, 211, 112, 123], [214, 208, 114, 125], [126, 115, 215, 216], [217, 215, 115, 119], [218, 205, 116, 130], [125, 117, 210, 214], [212, 219, 220, 118], [136, 119, 118, 135], [119, 221, 222, 217], [122, 182, 223, 224], [224, 225, 226, 122], [138, 123, 122, 137], [123, 220, 219, 213], [124, 139, 227, 228], [228, 229, 136, 124], [216, 222, 221, 126], [140, 127, 126, 139], [127, 230, 231, 232], [232, 233, 140, 127], [129, 135, 234, 235], [235, 236, 138, 129], [130, 132, 207, 218], [141, 131, 237, 238], [239, 237, 131, 150], [167, 134, 240, 241], [242, 240, 134, 142], [243, 234, 135, 220], [221, 136, 229, 244], [149, 137, 245, 246], [247, 245, 137, 226], [220, 138, 236, 243], [244, 227, 139, 221], [230, 140, 233, 248], [238, 249, 250, 141], [251, 142, 141, 252], [142, 253, 254, 242], [154, 255, 256, 143], [252, 144, 143, 251], [144, 257, 258, 147], [146, 258, 257, 145], [259, 148, 145, 260], [261, 146, 153, 262], [263, 154, 147, 264], [148, 265, 266, 153], [246, 267, 268, 149], [260, 150, 149, 259], [150, 250, 249, 239], [162, 269, 270, 151], [262, 152, 151, 261], [152, 271, 272, 179], [159, 273, 274, 155], [264, 156, 155, 263], [156, 270, 269, 163], [158, 256, 255, 157], [275, 164, 157, 276], [277, 158, 170, 278], [279, 159, 163, 280], [161, 274, 273, 160], [281, 173, 160, 282], [276, 161, 166, 275], [283, 162, 179, 284], [164, 285, 286, 170], [170, 188, 184, 164], [166, 185, 189, 173], [173, 287, 288, 166], [241, 254, 253, 167], [278, 168, 167, 277], [168, 289, 290, 291], [291, 292, 187, 168], [189, 293, 294, 171], [280, 172, 171, 279], [172, 295, 296, 185], [175, 190, 297, 297], [297, 298, 299, 175], [282, 176, 175, 281], [176, 294, 293, 190], [184, 296, 295, 177], [284, 178, 177, 283], [178, 300, 301, 188], [181, 272, 271, 180], [302, 191, 180, 303], [304, 181, 204, 305], [183, 266, 265, 182], [306, 223, 182, 307], [303, 183, 193, 302], [308, 184, 188, 309], [310, 189, 185, 311], [187, 301, 300, 186], [305, 202, 186, 304], [312, 187, 292, 313], [314, 297, 190, 315], [191, 316, 317, 204], [204, 318, 319, 191], [320, 192, 195, 321], [322, 195, 192, 319], [193, 320, 323, 223], [223, 324, 325, 193], [194, 326, 327, 211], [211, 328, 321, 194], [196, 322, 329, 197], [197, 330, 331, 196], [332, 198, 203, 333], [318, 203, 198, 329], [330, 199, 206, 334], [335, 206, 199, 336], [326, 200, 209, 337], [338, 209, 200, 331], [201, 332, 339, 240], [240, 340, 336, 201], [202, 341, 342, 292], [292, 343, 333, 202], [205, 344, 345, 210], [210, 338, 334, 205], [207, 335, 346, 237], [237, 347, 348, 207], [208, 349, 350, 215], [215, 351, 337, 208], [352, 212, 217, 353], [351, 217, 212, 327], [328, 213, 224, 323], [354, 224, 213, 355], [349, 214, 228, 356], [357, 228, 214, 345], [358, 216, 232, 359], [360, 232, 216, 350], [344, 218, 235, 361], [362, 235, 218, 348], [219, 352, 363, 364], [364, 365, 355, 219], [222, 358, 366, 367], [367, 368, 353, 222], [225, 354, 369, 370], [370, 371, 372, 225], [307, 226, 225, 306], [226, 268, 267, 247], [227, 373, 374, 233], [233, 360, 356, 227], [229, 357, 361, 234], [234, 375, 376, 229], [248, 231, 230, 230], [231, 377, 378, 379], [379, 380, 359, 231], [236, 362, 381, 245], [245, 382, 383, 236], [384, 238, 242, 385], [340, 242, 238, 346], [347, 239, 246, 381], [386, 246, 239, 387], [388, 241, 291, 389], [343, 291, 241, 339], [375, 243, 364, 390], [391, 364, 243, 383], [373, 244, 367, 392], [393, 367, 244, 376], [382, 247, 370, 394], [395, 370, 247, 396], [377, 248, 379, 397], [398, 379, 248, 374], [249, 384, 399, 400], [400, 401, 387, 249], [250, 260, 402, 403], [403, 404, 252, 250], [253, 251, 405, 406], [407, 405, 251, 256], [257, 252, 404, 408], [406, 409, 277, 253], [254, 388, 410, 411], [411, 412, 385, 254], [255, 263, 413, 414], [414, 415, 276, 255], [256, 277, 409, 407], [408, 402, 260, 257], [258, 261, 416, 417], [417, 418, 264, 258], [265, 259, 419, 420], [421, 419, 259, 268], [422, 416, 261, 270], [271, 262, 423, 424], [425, 423, 262, 266], [426, 413, 263, 274], [270, 264, 418, 422], [420, 427, 307, 265], [266, 303, 428, 425], [267, 386, 429, 430], [430, 431, 396, 267], [268, 307, 427, 421], [269, 283, 432, 433], [433, 434, 280, 269], [424, 428, 303, 271], [272, 304, 435, 436], [436, 437, 284, 272], [273, 279, 438, 439], [439, 440, 282, 273], [274, 276, 415, 426], [285, 275, 441, 442], [443, 441, 275, 288], [289, 278, 444, 445], [446, 444, 278, 286], [447, 438, 279, 294], [295, 280, 434, 448], [287, 281, 449, 450], [451, 449, 281, 299], [294, 282, 440, 447], [448, 432, 283, 295], [300, 284, 437, 452], [442, 453, 454, 285], [309, 286, 285, 308], [286, 455, 456, 446], [450, 457, 458, 287], [311, 288, 287, 310], [288, 454, 453, 443], [445, 456, 455, 289], [313, 290, 289, 312], [290, 459, 460, 461], [461, 462, 389, 290], [293, 310, 463, 464], [464, 465, 315, 293], [296, 308, 466, 467], [467, 468, 311, 296], [298, 314, 469, 470], [470, 471, 472, 298], [315, 299, 298, 314], [299, 458, 457, 451], [452, 435, 304, 300], [301, 312, 473, 474], [474, 475, 309, 301], [316, 302, 476, 477], [478, 476, 302, 325], [341, 305, 479, 480], [481, 479, 305, 317], [324, 306, 482, 483], [484, 482, 306, 372], [485, 466, 308, 454], [455, 309, 475, 486], [487, 463, 310, 458], [454, 311, 468, 485], [486, 473, 312, 455], [459, 313, 488, 489], [490, 488, 313, 342], [491, 469, 314, 472], [458, 315, 465, 487], [477, 492, 485, 316], [463, 317, 316, 468], [317, 487, 493, 481], [329, 447, 464, 318], [468, 319, 318, 463], [319, 467, 448, 322], [321, 448, 467, 320], [475, 323, 320, 466], [432, 321, 328, 437], [438, 329, 322, 434], [323, 474, 452, 328], [483, 494, 486, 324], [466, 325, 324, 475], [325, 485, 492, 478], [337, 422, 433, 326], [437, 327, 326, 432], [327, 436, 424, 351], [334, 426, 439, 330], [434, 331, 330, 438], [331, 433, 422, 338], [333, 464, 447, 332], [449, 339, 332, 440], [465, 333, 343, 469], [413, 334, 338, 418], [336, 439, 426, 335], [441, 346, 335, 415], [440, 336, 340, 449], [416, 337, 351, 423], [339, 451, 470, 343], [346, 443, 450, 340], [480, 493, 487, 341], [469, 342, 341, 465], [342, 491, 495, 490], [361, 407, 414, 344], [418, 345, 344, 413], [345, 417, 408, 357], [381, 446, 442, 347], [415, 348, 347, 441], [348, 414, 407, 362], [356, 408, 417, 349], [423, 350, 349, 416], [350, 425, 420, 360], [353, 424, 436, 352], [479, 363, 352, 435], [428, 353, 368, 476], [355, 452, 474, 354], [488, 369, 354, 473], [435, 355, 365, 479], [402, 356, 360, 419], [405, 361, 357, 404], [359, 420, 425, 358], [476, 366, 358, 428], [427, 359, 380, 482], [444, 381, 362, 409], [363, 481, 477, 368], [368, 393, 390, 363], [365, 391, 394, 369], [369, 490, 480, 365], [366, 478, 483, 380], [380, 398, 392, 366], [371, 395, 496, 497], [497, 498, 489, 371], [473, 372, 371, 488], [372, 486, 494, 484], [392, 400, 403, 373], [419, 374, 373, 402], [374, 421, 430, 398], [390, 411, 406, 375], [404, 376, 375, 405], [376, 403, 400, 393], [397, 430, 421, 377], [482, 378, 377, 427], [378, 484, 497, 499], [499, 499, 397, 378], [394, 461, 445, 382], [409, 383, 382, 444], [383, 406, 411, 391], [385, 450, 443, 384], [492, 399, 384, 453], [457, 385, 412, 493], [387, 442, 446, 386], [494, 429, 386, 456], [453, 387, 401, 492], [389, 470, 451, 388], [493, 410, 388, 457], [471, 389, 462, 495], [412, 390, 393, 399], [462, 394, 391, 410], [401, 392, 398, 429], [396, 445, 461, 395], [498, 496, 395, 460], [456, 396, 431, 494], [431, 397, 499, 496], [399, 477, 481, 412], [429, 483, 478, 401], [410, 480, 490, 462], [496, 497, 484, 431], [489, 495, 491, 459], [495, 460, 459, 471], [460, 489, 498, 498], [472, 472, 471, 491]]
assert C_r.table == table3 assert C_c.table == table3
# Group denoted by B2,4 from [2] Pg. 474 F, a, b = free_group("a, b") B_2_4 = FpGroup(F, [a**4, b**4, (a*b)**4, (a**-1*b)**4, (a**2*b)**4, \ (a*b**2)**4, (a**2*b**2)**4, (a**-1*b*a*b)**4, (a*b**-1*a*b)**4]) C_r = coset_enumeration_r(B_2_4, [a]) C_c = coset_enumeration_c(B_2_4, [a]) index_r = 0 for i in range(len(C_r.p)): if C_r.p[i] == i: index_r += 1 assert index_r == 1024
index_c = 0 for i in range(len(C_c.p)): if C_c.p[i] == i: index_c += 1 assert index_c == 1024
# trivial Macdonald group G(2,2) from [2] Pg. 480 M = FpGroup(F, [b**-1*a**-1*b*a*b**-1*a*b*a**-2, a**-1*b**-1*a*b*a**-1*b*a*b**-2]) C_r = coset_enumeration_r(M, [a]) C_r.compress(); C_r.standardize() C_c = coset_enumeration_c(M, [a]) C_c.compress(); C_c.standardize() table4 = [[0, 0, 0, 0]] assert C_r.table == table4 assert C_c.table == table4
def test_look_ahead(): # Section 3.2 [Test Example] Example (d) from [2] F, a, b, c = free_group("a, b, c") f = FpGroup(F, [a**11, b**5, c**4, (a*c)**3, b**2*c**-1*b**-1*c, a**4*b**-1*a**-1*b]) H = [c, b, c**2] table0 = [[1, 2, 0, 0, 0, 0], [3, 0, 4, 5, 6, 7], [0, 8, 9, 10, 11, 12], [5, 1, 10, 13, 14, 15], [16, 5, 16, 1, 17, 18], [4, 3, 1, 8, 19, 20], [12, 21, 22, 23, 24, 1], [25, 26, 27, 28, 1, 24], [2, 10, 5, 16, 22, 28], [10, 13, 13, 2, 29, 30]] CosetTable.max_stack_size = 10 C_c = coset_enumeration_c(f, H) C_c.compress(); C_c.standardize() assert C_c.table[: 10] == table0
def test_modified_methods(): ''' Tests for modified coset table methods. Example 5.7 from [1] Holt, D., Eick, B., O'Brien "Handbook of Computational Group Theory".
''' F, x, y = free_group("x, y") f = FpGroup(F, [x**3, y**5, (x*y)**2]) H = [x*y, x**-1*y**-1*x*y*x] C = CosetTable(f, H) C.modified_define(0, x) identity = C._grp.identity a_0 = C._grp.generators[0] a_1 = C._grp.generators[1]
assert C.P == [[identity, None, None, None], [None, identity, None, None]] assert C.table == [[1, None, None, None], [None, 0, None, None]]
C.modified_define(1, x) assert C.table == [[1, None, None, None], [2, 0, None, None], [None, 1, None, None]] assert C.P == [[identity, None, None, None], [identity, identity, None, None], [None, identity, None, None]]
C.modified_scan(0, x**3, C._grp.identity, fill=False) assert C.P == [[identity, identity, None, None], [identity, identity, None, None], [identity, identity, None, None]] assert C.table == [[1, 2, None, None], [2, 0, None, None], [0, 1, None, None]]
C.modified_scan(0, x*y, C._grp.generators[0], fill=False) assert C.P == [[identity, identity, None, a_0**-1], [identity, identity, a_0, None], [identity, identity, None, None]] assert C.table == [[1, 2, None, 1], [2, 0, 0, None], [0, 1, None, None]]
C.modified_define(2, y**-1) assert C.table == [[1, 2, None, 1], [2, 0, 0, None], [0, 1, None, 3], [None, None, 2, None]] assert C.P == [[identity, identity, None, a_0**-1], [identity, identity, a_0, None], [identity, identity, None, identity], [None, None, identity, None]]
C.modified_scan(0, x**-1*y**-1*x*y*x, C._grp.generators[1]) assert C.table == [[1, 2, None, 1], [2, 0, 0, None], [0, 1, None, 3], [3, 3, 2, None]] assert C.P == [[identity, identity, None, a_0**-1], [identity, identity, a_0, None], [identity, identity, None, identity], [a_1, a_1**-1, identity, None]]
C.modified_scan(2, (x*y)**2, C._grp.identity) assert C.table == [[1, 2, 3, 1], [2, 0, 0, None], [0, 1, None, 3], [3, 3, 2, 0]] assert C.P == [[identity, identity, a_1**-1, a_0**-1], [identity, identity, a_0, None], [identity, identity, None, identity], [a_1, a_1**-1, identity, a_1]]
C.modified_define(2, y) assert C.table == [[1, 2, 3, 1], [2, 0, 0, None], [0, 1, 4, 3], [3, 3, 2, 0], [None, None, None, 2]] assert C.P == [[identity, identity, a_1**-1, a_0**-1], [identity, identity, a_0, None], [identity, identity, identity, identity], [a_1, a_1**-1, identity, a_1], [None, None, None, identity]]
C.modified_scan(0, y**5, C._grp.identity) assert C.table == [[1, 2, 3, 1], [2, 0, 0, 4], [0, 1, 4, 3], [3, 3, 2, 0], [None, None, 1, 2]] assert C.P == [[identity, identity, a_1**-1, a_0**-1], [identity, identity, a_0, a_0*a_1**-1], [identity, identity, identity, identity], [a_1, a_1**-1, identity, a_1], [None, None, a_1*a_0**-1, identity]]
C.modified_scan(1, (x*y)**2, C._grp.identity) assert C.table == [[1, 2, 3, 1], [2, 0, 0, 4], [0, 1, 4, 3], [3, 3, 2, 0], [4, 4, 1, 2]] assert C.P == [[identity, identity, a_1**-1, a_0**-1], [identity, identity, a_0, a_0*a_1**-1], [identity, identity, identity, identity], [a_1, a_1**-1, identity, a_1], [a_0*a_1**-1, a_1*a_0**-1, a_1*a_0**-1, identity]]
# Modified coset enumeration test f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y]) C = coset_enumeration_r(f, [x]) C_m = modified_coset_enumeration_r(f, [x]) assert C_m.table == C.tablelib/python3.12/site-packages/sympy/combinatorics/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/coset_table.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/fp_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/free_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/galois.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/generators.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/graycode.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/group_constructs.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/group_numbers.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/homomorphisms.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/named_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/partitions.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/pc_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/polyhedron.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/prufer.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/rewritingsystem.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/rewritingsystem_fsm.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/schur_number.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/subsets.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/tensor_can.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/testutil.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/__pycache__/util.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/group_numbers.pyAdded+296
lib/python3.12/site-packages/sympy/combinatorics/partitions.pyAdded+745
lib/python3.12/site-packages/sympy/combinatorics/rewritingsystem.pyAdded+453
lib/python3.12/site-packages/sympy/combinatorics/tests/__init__.pyAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_coset_table.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_fp_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_free_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_galois.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_generators.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_graycode.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_group_constructs.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_group_numbers.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_homomorphisms.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_named_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_partitions.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_pc_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_perm_groups.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_permutations.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_polyhedron.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_prufer.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_rewriting.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_schur_number.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_subsets.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_tensor_can.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_testutil.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/__pycache__/test_util.cpython-312.pycAdded
lib/python3.12/site-packages/sympy/combinatorics/tests/test_coset_table.pyAdded+825