Ticket #10976: trac_10976.patch

File trac_10976.patch, 2.8 KB (added by was, 9 years ago)

renamed to standard format for patch names

  • sage/groups/perm_gps/permgroup.py

    diff --git a/sage/groups/perm_gps/permgroup.py b/sage/groups/perm_gps/permgroup.py
    a b  
    9090
    9191- Nicolas Borie (2009): Added orbit, transversals, stabiliser and strong_generating_system methods
    9292
     93- Christopher Swenson (2011): Added a special case to compute the order efficiently.
     94  (This patch Copyright 2012 Google Inc. All Rights Reserved. )
     95
    9396REFERENCES:
    9497
    9598- Cameron, P., Permutation Groups. New York: Cambridge University
     
    132135from sage.misc.package import is_package_installed
    133136from sage.sets.finite_enumerated_set import FiniteEnumeratedSet
    134137from sage.categories.all import FiniteEnumeratedSets
     138from sage.functions.other import factorial
    135139
    136140def load_hap():
    137141    """
     
    12891293        return '\\langle ' + \
    12901294               ', '.join([x._latex_() for x in self.gens()]) + ' \\rangle'
    12911295
     1296    def _order(self):
     1297        """
     1298        This handles a few special cases of computing the subgroup order much
     1299        faster than GAP.
     1300
     1301        This currently operates very quickly for stabilizer subgroups of
     1302        permutation groups, for one.
     1303
     1304        Will return None if the we could not easily compute it.
     1305
     1306        Author: Christopher Swenson
     1307
     1308        EXAMPLES::
     1309
     1310            sage: SymmetricGroup(10).stabilizer(4)._order()
     1311            362880
     1312            sage: SymmetricGroup(10).stabilizer(4).stabilizer(5)._order()
     1313            40320
     1314            sage: SymmetricGroup(200).stabilizer(100)._order() == factorial(199)  # this should be very fast
     1315            True
     1316        """
     1317        gens = self.gens()
     1318        # only work with more than 1 generator
     1319        if not gens or len(gens) < 2:
     1320          return None
     1321        # check for a wheel-spoke graph, i.e., all generators
     1322        # have a length of 2, and they all share a vertex
     1323        for g in gens:
     1324          if g.order() != 2:
     1325            return None
     1326        # find the common vertex
     1327        g0 = gens[0].cycle_tuples()[0]
     1328        g1 = gens[1].cycle_tuples()[0]
     1329        a, b = g0
     1330        if a not in g1 and b not in g1:
     1331          return None
     1332        if a in g1:
     1333          elem = a
     1334        else:
     1335          elem = b
     1336        # count the elements in the wheel
     1337        unique = set()
     1338        for g in gens:
     1339          a, b = g.cycle_tuples()[0]
     1340          if a != elem and b != elem:
     1341            return None
     1342          unique.add(a)
     1343          unique.add(b)
     1344        return factorial(len(unique))
     1345
    12921346    def order(self):
    12931347        """
    12941348        Return the number of elements of this group.
     
    13071361        """
    13081362        if not self.gens() or self.gens() == [self(1)]:
    13091363            return Integer(1)
     1364        subgroup_order = self._order()
     1365        if subgroup_order is not None:
     1366          return subgroup_order
    13101367        return Integer(self._gap_().Size())
    13111368
    13121369    def random_element(self):