Ask Your Question
1

is an object of a subcategory an object of the ambient category?

asked 2019-09-02 18:22:25 +0200

heluani gravatar image

updated 2019-09-02 21:03:40 +0200

I have defined a category Cs() and its subcategory Ds() as follows:


class Cs(Category_over_base_ring):
    ...
    def __init__(self, K):
       Category_over_base_ring.__init__(self, K)

    def super_categories(self):
        return [ GradedAlgebras(self.base_field()) ] 

class Ds(CategoryWithAxiom):
    _base_category_class_and_axiom = (Cs, 'Commutative')    

Cs.Commutative = Ds

The omitted code I think its irrelevant. I can check that Ds() is a subcategory of Cs():


sage: C = Cs(QQ)
sage: D = Ds(QQ)
sage: D.is_subcategory(C) 
True
sage: 

Now I create a parent of Ds() as follows:


class DParent (Parent,UniqueRepresentation):
    def __init__(self,K, *args, **kwds ): 
        if not (K in Fields() or \
            (isinstance(K, Category) and K.is_subcategory(Fields()))):
            raise ValueError(
                "base must be a field or a subcategory of Fields(); got {}".format(K))
        self._base_algebra = PolynomialRing(K,*args,**kwds)
        super(DParent,self).__init__(self,
            category=Ds(K))
...

And I can check that these parents are objects of Ds() but not of Cs():


sage: J = DParent(QQ, 1, 'x', order=TermOrder('wdeglex', (2,)))
sage: J in C
False
sage: J in D
True

Where can I be making a mistake?

Addition: I am looking at the implementation in sage/categories/category.py and I am more puzzled:

sage: J.category().is_subcategory(C)
True
sage: C.__contains__(J)
False

But at least I get


sage: c = J.categories()
sage: any(isinstance(cat,C.subcategory_class) for cat in c)
True
sage: C.__classcontains__(C.subcategory_class,J)
True
sage:
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-09-02 21:34:50 +0200

heluani gravatar image

I'll add an answer in case someone finds something similar. I am new to sage so I suppose there's something silly that I am doing and there are better ways of implementing this.

It turns out that Category_over_base_ring reimplements __contains__ and it tests for the base ring as well. For some reason that I don't know yet my parent's base_ring method does not call D.parent_class.base_ring method but some other. I overloaded it in DParent as follows


class DParent (Parent,UniqueRepresentation):
     ...
     def base_ring(self):
           return self.category().base_ring()

And now J in C returns true.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-09-02 18:22:25 +0200

Seen: 166 times

Last updated: Sep 02 '19