diff --git a/deps/src/ideals.cpp b/deps/src/ideals.cpp index beeeb96d6..57a54146f 100644 --- a/deps/src/ideals.cpp +++ b/deps/src/ideals.cpp @@ -15,6 +15,13 @@ auto id_sres_helper(sip_sideal * m, int n, ring R) return std::make_tuple(s, minimal); } +auto qring_simplify_helper(poly p, ring R) +{ + if (R->qideal==NULL) + return p_Copy(p,R); + else + return p_Copy(jj_NormalizeQRingP(p_Copy(p,R),R),R); +} auto id_fres_helper(sip_sideal * I, int n, std::string method, ring R) { @@ -722,4 +729,5 @@ void singular_define_ideals(jlcxx::Module & Singular) } return res; }); + Singular.method("qring_simplify", &qring_simplify_helper); } diff --git a/deps/src/rings.cpp b/deps/src/rings.cpp index 17ff06d4f..9d565eb1d 100644 --- a/deps/src/rings.cpp +++ b/deps/src/rings.cpp @@ -344,6 +344,7 @@ void singular_define_rings(jlcxx::Module & Singular) }); Singular.method("rCopy", rCopy); Singular.method("r_get_qideal", [](ring r) {return r->qideal;}); + Singular.method("is_qring", [](ring r) {return bool(r->qideal!=NULL);}); Singular.method("rQuotientRing", [](ideal i, ring r) { // This looks too simple, try make_qring if it doesn't work. ring Q = rCopy(r); diff --git a/src/poly/poly.jl b/src/poly/poly.jl index 0a679e8e5..c066579cb 100644 --- a/src/poly/poly.jl +++ b/src/poly/poly.jl @@ -140,7 +140,14 @@ function one(R::PolyRingUnion) end function iszero(p::SPolyUnion) - GC.@preserve p p.ptr.cpp_object == C_NULL + R = parent(p) + if libSingular.is_qring(R.ptr) + GC.@preserve p x = libSingular.qring_simplify(p.ptr,R.ptr) + xx = R(x) + return xx.ptr.cpp_object == C_NULL + else + return p.ptr.cpp_object == C_NULL + end end function isone(p::SPolyUnion) @@ -711,7 +718,7 @@ end function (x::SPolyUnion{T} == y::SPolyUnion{T}) where T <: Nemo.RingElem check_parent(x, y) - GC.@preserve x y return Bool(libSingular.p_EqualPolys(x.ptr, y.ptr, parent(x).ptr)) + return(iszero(x-y)) end function Base.isless(x::SPolyUnion{T}, y::SPolyUnion{T}) where T <: Nemo.RingElem diff --git a/test/poly/poly-test.jl b/test/poly/poly-test.jl index c7476ae59..1d5881ae0 100644 --- a/test/poly/poly-test.jl +++ b/test/poly/poly-test.jl @@ -234,6 +234,13 @@ end @test trailing_coefficient(R()) == 0 end +@testset "poly.QuotientRing" begin + R, (x,y) = polynomial_ring(QQ, ["x", "y"]) + Q, (a,b) = QuotientRing(R, Ideal(R, x-y)) + @test iszero(a-b) + @test (a-b)==Q(0) +end + @testset "poly.change_base_ring" begin R1, (x, ) = polynomial_ring(ZZ, ["x", ])