diff --git a/Project.toml b/Project.toml index 2b9645ede965..18128194ec82 100644 --- a/Project.toml +++ b/Project.toml @@ -31,7 +31,7 @@ GAP = "0.9.4" Hecke = "0.18.13" JSON = "^0.20, ^0.21" Nemo = "0.34.3" -Polymake = "0.9.0" +Polymake = "0.10.0" Preferences = "1" RandomExtensions = "0.4.3" RecipesBase = "1.2.1" diff --git a/src/PolyhedralGeometry/LP_file_format.jl b/src/PolyhedralGeometry/LP_file_format.jl index a8531c0231dd..bc1ac38a9036 100644 --- a/src/PolyhedralGeometry/LP_file_format.jl +++ b/src/PolyhedralGeometry/LP_file_format.jl @@ -96,7 +96,7 @@ julia> save_mps(stdout, milp) * Columns: 2 * Format: MPS * -Name unnamed#0 +NAME unnamed#0 ROWS N C0000000 G R0000000 diff --git a/src/TropicalGeometry/TropicalGeometry.jl b/src/TropicalGeometry/TropicalGeometry.jl index e1b894a9e60f..d15c630a5b77 100644 --- a/src/TropicalGeometry/TropicalGeometry.jl +++ b/src/TropicalGeometry/TropicalGeometry.jl @@ -7,46 +7,35 @@ include("groebner_basis.jl") include("groebner_polyhedron.jl") include("points.jl") -# Temporarily we will turn tropical polynomials into strings. This will be -# removed once Polymake.jl wraps its tropical polynomials and tropical numbers -# -# Warning: This function ignores all boundary cases! -function tropical_polynomial_to_polymake(f) - fstr = "" - if convention(base_ring(f)) == min - fstr *= "min(" - else - fstr *= "max(" - end - td = total_degree(f) - for i in 1:length(f) - fstr *= repr(coeff(f,i).data) - e = exponent_vector(f,i) - if td - sum(e) != 0 - fstr *= "+" - fstr *= repr(td-sum(e)) - fstr *= "x_0" - end - if !iszero(e) - for j in 1:length(e) - if !iszero(e[j]) - fstr *= "+" - fstr *= repr(e[j]) - fstr *= "*x_" - fstr *= repr(j) - end - end - end - if i != length(f) - fstr *= "," - end - end - fstr *= ")" - result = ["x_"*repr(i) for i in 0:nvars(parent(f))] - prepend!(result, [fstr]) - return result +# Decompose a tropical polynomial into parts that Polymake can eat. +# First function deals with the coefficients, +# Second function then deals with the entire polynomial. +function homogenize_and_convert_to_pm(t::Oscar.TropicalSemiringElem{S}) where S<:Union{typeof(max), typeof(min)} + Add = S == typeof(max) ? Polymake.Max : Polymake.Min + if isinf(t) + return Polymake.TropicalNumber{Add}() + else + return Polymake.TropicalNumber{Add}(Polymake.new_rational_from_fmpq(data(t))) + end end +function homogenize_and_convert_to_pm(f::Oscar.MPolyRingElem{Oscar.TropicalSemiringElem{S}}) where S<:Union{typeof(max), typeof(min)} + Add = S == typeof(max) ? Polymake.Max : Polymake.Min + coeffs = (Polymake.TropicalNumber{Add})[] + td = total_degree(f) + exps = (Vector{Int})[] + for term in terms(f) + push!(coeffs, homogenize_and_convert_to_pm(leading_coefficient(term))) + exp = leading_exponent_vector(term) + prepend!(exp, td-sum(exp)) + push!(exps, exp) + end + exps = matrix(ZZ, exps) + coeffs = Polymake.Vector{Polymake.TropicalNumber{Add, Polymake.Rational}}(coeffs) + return coeffs, exps +end + + ### # Allow gcd of vectors of univariate rational polynomials diff --git a/src/TropicalGeometry/hypersurface.jl b/src/TropicalGeometry/hypersurface.jl index d06ac693e115..e1191714020a 100644 --- a/src/TropicalGeometry/hypersurface.jl +++ b/src/TropicalGeometry/hypersurface.jl @@ -78,9 +78,8 @@ function TropicalHypersurface(f::AbstractAlgebra.Generic.MPoly{Oscar.TropicalSem error("Tropical hypersurfaces of constant polynomials not supported.") end M = convention(base_ring(f)) - fstr = Tuple(tropical_polynomial_to_polymake(f)) - pmpoly = Polymake.common.totropicalpolynomial(fstr...) - pmhypproj = Polymake.tropical.Hypersurface{M}(POLYNOMIAL=pmpoly) + coeffs, exps = homogenize_and_convert_to_pm(f) + pmhypproj = Polymake.tropical.Hypersurface{M}(MONOMIALS=exps, COEFFICIENTS=coeffs) pmhyp = Polymake.tropical.affine_chart(pmhypproj) Vf = TropicalHypersurface{M, true}(polyhedral_complex(pmhyp)) w = pmhypproj.WEIGHTS diff --git a/test/PolyhedralGeometry/linear_program.jl b/test/PolyhedralGeometry/linear_program.jl index b23a63e3350f..000f4762d09c 100644 --- a/test/PolyhedralGeometry/linear_program.jl +++ b/test/PolyhedralGeometry/linear_program.jl @@ -85,7 +85,7 @@ * Columns: 2 * Format: MPS * - Name unnamed#2 + NAME unnamed#2 ROWS N C0000000 G R0000000 diff --git a/test/TropicalGeometry/hypersurface.jl b/test/TropicalGeometry/hypersurface.jl new file mode 100644 index 000000000000..443a102b1fb9 --- /dev/null +++ b/test/TropicalGeometry/hypersurface.jl @@ -0,0 +1,14 @@ +@testset "hypersurface" begin + for addition in (max, min) + T = TropicalSemiring(addition) + R,(x,y,z) = PolynomialRing(T,3) + b = [T(10),T(3//2095), T(-5//2)] + m = [[1,0,1],[0,3,4],[1,0,7]] + f = R(b,m) + hyp = TropicalHypersurface(f) + coeffs, exps = Oscar.homogenize_and_convert_to_pm(f) + @test hyp isa TropicalHypersurface{addition} + @test coeffs == get_attribute(hyp, :polymake_bigobject).COEFFICIENTS + @test exps == matrix(ZZ, get_attribute(hyp, :polymake_bigobject).MONOMIALS) + end +end diff --git a/test/TropicalGeometry/runtests.jl b/test/TropicalGeometry/runtests.jl index 78aa89c7c61c..8a007c0cf95a 100644 --- a/test/TropicalGeometry/runtests.jl +++ b/test/TropicalGeometry/runtests.jl @@ -3,3 +3,4 @@ using Oscar include("groebner_basis.jl") include("groebner_fan.jl") include("initial.jl") +include("hypersurface.jl")