I am struggling with the Categories/Parents/Elements structure and am hoping someone can help me.
The reason I want to use this is that I have a construction which I want to use in several similar, but different contexts. If I was writing a standalone python package I would have an abstract base class with a couple of abstract methods and then some methods which use these. As I understand it, in sage, the way to implement this is to have a category. However it seems there are two possibilities; I could put these methods in either ParentMethods or ElementMethods. I can confused about which of these is preferable. Let me be more specific. In mathematical terms I have things which I call Tableaux. A Tableau is given as a list of objects. In the main examples, the objects would be partitions. In general, the objects and the conditions on the list are to be specified. The basic example, is that I think of a standard tableau as a list of partitions with the condition that at each step one box is added. Then I can think of the set of Tableaux as the parent and lists of objects as elements. In this case the methods would be in ElementMethods; this approach seemed more natural to me but I didn't find an example which I found disturbing. Alternatively I can think of a Tableau as a parent and the objects as elements; in this case the methods would be in ParentMethods. This is the approach taken for Posets. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The other problem I have is that I don't understand the Category, Parent, Element structure. I have read the sage documentation and looked at the sage source code. The sage documentation seems more focused on the needs of algebraic geometry than of combinatorics. I have struggled to find complete examples in the combinat source code. As I understand it the key components are Parent.__init__ Element.__init__ _element_constructor_ but I don't understand what these do or how they work together. I am even confused about what the arguments are. It seems that the arguments, or maybe just the order, are different for new style classes and old style classes. This doesn't help. I have attached a file which is a condensed version of my efforts (which doesn't work). -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-combinat-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-combinat-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-combinat-devel. For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Fri May 18 13:57:59 2018 @author: bruce """ ############################################################################### class PathTableaux(Category): def super_categories(self): return [Sets()] class ParentMethods: def foo(self): pass class ElementMethods: pass ############################################################################### class Weight(UniqueRepresentation,Element): @staticmethod def __classcall__(cls, x): y = tuple(Partition(x)) return super(Weight, cls).__classcall__(cls, y) def __init__(self,parent,term): self.term = term def __repr__(self): return "Weight(%d)"%self.term ############################################################################## class OscillatingTableau(UniqueRepresentation,Parent): @staticmethod def __classcall__(cls, x): y = ([ Weight(a) for a in x]) return super(OscillatingTableau, cls).__classcall__(cls, y) def __init__(self, x): Parent.__init__(self, category=PathTableaux() ) self.nodes = x def _element_constructor_(self, x): return self.element_class(self, x) def _repr_(self): return "An Oscillating Tableau" Element = Weight