Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is a minimal example that may do what you want:

class Foo(SageObject):
    # This class defines what a 'Foo' is and what can be done with it.
    def __init__(self, i):
        self.i = i

    def _repr_(self):
        return str(self.i)

class Foos(Parent, UniqueRepresentation):
    # This class represents the set of all 'Foo's
    def __contains__(self, f):
        return isinstance(f, Foo)

    Element = Foo

Here is how to use this with CombinatorialFreeModule:

sage: F = Foos()
sage: f = Foo(1)
sage: g = Foo(2)
sage: f
1
sage: g
2
sage: f + g
TypeError: unsupported operand type(s) for +: 'Foo' and 'Foo'
sage: M = CombinatorialFreeModule(QQ, F)
sage: a = M.monomial(f)
sage: b = M.monomial(g)
sage: a + b
B[2] + B[1]
sage: 2*a
2*B[1]