diff --git a/src/algorithms/dimension.jl b/src/algorithms/dimension.jl index 05ff7a4..c104e7f 100644 --- a/src/algorithms/dimension.jl +++ b/src/algorithms/dimension.jl @@ -19,17 +19,16 @@ julia> dimension(I) """ function dimension(I::Ideal{T}) where T <: MPolyRingElem - gb = isempty(values(I.gb)) ? groebner_basis(I) : first(values(I.gb)) + gb = get(I.gb, 0, groebner_basis(I, complete_reduction = true)) R = parent(first(gb)) res = [trues(ngens(R))] - lms = (Nemo.leading_monomial).(gb) - for lm in lms + lead_exps = (_drl_lead_exp).(gb) + for lexp in lead_exps to_del = Int[] new_miss = BitVector[] for (i, mis) in enumerate(res) - nz_exps_inds = findall(e -> !iszero(e), - first(Nemo.exponent_vectors(lm))) + nz_exps_inds = findall(e -> !iszero(e), lexp) ind_var_inds = findall(mis) if issubset(nz_exps_inds, ind_var_inds) for j in nz_exps_inds @@ -48,3 +47,13 @@ function dimension(I::Ideal{T}) where T <: MPolyRingElem max_length = maximum(mis -> length(findall(mis)), res) return max_length end + +function _drl_exp_vector(u::Vector{Int}) + return [sum(u), -reverse(u)...] +end + +function _drl_lead_exp(p::MPolyRingElem) + exps = collect(Nemo.exponent_vectors(p)) + _, i = findmax((u -> _drl_exp_vector(u)).(exps)) + return exps[i] +end diff --git a/test/algorithms/dimension.jl b/test/algorithms/dimension.jl index 265d576..d8cab64 100644 --- a/test/algorithms/dimension.jl +++ b/test/algorithms/dimension.jl @@ -5,5 +5,5 @@ R, (x,y,z) = polynomial_ring(GF(101),["x","y","z"]) I = Ideal([x+2*y+2*z-1, x^2+2*y^2+2*z^2-x, 2*x*y+2*y*z-y]) - @test isone(dimension(I)) + @test iszero(dimension(I)) end