Multivariate Tropical Polynomials

AUTHORS:

  • Verrel Rievaldo Wijaya (2024-06): initial version

EXAMPLES:

sage: T = TropicalSemiring(QQ, use_min=True)
sage: R.<x,y,z> = PolynomialRing(T)
sage: z.parent()
Multivariate Tropical Polynomial Semiring in x, y, z over Rational Field
sage: R(2)*x + R(-1)*x + R(5)*y + R(-3)
(-1)*x + 5*y + (-3)
sage: (x+y+z)^2
0*x^2 + 0*x*y + 0*y^2 + 0*x*z + 0*y*z + 0*z^2
>>> from sage.all import *
>>> T = TropicalSemiring(QQ, use_min=True)
>>> R = PolynomialRing(T, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)
>>> z.parent()
Multivariate Tropical Polynomial Semiring in x, y, z over Rational Field
>>> R(Integer(2))*x + R(-Integer(1))*x + R(Integer(5))*y + R(-Integer(3))
(-1)*x + 5*y + (-3)
>>> (x+y+z)**Integer(2)
0*x^2 + 0*x*y + 0*y^2 + 0*x*z + 0*y*z + 0*z^2

REFERENCES:

class sage.rings.semirings.tropical_mpolynomial.TropicalMPolynomial(parent, x)[source]

Bases: MPolynomial_polydict

A multivariate tropical polynomial.

Let \(x_1, x_2, \ldots, x_n\) be indeterminants. A tropical monomial is any product of these variables, possibly including repetitions: \(x_1^{i_1}\cdots x_n^{i_n}\) where \(i_j \in \{0,1,\ldots\}\), for all \(j\in \{1,\ldots,n\}\). A multivariate tropical polynomial is a finite linear combination of tropical monomials, \(p(x_1, \ldots, x_n) = \sum_{i=1}^n c_i x_1^{i_1}\cdots x_n^{i_n}\).

In classical arithmetic, we can rewrite the general form of a tropical monomial: \(x_1^{i_1}\cdots x_n^{i_n} \mapsto i_1 x_1 + \cdots + i_n x_n\). Thus, the tropical polynomial can be viewed as the minimum (maximum) of a finite collection of linear functions.

EXAMPLES:

Construct a multivariate tropical polynomial semiring in two variables:

sage: T = TropicalSemiring(QQ, use_min=False)
sage: R.<a,b> = PolynomialRing(T); R
Multivariate Tropical Polynomial Semiring in a, b over Rational Field
>>> from sage.all import *
>>> T = TropicalSemiring(QQ, use_min=False)
>>> R = PolynomialRing(T, names=('a', 'b',)); (a, b,) = R._first_ngens(2); R
Multivariate Tropical Polynomial Semiring in a, b over Rational Field

Define some multivariate tropical polynomials:

sage: p1 = R(3)*a*b + a + R(-1)*b; p1
3*a*b + 0*a + (-1)*b
sage: p2 = R(1)*a + R(1)*b + R(1)*a*b; p2
1*a*b + 1*a + 1*b
>>> from sage.all import *
>>> p1 = R(Integer(3))*a*b + a + R(-Integer(1))*b; p1
3*a*b + 0*a + (-1)*b
>>> p2 = R(Integer(1))*a + R(Integer(1))*b + R(Integer(1))*a*b; p2
1*a*b + 1*a + 1*b

Some basic arithmetic operations for multivariate tropical polynomials:

sage: p1 + p2
3*a*b + 1*a + 1*b
sage: p1 * p2
4*a^2*b^2 + 4*a^2*b + 4*a*b^2 + 1*a^2 + 1*a*b + 0*b^2
sage: T(2) * p1
5*a*b + 2*a + 1*b
sage: p1(T(1),T(2))
6
>>> from sage.all import *
>>> p1 + p2
3*a*b + 1*a + 1*b
>>> p1 * p2
4*a^2*b^2 + 4*a^2*b + 4*a*b^2 + 1*a^2 + 1*a*b + 0*b^2
>>> T(Integer(2)) * p1
5*a*b + 2*a + 1*b
>>> p1(T(Integer(1)),T(Integer(2)))
6

Let us look at the different result for tropical curve and 3d graph of tropical polynomial in two variables when different algebra is used. First for the min-plus algebra:

sage: T = TropicalSemiring(QQ, use_min=True)
sage: R.<a,b> = PolynomialRing(T)
sage: p1 = R(3)*a*b + a + R(-1)*b
sage: p1.tropical_variety()
Tropical curve of 3*a*b + 0*a + (-1)*b
sage: p1.tropical_variety().plot()
Graphics object consisting of 3 graphics primitives
>>> from sage.all import *
>>> T = TropicalSemiring(QQ, use_min=True)
>>> R = PolynomialRing(T, names=('a', 'b',)); (a, b,) = R._first_ngens(2)
>>> p1 = R(Integer(3))*a*b + a + R(-Integer(1))*b
>>> p1.tropical_variety()
Tropical curve of 3*a*b + 0*a + (-1)*b
>>> p1.tropical_variety().plot()
Graphics object consisting of 3 graphics primitives
../../../_images/tropical_mpolynomial-1.svg

Tropical polynomial in two variables will induce a function in three dimension that consists of a number of surfaces:

sage: p1.plot3d()
Graphics3d Object
>>> from sage.all import *
>>> p1.plot3d()
Graphics3d Object
../../../_images/tropical_mpolynomial-2.svg

If we use a max-plus algebra, we will get a slightly different result:

sage: T = TropicalSemiring(QQ, use_min=False)
sage: R.<a,b> = PolynomialRing(T)
sage: p1 = R(3)*a*b + a + R(-1)*b
sage: p1.tropical_variety()
Tropical curve of 3*a*b + 0*a + (-1)*b
sage: p1.tropical_variety().plot()
Graphics object consisting of 3 graphics primitives
>>> from sage.all import *
>>> T = TropicalSemiring(QQ, use_min=False)
>>> R = PolynomialRing(T, names=('a', 'b',)); (a, b,) = R._first_ngens(2)
>>> p1 = R(Integer(3))*a*b + a + R(-Integer(1))*b
>>> p1.tropical_variety()
Tropical curve of 3*a*b + 0*a + (-1)*b
>>> p1.tropical_variety().plot()
Graphics object consisting of 3 graphics primitives
../../../_images/tropical_mpolynomial-3.svg
sage: p1.plot3d()
Graphics3d Object
>>> from sage.all import *
>>> p1.plot3d()
Graphics3d Object
../../../_images/tropical_mpolynomial-4.svg
plot3d(color='random')[source]

Return the 3d plot of self.

Only implemented for tropical polynomial in two variables. The \(x\)-\(y\) axes for this 3d plot is the same as the \(x\)-\(y\) axes of the corresponding tropical curve.

OUTPUT: Graphics3d Object

EXAMPLES:

A simple tropical polynomial that consist of only one surface:

sage: T = TropicalSemiring(QQ, use_min=False)
sage: R.<x,y> = PolynomialRing(T)
sage: p1 = x^2
sage: p1.plot3d()
Graphics3d Object
>>> from sage.all import *
>>> T = TropicalSemiring(QQ, use_min=False)
>>> R = PolynomialRing(T, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
>>> p1 = x**Integer(2)
>>> p1.plot3d()
Graphics3d Object
../../../_images/tropical_mpolynomial-5.svg

Tropical polynomials often have graphs that represent a combination of multiple surfaces:

sage: p2 = R(3) + R(2)*x + R(2)*y + R(3)*x*y
sage: p2.plot3d()
Graphics3d Object
>>> from sage.all import *
>>> p2 = R(Integer(3)) + R(Integer(2))*x + R(Integer(2))*y + R(Integer(3))*x*y
>>> p2.plot3d()
Graphics3d Object
../../../_images/tropical_mpolynomial-6.svg
sage: T = TropicalSemiring(QQ)
sage: R.<x,y> = PolynomialRing(T)
sage: p3 = R(2)*x^2 + x*y + R(2)*y^2 + x + R(-1)*y + R(3)
sage: p3.plot3d()
Graphics3d Object
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
>>> p3 = R(Integer(2))*x**Integer(2) + x*y + R(Integer(2))*y**Integer(2) + x + R(-Integer(1))*y + R(Integer(3))
>>> p3.plot3d()
Graphics3d Object
../../../_images/tropical_mpolynomial-7.svg
subs(fixed=None, **kwds)[source]

Fix some given variables in self and return the changed tropical multivariate polynomials.

EXAMPLES:

sage: T = TropicalSemiring(QQ, use_min=False)
sage: R.<x,y> = PolynomialRing(T)
sage: p1 = x^2 + y + R(3)
sage: p1((R(4),y))
0*y + 8
sage: p1.subs({x: 4})
0*y + 8
>>> from sage.all import *
>>> T = TropicalSemiring(QQ, use_min=False)
>>> R = PolynomialRing(T, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
>>> p1 = x**Integer(2) + y + R(Integer(3))
>>> p1((R(Integer(4)),y))
0*y + 8
>>> p1.subs({x: Integer(4)})
0*y + 8
tropical_variety()[source]

Return tropical roots of self.

In the multivariate case, the roots can be represented by a tropical variety. In two dimensions, this is known as a tropical curve. For dimensions higher than two, it is referred to as a tropical hypersurface.

OUTPUT: a sage.rings.semirings.tropical_variety.TropicalVariety

EXAMPLES:

Tropical curve for tropical polynomials in two variables:

sage: T = TropicalSemiring(QQ, use_min=False)
sage: R.<x,y> = PolynomialRing(T)
sage: p1 = x + y + R(0); p1
0*x + 0*y + 0
sage: p1.tropical_variety()
Tropical curve of 0*x + 0*y + 0
>>> from sage.all import *
>>> T = TropicalSemiring(QQ, use_min=False)
>>> R = PolynomialRing(T, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
>>> p1 = x + y + R(Integer(0)); p1
0*x + 0*y + 0
>>> p1.tropical_variety()
Tropical curve of 0*x + 0*y + 0

Tropical hypersurface for tropical polynomials in more than two variables:

sage: T = TropicalSemiring(QQ)
sage: R.<x,y,z> = PolynomialRing(T)
sage: p1 = R(1)*x*y + R(-1/2)*x*z + R(4)*z^2; p1
1*x*y + (-1/2)*x*z + 4*z^2
sage: p1.tropical_variety()
Tropical surface of 1*x*y + (-1/2)*x*z + 4*z^2
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)
>>> p1 = R(Integer(1))*x*y + R(-Integer(1)/Integer(2))*x*z + R(Integer(4))*z**Integer(2); p1
1*x*y + (-1/2)*x*z + 4*z^2
>>> p1.tropical_variety()
Tropical surface of 1*x*y + (-1/2)*x*z + 4*z^2
class sage.rings.semirings.tropical_mpolynomial.TropicalMPolynomialSemiring(base_semiring, n, names, order)[source]

Bases: UniqueRepresentation, Parent

The semiring of tropical polynomials in multiple variables.

This is the commutative semiring consisting of all finite linear combinations of tropical monomials under (tropical) addition and multiplication with coefficients in a tropical semiring.

EXAMPLES:

sage: T = TropicalSemiring(QQ)
sage: R.<x,y> = PolynomialRing(T)
sage: f = T(1)*x + T(-1)*y
sage: g = T(2)*x + T(-2)*y
sage: f + g
1*x + (-2)*y
sage: f * g
3*x^2 + (-1)*x*y + (-3)*y^2
sage: f + R.zero() == f
True
sage: f * R.zero() == R.zero()
True
sage: f * R.one() == f
True
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
>>> f = T(Integer(1))*x + T(-Integer(1))*y
>>> g = T(Integer(2))*x + T(-Integer(2))*y
>>> f + g
1*x + (-2)*y
>>> f * g
3*x^2 + (-1)*x*y + (-3)*y^2
>>> f + R.zero() == f
True
>>> f * R.zero() == R.zero()
True
>>> f * R.one() == f
True
Element[source]

alias of TropicalMPolynomial

gen(n=0)[source]

Return the n-th generator of self.

EXAMPLES:

sage: T = TropicalSemiring(QQ)
sage: R.<a,b,c> = PolynomialRing(T)
sage: R.gen()
0*a
sage: R.gen(2)
0*c
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, names=('a', 'b', 'c',)); (a, b, c,) = R._first_ngens(3)
>>> R.gen()
0*a
>>> R.gen(Integer(2))
0*c
gens()[source]

Return the generators of self.

EXAMPLES:

sage: T = TropicalSemiring(QQ)
sage: R = PolynomialRing(T, 5, 'x')
sage: R.gens()
(0*x0, 0*x1, 0*x2, 0*x3, 0*x4)
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, Integer(5), 'x')
>>> R.gens()
(0*x0, 0*x1, 0*x2, 0*x3, 0*x4)
ngens()[source]

Return the number of generators of self.

EXAMPLES:

sage: T = TropicalSemiring(QQ)
sage: R = PolynomialRing(T, 10, 'z')
sage: R.ngens()
10
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, Integer(10), 'z')
>>> R.ngens()
10
one()[source]

Return the multiplicative identity of self.

EXAMPLES:

sage: T = TropicalSemiring(QQ)
sage: R = PolynomialRing(T, 'x,y')
sage: R.one()
0
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, 'x,y')
>>> R.one()
0
random_element(degree=2, terms=None, choose_degree=False, *args, **kwargs)[source]

Return a random multivariate tropical polynomial from self.

OUTPUT: a TropicalMPolynomial

EXAMPLES:

A random polynomial of at most degree \(d\) and at most \(t\) terms:

sage: T = TropicalSemiring(QQ)
sage: R.<a,b,c> = PolynomialRing(T)
sage: f = R.random_element(2, 5)
sage: f.degree() <= 2
True
sage: f.parent() is R
True
sage: len(list(f)) <= 5
True
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, names=('a', 'b', 'c',)); (a, b, c,) = R._first_ngens(3)
>>> f = R.random_element(Integer(2), Integer(5))
>>> f.degree() <= Integer(2)
True
>>> f.parent() is R
True
>>> len(list(f)) <= Integer(5)
True

Choose degrees of monomials randomly first rather than monomials uniformly random:

sage: f = R.random_element(3, 6, choose_degree=True)
sage: f.degree() <= 3
True
sage: f.parent() is R
True
sage: len(list(f)) <= 6
True
>>> from sage.all import *
>>> f = R.random_element(Integer(3), Integer(6), choose_degree=True)
>>> f.degree() <= Integer(3)
True
>>> f.parent() is R
True
>>> len(list(f)) <= Integer(6)
True
term_order()[source]

Return the defined term order of self.

EXAMPLES:

sage: T = TropicalSemiring(QQ)
sage: R.<x,y,z> = PolynomialRing(T)
sage: R.term_order()
Degree reverse lexicographic term order
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)
>>> R.term_order()
Degree reverse lexicographic term order
zero()[source]

Return the additive identity of self.

EXAMPLES:

sage: T = TropicalSemiring(QQ)
sage: R = PolynomialRing(T, 'x,y')
sage: R.zero()
+infinity
>>> from sage.all import *
>>> T = TropicalSemiring(QQ)
>>> R = PolynomialRing(T, 'x,y')
>>> R.zero()
+infinity