diff --git a/deps/src/ideals.cpp b/deps/src/ideals.cpp index 00f084b3b..bb96a12a2 100644 --- a/deps/src/ideals.cpp +++ b/deps/src/ideals.cpp @@ -134,7 +134,7 @@ auto id_Slimgb_helper(ideal a, ring b, bool complete_reduction = false) // bool complete_reduction= false; unsigned int crbit; if (complete_reduction) - auto crbit = Sy_bit(OPT_REDSB); + crbit = Sy_bit(OPT_REDSB); else crbit = 0; ideal id = NULL; @@ -144,11 +144,11 @@ auto id_Slimgb_helper(ideal a, ring b, bool complete_reduction = false) tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = t_rep_gb(b, a, a->rank); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; if (n != NULL) delete n; } @@ -187,11 +187,11 @@ auto id_Std_helper(ideal a, ring b, bool complete_reduction = false) tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = kStd(a, b->qideal, h, &n); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; if (n != NULL) delete n; } @@ -238,11 +238,11 @@ auto id_MinStd_helper(ideal a, ring b, bool complete_reduction = false) tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = kMin_std(a, b->qideal, h, NULL, m); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; return std::make_tuple(id, m); } @@ -275,11 +275,11 @@ auto id_StdHilb_helper(ideal a, tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = kStd(a, b->qideal, h, &n, hilb); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; if (n != NULL) delete n; } @@ -310,15 +310,15 @@ auto id_StdHilbWeighted_helper(ideal a, tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = kStd(a, currRing->qideal, h, &n, // module weights hilb, // hilbert series 0, 0, // syzComp, newIdeal varweights); // weights of vars - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; if (n != NULL) delete n; } @@ -528,37 +528,36 @@ void singular_define_ideals(jlcxx::Module & Singular) Singular.method("id_LiftStd", [](ideal m, ring o, bool complete_reduction = false) { const ring origin = currRing; - rChangeCurrRing(o); - matrix ma = mpNew(1, 1); unsigned int crbit; if (complete_reduction) crbit = Sy_bit(OPT_REDSB); else crbit = 0; unsigned int save_opt = si_opt_1; + rChangeCurrRing(o); + matrix ma = mpNew(1, 1); si_opt_1 |= crbit; ideal res = idLiftStd(m, &ma, testHomog, NULL); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; return std::make_tuple(res, ma); }); Singular.method("id_LiftStdSyz", [](ideal m, ring o, bool complete_reduction = false) { - const ring origin = currRing; - rChangeCurrRing(o); - matrix ma = mpNew(1, 1); - ideal syz = idInit(1, 1); unsigned int crbit; if (complete_reduction) crbit = Sy_bit(OPT_REDSB); else crbit = 0; unsigned int save_opt = si_opt_1; + const ring origin = currRing; + rChangeCurrRing(o); + matrix ma = mpNew(1, 1); + ideal syz = idInit(1, 1); si_opt_1 |= crbit; ideal res = idLiftStd(m, &ma, testHomog, &syz); - si_opt_1 = save_opt; - rChangeCurrRing(origin); + si_opt_1 = save_opt; return std::make_tuple(res, ma, syz); }); diff --git a/deps/src/singular.cpp b/deps/src/singular.cpp index 72b910aed..f21a4b6cd 100644 --- a/deps/src/singular.cpp +++ b/deps/src/singular.cpp @@ -54,6 +54,82 @@ static void WerrorS_and_reset(const char * s) singular_error_log.emplace_back(s); } +#define SETTER(A, B) \ + if (opt == #B) \ + { \ + old_value = (A & Sy_bit(B)) != 0; \ + A = value ? (A | Sy_bit(B)) : (A & ~Sy_bit(B)); \ + } else + +// all of the global setters return the previous value +auto set_option_helper(std::string opt, bool value, ring r) { + bool old_value = false; + ring oldring=currRing; + if (r!=NULL) rChangeCurrRing(r); + SETTER(si_opt_2, V_QUIET) + SETTER(si_opt_2, V_QRING) + SETTER(si_opt_2, V_SHOW_MEM) + SETTER(si_opt_2, V_YACC) + SETTER(si_opt_2, V_REDEFINE) + SETTER(si_opt_2, V_LOAD_LIB) + SETTER(si_opt_2, V_DEBUG_LIB) + SETTER(si_opt_2, V_LOAD_PROC) + SETTER(si_opt_2, V_DEF_RES) + SETTER(si_opt_2, V_SHOW_USE) + SETTER(si_opt_2, V_IMAP) + SETTER(si_opt_2, V_PROMPT) + SETTER(si_opt_2, V_NSB) + SETTER(si_opt_2, V_CONTENTSB) + SETTER(si_opt_2, V_CANCELUNIT) + SETTER(si_opt_2, V_MODPSOLVSB) + SETTER(si_opt_2, V_UPTORADICAL) + SETTER(si_opt_2, V_FINDMONOM) + SETTER(si_opt_2, V_COEFSTRAT) + SETTER(si_opt_2, V_IDLIFT) + SETTER(si_opt_2, V_LENGTH) + SETTER(si_opt_2, V_ALLWARN) + SETTER(si_opt_2, V_INTERSECT_ELIM) + SETTER(si_opt_2, V_INTERSECT_SYZ) + SETTER(si_opt_2, V_DEG_STOP) + + SETTER(si_opt_1, OPT_PROT) + SETTER(si_opt_1, OPT_REDSB) + SETTER(si_opt_1, OPT_NOT_BUCKETS) + SETTER(si_opt_1, OPT_NOT_SUGAR) + SETTER(si_opt_1, OPT_INTERRUPT) + SETTER(si_opt_1, OPT_SUGARCRIT) + SETTER(si_opt_1, OPT_DEBUG) + SETTER(si_opt_1, OPT_REDTHROUGH) + SETTER(si_opt_1, OPT_NO_SYZ_MINIM) + SETTER(si_opt_1, OPT_RETURN_SB) + SETTER(si_opt_1, OPT_FASTHC) + SETTER(si_opt_1, OPT_OLDSTD) + SETTER(si_opt_1, OPT_STAIRCASEBOUND) + SETTER(si_opt_1, OPT_MULTBOUND) + SETTER(si_opt_1, OPT_DEGBOUND) + SETTER(si_opt_1, OPT_REDTAIL) + SETTER(si_opt_1, OPT_INTSTRATEGY) + SETTER(si_opt_1, OPT_FINDET) + SETTER(si_opt_1, OPT_INFREDTAIL) + SETTER(si_opt_1, OPT_SB_1) + SETTER(si_opt_1, OPT_NOTREGULARITY) + SETTER(si_opt_1, OPT_WEIGHTM) + // else <--- not needed, already "provided" by SETTER + { + std::cerr << "unknown option " << opt << std::endl; + } + if (r!=NULL) + { + r->options=si_opt_1; + rChangeCurrRing(oldring); + } + return old_value; + } +auto set_option_helper2(std::string opt, bool value) { + return set_option_helper(opt,value,NULL); + } +#undef SETTER + JLCXX_MODULE define_julia_module(jlcxx::Module & Singular) { Singular.add_type("coeffs"); @@ -140,74 +216,9 @@ JLCXX_MODULE define_julia_module(jlcxx::Module & Singular) return ss.str(); }); -#define SETTER(A, B) \ - else if (opt == #B) \ - { \ - old_value = (A & Sy_bit(B)) != 0; \ - A = value ? (A | Sy_bit(B)) : (A & ~Sy_bit(B)); \ - } + Singular.method("set_option", &set_option_helper2); + Singular.method("set_option", &set_option_helper); - // all of the global setters return the previous value - Singular.method("set_option", [](std::string opt, bool value) { - bool old_value = false; - if (false) - ; - SETTER(si_opt_2, V_QUIET) - SETTER(si_opt_2, V_QRING) - SETTER(si_opt_2, V_SHOW_MEM) - SETTER(si_opt_2, V_YACC) - SETTER(si_opt_2, V_REDEFINE) - SETTER(si_opt_2, V_LOAD_LIB) - SETTER(si_opt_2, V_DEBUG_LIB) - SETTER(si_opt_2, V_LOAD_PROC) - SETTER(si_opt_2, V_DEF_RES) - SETTER(si_opt_2, V_SHOW_USE) - SETTER(si_opt_2, V_IMAP) - SETTER(si_opt_2, V_PROMPT) - SETTER(si_opt_2, V_NSB) - SETTER(si_opt_2, V_CONTENTSB) - SETTER(si_opt_2, V_CANCELUNIT) - SETTER(si_opt_2, V_MODPSOLVSB) - SETTER(si_opt_2, V_UPTORADICAL) - SETTER(si_opt_2, V_FINDMONOM) - SETTER(si_opt_2, V_COEFSTRAT) - SETTER(si_opt_2, V_IDLIFT) - SETTER(si_opt_2, V_LENGTH) - SETTER(si_opt_2, V_ALLWARN) - SETTER(si_opt_2, V_INTERSECT_ELIM) - SETTER(si_opt_2, V_INTERSECT_SYZ) - SETTER(si_opt_2, V_DEG_STOP) - - SETTER(si_opt_1, OPT_PROT) - SETTER(si_opt_1, OPT_REDSB) - SETTER(si_opt_1, OPT_NOT_BUCKETS) - SETTER(si_opt_1, OPT_NOT_SUGAR) - SETTER(si_opt_1, OPT_INTERRUPT) - SETTER(si_opt_1, OPT_SUGARCRIT) - SETTER(si_opt_1, OPT_DEBUG) - SETTER(si_opt_1, OPT_REDTHROUGH) - SETTER(si_opt_1, OPT_NO_SYZ_MINIM) - SETTER(si_opt_1, OPT_RETURN_SB) - SETTER(si_opt_1, OPT_FASTHC) - SETTER(si_opt_1, OPT_OLDSTD) - SETTER(si_opt_1, OPT_STAIRCASEBOUND) - SETTER(si_opt_1, OPT_MULTBOUND) - SETTER(si_opt_1, OPT_DEGBOUND) - SETTER(si_opt_1, OPT_REDTAIL) - SETTER(si_opt_1, OPT_INTSTRATEGY) - SETTER(si_opt_1, OPT_FINDET) - SETTER(si_opt_1, OPT_INFREDTAIL) - SETTER(si_opt_1, OPT_SB_1) - SETTER(si_opt_1, OPT_NOTREGULARITY) - SETTER(si_opt_1, OPT_WEIGHTM) - else - { - std::cerr << "unknown option " << opt << std::endl; - } - return old_value; - }); - -#undef SETTER // the "printlevel" system variable in Singular Singular.method("set_printlevel", [](int level) { diff --git a/src/MessyHacks.jl b/src/MessyHacks.jl index ef5ca3b99..cade9528e 100644 --- a/src/MessyHacks.jl +++ b/src/MessyHacks.jl @@ -16,13 +16,11 @@ Singular and this is the starting value. """ function with_degBound(f, degb::Integer) old_degb = libSingular.set_degBound(Cint(degb)) - local g = nothing try - g = f() + return f() finally libSingular.set_degBound(old_degb) end - return g end @doc raw""" @@ -35,13 +33,11 @@ bound in Singular and this is the starting value. """ function with_multBound(f, mu::Integer) old_mu = libSingular.set_multBound(Cint(mu)) - local g = nothing try - g = f() + return f() finally libSingular.set_multBound(old_mu) end - return g end for (name, str) in [(:with_fastHC, "OPT_FASTHC") @@ -56,19 +52,35 @@ for (name, str) in [(:with_fastHC, "OPT_FASTHC") @eval begin function ($name)(f, flag::Bool) old_flag = libSingular.set_option($str, flag) - local g = nothing try - g = f() + return f() finally libSingular.set_option($str, old_flag) end - return g end export $name end end +function with_redTail(f, flag::Bool, R::PolyRingUnion) + old_flag = libSingular.set_option("OPT_REDTAIL", flag, R.ptr) + try + return f() + finally + libSingular.set_option("OPT_REDTAIL", old_flag, R.ptr) + end +end + +function with_redThrough(f, flag::Bool, R::PolyRingUnion) + old_flag = libSingular.set_option("OPT_REDTHROUGH", flag, R.ptr) + try + return f() + finally + libSingular.set_option("OPT_REDTHROUGH", old_flag, R.ptr) + end +end + #= messy hack #1: diff --git a/src/ideal/ideal.jl b/src/ideal/ideal.jl index c5189b985..e2e8e15b0 100644 --- a/src/ideal/ideal.jl +++ b/src/ideal/ideal.jl @@ -847,12 +847,12 @@ from the identity matrix only for local ring orderings. function divrem(I::sideal{S}, G::sideal{S}; complete_reduction::Bool = false) where S <: SPolyUnion check_parent(I, G) R = base_ring(I) - old_redsb=libSingular.set_option("OPT_REDSB",complete_reduction) - old_redtail=libSingular.set_option("OPT_REDTAIL",complete_reduction) + old_redsb=libSingular.set_option("OPT_REDSB",complete_reduction,R.ptr) + old_redtail=libSingular.set_option("OPT_REDTAIL",complete_reduction,R.ptr) ptr_T,ptr_Rest,ptr_U = GC.@preserve I G R libSingular.id_Lift(G.ptr, I.ptr, true, false, true, R.ptr) - libSingular.set_option("OPT_REDSB",old_redsb) - libSingular.set_option("OPT_REDTAIL",old_redtail) + libSingular.set_option("OPT_REDSB",old_redsb,R.ptr) + libSingular.set_option("OPT_REDTAIL",old_redtail,R.ptr) return (smodule{S}(R,ptr_T), sideal{S}(R,ptr_Rest), smodule{S}(R,ptr_U)) end diff --git a/src/module/module.jl b/src/module/module.jl index a2de68882..fd7c9c3b4 100644 --- a/src/module/module.jl +++ b/src/module/module.jl @@ -274,12 +274,12 @@ from the identity matrix only for local ring orderings. function divrem(I::smodule{S}, G::smodule{S}; complete_reduction::Bool = false) where S <: SPolyUnion check_parent(I, G) R = base_ring(I) - old_redsb=libSingular.set_option("OPT_REDSB",complete_reduction) - old_redtail=libSingular.set_option("OPT_REDTAIL",complete_reduction) + old_redsb=libSingular.set_option("OPT_REDSB",complete_reduction,R.ptr) + old_redtail=libSingular.set_option("OPT_REDTAIL",complete_reduction,R.ptr) ptr_T,ptr_Rest,ptr_U = GC.@preserve I G R libSingular.id_Lift(G.ptr, I.ptr, true, false, true, R.ptr) - libSingular.set_option("OPT_REDSB",old_redsb) - libSingular.set_option("OPT_REDTAIL",old_redtail) + libSingular.set_option("OPT_REDSB",old_redsb,R.ptr) + libSingular.set_option("OPT_REDTAIL",old_redtail,R.ptr) return (smodule{S}(R,ptr_T), smodule{S}(R,ptr_Rest), smodule{S}(R,ptr_U)) end diff --git a/test/ideal-test.jl b/test/ideal-test.jl index 58379cbc9..0c70e2451 100644 --- a/test/ideal-test.jl +++ b/test/ideal-test.jl @@ -2,3 +2,4 @@ include("ideal/sideal-test.jl") include("ideal/quotient-test.jl") +include("ideal/freealg-test.jl") diff --git a/test/ideal/freealg-test.jl b/test/ideal/freealg-test.jl new file mode 100644 index 000000000..061774034 --- /dev/null +++ b/test/ideal/freealg-test.jl @@ -0,0 +1,30 @@ +@testset "freealg" begin + R, (u11,u12,u13,u14, + u21,u22,u23,u24, + u31,u32,u33,u34, + u41,u42,u43,u44) = FreeAlgebra(QQ, ["u11", "u12", "u13", "u14", + "u21", "u22", "u23", "u24", + "u31", "u32", "u33", "u34", + "u41", "u42", "u43", "u44"], 7) + #rs1 = u11 + u12 + u13 + u14 - 1 + rs2 = u21 + u22 + u23 + u24 - 1 + rs3 = u31 + u32 + u33 + u34 - 1 + rs4 = u41 + u42 + u43 + u44 - 1 + cs1 = u11 + u21 + u31 + u41 - 1 + cs2 = u12 + u22 + u32 + u42 - 1 + cs3 = u13 + u23 + u33 + u43 - 1 + cs4 = u14 + u24 + u34 + u44 - 1 + + Singular.libSingular.set_option("OPT_REDTAIL",false,R.ptr) + + J1 = Ideal(R,[rs2,rs3,rs4,cs1,cs2,cs3,cs4]) + J2 = std(J1) + + @test J2[7] == u11 + u21 + u31 + u41 - 1 + + J3 = Ideal(R,[rs2,rs3,rs4,cs1,cs2,cs3,cs4]) + J4 = with_redTail(false,R) do + std(J3) + end + @test J4[7] == u11 + u21 + u31 + u41 - 1 +end diff --git a/test/ideal/sideal-test.jl b/test/ideal/sideal-test.jl index d5417894e..3721bcf1c 100644 --- a/test/ideal/sideal-test.jl +++ b/test/ideal/sideal-test.jl @@ -396,7 +396,7 @@ end B = slimgb(I, complete_reduction=true) @test isequal(B, Ideal(R, 2y^2 + 3, x^2 + x*y + 1)) || - isequal(B, Ideal(x^2 + x*y + 1, 2y^2 + 3)) + isequal(B, Ideal(R, x^2 + x*y + 1, 2y^2 + 3)) @test B.isGB == true end diff --git a/test/module/smodule-test.jl b/test/module/smodule-test.jl index 46c0ffe8a..f15a93dfe 100644 --- a/test/module/smodule-test.jl +++ b/test/module/smodule-test.jl @@ -48,12 +48,12 @@ end v3 = v1 + v2 w1 = vector(R, y, y) - w2 = vector(R, x - y, y^2 - y) + w2 = vector(R, x, y^2) M = Singular.Module(R, v1, v2, v3) MM = Singular.minimal_generating_set(M) - @test MM[1] == w1 && MM[2] == w2 + @test MM[1] == w1 && MM[2] == -v2 end @testset "smodule.manipulation" begin