From a292f6533256f5bb41f980c6c0967638ab1b1bc9 Mon Sep 17 00:00:00 2001 From: Yue Ren Date: Tue, 20 Aug 2024 17:11:34 +0100 Subject: [PATCH] Allow AbstractVectors as input for initial (#4027) * TropicalGeometry: fixes initial issue https://github.com/oscar-system/Oscar.jl/issues/4025 * TropicalGeometry: allow point_vector as input for initial * TropicalGeometry: removing unused optional perturbation input * Update src/TropicalGeometry/initial.jl Co-authored-by: Benjamin Lorenz --------- Co-authored-by: Benjamin Lorenz --- docs/src/TropicalGeometry/groebner_theory.md | 4 ++-- src/TropicalGeometry/initial.jl | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/docs/src/TropicalGeometry/groebner_theory.md b/docs/src/TropicalGeometry/groebner_theory.md index e96f1b98ed7d..f697c68affe5 100644 --- a/docs/src/TropicalGeometry/groebner_theory.md +++ b/docs/src/TropicalGeometry/groebner_theory.md @@ -19,6 +19,6 @@ groebner_basis(I::MPolyIdeal, nu::TropicalSemiringMap, w::Vector{<:Union{QQField ## Initial forms and initial ideals ```@docs -initial(f::MPolyRingElem, nu::TropicalSemiringMap, w::Vector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}) -initial(I::MPolyIdeal, nu::TropicalSemiringMap, w::Vector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}; skip_groebner_basis_computation::Bool=false) +initial(f::MPolyRingElem, nu::TropicalSemiringMap, w::AbstractVector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}) +initial(I::MPolyIdeal, nu::TropicalSemiringMap, w::AbstractVector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}; skip_groebner_basis_computation::Bool=false) ``` diff --git a/src/TropicalGeometry/initial.jl b/src/TropicalGeometry/initial.jl index 191b43523a98..a5315f86bd57 100644 --- a/src/TropicalGeometry/initial.jl +++ b/src/TropicalGeometry/initial.jl @@ -5,7 +5,7 @@ ################################################################################ @doc raw""" - initial(f::MPolyRingElem, nu::TropicalSemiringMap, w::Vector; perturbation::Vector=[]) + initial(f::MPolyRingElem, nu::TropicalSemiringMap, w::Vector) Return the initial form of `f` with respect to the tropical semiring map `nu` and weight vector `w`. @@ -46,29 +46,19 @@ x + y + 1 ``` """ -function initial(f::MPolyRingElem, nu::TropicalSemiringMap, w::Vector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}; perturbation::Union{Nothing,Vector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}}=nothing) - +function initial(f::MPolyRingElem, nu::TropicalSemiringMap, w::AbstractVector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}) ### # Evaluate the tropicalization of f and all its terms at w, # mark the terms which attain the evaluated value ### coeffs = collect(coefficients(f)) expvs = collect(exponents(f)) - tropTermsEvaluated = [nu(c)*dot(w,alpha) for (c,alpha) in zip(coeffs,expvs)] + tropTermsEvaluated = [nu(c)*tropical_semiring(nu)(dot(w,alpha)) for (c,alpha) in zip(coeffs,expvs)] tropPolyEvaluated = sum(tropTermsEvaluated) termsAttainingValue = findall(isequal(tropPolyEvaluated),tropTermsEvaluated) coeffs = coeffs[termsAttainingValue] expvs = expvs[termsAttainingValue] - # if perturbation passed, further filter the marked terms - if !isnothing(perturbation) - tropTermsEvaluated = [tropical_semiring(nu)(dot(w,alpha)) for (c,alpha) in zip(coeffs,expvs)] - tropPolyEvaluated = sum(tropTermsEvaluated) - termsAttainingValue = findall(isequal(tropPolyEvaluated),tropTermsEvaluated) - coeffs = coeffs[termsAttainingValue] - expvs = expvs[termsAttainingValue] - end - ### # Construct the initial form ### @@ -110,7 +100,7 @@ Ideal generated by -2*x^2*y + 3*y^3 ``` """ -function initial(I::MPolyIdeal, nu::TropicalSemiringMap, w::Vector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}; skip_groebner_basis_computation::Bool=false) - G = (skip_groebner_basis_computation ? gens(G) : groebner_basis(I,nu,w)) +function initial(I::MPolyIdeal, nu::TropicalSemiringMap, w::AbstractVector{<:Union{QQFieldElem,ZZRingElem,Rational,Integer}}; skip_groebner_basis_computation::Bool=false) + G = (skip_groebner_basis_computation ? gens(I) : groebner_basis(I,nu,w)) return ideal(initial.(G,Ref(nu),Ref(w))) end