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 the method monomials_of_degree #35043

Merged
merged 3 commits into from
Mar 13, 2023

Conversation

DavidAyotte
Copy link
Member

@DavidAyotte DavidAyotte commented Feb 9, 2023

πŸ“š Description

Fixes #35042.

The goal of this PR is to fix two bugs of the method monomials_of_degree. First, the code does not take into account the case of weighted polynomial ring:

sage: P = PolynomialRing(QQ, 3, 'x,y,z', order=TermOrder('wdeglex', [4,5,6]))
sage: P.inject_variables()
Defining x, y, z
sage: x.degree()
4
sage: P.monomials_of_degree(1)
[x, y, z]

Next, as pointed out by @videlec, the current list of monomial that is returned is not sorted:

sage: R.<x,y,z> = ZZ[]
sage: mons = R.monomials_of_degree(2)
sage: mons
[x^2, x*y, x*z, y^2, y*z, z^2]
sage: sorted(mons)
[z^2, y*z, x*z, y^2, x*y, x^2]
sage: 

CC: @videlec, @yyyyx4

πŸ“ Checklist

  • I have made sure that the title is self-explanatory and the description concisely explains the PR.
  • I have linked an issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

βŒ› Dependencies

@yyyyx4
Copy link
Member

yyyyx4 commented Feb 9, 2023

Looks good so far, and sorry for not thinking of weighted polynomial rings when I wrote that method.

Could you add a doctest to demonstrate the corrected behavior?

@yyyyx4 yyyyx4 self-requested a review February 9, 2023 13:01
@videlec
Copy link
Contributor

videlec commented Feb 9, 2023

Let me mention that there are two bugs in the initial implementation. The term ordering is also not taken care of in the output (it ought to be sorted).

@DavidAyotte
Copy link
Member Author

Ok I added doctests. I'm not sure whether or not there is a better way of getting the degrees of the generators.

@videlec
Copy link
Contributor

videlec commented Feb 9, 2023

Could you add examples with different terms ordering (and no weighting)?

@videlec
Copy link
Contributor

videlec commented Feb 9, 2023

Nice!

@yyyyx4 yyyyx4 removed their request for review February 9, 2023 22:30
@vbraun vbraun merged commit f6da2bd into sagemath:develop Mar 13, 2023
@mkoeppe mkoeppe added this to the sage-10.0 milestone Mar 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.

Fix the method monomials_of_degree
5 participants