Navigation

Source code for sympy.combinatorics.util

fromsympy.ntheoryimportisprimefromsympy.combinatorics.permutationsimportPermutation,_af_invert,_af_rmulrmul=Permutation.rmul_af_new=Permutation._af_new################################################## Utilities for computational group theory###############################################

[docs]def_base_ordering(base,degree):r""" Order `\{0, 1, ..., n-1\}` so that base points come first and in order. Parameters ========== ``base`` - the base ``degree`` - the degree of the associated permutation group Returns ======= A list ``base_ordering`` such that ``base_ordering[point]`` is the number of ``point`` in the ordering. Examples ======== >>> from sympy.combinatorics.named_groups import SymmetricGroup >>> from sympy.combinatorics.util import _base_ordering >>> S = SymmetricGroup(4) >>> S.schreier_sims() >>> _base_ordering(S.base, S.degree) [0, 1, 2, 3] Notes ===== This is used in backtrack searches, when we define a relation `<<` on the underlying set for a permutation group of degree `n`, `\{0, 1, ..., n-1\}`, so that if `(b_1, b_2, ..., b_k)` is a base we have `b_i << b_j` whenever `i<j` and `b_i << a` for all `i\in\{1,2, ..., k\}` and `a` is not in the base. The idea is developed and applied to backtracking algorithms in [1], pp.108-132. The points that are not in the base are taken in increasing order. References ========== [1] Holt, D., Eick, B., O'Brien, E. "Handbook of computational group theory" """base_len=len(base)ordering=[0]*degreeforiinrange(base_len):ordering[base[i]]=icurrent=base_lenforiinrange(degree):ifinotinbase:ordering[i]=currentcurrent+=1returnordering

[docs]def_strip(g,base,orbits,transversals):""" Attempt to decompose a permutation using a (possibly partial) BSGS structure. This is done by treating the sequence ``base`` as an actual base, and the orbits ``orbits`` and transversals ``transversals`` as basic orbits and transversals relative to it. This process is called "sifting". A sift is unsuccessful when a certain orbit element is not found or when after the sift the decomposition doesn't end with the identity element. The argument ``transversals`` is a list of dictionaries that provides transversal elements for the orbits ``orbits``. Parameters ========== ``g`` - permutation to be decomposed ``base`` - sequence of points ``orbits`` - a list in which the ``i``-th entry is an orbit of ``base[i]`` under some subgroup of the pointwise stabilizer of ` `base[0], base[1], ..., base[i - 1]``. The groups themselves are implicit in this function since the only infromation we need is encoded in the orbits and transversals ``transversals`` - a list of orbit transversals associated with the orbits ``orbits``. Examples ======== >>> from sympy.combinatorics import Permutation >>> Permutation.print_cyclic = True >>> from sympy.combinatorics.named_groups import SymmetricGroup >>> from sympy.combinatorics.permutations import Permutation >>> from sympy.combinatorics.util import _strip >>> S = SymmetricGroup(5) >>> S.schreier_sims() >>> g = Permutation([0, 2, 3, 1, 4]) >>> _strip(g, S.base, S.basic_orbits, S.basic_transversals) (Permutation(4), 5) Notes ===== The algorithm is described in [1],pp.89-90. The reason for returning both the current state of the element being decomposed and the level at which the sifting ends is that they provide important information for the randomized version of the Schreier-Sims algorithm. References ========== [1] Holt, D., Eick, B., O'Brien, E. "Handbook of computational group theory" See Also ======== sympy.combinatorics.perm_groups.PermutationGroup.schreier_sims sympy.combinatorics.perm_groups.PermutationGroup.schreier_sims_random """h=g.array_formbase_len=len(base)foriinrange(base_len):beta=h[base[i]]ifbeta==base[i]:continueifbetanotinorbits[i]:return_af_new(h),i+1u=transversals[i][beta].array_formh=_af_rmul(_af_invert(u),h)return_af_new(h),base_len+1