Skip to content

gh-38632: Fix .degrees() to return ETuple and add as_ETuples parameter - #42634

Open
Chaitanya140904 wants to merge 2 commits into
sagemath:developfrom
Chaitanya140904:polynomial-degrees-etuple
Open

gh-38632: Fix .degrees() to return ETuple and add as_ETuples parameter#42634
Chaitanya140904 wants to merge 2 commits into
sagemath:developfrom
Chaitanya140904:polynomial-degrees-etuple

Conversation

@Chaitanya140904

Copy link
Copy Markdown
Contributor

The .degrees() method on multivariate polynomials is documented to return
an ETuple, but in practice most backends returned a plain tuple, making
the behavior inconsistent and the documentation incorrect.

What problem does this solve?

sage: R.<x,y,z> = QQ[]
sage: type(x.degrees())
<class 'tuple'>   # ← was wrong, should be ETuple

…parameter

The .degrees() method on multivariate polynomials was documented to
return an ETuple but actually returned a plain tuple in most backends.

Changes:
- multi_polynomial_element.py: return ETuple by default (was already
  returning ETuple via max_exp(), but now also supports as_ETuples=False)
- multi_polynomial_libsingular.pyx: return ETuple by default (was returning
  plain tuple of Integers); add as_ETuples parameter
- plural.pyx: return ETuple by default (was returning plain tuple);
  add as_ETuples parameter

All three backends now accept as_ETuples=True (default, returns ETuple)
and as_ETuples=False (returns plain tuple), consistent with the
existing .exponents(as_ETuples=True) API.

Fixes: sagemath#38632
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Documentation preview for this PR (built with commit 574ffb4; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

ETuple does not support negative indexing, so changing the default
return type from tuple to ETuple broke existing code like:
  self.polynomial().degrees()[-1]

Fix: keep as_ETuples=False (plain tuple) as the default, so
existing code is unaffected. Users who want ETuple can pass
as_ETuples=True explicitly.
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.

1 participant