@@ -72,13 +72,25 @@ def __call__(cls, item, perm_space=None):
7272class Perm (sequence_tools .CuteSequenceMixin , collections .Sequence ,
7373 metaclass = PermType ):
7474 '''
75- A permutation.
75+ A permutation of items from a `PermSpace`
7676
77+ In combinatorics, a permutation is a sequence of items taken from the
78+ original sequence.
79+
80+ Example:
81+
82+ >>> perm_space = PermSpace('abcd')
83+ >>> perm = Perm('dcba', perm_space)
84+ >>> perm
85+ <Perm: ('d', 'c', 'b', 'a')>
86+ >>> perm_space.index(perm)
87+ 23
7788
7889 '''
7990
8091 @classmethod
8192 def coerce (cls , item , perm_space = None ):
93+ '''Coerce item into a perm, optionally of a specified `PermSpace`.'''
8294 if isinstance (item , Perm ) and (perm_space is not None ) and \
8395 (item .nominal_perm_space == perm_space ._nominal_perm_space_of_perms ):
8496 return item
@@ -88,10 +100,10 @@ def coerce(cls, item, perm_space=None):
88100
89101 def __init__ (self , perm_sequence , perm_space = None ):
90102 '''
103+ Create the `Perm`.
91104
92- Not supplying `perm_space` is allowed only if given either a number (in
93- which case a pure infinite perm space will be assumed) or a sequence of
94- natural numbers.
105+ If `perm_space` is not supplied, we assume that this is a pure
106+ permutation, i.e. a permutation on `range(len(perm_sequence))`.
95107 '''
96108 perm_space = None if perm_space is None \
97109 else PermSpace .coerce (perm_space )
@@ -171,13 +183,20 @@ def __repr__(self):
171183 )
172184
173185 def index (self , member ):
186+ '''Get the index number of `member` in the permutation.'''
174187 numerical_index = self ._perm_sequence .index (member )
175188 return self .nominal_perm_space . \
176189 domain [numerical_index ] if self .is_dapplied else numerical_index
177190
178191
179192 @caching .CachedProperty
180193 def inverse (self ):
194+ '''
195+ The inverse of this permutation.
196+
197+ This means, the permutation such that `perm * ~perm` would be the identity
198+ permutation.
199+ '''
181200 if self .is_partial :
182201 raise TypeError ("Partial perms don't have an inverse." )
183202 if self .is_rapplied :
@@ -197,13 +216,14 @@ def inverse(self):
197216 __invert__ = lambda self : self .inverse
198217
199218 domain = caching .CachedProperty (
200- lambda self : self .nominal_perm_space .domain
219+ lambda self : self .nominal_perm_space .domain ,
220+ '''The permutation's domain.'''
201221 )
202222
203223
204224 @caching .CachedProperty
205225 def unrapplied (self ):
206-
226+ '''An unrapplied version of this permutation.'''
207227 ### Calculating the new perm sequence: ################################
208228 # #
209229 # This is more complex than a one-line generator because of recurrent
@@ -228,14 +248,16 @@ def unrapplied(self):
228248 lambda self : type (self )(
229249 self ._perm_sequence ,
230250 self .nominal_perm_space .undapplied
231- )
251+ ),
252+ '''An undapplied version of this permutation.'''
232253
233254 )
234255 uncombinationed = caching .CachedProperty (
235256 lambda self : Perm (
236257 self ._perm_sequence ,
237258 self .nominal_perm_space .uncombinationed
238- )
259+ ),
260+ '''A non-combination version of this permutation.'''
239261
240262 )
241263
@@ -256,18 +278,13 @@ def __getitem__(self, i):
256278 )
257279
258280 def apply (self , sequence , result_type = None ):
259- '''
281+ '''blocktododoc
282+ App
260283
261284 Specify `result_type` to determine the type of the result returned. If
262285 `result_type=None`, will use `tuple`, except when `other` is a `str` or
263286 `Perm`, in which case that same type would be used.
264287 '''
265- # if self.is_rapplied:
266- # raise TypeError("Can't apply a rapplied permutation, try "
267- # "`perm.unrapplied`.")
268- # if self.is_dapplied:
269- # raise TypeError("Can't apply a dapplied permutation, try "
270- # "`perm.undapplied`.")
271288 sequence = \
272289 sequence_tools .ensure_iterable_is_immutable_sequence (sequence )
273290 if sequence_tools .get_length (sequence ) < \
0 commit comments