|
78 | 78 | ###
|
79 | 79 | # Disabling ideals in tropical polyomial rings
|
80 | 80 | ###
|
81 |
| -function MPolyIdeal(R::Ring, g::Vector{Generic.MPoly{TropicalSemiringElem{minOrMax}}}) where {minOrMax} |
| 81 | +function MPolyIdeal(::Ring, ::Vector{Generic.MPoly{TropicalSemiringElem{minOrMax}}}) where {minOrMax <: Union{typeof(min),typeof(max)}} |
82 | 82 | error("Ideals over tropical semirings not supported")
|
83 | 83 | end
|
84 | 84 |
|
85 | 85 |
|
| 86 | +### |
| 87 | +# Roots of univariate tropical polynomials |
| 88 | +### |
| 89 | +""" |
| 90 | + roots(f::PolyRingElem{<:TropicalSemiringElem}) |
| 91 | +
|
| 92 | +Return the tropical roots of a univariate tropical polynomial `f`, i.e., the variable values where |
| 93 | +the min or max is attained at least twice. |
| 94 | +
|
| 95 | +# Examples |
| 96 | +
|
| 97 | +```jldoctest |
| 98 | +julia> R,x = polynomial_ring(tropical_semiring(min),:x) |
| 99 | +(Univariate polynomial ring in x over min tropical semiring, x) |
| 100 | +
|
| 101 | +julia> f = 1*x^2+x+0 |
| 102 | +(1)*x^2 + x + (0) |
| 103 | +
|
| 104 | +julia> roots(f) |
| 105 | +2-element Vector{QQFieldElem}: |
| 106 | + 0 |
| 107 | + -1 |
| 108 | +
|
| 109 | +julia> R,x = polynomial_ring(tropical_semiring(max),:x) |
| 110 | +(Univariate polynomial ring in x over max tropical semiring, x) |
| 111 | +
|
| 112 | +julia> f = 1*x^2+x+0 |
| 113 | +(1)*x^2 + x + (0) |
| 114 | +
|
| 115 | +julia> roots(f) |
| 116 | +1-element Vector{QQFieldElem}: |
| 117 | + -1//2 |
| 118 | +
|
| 119 | +``` |
| 120 | +""" |
| 121 | +function roots(f::PolyRingElem{TropicalSemiringElem{minOrMax}}) where {minOrMax <: Union{typeof(min),typeof(max)}} |
| 122 | + # Construct either the lower (min) or upper (max) convex hull of degrees and coefficients |
| 123 | + # Example: for min(1+2x,x,0) it is conv({(2,1), (1,0), (0,0)}) + RR_{>=0}*(0,1) |
| 124 | + # for max(1+2x,x,0) it is conv({(2,1), (1,0), (0,0)}) + RR_{>=0}*(0,-1) |
| 125 | + # Note: univariate polynomials also enumerate over zero coefficients, necessitating !iszero(c) below |
| 126 | + valsAndExps = [ QQFieldElem[first(d),QQ(c)] for (d,c) in zip(exponents(f),coefficients(f)) if !iszero(c) ] |
| 127 | + |
| 128 | + if length(valsAndExps)<2 |
| 129 | + return QQFieldElem[] # return empty set if f not at least binomial |
| 130 | + end |
| 131 | + |
| 132 | + s = minOrMax==typeof(min) ? 1 : -1 # +1 if min, -1 if max |
| 133 | + hullDirection = s*[0 1] |
| 134 | + newtonPolygon = convex_hull(valsAndExps,hullDirection) |
| 135 | + |
| 136 | + # The negated slopes of the lower (min) or upper (max) edges are when function value is attained at least twice |
| 137 | + # Example: for min(1+2x,x,0) it is -1 and 0, for max(1+2x,x,0) it is -1/2 |
| 138 | + F = affine_inequality_matrix(facets(newtonPolygon)) |
| 139 | + negatedSlopes = [ F[i,2]/F[i,3] for i in 1:nrows(F) if s*F[i,3]<0 ] |
| 140 | + return negatedSlopes |
| 141 | +end |
| 142 | + |
| 143 | + |
86 | 144 |
|
87 | 145 | ################################################################################
|
88 | 146 | #
|
|
0 commit comments