From 354d0fd6744cb78922ef8245ba3d45d474ff3ebd Mon Sep 17 00:00:00 2001 From: Yue Ren Date: Wed, 18 Sep 2024 07:16:30 +0100 Subject: [PATCH] TropicalGeometry: resolved merge conflict --- src/TropicalGeometry/homogenization.jl | 24 +++--- src/TropicalGeometry/variety.jl | 104 ------------------------- 2 files changed, 15 insertions(+), 113 deletions(-) diff --git a/src/TropicalGeometry/homogenization.jl b/src/TropicalGeometry/homogenization.jl index d58d78093319..a99d56f21f54 100644 --- a/src/TropicalGeometry/homogenization.jl +++ b/src/TropicalGeometry/homogenization.jl @@ -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])) @@ -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) @@ -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 diff --git a/src/TropicalGeometry/variety.jl b/src/TropicalGeometry/variety.jl index f4f78b0837bc..f4e209134edd 100644 --- a/src/TropicalGeometry/variety.jl +++ b/src/TropicalGeometry/variety.jl @@ -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