Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaning CategoryObject/Parent #21380

Open
videlec opened this issue Aug 31, 2016 · 48 comments
Open

cleaning CategoryObject/Parent #21380

videlec opened this issue Aug 31, 2016 · 48 comments

Comments

@videlec
Copy link
Contributor

videlec commented Aug 31, 2016

Abstract

This ticket stands to clean CategoryObject and Parent with respect to:

  • hacks and too specialized methods (e.g. base or _ngens_)
  • undocumented and old (e.g. sage.structure.generators)
  • duplicated stuff (e.g. _an_element_ and an_element)

Subtasks

Base and generators

We should move out of CategoryObject the attributes and methods related to generators and variable names.

Attributes:

  • _names

Methods:

  • gens_dict
  • gens_dict_recursive
  • objgens
  • objgen
  • _first_ngens
  • _defining_names
  • _assign_names
  • __temporarily_change_names
  • variable_names
  • variable_name
  • latex_variable_names
  • latex_name
  • inject_variables
  • base_ring

It is not clear where all this should be moved... Moreover "generators" is ambiguous since "monoid generators", "group generators", "algebra generators", ... are different things.

Keep

These were originally proposed to be removed too, but are sufficiently useful:

Attributes:

  • _base
    Methods:
  • base
    Functions:
  • normalize_names
  • certify_names

Tickets

Some related tickets are

Transition to FiniteEnumeratedSet

Duplicated names for same function

Others

Closed tickets

CC: @tscrim

Component: categories

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

@videlec videlec added this to the sage-7.4 milestone Aug 31, 2016
@jdemeyer
Copy link

comment:1

Are you sure this would affect Element much? All the things you write are about CategoryObject or Parent.

@jdemeyer

This comment has been minimized.

@jdemeyer jdemeyer changed the title cleaning CategoryObject/Element/Parent cleaning CategoryObject/Parent Aug 31, 2016
@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@videlec

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link

Replying to @videlec:

We should move out of CategoryObject the attributes and methods relative to "base"

After thinking about this now and then, I think that it does make sense to keep _base inside CategoryObject. There are a lot of objects which naturally have a base object. For efficiency and simplicity, I suggest to keep CategoryObject._base.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link

comment:21

What is wrong with the functions normalize_names() and certify_names? They have to be put somewhere, why not in structure/category_object.pyx?

@videlec
Copy link
Contributor Author

videlec commented Nov 29, 2017

comment:22

Replying to @jdemeyer:

Replying to @videlec:

We should move out of CategoryObject the attributes and methods relative to "base"

After thinking about this now and then, I think that it does make sense to keep _base inside CategoryObject. There are a lot of objects which naturally have a base object. For efficiency and simplicity, I suggest to keep CategoryObject._base.

Some does, some does not and there is no specification of what a base is. I would be happy to hear a definition.

@videlec
Copy link
Contributor Author

videlec commented Nov 29, 2017

comment:23

Replying to @jdemeyer:

What is wrong with the functions normalize_names() and certify_names? They have to be put somewhere, why not in structure/category_object.pyx?

Right (I made the listing rather quickly)

@jdemeyer
Copy link

comment:24

Replying to @videlec:

Some does, some does not and there is no specification of what a base is. I would be happy to hear a definition.

Well, we cannot define "base" in full generality. Some objects do not have a natural base and then this attribute should simply be None.

But in certain important categories, we can define "base". For example, for modules, we define "base" to mean the parent of the scalars used for scalar multiplication.

@videlec
Copy link
Contributor Author

videlec commented Nov 29, 2017

comment:25

Replying to @jdemeyer:

Replying to @videlec:

Some does, some does not and there is no specification of what a base is. I would be happy to hear a definition.

Well, we cannot define "base" in full generality. Some objects do not have a natural base and then this attribute should simply be None.

But in certain important categories, we can define "base". For example, for modules, we define "base" to mean the parent of the scalars used for scalar multiplication.

This is precisely the reason why I dislike it. It is a fake global concept that is mostly meant for "the underlying ring of a module". And because modules are important all parents have an attribute _base as well as methods base and base_ring. Think for a minute about the list of parents without base: permutations, graphs, groups, rings, schemes, simplicial complexes, ...

Moreover, I (maybe wrongly) thought that this "base ring of a module" is the kind of information that belongs to the category

sage: Modules(ZZ)
Category of modules over Integer Ring
sage: Modules(ZZ).base()
Integer Ring

@jdemeyer
Copy link

comment:39

Replying to @videlec:

Moving base() and base_ring() to the category would not be possible if the attribute _base is private. How do you plan to declare it?

You could make _base accessible to Python code (cdef public _base instead of cdef _base).

@jdemeyer
Copy link

jdemeyer commented Dec 7, 2017

comment:40

Replying to @tscrim:

I was thinking of a hierarchy like this:

+-Parent
|
+---ParentWithBase  (maybe useless right now)
|
+-+-ParentWithGens
  |
  +-+-ParentWithBaseAndGens
    |
    +-Module (etc).

I don't think that it makes much sense to have unrelated classes ParentWithBase and ParentWithBaseAndGens. Since base seems more important than gens, I would actually suggest

CategoryObject
|
+--Parent
   |
   +--ParentWithBase
      |
      +--Module
      |
      +--Ring
      |
     ...

I said new-style because there still is the old-style ParentWithGens floating around.

Thanks for the reminder. Getting rid of those old-style parents should probably be higher priority than this ticket.

@tscrim
Copy link
Collaborator

tscrim commented Dec 8, 2017

comment:41

Replying to @jdemeyer:

Replying to @tscrim:

I was thinking of a hierarchy like this:

+-Parent
|
+---ParentWithBase  (maybe useless right now)
|
+-+-ParentWithGens
  |
  +-+-ParentWithBaseAndGens
    |
    +-Module (etc).

I don't think that it makes much sense to have unrelated classes ParentWithBase and ParentWithBaseAndGens.

Ideally it should be a diamond IMO, but Cython does not (yet?) support multiple inheritance (or something like interfaces in Java-speak).

Since base seems more important than gens, I would actually suggest

CategoryObject
|
+--Parent
   |
   +--ParentWithBase
      |
      +--Module
      |
      +--Ring
      |
     ...

We have objects with base but without gens (e.g., polytopes), objects without base but with gens (e.g., permutation groups), as well as with(out) both. So I was trying to address that with my proposed hierarchy. At least I would like ParentWithGens in between Parent and ParentWithBase as there are very few things in Sage that have gens but no concept of base. (Which, as it turns out, is not quite the old parent hierarchy ParentWithGens -> ParentWithBase -> Parent_old.)

Although I'm a little worried with the group class hierarchy becoming a bit more of a mess because of the Cython parents and not having the multiple inheritance. Might be a necessary complication in order to improve the interface (which IMO is net benefit). Spreading out to a more refined parent hierarchy is going to be a fairly invasive change, so I guess it will just have to be done.

I said new-style because there still is the old-style ParentWithGens floating around.

Thanks for the reminder. Getting rid of those old-style parents should probably be higher priority than this ticket.

Yes, definitely. Although most of them are really fundamental parents such as Ring, number fields, etc. I guess we can take care of the leaf classes a little more easily, such as ComplexIntervalField. Although it is somewhat counter to the objective of having a more refined parent hierarchy as it usually means making the class inherit from Parent...

@jdemeyer
Copy link

jdemeyer commented Dec 8, 2017

comment:42

Replying to @tscrim:

Cython does not (yet?) support multiple inheritance

First of all, the next release of Cython is going to support multiple inheritance in a limited way. The list of bases can be CyClass, PyClass1, ..., PyClassN, which is the most general thing which is allowed by Python and which doesn't hurt Cython's performance (because all Python classes come after all Cython classes in the MRO).

Second, the fact that diamonds are not allowed is because of Python's design. In plain Python, you cannot do class X(list, str) either. So don't blame Cython for something that they cannot fix.

Anyway, the conclusion is that ParentWithGens could be a Python class and then the diamond would work in Cython 0.28.

@jdemeyer
Copy link

jdemeyer commented Dec 8, 2017

comment:43

Replying to @tscrim:

Yes, definitely. Although most of them are really fundamental parents such as Ring

The large majority of rings use the new coercion model, so it's not as bad as you think.

@tscrim
Copy link
Collaborator

tscrim commented Dec 11, 2017

comment:44

Replying to @jdemeyer:

Replying to @tscrim:

Cython does not (yet?) support multiple inheritance

First of all, the next release of Cython is going to support multiple inheritance in a limited way. The list of bases can be CyClass, PyClass1, ..., PyClassN, which is the most general thing which is allowed by Python and which doesn't hurt Cython's performance (because all Python classes come after all Cython classes in the MRO).

That's good to hear and should be useful here.

Second, the fact that diamonds are not allowed is because of Python's design. In plain Python, you cannot do class X(list, str) either. So don't blame Cython for something that they cannot fix.

Sorry, I guess I was thinking a little too loosely with not distinguishing between classes and (builtin) types.

Anyway, the conclusion is that ParentWithGens could be a Python class and then the diamond would work in Cython 0.28.

I think this would be the most sensible solution since most of our Cython parent classes would inherit from the ParentWithGensAndBase (e.g., Ring, where we really treat everything as some R-algebra), but would keep the flexibility for other parents in a reasonable way.

@tscrim
Copy link
Collaborator

tscrim commented Dec 11, 2017

comment:45

Replying to @jdemeyer:

Replying to @tscrim:

Yes, definitely. Although most of them are really fundamental parents such as Ring

The large majority of rings use the new coercion model, so it's not as bad as you think.

That's good to hear. Now if only I could find some time to work on this directly...

@videlec

This comment has been minimized.

@mkoeppe mkoeppe modified the milestones: sage-7.4, sage-9.3 Aug 17, 2020
@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 13, 2021

comment:48

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants