Hello.

I'm wondering if there is some documentation or a howto somewhere that
describes the process of adding new structures to Sage. For example,
we want to add poset functionality to Sage---Peter Jipsen and I began
working on this at Sage Days 7. So we created a Poset class that
inherits from ParentWithBase (because inheriting from Parent isn't
support if I want to have elements---something that should be fixed, I
guess), and a PosetElement class that inherits from the Element class.
If this is not correct, then someone should tell me now, and the
better way to do this.

Also, I have some technical questions.

1. Can someone describe to me how ParentWithBase works? Does each
instance of Element store the parent poset? I imagine this is not the
case as it would mean several copies of the Parent will be stored in
memory. So it's some kind of identifier for the poset?

2. My PosetElement class accepts two arguments: the Parent poset P and
a label for the poset element. The problem I am having here is that I
can create an instance of PosetElement with Parent poset P, but this
element won't belong to P (and it shouldn't). But then the parent
function returns P on this new element. Here is a psuedo-example:

sage: P = FinitePoset([0,1,2])
sage: y = PosetElement(P,3)
sage: parent(y) == P
True
sage: y in P
False

I'm probably messing something up with my class definitions. (I'm new
to OOProgramming and Sage.) I'm including a very basic implementation
of the classes below. Any suggestions?

Take care,
Franco

--

from sage.structure.element import Element

class FinitePoset(ParentWithBase):
        def __init__(self,data=None):
                Parent.__init__(self)
                self.elements=[]
                if not data is None:
                        for x in data:
                                self.elements.append(PosetElement(self,x))

        def __contains__(self,x):
                return x in self.elements

        def list(self):
                return self.elements

class PosetElement(Element):
        def __init__(self,poset,label):
                Element.__init__(self,poset)

--

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to