sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.31k stars 449 forks source link

Category Modules ~> Algebras #16443

Open 3f8450e1-87bf-41c6-ab53-29a0552debb3 opened 10 years ago

3f8450e1-87bf-41c6-ab53-29a0552debb3 commented 10 years ago

Strange problem:

from sage.categories.category_types import Category_over_base_ring

class A(Category_over_base_ring):

    def super_categories(self):
        R = self.base_ring()
        return [Algebras(R]
        #return [Modules(R)]

class B(UniqueRepresentation, Parent):

    def __init__(self, R):
        Parent.__init__(self, category=A(R))

That fails! (6.2 rc 2):

sage: B(QQ)
...
TypeError: None is not in Category of rings

But if I try to change the super categories:

Algebras(R) --> Modules(R)

That works! What's error mean?

CC: @nthiery

Component: categories

Issue created by migration from https://trac.sagemath.org/ticket/16443

nthiery commented 10 years ago
comment:1

It in fact does not work either: a parent in Modules(...) should implement a base_ring method. This method just turns out not to be called upon initialization if B is just in Modules() instead of Algebras(), so the problem goes undetected, so far ...

It indeed feels a bit redundant to have to specify the base ring in the category and in the base_ring method. The thing is that, in the category, one can now specify something like Algebras(Rings()); I'd say it's even recommended. So one can't recover the base ring from the just the category. It's not so bad, because more often than not, when implementing a module, one inherits from some preexisting module that implements base_ring for us.

Now, yes, definitely, this all might not be stated explicitly in the documentation; and the error message is not informative ...

Step that can be taken right away:

Steps that are a bit more tricky (I tried and dropped the case; but I had to act fast then to get #10963 in):

Cheers, Nicolas