Skip to content

Commit

Permalink
TropicalGeometry: resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
YueRen committed Sep 18, 2024
1 parent 44cd831 commit fdde04b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 114 deletions.
2 changes: 1 addition & 1 deletion src/TropicalGeometry/TropicalGeometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ include("semiring.jl")
include("semiring_map.jl")
include("matrix.jl")
include("poly.jl")
include("variety_supertype.jl")
include("homogenization.jl")
include("groebner_basis.jl")
include("initial.jl")
# include("groebner_polyhedron.jl")
# include("points.jl")
include("variety_supertype.jl")
include("hypersurface.jl")
include("curve.jl")
include("linear_space.jl")
Expand Down
24 changes: 15 additions & 9 deletions src/TropicalGeometry/homogenization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ function homogenize_pre_tropicalization(I::MPolyIdeal)
end


function dehomogenize_post_tropicalization(Sigma::PolyhedralComplex)
@req lineality_dim(Sigma)>0 "dehomogenizing polyhedral complex without lineality"
function dehomogenize_post_tropicalization(TropV::TropicalVarietySupertype)

@req lineality_dim(TropV)>0 "dehomogenizing polyhedral complex without lineality"

###
# Construct hyperplane {first coord = 0}
###
n = ambient_dim(Sigma)
n = ambient_dim(TropV)
zerothUnitRowVector = zeros(Int,1,n)
zerothUnitRowVector[1,1] = 1
dehomogenisingHyperplane = polyhedron((zeros(Int,0,n),zeros(Int,0)), (zerothUnitRowVector,[0]))
Expand All @@ -52,7 +53,7 @@ function dehomogenize_post_tropicalization(Sigma::PolyhedralComplex)
dehomogenizedVertices = Vector{QQFieldElem}[]
incidenceMatrixRays = Vector{Int}[]
dehomogenizedRays = Vector{QQFieldElem}[]
for sigma in maximal_polyhedra(Sigma)
for sigma in maximal_polyhedra(TropV)
sigmaDehomogenized = intersect(sigma,dehomogenisingHyperplane)
incidenceVectorVertices = Int[]
V,_ = minimal_faces(sigmaDehomogenized)
Expand Down Expand Up @@ -95,12 +96,17 @@ function dehomogenize_post_tropicalization(Sigma::PolyhedralComplex)
###
# Dehomogenize lineality space
###
sigma = first(maximal_polyhedra(Sigma))
sigma = first(maximal_polyhedra(TropV))
sigmaDehomogenized = intersect(sigma,dehomogenisingHyperplane)
dehomogenizedLineality = [linealityVector[2:end] for linealityVector in lineality_space(sigmaDehomogenized)]

return polyhedral_complex(incidenceMatrixVerticesAndRays,
dehomogenizedVerticesAndRays,
collect(length(dehomogenizedVertices)+1:length(dehomogenizedVertices)+length(dehomogenizedRays)),
dehomogenizedLineality)
SigmaDehom = polyhedral_complex(incidenceMatrixVerticesAndRays,
dehomogenizedVerticesAndRays,
collect(length(dehomogenizedVertices)+1:length(dehomogenizedVertices)+length(dehomogenizedRays)),
dehomogenizedLineality)

TropVDehom = tropical_variety(SigmaDehom,multiplicities(TropV),convention(TropV))
# TropVDehom.__attrs = deepcopy(TropV.__attrs) # TODO: not working, how to copy all attributes?
return TropVDehom

end
104 changes: 0 additions & 104 deletions src/TropicalGeometry/variety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,107 +194,3 @@ end
function tropical_variety(f::MPolyRingElem, nu::Union{TropicalSemiringMap,Nothing}=nothing; weighted_polyhedral_complex_only::Bool=false)
return tropical_variety(ideal(parent(f),[f]),nu,weighted_polyhedral_complex_only=weighted_polyhedral_complex_only)
end


function homogenize_pre_tropicalization(I::MPolyIdeal)
###
# Compute reduced Groebner basis (usually already cached), and construct homogenization
###
G = groebner_basis(I,complete_reduction=true)

Kx = base_ring(I)
K = coefficient_ring(Kx)
x = symbols(Kx)
Kxhx,_ = polynomial_ring(K,vcat([:xh],x))

Gh = Vector{elem_type(Kx)}(undef,length(G))
for (i,g) in enumerate(G)
gh = MPolyBuildCtx(Kxhx)
d = total_degree(g)
for (c,alpha) in coefficients_and_exponents(g)
pushfirst!(alpha,d-sum(alpha)) # homogenize exponent vector
push_term!(gh,c,alpha)
end
Gh[i] = finish(gh)
end

return ideal(Gh)
end


function dehomogenize_post_tropicalization(TropV::TropicalVarietySupertype)

@req lineality_dim(TropV)>0 "dehomogenizing polyhedral complex without lineality"

###
# Construct hyperplane {first coord = 0}
###
n = ambient_dim(TropV)
zerothUnitRowVector = zeros(Int,1,n)
zerothUnitRowVector[1,1] = 1
dehomogenisingHyperplane = polyhedron((zeros(Int,0,n),zeros(Int,0)), (zerothUnitRowVector,[0]))

###
# Construct matrix and incidence matrix of vertices and rays
###
incidenceMatrixVertices = Vector{Int}[]
dehomogenizedVertices = Vector{QQFieldElem}[]
incidenceMatrixRays = Vector{Int}[]
dehomogenizedRays = Vector{QQFieldElem}[]
for sigma in maximal_polyhedra(TropV)
sigmaDehomogenized = intersect(sigma,dehomogenisingHyperplane)
incidenceVectorVertices = Int[]
V,_ = minimal_faces(sigmaDehomogenized)
for vertex in V
vertex = vertex[2:end]
i = findfirst(isequal(vertex),dehomogenizedVertices)
if i === nothing
push!(dehomogenizedVertices,vertex)
push!(incidenceVectorVertices,length(dehomogenizedVertices))
else
push!(incidenceVectorVertices,i)
end
end
push!(incidenceMatrixVertices,incidenceVectorVertices)

incidenceVectorRays = Int[]
R,_ = rays_modulo_lineality(sigmaDehomogenized)
for ray in R
ray = ray[2:end]
i = findfirst(isequal(ray),dehomogenizedRays)
if i === nothing
push!(dehomogenizedRays,ray)
push!(incidenceVectorRays,length(dehomogenizedRays))
else
push!(incidenceVectorRays,i)
end
end
push!(incidenceMatrixRays,incidenceVectorRays)
end

###
# Concatenate vertically matrixes of vertices and rays,
# shift incidence matrix of rays and concatenate it horizontally to incicende matrix of vertices,
# dehomogenize generators of lineality space
###
dehomogenizedVerticesAndRays = matrix(QQ,vcat(dehomogenizedVertices,dehomogenizedRays))
incidenceMatrixRaysShifted = (x -> x .+length(dehomogenizedVertices)).(incidenceMatrixRays)
incidenceMatrixVerticesAndRays = IncidenceMatrix([vcat(iv,ir) for (iv,ir) in zip(incidenceMatrixVertices,incidenceMatrixRaysShifted)])

###
# Dehomogenize lineality space
###
sigma = first(maximal_polyhedra(TropV))
sigmaDehomogenized = intersect(sigma,dehomogenisingHyperplane)
dehomogenizedLineality = [linealityVector[2:end] for linealityVector in lineality_space(sigmaDehomogenized)]

SigmaDehom = polyhedral_complex(incidenceMatrixVerticesAndRays,
dehomogenizedVerticesAndRays,
collect(length(dehomogenizedVertices)+1:length(dehomogenizedVertices)+length(dehomogenizedRays)),
dehomogenizedLineality)

TropVDehom = tropical_variety(SigmaDehom,multiplicities(TropV),convention(TropV))
# TropVDehom.__attrs = deepcopy(TropV.__attrs) # TODO: not working, how to copy all attributes?
return TropVDehom

end

0 comments on commit fdde04b

Please sign in to comment.