sagemath / sage

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

Toward singleton categories: subcategories of Modules #22962

Open nthiery opened 7 years ago

nthiery commented 7 years ago

Categories over base ring like Algebras(QQ) have been a regular source of issues. A series of tickets culminating in #15801 improved quite some the situation. Yet #15475, #20896, #20469 show that this is not the end.

In this ticket, we explore a plan first proposed at #20896 comment:3.

Issue analysis

The issue in #20896 is that, by design, A3=Algebras(GF(3)) and A5=Algebras(GF(5)) share the same element/parent/... classes. However the MRO for such classes is built to be consistent with a total order on categories, and that total order is built dynamically using little context; so hard to keep consistent. Hence the order we get for A3 and A5 need not be the same, and the MRO basically depends on which one has been built first. If one builds alternatively larger and larger hierarchies for GF(5) and GF(3) we are likely to hit an inconsistency at some point.

Aim: toward singleton categories

This, together with other stuff I do (e.g. [1]) with colleagues from other systems (GAP, MMT, ...), finished to convince me that most of our categories should really be singleton categories, and not be parametrized.

Let's see what this means for categories over a ring like Algebras. I originally followed the tradition of Axiom and MuPAD by having them be systematically parametrized by the base ring. However the series of issues we faced and are still facing shows that this does not scale.

Instead, to provide generic code, tests, ... we want a collection of singleton categories like:

After all, the code provided in e.g. ParentMethods will always be the same, regardless of the parameters of the category (well, that's not perfectly true; there are in Axiom and MuPAD idioms enabling the conditional definition of methods depending on the base ring; we could try to port those idioms over).

Of course, there can be cases, e.g. for typechecking, where it's handy to model some finer category like Algebras(GF(3)). However such categories should really be implemented as thin wrappers on top of the previous ones.

We had already discussed approaches in this direction, in particular with Simon. #15801 was a first step, but remaing issues show that this is not enough.

Proposition of design

We keep our current Category_over_base_ring's (Modules, Algebras, HopfAlgebras, ...). However they now are all singleton categories, meant to be called as:

Whenever some of the above category needs to be refined depending on the properties on the base ring, we define some appropriate axiom. E.g. VectorSpaces() would be Modules().OverFields(). And we could eventually have categories like Modules().OverPIDs(), Polynomials().OverPIDs().

Now what happens if one calls Algebras(QQ)?

As a syntactical sugar, this returns the join Algebras() & Modules().Over(QQ).

Fine, now what's this latter gadget? It's merely a place holder with two roles:

Implementation details

Pros, cons, points to be discussed

Pros:

Cons:

Points to be debated:

[1] https://github.com/nthiery/sage-gap-semantic-interface

CC: @tscrim @simon-king-jena

Component: categories

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

nthiery commented 7 years ago
comment:1

I am planning to work on this in the coming days.

jdemeyer commented 7 years ago

Replying to @nthiery:

  • What name for the axioms? OverField, or OverFields?

Why not Over(Fields())?

nthiery commented 7 years ago
comment:3

Hi Jeroen,

Replying to @jdemeyer:

Replying to @nthiery:

  • What name for the axioms? OverField, or OverFields?

Why not Over(Fields())?

I would love it :-)

And we certainly could implement some idiom:

    sage: C = Algebras()
    sage: C.Over(Fields())

However, with the current axiom infrastructure, we still need a name for the actual class holding the code for the corresponding category. That name has to be a string.

    class Algebras:
        class OverFields(CategoryWithAxiom):
            class ParentMethods:
                ....

We could kind of hide this with some mangling (e.g. calling the class _OverFields and using #22965 to have the axiom be printed as Over(Fields())). However, at this stage, this feels like adding one layer of complexity. I'd rather keep things "simple".

pjbruin commented 4 years ago
comment:4

Hopefully this would also solve things like #29374.