Ticket #5790: trac_5790_review_nt.patch
| File trac_5790_review_nt.patch, 15.7 KB (added by nthiery, 8 months ago) |
|---|
-
sage/combinat/partition.py
old new 20 20 - Dan Drake (2009-03-28): deprecate RestrictedPartitions and implement 21 21 Partitions_parts_in 22 22 23 EXAMPLES: There are 5 partitions of the integer 4.23 EXAMPLES: 24 24 25 ::25 There are 5 partitions of the integer 4:: 26 26 27 27 sage: Partitions(4).cardinality() 28 28 5 … … 30 30 [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]] 31 31 32 32 We can use the method .first() to get the 'first' partition of a 33 number. 34 35 :: 33 number:: 36 34 37 35 sage: Partitions(4).first() 38 36 [4] 39 37 40 38 Using the method .next(), we can calculate the 'next' partition. 41 When we are at the last partition, None will be returned. 42 43 :: 39 When we are at the last partition, None will be returned:: 44 40 45 41 sage: Partitions(4).next([4]) 46 42 [3, 1] … … 48 44 True 49 45 50 46 We can use ``iter`` to get an object which iterates over the partitions one 51 by one to save memory. Note that when we do something like 52 ``for part in Partitions(4)`` this iterator is used in the background. 53 54 :: 47 by one to save memory. Note that when we do something like 48 ``for part in Partitions(4)`` this iterator is used in the background:: 55 49 56 50 sage: g = iter(Partitions(4)) 57 51 … … 95 89 96 90 The min_part options is complementary to max_part and selects 97 91 partitions having only 'large' parts. Here is the list of all 98 partitions of 4 with each part at least 2. 99 100 :: 92 partitions of 4 with each part at least 2:: 101 93 102 94 sage: Partitions(4, min_part=2).list() 103 95 [[4], [2, 2]] … … 119 111 120 112 Finally, here are the partitions of 4 with [1,1,1] as an inner 121 113 bound. Note that inner sets min_length to the length of its 122 argument. 123 124 :: 114 argument:: 125 115 126 116 sage: Partitions(4, inner=[1,1,1]).list() 127 117 [[2, 1, 1], [1, 1, 1, 1]] … … 143 133 [[7, 4], [6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2], [5, 3, 2, 1]] 144 134 145 135 Partition objects can also be created individually with the 146 Partition function. 147 148 :: 136 Partition function:: 149 137 150 138 sage: Partition([2,1]) 151 139 [2, 1] … … 154 142 methods that we can use. For example, we can get the conjugate of a 155 143 partition. Geometrically, the conjugate of a partition is the 156 144 reflection of that partition through its main diagonal. Of course, 157 this operation is an involution. 158 159 :: 145 this operation is an involution:: 160 146 161 147 sage: Partition([4,1]).conjugate() 162 148 [2, 1, 1, 1] … … 165 151 166 152 We can go back and forth between the exponential notations of a 167 153 partition. The exponential notation can be padded with extra 168 zeros. 169 170 :: 154 zeros:: 171 155 172 156 sage: Partition([6,4,4,2,1]).to_exp() 173 157 [1, 1, 0, 2, 0, 1] … … 180 164 sage: Partition([6,4,4,2,1]).to_exp(10) 181 165 [1, 1, 0, 2, 0, 1, 0, 0, 0, 0] 182 166 183 We can get the coordinates of the corners of a partition. 184 185 :: 167 We can get the coordinates of the corners of a partition:: 186 168 187 169 sage: Partition([4,3,1]).corners() 188 170 [[0, 3], [1, 2], [2, 0]] 189 171 190 172 We can compute the core and quotient of a partition and build 191 the partition back up from them. 192 193 :: 173 the partition back up from them:: 194 174 195 175 sage: Partition([6,3,2,2]).core(3) 196 176 [2, 1, 1] … … 208 188 # Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>, 209 189 # 210 190 # Distributed under the terms of the GNU General Public License (GPL) 211 #212 # This code is distributed in the hope that it will be useful,213 # but WITHOUT ANY WARRANTY; without even the implied warranty of214 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU215 # General Public License for more details.216 #217 # The full text of the GPL is available at:218 #219 191 # http://www.gnu.org/licenses/ 220 192 #***************************************************************************** 221 193 222 194 from sage.interfaces.all import gap, gp 223 195 from sage.rings.all import QQ, ZZ, infinity, factorial, gcd 224 from sage.misc.all import prod , sage_eval196 from sage.misc.all import prod 225 197 from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 226 198 import sage.combinat.misc as misc 227 199 import sage.combinat.skew_partition … … 239 211 from integer_list import IntegerListsLex 240 212 from sage.functions.other import ceil 241 213 242 def Partition(mu=None, **key_word): 243 """ 244 A partition is a weakly decreasing ordered sequence of non-negative 245 integers. This function returns a Sage partition object which can 246 be specified in one of the following ways:: 247 * a list (the default) 248 * using exponential notation 249 * by beta numbers (TODO) 250 * specifying the core and the quotient 251 * specifying the core and the canonical quotient (TODO) 252 See the examples below. 253 254 Sage follows the usual python conventions when dealing with partitions, 255 so that the first part of the partition ``mu=Partition([4,3,2,2])`` is 256 ``mu[0]``, the second part is ``mu[1]`` and so on. As is usual, Sage ignores 257 trailing zeros at the end of partitions. 258 259 EXAMPLES:: 260 261 sage: Partition([3,2,1]) 262 [3, 2, 1] 263 sage: Partition([3,2,1,0]) 264 [3, 2, 1] 214 def Partition(mu=None, **keyword): 215 """ 216 A partition is a weakly decreasing ordered sequence of non-negative 217 integers. This function returns a Sage partition object which can 218 be specified in one of the following ways:: 219 220 * a list (the default) 221 * using exponential notation 222 * by beta numbers (TODO) 223 * specifying the core and the quotient 224 * specifying the core and the canonical quotient (TODO) 225 226 See the examples below. 227 228 Sage follows the usual python conventions when dealing with partitions, 229 so that the first part of the partition ``mu=Partition([4,3,2,2])`` is 230 ``mu[0]``, the second part is ``mu[1]`` and so on. As is usual, Sage ignores 231 trailing zeros at the end of partitions. 232 233 EXAMPLES:: 234 235 sage: Partition([3,2,1]) 236 [3, 2, 1] 237 sage: Partition([3,2,1,0]) 238 [3, 2, 1] 265 239 sage: Partition(exp=[2,1,1]) 266 240 [3, 2, 1, 1] 267 241 sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) … … 275 249 ... 276 250 ValueError: [1, 2, 3] is not a valid partition 277 251 """ 278 if mu is not None and len(key _word)==0:252 if mu is not None and len(keyword)==0: 279 253 mu = [i for i in mu if i != 0] 280 254 if mu in Partitions_all(): 281 255 return Partition_class(mu) 282 256 else: 283 257 raise ValueError, "%s is not a valid partition"%mu 284 elif 'beta_numbers' in key _word and len(key_word)==1:258 elif 'beta_numbers' in keyword and len(keyword)==1: 285 259 raise NotImplementedError 286 elif 'exp' in key _word and len(key_word)==1:287 return from_exp(key _word['exp'])288 elif 'core' in key _word and 'quotient' in key_word and len(key_word)==2:289 return from_core_and_quotient(key _word['core'], key_word['quotient'])290 elif 'core' in key _word and 'canonical_quotient' in key_word and len(key_word)==2:260 elif 'exp' in keyword and len(keyword)==1: 261 return from_exp(keyword['exp']) 262 elif 'core' in keyword and 'quotient' in keyword and len(keyword)==2: 263 return from_core_and_quotient(keyword['core'], keyword['quotient']) 264 elif 'core' in keyword and 'canonical_quotient' in keyword and len(keyword)==2: 291 265 raise NotImplementedError 292 elif 'core_and_quotient' in key _word and len(key_word)==1:266 elif 'core_and_quotient' in keyword and len(keyword)==1: 293 267 from sage.misc.misc import deprecation 294 268 deprecation('"core_and_quotient=(*)" is deprecated. Use "core=[*], quotient=[*]" instead.') 295 return from_core_and_quotient(*key _word['core_and_quotient'])269 return from_core_and_quotient(*keyword['core_and_quotient']) 296 270 else: 297 271 raise ValueError, 'incorrect syntax for Partition()' 298 272 … … 304 278 305 279 This function is for internal use only; 306 280 use Partition(exp=*) instead. 307 281 308 282 EXAMPLES:: 309 283 310 284 sage: Partition(exp=[1,2,1]) 311 285 [3, 2, 2, 1] 312 286 """ … … 318 292 def from_core_and_quotient(core, quotient): 319 293 """ 320 294 ** This function is being deprecated - use Partition(core=*, quotient=*) instead ** 321 295 322 296 Returns a partition from its core and quotient. 323 297 324 298 Algorithm from mupad-combinat. … … 327 301 328 302 This function is for internal use only; 329 303 use Partition(core=*, quotient=*) instead. 330 304 331 305 EXAMPLES:: 332 306 333 307 sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 334 308 [11, 5, 5, 3, 2, 2, 2] 335 309 """ … … 397 371 398 372 return sage.combinat.skew_partition.SkewPartition([self[:], p]) 399 373 400 def power(self, k):374 def power(self, k): 401 375 """ 402 partition_power( pi, k ) returns the partition corresponding to403 the `k`-th power of a permutation with cycle structure pi404 (thus describes the powermap ofsymmetric groups).376 Returns the cycle type of the `k`-th power of any permutation 377 with cycle type ``self`` (thus describes the powermap of 378 symmetric groups). 405 379 406 380 Wraps GAP's PowerPartition. 407 381 … … 514 488 515 489 def sign(self): 516 490 r""" 517 Returns the sign of a permutation with cycle type of the partition.491 Returns the sign of any permutation with cycle type ``self``. 518 492 519 493 This function corresponds to a homomorphism from the symmetric 520 494 group `S_n` into the cyclic group of order 2, whose kernel … … 1267 1241 def centralizer_size(self, t=0, q=0): 1268 1242 """ 1269 1243 Returns the size of the centralizer of any permutation of cycle type 1270 p. If m_i is the multiplicity of i as a part of p, this is given1244 ``self``. If m_i is the multiplicity of i as a part of p, this is given 1271 1245 by `\prod_i (i^m[i])*(m[i]!)`. Including the optional 1272 1246 parameters t and q gives the q-t analog which is the former product 1273 1247 times `\prod_{i=1}^{length(p)} (1 - q^{p[i]}) / (1 - t^{p[i]}).` … … 1294 1268 def aut(self): 1295 1269 r""" 1296 1270 Returns a factor for the number of permutations with cycle type 1297 self. self.aut() returns1271 ``self``. self.aut() returns 1298 1272 `1^{j_1}j_1! \cdots n^{j_n}j_n!` where `j_k` 1299 1273 is the number of parts in self equal to k. 1300 1274 … … 1417 1391 return res 1418 1392 1419 1393 def r_core(self, length): 1420 """ *** deprecate *** """ 1421 from sage.misc.misc import deprecation 1422 deprecation('r_core is deprecated. Use core instead.') 1423 return self.core(self, length) 1394 """ 1395 This function is deprecated. 1396 1397 EXAMPLES:: 1398 1399 sage: Partition([6,3,2,2]).r_core(3) 1400 doctest:1: DeprecationWarning: r_core is deprecated. Please use core instead. 1401 [2, 1, 1] 1402 1403 Please use :meth:`core` instead:: 1404 1405 sage: Partition([6,3,2,2]).core(3) 1406 [2, 1, 1] 1407 1408 """ 1409 from sage.misc.misc import deprecation 1410 deprecation('r_core is deprecated. Please use core instead.') 1411 return self.core(length) 1424 1412 1425 1413 def core(self, length): 1426 1414 """ 1427 1415 Returns the core of the partition -- in the literature the core is 1428 commonly referred to as the k-core, p-core, r-core, ... . The1416 commonly referred to as the `k`-core, `p`-core, `r`-core, ... . The 1429 1417 construction of the core can be visualized by repeatedly removing 1430 border strips of size r from puntil this is no longer possible.1418 border strips of size `r` from ``self`` until this is no longer possible. 1431 1419 The remaining partition is the core. 1432 1420 1433 1421 EXAMPLES:: 1434 1422 1435 1423 sage: Partition([6,3,2,2]).core(3) 1436 1424 [2, 1, 1] 1437 1425 sage: Partition([]).core(3) 1438 1426 [] 1439 1427 sage: Partition([8,7,7,4,1,1,1,1,1]).core(3) 1440 1428 [2, 1, 1] 1441 1429 1442 1430 TESTS:: 1443 1431 1444 1432 sage: Partition([3,3,3,2,1]).core(3) 1445 1433 [] 1446 1434 sage: Partition([10,8,7,7]).core(4) … … 1471 1459 return filter(lambda x: x != 0, part) 1472 1460 1473 1461 def r_quotient(self, length): 1474 """ *** deprecate *** """ 1475 from sage.misc.misc import deprecation 1476 deprecation('r_quotient is deprecated. Use quotient instead.') 1477 return self.quotient(self,length) 1462 """ 1463 This function is deprecated. 1464 1465 EXAMPLES:: 1466 1467 sage: Partition([6,3,2,2]).r_quotient(3) 1468 doctest:1: DeprecationWarning: r_quotient is deprecated. Please use quotient instead. 1469 [[], [], [2, 1]] 1478 1470 1471 Please use :meth:`quotient` instead:: 1472 1473 sage: Partition([6,3,2,2]).quotient(3) 1474 [[], [], [2, 1]] 1475 """ 1476 from sage.misc.misc import deprecation 1477 deprecation('r_quotient is deprecated. Please use quotient instead.') 1478 return self.quotient(length) 1479 1479 1480 1480 def quotient(self, length): 1481 1481 """ 1482 1482 Returns the quotient of the partition -- in the literature the 1483 core is commonly referred to as the k-core, p-core, r-core, ... . The1484 quotient is a list of rpartitions, constructed in the following1485 way. Label each cell in p with its content, modulo r. Let R_ibe1486 the set of rows ending in a box labelled i, and C_ibe the set of1487 columns ending in a box labelled i. Then the jth component of the1488 quotient of p is the partition defined by intersecting R_jwith1489 C_j+1.1490 1483 core is commonly referred to as the `k`-core, `p`-core, `r`-core, ... . The 1484 quotient is a list of `r` partitions, constructed in the following 1485 way. Label each cell in `p` with its content, modulo `r`. Let `R_i` be 1486 the set of rows ending in a box labelled `i`, and `C_i` be the set of 1487 columns ending in a box labelled `i`. Then the `j`-th component of the 1488 quotient of `p` is the partition defined by intersecting `R_j` with 1489 `C_j+1`. 1490 1491 1491 EXAMPLES:: 1492 1492 1493 1493 sage: Partition([7,7,5,3,3,3,1]).quotient(3) … … 4251 4251 def partition_power(pi,k): 4252 4252 """ 4253 4253 partition_power( pi, k ) returns the partition corresponding to 4254 the `k`-th power of a permutation with cycle structure pi4254 the `k`-th power of a permutation with cycle structure ``pi`` 4255 4255 (thus describes the powermap of symmetric groups). 4256 4256 4257 4257 Wraps GAP's PowerPartition. … … 4295 4295 is exactly the alternating group `A_n`. Partitions of sign 4296 4296 `1` are called even partitions while partitions of sign 4297 4297 `-1` are called odd. 4298 4298 4299 4299 This function is deprecated: use Partition( pi ).sign() instead. 4300 4300 4301 4301 EXAMPLES:: 4302 4302 4303 4303 sage: Partition([5,3]).sign() 4304 4304 1 4305 4305 sage: Partition([5,2]).sign() … … 4390 4390 from sage.misc.misc import deprecation 4391 4391 deprecation('"partition_associated deprecated. Use Partition(pi).conjugte() instead') 4392 4392 return Partition(pi).conjugate() 4393 4393
