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

Missing hash methods #2222

Open
3 of 5 tasks
fingolfin opened this issue Apr 5, 2023 · 2 comments
Open
3 of 5 tasks

Missing hash methods #2222

fingolfin opened this issue Apr 5, 2023 · 2 comments
Labels
bug Something isn't working triage

Comments

@fingolfin
Copy link
Member

fingolfin commented Apr 5, 2023

There are a bunch of our types which implement == but not hash, which leads to confusing behavior and bugs. E.g. for a vector consisting of two such objects which are equal but not identical, the function unique will return a vector with both objects, instead of just one. @YueRen just re-discovered this for Polyhedron, but there are more affected types.

Perhaps someone could write a little script to find more instances semi-automatically (e.g.: iterate over all objects in the Oscar module; for each which is a type, check if there is a custom Base.== method defined; and then for each check if also a custom Base.hash method is defined; if not, print the type).

In the meantime, here is a manual list which is certainly incomplete (and I also might have included some things incorrectly, because I overlooked a hash method). Feel free to edit this list or request changes.

Also for a few types we should perhaps improve the existing hash methods. E.g. we have this right now:

Base.hash(x::GAPGroup, h::UInt) = h # FIXME
Base.hash(x::GAPGroupElem, h::UInt) = h # FIXME

I think they should at least produce different hashes according to their type. Thus a slightly better approach might be to do something like this:

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

But we could still do more, e.g. for permutation groups the degree could be included, and arguably also the order (I mean, computing the order costs us, but if we compute a hash for a group, then we probably will also test equality at some point, and then we need a stabilizer chain anyway, so whatever).

@fingolfin fingolfin added the bug Something isn't working label Apr 5, 2023
@lgoettgens
Copy link
Member

lgoettgens commented Apr 6, 2023

I wrote some small script (NEEDS julia 1.10!!!!) to get all cases, including the package that defines the type, and the file and line number the == method is defined (in some nice printing):

list = map(
  filter(names(Oscar; all=true)) do name
    isdefined(Oscar, name) || return false            # remove all wrong exports (see #1964)
    T = getfield(Oscar, name)
    T isa DataType || T isa UnionAll || return false  # remove all non-types and non-parametric-types
    parentmodule(==, (T, T)) == Base && return false  # remove everything without custom ==
    loc = functionloc(==, (T, T))
    endswith(loc[1], "julia/base/Base.jl") && loc[2] == 165 && return false  # remove everything without custom ==
    parentmodule(hash, (T, UInt)) == Base             # keep iff there is no custom hash
  end,
) do name
  T = getfield(Oscar, name)
  loc = functionloc(==, (T, T))
  if occursin("Oscar.jl/", loc[1])
    loc_cleaned = loc[1][first(findlast("Oscar.jl/", loc[1])):end]
  elseif occursin("packages/", loc[1])
    loc_cleaned = loc[1][(first(findlast("packages/", loc[1])) + length("packages/")):end]
  elseif occursin("julia/base/", loc[1])
    loc_cleaned = loc[1][first(findlast("julia/base/", loc[1])):end]
  else
    loc_cleaned = loc[1]
  end
  name, parentmodule(T), (loc_cleaned, loc[2])
end;

Currently (on e2dfa57), I get the following list of things:

82-element Vector{Tuple{Symbol, Module, Tuple{String, Int32}}}:
 (:AbsAffineSurface, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:AbsGlueing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Gluing/Methods.jl", 183))
 (:AbsGluing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Gluing/Methods.jl", 183))
 (:AbsIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:AbsNumFieldOrder, Hecke, ("Hecke/p6Ffl/src/NumFieldOrd/NfOrd/NfOrd.jl", 1160))
 (:AbsNumFieldOrderSet, Hecke, ("Hecke/p6Ffl/src/NumFieldOrd/NfOrd/NfOrd.jl", 1179))
 (:AbsProjectiveSurface, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/ProjectiveSchemes/Objects/Methods.jl", 384))
 (:AbsProjectiveVariety, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/ProjectiveSchemes/Objects/Methods.jl", 384))
 (:AbsSimpleNumFieldEmbedding, Hecke, ("Hecke/p6Ffl/src/NumField/ComplexEmbeddings/NfAbs.jl", 66))
 (:AbsSimpleNumFieldOrder, Hecke, ("Hecke/p6Ffl/src/NumFieldOrd/NfOrd/NfOrd.jl", 1160))
 (:AbsSpaceGerm, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:AbstractBundle, Oscar.IntersectionTheory, ("Oscar.jl/experimental/IntersectionTheory/src/Main.jl", 53))
 (:AcbFieldElem, Nemo, ("Nemo/0X3AB/src/arb/acb.jl", 340))
 (:AffineAlgebraicSet, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:AffineNormalToricVariety, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:AffineScheme, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:AffineSchemeOpenSubscheme, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemeOpenSubscheme/Objects/Methods.jl", 75))
 (:AffineSchemeOpenSubschemeRing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemeOpenSubscheme/Rings/Methods.jl", 5))
 (:AffineSchemeOpenSubschemeRingElem, Oscar, ("AbstractAlgebra/oeXjP/src/NCRings.jl", 86))
 (:AffineVariety, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:AlgebraicCycle, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Divisors/AlgebraicCycles.jl", 486))
 (:ArbFieldElem, Nemo, ("Nemo/0X3AB/src/arb/arb.jl", 365))
 (:CartierDivisor, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Divisors/CartierDivisor.jl", 198))
 (:ClassField, Hecke, ("Hecke/p6Ffl/src/RCF/class_fields.jl", 240))
 (:CompleteIntersectionGerm, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:ComplexFieldElem, Nemo, ("Nemo/0X3AB/src/arb/Complex.jl", 336))
 (:Divisor, Hecke, ("Hecke/p6Ffl/src/FunField/Divisor.jl", 225))
 (:EllipticCurve, Hecke, ("Hecke/p6Ffl/src/EllCrv/EllCrv.jl", 401))
 (:FinGenAbGroupHom, Hecke, ("Hecke/p6Ffl/src/GrpAb/Map.jl", 245))
 (:FractionalIdeal, Oscar, ("Oscar.jl/src/Rings/FractionalIdeal.jl", 55))
 (:FunFldDiff, Hecke, ("Hecke/p6Ffl/src/FunField/Differential.jl", 78))
 (:GenOrdFracIdl, Hecke, ("Hecke/p6Ffl/src/GenOrd/FractionalIdeal.jl", 272))
 (:GermAtClosedPoint, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:GermAtGeometricPoint, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:Glueing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Gluing/Methods.jl", 183))
 (:Gluing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Gluing/Methods.jl", 183))
 (:HypersurfaceGerm, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:IdealGens, Oscar, ("Oscar.jl/src/Rings/mpoly.jl", 427))
 (:IdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:IncidenceMatrix, Polymake.LibPolymake, ("julia/base/abstractarray.jl", 2938))
 (:KodairaSymbol, Hecke, ("Hecke/p6Ffl/src/EllCrv/LocalData.jl", 849))
 (:LazyGluing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Gluing/Methods.jl", 183))
 (:LocElem, AbstractAlgebra.Generic, ("AbstractAlgebra/oeXjP/src/NCRings.jl", 86))
 (:LocalizedEuclideanRingElem, AbstractAlgebra.Generic, ("AbstractAlgebra/oeXjP/src/NCRings.jl", 86))
 (:NfAbsNSGenElem, Oscar, ("Oscar.jl/src/Rings/NumberField.jl", 454))
 (:NfNSGenElem, Oscar, ("AbstractAlgebra/oeXjP/src/NCRings.jl", 86))
 (:NormalToricVariety, Oscar, ("Oscar.jl/src/AlgebraicGeometry/ToricVarieties/NormalToricVarieties/constructors.jl", 185))
 (:OrdLocElem, Hecke, ("AbstractAlgebra/oeXjP/src/NCRings.jl", 86))
 (:Polygon, Hecke, ("Hecke/p6Ffl/src/NumFieldOrd/NfOrd/MaxOrd/Polygons.jl", 94))
 (:PrimeIdealSheafFromChart, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 2148))
 (:PrincipalOpenSubset, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:ProductIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:ProjectiveAlgebraicSet, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/ProjectiveSchemes/Objects/Methods.jl", 384))
 (:ProjectiveCurve, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/ProjectiveSchemes/Objects/Methods.jl", 384))
 (:ProjectiveScheme, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/ProjectiveSchemes/Objects/Methods.jl", 384))
 (:ProjectiveVariety, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/ProjectiveSchemes/Objects/Methods.jl", 384))
 (:PullbackIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:PushforwardIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:QuadBin, Hecke, ("Hecke/p6Ffl/src/QuadForm/QuadBin.jl", 291))
 (:RadicalOfIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:RayVector, Oscar, ("Oscar.jl/src/PolyhedralGeometry/iterators.jl", 88))
 (:RealFieldElem, Nemo, ("Nemo/0X3AB/src/arb/Real.jl", 345))
 (:RelSimpleNumFieldEmbedding, Hecke, ("Hecke/p6Ffl/src/NumField/ComplexEmbeddings/NfRel.jl", 61))
 (:SLPoly, Oscar, ("AbstractAlgebra/oeXjP/src/NCRings.jl", 86))
 (:SimpleGlueing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Gluing/Methods.jl", 183))
 (:SimpleGluing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Gluing/Methods.jl", 183))
 (:SimplifiedAffineScheme, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:SimplifiedIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:SimplifiedSpec, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:SingularLocusIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:SpaceGerm, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:Spec, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemes/Objects/Methods.jl", 14))
 (:SpecOpen, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemeOpenSubscheme/Objects/Methods.jl", 75))
 (:SpecOpenRing, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/AffineSchemeOpenSubscheme/Rings/Methods.jl", 5))
 (:SpecOpenRingElem, Oscar, ("AbstractAlgebra/oeXjP/src/NCRings.jl", 86))
 (:StrictTransformIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:SubModuleOfFreeModule, Oscar, ("Oscar.jl/src/Modules/UngradedModules/SubModuleOfFreeModule.jl", 396))
 (:SumIdealSheaf, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:ToricIdealSheafFromCoxRingIdeal, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Sheaves/IdealSheaves.jl", 574))
 (:WeilDivisor, Oscar, ("Oscar.jl/src/AlgebraicGeometry/Schemes/Divisors/WeilDivisor.jl", 309))
 (:acb, Nemo, ("Nemo/0X3AB/src/arb/acb.jl", 340))
 (:arb, Nemo, ("Nemo/0X3AB/src/arb/arb.jl", 365))

One needs unfortunately to check the == methods by hand. If they are just delegating to objectid(-) == objected(-), I would propose to remove them, to make disappear from this list.

@fingolfin
Copy link
Member Author

@lgoettgens can you please refresh that list? and then we can whittle it down and mark known false-positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants