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

sage.rings.finite_rings: Modularization fixes, # needs #36056

Merged
merged 23 commits into from
Aug 13, 2023

Conversation

mkoeppe
Copy link
Contributor

@mkoeppe mkoeppe commented Aug 10, 2023

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

@@ -45,19 +48,19 @@ def conway_polynomial(p, n):

EXAMPLES::

sage: conway_polynomial(2,5)
sage: conway_polynomial(2,5) # needs conway_polynomials
x^5 + x^2 + 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the tag be file-scoped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module also contains code for computing pseudo-Conway polynomials, which has to be used when the database is not available

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.rings.finite_rings
# sage.doctest: needs sage.rings.finite_rings
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't all files in src/sage/rings/finite_rings installed by the distribution that provides the feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sagemath-categories ships the basic modules of sage.rings.finite_rings - https://github.com/mkoeppe/sage/blob/t/32432/modularization_of_sagelib__break_out_a_separate_package_sagemath_polyhedra/pkgs/sagemath-categories/MANIFEST.in.m4#L109-L123

This makes the prime fields and the integer mod rings available.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I missed it.

try:
return ConwayPolynomials().has_polynomial(p,n)
except ImportError:
return False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it incorrect to return False when the database is not available? Why catch ImportError?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is named exists_conway_polynomial, but it actually only tests whether it is known to Sage. When the database is not installed, nothing is known to Sage.
Return False here triggers the use of pseudo-Conway polynomials in the relevant code paths.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That is reasonable. Thanks.

Partially defined reduction map:
From: Fraction Field of
Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X)
To: Residue field in tbar of Principal ideal (t^7 + t^6 + t^5 + t^4 + 1) of
Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X)
sage: type(k)
sage: type(k) # needs sage.libs.linbox
<class 'sage.rings.finite_rings.residue_field_givaro.ResidueFiniteField_givaro_with_category'>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right? Needs sage.libs.linbox to get type(k) but does not to create k?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple implementations available that can cover a given p.
This example works even when NTL and LinBox are not available, but the tests hardcode the implementation ("using GF2X") based on NTL and LinBox being standard packages.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Thanks for explaining.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we may handle this in a similar way as below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the change below because that doctest is just displaying the codomain.

Here k has already been displayed, so the doctest seems to be intended to display a specific type.
So I'm keeping it in the current form

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
sage: k.<a> = R.residue_field(h)
sage: K = R.fraction_field()
sage: L = k.lift_map(); L.codomain()
sage: L = k.lift_map(); L.codomain() # needs sage.libs.ntl
Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If sage.libs.ntl is needed just for k.lift_map() and L.codomain(), perhaps sage.rings.finite_rings should depend on sage.libs.ntl. No?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the test also works when only PARI provides an implementation, but then the text "(using GF2X)" is missing.

Copy link
Collaborator

@kwankyu kwankyu Aug 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

An alternative (but less confusing) way to handle it is

sage: L = k.lift_map(); L.codomain()                                       
Univariate Polynomial Ring in t over Finite Field of size 2 (...)

or something similar.

Copy link
Contributor Author

@mkoeppe mkoeppe Aug 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done in 744ddf8.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@github-actions
Copy link

Documentation preview for this PR (built with commit 744ddf8; changes) is ready! 🎉

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Aug 12, 2023

Thank you!

@vbraun vbraun merged commit d6c6f62 into sagemath:develop Aug 13, 2023
@mkoeppe mkoeppe added this to the sage-10.1 milestone Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants