oscar-system / Oscar.jl

A comprehensive open source computer algebra system for computations in algebra, geometry, and number theory.
https://www.oscar-system.org
Other
338 stars 120 forks source link

Comparison of polynomials from different rings throws inconsistently #4107

Open lkastner opened 1 week ago

lkastner commented 1 week ago

Describe the bug When comparing polynomials from different rings I get inconsistent behaviour. Sometimes I just get false and sometimes an error.

To Reproduce

julia> R0,(x0) = polynomial_ring(QQ,1)
(Multivariate polynomial ring in 1 variable over QQ, QQMPolyRingElem[x1])

julia> R1,(x1) = polynomial_ring(ZZ,1)
(Multivariate polynomial ring in 1 variable over ZZ, ZZMPolyRingElem[x1])

julia> R2,(x2) = polynomial_ring(GF(2),1)
(Multivariate polynomial ring in 1 variable over GF(2), FqMPolyRingElem[x1])

julia> x0 == x1
false

julia> x0 == x2
false

julia> R3,(x3) = polynomial_ring(GF(3),1)
(Multivariate polynomial ring in 1 variable over GF(3), FqMPolyRingElem[x1])

julia> x2 == x3
ERROR: parents do not match
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] check_parent
   @ ~/.julia/packages/AbstractAlgebra/QjFtH/src/AbstractAlgebra.jl:208 [inlined]
 [3] check_parent
   @ ~/.julia/packages/AbstractAlgebra/QjFtH/src/AbstractAlgebra.jl:207 [inlined]
 [4] ==(a::FqMPolyRingElem, b::FqMPolyRingElem)
   @ Nemo ~/.julia/packages/Nemo/4P3uO/src/flint/fq_default_mpoly.jl:295
 [5] ==(A::Vector{FqMPolyRingElem}, B::Vector{FqMPolyRingElem})
   @ Base ./abstractarray.jl:2943
 [6] top-level scope
   @ REPL[18]:1

julia> x0 == x3
false

Expected behavior We have many places where we first compare the "surrounding space" before comparing the actual objects. So I would expect an error to get thrown. E.g. try

cube(2) == cube(3)

Additional context Maybe this needs a styleguide entry, I actually did not look it up.

lgoettgens commented 1 week ago

Some background: In the cases with an error printed, the types of both arguments are equal, but the parents are not. In the other cases, the types are not equal and thus julia delegated == to ===.

lgoettgens commented 1 week ago

Let's discuss the possible fix in https://github.com/Nemocas/AbstractAlgebra.jl/pull/1800 in triage.

mjrodgers commented 6 days ago

It seems that there are cases where we would want an error rather than false when the parents are not ===. So maybe this inconsistency is hard to avoid. After discussing in triage, no conclusion on proper behavior was reached.

mjrodgers commented 6 days ago

arguably, always throwing an error might be preferable.