Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AbstractVectors as input for initial #4027

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
```
18 changes: 4 additions & 14 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)
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(G) : groebner_basis(I,nu,w))
return ideal(initial.(G,Ref(nu),Ref(w)))
YueRen marked this conversation as resolved.
Show resolved Hide resolved
end
Loading