Ticket #8500: trac_8500_number_transitive_group-nb.patch

File trac_8500_number_transitive_group-nb.patch, 11.0 KB (added by nborie, 12 years ago)
  • sage/groups/perm_gps/all.py

    # HG changeset patch
    # User Nicolas Borie <nicolas.borie at math.u-psud.fr>
    # Date 1268665182 -3600
    # Node ID 967f7b075e27d4d1b7786c65e7fdcff746d638f5
    # Parent  9128d3194877c1b7121475b5a5ad520aab47f241
    #8500 Add the enumerated set of TransitiveGroups
    
    
    diff -r 9128d3194877 -r 967f7b075e27 sage/groups/perm_gps/all.py
    a b  
    55                       DihedralGroup, CyclicPermutationGroup,
    66                       DiCyclicGroup, TransitiveGroup, PGL, PSL, PSp,PSU,PGU,
    77                       MathieuGroup, KleinFourGroup, QuaternionGroup,
    8                        SuzukiGroup)
     8                       SuzukiGroup, TransitiveGroups)
    99
    1010from permgroup import  PermutationGroup, PermutationGroup_generic, PermutationGroup_subgroup, direct_product_permgroups
    1111
  • sage/groups/perm_gps/permgroup_named.py

    diff -r 9128d3194877 -r 967f7b075e27 sage/groups/perm_gps/permgroup_named.py
    a b  
    7878from sage.groups.perm_gps.permgroup import PermutationGroup_generic
    7979from sage.groups.perm_gps.permgroup_element import PermutationGroupElement
    8080from sage.structure.unique_representation import UniqueRepresentation
     81from sage.structure.parent import Parent
     82from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
     83from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
     84from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
     85from sage.sets.non_negative_integers import NonNegativeIntegers
     86from sage.sets.family import Family
    8187
    8288class PermutationGroup_unique(UniqueRepresentation, PermutationGroup_generic):
    8389
     
    867873            Category of finite permutation groups
    868874            sage: TestSuite(G).run()
    869875        """
    870         id = 'Group([()])' if d == 1 else 'TransitiveGroup(%s,%s)'%(d,n)
     876        id = 'Group([()])' if d in [0,1] else 'TransitiveGroup(%s,%s)'%(d,n)
    871877        try:
    872878            PermutationGroup_generic.__init__(self, gap_group=id)
    873879        except RuntimeError:
     
    885891        """
    886892        return "Transitive group number %s of degree %s"%(self._n, self._d)
    887893
     894def number_of_transitive_groups(degree):
     895    """
     896    Returns the number of transitive groups of a given ``degree``.
     897    As in Gap, transitive groups of degree `n` are indexed from 1 to
     898    number_of_transitive_groups(n).
     899
     900    The database_gap contains all transitive groups up to degree 30.
     901
     902    EXAMPLES::
     903
     904        sage: from sage.groups.perm_gps.permgroup_named import number_of_transitive_groups
     905        sage: k = number_of_transitive_groups(12); k                # requires optional database_gap
     906        301
     907        sage: type(k)                                               # requires optional database_gap
     908        <type 'sage.rings.integer.Integer'>
     909        sage: [number_of_transitive_groups(Integer(i)) for i in range(11)] # requires optional database_gap
     910        [1, 1, 1, 2, 5, 5, 16, 7, 50, 34, 45]
     911        sage: for i in range(number_of_transitive_groups(5)):       # requires optional database_gap
     912        ...       print TransitiveGroup(6,i+1).cardinality()
     913        6
     914        6
     915        12
     916        12
     917        18
     918    """
     919    if (not isinstance(degree, Integer)) or degree < 0:
     920        raise ValueError("A transitive group acts on a non negative integer number of positions")
     921    if degree == 0: # gap.NrTransitiveGroups(0) --> fail : This ligne can't be removed.
     922        return 1
     923    if degree > 30:
     924        raise NotImplementedError
     925    else:
     926        try:
     927            G = PermutationGroup_generic(gap_group='TransitiveGroup(2,1)')
     928            return Integer(gap.NrTransitiveGroups(gap(degree)))
     929        except RuntimeError:
     930            from sage.misc.misc import verbose
     931            verbose("Warning: Computing with TransitiveGroups requires the optional database_gap package. Please install it.", level=0)
     932
     933def TransitiveGroups(n=None):
     934    """
     935    Returns the set of transitive groups of a given degree ``n`` if
     936    specified, it returns the set of all transitive groups up to
     937    degree 30 otherwise.
     938
     939    Warning: Computing with TransitiveGroups requires the optional
     940    database_gap package. Please install it.
     941
     942    EXAMPLES::
     943   
     944        sage: from sage.groups.perm_gps.permgroup_named import number_of_transitive_groups
     945        sage: TransitiveGroups(3) # requires optional database_gap
     946        Transitive Groups of degree 3
     947        sage: TransitiveGroups(7) # requires optional database_gap
     948        Transitive Groups of degree 7
     949        sage: TransitiveGroups(8) # requires optional database_gap
     950        Transitive Groups of degree 8
     951       
     952    If no degree is specified, it Returns the complete database which
     953    contains all transitive groups up to degree 30::
     954
     955        sage: TransitiveGroups() # requires optional database_gap
     956        Transitive Groups
     957    """
     958#    tests of the file takes [234.0 s] on a macbook(2009) with the following check
     959#    if any(['database_gap' == p.split("-")[0] for p in optional_packages()[0]]):
     960#    instead of [59.8 s] for the hard coded following check over an optional
     961#    object
     962    try:
     963        G = PermutationGroup_generic(gap_group='TransitiveGroup(2,1)')
     964    except RuntimeError:
     965        from sage.misc.misc import verbose
     966        verbose("Warning: Computing with TransitiveGroups requires the optional database_gap package. Please install it.", level=0)       
     967
     968    if n == None:
     969        return TransitiveGroupsAll()
     970    else:
     971        if (not isinstance(n, Integer)) or n < 0:
     972            raise ValueError("A transitive group acts on a non negative integer number of positions")
     973        if n < 31:
     974            return TransitiveGroupsOfDegree(n)
     975        else:
     976            raise NotImplementedError
     977
     978
     979class TransitiveGroupsAll(DisjointUnionEnumeratedSets):
     980    """
     981    The finite set of all transitive groups.
     982
     983    EXAMPLES::
     984
     985        sage: L = TransitiveGroups(); L # requires optional database_gap
     986        Transitive Groups
     987        sage: L.cardinality() # requires optional database_gap
     988        +Infinity
     989        sage: p = L.__iter__() # requires optional database_gap
     990        sage: (p.next(), p.next(), p.next(), p.next(), p.next(), p.next(), p.next(), p.next()) # requires optional database_gap
     991        (Transitive group number 1 of degree 0, Transitive group number 1 of degree 1, Transitive group number 1 of degree 2, Transitive group number 1 of degree 3, Transitive group number 2 of degree 3, Transitive group number 1 of degree 4, Transitive group number 2 of degree 4, Transitive group number 3 of degree 4)
     992
     993    TESTS::
     994
     995        sage: TestSuite(TransitiveGroups()).run() # requires optional database_gap # long time
     996    """
     997    def __init__(self):
     998        """
     999        TESTS::
     1000
     1001            sage: S = TransitiveGroups() # requires optional database_gap
     1002            sage: S.category() # requires optional database_gap
     1003            Category of infinite enumerated sets
     1004        """
     1005        DisjointUnionEnumeratedSets.__init__(self, Family(NonNegativeIntegers(), lambda i: TransitiveGroups(i)) )
     1006
     1007    def __repr__(self):
     1008        """
     1009        TESTS::
     1010
     1011            sage: TransitiveGroups() # requires optional database_gap
     1012            Transitive Groups
     1013        """
     1014        return "Transitive Groups"
     1015
     1016    def __contains__(self, G):
     1017        r"""
     1018        EXAMPLES::
     1019
     1020            sage: TransitiveGroup(5,2) in TransitiveGroups() # requires optional database_gap
     1021            True
     1022            sage: TransitiveGroup(6,5) in TransitiveGroups() # requires optional database_gap
     1023            True
     1024        """
     1025        return isinstance(G,TransitiveGroup)
     1026
     1027    def _an_element_(self):
     1028        """
     1029        Returns an element of ``self``.
     1030
     1031        EXAMPLES::
     1032
     1033            sage: TransitiveGroups(5)._an_element_() # requires optional database_gap
     1034            Transitive group number 1 of degree 5
     1035        """
     1036        return TransitiveGroup(7,3)
     1037
     1038class TransitiveGroupsOfDegree(UniqueRepresentation, Parent):
     1039    """
     1040    The Set of Transitive Groups of a given small degree.
     1041
     1042    EXAMPLES::
     1043
     1044        sage: S = TransitiveGroups(4); S # requires optional database_gap
     1045        Transitive Groups of degree 4
     1046        sage: list(S) # requires optional database_gap
     1047        [Transitive group number 1 of degree 4, Transitive group number 2 of degree 4, Transitive group number 3 of degree 4, Transitive group number 4 of degree 4, Transitive group number 5 of degree 4]
     1048
     1049    TEST::
     1050   
     1051        sage: TestSuite(TransitiveGroups(6)).run() # requires optional database_gap # long time
     1052    """
     1053    def __init__(self, n):
     1054        """
     1055        TESTS::
     1056
     1057            sage: S = TransitiveGroups(4) # requires optional database_gap
     1058            sage: S.category() # requires optional database_gap
     1059            Category of finite enumerated sets
     1060        """
     1061        self._degree = n
     1062        Parent.__init__(self, category = FiniteEnumeratedSets())
     1063
     1064    def __repr__(self):
     1065        """
     1066        TESTS::
     1067
     1068            sage: TransitiveGroups(6) # requires optional database_gap
     1069            Transitive Groups of degree 6
     1070        """
     1071        return "Transitive Groups of degree %s"%(self._degree)
     1072
     1073    def __contains__(self, G):
     1074        r"""
     1075        EXAMPLES::
     1076
     1077            sage: TransitiveGroup(6,5) in TransitiveGroups(4) # requires optional database_gap
     1078            False
     1079            sage: TransitiveGroup(4,3) in TransitiveGroups(4) # requires optional database_gap
     1080            True
     1081        """
     1082        if isinstance(G,TransitiveGroup):
     1083            return G._d == self._degree
     1084        else:
     1085            False
     1086
     1087    def _an_element_(self):
     1088        """
     1089        Returns an element of ``self``.
     1090
     1091        EXAMPLES::
     1092
     1093            sage: TransitiveGroups(5)._an_element_() # requires optional database_gap
     1094            Transitive group number 1 of degree 5
     1095        """
     1096        return TransitiveGroup(self._degree,1)
     1097
     1098    def __iter__(self):
     1099        """
     1100        EXAMPLES::
     1101
     1102            sage: list(TransitiveGroups(5)) # indirect doctest # requires optional database_gap
     1103            [Transitive group number 1 of degree 5, Transitive group number 2 of degree 5, Transitive group number 3 of degree 5, Transitive group number 4 of degree 5, Transitive group number 5 of degree 5]
     1104        """
     1105        for i in range(1,number_of_transitive_groups(self._degree)+1):
     1106            yield TransitiveGroup(self._degree,i)
     1107
     1108    def cardinality(self):
     1109        """
     1110        Returns the cardinality of ``self``.
     1111
     1112        EXAMPLES::
     1113       
     1114            sage: TransitiveGroups(2).cardinality() # requires optional database_gap
     1115            1
     1116            sage: TransitiveGroups(7).cardinality() # requires optional database_gap
     1117            7
     1118            sage: TransitiveGroups(12).cardinality() # requires optional database_gap
     1119            301
     1120        """
     1121        return number_of_transitive_groups(self._degree)
     1122
    8881123class PermutationGroup_plg(PermutationGroup_unique):
    8891124    def base_ring(self):
    8901125        """