-
-
Notifications
You must be signed in to change notification settings - Fork 559
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
Implement preimage computation for Homomorphism from Quotient Ring to Finite Field of the same characteristic #39709
base: develop
Are you sure you want to change the base?
Conversation
…inting based on PR:39699
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.
I will look at it more detailedly later once my Sage rebuilds.
By the way, please avoid touching random styling issues in the future, I know it annoys you (and me) but better do it in a separate PR (and we should have more of those!)
src/sage/rings/morphism.pyx
Outdated
sage: f._preimage_from_linear_dependence(z) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: The cardinalities of the domain (=1024) and codomain (=64) should be equal. |
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.
ValueError: The cardinalities of the domain (=1024) and codomain (=64) should be equal. | |
ValueError: the cardinalities of the domain (=1024) and codomain (=64) should be equal |
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.
Done! (Check new commit)
src/sage/rings/morphism.pyx
Outdated
D = self.domain() | ||
C = self.codomain() | ||
if (d_card := D.cardinality()) != (c_card := C.cardinality()): | ||
raise ValueError(f"The cardinalities of the domain (={d_card}) and codomain (={c_card}) should be equal.") |
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.
raise ValueError(f"The cardinalities of the domain (={d_card}) and codomain (={c_card}) should be equal.") | |
raise ValueError(f"the cardinalities of the domain (={d_card}) and codomain (={c_card}) should be equal") |
errors should start with lowercase and not end with punctuations
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.
Done! (Check new commit)
src/sage/rings/morphism.pyx
Outdated
raise TypeError(f"{b} fails to convert into the morphism's codomain {C}") | ||
F1 = D.base_ring() | ||
if F1.prime_subfield() != C.prime_subfield(): | ||
raise NotImplementedError("The domain's base ring and codomain's prime subfields should match.") |
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.
raise NotImplementedError("The domain's base ring and codomain's prime subfields should match.") | |
raise ValueError("the domain's base ring and codomain's prime subfields should match") |
It seems to be this should be a value error?
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.
Done! (Check new commit)
src/sage/rings/morphism.pyx
Outdated
from sage.rings.finite_rings.finite_field_base import FiniteField | ||
from sage.rings.quotient_ring import QuotientRing_nc | ||
if isinstance(self.domain(), QuotientRing_nc) and isinstance(self.codomain(), FiniteField): | ||
if self.domain().base_ring().prime_subfield() == self.codomain().prime_subfield(): | ||
return self._preimage_from_linear_dependence(b) |
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.
Can you add a test for this part by the way?
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.
Since _inverse_image_element
is a private function, the tests inside should call a public function that eventually calls this private one (for example the rest tests use inverse_image
). Is that okay?
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.
Yes. You can add the indirect doctest tag after the test to make the coverage test happy (does anyone care...)
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.
Done! (Check new commit)
Also, do you mind elaborating what happens if the map is not bijective but domain and codomain have the same size? And another question, since ring homs are decided by the action on the generators, would it be more efficient if you cache the result |
src/sage/rings/morphism.pyx
Outdated
from sage.rings.finite_rings.finite_field_base import FiniteField | ||
from sage.rings.quotient_ring import QuotientRing_nc | ||
if isinstance(self.domain(), QuotientRing_nc) and isinstance(self.codomain(), FiniteField): | ||
if self.domain().base_ring().prime_subfield() == self.codomain().prime_subfield(): |
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.
if self.domain().base_ring().prime_subfield() == self.codomain().prime_subfield(): | |
if self.domain().base_ring().prime_subfield() is self.codomain().prime_subfield(): |
Sage (especially algebraic) stuff usually inherit from UniqueFactory
so is
works and is faster (bypasses coercion).
One more comment: I realised that this PR is supposed to fix #39690. Can you reflect that in your test? In other words, add a test (or really just a line) showing that |
This test should be included in |
|
Documentation preview for this PR (built with commit 11ae3b1; changes) is ready! 🎉 |
Technical Details
This PR introduces a new function into the file$f$ from a univariate polynomial quotient ring to a finite extension field extension. When the codomain's field degree is the same as the domain's base ring degree, and the domain is constructed from an irreducible polynomial, $f$ is guaranteed to have a preimage for any element and
src/sage/rings/morphism.pyx
, named_preimage_from_linear_dependence
.More specifically, it computes the preimage of an element for a homomorphism
_preimage_from_linear_dependence
returns this preimage.Fixes #39690.
The way this function is currently used, it fixes the
NotImplementedError
raised by:f.inverse
f.inverse_image
andf._inverse_image_element
How it was fixed?
Internally,
_inverse_image_element
calls_graph_ideal
which is the cause of the NotImplementedError due to the checkA.base_ring() != B.base_ring()
. Now, before calling_graph_ideal
, the new method_preimage_from_linear_dependence
is conditionally called and returns early, thereby avoiding the error.I have not included any documentation because it's supposed to be used as an internal function. Let me know if it is needed.
📝 Checklist
⌛ Dependencies