Skip to content

Commit

Permalink
Allow AbstractVectors as input for initial (oscar-system#4027)
Browse files Browse the repository at this point in the history
* TropicalGeometry: fixes initial issue

oscar-system#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 <benlorenz@users.noreply.github.com>

---------

Co-authored-by: Benjamin Lorenz <benlorenz@users.noreply.github.com>
  • Loading branch information
2 people authored and HechtiDerLachs committed Sep 13, 2024
1 parent 4fd3ac4 commit a292f65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/src/TropicalGeometry/groebner_theory.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
20 changes: 5 additions & 15 deletions src/TropicalGeometry/initial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
###
Expand Down Expand Up @@ -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

0 comments on commit a292f65

Please sign in to comment.