Ticket #14291: ducktype_design.patch

File ducktype_design.patch, 4.3 KB (added by dimpase, 8 years ago)
  • sage/groups/perm_gps/permgroup.py

    # HG changeset patch
    # User Dmitrii Pasechnik <dimpase@gmail.com>
    # Date 1363833095 -28800
    # Node ID 1374d0855a2131b6b02055f4ed232dfb51a0d3cd
    # Parent  8122a491abdefccf81532c21a5d38612511a58c3
    duck type design for actions/orbits (updated)
    
    diff --git a/sage/groups/perm_gps/permgroup.py b/sage/groups/perm_gps/permgroup.py
    a b  
    11201120            sage: S4.orbit(((1,2),(3,4)), action = "OnSetsDisjointSets")
    11211121            [[[1, 2], [3, 4]], [[1, 4], [2, 3]], [[1, 3], [2, 4]]]
    11221122
     1123        Action of `S_4` (on a nonstandard domain) on tuples of sets::
     1124
     1125            sage: S4 = PermutationGroup([ [('c','d')], [('a','c')], [('a','b')] ])
     1126            sage: S4.orbit((('a','c'),('b','d')),"OnTuplesSets")
     1127            [[['a', 'c'], ['b', 'd']], [['a', 'd'], ['b', 'c']], [['b', 'c'], ['a', 'd']], [['b', 'd'], ['a', 'c']], [['c', 'd'], ['a', 'b']], [['a', 'b'], ['c', 'd']]]
     1128
     1129        Action of `S_4` (on a very nonstandard domain) on tuples of sets::
     1130
     1131            sage: S4 = PermutationGroup([ [((11,(12,13)),'d')], [((12,(12,11)),(11,(12,13)))], [((12,(12,11)),'b')] ])
     1132            sage: S4.orbit((( (11,(12,13)), (12,(12,11))),('b','d')),"OnTuplesSets")
     1133            [[[(11, (12, 13)), (12, (12, 11))], ['b', 'd']], [['d', (12, (12, 11))], ['b', (11, (12, 13))]], [['b', (11, (12, 13))], ['d', (12, (12, 11))]], [['d', (11, (12, 13))], ['b', (12, (12, 11))]], [['b', 'd'], [(11, (12, 13)), (12, (12, 11))]], [['b', (12, (12, 11))], ['d', (11, (12, 13))]]]
     1134
    11231135        """
    11241136        if action == "OnPoints":
    11251137            try:
     
    11311143                                 "argument explicitly.")
    11321144            return [self._domain_from_gap[x] for x in self._gap_().Orbit(point).sage()]
    11331145
    1134         elif action in self.supported_actions:
    1135             if action in ['OnTuples', 'OnSets', 'OnPairs']:
    1136                 points = [self._domain_to_gap[x] for x in point]
    1137                 orbits = self._gap_().Orbit(points, action).sage()
    1138                 return [[self._domain_from_gap[x] for x in o] for o in orbits]
    1139             else:
    1140                 points = [[self._domain_to_gap[x] for x in p] for p in point]
    1141                 orbits = self._gap_().Orbit(points, action).sage()
    1142                 return [[[self._domain_from_gap[x] for x in p] for p in o]
    1143                         for o in orbits]
    1144 
    1145         else:
    1146             raise ValueError("'action' can only take values among "+
    1147                              self.supported_actions)
     1146        def dom_to_gap(x):
     1147            try:
     1148                return self._domain_to_gap[x]
     1149            except (TypeError, KeyError):
     1150                return [dom_to_gap(y) for y in x]
     1151
     1152        def dom_from_gap(x):
     1153            try:
     1154                return self._domain_from_gap[x]
     1155            except (TypeError, KeyError):
     1156                return [dom_from_gap(y) for y in x]
     1157
     1158        return dom_from_gap(self._gap_().Orbit(dom_to_gap(point), action).sage())
    11481159
    11491160    def action(self, domain, action = "OnPoints"):
    11501161        """
     
    11821193            sage: S3.order()
    11831194            6
    11841195
     1196        Action of `S_4` (on a nonstandard domain) on tuples of sets::
     1197
     1198            sage: S4 = PermutationGroup([ [('c','d')], [('a','c')], [('a','b')] ])
     1199            sage: o6 = S4.orbit((('a','c'),('b','d')),"OnTuplesSets")
     1200            sage: S4.action(o6, "OnTuplesSets")
     1201            Permutation Group with generators [(2,5)(3,6), (1,2)(3,4), (1,3)(2,4)]
     1202
     1203        Action of `S_4` (on a very nonstandard domain) on tuples of sets::
     1204
     1205            sage: S4 = PermutationGroup([ [((11,(12,13)),'d')], [((12,(12,11)),(11,(12,13)))], [((12,(12,11)),'b')] ])
     1206            sage: o6 = S4.orbit((( (11,(12,13)), (12,(12,11))),('b','d')),"OnTuplesSets")
     1207            sage: S4.action(o6, "OnTuplesSets")
     1208            Permutation Group with generators [(2,4)(3,6), (1,2)(3,5), (1,3)(2,5)]
     1209
    11851210        """
    1186         return PermutationGroup(gap_group = self._gap_().Action(domain, action))
     1211        def dom_to_gap(x):
     1212            try:
     1213                return self._domain_to_gap[x]
     1214            except (TypeError, KeyError):
     1215                return [dom_to_gap(y) for y in x]
     1216
     1217        return PermutationGroup(gap_group = self._gap_().Action(
     1218             dom_to_gap(domain), action))
    11871219
    11881220    def transversals(self, point):
    11891221        """