Ticket #3662: trac_3662-4.patch
| File trac_3662-4.patch, 29.5 kB (added by mhansen, 4 months ago) |
|---|
-
a/sage/combinat/combinatorial_algebra.py
old new 317 317 """ 318 318 return self._element_class(self, {self._one:self.base_ring()(1)}) 319 319 320 def _coerce_impl(self, x): 321 """ 322 EXAMPLES: 323 sage: s = SFASchur(QQ) 324 sage: s._coerce_impl(2) 325 2*s[] 326 """ 327 try: 328 R = x.parent() 329 if R.__class__ is self.__class__: 330 #Only perform the coercion if we can go from the base 331 #ring of x to the base ring of self 332 if self.base_ring().has_coerce_map_from( R.base_ring() ): 333 return self(x) 334 except AttributeError: 335 pass 336 337 # any ring that coerces to the base ring 338 return self._coerce_try(x, [self.base_ring()]) 320 339 321 340 def multiply(self,left,right): 322 341 """ -
a/sage/combinat/free_module.py
old new 1 """ 2 Free modules 3 """ 1 4 #***************************************************************************** 2 5 # Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>, 3 6 # … … 22 25 from sage.combinat.finite_class import FiniteCombinatorialClass 23 26 from sage.combinat.combinat import CombinatorialClass 24 27 25 # TODO:26 # Rewrite all tests in a more self contained way27 28 28 class CombinatorialFreeModuleElement(ModuleElement): 29 29 def __init__(self, M, x): 30 30 """ 31 31 Create a combinatorial module element x. This should never 32 32 be called directly, but only through the parent combinatorial 33 33 module's __call__ method. 34 35 TESTS: 36 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 37 sage: B = F.basis() 38 sage: f = B['a'] + 3*B['c']; f 39 B('a') + 3*B('c') 40 sage: f == loads(dumps(f)) 41 True 34 42 35 43 """ 36 44 ModuleElement.__init__(self, M) … … 39 47 def __iter__(self): 40 48 """ 41 49 EXAMPLES: 50 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 51 sage: B = F.basis() 52 sage: f = B['a'] + 3*B['c'] 53 sage: [i for i in sorted(f)] 54 [('a', 1), ('c', 3)] 55 42 56 sage: s = SFASchur(QQ) 43 57 sage: a = s([2,1]) + s([3]) 44 58 sage: [i for i in sorted(a)] … … 53 67 element is in the support of self. 54 68 55 69 EXAMPLES: 70 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 71 sage: B = F.basis() 72 sage: f = B['a'] + 3*B['c'] 73 sage: 'a' in f 74 True 75 sage: 'b' in f 76 False 77 56 78 sage: s = SFASchur(QQ) 57 79 sage: a = s([2,1]) + s([3]) 58 80 sage: Partition([2,1]) in a … … 69 91 coefficients as values. 70 92 71 93 EXAMPLES: 94 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 95 sage: B = F.basis() 96 sage: f = B['a'] + 3*B['c'] 97 sage: d = f.monomial_coefficients() 98 sage: d['a'] 99 1 100 sage: d['c'] 101 3 102 72 103 sage: s = SFASchur(QQ) 73 104 sage: a = s([2,1])+2*s([3,2]) 74 105 sage: d = a.monomial_coefficients() … … 104 135 def _latex_(self): 105 136 """ 106 137 EXAMPLES: 138 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 139 sage: B = F.basis() 140 sage: f = B['a'] + 3*B['c'] 141 sage: latex(f) 142 B_{a} + 3B_{c} 143 107 144 sage: QS3 = SymmetricGroupAlgebra(QQ,3) 108 145 sage: a = 2 + QS3([2,1,3]) 109 146 sage: latex(a) #indirect doctest … … 145 182 def _add_(self, y): 146 183 """ 147 184 EXAMPLES: 185 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 186 sage: B = F.basis() 187 sage: B['a'] + 3*B['c'] 188 B('a') + 3*B('c') 189 148 190 sage: s = SFASchur(QQ) 149 191 sage: s([2,1]) + s([5,4]) # indirect doctest 150 192 s[2, 1] + s[5, 4] … … 181 223 def _neg_(self): 182 224 """ 183 225 EXAMPLES: 226 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 227 sage: B = F.basis() 228 sage: f = B['a'] + 3*B['c'] 229 sage: -f 230 -B('a') - 3*B('c') 231 184 232 sage: s = SFASchur(QQ) 185 233 sage: -s([2,1]) # indirect doctest 186 234 -s[2, 1] … … 191 239 def _sub_(self, y): 192 240 """ 193 241 EXAMPLES: 242 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 243 sage: B = F.basis() 244 sage: B['a'] - 3*B['c'] 245 B('a') - 3*B('c') 246 194 247 sage: s = SFASchur(QQ) 195 248 sage: s([2,1]) - s([5,4]) # indirect doctest 196 249 s[2, 1] - s[5, 4] … … 234 287 Traceback (most recent call last): 235 288 ... 236 289 TypeError: list objects are unhashable 290 237 291 sage: a._coefficient_fast(p) 238 292 1 239 293 sage: a._coefficient_fast(p, 2) … … 255 309 256 310 def coefficient(self, m): 257 311 """ 258 259 # NT: coefficient_fast should be the default, just with appropriate assertions260 # that can be turned on or of261 262 312 EXAMPLES: 263 313 sage: s = SFASchur(QQ) 264 314 sage: z = s([4]) - 2*s([2,1]) + s([1,1,1]) + s([1]) … … 267 317 sage: z.coefficient([2,1]) 268 318 -2 269 319 """ 320 # NT: coefficient_fast should be the default, just with appropriate assertions 321 # that can be turned on or off 270 322 p = self.parent() 271 323 if isinstance(m, p._combinatorial_class.object_class): 272 324 return self._monomial_coefficients.get(m, p.base_ring().zero_element()) … … 281 333 Returns True if and only self == 0. 282 334 283 335 EXAMPLES: 336 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 337 sage: B = F.basis() 338 sage: f = B['a'] - 3*B['c'] 339 sage: f.is_zero() 340 False 341 sage: F(0).is_zero() 342 True 343 284 344 sage: s = SFASchur(QQ) 285 345 sage: s([2,1]).is_zero() 286 346 False … … 301 361 nonzero coefficients. 302 362 303 363 EXAMPLES: 364 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 365 sage: B = F.basis() 366 sage: f = B['a'] - 3*B['c'] 367 sage: len(f) 368 2 369 304 370 sage: s = SFASchur(QQ) 305 371 sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) 306 372 sage: len(z) … … 314 380 nonzero coefficients. 315 381 316 382 EXAMPLES: 383 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 384 sage: B = F.basis() 385 sage: f = B['a'] - 3*B['c'] 386 sage: f.length() 387 2 388 317 389 sage: s = SFASchur(QQ) 318 390 sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) 319 391 sage: z.length() 320 392 4 321 393 """ 322 return len( filter(lambda x: self._monomial_coefficients[x] != 0, self._monomial_coefficients) ) 323 394 return len([mon for mon,coeff in self._monomial_coefficients.items() if coeff !=0 ]) 324 395 325 396 def support(self): 326 """327 # NT: ???328 Returns a pair [mons, cffs] of lists of the monomials329 of self (mons) and their respective coefficients (cffs).330 331 EXAMPLES:332 sage: s = SFASchur(QQ)333 sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1])334 sage: z.support()335 [[[1], [1, 1, 1], [2, 1], [4]], [1, 1, 1, 1]]336 """337 v = self._monomial_coefficients.items()338 v.sort()339 mons = [ m for (m, _) in v ]340 cffs = [ x for (_, x) in v ]341 return [mons, cffs]342 343 def monomials(self):344 397 """ 345 398 Returns a list of the combinatorial objects indexing 346 399 the basis elements of self which non-zero coefficients. 347 400 348 401 EXAMPLES: 402 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 403 sage: B = F.basis() 404 sage: f = B['a'] - 3*B['c'] 405 sage: f.support() 406 ['a', 'c'] 407 349 408 sage: s = SFASchur(QQ) 350 409 sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) 351 sage: z. monomials()410 sage: z.support() 352 411 [[1], [1, 1, 1], [2, 1], [4]] 353 412 """ 354 413 v = self._monomial_coefficients.items() 355 414 v.sort() 356 415 mons = [ m for (m, _) in v ] 357 416 return mons 417 418 def monomials(self): 419 """ 420 EXAMPLES: 421 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 422 sage: B = F.basis() 423 sage: f = B['a'] + 2*B['c'] 424 sage: f.monomials() 425 [B('a'), B('c')] 426 """ 427 P = self.parent() 428 one = P.base_ring()(1) 429 v = self._monomial_coefficients.items() 430 v.sort() 431 return [P._from_dict({key:one}) for key,value in v] 432 433 def terms(self): 434 """ 435 EXAMPLES: 436 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 437 sage: B = F.basis() 438 sage: f = B['a'] + 2*B['c'] 439 sage: f.terms() 440 [B('a'), 2*B('c')] 441 """ 442 P = self.parent() 443 v = self._monomial_coefficients.items() 444 v.sort() 445 return [P._from_dict({key:value}) for key,value in v] 358 446 359 447 def coefficients(self): 360 448 """ … … 362 450 basiselements in self. 363 451 364 452 EXAMPLES: 453 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 454 sage: B = F.basis() 455 sage: f = B['a'] - 3*B['c'] 456 sage: f.coefficients() 457 [1, -3] 458 365 459 sage: s = SFASchur(QQ) 366 460 sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) 367 461 sage: z.coefficients() … … 378 472 then in returns a vector over new_BR. 379 473 380 474 EXAMPLES: 475 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 476 sage: B = F.basis() 477 sage: f = B['a'] - 3*B['c'] 478 sage: vector(f) 479 (1, 0, -3) 480 381 481 sage: QS3 = SymmetricGroupAlgebra(QQ, 3) 382 482 sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) 383 483 sage: a._vector_() … … 389 489 """ 390 490 parent = self.parent() 391 491 if parent.get_order() is None: 392 cc = parent._combinatorial_class 492 cc = parent._combinatorial_class.list() 493 cc.sort() 393 494 else: 394 495 cc = parent.get_order() 395 496 … … 403 504 Returns a vector version of self. 404 505 405 506 EXAMPLES: 507 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 508 sage: B = F.basis() 509 sage: f = B['a'] - 3*B['c'] 510 sage: f.to_vector() 511 (1, 0, -3) 512 406 513 sage: QS3 = SymmetricGroupAlgebra(QQ, 3) 407 514 sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) 408 515 sage: a.to_vector() … … 418 525 of self. 419 526 420 527 EXAMPLES: 528 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 529 sage: B = F.basis() 530 sage: f = B['a'] - 3*B['c'] 531 sage: f.map_coefficients(lambda x: x+5) 532 6*B('a') + 2*B('c') 533 421 534 sage: s = SFASchur(QQ) 422 535 sage: a = s([2,1])+2*s([3,2]) 423 536 sage: a.map_coefficients(lambda x: x*2) … … 429 542 return self.parent()._from_dict(z_elt) 430 543 431 544 432 def map_ basis(self, f):545 def map_support(self, f): 433 546 """ 434 547 Returns a new element of self.parent() obtained 435 548 by applying the function f to all of the combinatorial 436 549 objects indexing the basis elements. 437 550 438 FIXME: rename to map_support?439 440 551 EXAMPLES: 441 552 sage: s = SFASchur(QQ) 442 553 sage: a = s([2,1])+2*s([3,2]) 443 sage: a.map_ basis(lambda x: x.conjugate())554 sage: a.map_support(lambda x: x.conjugate()) 444 555 s[2, 1] + 2*s[2, 2, 1] 445 556 """ 446 557 res = self.parent()(0) … … 450 561 res._monomial_coefficients = z_elt 451 562 return res 452 563 453 def map (self, f):564 def map_monomial(self, f): 454 565 """ 455 566 Returns a new element of self.parent() obtained 456 567 by applying the function f to a monomial coefficient 457 568 (m,c) pair. f returns a (new_m, new_c) pair. 458 569 459 FIXME: map_monomial?460 461 570 EXAMPLES: 462 571 sage: s = SFASchur(QQ) 463 572 sage: f = lambda m,c: (m.conjugate(), 2*c) 464 573 sage: a = s([2,1]) + s([1,1,1]) 465 sage: a.map_m c(f)574 sage: a.map_monomial(f) 466 575 2*s[2, 1] + 2*s[3] 467 576 """ 468 577 z_elt = {} … … 471 580 z_elt[new_m] = new_c 472 581 return self.parent()._from_dict(z_elt) 473 582 474 map_mc = map 583 map_mc = map_monomial 475 584 476 585 def _l_action(self, x): 586 """ 587 Returns the action of a scalar on self when self is on the left (and the 588 scalar is on the right). 589 590 EXAMPLES: 591 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 592 sage: B = F.basis() 593 sage: B['a']*1/2 594 1/2*B('a') 595 596 """ 597 x = self.base_ring()(x) 598 return self.map_coefficients(lambda c: c*x) 599 600 def _r_action(self, x): 601 """ 602 Returns the action of a scalar on self when self is on the right (and the 603 scalar is on the left). 604 605 EXAMPLES: 606 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 607 sage: B = F.basis() 608 sage: 1/2*B['a'] 609 1/2*B('a') 610 611 """ 477 612 x = self.base_ring()(x) 478 613 return self.map_coefficients(lambda c: x*c) 479 480 def _r_action(self, x):481 x = self.base_ring()(x)482 return self.map_coefficients(lambda c: c*x)483 614 484 615 def __div__(self, x): 485 616 """ 486 617 Division by coefficients 487 618 488 619 EXAMPLES: 489 sage: F = CombinatorialFreeModule (QQ, [1,2,3])620 sage: F = CombinatorialFreeModule(QQ, [1,2,3]) 490 621 sage: x = F._from_dict({1:2, 2:3}) 491 622 sage: x/2 492 623 B(1) + 3/2*B(2) 624 625 sage: F = CombinatorialFreeModule(QQ, [1,2,3]) 626 sage: B = F.basis() 627 sage: f = 2*B[2] + 4*B[3] 628 sage: f/2 629 B(2) + 2*B(3) 630 493 631 """ 494 # FIXME: make this robust, especially over rings! 495 x = self.base_ring()(x) 496 return self.map_coefficients(lambda c: c/x) 632 if self.base_ring().is_field(): 633 x = self.base_ring()(x) 634 return self.map_coefficients(lambda c: c/x) 635 else: 636 return self.map_coefficients(lambda c: _divide_if_possible(c, x)) 497 637 498 # NT: There is nothing combinatorial here 499 # NT: It's really too bad that we can't have the ring as second optional argument 500 class CombinatorialFreeModuleInterface(): # Should not it inherit from ParentWithBase? 638 def _divide_if_possible(x, y): 639 """ 640 EXAMPLES: 641 sage: from sage.combinat.free_module import _divide_if_possible 642 sage: _divide_if_possible(4, 2) 643 2 644 sage: _.parent() 645 Integer Ring 646 647 sage: _divide_if_possible(4, 3) 648 Traceback (most recent call last): 649 ... 650 ValueError: 4 is not divisible by 3 651 """ 652 q, r = x.quo_rem(y) 653 if r != 0: 654 raise ValueError, "%s is not divisible by %s"%(x, y) 655 else: 656 return q 657 658 659 class CombinatorialFreeModuleInterface(sage.structure.parent_base.ParentWithBase): 501 660 def __init__(self, R, element_class): 661 """ 662 """ 502 663 #Make sure R is a ring with unit element 503 664 if not isinstance(R, Ring): 504 665 raise TypeError, "Argument R must be a ring." … … 521 682 # Should be an attribute? 522 683 def basis(self): 523 684 """ 524 Returns a list of the basis elements of self.685 Returns the basis of self. 525 686 526 687 EXAMPLES: 688 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 689 sage: F.basis() 690 Finite family {'a': B('a'), 'c': B('c'), 'b': B('b')} 691 527 692 sage: QS3 = SymmetricGroupAlgebra(QQ,3) 528 693 sage: list(QS3.basis()) 529 694 [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] 530 531 sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])532 sage: F.basis()533 Finite family {'a': B('a'), 'c': B('c'), 'b': B('b')}534 695 535 696 """ 536 697 return Family(self._combinatorial_class, self.term) … … 540 701 Coerce x into self. 541 702 542 703 EXAMPLES: 704 sage: F = CombinatorialFreeModule(QQ,[0,1]) 705 sage: F(0) 706 0 707 sage: F(1) 708 Traceback (most recent call last): 709 ... 710 TypeError: do not know how to make x (= 1) an element of Free module generated by [0, 1] over Rational Field 711 543 712 sage: QS3 = SymmetricGroupAlgebra(QQ,3) 544 713 sage: QS3(2) 545 714 2*[1, 2, 3] 546 715 sage: QS3([2,3,1]) 547 716 [2, 3, 1] 548 sage: F = CombinatorialFreeModule(QQ,[0,1])549 sage: F(0)550 0551 717 """ 552 718 R = self.base_ring() 553 719 eclass = self._element_class … … 556 722 if isinstance(x, int): 557 723 x = Integer(x) 558 724 559 # Workaround when the indexing set contains 0560 if isinstance(x, Integer) and x == 0:561 return self.zero()562 563 725 if hasattr(self, '_coerce_start'): 564 726 try: 565 727 return self._coerce_start(x) 566 728 except TypeError: 567 729 pass 568 730 569 # NT: coercion from the indexing set is louzy: 570 # in FreeModule(ZZ, [1,2,3]), how do tell the difference between 571 # an element of the ground ring and one of the indexing set? 572 573 #x is an element of the same type of combinatorial algebra 731 #x is an element of the same type of combinatorial free module 574 732 if hasattr(x, 'parent') and x.parent().__class__ is self.__class__: 575 733 P = x.parent() 576 734 #same base ring … … 580 738 else: 581 739 return eclass(self, dict([ (e1,R(e2)) for e1,e2 in x._monomial_coefficients.items()])) 582 740 #x is an element of the basis combinatorial class 741 elif x in R: 742 if x == 0: 743 return self.zero() 744 else: 745 raise TypeError, "do not know how to make x (= %s) an element of %s"%(x, self) 583 746 elif isinstance(self._combinatorial_class.object_class, type) and isinstance(x, self._combinatorial_class.object_class): 584 747 return eclass(self, {x:R(1)}) 585 748 elif x in self._combinatorial_class: … … 594 757 595 758 def _an_element_impl(self): 596 759 """ 597 Returns an element of self, namely the unitelement.760 Returns an element of self, namely the zero element. 598 761 599 762 EXAMPLES: 600 763 sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) … … 620 783 elements. 621 784 622 785 EXAMPLES: 786 sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 787 sage: F.combinatorial_class() 788 Combinatorial class with elements in ['a', 'b', 'c'] 789 623 790 sage: s = SFASchur(QQ) 624 791 sage: s.combinatorial_class() 625 792 Partitions 626 793 """ 627 794 return self._combinatorial_class 628 629 def _coerce_impl(self, x):630 """631 EXAMPLES:632 sage: s = SFASchur(QQ)633 sage: s._coerce_impl(2)634 2*s[]635 """636 try:637 R = x.parent()638 if R.__class__ is self.__class__:639 #Only perform the coercion if we can go from the base640 #ring of x to the base ring of self641 if self.base_ring().has_coerce_map_from( R.base_ring() ):642 return self(x)643 except AttributeError:644 pass645 646 # any ring that coerces to the base ring647 return self._coerce_try(x, [self.base_ring()])648 795 649 796 def dimension(self): 650 797 """ … … 652 799 by the number of elements in the associated combinatorial class). 653 800 654 801 EXAMPLES: 802 sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 803 sage: F.dimension() 804 3 805 655 806 sage: s = SFASchur(QQ) 656 807 sage: s.dimension() 657 808 +Infinity … … 695 846 Returns the prefix used when displaying elements of self. 696 847 697 848 EXAMPLES: 849 sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 850 sage: F.prefix() 851 'B' 852 698 853 sage: X = SchubertPolynomialRing(QQ) 699 854 sage: X.prefix() 700 855 'X' … … 782 937 return self._from_dict({i:self.base_ring().one_element()}) 783 938 784 939 def zero(self): 785 # TODO: cache786 940 """ 787 941 EXAMPLES: 788 942 sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 789 943 sage: F.zero() 790 944 0 791 945 """ 946 # TODO: cache 792 947 return self._from_dict({}) 793 948 794 949 def sum(self, operands): … … 834 989 We construct a free module whose basis is indexed by the letters a,b,c: 835 990 836 991 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 837 sage: F # todo: not implemented: F.basis().keys() should be ['a','b','c']992 sage: F 838 993 Free module generated by ['a', 'b', 'c'] over Rational Field 839 994 840 995 Its basis is a family, indexed by a,b,c: 841 996 Caveat in family: the order of the indices is not preserved 842 997 sage: e = F.basis() 843 998 844 sage: e.keys() # todo: not implemented999 sage: list(sorted(e.keys())) 845 1000 ['a', 'b', 'c'] 846 sage: list( e) # todo: not implemented1001 sage: list(sorted(e)) 847 1002 [B('a'), B('b'), B('c')] 848 1003 849 1004 Let us construct some elements, and compute with them: … … 854 1009 sage: e['a'] + 3*e['b'] 855 1010 B('a') + 3*B('b') 856 1011 """ 857 858 859 1012 def __init__(self, R, cc, element_class = CombinatorialFreeModuleElement, prefix="B"): 1013 """ 1014 EXAMPLES: 1015 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 1016 sage: F == loads(dumps(F)) 1017 True 1018 """ 1019 self._name = "Free module generated by %s"%cc 860 1020 if isinstance(cc, list): 861 1021 cc = FiniteCombinatorialClass(cc) 862 1022 if not isinstance(cc, CombinatorialClass): 863 1023 raise TypeError, "cc = (%s) must be an instance of CombinatorialClass"%cc 864 1024 self._combinatorial_class = cc 865 1025 self._prefix = prefix 866 self._name = "Free module generated by %s"%cc867 1026 CombinatorialFreeModuleInterface.__init__(self, R, element_class) 868 pass 1027 -
a/sage/combinat/sf/classical.py
old new 342 342 return "Symmetric Function Algebra over %s, %s symmetric functions as basis"%(self.base_ring(), self._basis.capitalize()) 343 343 344 344 345 def prefix(self):346 """347 Returns the prefix on the elements of self.348 349 EXAMPLES:350 sage: s = SFASchur(QQ)351 sage: s.prefix()352 's'353 """354 return self._prefix355 356 def transition_matrix(self, basis, n):357 """358 Returns the transitions matrix between self and basis359 for the homogenous component of degree n.360 361 EXAMPLES:362 sage: s = SFASchur(QQ)363 sage: m = SFAMonomial(QQ)364 sage: s.transition_matrix(m,5)365 [1 1 1 1 1 1 1]366 [0 1 1 2 2 3 4]367 [0 0 1 1 2 3 5]368 [0 0 0 1 1 3 6]369 [0 0 0 0 1 2 5]370 [0 0 0 0 0 1 4]371 [0 0 0 0 0 0 1]372 373 sage: p = SFAPower(QQ)374 sage: s.transition_matrix(p, 4)375 [ 1/4 1/3 1/8 1/4 1/24]376 [-1/4 0 -1/8 1/4 1/8]377 [ 0 -1/3 1/4 0 1/12]378 [ 1/4 0 -1/8 -1/4 1/8]379 [-1/4 1/3 1/8 -1/4 1/24]380 sage: StoP = s.transition_matrix(p,4)381 sage: a = s([3,1])+5*s([1,1,1,1])-s([4])382 sage: a383 5*s[1, 1, 1, 1] + s[3, 1] - s[4]384 sage: mon, coef = a.support()385 sage: coef386 [5, 1, -1]387 sage: mon388 [[1, 1, 1, 1], [3, 1], [4]]389 sage: cm = matrix([[-1,1,0,0,5]])390 sage: cm * StoP391 [-7/4 4/3 3/8 -5/4 7/24]392 sage: p(a)393 7/24*p[1, 1, 1, 1] - 5/4*p[2, 1, 1] + 3/8*p[2, 2] + 4/3*p[3, 1] - 7/4*p[4]394 395 396 sage: h = SFAHomogeneous(QQ)397 sage: e = SFAElementary(QQ)398 sage: s.transition_matrix(m,7) == h.transition_matrix(s,7).transpose()399 True400 401 sage: h.transition_matrix(m, 7) == h.transition_matrix(m, 7).transpose()402 True403 404 sage: h.transition_matrix(e, 7) == e.transition_matrix(h, 7)405 True406 407 408 sage: p.transition_matrix(s, 5)409 [ 1 -1 0 1 0 -1 1]410 [ 1 0 -1 0 1 0 -1]411 [ 1 -1 1 0 -1 1 -1]412 [ 1 1 -1 0 -1 1 1]413 [ 1 0 1 -2 1 0 1]414 [ 1 2 1 0 -1 -2 -1]415 [ 1 4 5 6 5 4 1]416 417 sage: e.transition_matrix(m,7) == e.transition_matrix(m,7).transpose()418 True419 420 421 """422 P = sage.combinat.partition.Partitions_n(n)423 Plist = P.list()424 m = []425 for row_part in Plist:426 z = basis(self(row_part))427 m.append( map( lambda col_part: z.coefficient(col_part), Plist ) )428 return matrix(m)429 345 430 346 431 347 class SymmetricFunctionAlgebraElement_classical(sfa.SymmetricFunctionAlgebraElement_generic): 432 348 """ 433 349 A symmetric function. 434 350 """ 435 351 pass 436 352 437 353 ## def __pow__(self, n): 438 354 ## """ -
a/sage/combinat/sf/kschur.py
old new 67 67 out = {} 68 68 fail = False 69 69 while el != 0: 70 l = el. monomials()70 l = el.support() 71 71 l.sort() 72 72 part2 = l[0] 73 73 n = part2.size() … … 166 166 167 167 if isinstance(x, sfa.SymmetricFunctionAlgebraElement_generic): 168 168 x = self._s(x).restrict_parts(self.k) 169 for p in x. monomials():169 for p in x.support(): 170 170 self._s_cache(p.size()) 171 171 return self._change_by_triangularity(x, self._self_to_s_cache, True) 172 172 else: -
a/sage/combinat/sf/schur.py
old new 108 108 s[3, 1] 109 109 """ 110 110 conj = lambda part: part.conjugate() 111 return self.map_ basis(conj)111 return self.map_support(conj) 112 112 113 113 114 114 def scalar(self, x): -
a/sage/combinat/sf/sfa.py
old new 113 113 sage: z.length() 114 114 2 115 115 sage: z.support() 116 [[ [1, 1, 1], [2, 1]], [1, 1]]116 [[1, 1, 1], [2, 1]] 117 117 sage: z.degree() 118 118 3 119 119 … … 771 771 sage: a = s([3,1])+5*s([1,1,1,1])-s([4]) 772 772 sage: a 773 773 5*s[1, 1, 1, 1] + s[3, 1] - s[4] 774 sage: mon, coef = a.support() 775 sage: coef 774 sage: mon = a.support() 775 sage: coeffs = a.coefficients() 776 sage: coeffs 776 777 [5, 1, -1] 777 778 sage: mon 778 779 [[1, 1, 1, 1], [3, 1], [4]] … … 1120 1121 #Takes n an symmetric function f, and an n and returns the 1121 1122 #symmetric function with all of its basis partitions scaled 1122 1123 #by n 1123 pn_pleth = lambda f, n: f.map_ basis(scale_part(n))1124 pn_pleth = lambda f, n: f.map_support(scale_part(n)) 1124 1125 1125 1126 #Takes in a partition and applies 1126 1127 f = lambda part: prod( pn_pleth(p_x.map_coefficients(raise_c(i)), i) for i in part ) … … 1154 1155 1155 1156 p = SFAPower(QQ) 1156 1157 res = 0 1157 degrees = uniq([ sum(m) for m in g. monomials() ])1158 degrees = uniq([ sum(m) for m in g.support() ]) 1158 1159 for d in degrees: 1159 1160 for mu in sage.combinat.partition.Partitions(d): 1160 1161 mu_k = mu.power(k) … … 1190 1191 if len(nu) == 0: 1191 1192 s = SFASchur(self.base_ring()) 1192 1193 p = SFAPower(self.base_ring()) 1193 degrees = [ part.size() for part in p_x. monomials() ]1194 degrees = [ part.size() for part in p_x.support() ] 1194 1195 degrees = uniq(degrees) 1195 1196 return p(sum([s([n]) for n in degrees])) 1196 1197 -
a/sage/combinat/symmetric_group_algebra.py
old new 283 283 if permutation.PermutationOptions()['mult'] == 'l2r': 284 284 return z 285 285 else: 286 return z.map_ basis(lambda x: x.inverse())286 return z.map_support(lambda x: x.inverse()) 287 287 288 288 289 289