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  
    317317        """ 
    318318        return self._element_class(self, {self._one:self.base_ring()(1)}) 
    319319 
     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()]) 
    320339             
    321340    def multiply(self,left,right): 
    322341        """ 
  • a/sage/combinat/free_module.py

    old new  
     1""" 
     2Free modules 
     3""" 
    14#***************************************************************************** 
    25#       Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>,  
    36# 
     
    2225from sage.combinat.finite_class import FiniteCombinatorialClass 
    2326from sage.combinat.combinat import CombinatorialClass 
    2427 
    25 # TODO: 
    26 # Rewrite all tests in a more self contained way 
    27  
    2828class CombinatorialFreeModuleElement(ModuleElement): 
    2929    def __init__(self, M, x): 
    3030        """ 
    3131        Create a combinatorial module element x.  This should never 
    3232        be called directly, but only through the parent combinatorial 
    3333        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 
    3442 
    3543        """ 
    3644        ModuleElement.__init__(self, M) 
     
    3947    def __iter__(self): 
    4048        """ 
    4149        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 
    4256            sage: s = SFASchur(QQ) 
    4357            sage: a = s([2,1]) + s([3]) 
    4458            sage: [i for i in sorted(a)] 
     
    5367        element is in the support of self. 
    5468         
    5569        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 
    5678            sage: s = SFASchur(QQ) 
    5779            sage: a = s([2,1]) + s([3]) 
    5880            sage: Partition([2,1]) in a 
     
    6991        coefficients as values. 
    7092 
    7193        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 
    72103            sage: s = SFASchur(QQ) 
    73104            sage: a = s([2,1])+2*s([3,2]) 
    74105            sage: d = a.monomial_coefficients() 
     
    104135    def _latex_(self): 
    105136        """ 
    106137        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 
    107144            sage: QS3 = SymmetricGroupAlgebra(QQ,3) 
    108145            sage: a = 2 + QS3([2,1,3]) 
    109146            sage: latex(a) #indirect doctest 
     
    145182    def _add_(self, y): 
    146183        """ 
    147184        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 
    148190            sage: s = SFASchur(QQ) 
    149191            sage: s([2,1]) + s([5,4]) # indirect doctest 
    150192            s[2, 1] + s[5, 4] 
     
    181223    def _neg_(self): 
    182224        """ 
    183225        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 
    184232            sage: s = SFASchur(QQ) 
    185233            sage: -s([2,1]) # indirect doctest 
    186234            -s[2, 1] 
     
    191239    def _sub_(self, y): 
    192240        """ 
    193241        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 
    194247            sage: s = SFASchur(QQ) 
    195248            sage: s([2,1]) - s([5,4]) # indirect doctest 
    196249            s[2, 1] - s[5, 4] 
     
    234287            Traceback (most recent call last): 
    235288            ... 
    236289            TypeError: list objects are unhashable 
     290 
    237291            sage: a._coefficient_fast(p) 
    238292            1 
    239293            sage: a._coefficient_fast(p, 2) 
     
    255309 
    256310    def coefficient(self, m): 
    257311        """ 
    258  
    259         # NT: coefficient_fast should be the default, just with appropriate assertions 
    260         # that can be turned on or of 
    261          
    262312        EXAMPLES: 
    263313            sage: s = SFASchur(QQ) 
    264314            sage: z = s([4]) - 2*s([2,1]) + s([1,1,1]) + s([1]) 
     
    267317            sage: z.coefficient([2,1]) 
    268318            -2 
    269319        """ 
     320        # NT: coefficient_fast should be the default, just with appropriate assertions 
     321        # that can be turned on or off 
    270322        p = self.parent() 
    271323        if isinstance(m, p._combinatorial_class.object_class): 
    272324            return self._monomial_coefficients.get(m, p.base_ring().zero_element()) 
     
    281333        Returns True if and only self == 0. 
    282334 
    283335        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 
    284344            sage: s = SFASchur(QQ) 
    285345            sage: s([2,1]).is_zero() 
    286346            False 
     
    301361        nonzero coefficients. 
    302362         
    303363        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             
    304370            sage: s = SFASchur(QQ) 
    305371            sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) 
    306372            sage: len(z) 
     
    314380        nonzero coefficients. 
    315381         
    316382        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 
    317389            sage: s = SFASchur(QQ) 
    318390            sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) 
    319391            sage: z.length() 
    320392            4 
    321393        """ 
    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 ]) 
    324395 
    325396    def support(self): 
    326         """ 
    327         # NT: ??? 
    328         Returns a pair [mons, cffs] of lists of the monomials 
    329         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): 
    344397        """ 
    345398        Returns a list of the combinatorial objects indexing 
    346399        the basis elements of self which non-zero coefficients. 
    347400 
    348401        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 
    349408            sage: s = SFASchur(QQ) 
    350409            sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) 
    351             sage: z.monomials() 
     410            sage: z.support() 
    352411            [[1], [1, 1, 1], [2, 1], [4]] 
    353412        """ 
    354413        v = self._monomial_coefficients.items() 
    355414        v.sort() 
    356415        mons = [ m for (m, _) in v ] 
    357416        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] 
    358446     
    359447    def coefficients(self): 
    360448        """ 
     
    362450        basiselements in self. 
    363451 
    364452        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 
    365459            sage: s = SFASchur(QQ) 
    366460            sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) 
    367461            sage: z.coefficients() 
     
    378472        then in returns a vector over new_BR. 
    379473 
    380474        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 
    381481            sage: QS3 = SymmetricGroupAlgebra(QQ, 3) 
    382482            sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) 
    383483            sage: a._vector_() 
     
    389489        """ 
    390490        parent = self.parent() 
    391491        if parent.get_order() is None: 
    392             cc = parent._combinatorial_class 
     492            cc = parent._combinatorial_class.list() 
     493            cc.sort() 
    393494        else: 
    394495            cc = parent.get_order() 
    395496             
     
    403504        Returns a vector version of self. 
    404505 
    405506        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 
    406513            sage: QS3 = SymmetricGroupAlgebra(QQ, 3) 
    407514            sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) 
    408515            sage: a.to_vector() 
     
    418525        of self. 
    419526 
    420527        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 
    421534            sage: s = SFASchur(QQ) 
    422535            sage: a = s([2,1])+2*s([3,2]) 
    423536            sage: a.map_coefficients(lambda x: x*2) 
     
    429542        return self.parent()._from_dict(z_elt) 
    430543 
    431544 
    432     def map_basis(self, f): 
     545    def map_support(self, f): 
    433546        """ 
    434547        Returns a new element of self.parent() obtained 
    435548        by applying the function f to all of the combinatorial 
    436549        objects indexing the basis elements. 
    437550 
    438         FIXME: rename to map_support? 
    439  
    440551        EXAMPLES: 
    441552            sage: s = SFASchur(QQ) 
    442553            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()) 
    444555            s[2, 1] + 2*s[2, 2, 1] 
    445556        """ 
    446557        res = self.parent()(0) 
     
    450561        res._monomial_coefficients = z_elt 
    451562        return res 
    452563 
    453     def map(self, f): 
     564    def map_monomial(self, f): 
    454565        """ 
    455566        Returns a new element of self.parent() obtained 
    456567        by applying the function f to a monomial coefficient 
    457568        (m,c) pair.  f returns a (new_m, new_c) pair. 
    458569 
    459         FIXME: map_monomial? 
    460  
    461570        EXAMPLES: 
    462571            sage: s = SFASchur(QQ) 
    463572            sage: f = lambda m,c: (m.conjugate(), 2*c) 
    464573            sage: a = s([2,1]) + s([1,1,1]) 
    465             sage: a.map_mc(f) 
     574            sage: a.map_monomial(f) 
    466575            2*s[2, 1] + 2*s[3] 
    467576        """ 
    468577        z_elt = {} 
     
    471580            z_elt[new_m] = new_c 
    472581        return self.parent()._from_dict(z_elt) 
    473582 
    474     map_mc = map 
     583    map_mc = map_monomial 
    475584 
    476585    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        """         
    477612        x = self.base_ring()(x) 
    478613        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) 
    483614 
    484615    def __div__(self, x): 
    485616        """ 
    486617        Division by coefficients 
    487618 
    488619        EXAMPLES: 
    489             sage: F = CombinatorialFreeModule (QQ, [1,2,3]) 
     620            sage: F = CombinatorialFreeModule(QQ, [1,2,3]) 
    490621            sage: x = F._from_dict({1:2, 2:3}) 
    491622            sage: x/2 
    492623            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 
    493631        """ 
    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)) 
    497637 
    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? 
     638def _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 
     659class CombinatorialFreeModuleInterface(sage.structure.parent_base.ParentWithBase):  
    501660    def __init__(self, R, element_class): 
     661        """ 
     662        """ 
    502663        #Make sure R is a ring with unit element 
    503664        if not isinstance(R, Ring): 
    504665            raise TypeError, "Argument R must be a ring." 
     
    521682    # Should be an attribute? 
    522683    def basis(self): 
    523684        """ 
    524         Returns a list of the basis elements of self. 
     685        Returns the basis of self. 
    525686 
    526687        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 
    527692            sage: QS3 = SymmetricGroupAlgebra(QQ,3) 
    528693            sage: list(QS3.basis()) 
    529694            [[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')} 
    534695 
    535696        """ 
    536697        return Family(self._combinatorial_class, self.term) 
     
    540701        Coerce x into self. 
    541702 
    542703        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 
    543712            sage: QS3 = SymmetricGroupAlgebra(QQ,3) 
    544713            sage: QS3(2) 
    545714            2*[1, 2, 3] 
    546715            sage: QS3([2,3,1]) 
    547716            [2, 3, 1] 
    548             sage: F = CombinatorialFreeModule(QQ,[0,1]) 
    549             sage: F(0) 
    550             0 
    551717        """ 
    552718        R = self.base_ring() 
    553719        eclass = self._element_class 
     
    556722        if isinstance(x, int): 
    557723            x = Integer(x) 
    558724 
    559         # Workaround when the indexing set contains 0 
    560         if isinstance(x, Integer) and x == 0: 
    561             return self.zero() 
    562  
    563725        if hasattr(self, '_coerce_start'): 
    564726            try: 
    565727                return self._coerce_start(x) 
    566728            except TypeError: 
    567729                pass 
    568730 
    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 
    574732        if hasattr(x, 'parent') and x.parent().__class__ is self.__class__: 
    575733            P = x.parent() 
    576734            #same base ring 
     
    580738            else: 
    581739                return eclass(self, dict([ (e1,R(e2)) for e1,e2 in x._monomial_coefficients.items()])) 
    582740        #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) 
    583746        elif isinstance(self._combinatorial_class.object_class, type) and isinstance(x, self._combinatorial_class.object_class): 
    584747            return eclass(self, {x:R(1)})  
    585748        elif x in self._combinatorial_class: 
     
    594757 
    595758    def _an_element_impl(self): 
    596759        """ 
    597         Returns an element of self, namely the unit element. 
     760        Returns an element of self, namely the zero element. 
    598761 
    599762        EXAMPLES: 
    600763            sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 
     
    620783        elements. 
    621784 
    622785        EXAMPLES: 
     786            sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 
     787            sage: F.combinatorial_class() 
     788            Combinatorial class with elements in ['a', 'b', 'c'] 
     789 
    623790            sage: s = SFASchur(QQ) 
    624791            sage: s.combinatorial_class() 
    625792            Partitions 
    626793        """ 
    627794        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 base 
    640                 #ring of x to the base ring of self 
    641                 if self.base_ring().has_coerce_map_from( R.base_ring() ): 
    642                     return self(x) 
    643         except AttributeError: 
    644             pass 
    645          
    646         # any ring that coerces to the base ring 
    647         return self._coerce_try(x, [self.base_ring()]) 
    648795                                 
    649796    def dimension(self): 
    650797        """ 
     
    652799        by the number of elements in the associated combinatorial class). 
    653800 
    654801        EXAMPLES: 
     802            sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 
     803            sage: F.dimension() 
     804            3 
     805 
    655806            sage: s = SFASchur(QQ) 
    656807            sage: s.dimension() 
    657808            +Infinity 
     
    695846        Returns the prefix used when displaying elements of self. 
    696847 
    697848        EXAMPLES: 
     849            sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 
     850            sage: F.prefix() 
     851            'B' 
     852 
    698853            sage: X = SchubertPolynomialRing(QQ) 
    699854            sage: X.prefix() 
    700855            'X' 
     
    782937        return self._from_dict({i:self.base_ring().one_element()}) 
    783938 
    784939    def zero(self): 
    785         # TODO: cache 
    786940        """ 
    787941        EXAMPLES: 
    788942            sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) 
    789943            sage: F.zero() 
    790944            0 
    791945        """ 
     946        # TODO: cache 
    792947        return self._from_dict({}) 
    793948     
    794949    def sum(self, operands): 
     
    834989        We construct a free module whose basis is indexed by the letters a,b,c: 
    835990 
    836991            sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) 
    837             sage: F  # todo: not implemented: F.basis().keys() should be ['a','b','c'] 
     992            sage: F 
    838993            Free module generated by ['a', 'b', 'c'] over Rational Field 
    839994 
    840995        Its basis is a family, indexed by a,b,c: 
    841996        Caveat in family: the order of the indices is not preserved 
    842997            sage: e = F.basis() 
    843998 
    844             sage: e.keys()  # todo: not implemented 
     999            sage: list(sorted(e.keys())) 
    8451000            ['a', 'b', 'c'] 
    846             sage: list(e)   # todo: not implemented 
     1001            sage: list(sorted(e)) 
    8471002            [B('a'), B('b'), B('c')] 
    8481003 
    8491004        Let us construct some elements, and compute with them: 
     
    8541009            sage: e['a'] + 3*e['b'] 
    8551010            B('a') + 3*B('b') 
    8561011    """ 
    857  
    858  
    8591012    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 
    8601020        if isinstance(cc, list): 
    8611021            cc = FiniteCombinatorialClass(cc) 
    8621022        if not isinstance(cc, CombinatorialClass): 
    8631023            raise TypeError, "cc = (%s) must be an instance of CombinatorialClass"%cc 
    8641024        self._combinatorial_class = cc 
    8651025        self._prefix = prefix 
    866         self._name = "Free module generated by %s"%cc 
    8671026        CombinatorialFreeModuleInterface.__init__(self, R, element_class) 
    868     pass 
     1027 
  • a/sage/combinat/sf/classical.py

    old new  
    342342        return "Symmetric Function Algebra over %s, %s symmetric functions as basis"%(self.base_ring(), self._basis.capitalize()) 
    343343 
    344344 
    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._prefix 
    355  
    356     def transition_matrix(self, basis, n): 
    357         """ 
    358         Returns the transitions matrix between self and basis 
    359         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: a 
    383             5*s[1, 1, 1, 1] + s[3, 1] - s[4] 
    384             sage: mon, coef = a.support() 
    385             sage: coef 
    386             [5, 1, -1] 
    387             sage: mon 
    388             [[1, 1, 1, 1], [3, 1], [4]] 
    389             sage: cm = matrix([[-1,1,0,0,5]]) 
    390             sage: cm * StoP 
    391             [-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             True 
    400  
    401             sage: h.transition_matrix(m, 7) == h.transition_matrix(m, 7).transpose() 
    402             True 
    403  
    404             sage: h.transition_matrix(e, 7) == e.transition_matrix(h, 7) 
    405             True 
    406  
    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             True 
    419  
    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) 
    429345 
    430346 
    431347class SymmetricFunctionAlgebraElement_classical(sfa.SymmetricFunctionAlgebraElement_generic): 
    432348    """ 
    433349    A symmetric function. 
    434350    """ 
    435  
     351    pass 
    436352 
    437353##     def __pow__(self, n): 
    438354##         """ 
  • a/sage/combinat/sf/kschur.py

    old new  
    6767        out = {} 
    6868        fail = False 
    6969        while el != 0: 
    70             l = el.monomials() 
     70            l = el.support() 
    7171            l.sort() 
    7272            part2 = l[0] 
    7373            n = part2.size() 
     
    166166 
    167167        if isinstance(x, sfa.SymmetricFunctionAlgebraElement_generic): 
    168168            x = self._s(x).restrict_parts(self.k) 
    169             for p in x.monomials(): 
     169            for p in x.support(): 
    170170                self._s_cache(p.size()) 
    171171            return self._change_by_triangularity(x, self._self_to_s_cache, True) 
    172172        else: 
  • a/sage/combinat/sf/schur.py

    old new  
    108108            s[3, 1] 
    109109        """ 
    110110        conj = lambda part: part.conjugate() 
    111         return self.map_basis(conj) 
     111        return self.map_support(conj) 
    112112 
    113113 
    114114    def scalar(self, x): 
  • a/sage/combinat/sf/sfa.py

    old new  
    113113sage: z.length() 
    1141142 
    115115sage: z.support() 
    116 [[[1, 1, 1], [2, 1]], [1, 1]] 
     116[[1, 1, 1], [2, 1]] 
    117117sage: z.degree() 
    1181183 
    119119 
     
    771771            sage: a = s([3,1])+5*s([1,1,1,1])-s([4]) 
    772772            sage: a 
    773773            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 
    776777            [5, 1, -1] 
    777778            sage: mon 
    778779            [[1, 1, 1, 1], [3, 1], [4]] 
     
    11201121        #Takes n an symmetric function f, and an n and returns the 
    11211122        #symmetric function with all of its basis partitions scaled 
    11221123        #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)) 
    11241125 
    11251126        #Takes in a partition and applies         
    11261127        f = lambda part: prod( pn_pleth(p_x.map_coefficients(raise_c(i)), i) for i in part ) 
     
    11541155         
    11551156        p = SFAPower(QQ) 
    11561157        res = 0 
    1157         degrees = uniq([ sum(m) for m in g.monomials() ]) 
     1158        degrees = uniq([ sum(m) for m in g.support() ]) 
    11581159        for d in degrees: 
    11591160            for mu in sage.combinat.partition.Partitions(d): 
    11601161                mu_k = mu.power(k) 
     
    11901191        if len(nu) == 0: 
    11911192            s = SFASchur(self.base_ring()) 
    11921193            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() ] 
    11941195            degrees = uniq(degrees) 
    11951196            return p(sum([s([n]) for n in degrees])) 
    11961197 
  • a/sage/combinat/symmetric_group_algebra.py

    old new  
    283283        if permutation.PermutationOptions()['mult'] == 'l2r': 
    284284            return z 
    285285        else: 
    286             return z.map_basis(lambda x: x.inverse()) 
     286            return z.map_support(lambda x: x.inverse()) 
    287287         
    288288   
    289289