Ticket #12464: trac_12464free_module_classcallfh.patch
File trac_12464free_module_classcallfh.patch, 4.4 KB (added by , 6 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 171 171 if base_ring is None: 172 172 base_ring = q1.parent() 173 173 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) 175 175 176 176 def __init__(self, W, q1, q2, base_ring, prefix): 177 177 """ 
sage/combinat/free_module.py
diff git a/sage/combinat/free_module.py b/sage/combinat/free_module.py
a b class CombinatorialFreeModule(UniqueRepr 928 928 """ 929 929 930 930 @staticmethod 931 def __classcall_private__(cls, *args, **keywords):931 def __classcall_private__(cls, base_ring, basis_keys, category = None, **keywords): 932 932 """ 933 933 TESTS:: 934 934 … … class CombinatorialFreeModule(UniqueRepr 940 940 sage: F = CombinatorialFreeModule(QQ, ['a','b','c'], latex_bracket=['LEFT', 'RIGHT']) 941 941 sage: F.print_options()['latex_bracket'] 942 942 ('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 943 961 """ 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) 950 965 # bracket or latex_bracket might be lists, so convert 951 966 # them to tuples so that they're hashable. 952 967 bracket = keywords.get('bracket', None) … … class CombinatorialFreeModule(UniqueRepr 955 970 latex_bracket = keywords.get('latex_bracket', None) 956 971 if isinstance(latex_bracket, list): 957 972 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) 959 974 960 975 Element = CombinatorialFreeModuleElement 961 976 … … class CombinatorialFreeModule(UniqueRepr 1005 1020 from sage.categories.all import Rings 1006 1021 if R not in Rings(): 1007 1022 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"1012 1023 1013 1024 if category is None: 1014 1025 category = ModulesWithBasis(R) 1026 1015 1027 if element_class is not None: 1016 1028 self.Element = element_class 1017 1029