Opened 9 years ago
Last modified 8 years ago
#9944 closed defect
categories for polynomial rings — at Version 16
Reported by: | robertwb | Owned by: | nthiery |
---|---|---|---|
Priority: | major | Milestone: | sage-4.7.1 |
Component: | categories | Keywords: | |
Cc: | sage-combinat | Merged in: | |
Authors: | Robert Bradshaw | Reviewers: | Nicolas M. Thiéry, Mike Hansen |
Report Upstream: | N/A | Work issues: | Fix one test |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
Currently, they're always just commutative rings.
Apply:
Change History (21)
Changed 9 years ago by
comment:1 Changed 9 years ago by
- Status changed from new to needs_review
comment:2 Changed 9 years ago by
Changed 9 years ago by
comment:3 Changed 9 years ago by
- Reviewers set to Nicolas M. Thiéry, Mike Hansen
I went ahead and moved the functionality to it's own category since we want the mathematical information at the category level. Could someone look over these changes?
comment:4 follow-up: ↓ 8 Changed 9 years ago by
The first patch only concerned univarite polynomial rings, the logic is not all correct for multivariate polynomial rings (though on an orthogonal note, that could use some fixing up as well). It seems odd to have a category of univariate polynomial rings over a fixed basering, which is why I put the logic into the concrete object. I suppose the category should a be declared as a graded R-algebra as well (do we have join categories yet?).
I don't know if PolynomialRing? asserts its basering is commutative, but IIRC it's been assumed for a long time.
comment:5 Changed 9 years ago by
Apply only 9944-poly-cat.patch
Changed 8 years ago by
comment:6 Changed 8 years ago by
Apply 9944-poly-cat.patch and 9944-poly-cat-doctests.patch .
Changed 8 years ago by
comment:7 Changed 8 years ago by
- Description modified (diff)
I would give this a positive review for Robert's idea and I would open a new ticket for the multivariate rings. I'll just send a mail to Mike whether he is ok with that or no.
comment:8 in reply to: ↑ 4 ; follow-up: ↓ 9 Changed 8 years ago by
Replying to robertwb:
The first patch only concerned univarite polynomial rings, the logic is not all correct for multivariate polynomial rings (though on an orthogonal note, that could use some fixing up as well). It seems odd to have a category of univariate polynomial rings over a fixed basering, which is why I put the logic into the concrete object. I suppose the category should a be declared as a graded R-algebra as well (do we have join categories yet?).
Sorry for the very late answer. In MuPAD, we had a category for univariate polynomial rings: there are several possible implementations of such, and it's natural to factor out the generic code, together with the category inheritance logic, in a category.
And yes, we have join categories. See Category.join.
I let you see whether to create the UnivariatePolynomialRing? category in this ticket or in a later ticket.
comment:9 in reply to: ↑ 8 ; follow-up: ↓ 12 Changed 8 years ago by
Replying to nthiery:
Sorry for the very late answer. In MuPAD, we had a category for univariate polynomial rings: there are several possible implementations of such, and it's natural to factor out the generic code, together with the category inheritance logic, in a category.
Aparently there is a doctest failure. I fixed it, but unfortunately it went into my patch submitted for #9138. Therefore, "needs work".
Question: Do we really want a category of polynomial rings? Or do we want that (1) polynomial rings use the category framework (that's the purpose of my patch for #9138) and (2) the category to which a given polynomial ring belongs is a bit narrower than simply "category of rings"? I hope it is the latter.
My suggestion is that I submit a small patch fixing the doctests. Please tell whether my patch for #9138 improves the multivariate case. Then, perhaps it would be possible to give Roberts patches (+ doctest fix) a positive review, so that we can focus on #9138.
comment:10 Changed 8 years ago by
- Status changed from needs_review to needs_work
- Work issues set to Fix one test
comment:11 Changed 8 years ago by
At #9138, Jason Bandlow reported a slow-down, that is at least partially caused by the patches here. Do you have any idea what could be the reason?
comment:12 in reply to: ↑ 9 Changed 8 years ago by
- Description modified (diff)
Replying to SimonKing:
Aparently there is a doctest failure. I fixed it, but unfortunately it went into my patch submitted for #9138. Therefore, "needs work".
Strange: Although the patch bot did see that error in one run, I can not reproduce it (but I had to change that test in my patch for #9138, because it turns QQ['x'].category()
into the join of the category of euclidean domains and commutative algebras over QQ
.
The other issue, namely the performance loss, was studied on sage-devel.
Florent Hivert found that a long mro does not matter for Python, but it does matter if the classes inherit from a cdef class. That is the case for most classes in Sage (inheriting from SageObject
), so, we should address the problem of a long mro.
Eventually, that should be fixed in Cython (and I think Florent reported it upstream). But for now, it seems to me we should think of a work-around.
Would it be acceptable coding practice to explicitly state in a derived class (say, MPolynomialRing_generic
), that frequently used methods such as base or base_ring are the same as Parent.base
or Parent.base_ring
? David Roe stated that it might be dangerous to do so, at least if cpdef
methods are involved.
comment:13 Changed 8 years ago by
Concerning performance loss:
It seems to me that part of the reason is the fact that with the patchse, __init_extra__
is not executed when it should. Sometimes, the parent methods of a category provide a useful __init_extra__
, for example the category of algebras.
I am not sure yet why that happens, but I think it would happen if Parent.__init__
is called without providing the category: Namely, doing self._init_category_(...)
alone will not trigger the execution of __init_extra__
.
comment:14 Changed 8 years ago by
It seems I was right!
Namely, the whole ring stuff is (unfortunately) inherited from ParentWithGens
, which inherits from ParentWithBase
, which inherits from parent_old.Parent
.
And parent_old.Parent
inherits from "the one and only Parent" -- but forgets to call Parent.__init__
!! Instead, it just does self._init_category_(...)
.
I'll change it and see what happens.
comment:15 Changed 8 years ago by
Very bad things happen. As soon as parent.Parent.__init__
is called in parent_old.Parent.__init__
, an infinite recursion occurs.
comment:16 Changed 8 years ago by
- Description modified (diff)
I attached a small patch to solve part of the problem of the missing parent initialisation: I call Parent.__init__
and ParentWithGens.__init__
explicitly, during initialisation of a ring. In that way, the __init_extra__
methods are correctly picked up.
However, that does not solve the performance problem.
Question one: How can one come to speed?
Question two: Is my patch really trivial enough to be called a referee patch?
For the patchbot:
Apply 9944-poly-cat.patch 9944-poly-cat-doctests.patch trac-9944-poly-cat-review.patch trac9944_second_referee.patch
I have been through the patch, and it sounds good! I won't have the time to actually test it before some time, so please anyone beat me to it!
Just one micro question: does PolynomialRing? actually check that the ring is commutative?
Cheers