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

Merged
merged 37 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
03fd6f4
Fix docstring based on review
verreld7 Oct 24, 2024
a05ec06
Fix docstring and weight_vectors
verreld7 Oct 25, 2024
1adcd0e
Add test to weight_vectors
verreld7 Oct 25, 2024
60aa804
Fix lint error
verreld7 Oct 25, 2024
f135107
Refactor code based on review
verreld7 Oct 29, 2024
c0aa966
Merge branch 'sagemath:develop' into dualsubdivision
verreld7 Oct 29, 2024
c3011eb
Merge branch 'sagemath:develop' into dualsubdivision
verreld7 Nov 5, 2024
3cfedc8
Add mark to long doctest
verreld7 Nov 5, 2024
5cf46b1
Add the data for newton polytope and dual subdivision
verreld7 Nov 6, 2024
220a0b9
Add example; update docstring
verreld7 Nov 10, 2024
99e8af5
Fix documentation
verreld7 Nov 11, 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 @@ -4699,6 +4699,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
270 changes: 264 additions & 6 deletions src/sage/rings/semirings/tropical_mpolynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,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 @@ -196,7 +213,7 @@ def subs(self, fixed=None, **kwds):
return self(tuple(variables))

def plot3d(self, color='random'):
"""
r"""
Return the 3d plot of ``self``.

Only implemented for tropical polynomial in two variables.
Expand Down Expand Up @@ -285,7 +302,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 +376,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,9 +407,250 @@ def tropical_variety(self):
return TropicalSurface(self)
return TropicalVariety(self)

def newton_polytope(self):
r"""
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: :func:`~sage.geometry.polyhedron.constructor.Polyhedron`

EXAMPLES:

A 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
tscrim marked this conversation as resolved.
Show resolved Hide resolved
sage: p1.newton_polytope().Vrepresentation()
(A vertex at (0, 1), A vertex at (1, 0))
sage: p1.newton_polytope().Hrepresentation()
(An equation (1, 1) x - 1 == 0,
An inequality (0, -1) x + 1 >= 0,
An inequality (0, 1) x + 0 >= 0)

.. 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())

A 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
sage: p1.newton_polytope().Vrepresentation()
(A vertex at (0, 0, 0),
A vertex at (0, 0, 1),
A vertex at (0, 1, 0),
A vertex at (2, 0, 0),
A vertex at (1, 1, 1))
sage: p1.newton_polytope().Hrepresentation()
(An inequality (0, 1, 0) x + 0 >= 0,
An inequality (0, 0, 1) x + 0 >= 0,
An inequality (1, 0, 0) x + 0 >= 0,
An inequality (1, -1, -1) x + 1 >= 0,
An inequality (-1, -2, 1) x + 2 >= 0,
An inequality (-1, 1, -2) x + 2 >= 0)

.. 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: pc = p1.dual_subdivision(); pc
Polyhedral complex with 4 maximal cells
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have it also display the maximal cell polytopes in this complex (with their explicit data) and also below.

sage: [p.Vrepresentation() for p in pc.maximal_cells_sorted()]
[(A vertex at (0, 0), A vertex at (0, 1), A vertex at (1, 1)),
(A vertex at (0, 0), A vertex at (1, 0), A vertex at (1, 1)),
(A vertex at (0, 1), A vertex at (0, 2), A vertex at (1, 1)),
(A vertex at (1, 0), A vertex at (1, 1), A vertex at (2, 0))]

.. 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: pc = p2.dual_subdivision(); pc
Polyhedral complex with 5 maximal cells
sage: [p.Vrepresentation() for p in pc.maximal_cells_sorted()]
[(A vertex at (0, 0), A vertex at (0, 1), A vertex at (1, 3)),
(A vertex at (0, 0), A vertex at (1, 3), A vertex at (2, 1)),
(A vertex at (0, 0), A vertex at (2, 0), A vertex at (2, 1)),
(A vertex at (1, 3), A vertex at (2, 1), A vertex at (3, 4)),
(A vertex at (2, 0), A vertex at (2, 1), A vertex at (3, 4))]

.. 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: T = TropicalSemiring(QQ)
sage: R.<x,y> = PolynomialRing(T)
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: pc = p3.dual_subdivision(); pc
Polyhedral complex with 10 maximal cells
sage: [p.Vrepresentation() for p in pc.maximal_cells_sorted()]
[(A vertex at (0, 0), A vertex at (0, 1), A vertex at (1, 0)),
(A vertex at (0, 1), A vertex at (0, 2), A vertex at (1, 1)),
(A vertex at (0, 1), A vertex at (1, 0), A vertex at (2, 0)),
(A vertex at (0, 1), A vertex at (1, 1), A vertex at (2, 0)),
(A vertex at (0, 2), A vertex at (0, 4), A vertex at (1, 1)),
(A vertex at (0, 4),
A vertex at (1, 1),
A vertex at (2, 1),
A vertex at (2, 2)),
(A vertex at (1, 1), A vertex at (2, 0), A vertex at (2, 1)),
(A vertex at (2, 0), A vertex at (2, 1), A vertex at (3, 0)),
(A vertex at (2, 1), A vertex at (2, 2), A vertex at (3, 0)),
(A vertex at (2, 2), A vertex at (3, 0), A vertex at (4, 0))]

.. PLOT::
:width: 300 px

T = TropicalSemiring(QQ)
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: pc = p1.dual_subdivision(); pc
Polyhedral complex with 7 maximal cells
sage: [p.Vrepresentation() for p in pc.maximal_cells_sorted()]
[(A vertex at (0, 0, 0), A vertex at (0, 0, 1), A vertex at (0, 1, 0)),
(A vertex at (0, 0, 0), A vertex at (0, 0, 1), A vertex at (1, 0, 0)),
(A vertex at (0, 0, 0), A vertex at (0, 1, 0), A vertex at (1, 0, 0)),
(A vertex at (0, 0, 1), A vertex at (0, 1, 0), A vertex at (1, 0, 0)),
(A vertex at (0, 0, 1), A vertex at (0, 1, 0), A vertex at (2, 0, 0)),
(A vertex at (0, 0, 1), A vertex at (1, 0, 0), A vertex at (2, 0, 0)),
(A vertex at (0, 1, 0), A vertex at (1, 0, 0), A vertex at (2, 0, 0))]

.. 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: pc = p1.dual_subdivision(); pc
Polyhedral complex with 4 maximal cells
sage: [p.Vrepresentation() for p in pc.maximal_cells_sorted()]
[(A vertex at (0, 0, 2, 0),
A vertex at (1, 0, 0, 1),
A vertex at (1, 0, 1, 0)),
(A vertex at (0, 0, 2, 0),
A vertex at (1, 0, 0, 1),
A vertex at (1, 1, 0, 0)),
(A vertex at (0, 0, 2, 0),
A vertex at (1, 0, 1, 0),
A vertex at (1, 1, 0, 0)),
(A vertex at (1, 0, 0, 1),
A vertex at (1, 0, 1, 0),
A vertex at (1, 1, 0, 0))]
"""
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``.
Return a string representation of ``self``.

EXAMPLES::

Expand All @@ -413,7 +671,7 @@ def _repr_(self):

def _latex_(self):
r"""
Return the latex representation of ``self``.
Return a latex representation of ``self``.

EXAMPLES::

Expand Down Expand Up @@ -595,7 +853,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
Loading
Loading