#10127: Fix initialization order in CombinatorialFreeModule
---------------------------------+------------------------------------------
   Reporter:  nthiery            |       Owner:  AlexGhitza
       Type:  defect             |      Status:  new       
   Priority:  major              |   Milestone:  sage-4.6.1
  Component:  algebra            |    Keywords:            
     Author:  Nicolas Borie      |    Upstream:  N/A       
   Reviewer:  Nicolas M. ThiƩry  |      Merged:            
Work_issues:                     |  
---------------------------------+------------------------------------------
Changes (by nthiery):

  * work_issues:  Just needs a regression test =>


Old description:

> Preliminary patch on the Sage-Combinat patch server

New description:

 This patch fixes ``CombinatorialFreeModule.__init__`` in order to set
 ``self._basis_keys`` early enough in case the initialization of the
 categories use ``self.basis().keys()``. This occured on several occasions
 in non trivial constructions. In the following example,
 ``AlgebrasWithBasis`` constructs ``Homset(self,self)`` to extend by
 bilinearity the ``product_on_basis`` method, which in turn triggers the
 `self._repr_()`::

 {{{
     sage: class MyAlgebra(CombinatorialFreeModule):
     ...       def _repr_(self):
     ...           return "MyAlgebra on %s"%(self.basis().keys())
     ...       def product_on_basis(self,i,j):
     ...           pass
     sage: MyAlgebra(ZZ, ZZ, category = AlgebrasWithBasis(QQ))
 Traceback (most recent call last):
   File "<ipython console>", line 1, in <module>
   File "/opt/sage-4.5.2/local/lib/python2.6/site-
 packages/sage/misc/classcall_metaclass.py", line 258, in __call__
     return cls.__classcall__(cls, *args, **options)
   File "/opt/sage-4.5.2/local/lib/python2.6/site-
 packages/sage/misc/cachefunc.py", line 115, in __call__
     w = self.f(*args, **kwds)
   File "/opt/sage-4.5.2/local/lib/python2.6/site-
 packages/sage/structure/unique_representation.py", line 449, in
 __classcall__
     instance = type.__call__(cls, *args, **options)
   File "/opt/sage-4.5.2/local/lib/python2.6/site-
 packages/sage/combinat/free_module.py", line 827, in __init__
     element_constructor = self._element_constructor_)
   File "parent.pyx", line 458, in sage.structure.parent.Parent.__init__
 (sage/structure/parent.c:3855)
   File "/opt/sage-4.5.2/local/lib/python2.6/site-
 packages/sage/categories/magmas.py", line 115, in __init_extra__
     if (self.product != self.product_from_element_class_mul) and
 hasattr(self, "element_class") and hasattr(self.element_class,
 "_mul_parent"):
   File "element.pyx", line 863, in
 sage.structure.element.Element.__richcmp__ (sage/structure/element.c:7107)
   File "element.pyx", line 804, in sage.structure.element.Element._richcmp
 (sage/structure/element.c:6487)
   File "coerce.pyx", line 907, in
 sage.structure.coerce.CoercionModel_cache_maps.canonical_coercion
 (sage/structure/coerce.c:8540)
   File "sage_object.pyx", line 101, in
 sage.structure.sage_object.SageObject.__repr__
 (sage/structure/sage_object.c:1370)
   File "/opt/sage-4.5.2/local/lib/python2.6/site-
 packages/sage/categories/homset.py", line 302, in _repr_
     self._domain, self._codomain, self.__category)
   File "sage_object.pyx", line 101, in
 sage.structure.sage_object.SageObject.__repr__
 (sage/structure/sage_object.c:1370)
   File "<string>", line 4, in _repr_
   File "/opt/sage-4.5.2/local/lib/python2.6/site-
 packages/sage/combinat/free_module.py", line 869, in basis
     return Family(self._basis_keys, self.monomial) #.
   File "parent.pyx", line 680, in sage.structure.parent.Parent.__getattr__
 (sage/structure/parent.c:5311)
   File "parent.pyx", line 264, in
 sage.structure.parent.getattr_from_other_class
 (sage/structure/parent.c:2757)
   File "parent.pyx", line 172, in
 sage.structure.parent.raise_attribute_error (sage/structure/parent.c:2629)
 AttributeError: 'MyAlgebra_with_category' object has no attribute
 '_basis_keys'
 }}}

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10127#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to