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

create correct Singular coeffs with create_ring_from_singular_ring #773

Merged
merged 13 commits into from
Feb 23, 2024
32 changes: 32 additions & 0 deletions deps/src/coeffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,38 @@ void singular_define_coeffs(jlcxx::Module & Singular)
return bool(nCoeff_is_algExt(n));
});

Singular.method("nCoeff_is_Nemo_AnticNumberField", [](coeffs n) {
return n->type==n_Nemo_AnticNumberField;
});

Singular.method("nCoeff_is_Nemo_QQField", [](coeffs n) {
return n->type==n_Nemo_QQField;
});

Singular.method("nCoeff_is_Nemo_ZZRing", [](coeffs n) {
return n->type==n_Nemo_ZZRing;
});

Singular.method("nCoeff_is_Nemo_FqPolyRepField", [](coeffs n) {
return n->type==n_Nemo_FqPolyRepField;
});

Singular.method("nCoeff_is_Nemo_fqPolyRepField", [](coeffs n) {
return n->type==n_Nemo_fqPolyRepField;
});

Singular.method("nCoeff_is_Nemo_Field", [](coeffs n) {
return n->type==n_Nemo_Field;
});

Singular.method("nCoeff_is_Nemo_Ring", [](coeffs n) {
return n->type==n_Nemo_Ring;
});

Singular.method("nGetCoeffData", [](coeffs n) {
return n->data;
});

/* make a copy of a coefficient domain (actually just increments a
* reference count) */
Singular.method("nCopyCoeff", &nCopyCoeff);
Expand Down
6 changes: 6 additions & 0 deletions src/caller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ function create_ring_from_singular_ring(r::libSingular.ring_ptr)
minpoly = F(libSingular.algExt_GetMinpoly(c, F.ptr))
basering = N_AlgExtField(libSingular.nCopyCoeff(c), minpoly)
T = n_algExt
elseif libSingular.nCoeff_is_Nemo_Field(c) || libSingular.nCoeff_is_Nemo_Ring(c)
cf = libSingular.nCopyCoeff(c)
data_ptr = libSingular.nGetCoeffData(cf)
R = unsafe_pointer_to_objref(data_ptr)
fingolfin marked this conversation as resolved.
Show resolved Hide resolved
basering = CoefficientRing(R) # FIXME: should we set cache=false ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now uses CoefficientRing which apparently was made for just this kind of purpose... It even looks up existing wrappers

T = elem_type(basering)
else
basering = N_UnknownSingularCoefficientRing(libSingular.nCopyCoeff(c))
T = n_unknownsingularcoefficient
Expand Down
7 changes: 7 additions & 0 deletions test/caller-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,10 @@ end
@test Singular.libSingular.random() == 16807
@test Singular.libSingular.random() == 282475249
end

@testset "Nemo coeffs" begin
F = Nemo.fraction_field(Nemo.polynomial_ring(Nemo.ZZ)[1])
R, x = Singular.polynomial_ring(F, [:x])
S = Singular.create_ring_from_singular_ring(Singular.libSingular.rCopy(R.ptr))
@test base_ring(R) == base_ring(S)
end
Loading