Skip to content

Commit

Permalink
iszero and == for spoly in quotient ring
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes14 committed Aug 24, 2023
1 parent 5c0beea commit 802eaaf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions deps/src/ideals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -722,4 +729,5 @@ void singular_define_ideals(jlcxx::Module & Singular)
}
return res;
});
Singular.method("qring_simplify", &qring_simplify_helper);
}
1 change: 1 addition & 0 deletions deps/src/rings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/poly/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/poly/poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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", ])

Expand Down

0 comments on commit 802eaaf

Please sign in to comment.