Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dual subdivision and weight vectors for tropical variety #38536

Draft
wants to merge 26 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
06841b5
Add ``dual_subdivision``
verreld7 Aug 20, 2024
6734319
Add ``_components_of_vertices`` and ``weight_vectors``
verreld7 Aug 20, 2024
8b8c5cc
Add ``is_smooth``, ``is_simple``, ``genus``, ``contribution``
verreld7 Aug 21, 2024
5c9e8d1
Add ``weight_vectors`` in tropical surface
verreld7 Aug 21, 2024
010149c
Add ``PLOT`` section in dual subdvision and add one reference
verreld7 Aug 22, 2024
3f1641a
Add ``TESTS`` to genus and contribution
verreld7 Aug 23, 2024
4795639
Small fix on style and white spaces
verreld7 Aug 23, 2024
a601cbd
Refactor ``vertices`` in tropical curve
verreld7 Aug 25, 2024
2e8592c
Move ``weight_vectors`` from ``TropicalSurface`` to ``TropicalVariety``
verreld7 Aug 25, 2024
96a0f4c
Small fix on example
verreld7 Aug 25, 2024
ec4307d
Another fix
verreld7 Aug 25, 2024
401ad51
Fix docstring in ``weight_vectors``
verreld7 Aug 26, 2024
792b829
Change output of dual subdivision from Graph to PolyhedralComplex
verreld7 Aug 30, 2024
dd2d14d
Refine docstring
verreld7 Aug 30, 2024
f20838a
Small fix on example
verreld7 Aug 30, 2024
f425552
Refine the docstring more
verreld7 Aug 30, 2024
4306750
Add more examples to ``TropicalCurve``
verreld7 Sep 2, 2024
3d05257
Move dual subdivision to ``TropicalMPolynomial``
verreld7 Sep 8, 2024
d2d211b
Add ``polytope`` to ``TropicalMPolynomial``
verreld7 Sep 8, 2024
53f495e
Fix ``PLOT`` section in dual subdivision
verreld7 Sep 8, 2024
9f66327
Fix dual subdivision
verreld7 Sep 9, 2024
2fe9f38
Modify dual subdivisio to utilize weight vectors
verreld7 Sep 10, 2024
b07189d
Merge branch 'sagemath:develop' into dualsubdivision
verreld7 Sep 15, 2024
87cd7bc
Add more examples for dual subdivision
verreld7 Sep 18, 2024
d4c1251
Merge branch 'develop' into dualsubdivision
verreld7 Sep 21, 2024
204a525
Fix lint error
verreld7 Sep 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/doc/en/reference/references/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4651,6 +4651,9 @@ REFERENCES:
University Press, New York, 1995, With contributions
by A. Zelevinsky, Oxford Science Publications.

.. [Mac2015] Diane Maclagan and Bernd Sturmfels, *Introduction to
Tropical Geometry*, American Mathematical Society, 2015.

.. [MagmaHGM] *Hypergeometric motives* in Magma,
http://magma.maths.usyd.edu.au/~watkins/papers/HGM-chapter.pdf

Expand Down
199 changes: 194 additions & 5 deletions src/sage/rings/semirings/tropical_mpolynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
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

Expand Down Expand Up @@ -151,6 +149,23 @@ class TropicalMPolynomial(MPolynomial_polydict):
p1 = R(3)*a*b + a + R(-1)*b
sphinx_plot(p1.plot3d())

Another way to represent tropical curve is through dual subdivision,
which is a subdivision of Newton polytope of tropical polynomial::

sage: p1.Newton_polytope()
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices
sage: p1.dual_subdivision()
Polyhedral complex with 1 maximal cell

.. PLOT::
:width: 300 px

T = TropicalSemiring(QQ, use_min=False)
R = PolynomialRing(T, ('a,b'))
a, b = R.gen(), R.gen(1)
p1 = R(3)*a*b + a + R(-1)*b
sphinx_plot(p1.dual_subdivision().plot())

TESTS:

There is no subtraction defined for tropical polynomials::
Expand Down Expand Up @@ -285,7 +300,7 @@ def plot3d(self, color='random'):
T = self.parent().base()
R = self.base_ring().base_ring()

# Finding the point of curve that touch the edge of the axes
# Find the point of curve that touch the edge of the axes
for comp in tv.components():
if len(comp[1]) == 1:
valid_int = RealSet(comp[1][0])
Expand Down Expand Up @@ -359,7 +374,7 @@ def tropical_variety(self):
curve. For dimensions higher than two, it is referred to as a
tropical hypersurface.

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

EXAMPLES:

Expand Down Expand Up @@ -390,6 +405,180 @@ def tropical_variety(self):
return TropicalSurface(self)
return TropicalVariety(self)

def Newton_polytope(self):
"""
Return the Newton polytope of ``self``.

The Newton polytope is the convex hull of all the points
corresponding to the exponents of the monomials of tropical
polynomial.

OUTPUT: :class:`sage.geometry.polyhedron.constructor.Polyhedron`

EXAMPLES:

Newton polytope for a two-variable tropical polynomial::

sage: T = TropicalSemiring(QQ)
sage: R.<x,y> = PolynomialRing(T)
sage: p1 = x + y
sage: p1.Newton_polytope()
A 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices

.. PLOT::
:width: 300 px

T = TropicalSemiring(QQ)
R = PolynomialRing(T, ('x,y'))
x, y = R.gen(), R.gen(1)
p1 = x + y
sphinx_plot(p1.Newton_polytope().plot())

Newton polytope in three dimension::

sage: T = TropicalSemiring(QQ)
sage: R.<x,y,z> = PolynomialRing(T)
sage: p1 = x^2 + x*y*z + x + y + z + R(0)
sage: p1.Newton_polytope()
A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 5 vertices

.. PLOT::
:width: 300 px

T = TropicalSemiring(QQ)
R = PolynomialRing(T, ('x,y,z'))
x, y, z = R.gen(), R.gen(1), R.gen(2)
p1 = x**2 + x*y*z + x + y + z + R(0)
sphinx_plot(p1.Newton_polytope().plot())
"""
from sage.geometry.polyhedron.constructor import Polyhedron

exponents = self.exponents()
return Polyhedron(exponents)

def dual_subdivision(self):
"""
Return the dual subdivision of ``self``.

Dual subdivision refers to a specific decomposition of the
Newton polytope of a tropical polynomial. The term "dual" is
used in the sense that the combinatorial structure of the
tropical variety is reflected in the dual subdivision.
Specifically, vertices of the dual subdivision correspond to
the intersection of multiple components. Edges of the dual
subdivision correspond to the individual components.

OUTPUT: :class:`sage.geometry.polyhedral_complex.PolyhedralComplex`

EXAMPLES:

Dual subdivision of a tropical curve::

sage: T = TropicalSemiring(QQ, use_min=False)
sage: R.<x,y> = PolynomialRing(T)
sage: p1 = R(3) + R(2)*x + R(2)*y + R(3)*x*y + x^2 + y^2
sage: p1.dual_subdivision()
Polyhedral complex with 4 maximal cells

.. PLOT::
:width: 300 px

T = TropicalSemiring(QQ, use_min=False)
R = PolynomialRing(T, ('x,y'))
x, y = R.gen(), R.gen(1)
p1 = R(3) + R(2)*x + R(2)*y + R(3)*x*y + x**2 + y**2
sphinx_plot(p1.dual_subdivision().plot())

A subdivision of a pentagonal Newton polytope::

sage: p2 = R(3) + x^2 + R(-2)*y + R(1/2)*x^2*y + R(2)*x*y^3 + R(-1)*x^3*y^4
sage: p2.dual_subdivision()
Polyhedral complex with 5 maximal cells

.. PLOT::
:width: 300 px

T = TropicalSemiring(QQ, use_min=False)
R = PolynomialRing(T, ('x,y'))
x, y = R.gen(), R.gen(1)
p2 = R(3) + x**2 + R(-2)*y + R(1/2)*x**2*y + R(2)*x*y**3 + R(-1)*x**3*y**4
sphinx_plot(p2.dual_subdivision().plot())

A subdivision with many faces, not all of which are triangles::

sage: p3 = R(8) + R(4)*x + R(2)*y + R(1)*x^2 + x*y + R(1)*y^2 \
....: + R(2)*x^3 + x^2*y + x*y^2 + R(4)*y^3 + R(8)*x^4 \
....: + R(4)*x^3*y + x^2*y^2 + R(2)*x*y^3 + y^4
sage: p3.dual_subdivision().plot()
Graphics object consisting of 10 graphics primitives

.. PLOT::
:width: 300 px

T = TropicalSemiring(QQ, use_min=False)
R = PolynomialRing(T, ('x,y'))
x, y = R.gen(), R.gen(1)
p3 = R(8) + R(4)*x + R(2)*y + R(1)*x**2 + x*y + R(1)*y**2 \
+ R(2)*x**3 + x**2*y + x*y**2 + R(4)*y**3 + R(8)*x**4 \
+ R(4)*x**3*y + x**2*y**2 + R(2)*x*y**3 + y**4
sphinx_plot(p3.dual_subdivision().plot())

Dual subdivision of a tropical surface::

sage: T = TropicalSemiring(QQ)
sage: R.<x,y,z> = PolynomialRing(T)
sage: p1 = x + y + z + x^2 + R(1)
sage: p1.dual_subdivision()
Polyhedral complex with 7 maximal cells

.. PLOT::
:width: 300 px

T = TropicalSemiring(QQ, use_min=False)
R = PolynomialRing(T, ('x,y,z'))
x, y, z = R.gen(), R.gen(1), R.gen(2)
p1 = x + y + z + x**2 + R(1)
sphinx_plot(p1.dual_subdivision().plot())

Dual subdivision of a tropical hypersurface::

sage: T = TropicalSemiring(QQ)
sage: R.<a,b,c,d> = PolynomialRing(T)
sage: p1 = R(2)*a*b + R(3)*a*c + R(-1)*c^2 + R(-1/3)*a*d
sage: p1.dual_subdivision()
Polyhedral complex with 4 maximal cells
"""
from sage.geometry.polyhedron.constructor import Polyhedron
from sage.geometry.polyhedral_complex import PolyhedralComplex

TV = self.tropical_variety()
cycles = []

if TV.dimension() == 2:
for indices in TV._vertices_components().values():
cycle = []
for index in indices:
vertices = TV._keys[index[0]]
for v in vertices:
cycle.append(v)
cycles.append(cycle)
else:
line_comps = TV.weight_vectors()[1]
for indices in line_comps.values():
cycle = []
for index in indices:
vertices = TV._keys[index]
for v in vertices:
cycle.append(v)
cycles.append(cycle)

polyhedron_lst = []
for cycle in cycles:
polyhedron = Polyhedron(vertices=cycle)
polyhedron_lst.append(polyhedron)
pc = PolyhedralComplex(polyhedron_lst)
return pc

def _repr_(self):
r"""
Return string representation of ``self``.
Expand Down Expand Up @@ -595,7 +784,7 @@ def random_element(self, degree=2, terms=None, choose_degree=False,
r"""
Return a random multivariate tropical polynomial from ``self``.

OUTPUT: a :class:`TropicalMPolynomial`
OUTPUT: :class:`TropicalMPolynomial`

.. SEEALSO::

Expand Down
16 changes: 7 additions & 9 deletions src/sage/rings/semirings/tropical_polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
sage: R.<x> = PolynomialRing(T)
sage: x.parent()
Univariate Tropical Polynomial Semiring in x over Rational Field
sage: (x + R(3)*x) * (x^2 + x)
3*x^3 + 3*x^2
sage: (x^2 + R(1)*x + R(-1))^2
0*x^4 + 1*x^3 + 2*x^2 + 0*x + (-2)
sage: (x^2 + x + R(0))^2
0*x^4 + 0*x^3 + 0*x^2 + 0*x + 0

REFERENCES:

Expand Down Expand Up @@ -56,7 +54,7 @@ class TropicalPolynomial(Polynomial_generic_sparse):

EXAMPLES:

First, we construct a tropical polynomial semiring by defining a base
We construct a tropical polynomial semiring by defining a base
tropical semiring and then inputting it to :class:`PolynomialRing`::

sage: T = TropicalSemiring(QQ, use_min=False)
Expand Down Expand Up @@ -168,7 +166,7 @@ def roots(self):
Return the list of all tropical roots of ``self``, counted with
multiplicity.

OUTPUT: a list of tropical numbers
OUTPUT: A list of tropical numbers

ALGORITHM:

Expand Down Expand Up @@ -294,7 +292,7 @@ def factor(self):
`x + x_0` is `x_0` and not `-x_0`. However, not every tropical
polynomial can be factored.

OUTPUT: a :class:'Factorization'
OUTPUT: :class:'Factorization'

EXAMPLES::

Expand Down Expand Up @@ -800,7 +798,7 @@ def random_element(self, degree=(-1, 2), monic=False, *args, **kwds):
r"""
Return a random tropical polynomial of given degrees (bounds).

OUTPUT: a :class:`TropicalPolynomial`
OUTPUT: :class:`TropicalPolynomial`

.. SEEALSO::

Expand Down Expand Up @@ -875,7 +873,7 @@ def interpolation(self, points):

- ``points`` -- a list of tuples ``(x, y)``

OUTPUT: a :class:`TropicalPolynomial`
OUTPUT: :class:`TropicalPolynomial`

EXAMPLES::

Expand Down
Loading
Loading