-
Notifications
You must be signed in to change notification settings - Fork 33
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
add trivial hash function for spoly #121
Changes from 5 commits
0f99e56
9f7229e
754f514
1bb108f
45400e3
2a927c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -454,6 +454,28 @@ function test_spoly_differential() | |
@test jf == x^3 | ||
end | ||
|
||
function test_spoly_unique() | ||
print("spoly.unique...") | ||
|
||
R, (x, y) = PolynomialRing(QQ, ["x", "y"]) | ||
|
||
@test unique([x, x+y-y]) == [x] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test will occasionally pass even without overloaded hash function; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See 1bb108f. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So is |
||
|
||
println("PASS") | ||
end | ||
|
||
function test_spoly_hash() | ||
print("spoly.hash...") | ||
|
||
R, (x, y) = PolynomialRing(QQ, ["x", "y"]) | ||
|
||
@test hash(x) == hash(x+y-y) | ||
@test hash(x,zero(UInt)) == hash(x+y-y,zero(UInt)) | ||
@test hash(x,one(UInt)) == hash(x+y-y,one(UInt)) | ||
|
||
println("PASS") | ||
end | ||
|
||
function test_spoly() | ||
test_spoly_constructors() | ||
test_spoly_printing() | ||
|
@@ -475,6 +497,8 @@ function test_spoly() | |
test_spoly_Polynomials() | ||
# test_convert_between_MPoly_and_SingularPoly() | ||
test_spoly_differential() | ||
test_spoly_unique() | ||
test_spoly_hash() | ||
|
||
println("") | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since
Base.hash
by default setsh=UInt(0)
, it's not really much better than justh
;-)I have no idea what are the inners of
spoly
, but a simple implementation could behash(p::spoly{T}, h::UInt) where T = xor(hash(spoly), hash(coefficients_or_something_unique_to(p), h))
hash(spoly)
can be of course precomputed first (add a comment).Or if You can iterate over coefficients of
p
thenhash(p::spoly, h::UInt) = xor(HASH_SPOLY, reduce(xor, hash(c, h) for c in coeffs(p))
But I'd really like to see it as
UInt(0)
globally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't make the hash depend on the object pointer at all. You have to use the data in the actual polynomial, i.e. the coefficients.
For about the fifth time, this is not difficult to do in the slightest and we have examples of how to do it in Nemo and AbstractAlgebra.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kalmarek I hope the version in 2a927c5 is a little better.