Ticket #9138 (new defect)

Opened 3 months ago

Last modified 5 weeks ago

Categories for polynomial rings

Reported by: jbandlow Owned by: nthiery
Priority: major Milestone: sage-4.5.3
Component: categories Keywords: introspection, categories
Cc: sage-combinat Author(s):
Report Upstream: N/A Reviewer(s):
Merged in: Work issues:

Description (last modified by nthiery) (diff)

Introspection is failing on polynomial rings:

sage: R.<x> = QQ[] 
sage: R.su<tab> 
R.sum                               R.summation 
R.summation_from_element_class_add 
sage: R.sum? 
Object `R.sum` not found. 
sage: R.sum() 
--------------------------------------------------------------------------- 
AttributeError                            Traceback (most recent call last) 

This is because polynomial rings do not yet set their category properly:

sage: QQ[x]._test_category()
------------------------------------------------------------
Traceback (most recent call last):
...
AssertionError: category of self improperly initialized

See  http://groups.google.com/group/sage-devel/browse_thread/thread/4780192a11a8b591 for more discussion.

Change History

  Changed 3 months ago by nthiery

  • cc sage-combinat added
  • keywords introspection, categories added; introspection removed
  • description modified (diff)
  • summary changed from Introspection is failing on polynomial rings to Categories for polynomial rings

follow-up: ↓ 3   Changed 3 months ago by mmezzarobba

This ticket seems to be a duplicate of #8613.

in reply to: ↑ 2   Changed 3 months ago by nthiery

Replying to mmezzarobba:

This ticket seems to be a duplicate of #8613.

Indeed. This should have ringed a bell to me!

Since I have already recycled this ticket to "Categories for polynomial ring", I leave the two tickets as is. Once this ticket will be closed, it should be possible to close #8613 as well.

follow-up: ↓ 5   Changed 5 weeks ago by SimonKing

This ticket is just about a single kind of parent classes. Rather than going through a long list of parent classes one by one and inserting the missing pieces: Wouldn't it be a more thorough approach to provide a default implementation for the attributes needed in the category framework, in cases where it makes sense?

Here is an example:

sage: R.<x,y> = QQ[]
sage: 'element_class' in dir(R)
True
sage: hasattr(R,'element_class')
False

If I am not mistaken, "element_class" should be implemented by providing the attribute "Element".

But is there a reason why element_class is a dynamic meta-class and not a regular method? Since any parent class has a "an_element" method, it seems to me that the following default implementation makes sense (and it solves the problem in my example above):

    def element_class(self):
        try:
            return self.Element
        except AttributeError:
            return self.an_element().__class__

It seems to me that providing reasonable default implementations would, on the long run, be easier than going through any single parent class. But certainly other people know more about the "how-to" of categories.

in reply to: ↑ 4 ; follow-up: ↓ 6   Changed 5 weeks ago by SimonKing

Replying to SimonKing:

But is there a reason why element_class is a dynamic meta-class and not a regular method?

Sorry, I just noticed that "element_class" is not a method at all: I assumed that it should be used like R.element_class(), but sadly it is R.element_class without calling the attribute. So, one attribute (element_class) is implemented by providing another attribute (Element).

Anyway, if there shall be a default implementation for element_class then unfortunately it must be in __getattr__.

in reply to: ↑ 5   Changed 5 weeks ago by SimonKing

Replying to SimonKing:

Replying to SimonKing:

But is there a reason why element_class is a dynamic meta-class and not a regular method?

Sorry, I just noticed that "element_class" is not a method at all...

Again wrong. I found in sage.structure.parent that there is indeed a method element_class -- with a lazy_attribute decorator. I am still confused by that programming style, so, better I shut up.

Anyway, changing the element_class method so that an_element is used (rather than raising an AttributeError) did not help. Can you explain why this does not work?

Note: See TracTickets for help on using tickets.