Ticket #3662: trac_3662-3.patch
| File trac_3662-3.patch, 6.0 kB (added by mhansen, 4 months ago) |
|---|
-
a/sage/combinat/free_module.py
old new 227 227 228 228 EXAMPLES: 229 229 sage: p = Partition([2,1]) 230 sage: q = Partition([1,1,1]) 230 231 sage: s = SFASchur(QQ) 231 sage: a = s( [2,1])232 sage: a = s(p) 232 233 sage: a._coefficient_fast([2,1]) 233 234 Traceback (most recent call last): 234 235 ... … … 237 238 1 238 239 sage: a._coefficient_fast(p, 2) 239 240 1 241 sage: a._coefficient_fast(q) 242 0 243 sage: a._coefficient_fast(q, 2) 244 2 245 sage: a[p] 246 1 247 sage: a[q] 248 0 240 249 """ 241 250 if default is None: 242 251 default = self.base_ring()(0) 243 252 return self._monomial_coefficients.get(m, default) 253 254 __getitem__ = _coefficient_fast 244 255 245 256 def coefficient(self, m): 246 257 """ … … 470 481 x = self.base_ring()(x) 471 482 return self.map_coefficients(lambda c: c*x) 472 483 484 def __div__(self, x): 485 """ 486 Division by coefficients 487 488 EXAMPLES: 489 sage: F = CombinatorialFreeModule (QQ, [1,2,3]) 490 sage: x = F._from_dict({1:2, 2:3}) 491 sage: x/2 492 B(1) + 3/2*B(2) 493 """ 494 # FIXME: make this robust, especially over rings! 495 x = self.base_ring()(x) 496 return self.map_coefficients(lambda c: c/x) 473 497 474 498 # NT: There is nothing combinatorial here 475 499 # NT: It's really too bad that we can't have the ring as second optional argument … … 521 545 2*[1, 2, 3] 522 546 sage: QS3([2,3,1]) 523 547 [2, 3, 1] 548 sage: F = CombinatorialFreeModule(QQ,[0,1]) 549 sage: F(0) 550 0 524 551 """ 525 552 R = self.base_ring() 526 553 eclass = self._element_class … … 529 556 if isinstance(x, int): 530 557 x = Integer(x) 531 558 559 # Workaround when the indexing set contains 0 560 if isinstance(x, Integer) and x == 0: 561 return self.zero() 532 562 533 563 if hasattr(self, '_coerce_start'): 534 564 try: … … 750 780 B('a') 751 781 """ 752 782 return self._from_dict({i:self.base_ring().one_element()}) 783 784 def zero(self): 785 # TODO: cache 786 """ 787 EXAMPLES: 788 sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 789 sage: F.zero() 790 0 791 """ 792 return self._from_dict({}) 753 793 794 def sum(self, operands): 795 """ 796 EXAMPLES: 797 sage: F = CombinatorialFreeModule(QQ, [1,2,3,4]) 798 sage: F.sum(F.term(i) for i in [1,2,3]) 799 B(1) + B(2) + B(3) 800 """ 801 return sum(operands, self.zero()) 802 754 803 def _from_dict(self, d, coerce=False): 755 804 """ 756 805 Given a monomial coefficient dictionary d, return the element … … 785 834 We construct a free module whose basis is indexed by the letters a,b,c: 786 835 787 836 sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 788 sage: F 837 sage: F # todo: not implemented: F.basis().keys() should be ['a','b','c'] 789 838 Free module generated by ['a', 'b', 'c'] over Rational Field 790 839 791 840 Its basis is a family, indexed by a,b,c: 792 FIXME in family: we should preserve the order of the indices841 Caveat in family: the order of the indices is not preserved 793 842 sage: e = F.basis() 794 843 795 sage: e.keys() 844 sage: e.keys() # todo: not implemented 796 845 ['a', 'b', 'c'] 797 sage: list(e) 846 sage: list(e) # todo: not implemented 798 847 [B('a'), B('b'), B('c')] 799 848 800 849 Let us construct some elements, and compute with them: … … 807 856 """ 808 857 809 858 810 def __init__(self, R, cc, prefix="B"):859 def __init__(self, R, cc, element_class = CombinatorialFreeModuleElement, prefix="B"): 811 860 if isinstance(cc, list): 812 861 cc = FiniteCombinatorialClass(cc) 813 862 if not isinstance(cc, CombinatorialClass): … … 815 864 self._combinatorial_class = cc 816 865 self._prefix = prefix 817 866 self._name = "Free module generated by %s"%cc 818 CombinatorialFreeModuleInterface.__init__(self, R, CombinatorialFreeModuleElement)867 CombinatorialFreeModuleInterface.__init__(self, R, element_class) 819 868 pass -
a/sage/combinat/sf/sfa.py
old new 354 354 f = lambda m,c: (m, c*prod([expr_k(k) for k in m])) 355 355 return self(p_x.map_mc(f)) 356 356 357 357 # TODO: 358 # - lift to combinatorial_module 359 # - rename to _apply_bimodule_morphism or generalize to true multi_module 360 # - generalization with a "neighbor function" that given x says 361 # for which y one has f(x,y) != 0 362 # - add option orthonormal 358 363 def _apply_multi_module_morphism(self, x, y, f, orthogonal=False): 359 364 """ 360 365 INPUT: … … 380 385 sage: s._apply_multi_module_morphism(a,b,f2,orthogonal=True) #2+2 381 386 4 382 387 """ 388 # broken for most coeff ring 383 389 res = 0 384 390 if orthogonal: 391 # could check which of x and y has less terms 392 # for mx, cx in x: 385 393 for mx, cx in x._monomial_coefficients.iteritems(): 394 # if not y.has_key(mx): 386 395 if mx not in y._monomial_coefficients: 387 396 continue 388 397 else: 398 # cy = y[mx] 389 399 cy = y._monomial_coefficients[mx] 400 # might as well call f(mx) 390 401 res += cx*cy*f(mx, mx) 391 402 return res 392 403 else: