From b66dcd1f0371134fd68c0198ef8261da3fae1492 Mon Sep 17 00:00:00 2001 From: Hans Schoenemann Date: Wed, 7 Feb 2024 11:17:56 +0100 Subject: [PATCH 1/7] add divrem2 --- deps/src/ideals.cpp | 4 ++-- src/ideal/ideal.jl | 23 +++++++++++++++++++++-- test/ideal/sideal-test.jl | 2 ++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/deps/src/ideals.cpp b/deps/src/ideals.cpp index 5834b7216..393d1562a 100644 --- a/deps/src/ideals.cpp +++ b/deps/src/ideals.cpp @@ -473,9 +473,9 @@ void singular_define_ideals(jlcxx::Module & Singular) rChangeCurrRing(o); ideal factors; ideal unit; - ideal res = idDivRem(sm, m, factors, &unit, flag); + ideal quot = idDivRem(m, sm, factors, &unit, flag); rChangeCurrRing(origin); - return std::make_tuple(res, factors, unit); + return std::make_tuple(quot,factors, unit); }); Singular.method("id_Lift", [](ideal m, ideal sm, ring o) { diff --git a/src/ideal/ideal.jl b/src/ideal/ideal.jl index db92c1f96..a553182bf 100644 --- a/src/ideal/ideal.jl +++ b/src/ideal/ideal.jl @@ -5,7 +5,7 @@ export sideal, IdealSet, syz, lead, normalize!, is_constant, is_zerodim, fglm, intersection, homogenize_ideal, homogenize_ideal_with_weights, quotient, reduce, eliminate, kernel, equal, contains, is_var_generated, saturation, saturation2, satstd, slimgb, std, vdim, interreduce, degree, mult, - hilbert_series, std_hilbert, is_homogeneous, division, divrem, mstd + hilbert_series, std_hilbert, is_homogeneous, division, divrem, divrem2, mstd ############################################################################### # @@ -837,7 +837,26 @@ function divrem(I::sideal{S}, G::sideal{S}; complete_reduction::Bool = false) wh false, true, R.ptr) libSingular.set_option("OPT_REDSB",old_redsb) libSingular.set_option("OPT_REDTAIL",old_redtail) - return (smodule{S}(R,ptr_T), sideal{S}(R,ptr_Rest), smodule{S}(R,ptr_U)) + return (sideal{S}(R,ptr_T), sideal{S}(R,ptr_Rest), smodule{S}(R,ptr_U)) +end + +@doc raw""" + divrem2(I::sideal{S}, G::sideal{S}; complete_reduction::Bool = false) where S <: SPolyUnion + +Computes a normalform of the generators of `I` by the generators of `G`, +keeping track of the reduction. Returns a tuple (Quo, Rem, U) where +`Matrix(I)*Matrix(U) = Matrix(G)*Matrix(Quo) + Matrix(Rem)` +and `Rem = normalform(I, G)`. `U` is a diagonal matrix of units differing +from the identity matrix only for local ring orderings. +Leading terms of `Matrix(G)*Matrix(Quo)` are less or equal to the corresponding terms of `I`. +No term of `Rem` is divisible by any leading term of `G`. +`divrem2` is identical to `divrem` if G is given by a Groebner basis. +""" +function divrem2(I::sideal{S}, G::sideal{S}; complete_reduction::Bool = false) where S <: SPolyUnion + check_parent(I, G) + R = base_ring(I) + ptr_Rest,ptr_T,ptr_U = GC.@preserve I G R libSingular.id_DivRem_Unit(I.ptr, G.ptr, R.ptr, 0) + return (smodule{S}(R,ptr_T), sideal{S}(R,ptr_Rest),smodule{S}(R,ptr_U)) end ############################################################################### diff --git a/test/ideal/sideal-test.jl b/test/ideal/sideal-test.jl index 7aed0a30e..f2387e336 100644 --- a/test/ideal/sideal-test.jl +++ b/test/ideal/sideal-test.jl @@ -713,4 +713,6 @@ end @test Singular.Matrix(a)*Singular.Matrix(u) == Singular.Matrix(b)*Singular.Matrix(q)+Singular.Matrix(r) @test gens(reduce(a, b, complete_reduction=false))[1] ==y^3+x*y @test gens(reduce(a, b, complete_reduction=true))[1] == y^3 + q2,r2,u2 = divrem2(a, b) + @test Singular.Matrix(a)*Singular.Matrix(u2) == Singular.Matrix(b)*Singular.Matrix(q2)+Singular.Matrix(r2) end From 8b28f441a180a69729d2d5372f908ac04c1bacca Mon Sep 17 00:00:00 2001 From: Hans Schoenemann Date: Wed, 7 Feb 2024 13:45:48 +0100 Subject: [PATCH 2/7] Update src/ideal/ideal.jl Co-authored-by: ederc --- src/ideal/ideal.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ideal/ideal.jl b/src/ideal/ideal.jl index a553182bf..294f71b70 100644 --- a/src/ideal/ideal.jl +++ b/src/ideal/ideal.jl @@ -843,7 +843,7 @@ end @doc raw""" divrem2(I::sideal{S}, G::sideal{S}; complete_reduction::Bool = false) where S <: SPolyUnion -Computes a normalform of the generators of `I` by the generators of `G`, +Computes a normal form of the generators of `I` by the generators of `G`, keeping track of the reduction. Returns a tuple (Quo, Rem, U) where `Matrix(I)*Matrix(U) = Matrix(G)*Matrix(Quo) + Matrix(Rem)` and `Rem = normalform(I, G)`. `U` is a diagonal matrix of units differing From 39470436de79d11487e0651252a5a5095dca7c20 Mon Sep 17 00:00:00 2001 From: Hans Schoenemann Date: Wed, 7 Feb 2024 13:45:57 +0100 Subject: [PATCH 3/7] Update src/ideal/ideal.jl Co-authored-by: ederc --- src/ideal/ideal.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ideal/ideal.jl b/src/ideal/ideal.jl index 294f71b70..f23df25ac 100644 --- a/src/ideal/ideal.jl +++ b/src/ideal/ideal.jl @@ -847,7 +847,7 @@ Computes a normal form of the generators of `I` by the generators of `G`, keeping track of the reduction. Returns a tuple (Quo, Rem, U) where `Matrix(I)*Matrix(U) = Matrix(G)*Matrix(Quo) + Matrix(Rem)` and `Rem = normalform(I, G)`. `U` is a diagonal matrix of units differing -from the identity matrix only for local ring orderings. +from the identity matrix only for local monomial orderings. Leading terms of `Matrix(G)*Matrix(Quo)` are less or equal to the corresponding terms of `I`. No term of `Rem` is divisible by any leading term of `G`. `divrem2` is identical to `divrem` if G is given by a Groebner basis. From b66bd3fe930ee73d2f13ee395623cc3a3ad173f0 Mon Sep 17 00:00:00 2001 From: Hans Schoenemann Date: Wed, 7 Feb 2024 15:17:37 +0100 Subject: [PATCH 4/7] compatibily --- deps/src/ideals.cpp | 5 +++-- src/ideal/ideal.jl | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/deps/src/ideals.cpp b/deps/src/ideals.cpp index 393d1562a..7c4731868 100644 --- a/deps/src/ideals.cpp +++ b/deps/src/ideals.cpp @@ -473,9 +473,10 @@ void singular_define_ideals(jlcxx::Module & Singular) rChangeCurrRing(o); ideal factors; ideal unit; - ideal quot = idDivRem(m, sm, factors, &unit, flag); + ideal rest = idDivRem(m, sm, factors, &unit, flag); + rest->rank = m->rank; rChangeCurrRing(origin); - return std::make_tuple(quot,factors, unit); + return std::make_tuple(rest,factors, unit); }); Singular.method("id_Lift", [](ideal m, ideal sm, ring o) { diff --git a/src/ideal/ideal.jl b/src/ideal/ideal.jl index f23df25ac..1811e808d 100644 --- a/src/ideal/ideal.jl +++ b/src/ideal/ideal.jl @@ -837,7 +837,7 @@ function divrem(I::sideal{S}, G::sideal{S}; complete_reduction::Bool = false) wh false, true, R.ptr) libSingular.set_option("OPT_REDSB",old_redsb) libSingular.set_option("OPT_REDTAIL",old_redtail) - return (sideal{S}(R,ptr_T), sideal{S}(R,ptr_Rest), smodule{S}(R,ptr_U)) + return (smodule{S}(R,ptr_T), sideal{S}(R,ptr_Rest), smodule{S}(R,ptr_U)) end @doc raw""" From 68928797af3b5b45a1d25af2bd8d6064c067fb17 Mon Sep 17 00:00:00 2001 From: Hans Schoenemann Date: Mon, 12 Feb 2024 15:22:50 +0100 Subject: [PATCH 5/7] Update src/ideal/ideal.jl Co-authored-by: Max Horn --- src/ideal/ideal.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ideal/ideal.jl b/src/ideal/ideal.jl index 1811e808d..267d5c64e 100644 --- a/src/ideal/ideal.jl +++ b/src/ideal/ideal.jl @@ -846,7 +846,7 @@ end Computes a normal form of the generators of `I` by the generators of `G`, keeping track of the reduction. Returns a tuple (Quo, Rem, U) where `Matrix(I)*Matrix(U) = Matrix(G)*Matrix(Quo) + Matrix(Rem)` -and `Rem = normalform(I, G)`. `U` is a diagonal matrix of units differing +and `Rem = reduce(I, G; complete_reduction)`. `U` is a diagonal matrix of units differing from the identity matrix only for local monomial orderings. Leading terms of `Matrix(G)*Matrix(Quo)` are less or equal to the corresponding terms of `I`. No term of `Rem` is divisible by any leading term of `G`. From f46ddb42910d6b39deed8e5c322ea2a784b1d5e6 Mon Sep 17 00:00:00 2001 From: Hans Schoenemann Date: Mon, 12 Feb 2024 15:36:16 +0100 Subject: [PATCH 6/7] Update test/ideal/sideal-test.jl Co-authored-by: Max Horn --- test/ideal/sideal-test.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ideal/sideal-test.jl b/test/ideal/sideal-test.jl index f2387e336..c500708bb 100644 --- a/test/ideal/sideal-test.jl +++ b/test/ideal/sideal-test.jl @@ -715,4 +715,5 @@ end @test gens(reduce(a, b, complete_reduction=true))[1] == y^3 q2,r2,u2 = divrem2(a, b) @test Singular.Matrix(a)*Singular.Matrix(u2) == Singular.Matrix(b)*Singular.Matrix(q2)+Singular.Matrix(r2) + @test r2 == reduce(a, b) end From 03c89cbd50148073ace2a7e0ace42ba5d98cbaca Mon Sep 17 00:00:00 2001 From: Hans Schoenemann Date: Mon, 12 Feb 2024 15:48:48 +0100 Subject: [PATCH 7/7] fix: test --- test/ideal/sideal-test.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ideal/sideal-test.jl b/test/ideal/sideal-test.jl index c500708bb..5f62ca1ba 100644 --- a/test/ideal/sideal-test.jl +++ b/test/ideal/sideal-test.jl @@ -715,5 +715,5 @@ end @test gens(reduce(a, b, complete_reduction=true))[1] == y^3 q2,r2,u2 = divrem2(a, b) @test Singular.Matrix(a)*Singular.Matrix(u2) == Singular.Matrix(b)*Singular.Matrix(q2)+Singular.Matrix(r2) - @test r2 == reduce(a, b) + @test isequal(r2, reduce(a, b)) end