Skip to content

Commit

Permalink
gh-35174: cleaning and enhancement to PolyDict
Browse files Browse the repository at this point in the history
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes #1234" use "Introduce new method to
calculate 1+1"
-->
### 📚 Description

Fixes #34000 (and more complete version of the proposition at #35020).

A discussion about the general problem of inexact zeros has been opened
at #35319

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] I have made sure that the title is self-explanatory and the
description concisely explains the PR.
- [x] I have linked an issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.
    
URL: #35174
Reported by: Vincent Delecroix
Reviewer(s): Frédéric Chapoton, Travis Scrimshaw, Vincent Delecroix
  • Loading branch information
Release Manager committed Mar 24, 2023
2 parents 85b1e02 + 1a7eeac commit 1e77797
Show file tree
Hide file tree
Showing 8 changed files with 1,337 additions and 820 deletions.
5 changes: 2 additions & 3 deletions src/sage/rings/polynomial/hilbert.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ cdef list quotient_by_var(list L, size_t index):
cdef list result = L[:len(L)] # creates a copy
cdef size_t i
for i in range(len(L)):
m_j = (<ETuple>PyList_GET_ITEM(L,i)).divide_by_var(index)
if m_j is not None:
result.append(m_j)
if (<ETuple> PyList_GET_ITEM(L, i)).get_exp(index):
result.append((<ETuple> PyList_GET_ITEM(L, i)).divide_by_var(index))
return interred(result)

cdef ETuple sum_from_list(list L, size_t s, size_t l):
Expand Down
18 changes: 9 additions & 9 deletions src/sage/rings/polynomial/laurent_polynomial.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Elements of Laurent polynomial rings

from sage.rings.integer cimport Integer
from sage.categories.map cimport Map
from sage.structure.element import is_Element, coerce_binop
from sage.structure.element import is_Element, coerce_binop, parent
from sage.structure.factorization import Factorization
from sage.misc.derivative import multi_derivative
from sage.rings.polynomial.polydict cimport monomial_exponent
from sage.rings.polynomial.polynomial_element import Polynomial
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
from sage.structure.richcmp cimport richcmp, rich_to_bool
Expand Down Expand Up @@ -2254,12 +2255,12 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial):
cdef dict D = <dict> self._poly.dict()
cdef dict DD
if self._mon.is_constant():
self._prod = PolyDict(D, force_etuples=False)
self._prod = PolyDict(D)
return
DD = {}
for k in D:
DD[k.eadd(self._mon)] = D[k]
self._prod = PolyDict(DD, force_etuples=False)
self._prod = PolyDict(DD)

def is_unit(self):
"""
Expand Down Expand Up @@ -2556,19 +2557,18 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial):
sage: f.monomial_coefficient(x + y)
Traceback (most recent call last):
...
ValueError: input must be a monomial
ValueError: not a monomial
"""
if mon.parent() != self._parent:
if parent(mon) != self._parent:
raise TypeError("input must have the same parent")
cdef LaurentPolynomial_mpair m = <LaurentPolynomial_mpair> mon
if m._prod is None:
m._compute_polydict()
if len(m._prod) != 1:
raise ValueError("input must be a monomial")
if self._prod is None:
self._compute_polydict()
c = self._prod.monomial_coefficient(m._prod.dict())
return self._parent.base_ring()(c)
exp = monomial_exponent(m._prod)
zero = self._parent.base_ring().zero()
return self._prod.get(exp, zero)

def constant_coefficient(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/multi_polynomial.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ cdef class MPolynomial(CommutativePolynomial):
sage: F.reduced_form(prec=50, smallest_coeffs=False)
Traceback (most recent call last):
...
ValueError: accuracy of Newton's root not within tolerance(0.0000124... > 1e-06), increase precision
ValueError: accuracy of Newton's root not within tolerance(0.000012... > 1e-06), increase precision
sage: F.reduced_form(prec=100, smallest_coeffs=False)
(
[-1 -1]
Expand Down
Loading

0 comments on commit 1e77797

Please sign in to comment.