Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
5 changes: 5 additions & 0 deletions src/Oscar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ function __init__()
Pkg.is_manifest_current(dirname(Base.active_project())))
@warn "Project dependencies might have changed, please run `]up` or `]resolve`."
end

# Temporary workaround to allow access to Singular's tropicalVariety command
# see https://github.com/oscar-system/Oscar.jl/issues/5392
Singular.libSingular.load_library("tropical.lib")
Singular.call_interpreter("proc tropicalVariety_as_string(ideal I, list #) { if(size(#)==0) { return(string(tropicalVariety(I))); }; return(string(tropicalVariety(I,#[1]))); }")
end

const PROJECT_TOML = Pkg.TOML.parsefile(joinpath(@__DIR__, "..", "Project.toml"))
Expand Down
1 change: 0 additions & 1 deletion src/TropicalGeometry/variety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ julia> vertices(TropI_3)
```
"""
function tropical_variety(I::MPolyIdeal, nu::TropicalSemiringMap=tropical_semiring_map(coefficient_ring(I)); weighted_polyhedral_complex_only::Bool=false, skip_saturation::Bool=false, skip_decomposition::Bool=false)

if !skip_saturation
###
# If saturation requested, saturate `I`
Expand Down
29 changes: 20 additions & 9 deletions src/TropicalGeometry/variety_prime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ function tropical_variety_prime(I::MPolyIdeal, nu::TropicalSemiringMap; weighted
return dehomogenize_post_tropicalization(TropIh)
end


# trivial valuation
function tropical_variety_prime_singular(I::MPolyIdeal, nu::TropicalSemiringMap{QQField,Nothing,<:Union{typeof(min),typeof(max)}}; weighted_polyhedral_complex_only::Bool=false)
R = base_ring(I)
singularCommand = join(["ring r=0,("*join(string.(symbols(R)),",")*"),dp;",
"ideal I = "*join(string.(gens(I)), ",")*";",
"if (!defined(tropicalVariety)) { LIB \"tropical.lib\"; };",
"fan TropI = tropicalVariety(I);",
"string TropIString = string(TropI);"])
Singular.call_interpreter(singularCommand)
TropIString = Singular.lookup_library_symbol("Top", "TropIString")

sI = Oscar.singular_generators(I)
TropIString = Singular.low_level_caller("tropical", "tropicalVariety_as_string", sI)

Sigma = gfan_fan_string_to_oscar_complex(TropIString,convention(nu)==max,false)
TropI = compute_weights_and_construct_tropical_variety(Sigma,I,nu)
if !weighted_polyhedral_complex_only
Expand All @@ -38,8 +35,23 @@ function tropical_variety_prime_singular(I::MPolyIdeal, nu::TropicalSemiringMap{
return TropI
end

# Given a polynomial ring S, return a map into an isomorphic polynomial ring S->R
# but with variables renamed to be Singular compatible.
# The new names are x1, ..., xn if nvars(R)<10, x01, ..., x10 if nvar(R)<100, etc.
# zero padding is necessary because Singular interpreter does not like variable names
# that are substrings of other variable names.
function hom_rename_variables_singular_compatible(S::MPolyRing)
n = nvars(S)
l = ndigits(n)
newVarNames = [Symbol(:x, lpad(string(i), l, '0')) for i in 1:n]
R,x = polynomial_ring(base_ring(S), newVarNames)
return hom(S,R,x)
end

# p-adic valuation
function tropical_variety_prime_singular(I::MPolyIdeal, nu::TropicalSemiringMap{QQField,ZZRingElem,<:Union{typeof(min),typeof(max)}}; weighted_polyhedral_complex_only::Bool=false)
phi = hom_rename_variables_singular_compatible(base_ring(I))
I = phi(I)
R = base_ring(I)
singularCommand = join(["ring r=0,("*join(string.(symbols(R)),",")*"),dp;",
"ideal I = "*join(string.(gens(I)), ",")*";",
Expand Down Expand Up @@ -121,7 +133,6 @@ function gfan_fan_string_to_oscar_complex(input_string::String, negateFan::Bool=
coneIncidences = [ vcat(incidence,[originIndex]) for incidence in coneIncidences ]
return polyhedral_complex(IncidenceMatrix(coneIncidences), rayGenerators, rayIndices, linealityGenerators)
end

end


Expand Down
3 changes: 3 additions & 0 deletions test/TropicalGeometry/variety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@
@test f_vector(TropV) == [1,3]

# general ideals, see doctests
I = grassmann_pluecker_ideal(2, 5)
TropI = tropical_variety(I; skip_saturation=true, skip_decomposition=true)
@test f_vector(TropI) == [0, 0, 0, 0, 0, 1, 10, 15]
end
end
Loading