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

normalization (and hash) for Laurent polynomials is broken #21272

Closed
videlec opened this issue Aug 17, 2016 · 27 comments
Closed

normalization (and hash) for Laurent polynomials is broken #21272

videlec opened this issue Aug 17, 2016 · 27 comments

Comments

@videlec
Copy link
Contributor

videlec commented Aug 17, 2016

sage: R.<t> = LaurentPolynomialRing(ZZ)
sage: hash(R.zero())
0
sage: hash(t - t)
1

Original report:

https://groups.google.com/forum/#!topic/sage-support/HqP8dXYNDTU

see also: #21284

Component: algebra

Author: Vincent Delecroix

Branch/Commit: 85b064e

Reviewer: Julian Rüth

Issue created by migration from https://trac.sagemath.org/ticket/21272

@videlec videlec added this to the sage-7.4 milestone Aug 17, 2016
@videlec videlec changed the title hash for Laurent polynomials is broken normalization (and hash) for Laurent polynomials is broken Aug 17, 2016
@nbruin
Copy link
Contributor

nbruin commented Aug 18, 2016

comment:2

Fixing __normalize should be pretty easy: laurent polynomials are represented as u*xn, where u is a unit or 0. Normalize should simply force n to be a particular value (probably n=0) if u=0.

@videlec
Copy link
Contributor Author

videlec commented Aug 18, 2016

comment:3

Sure but there are other things I want to do:

  • the hash should coincide with polynomials when valuation is >= 0
  • the hash should be non-trivial enough to avoid simple collisions

@videlec

This comment has been minimized.

@videlec
Copy link
Contributor Author

videlec commented Aug 18, 2016

Commit: 388fb53

@videlec
Copy link
Contributor Author

videlec commented Aug 18, 2016

Branch: u/vdelecroix/21272

@videlec
Copy link
Contributor Author

videlec commented Aug 18, 2016

Author: Vincent Delecroix

@videlec
Copy link
Contributor Author

videlec commented Aug 18, 2016

New commits:

388fb53Trac 21272: fix normalize and hash of Laurent polynomials

@bgrenet
Copy link

bgrenet commented Aug 22, 2016

comment:6
  • How did you choose the value 700005?
  • You should replace TESTS: by TESTS:: in __hash__.

@saraedum
Copy link
Member

Work Issues: reviewer comments

@saraedum
Copy link
Member

comment:8

vdelecroix: Can you somehow push this branch again? For me, all it shows in trac is that the laurent_polynomial.pyx file has been deleted.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 16, 2016

Changed commit from 388fb53 to 16b6633

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 16, 2016

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

16b6633Trac 21272: fix normalize and hash of Laurent polynomials

@videlec
Copy link
Contributor Author

videlec commented Dec 16, 2016

comment:10

Rebased on 7.5.beta6!

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 17, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

6439a4e21272: forgot a colon

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 17, 2016

Changed commit from 16b6633 to 6439a4e

@videlec
Copy link
Contributor Author

videlec commented Dec 17, 2016

comment:12

Replying to @bgrenet:

  • How did you choose the value 700005?

A fairly random number.

  • You should replace TESTS: by TESTS:: in __hash__.

Done. Thanks.

@saraedum
Copy link
Member

Changed work issues from reviewer comments to none

@saraedum
Copy link
Member

Changed branch from u/vdelecroix/21272 to u/saraedum/21272

@saraedum
Copy link
Member

comment:15

If you agree with my change, feel free to set this to positive review.

@saraedum
Copy link
Member

Reviewer: Julian Rüth

@saraedum
Copy link
Member

Changed branch from u/saraedum/21272 to u/vdelecroix/21272

@saraedum
Copy link
Member

Changed branch from u/vdelecroix/21272 to u/saraedum/21272

@saraedum
Copy link
Member

Changed commit from 6439a4e to 85b064e

@saraedum
Copy link
Member

New commits:

85b064efix grammar

@saraedum
Copy link
Member

comment:17

Have you considered turning __u into a sparse polynomial, shifting it, and computing the hash from there? I guess that would be my only proposal here to remove a duplication of code. But it is probably not worth it. Your tests should catch any changes in the implementation of the hash function of polynomials…

@videlec
Copy link
Contributor Author

videlec commented Dec 19, 2016

comment:18

Replying to @saraedum:

Have you considered turning __u into a sparse polynomial, shifting it, and computing the hash from there? I guess that would be my only proposal here to remove a duplication of code. But it is probably not worth it. Your tests should catch any changes in the implementation of the hash function of polynomials…

Converting the data structure at the time of the hash is not a good idea (time costly). Is this what you were proposing? On the other hand, modifying the internal data structure of laurent polynomials is beyond the scope of this ticket.

@vbraun
Copy link
Member

vbraun commented Jan 18, 2017

Changed branch from u/saraedum/21272 to 85b064e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants