Ticket #12464: trac_12464-free_module_classcall-fh.patch

File trac_12464-free_module_classcall-fh.patch, 4.4 KB (added by nthiery, 4 years ago)
  • sage/algebras/iwahori_hecke_algebra.py

    # HG changeset patch
    # User Nicolas M. Thiery <nthiery@users.sf.net>
    # Date 1328952421 -3600
    # Node ID 4e5a2bafa897ddfb80dbe88182b77e4a7f45a381
    # Parent  8afdf9a668cd4e57803729ef84482eefe4f4d292
    #12464: Better uniqueness for combinatorial free modules
    
    - The arguments (basis_keys, category, ...) are straightened before
      being passed down to UniqueRepresentation.
    - The existence base_ring.one() is not checked anymore
      (Rings are supposed to be unital!)
    
    diff --git a/sage/algebras/iwahori_hecke_algebra.py b/sage/algebras/iwahori_hecke_algebra.py
    a b class IwahoriHeckeAlgebraT(Combinatorial 
    171171        if base_ring is None:
    172172            base_ring = q1.parent()
    173173        q2 = base_ring(q2)
    174         return super(IwahoriHeckeAlgebraT, cls).__classcall_private__(cls, W, q1=q1, q2=q2, base_ring=base_ring, prefix=prefix)
     174        return super(IwahoriHeckeAlgebraT, cls).__classcall__(cls, W, q1=q1, q2=q2, base_ring = base_ring, prefix=prefix)
    175175
    176176    def __init__(self, W, q1, q2, base_ring, prefix):
    177177         """
  • sage/combinat/free_module.py

    diff --git a/sage/combinat/free_module.py b/sage/combinat/free_module.py
    a b class CombinatorialFreeModule(UniqueRepr 
    928928    """
    929929
    930930    @staticmethod
    931     def __classcall_private__(cls, *args, **keywords):
     931    def __classcall_private__(cls, base_ring, basis_keys, category = None, **keywords):
    932932        """
    933933        TESTS::
    934934
    class CombinatorialFreeModule(UniqueRepr 
    940940            sage: F = CombinatorialFreeModule(QQ, ['a','b','c'], latex_bracket=['LEFT', 'RIGHT'])
    941941            sage: F.print_options()['latex_bracket']
    942942            ('LEFT', 'RIGHT')
     943
     944            sage: F is G
     945            False
     946
     947        We check that the category is properly straightened::
     948
     949            sage: F  = CombinatorialFreeModule(QQ, ['a','b'])
     950            sage: F1 = CombinatorialFreeModule(QQ, ['a','b'], category = ModulesWithBasis(QQ))
     951            sage: F2 = CombinatorialFreeModule(QQ, ['a','b'], category = [ModulesWithBasis(QQ)])
     952            sage: F3 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),))
     953            sage: F4 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),CommutativeAdditiveSemigroups()))
     954            sage: F5 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),Category.join((LeftModules(QQ), RightModules(QQ)))))
     955            sage: F1 is F, F2 is F, F3 is F, F4 is F, F5 is F
     956            (True, True, True, True, True)
     957
     958            sage: G  = CombinatorialFreeModule(QQ, ['a','b'], category = AlgebrasWithBasis(QQ))
     959            sage: F is G
     960            False
    943961        """
    944         # Convert the argument args[1] into a FiniteEumeratedSet
    945         # if it is a list or a tuple in order it to have a cardinality() method.
    946         # note: if args is too short, we still propagate it down
    947         # to __init__ to let it handle proper exception raising.
    948         if len(args) >= 2 and isinstance(args[1], (list, tuple)):
    949             args = (args[0], FiniteEnumeratedSet(args[1])) + args[2:]
     962        if isinstance(basis_keys, (list, tuple)):
     963            basis_keys = FiniteEnumeratedSet(basis_keys)
     964        category = ModulesWithBasis(base_ring).or_subcategory(category)
    950965        # bracket or latex_bracket might be lists, so convert
    951966        # them to tuples so that they're hashable.
    952967        bracket = keywords.get('bracket', None)
    class CombinatorialFreeModule(UniqueRepr 
    955970        latex_bracket = keywords.get('latex_bracket', None)
    956971        if isinstance(latex_bracket, list):
    957972            keywords['latex_bracket'] = tuple(latex_bracket)
    958         return super(CombinatorialFreeModule, cls).__classcall__(cls, *args, **keywords)
     973        return super(CombinatorialFreeModule, cls).__classcall__(cls, base_ring, basis_keys, category = category, **keywords)
    959974
    960975    Element = CombinatorialFreeModuleElement
    961976
    class CombinatorialFreeModule(UniqueRepr 
    10051020        from sage.categories.all import Rings
    10061021        if R not in Rings():
    10071022            raise TypeError, "Argument R must be a ring."
    1008         try:
    1009             z = R.one()
    1010         except:
    1011             raise ValueError, "R must have a unit element"
    10121023
    10131024        if category is None:
    10141025            category = ModulesWithBasis(R)
     1026
    10151027        if element_class is not None:
    10161028            self.Element = element_class
    10171029