-
-
Notifications
You must be signed in to change notification settings - Fork 465
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
base: develop
Are you sure you want to change the base?
Changes from all commits
06841b5
6734319
8b8c5cc
5c9e8d1
010149c
3f1641a
4795639
a601cbd
2e8592c
96a0f4c
ec4307d
401ad51
792b829
dd2d14d
f20838a
f425552
4306750
3d05257
d2d211b
53f495e
9f66327
2fe9f38
b07189d
87cd7bc
d4c1251
204a525
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -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:: | ||||||||||||||||||
|
@@ -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]) | ||||||||||||||||||
|
@@ -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: | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -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` | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
EXAMPLES: | ||||||||||||||||||
|
||||||||||||||||||
Newton polytope for a two-variable tropical polynomial:: | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
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:: | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
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` | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
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 | ||||||||||||||||||
Comment on lines
+509
to
+511
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You can see in the built html doc the output is strange. Plus this is considered to be better practice. |
||||||||||||||||||
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()) | ||||||||||||||||||
Comment on lines
+521
to
+524
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
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``. | ||||||||||||||||||
|
@@ -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:: | ||||||||||||||||||
|
||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
Comment on lines
-14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change these tests? Why not just add the extra one? |
||
|
||
REFERENCES: | ||
|
||
|
@@ -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) | ||
|
@@ -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 | ||
Comment on lines
-171
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this as our style is (usually) starting with a lower case in this instance. |
||
|
||
ALGORITHM: | ||
|
||
|
@@ -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:: | ||
|
||
|
@@ -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:: | ||
|
||
|
@@ -875,7 +873,7 @@ def interpolation(self, points): | |
|
||
- ``points`` -- a list of tuples ``(x, y)`` | ||
|
||
OUTPUT: a :class:`TropicalPolynomial` | ||
OUTPUT: :class:`TropicalPolynomial` | ||
|
||
EXAMPLES:: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We follow Python's naming conventions, even when the words are proper nouns.