-
-
Notifications
You must be signed in to change notification settings - Fork 649
move is_field from Ring to Rings #39520
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
Conversation
Wir haben viel gelacht. |
So, the problem is that In the case at hand, this triggers the computation of The reason why One solution is not to special case whether the ring is the zero ring, which should not happen to often anyway. More generally, it seems to me that we should simply not try to deal with any obscure special cases, but simply require that every ring implements |
…en discovered, disable check for zero ring in is_field
Documentation preview for this PR (built with commit 75d4491; changes) is ready! 🎉 |
Cool! The failure
is real, but unrelated, it is the specific seed that triggers it. What is quite surprising to me: the only instance where a coercion is registered after a conversion was discovered is the one we found! |
@tscrim, is it hard to replace @cached_method
def one(self):
"""
Return the element `1` in ``self``.
EXAMPLES::
sage: S = SymmetricGroupAlgebra(QQ, 3)
sage: C = S.cellular_basis()
sage: C.one()
C([1, 1, 1], [[1], [2], [3]], [[1], [2], [3]])
+ C([2, 1], [[1, 2], [3]], [[1, 2], [3]])
+ C([2, 1], [[1, 3], [2]], [[1, 3], [2]])
+ C([3], [[1, 2, 3]], [[1, 2, 3]])
"""
return self(self._algebra.one()) by something that does not involve conversion? If so, I see three possibilities to proceed:
|
Basically it is impossible. This type of construction should be allowed anyways. I don't quite understand your analysis at this point, so I can't offer any advice. I will try to look at it this tonight or tomorrow, but it would be helpful if you could expand a bit on what the problem is. |
Hi @tscrim! Here is what I believe to understand. Consider the following setup:
We want to move def __init__(self, A, to_algebra=None, from_algebra=None, **kwargs):
...
cat = Algebras(A.category().base_ring()).FiniteDimensional().WithBasis().Cellular()
CombinatorialFreeModule.__init__(self, A.base_ring(), I,
prefix=prefix, bracket=False,
category=cat, **kwargs)
...
to_cellular.register_as_coercion()
from_cellular.register_as_coercion() After this PR, the
However, this map is apparently the wrong one. In fact, it is unable to compute Does this help? |
Interesting. This is something specific when the base ring is a number field. It comes from the number field testing the field-ness of the codomain for the base ring morphism. This returns diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py
index 68031c3d642..d58dd8633a3 100644
--- a/src/sage/rings/number_field/number_field.py
+++ b/src/sage/rings/number_field/number_field.py
@@ -136,15 +136,18 @@ lazy_import('sage.rings.universal_cyclotomic_field', 'UniversalCyclotomicFieldEl
_NumberFields = NumberFields()
-def is_NumberFieldHomsetCodomain(codomain):
+def is_NumberFieldHomsetCodomain(codomain, category=None):
"""
- Return whether ``codomain`` is a valid codomain for a number
- field homset.
+ Return whether ``codomain`` is a valid codomain for a number field
+ homset (as an object in the category ``category`` if specified).
This is used by NumberField._Hom_ to determine
whether the created homsets should be a
:class:`sage.rings.number_field.homset.NumberFieldHomset`.
+ This also takes into account the category, which checks if it is
+ a subcategory of :class:`Fields`.
+
EXAMPLES:
This currently accepts any parent (CC, RR, ...) in :class:`Fields`::
@@ -173,7 +176,9 @@ def is_NumberFieldHomsetCodomain(codomain):
False
"""
from sage.categories.fields import Fields
- return codomain in Fields()
+ if category is None:
+ return codomain in Fields()
+ return category.is_subcategory(Fields())
def proof_flag(t):
@@ -1988,7 +1993,7 @@ class NumberField_generic(WithEqualityById, number_field_base.NumberField):
sage: loads(dumps(H)) is H
True
"""
- if not is_NumberFieldHomsetCodomain(codomain):
+ if not is_NumberFieldHomsetCodomain(codomain, category):
# Using LazyFormat fixes #28036 - infinite loop
from sage.misc.lazy_format import LazyFormat
raise TypeError(LazyFormat("%s is not suitable as codomain for homomorphisms from %s") % (codomain, self))
@@ -11476,7 +11481,7 @@ class NumberField_cyclotomic(NumberField_absolute, sage.rings.abc.NumberField_cy
sage: End(CyclotomicField(21))
Automorphism group of Cyclotomic Field of order 21 and degree 12
"""
- if is_NumberFieldHomsetCodomain(codomain):
+ if is_NumberFieldHomsetCodomain(codomain, cat):
from sage.rings.number_field.homset import CyclotomicFieldHomset
return CyclotomicFieldHomset(self, codomain)
else: |
Let me put it another way, I think it is bad to have |
I agree, but it is not clear to me how to avoid that properly. In the case at hand, it is calling |
We can’t enforce it, but neither can we enforce people from doing other evil things with code (other than with careful reviewing and having good doctests). I think it is fairly rare that something like this will happen; in this case it is somewhat of a coincidence as the map already knows it is not a map as fields (in general). (Side note: it might be better for |
… is_NumberFieldHomsetCodomain
… move_is_field
@tscrim I don't fully understand your proposed change but maybe I am misunderstanding how things are supposed to work. So, when I say That said, it's unclear what
It seems odd to me that a function by that names looks at a category argument and not at the codomain at all. So, what this function is really about is whether |
Here's a different proposal. I played a bit with it locally, and it doesn't seem to be obviously broken. But maybe lots of doctests fail now. Let's see… |
This is independent of my latest change, but I don't think this is good: sage: K = CyclotomicField(3)
sage: Hom(K, ZZ).category()
-Category of homsets of euclidean domains and noetherian rings
+Category of homsets of unital magmas and additive unital additive magmas Fixed in 8715d39. |
@@ -556,6 +556,54 @@ def is_subring(self, other): | |||
except (TypeError, AttributeError): | |||
return False | |||
|
|||
def is_field(self, proof=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we tried to see what happens if we just delete this? (Maybe it makes the world a better place…)
so that the category (and other logic) is correct
Are we to blame for that?
Tests pass for me locally. Let's see if the CI is happy if we merge in dev again. |
i.e.
I doubt we have anything to do with that. |
This doctest in |
Co-authored-by: Travis Scrimshaw <clfrngrown@aol.com>
I have re-launched the CI. Not sure what is blocking us here now. |
You mean why the CI fails? I don't know. If you mean why this does not have positive review? I think we should set this to positive review. |
Co-authored-by: Travis Scrimshaw <clfrngrown@aol.com>
I think this is ready, isn't it? |
I think so. But let me first re-run the tests by merging with the latest beta. |
ok, this looks good enough. I am setting to positive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move on
sagemathgh-39520: move is_field from Ring to Rings We move the method `is_field` from the class `Ring` to the category `Rings` URL: sagemath#39520 Reported by: Martin Rubey Reviewer(s): Frédéric Chapoton, Julian Rüth, Martin Rubey, Travis Scrimshaw
We move the method
is_field
from the classRing
to the categoryRings