Permalink
Browse files

Removed list_lex_by_base and related tests/references.

The function list_lex_by_base served as a stepping stone in
my understanding of more complex backtracking routines, so
I'm removing it now. There are other (and faster) functions
that list all group elements.
  • Loading branch information...
1 parent c9f9808 commit 547b393852a3ca6a94c9f8995b943f18a732250c Aleksandar Makelov committed Jul 26, 2012
Showing with 0 additions and 137 deletions.
  1. +0 −120 sympy/combinatorics/perm_groups.py
  2. +0 −12 sympy/combinatorics/tests/test_perm_groups.py
  3. +0 −5 sympy/combinatorics/util.py
@@ -2260,126 +2260,6 @@ def schreier_sims_random(self, base=None, gens=None, consec_succ=10,\
strong_gens.append(gen)
return base, strong_gens
- def list_lex_by_base(self, base, strong_gens, transversals=None,\
- basic_orbits=None, distr_gens=None):
- """
- List all group elements in increasing order of base images.
-
- For a group `G` with a base `(b_1, b_2, ..., b_k)`, the element `g`
- precedes the element `h` in the order of base images if
- `(g(b_1), g(b_2), ..., g(b_k))` precedes
- `(h(b_1), h(b_2), ..., h(b_k))` in the lexicographical ordering of
- `\{0, 1, ..., n-1\}` induced by the base (i.e., base points come first
- and in order, and non-base points come after that and in the usual
- ordering).
-
- Parameters
- ==========
-
- ``base``, ``strong_gens`` - the base and strong generating set
- ``transversals`` - transversals for the basic orbits, if known
- ``basic_orbits`` - basic orbits, if known
- ``distr_gens`` - strong generators distributed by basic stabilizers,
- if known
-
- Examples
- ========
-
- >>> from sympy.combinatorics.named_groups import SymmetricGroup
- >>> S = SymmetricGroup(3)
- >>> S.schreier_sims()
- >>> S.list_lex_by_base(S.base, S.strong_gens)
- [Permutation([0, 1, 2]), Permutation([0, 2, 1]),\
- Permutation([1, 0, 2]), Permutation([1, 2, 0]),\
- Permutation([2, 0, 1]), Permutation([2, 1, 0])]
-
- >>> S.base
- [0, 1]
-
- Notes
- =====
-
- This is a depth-first search visiting all group elements. Printing is
- done once the current group elements is fully constructed from the
- transversal elements found from the base and strong generating sets.
- This basic way of traversing the group is used in backtracking
- algorithms in order to "prune" the search tree by testing partial
- base images for certain properties and thus avoid visiting large
- numbers of group elements. The algorithm and possible implementations
- are discussed in [1],pp.110-111. For a group `G` with a base
- `(b_1, b_2, ..., b_k)`, the current solution for storing the
- partial decomposition `u_1u_2...u_l` for `l < k` of a group element
- `g = u_1u_2...u_k` is to keep an array the `l`-th entry of which
- is `u_1u_2...u_l` and update it accordingly.
-
- See Also
- ========
-
- _base_ordering from sympy.combinatorics.util
-
- """
- result = []
- degree = self.degree
- # order the points in range(degree) according to the base
- base_ordering = _base_ordering(base, degree)
- # construct the basic orbits, generators for the stabilizer chain
- # and transversal elements from whatever was provided
- transversals, basic_orbits, distr_gens =\
- _handle_precomputed_bsgs(base, strong_gens, transversals,\
- basic_orbits, distr_gens)
- # initialize sorted orbits
- base_len = len(base)
- c = [0]*base_len
- u = [None]*base_len
- sorted_orbits = [None]*base_len
- u[0] = _new_from_array_form(range(degree))
- # sort the first basic orbit according to the base ordering
- sorted_orbits[0] = basic_orbits[0][:]
- sorted_orbits[0].sort(key = lambda point: base_ordering[point])
- # set the depth of the search
- depth = 0
- computed_words = [0]*base_len
- computed_words[0] = u[0]
- # depth-first search
- while True:
- # in this loop, initialize the new branches of the search tree
- while depth < base_len - 1:
- depth += 1
- g = computed_words[depth - 1]
- orb_image = [g(point) for point in basic_orbits[depth]]
- # order the orbit image according to the base ordering
- orb_image.sort(key = lambda point: base_ordering[point])
- sorted_orbits[depth] = orb_image
- # now set the transversal element so that the image of
- # base[depth] under u[0]*...*u[l] is smallest in the base
- # ordering
- c[depth] = 0
- g_inverse = ~g
- gamma = g_inverse(sorted_orbits[depth][c[depth]])
- u[depth] = transversals[depth][gamma]
- computed_words[depth] = computed_words[depth - 1]*u[depth]
- # append whatever we have at depth = base_len-1 to the result
- output = computed_words[base_len - 1]
- result.append(output)
- # go up the tree to the first branch that is not searched entirely
- while depth >= 0 and c[depth] + 1 == len(basic_orbits[depth]):
- depth -= 1
- if depth == -1:
- return result
- # find the next element in the ordering
- c[depth] += 1
- if depth == 0:
- g = _new_from_array_form(range(degree))
- else:
- g = computed_words[depth - 1]
- g_inverse = ~g
- gamma = g_inverse(sorted_orbits[depth][c[depth]])
- u[depth] = transversals[depth][gamma]
- if depth == 0:
- computed_words[depth] = u[depth]
- else:
- computed_words[depth] = computed_words[depth - 1]*u[depth]
-
def baseswap(self, base, strong_gens, pos, randomized=True,\
transversals=None, basic_orbits=None, distr_gens=None):
r"""
@@ -337,18 +337,6 @@ def test_transitivity_degree():
Alt = PermutationGroup([gen1, gen2])
assert Alt.transitivity_degree == 3
-def test_list_lex_by_base():
- D = DihedralGroup(6)
- D.schreier_sims()
- assert D.base == [0, 1]
- assert D.list_lex_by_base(D.base, D.strong_gens) ==\
- [Permutation([0, 1, 2, 3, 4, 5]), Permutation([0, 5, 4, 3, 2, 1]),\
- Permutation([1, 0, 5, 4, 3, 2]), Permutation([1, 2, 3, 4, 5, 0]),\
- Permutation([2, 1, 0, 5, 4, 3]), Permutation([2, 3, 4, 5, 0, 1]),\
- Permutation([3, 2, 1, 0, 5, 4]), Permutation([3, 4, 5, 0, 1, 2]),\
- Permutation([4, 3, 2, 1, 0, 5]), Permutation([4, 5, 0, 1, 2, 3]),\
- Permutation([5, 0, 1, 2, 3, 4]), Permutation([5, 4, 3, 2, 1, 0])]
-
def test_schreier_sims_random():
S = SymmetricGroup(3)
base = [0, 1]
@@ -304,11 +304,6 @@ def _base_ordering(base, degree):
and applied to backtracking algorithms in [1], pp.108-132. The points
that are not in the base are taken in increasing order.
- See Also
- ========
-
- sympy.combinatorics.perm_groups.PermutationGroup.list_lex_by_base
-
References
==========

0 comments on commit 547b393

Please sign in to comment.