Ticket #14291: trac_14291_reviewer.patch

File trac_14291_reviewer.patch, 8.4 KB (added by vbraun, 8 years ago)

Updated patch

  • sage/groups/perm_gps/permgroup.py

    # HG changeset patch
    # User Volker Braun <vbraun.name@gmail.com>
    # Date 1365762218 -3600
    # Node ID 60b480bfb8d32b38e0f17d7e06d619953b8c3639
    # Parent  6050396d786a0f8baa22e442fde495d6adae1b98
    Reviewer patch to make things more beautiful
    
    diff --git a/sage/groups/perm_gps/permgroup.py b/sage/groups/perm_gps/permgroup.py
    a b  
    10671067                self._gap_().Orbits(self._domain_gap()).sage()]
    10681068
    10691069    @cached_method
    1070     def orbit(self, point, action = "OnPoints"):
     1070    def orbit(self, point, action="OnPoints"):
    10711071        """
    10721072        Return the orbit of a point under a group action.
    10731073
     
    10761076        - ``point`` -- can be a point or any of the list above, depending on the
    10771077          action to be considered.
    10781078
    1079         - ``action`` (string) -- if ``point`` is an element from the domain, a
     1079        - ``action`` -- string. if ``point`` is an element from the domain, a
    10801080          tuple of elements of the domain, a tuple of tuples [...], this
    10811081          variable describes how the group is acting.
    10821082
    1083           The actions currently available through this method are "OnPoints",
    1084           "OnTuples", "OnSets", "OnPairs", "OnSetsSets", "OnSetsDisjointSets",
    1085           "OnSetsTuples", "OnTuplesSets", "OnTuplesTuples". They are taken from
    1086           GAP's list `http://www.gap-system.org/Manuals/doc/ref/chap41.html`_.
     1083          The actions currently available through this method are
     1084          ``"OnPoints"``, ``"OnTuples"``, ``"OnSets"``, ``"OnPairs"``,
     1085          ``"OnSetsSets"``, ``"OnSetsDisjointSets"``,
     1086          ``"OnSetsTuples"``, ``"OnTuplesSets"``,
     1087          ``"OnTuplesTuples"``. They are taken from GAP's list of
     1088          group actions, see ``gap.help('Group Actions')``.
    10871089
    10881090          It is set to ``"OnPoints"`` by default. See below for examples.
    10891091
     1092        OUTPUT:
     1093
     1094        The orbit of ``point`` as a tuple. Each entry is an image
     1095        under the action of the permutation group, if necessary
     1096        converted to the corresponding container. That is, if
     1097        ``action='OnSets'`` then each entry will be a set even if
     1098        ``point`` was given by a list/tuple/iterable.
     1099
    10901100        EXAMPLES::
    10911101
    10921102            sage: G = PermutationGroup([ [(3,4)], [(1,3)] ])
    10931103            sage: G.orbit(3)
    1094             [3, 4, 1]
     1104            (3, 4, 1)
    10951105            sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4,10)]])
    10961106            sage: G.orbit(3)
    1097             [3, 4, 10, 1, 2]
     1107            (3, 4, 10, 1, 2)
    10981108            sage: G = PermutationGroup([ [('c','d')], [('a','c')] ])
    10991109            sage: G.orbit('a')
    1100             ['a', 'c', 'd']
     1110            ('a', 'c', 'd')
    11011111
    11021112        Action of `S_3` on sets::
    11031113
    11041114            sage: S3 = groups.permutation.Symmetric(3)
    11051115            sage: S3.orbit((1,2), action = "OnSets")
    1106             [[1, 2], [2, 3], [1, 3]]
     1116            ({1, 2}, {2, 3}, {1, 3})
    11071117
    11081118        On tuples::
    11091119
    11101120            sage: S3.orbit((1,2), action = "OnTuples")
    1111             [[1, 2], [2, 3], [2, 1], [3, 1], [1, 3], [3, 2]]
     1121            ((1, 2), (2, 3), (2, 1), (3, 1), (1, 3), (3, 2))
    11121122
    11131123        Action of `S_4` on sets of disjoint sets::
    11141124
    11151125            sage: S4 = groups.permutation.Symmetric(4)
    11161126            sage: S4.orbit(((1,2),(3,4)), action = "OnSetsDisjointSets")
    1117             [[[1, 2], [3, 4]],
    1118              [[1, 4], [2, 3]],
    1119              [[1, 3], [2, 4]]]
     1127            ({{1, 2}, {3, 4}}, {{2, 3}, {1, 4}}, {{1, 3}, {2, 4}})
    11201128
    11211129        Action of `S_4` (on a nonstandard domain) on tuples of sets::
    11221130
    11231131            sage: S4 = PermutationGroup([ [('c','d')], [('a','c')], [('a','b')] ])
    11241132            sage: S4.orbit((('a','c'),('b','d')),"OnTuplesSets")
    1125             [[['a', 'c'], ['b', 'd']], [['a', 'd'], ['b', 'c']],
    1126              [['b', 'c'], ['a', 'd']], [['b', 'd'], ['a', 'c']],
    1127              [['c', 'd'], ['a', 'b']], [['a', 'b'], ['c', 'd']]]
     1133            (({'a', 'c'}, {'b', 'd'}),
     1134             ({'a', 'd'}, {'c', 'b'}),
     1135             ({'c', 'b'}, {'a', 'd'}),
     1136             ({'b', 'd'}, {'a', 'c'}),
     1137             ({'c', 'd'}, {'a', 'b'}),
     1138             ({'a', 'b'}, {'c', 'd'}))
    11281139
    11291140        Action of `S_4` (on a very nonstandard domain) on tuples of sets::
    11301141
    1131             sage: S4 = PermutationGroup([ [((11,(12,13)),'d')], [((12,(12,11)),(11,(12,13)))], [((12,(12,11)),'b')] ])
     1142            sage: S4 = PermutationGroup([ [((11,(12,13)),'d')],
     1143            ...           [((12,(12,11)),(11,(12,13)))], [((12,(12,11)),'b')] ])
    11321144            sage: S4.orbit((( (11,(12,13)), (12,(12,11))),('b','d')),"OnTuplesSets")
    1133             [[[(11, (12, 13)), (12, (12, 11))], ['b', 'd']],
    1134              [['d', (12, (12, 11))], ['b', (11, (12, 13))]],
    1135              [['b', (11, (12, 13))], ['d', (12, (12, 11))]],
    1136              [['d', (11, (12, 13))], ['b', (12, (12, 11))]],
    1137              [['b', 'd'], [(11, (12, 13)), (12, (12, 11))]],
    1138              [['b', (12, (12, 11))], ['d', (11, (12, 13))]]]
    1139 
     1145            (({(11, (12, 13)), (12, (12, 11))}, {'b', 'd'}),
     1146             ({'d', (12, (12, 11))}, {(11, (12, 13)), 'b'}),
     1147             ({(11, (12, 13)), 'b'}, {'d', (12, (12, 11))}),
     1148             ({(11, (12, 13)), 'd'}, {'b', (12, (12, 11))}),
     1149             ({'b', 'd'}, {(11, (12, 13)), (12, (12, 11))}),
     1150             ({'b', (12, (12, 11))}, {(11, (12, 13)), 'd'}))
    11401151        """
    1141         def input_to_gap(x, depth, sort):
    1142             if depth:
    1143                 ans = [input_to_gap(xx,depth-1,sort) for xx in x]
    1144                 if depth == 1 and sort:
    1145                     ans.sort()
    1146                 return ans
     1152        from sage.sets.set import Set
     1153        actions = {
     1154            "OnPoints"           : [],
     1155            "OnSets"             : [Set],
     1156            "OnPairs"            : [tuple],
     1157            "OnTuples"           : [tuple],
     1158            "OnSetsSets"         : [Set, Set],
     1159            "OnSetsDisjointSets" : [Set, Set],
     1160            "OnSetsTuples"       : [Set, tuple],
     1161            "OnTuplesSets"       : [tuple, Set],
     1162            "OnTuplesTuples"     : [tuple, tuple],
     1163            }
     1164
     1165        def input_for_gap(x, depth, container):
     1166            if depth == len(container):
     1167                try:
     1168                    return self._domain_to_gap[x]
     1169                except KeyError:
     1170                    raise ValueError('{0} is not part of the domain'.format(x))
     1171            x = [input_for_gap(xx, depth+1, container) for xx in x]
     1172            if container[depth] is Set:
     1173                x.sort()
     1174            return x
     1175
     1176        def gap_to_output(x, depth, container):
     1177            if depth == len(container):
     1178                return self._domain_from_gap[x]
    11471179            else:
    1148                 return self._domain_to_gap[x]
    1149 
    1150         def gap_to_output(x, depth):
    1151             if depth:
    1152                 return [gap_to_output(xx,depth-1) for xx in x]
    1153             else:
    1154                 return self._domain_from_gap[x]
    1155 
    1156         sort = False
    1157 
    1158         actions = {
    1159             "OnPoints"           : {"depth" : 0, "sort" : False},
    1160             "OnSets"             : {"depth" : 1, "sort" : True},
    1161             "OnPairs"            : {"depth" : 1, "sort" : False},
    1162             "OnTuples"           : {"depth" : 1, "sort" : False},
    1163             "OnTuples"           : {"depth" : 1, "sort" : False},
    1164             "OnSetsSets"         : {"depth" : 2, "sort" : True},
    1165             "OnSetsDisjointSets" : {"depth" : 2, "sort" : True},
    1166             "OnTuplesSets"       : {"depth" : 2, "sort" : True},
    1167             "OnTuplesTuples"     : {"depth" : 2, "sort" : False},
    1168             "OnTuplesTuples"     : {"depth" : 2, "sort" : False}
    1169             }
     1180                x = [gap_to_output(xx, depth+1, container) for xx in x]
     1181                return container[depth](x)
    11701182        try:
    1171             params = actions[action]
     1183            container = actions[action]
    11721184        except KeyError:
    1173             raise ValueError("This action is not implemented (yet?).")
    1174 
    1175         try:
    1176             point = input_to_gap(point, **params)
    1177         except KeyError:
    1178             raise ValueError("One element does not seem to be part of the domain.")
    1179 
    1180         ans = self._gap_().Orbit(point, action).sage()
    1181 
    1182         return gap_to_output(ans, params['depth']+1)
     1185            raise NotImplementedError("This action is not implemented (yet?).")
     1186        point = input_for_gap(point, 0, container)
     1187        result = self._gap_().Orbit(point, action).sage()
     1188        result = [gap_to_output(x, 0, container) for x in result]
     1189        return tuple(result)
    11831190
    11841191    def transversals(self, point):
    11851192        """