Skip to content

Commit

Permalink
TropicalGeometry: tests for varieties and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
YueRen committed Oct 19, 2023
1 parent cbc4697 commit 7071095
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 86 deletions.
13 changes: 9 additions & 4 deletions src/TropicalGeometry/linear_space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ Min tropical linear space
```
"""
function tropical_linear_space(A::Union{Matrix{T},MatElem{T}};
weighted_polyhedral_complex_only::Bool=false) where T <: TropicalSemiringElem
function tropical_linear_space(A::Union{Matrix{T},MatElem{T}}; weighted_polyhedral_complex_only::Bool=false) where {T<:TropicalSemiringElem}
# convert to Oscar matrix (necessary for AbstractAlgebra.minors)
if A isa Matrix
A = matrix(parent(first(A)),A)
Expand Down Expand Up @@ -278,8 +277,11 @@ Min tropical linear space
```
"""
function tropical_linear_space(A::MatElem, nu::TropicalSemiringMap;
function tropical_linear_space(A::MatElem, nu::Union{Nothing,TropicalSemiringMap}=nothing;
weighted_polyhedral_complex_only::Bool=false)
# initialise nu as the trivial valuation if not specified by user
isnothing(nu) && (nu=tropical_semiring_map(coefficient_ring(f)))

n = max(nrows(A), ncols(A))
k = min(nrows(A), ncols(A))
plueckerIndices = AbstractAlgebra.combinations(1:n,k)
Expand Down Expand Up @@ -315,8 +317,11 @@ Min tropical linear space
```
"""
function tropical_linear_space(I::MPolyIdeal, nu::TropicalSemiringMap;
function tropical_linear_space(I::MPolyIdeal, nu::Union{Nothing,TropicalSemiringMap}=nothing;
weighted_polyhedral_complex_only::Bool=false)
# initialise nu as the trivial valuation if not specified by user
isnothing(nu) && (nu=tropical_semiring_map(coefficient_ring(f)))

x = gens(base_ring(I))
G = gens(I)
macaulayMatrix = matrix([[coeff(g,xi) for xi in x] for g in G])
Expand Down
2 changes: 1 addition & 1 deletion src/TropicalGeometry/variety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function tropical_variety_binomial(I::MPolyIdeal,nu::TropicalSemiringMap; weight
###
G = groebner_basis(I,complete_reduction=true)
A = matrix(ZZ,[first(collect(expv))-last(collect(expv)) for expv in exponents.(G)])
b = [ QQ(nu(first(collect(coeff))/last(collect(coeff)))) for coeff in coefficients.(G)]
b = [ QQ(nu(last(collect(coeff))/first(collect(coeff)))) for coeff in coefficients.(G)]

###
# Compute tropical variety multiplicity
Expand Down
45 changes: 0 additions & 45 deletions test/TropicalGeometry/hypersurface.jl

This file was deleted.

72 changes: 36 additions & 36 deletions test/TropicalGeometry/variety.jl
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
@testset "src/TropicalGeometry/{variety,hypersurface,curve,linear_space}.jl" begin

# no dedicated tests for variety.jl
# will be tested inside the following testsets

@testset "hypersurface.jl" begin
# semiring min
T = tropical_semiring()
R,(x,y) = T["x","y"]
f = x^3+y^3+1*x*y+0
TropH = tropical_hypersurface(f)
S,(x,y) = QQ["x","y"];
TropV = first(tropical_variety(ideal(S,[x^3+y^3+1]))) # default trivial valuation, min convention
@test issetequal(vertices_and_rays(TropH),vertices_and_rays(TropV))
@test n_maximal_polyhedra(TropH)==3

# semiring max
T = tropical_semiring(max)
R,(x,y) = T["x","y"]
f = x^3+y^3+(-1)*x*y+0
TropH = tropical_hypersurface(f)
S,(x,y) = QQ["x","y"];
nu = tropical_semiring_map(QQ,max)
TropV = first(tropical_variety(ideal(S,[x^3+y^3+1]),nu))
@test issetequal(vertices_and_rays(TropH),vertices_and_rays(TropV))
@test n_maximal_polyhedra(TropH)==3
# constructing various tropicalizations two ways
# and comparing their results
@testset "hypersurface and linear spaces" begin
R,(x,y,z) = QQ["x","y","z"]
f = x+2*y+4*z
nu = tropical_semiring_map(QQ,2)
TropH = tropical_hypersurface(f,nu)
TropL = tropical_linear_space(ideal(R,f),nu)
@test issetequal(maximal_polyhedra(TropH),maximal_polyhedra(TropL))
nu = tropical_semiring_map(QQ,2,max)
TropH = tropical_hypersurface(f,nu)
TropL = tropical_linear_space(ideal(R,f),nu)
@test issetequal(maximal_polyhedra(TropH),maximal_polyhedra(TropL))
end

# trivial, min
R,(x,y) = QQ["x","y"]
f = x^3+y^3+x*y+0
TropH = tropical_hypersurface(f)
TropV = first(tropical_variety(f))
issetequal(vertices_and_rays(TropH),vertices_and_rays(TropV))
n_maximal_polyhedra(TropH)==3
@testset "binomial ideals and linear spaces" begin
R,(x,y,z,w) = QQ["x","y","z","w"]
I = ideal(R,[x+2*y,z+4*w])
nu = tropical_semiring_map(QQ,2)
TropV = first(tropical_variety(I,nu))
TropL = tropical_linear_space(I,nu)
@test issetequal(maximal_polyhedra(TropV),maximal_polyhedra(TropL))
nu = tropical_semiring_map(QQ,2,max)
TropV = first(tropical_variety(I,nu))
TropL = tropical_linear_space(I,nu)
@test issetequal(maximal_polyhedra(TropV),maximal_polyhedra(TropL))
end

# trivial, max
nu = tropical_semiring_map(QQ,max)
@testset "hypersurface and binomial ideals" begin
R,(x,y,z) = QQ["x","y","z"]
f = x*y*z+2
nu = tropical_semiring_map(QQ,2)
TropH = tropical_hypersurface(f,nu)
TropV = first(tropical_variety(ideal(R,f),nu))
@test issetequal(maximal_polyhedra(TropH),maximal_polyhedra(TropV))
nu = tropical_semiring_map(QQ,2,max)
TropV = first(tropical_variety(ideal(R,f),nu))
TropH = tropical_hypersurface(f,nu)
TropV = first(tropical_variety(f,nu))
issetequal(vertices_and_rays(TropH),vertices_and_rays(TropV))
n_maximal_polyhedra(TropH)==3
@test issetequal(maximal_polyhedra(TropH),maximal_polyhedra(TropV))
end

end

0 comments on commit 7071095

Please sign in to comment.