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 121 forks source link

special simplify function #2603

Open wdecker opened 1 year ago

wdecker commented 1 year ago

The function simplify(f::MPolyQuoRingElem) below is called simplify but simplifies only in the case f is the zero class. The name is misleading and will lead to wrong results of functions such as ==.

@HechtiDerLachs Should we rename the function? Or?

# The above methods for `simplify` assume that there is a singular backend which 
# can be used. However, we are using (graded) quotient rings also with coefficient 
# rings R which can not be translated to Singular; for instance when R is again 
# a polynomial ring, or a quotient/localization thereof, or even a `SpecOpenRing`. 
# Still in many of those cases, we can use `RingFlattening` to bind a computational 
# backend. In particular, this allows us to do ideal_membership tests; see 
# the file `flattenings.jl` for details. 
#
# The generic method below is a compromise in the sense that `simplify` does not reduce 
# a given element to a unique representative as would be the case in a groebner basis reduction, 
# but it nevertheless reduces the element to zero in case its representative is 
# contained in the modulus. This allows for both, the use of `RingFlattening`s and 
# the potential speedup of `iszero` tests. 
function simplify(f::MPolyQuoRingElem)
  f.simplified && return f
  if f.f in modulus(parent(f))
    f.f = zero(f.f)
  end
  f.simplified = true
  return f::elem_type(parent(f))
end
fingolfin commented 1 year ago

@wdecker could you please provide an example that reproduces the problem?

fingolfin commented 1 year ago

Apparently there is still a (hypothetical?) example where comparison of elements will fail, because it does simplify(x) == simplify(y), and not simplify(x-y); but simplify apparently right now only changes elements when they simplify to 0, but does not replace elements with a "normal form" (if that even make sense).

This also is a concern for hashing (to get a unique hash you need a unique normal form...)

fingolfin commented 1 year ago

Maybe a first step would be to construct an actual example where this happens, i.e., where this general simplify method is triggered and not some specialization for it or for equality tests.