|
223 | 223 | =================== |
224 | 224 | """ |
225 | 225 |
|
226 | | -#***************************************************************************** |
| 226 | +# **************************************************************************** |
227 | 227 | # Copyright (C) 2007 Mike Hansen <[email protected]> |
228 | 228 | # |
229 | 229 | # This program is free software: you can redistribute it and/or modify |
230 | 230 | # it under the terms of the GNU General Public License as published by |
231 | 231 | # the Free Software Foundation, either version 2 of the License, or |
232 | 232 | # (at your option) any later version. |
233 | 233 | # https://www.gnu.org/licenses/ |
234 | | -#***************************************************************************** |
| 234 | +# **************************************************************************** |
235 | 235 |
|
236 | 236 | from sage.structure.parent import Parent |
237 | 237 | from sage.structure.unique_representation import UniqueRepresentation |
@@ -701,7 +701,7 @@ def size(self): |
701 | 701 |
|
702 | 702 | def cycle_string(self, singletons=False): |
703 | 703 | """ |
704 | | - Returns a string of the permutation in cycle notation. |
| 704 | + Return a string of the permutation in cycle notation. |
705 | 705 |
|
706 | 706 | If ``singletons=True``, it includes 1-cycles in the string. |
707 | 707 |
|
@@ -749,8 +749,8 @@ def __next__(self): |
749 | 749 |
|
750 | 750 | #Starting from the end, find the first o such that |
751 | 751 | #p[o] < p[o+1] |
752 | | - for i in reversed(range(0,n-1)): |
753 | | - if p[i] < p[i+1]: |
| 752 | + for i in reversed(range(n - 1)): |
| 753 | + if p[i] < p[i + 1]: |
754 | 754 | first = i |
755 | 755 | break |
756 | 756 |
|
@@ -809,8 +809,8 @@ def prev(self): |
809 | 809 |
|
810 | 810 | #Starting from the end, find the first o such that |
811 | 811 | #p[o] > p[o+1] |
812 | | - for i in reversed(range(0, n-1)): |
813 | | - if p[i] > p[i+1]: |
| 812 | + for i in reversed(range(n - 1)): |
| 813 | + if p[i] > p[i + 1]: |
814 | 814 | first = i |
815 | 815 | break |
816 | 816 |
|
@@ -968,7 +968,7 @@ def to_cycles(self, singletons=True, use_min=True): |
968 | 968 |
|
969 | 969 | def _to_cycles_orig(self, singletons=True): |
970 | 970 | r""" |
971 | | - Returns the permutation ``self`` as a list of disjoint cycles. |
| 971 | + Return the permutation ``self`` as a list of disjoint cycles. |
972 | 972 |
|
973 | 973 | EXAMPLES:: |
974 | 974 |
|
@@ -1115,7 +1115,7 @@ def _to_cycles_list(self, singletons=True): |
1115 | 1115 |
|
1116 | 1116 | def to_permutation_group_element(self): |
1117 | 1117 | """ |
1118 | | - Returns a PermutationGroupElement equal to self. |
| 1118 | + Return a PermutationGroupElement equal to self. |
1119 | 1119 |
|
1120 | 1120 | EXAMPLES:: |
1121 | 1121 |
|
@@ -1389,15 +1389,9 @@ def rank(self): |
1389 | 1389 | True |
1390 | 1390 | """ |
1391 | 1391 | n = len(self) |
1392 | | - |
1393 | 1392 | factoradic = self.to_lehmer_code() |
1394 | | - |
1395 | | - #Compute the index |
1396 | | - rank = 0 |
1397 | | - for i in reversed(range(0, n)): |
1398 | | - rank += factoradic[n-1-i]*factorial(i) |
1399 | | - |
1400 | | - return rank |
| 1393 | + return sum(factoradic[n - 1 - i] * factorial(i) |
| 1394 | + for i in reversed(range(n))) |
1401 | 1395 |
|
1402 | 1396 | ############## |
1403 | 1397 | # Inversions # |
@@ -1869,10 +1863,10 @@ def _icondition(self, i): |
1869 | 1863 |
|
1870 | 1864 | .. NOTE:: |
1871 | 1865 |
|
1872 | | - An imove (that is, an iswitch or an ishift) can only be applied |
1873 | | - when the relative positions of `i-1,i,i+1` are one of '213', |
1874 | | - '132', '231', or '312'. ``None`` is returned in the other cases |
1875 | | - to signal that an imove cannot be applied. |
| 1866 | + An imove (that is, an iswitch or an ishift) can only be applied |
| 1867 | + when the relative positions of `i-1,i,i+1` are one of '213', |
| 1868 | + '132', '231', or '312'. ``None`` is returned in the other cases |
| 1869 | + to signal that an imove cannot be applied. |
1876 | 1870 |
|
1877 | 1871 | EXAMPLES:: |
1878 | 1872 |
|
@@ -2161,9 +2155,9 @@ def longest_increasing_subsequences(self): |
2161 | 2155 | r""" |
2162 | 2156 | Return the list of the longest increasing subsequences of ``self``. |
2163 | 2157 |
|
2164 | | - .. note:: |
| 2158 | + .. NOTE:: |
2165 | 2159 |
|
2166 | | - The algorithm is not optimal. |
| 2160 | + The algorithm is not optimal. |
2167 | 2161 |
|
2168 | 2162 | EXAMPLES:: |
2169 | 2163 |
|
@@ -2704,7 +2698,7 @@ def to_lehmer_cocode(self): |
2704 | 2698 | n = len(p) |
2705 | 2699 | cocode = [0] * n |
2706 | 2700 | for i in range(1, n): |
2707 | | - for j in range(0, i): |
| 2701 | + for j in range(i): |
2708 | 2702 | if p[j] > p[i]: |
2709 | 2703 | cocode[i] += 1 |
2710 | 2704 | return cocode |
@@ -3652,7 +3646,7 @@ def bruhat_smaller(self): |
3652 | 3646 |
|
3653 | 3647 | def bruhat_greater(self): |
3654 | 3648 | r""" |
3655 | | - Returns the combinatorial class of permutations greater than or |
| 3649 | + Return the combinatorial class of permutations greater than or |
3656 | 3650 | equal to ``self`` in the Bruhat order (on the symmetric group |
3657 | 3651 | containing ``self``). |
3658 | 3652 |
|
@@ -3799,7 +3793,7 @@ def permutohedron_succ(self, side="right"): |
3799 | 3793 | P = Permutations() |
3800 | 3794 | succ = [] |
3801 | 3795 | if side == "right": |
3802 | | - rise = lambda perm: [i for i in range(0,n-1) if perm[i] < perm[i+1]] |
| 3796 | + rise = lambda perm: [i for i in range(n - 1) if perm[i] < perm[i+1]] |
3803 | 3797 | for i in rise(p): |
3804 | 3798 | pp = p[:] |
3805 | 3799 | pp[i] = p[i+1] |
@@ -4313,7 +4307,7 @@ def simion_schmidt(self, avoid=[1,2,3]): |
4313 | 4307 | @combinatorial_map(order=2,name='reverse') |
4314 | 4308 | def reverse(self): |
4315 | 4309 | """ |
4316 | | - Returns the permutation obtained by reversing the list. |
| 4310 | + Return the permutation obtained by reversing the list. |
4317 | 4311 |
|
4318 | 4312 | EXAMPLES:: |
4319 | 4313 |
|
@@ -4379,7 +4373,7 @@ def permutation_poset(self): |
4379 | 4373 |
|
4380 | 4374 | def dict(self): |
4381 | 4375 | """ |
4382 | | - Returns a dictionary corresponding to the permutation. |
| 4376 | + Return a dictionary corresponding to the permutation. |
4383 | 4377 |
|
4384 | 4378 | EXAMPLES:: |
4385 | 4379 |
|
|
0 commit comments