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

Fix change_ring method of multi-variate polynomials #37159

Merged
merged 4 commits into from
Feb 2, 2024

Conversation

kwankyu
Copy link
Collaborator

@kwankyu kwankyu commented Jan 25, 2024

Fixes #36832.

📝 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

@kwankyu kwankyu changed the title Use base_map in change_ring method Use base_map in change_ring method of multi-variate polynomial rings Jan 25, 2024
@kwankyu kwankyu changed the title Use base_map in change_ring method of multi-variate polynomial rings Fix change_ring method of multi-variate polynomial rings Jan 25, 2024
@kwankyu kwankyu changed the title Fix change_ring method of multi-variate polynomial rings Fix change_ring method of multi-variate polynomial Jan 25, 2024
@kwankyu kwankyu marked this pull request as ready for review January 25, 2024 07:14
@kwankyu kwankyu changed the title Fix change_ring method of multi-variate polynomial Fix change_ring method of multi-variate polynomials Jan 25, 2024
@JohnCremona
Copy link
Member

Since you are claiming that this fixes #36832, please could you add at least one doctest showing that the errors previously existing have been fixed by this? With that, and assuming that this change does not break anything else, I would be happy with merging it, though I confess that I have not looked into the details.

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 25, 2024

Sure. Done. Moreover

Before the patch:

sage: F = GF(11)
sage: phi = Hom(F, F.extension(2)).an_element()
sage: R.<x,y> = F[]
sage: x.change_ring(phi)
sage: timeit('x.change_ring(phi)')
625 loops, best of 3: 148 μs per loop

After the patch:

sage: F = GF(11)
sage: phi = Hom(F, F.extension(2)).an_element()
sage: R.<x,y> = F[]
sage: x.change_ring(phi)
sage: timeit('x.change_ring(phi)')
625 loops, best of 3: 53 μs per loop

Hence the new change_ring is faster!

@mantepse
Copy link
Collaborator

Hence the new change_ring is faster!

I don't understand. Wasn't #36832 about the following?

sage: F = GF(11)
sage: phi = Hom(F,F).an_element()
sage: R.<x,y> = F[]
sage: x.change_ring(phi)

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 25, 2024

Hence the new change_ring is faster!

I don't understand. Wasn't #36832 about the following?

sage: F = GF(11)
sage: phi = Hom(F,F).an_element()
sage: R.<x,y> = F[]
sage: x.change_ring(phi)

Yes. That (which didn't work before) is fixed by this PR. But as a bonus, the PR speeds up already working cases.

@mantepse
Copy link
Collaborator

Hence the new change_ring is faster!

I don't understand. Wasn't #36832 about the following?

sage: F = GF(11)
sage: phi = Hom(F,F).an_element()
sage: R.<x,y> = F[]
sage: x.change_ring(phi)

Yes. That (which didn't work before) is fixed by this PR. But as a bonus, the PR speeds up already working cases.

It would be good to make that a doctest, don't you think?

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 25, 2024

Hence the new change_ring is faster!

I don't understand. Wasn't #36832 about the following?

sage: F = GF(11)
sage: phi = Hom(F,F).an_element()
sage: R.<x,y> = F[]
sage: x.change_ring(phi)

Yes. That (which didn't work before) is fixed by this PR. But as a bonus, the PR speeds up already working cases.

It would be good to make that a doctest, don't you think?

Above one? A doctest is already added by ccaa957.

@tornaria
Copy link
Contributor

Notes:

  • could you squash together the first two commits? The first one makes a change that the second one changes again. That makes history more difficult to use.
  • is it possible to separate the pycodestyle changes from the actual fix?
  • could mention Fix change_ring method of multi-variate polynomials #37159 (and/or Random failure in ell_field.py with division_field #36832) in the commit message
  • maybe it's reasonable to add a test in ell_field.py that (deterministically) triggers the original issue.
  • I'm not sure what happens with the same code in src/sage/rings/polynomial/multi_polynomial_element.py? Is it ever used? In any case, it's either redundant (should be removed) or buggy (also it checks isinstance(R, Morhpism) instead of isinstance(R, Map), this comes also from Change ring to QQbar fails for subschemes #20067 and was fixed in the other two occurrences).

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 30, 2024

Notes:

  • could you squash together the first two commits? The first one makes a change that the second one changes again. That makes history more difficult to use.
  • is it possible to separate the pycodestyle changes from the actual fix?

Done.

Sorry but I don't see the need.

  • maybe it's reasonable to add a test in ell_field.py that (deterministically) triggers the original issue.

As the failure in ell_field.py is a derivative from one in src/sage/rings/polynomial/multi_polynomial.pyx, for which a test is added, I think a test in ell_field.py is redundant.

  • I'm not sure what happens with the same code in src/sage/rings/polynomial/multi_polynomial_element.py? Is it ever used? In any case, it's either redundant (should be removed) or buggy (also it checks isinstance(R, Morhpism) instead of isinstance(R, Map), this comes also from Change ring to QQbar fails for subschemes #20067 and was fixed in the other two occurrences).

Right, it seems redundant. Removed and combined with the one in src/sage/rings/polynomial/multi_polynomial.pyx. Thanks for pointing this out.

Copy link

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

@tornaria
Copy link
Contributor

LGTM

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 30, 2024

Thanks!

@vbraun vbraun merged commit 02fbbdd into sagemath:develop Feb 2, 2024
22 of 24 checks passed
@mkoeppe mkoeppe added this to the sage-10.3 milestone Mar 7, 2024
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.

Random failure in ell_field.py with division_field
6 participants