Skip to content

Commit

Permalink
add divrem2 (#774)
Browse files Browse the repository at this point in the history
* add divrem2

* Update src/ideal/ideal.jl

Co-authored-by: ederc <ederc@mathematik.uni-kl.de>

* Update src/ideal/ideal.jl

Co-authored-by: ederc <ederc@mathematik.uni-kl.de>

* compatibily

* Update src/ideal/ideal.jl

Co-authored-by: Max Horn <max@quendi.de>

* Update test/ideal/sideal-test.jl

Co-authored-by: Max Horn <max@quendi.de>

* fix: test

---------

Co-authored-by: ederc <ederc@mathematik.uni-kl.de>
Co-authored-by: Max Horn <max@quendi.de>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent 8521208 commit a7a0749
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions deps/src/ideals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,10 @@ void singular_define_ideals(jlcxx::Module & Singular)
rChangeCurrRing(o);
ideal factors;
ideal unit;
ideal res = idDivRem(sm, m, factors, &unit, flag);
ideal rest = idDivRem(m, sm, factors, &unit, flag);
rest->rank = m->rank;
rChangeCurrRing(origin);
return std::make_tuple(res, factors, unit);
return std::make_tuple(rest,factors, unit);
});

Singular.method("id_Lift", [](ideal m, ideal sm, ring o) {
Expand Down
21 changes: 20 additions & 1 deletion src/ideal/ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

###############################################################################
#
Expand Down Expand Up @@ -840,6 +840,25 @@ function divrem(I::sideal{S}, G::sideal{S}; complete_reduction::Bool = false) wh
return (smodule{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 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 = 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`.
`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

###############################################################################
#
# Eliminate
Expand Down
3 changes: 3 additions & 0 deletions test/ideal/sideal-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,7 @@ 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)
@test isequal(r2, reduce(a, b))
end

0 comments on commit a7a0749

Please sign in to comment.