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 #34000 #35020

Closed
wants to merge 19 commits into from

Conversation

fchapoton
Copy link
Contributor

This fixes #34000

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

βŒ› Dependencies

@dimpase dimpase changed the title Ticket34000 cleaning and enhancement to PolyDict #34000 Feb 8, 2023
@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2023

Codecov Report

Base: 88.59% // Head: 88.59% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (027d93a) compared to base (104dde9).
Patch coverage: 95.38% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #35020      +/-   ##
===========================================
- Coverage    88.59%   88.59%   -0.01%     
===========================================
  Files         2136     2136              
  Lines       396142   396156      +14     
===========================================
+ Hits        350948   350958      +10     
- Misses       45194    45198       +4     
Impacted Files Coverage Ξ”
.../sage/rings/polynomial/multi_polynomial_element.py 90.67% <94.33%> (-0.42%) ⬇️
src/sage/rings/polynomial/multi_polynomial_ring.py 86.25% <100.00%> (+0.35%) ⬆️
src/sage/version.py 100.00% <100.00%> (ΓΈ)
src/sage/misc/banner.py 72.97% <0.00%> (-14.87%) ⬇️
src/sage/interfaces/qsieve.py 71.30% <0.00%> (-2.61%) ⬇️
src/sage/rings/polynomial/pbori/parallel.py 59.82% <0.00%> (-1.79%) ⬇️
src/sage/modular/hecke/algebra.py 94.65% <0.00%> (-1.07%) ⬇️
src/sage/modular/arithgroup/congroup_gamma0.py 94.41% <0.00%> (-0.56%) ⬇️
src/sage/graphs/generic_graph.py 89.12% <0.00%> (-0.42%) ⬇️
src/sage/rings/continued_fraction.py 90.46% <0.00%> (-0.17%) ⬇️
... and 13 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

β˜” View full report at Codecov.
πŸ“’ Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@roed314 roed314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall there are a bunch of improvements here. Aside from the handling of inexact zeros, I didn't notice any major problems, though adding more documentation and testing may take some work.

-y + 1
"""
return self.__class__(self.parent(), -self.__element)

def _add_(self, right):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a docstring

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #35174

return self.__class__(self.parent(),self.__element + right.__element)
elt = self.__element + right.__element
elt.remove_zeros()
return self.__class__(self.parent(), elt)

def _sub_(self, right):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a docstring

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #35174

S = P.change_ring(Q)

if P is not S:
return S.coerce(self).derivative(var)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be S.coerce(self).integral(var)?

pdict = new_pdict
if isinstance(pdict, list):
v = {}
L = <list> pdict
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think using <list> here does anything; perhaps just remove this line and update the iteration on the next.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I thought this changes the behavior of Cython. The <list> cast is supposedly optimized assuming pdict is a list.

pdict = new_pdict
if isinstance(pdict, list):
v = {}
L = <list> pdict
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think using <list> here does anything; perhaps just remove this line and update the iteration on the next.

src/sage/rings/polynomial/polydict.pyx Show resolved Hide resolved
src/sage/rings/polynomial/polydict.pyx Show resolved Hide resolved
result._nonzero -= 1
rindex -= 1
need_to_add = 0
result._data = <int*> sig_malloc(sizeof(int) * (self._nonzero + 1) * 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a problem that self._nonzero + 1 might be wrong? I'm not sure what the __dealloc__ looks like, but this might cause a memory leak.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A memory leak definitely not. But there could be an overflow in the operation sizeof(int) * (self._nonzero + 1) * 2. As this is not the only place where is it is not checked I would not worry too much.

@@ -2241,8 +2438,7 @@ cdef class ETuple:


def make_PolyDict(data):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a docstring.

Copy link
Contributor

@videlec videlec Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually make_PolyDict is useless (except for old pickles from previous sage versions).

@@ -857,7 +857,7 @@ def groebner_basis_pote(I, prec, verbose=0):
sage: I.groebner_basis(algorithm="PoTe", prec=100) # indirect doctest
[...0000000001*x^3 + ...2222222222*y + ...000000000*x^2*y^2 + O(3^99 * <x, y>),
...0000000001*x^2*y + ...01210121020 + O(3^100 * <x, y>),
...0000000001*y^2 + ...01210121020*x + ...000000000*x^2*y^3 + ...0000000000*x^3*y + O(3^99 * <x, y>)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing inexact zeros is a regression. I know that there was some discussion on the ticket (and also that handling inexact zeros overall in Sage isn't perfect), but perhaps the remove_zeros method can check to see if the base ring is inexact? Ideally I'd like to keep inexact zeros for most p-adic rings (excepting floating point and fixed mod precision), power series, and real interval fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inexactitude of the base ring is not accurate enough. For example, you do want to remove zeros for floating points.

@videlec
Copy link
Contributor

videlec commented Feb 22, 2023

The merge ddb15a3 made the comments outdated. It is very annoying to introduce merge commits without any serious reason.

@videlec
Copy link
Contributor

videlec commented Feb 22, 2023

Since I am not allowed to push here I opened #35174 to actually fix #34000

vbraun pushed a commit that referenced this pull request Mar 26, 2023
    
<!-- ^^^^^
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
@fchapoton
Copy link
Contributor Author

@videlec
can we close this one as dpulicate of #35174 ?

@fchapoton
Copy link
Contributor Author

This now conflicts with the changes done elsewhere.
So closing as duplicate

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.

cleaning and enhancement to PolyDict
6 participants