I am trying to write a class that inherits from CombinatorialFreeModule. My problem is correctly inheriting from the element class. I have the following code:
from sage.sets.family import Family
from sage.categories.all import GradedAlgebrasWithBasis
from sage.combinat.free_module import CombinatorialFreeModule, CombinatorialFreeModuleElement
from sage.categories.all import tensor
class TestRing(CombinatorialFreeModule):
def __init__(self, R, G):
super(TestRing, self).__init__(R, G)
class TestRingElement(CombinatorialFreeModuleElement):
def __init__(self, M, x):
super(TestRingElement, self).__init__(self, M, x)
self.data = x
I can create a TestRing object and get its basis elements as follows:
sage: R = TestRing(QQ, ('a','b'))
sage: a,b = R.basis()
My problem is that a
and b
have no data
attribute. They are not instances of the TestRingElement
class:
sage: a.d
a.db a.dump a.dumps
sage: isinstance( a, TestRingElement )
False
I want to be able to add more attributes to the elements of my module. Can someone tell me the correct way to do this?
Incidentally, this code breaks when I call TestRing
with a list as its second argument, instead of a tuple. Though, if I create a list inside the constructor (based on input to the constructor) and use that when I call the parent constructor, everything runs fine. Can anyone tell me why the code breaks in the first instance? Or, why does it work in the second instance?
Thanks!