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

cleaning and enhancement to PolyDict #35174

Merged
merged 47 commits into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d935b6c
34000: cleaning and enhancement to polydict
Jun 16, 2022
7a5c0d7
34000: remove PolyDict.__pow__
Jun 16, 2022
d516cef
34000: cleaner optimization in derivative/integral
Jun 18, 2022
cd246f7
34000: clarify RuntimeError
Jun 18, 2022
8a36083
34000: two little optimizations
Jun 18, 2022
d5fd656
34000: replace RuntimeError with assertion
Jun 18, 2022
182d756
34000: fix Polydict.homogenize and ETuple.eadd_p
Jun 19, 2022
366436f
34000: fix zero coefficient in PolyDict.homogenize
Jun 19, 2022
052cd62
34000: make a copy of input in PolyDict.__init__
Jun 19, 2022
012e322
34000: do not simplify zero coefficients in PolyDict
Jun 19, 2022
d21202e
34000: fix doctest in multi_polynomial.pyx
Aug 12, 2022
6d9cefa
34000: change tate algebras doctests
Aug 12, 2022
75cafe7
34000: doc details
Aug 12, 2022
5d86a92
some fixes for ticket 34000
fchapoton Feb 12, 2023
1b6c82e
fix doctests
fchapoton Feb 12, 2023
b82030f
34000: declare all degree methods as cpdef and doctest some of them
videlec Feb 22, 2023
73dd75b
34000: check -1 return value when calling gen_index
videlec Feb 22, 2023
d3124b0
34000: deprecate remove_zero arg in constructor + remove_zeros cleaning
videlec Feb 22, 2023
3785023
34000: clean PolyDict comparison
videlec Feb 22, 2023
29292d6
34000: remove PolyDict.valuation
videlec Feb 22, 2023
6d5847a
34000: use type rather isinstance
videlec Feb 22, 2023
3cd2b22
34000: modernize PolyDict pickling/unpickling
videlec Feb 22, 2023
1661dff
34000: optimize with memcpy in one place
videlec Feb 22, 2023
b830bbd
34000: remove useless type annotation for self
videlec Feb 22, 2023
c277ee3
34000: design a cleaner PolyDict.get to replace PolyDict.monomial_coe…
videlec Feb 22, 2023
9cb7adf
34000: doc and clean in polydict.pyx
videlec Feb 22, 2023
4705d0d
34000: adapt polynomials to the changes in PolyDict
videlec Feb 22, 2023
81f4845
change url in deprecation warning message
videlec Feb 25, 2023
eb5dfef
remove inaccurate statement in __richcmp__ docstring
videlec Feb 25, 2023
3d7852e
Update polydict.pyx
fchapoton Mar 9, 2023
b2fe0fc
self.base_ring()(right) -> right.constant_coefficient()
videlec Mar 18, 2023
5d9ee4e
datastructure -> data structure
videlec Mar 18, 2023
3b1b364
improve PolyDict constructor
videlec Mar 18, 2023
8dd263b
cython for loop optimization and cleaning
videlec Mar 18, 2023
7768edf
PolyDict doc
videlec Mar 18, 2023
1bbb481
more tests
videlec Mar 18, 2023
dfd6609
introduce a check argument for PolyDict faster constructor
videlec Mar 19, 2023
23d50f4
cleaner MPolynomialRing_polydict.sum
videlec Mar 19, 2023
f65a16c
More optimization and cleaning
videlec Mar 19, 2023
a85d717
declare except * for errors
videlec Mar 19, 2023
563b77c
more flexible PolyDict.remove_zeros and fix PolyDict.__mul__
videlec Mar 19, 2023
e7e79fc
fix declarations in poldict.pxd
videlec Mar 19, 2023
9d38b94
implement apply_map and deprecate coerce_coefficients
videlec Mar 19, 2023
b47c982
remove unused imports
videlec Mar 19, 2023
db9aed3
ultimate doc cleaning
videlec Mar 19, 2023
0e0e5f8
mention inexact zeros issue
videlec Mar 20, 2023
1a7eeac
some final details
videlec Mar 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 8 additions & 8 deletions src/sage/rings/polynomial/multi_polynomial_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def __iter__(self):
ring = self.parent()
one = ring.base_ring().one()
for exp in self._exponents:
yield (elt[exp], MPolynomial_polydict(ring, polydict.PolyDict({exp:one})))
yield (elt[exp], MPolynomial_polydict(ring, polydict.PolyDict({exp: one}, check=False)))

def __getitem__(self, x):
"""
Expand Down Expand Up @@ -1459,7 +1459,7 @@ def monomials(self):
"""
ring = self.parent()
one = ring.base_ring().one()
return [MPolynomial_polydict(ring, polydict.PolyDict({m:one}))
return [MPolynomial_polydict(ring, polydict.PolyDict({m: one}, check=False))
for m in self._exponents]

def constant_coefficient(self):
Expand Down Expand Up @@ -1708,9 +1708,9 @@ def lm(self):
if self.is_zero():
return self
R = self.parent()
f = self._MPolynomial_element__element.lcmt( R.term_order().greater_tuple )
f = self._MPolynomial_element__element.lcmt(R.term_order().greater_tuple)
one = R.base_ring().one()
self.__lm = MPolynomial_polydict(R,polydict.PolyDict({f:one}))
self.__lm = MPolynomial_polydict(R,polydict.PolyDict({f: one}, check=False))
return self.__lm

def lc(self):
Expand Down Expand Up @@ -1767,8 +1767,8 @@ def lt(self):
return self
R = self.parent()
f = self._MPolynomial_element__element.dict()
res = self._MPolynomial_element__element.lcmt( R.term_order().greater_tuple )
self.__lt = MPolynomial_polydict(R, polydict.PolyDict({res:f[res]}))
res = self._MPolynomial_element__element.lcmt(R.term_order().greater_tuple)
self.__lt = MPolynomial_polydict(R, polydict.PolyDict({res: f[res]}, check=False))
return self.__lt

def __eq__(self, right):
Expand Down Expand Up @@ -1881,7 +1881,7 @@ def _derivative(self, var=None):
# var is not a generator; do term-by-term differentiation recursively
# var may be, for example, a generator of the base ring
d = dict([(e, x._derivative(var)) for (e, x) in self.dict().items()])
d = polydict.PolyDict(d)
d = polydict.PolyDict(d, check=False)
d.remove_zeros()
return MPolynomial_polydict(P, d)

Expand Down Expand Up @@ -1976,7 +1976,7 @@ def integral(self, var=None):
# var may be, for example, a generator of the base ring
d = {e: x.integral(var)
for e, x in self.dict().items()}
d = polydict.PolyDict(d)
d = polydict.PolyDict(d, check=False)
d.remove_zeros()
else:
# integrate w.r.t. indicated variable
Expand Down
9 changes: 6 additions & 3 deletions src/sage/rings/polynomial/multi_polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,11 +911,14 @@ def sum(self, terms):
sage: sum([x*y, 2*x^2*z - 2*x*y, 1 + y + z])
(-x + 1)*y + (2*x^2 + 1)*z + 1
"""
ans = self(0)
elt = ans.element()
elt = PolyDict({}, check=False)
for t in terms:
elt += self(t).element()
return ans
# NOTE: here we should be using self.element_class but polynomial rings are not complient
# with categories...
from sage.rings.polynomial.multi_polynomial_element import MPolynomial_polydict
return MPolynomial_polydict(self, elt)


class MPolynomialRing_polydict_domain(IntegralDomain,
MPolynomialRing_polydict):
Expand Down
18 changes: 10 additions & 8 deletions src/sage/rings/polynomial/polydict.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ cdef class PolyDict:
cdef dict __repn

cdef PolyDict _new(self, dict pdict)
cpdef remove_zeros(self)
cpdef remove_zeros(self, zero_test=*)


cdef class ETuple:
cdef size_t _length
cdef size_t _nonzero
cdef int *_data

cdef size_t get_position(self, size_t i, size_t start, size_t end)
cdef ETuple _new(self)
cdef int get_exp(self, size_t i)

cpdef int unweighted_degree(self) except *
cpdef int weighted_degree(self, tuple w) except *
cpdef int unweighted_quotient_degree(self, ETuple other) except *
Expand All @@ -22,19 +26,17 @@ cdef class ETuple:
cpdef ETuple emax(self, ETuple other)
cpdef ETuple eadd_p(self, int other, size_t pos)
cpdef ETuple eadd_scaled(self, ETuple other, int scalar)
cpdef int dotprod(self, ETuple other)
cpdef int dotprod(self, ETuple other) except *
cpdef ETuple escalar_div(self, int n)
cdef ETuple divide_by_gcd(self, ETuple other)
cdef ETuple divide_by_var(self, size_t index)
cdef bint divides(self, ETuple other)
cpdef ETuple divide_by_gcd(self, ETuple other)
cpdef ETuple divide_by_var(self, size_t pos)
cpdef bint divides(self, ETuple other) except *
cpdef bint is_constant(self)
cpdef bint is_multiple_of(self, int n)
cpdef bint is_multiple_of(self, int n) except *
cpdef list nonzero_positions(self, bint sort=*)
cpdef common_nonzero_positions(self, ETuple other, bint sort=*)
cpdef list nonzero_values(self, bint sort=*)
cpdef ETuple reversed(self)
cdef ETuple _new(self)
cdef int get_exp(self, size_t i)

cpdef int gen_index(PolyDict x)
cpdef ETuple monomial_exponent(PolyDict p)
Loading