From bcd1d946554dacea33ff354d6adb4310f9ac0f66 Mon Sep 17 00:00:00 2001 From: Yue Ren Date: Wed, 27 Nov 2024 11:00:12 +0000 Subject: [PATCH] TropicalGeometry: tropical_linear_space from graphs --- docs/src/TropicalGeometry/linear_space.md | 1 + src/TropicalGeometry/linear_space.jl | 24 +++++++++++++++++++++++ test/TropicalGeometry/linear_space.jl | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/docs/src/TropicalGeometry/linear_space.md b/docs/src/TropicalGeometry/linear_space.md index e24400084940..0377a47a62bb 100644 --- a/docs/src/TropicalGeometry/linear_space.md +++ b/docs/src/TropicalGeometry/linear_space.md @@ -18,6 +18,7 @@ In addition to converting from `TropicalVariety`, objects of type `TropicalLinea 4. matrices over a field and a tropical semiring map. - if matrix over `QQ` and tropical semiring map is trivial, uses an implementation of Rincon's algorithm [Rin13](@cite) in `polymake` - for general input, computes minors and uses constructor (2.) +5. graphs ```@docs tropical_linear_space ``` diff --git a/src/TropicalGeometry/linear_space.jl b/src/TropicalGeometry/linear_space.jl index df85b285f466..0fcb9e332993 100644 --- a/src/TropicalGeometry/linear_space.jl +++ b/src/TropicalGeometry/linear_space.jl @@ -365,6 +365,30 @@ function tropical_linear_space(I::MPolyIdeal, nu::Union{Nothing,TropicalSemiring end +@doc raw""" + tropical_linear_space(G::Graph, nu::TropicalSemiringMap; weighted_polyhedral_complex_only::Bool=false) + +Return the Bergman fan of the graphic matroid of `G` as a tropical linear space, the tropical semiring map `nu` is used to fix the convention. If `weighted_polyhedral_complex==true`, will not cache any extra information. + +# Examples +```jldoctest +julia> G = complete_graph(4) +Undirected graph with 4 nodes and the following edges: +(2, 1)(3, 1)(3, 2)(4, 1)(4, 2)(4, 3) + +julia> tropical_linear_space(G) +Min tropical linear space + +``` +""" +function tropical_linear_space(G::Graph, nu::Union{Nothing,TropicalSemiringMap}=nothing; weighted_polyhedral_complex_only::Bool=false) + M = matrix(QQ,signed_incidence_matrix(G)) + TropG = tropical_linear_space(M,nu;weighted_polyhedral_complex_only=weighted_polyhedral_complex_only) + if !weighted_polyhedral_complex_only + set_attribute!(TropG,:graph,G) + end + return TropG +end ############################################################################### # diff --git a/test/TropicalGeometry/linear_space.jl b/test/TropicalGeometry/linear_space.jl index 537cbe8aeddc..b2f7409a0f9a 100644 --- a/test/TropicalGeometry/linear_space.jl +++ b/test/TropicalGeometry/linear_space.jl @@ -32,4 +32,10 @@ @test issetequal(plueckerVector,tropical_pluecker_vector(TropL)) end + @testset "tropical linear space from graphs" begin + G = complete_graph(3) + TropG = tropical_linear_space(G) + @test f_vector(TropG) == [0,1,3] + end + end