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

Add hash methods for many types with == method #2373

Merged
merged 23 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b77284d
Add `hash(::GAPGroupHomomorphism)`
lgoettgens May 11, 2023
454a0e3
Add `hash(::FreeMod_dec)`
lgoettgens May 11, 2023
0f1130e
Add `hash(::PBWAlgIdeal)`
lgoettgens May 11, 2023
ade3c66
Add `hash(::ModuleFPHom)`
lgoettgens May 11, 2023
3250427
Add `hash` for `(Affine/Linear)(Halfspace/Hyperplane)
lgoettgens May 11, 2023
25577af
Add `hash(::SesquilinearForm)`
lgoettgens May 11, 2023
5e9b5f3
Add `hash(::AbsMPolyMultSet)`
lgoettgens May 11, 2023
0467882
Add `hash(::CohomologyClass)`
lgoettgens May 11, 2023
53962f3
Add `hash(::ElementOfGSet)`
lgoettgens May 11, 2023
252984c
Add `hash(::MPolyLocalizedRingHom)`
lgoettgens May 11, 2023
be883d1
Add `hash(::MPolyQuoLocalizedRingHom)`
lgoettgens May 11, 2023
f007f4a
Add `hash(::RationalEquivalenceClass)`
lgoettgens May 11, 2023
8caa177
Enhance `hash(::FreeMod)` and `hash(::AbstractFreeModElem)`
lgoettgens May 11, 2023
5ae1f6e
Add `hash(::SubquoModuleElem)`
lgoettgens May 11, 2023
54b3eed
Add `hash(::ToricDivisor)`
lgoettgens May 11, 2023
e8a8ab5
Add `hash(::ToricDivisorClass)`
lgoettgens May 11, 2023
5e05adc
Add `hash(::ToricLineBundle)`
lgoettgens May 11, 2023
9d7b953
Add `hash(::ToricMorphism)`
lgoettgens May 11, 2023
2c8bfd3
Add `hash(::TropicalSemiringElem)`
lgoettgens May 11, 2023
3b09a90
Update `hash` for `MPolyQuoLocalizedRingHom` and `MPolyLocalizedRingHom`
lgoettgens May 17, 2023
14d6e1e
Update `==` and `hash` for toric types
lgoettgens Jun 7, 2023
cb08ab6
Let `hash` for `AbsMPolyMultSet` and `SubquoModuleElem` error
lgoettgens May 22, 2023
db87017
Bump version (this PR is breaking)
lgoettgens Jun 7, 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Oscar"
uuid = "f1435218-dba5-11e9-1e4d-f1a5fab5fc13"
authors = ["The OSCAR Team <oscar@mathematik.uni-kl.de>"]
version = "0.12.2-DEV"
version = "0.13.0-DEV"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,18 @@


####################################################
# 6: Equality
# 6: Equality and hash
####################################################

function Base.:(==)(ac1::RationalEquivalenceClass, ac2::RationalEquivalenceClass)
return toric_variety(ac1) === toric_variety(ac2) && iszero(polynomial(ac1-ac2))
return toric_variety(ac1) === toric_variety(ac2) && polynomial(ac1) == polynomial(ac2)
end

function Base.hash(ac::RationalEquivalenceClass, h::UInt)
b = 0xb5d4ac6b9084eb6e % UInt
h = hash(toric_variety(ac), h)
h = hash(polynomial(ac), h)
return xor(h, b)

Check warning on line 281 in src/AlgebraicGeometry/ToricVarieties/AlgebraicCycles/constructors.jl

View check run for this annotation

Codecov / codecov/patch

src/AlgebraicGeometry/ToricVarieties/AlgebraicCycles/constructors.jl#L277-L281

Added lines #L277 - L281 were not covered by tests
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,19 @@


########################
# 5: Equality
# 5: Equality and hash
########################

Base.:(==)(cc1::CohomologyClass, cc2::CohomologyClass) = toric_variety(cc1) === toric_variety(cc2) && iszero(polynomial(cc1-cc2))
function Base.:(==)(cc1::CohomologyClass, cc2::CohomologyClass)
toric_variety(cc1) === toric_variety(cc2) && polynomial(cc1) == polynomial(cc2)
end

function Base.hash(cc::CohomologyClass, h::UInt)
b = 0x4de32042e67d89c8 % UInt
h = hash(toric_variety(cc), h)
h = hash(polynomial(cc), h)
return xor(h, b)

Check warning on line 159 in src/AlgebraicGeometry/ToricVarieties/CohomologyClasses/constructors.jl

View check run for this annotation

Codecov / codecov/patch

src/AlgebraicGeometry/ToricVarieties/CohomologyClasses/constructors.jl#L155-L159

Added lines #L155 - L159 were not covered by tests
end

######################
# 6: Display
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,18 @@


########################
# 5: Equality
# 5: Equality and hash
########################

function Base.:(==)(tdc1::ToricDivisorClass, tdc2::ToricDivisorClass)
return toric_variety(tdc1) === toric_variety(tdc2) && iszero(divisor_class(tdc1) - divisor_class(tdc2))
return toric_variety(tdc1) === toric_variety(tdc2) && divisor_class(tdc1) == divisor_class(tdc2)
end

function Base.hash(tdc::ToricDivisorClass, h::UInt)
b = 0x118eb1fba136490c % UInt
h = hash(toric_variety(tdc), h)
h = hash(divisor_class(tdc), h)
return xor(h, b)

Check warning on line 114 in src/AlgebraicGeometry/ToricVarieties/ToricDivisorClasses/constructors.jl

View check run for this annotation

Codecov / codecov/patch

src/AlgebraicGeometry/ToricVarieties/ToricDivisorClasses/constructors.jl#L110-L114

Added lines #L110 - L114 were not covered by tests
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,20 @@


######################
# 5: Equality
# 5: Equality and hash
######################s

function Base.:(==)(td1::ToricDivisor, td2::ToricDivisor)
return toric_variety(td1) === toric_variety(td2) && coefficients(td1) == coefficients(td2)
end

function Base.hash(td::ToricDivisor, h::UInt)
b = 0x92bd6ac4f87d834e % UInt
h = hash(toric_variety(td), h)
h = hash(coefficients(td), h)
return xor(h, b)

Check warning on line 113 in src/AlgebraicGeometry/ToricVarieties/ToricDivisors/constructors.jl

View check run for this annotation

Codecov / codecov/patch

src/AlgebraicGeometry/ToricVarieties/ToricDivisors/constructors.jl#L109-L113

Added lines #L109 - L113 were not covered by tests
end


######################
# 6: Display
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,20 @@


########################
# 5: Equality
# 5: Equality and hash
########################

function Base.:(==)(l1::ToricLineBundle, l2::ToricLineBundle)
return toric_variety(l1) === toric_variety(l2) && picard_class(l1) == picard_class(l2)
end

function Base.hash(l::ToricLineBundle, h::UInt)
b = 0xa2b0a2cd60a8ffbf % UInt
h = hash(toric_variety(l), h)
h = hash(picard_class(l), h)
return xor(h, b)

Check warning on line 188 in src/AlgebraicGeometry/ToricVarieties/ToricLineBundles/constructors.jl

View check run for this annotation

Codecov / codecov/patch

src/AlgebraicGeometry/ToricVarieties/ToricLineBundles/constructors.jl#L184-L188

Added lines #L184 - L188 were not covered by tests
end


########################
# 6: Display
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,24 @@


####################################################
# 6: Equality of toric morphisms
# 6: Equality and hash of toric morphisms
####################################################

function Base.:(==)(tm1::ToricMorphism, tm2::ToricMorphism)
return domain(tm1) == domain(tm2) && codomain(tm1) == codomain(tm2) && grid_morphism(tm1) == grid_morphism(tm2)
end

function Base.hash(tm::ToricMorphism, h::UInt)
b = 0x1a66f927cae2d409 % UInt
h = hash(domain(tm), h)
h = hash(codomain(tm), h)
h = hash(grid_morphism(tm), h)
return xor(h, b)

Check warning on line 235 in src/AlgebraicGeometry/ToricVarieties/ToricMorphisms/constructors.jl

View check run for this annotation

Codecov / codecov/patch

src/AlgebraicGeometry/ToricVarieties/ToricMorphisms/constructors.jl#L230-L235

Added lines #L230 - L235 were not covered by tests
end


######################
# 6: Display
# 7: Display
######################

function Base.show(io::IO, tm::ToricMorphism)
Expand Down
10 changes: 9 additions & 1 deletion src/Groups/gsets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,15 @@
return ElementOfGSet(Omega, fun(omega.obj, g))
end

==(omega1::ElementOfGSet, omega2::ElementOfGSet) = ((omega1.gset == omega2.gset) && (omega1.obj == omega2.obj))
==(omega1::ElementOfGSet, omega2::ElementOfGSet) =
((omega1.gset == omega2.gset) && (omega1.obj == omega2.obj))

function Base.hash(omega::ElementOfGSet, h::UInt)
b = 0x4dd1b3e65edeab89 % UInt
h = hash(omega.gset, h)
h = hash(omega.obj, h)
return xor(h, b)

Check warning on line 223 in src/Groups/gsets.jl

View check run for this annotation

Codecov / codecov/patch

src/Groups/gsets.jl#L219-L223

Added lines #L219 - L223 were not covered by tests
end

Base.in(omega::ElementOfGSet, Omega::GSet) = Base.in(omega.obj, Omega)

Expand Down
7 changes: 6 additions & 1 deletion src/Groups/homomorphisms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
end

function ==(f::GAPGroupHomomorphism{S,T}, g::GAPGroupHomomorphism{S,T}) where S where T
return f.map == g.map
return f.map == g.map
end

function Base.hash(f::GAPGroupHomomorphism{S,T}, h::UInt) where S where T
b = 0xdc777737af4c0c7b % UInt
return xor(hash(f.map, hash((S, T), h)), b)

Check warning on line 14 in src/Groups/homomorphisms.jl

View check run for this annotation

Codecov / codecov/patch

src/Groups/homomorphisms.jl#L12-L14

Added lines #L12 - L14 were not covered by tests
lgoettgens marked this conversation as resolved.
Show resolved Hide resolved
end

Base.:*(f::GAPGroupHomomorphism{S, T}, g::GAPGroupHomomorphism{T, U}) where S where T where U = compose(f, g)
Expand Down
9 changes: 8 additions & 1 deletion src/Groups/matrices/forms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@
########################################################################

#TODO: checking whether two quadratic forms coincide by checking their polynomials is not possible yet.
==(B::SesquilinearForm, C::SesquilinearForm) = gram_matrix(B)==gram_matrix(C) && B.descr==C.descr
==(B::SesquilinearForm, C::SesquilinearForm) = B.descr == C.descr && gram_matrix(B) == gram_matrix(C)

function Base.hash(f::SesquilinearForm, h::UInt)
b = 0xf64440baac005f8c % UInt
h = hash(f.descr, h)
h = hash(gram_matrix(f), h)
return xor(h, b)

Check warning on line 185 in src/Groups/matrices/forms.jl

View check run for this annotation

Codecov / codecov/patch

src/Groups/matrices/forms.jl#L181-L185

Added lines #L181 - L185 were not covered by tests
end

function base_ring(B::SesquilinearForm)
if isdefined(B,:matrix) return base_ring(gram_matrix(B))
Expand Down
5 changes: 5 additions & 0 deletions src/Modules/ModulesGraded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,11 @@
return forget_decoration(F) == forget_decoration(G) && F.d == G.d
end

function Base.hash(F::FreeMod_dec, h::UInt)
b = 0x13d6e1b453cb661a % UInt
return xor(hash(forget_decoration(F), hash(F.d, h)), b)

Check warning on line 1649 in src/Modules/ModulesGraded.jl

View check run for this annotation

Codecov / codecov/patch

src/Modules/ModulesGraded.jl#L1647-L1649

Added lines #L1647 - L1649 were not covered by tests
end

###############################################################################
# FreeModElem_dec constructors
###############################################################################
Expand Down
34 changes: 31 additions & 3 deletions src/Modules/UngradedModules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@
end

function hash(F::FreeMod, h::UInt)
is_graded(F) && return hash((base_ring(F), rank(F), F.S, F.d), h)
return hash((base_ring(F), rank(F), F.S), h)
b = is_graded(F) ? (0x2d55d561d3f7e215 % UInt) : (0x62ca4181ff3a12f4 % UInt)
h = hash(base_ring(F), h)
h = hash(rank(F), h)
h = hash(F.S, h)
is_graded(F) && (h = hash(F.d, h))
return xor(h, b)
end

@doc raw"""
Expand Down Expand Up @@ -490,7 +494,11 @@
end

function hash(a::AbstractFreeModElem, h::UInt)
return xor(hash(tuple(parent(a), coordinates(a)), h), hash(typeof(a)))
b = 0xaa2ba4a32dd0b431 % UInt
h = hash(typeof(a), h)
h = hash(parent(a), h)
h = hash(coordinates(a), h)
return xor(h, b)
end

function Base.deepcopy_internal(a::AbstractFreeModElem, dict::IdDict)
Expand Down Expand Up @@ -3515,39 +3523,50 @@
check_parent(a,b)
return SubquoModuleElem(coordinates(a)+coordinates(b), a.parent)
end

function -(a::SubquoModuleElem, b::SubquoModuleElem)
check_parent(a,b)
return SubquoModuleElem(coordinates(a)-coordinates(b), a.parent)
end

-(a::SubquoModuleElem) = SubquoModuleElem(-coordinates(a), a.parent)

function *(a::MPolyDecRingElem, b::SubquoModuleElem)
if parent(a) !== base_ring(parent(b))
return base_ring(parent(b))(a)*b # this will throw if conversion is not possible
end
return SubquoModuleElem(a*coordinates(b), b.parent)
end

function *(a::MPolyRingElem, b::SubquoModuleElem)
if parent(a) !== base_ring(parent(b))
return base_ring(parent(b))(a)*b # this will throw if conversion is not possible
end
return SubquoModuleElem(a*coordinates(b), b.parent)
end

function *(a::RingElem, b::SubquoModuleElem)
if parent(a) !== base_ring(parent(b))
return base_ring(parent(b))(a)*b # this will throw if conversion is not possible
end
return SubquoModuleElem(a*coordinates(b), b.parent)
end

*(a::Int, b::SubquoModuleElem) = SubquoModuleElem(a*coordinates(b), b.parent)
*(a::Integer, b::SubquoModuleElem) = SubquoModuleElem(a*coordinates(b), b.parent)
*(a::QQFieldElem, b::SubquoModuleElem) = SubquoModuleElem(a*coordinates(b), b.parent)

function (==)(a::SubquoModuleElem, b::SubquoModuleElem)
if parent(a) !== parent(b)
return false
end
return iszero(a-b)
end

function Base.hash(a::SubquoModuleElem, h::UInt)
error("not implemented")

Check warning on line 3567 in src/Modules/UngradedModules.jl

View check run for this annotation

Codecov / codecov/patch

src/Modules/UngradedModules.jl#L3566-L3567

Added lines #L3566 - L3567 were not covered by tests
end

function Base.deepcopy_internal(a::SubquoModuleElem, dict::IdDict)
return SubquoModuleElem(deepcopy_internal(coordinates(a), dict), a.parent)
end
Expand Down Expand Up @@ -4820,6 +4839,15 @@
end
return true
end

function Base.hash(f::ModuleFPHom, h::UInt)
b = 0x535bbdbb2bc54b46 % UInt
h = hash(typeof(f), h)
h = hash(domain(f), h)
h = hash(codomain(f), h)
return xor(h, b)
end

###################################################################

@doc raw"""
Expand Down
6 changes: 6 additions & 0 deletions src/PolyhedralGeometry/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@

Base.:(==)(x::LinearHyperplane, y::LinearHyperplane) = x.a == y.a

Base.hash(x::T, h::UInt) where {T<:Union{AffineHalfspace,AffineHyperplane}} =

Check warning on line 191 in src/PolyhedralGeometry/iterators.jl

View check run for this annotation

Codecov / codecov/patch

src/PolyhedralGeometry/iterators.jl#L191

Added line #L191 was not covered by tests
hash((x.a, x.b), hash(T, h))

Base.hash(x::T, h::UInt) where {T<:Union{LinearHalfspace,LinearHyperplane}} =

Check warning on line 194 in src/PolyhedralGeometry/iterators.jl

View check run for this annotation

Codecov / codecov/patch

src/PolyhedralGeometry/iterators.jl#L194

Added line #L194 was not covered by tests
hash(x.a, hash(T, h))

################################################################################

for T in [LinearHalfspace, LinearHyperplane]
Expand Down
4 changes: 4 additions & 0 deletions src/Rings/PBWAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,10 @@
return is_subset(a, b) && is_subset(b, a)
end

function Base.hash(a::PBWAlgIdeal{D, T, S}, h::UInt) where {D, T, S}
b = 0x91c65dda1eed350f % UInt
return xor(hash(base_ring(a), hash(D, h)), b)

Check warning on line 1083 in src/Rings/PBWAlgebra.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings/PBWAlgebra.jl#L1081-L1083

Added lines #L1081 - L1083 were not covered by tests
end

#### elimination

Expand Down
14 changes: 14 additions & 0 deletions src/Rings/mpoly-localizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@
return (issubset(T, U) && issubset(U, T))
end

function Base.hash(T::AbsMPolyMultSet{BRT, BRET, RT, RET}, h::UInt) where {BRT,BRET,RT,RET}
error("not implemented")

Check warning on line 678 in src/Rings/mpoly-localizations.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings/mpoly-localizations.jl#L677-L678

Added lines #L677 - L678 were not covered by tests
end

function issubset(
T::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET},
U::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET}
Expand Down Expand Up @@ -2890,6 +2894,16 @@
return true
end

function Base.hash(f::MPolyLocalizedRingHom, h::UInt)
b = 0xe29cdc1ecb68b7a0 % UInt
h = hash(domain(f), h)
h = hash(codomain(f), h)
lgoettgens marked this conversation as resolved.
Show resolved Hide resolved
for x in gens(base_ring(domain(f)))
h = hash(f(x), h)
end
return xor(h, b)

Check warning on line 2904 in src/Rings/mpoly-localizations.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings/mpoly-localizations.jl#L2897-L2904

Added lines #L2897 - L2904 were not covered by tests
end

function divides(a::MPolyLocRingElem, b::MPolyLocRingElem)
W = parent(a)
W == parent(b) || error("elements do not belong to the same ring")
Expand Down
10 changes: 10 additions & 0 deletions src/Rings/mpolyquo-localizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,16 @@
return true
end

function Base.hash(f::MPolyQuoLocalizedRingHom, h::UInt)
b = 0xd6d389598ad28724 % UInt
h = hash(domain(f), h)
h = hash(codomain(f), h)
lgoettgens marked this conversation as resolved.
Show resolved Hide resolved
for x in gens(base_ring(domain(f)))
h = hash(f(x), h)
end
return xor(h, b)

Check warning on line 1089 in src/Rings/mpolyquo-localizations.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings/mpolyquo-localizations.jl#L1082-L1089

Added lines #L1082 - L1089 were not covered by tests
end

### printing
function Base.show(io::IO, ::MIME"text/plain", phi::MPolyQuoLocalizedRingHom)
R = base_ring(domain(phi))
Expand Down
11 changes: 10 additions & 1 deletion src/TropicalGeometry/semiring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@

################################################################################
#
# Equality
# Equality and hash
#
################################################################################

Expand All @@ -237,6 +237,15 @@
return data(x) == data(y)
end

function Base.hash(x::TropicalSemiringElem, h::UInt)
b = 0x4df38853cc07aa27 % UInt
h = hash(isinf(x), h)
if !isinf(x)
h = hash(data(x), h)

Check warning on line 244 in src/TropicalGeometry/semiring.jl

View check run for this annotation

Codecov / codecov/patch

src/TropicalGeometry/semiring.jl#L240-L244

Added lines #L240 - L244 were not covered by tests
end
return xor(h, b)

Check warning on line 246 in src/TropicalGeometry/semiring.jl

View check run for this annotation

Codecov / codecov/patch

src/TropicalGeometry/semiring.jl#L246

Added line #L246 was not covered by tests
end

################################################################################
#
# Comparison
Expand Down