passagemath-polyhedra 10.6.37__cp314-cp314-musllinux_1_2_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. passagemath_polyhedra/__init__.py +3 -0
  2. passagemath_polyhedra-10.6.37.dist-info/METADATA +367 -0
  3. passagemath_polyhedra-10.6.37.dist-info/METADATA.bak +369 -0
  4. passagemath_polyhedra-10.6.37.dist-info/RECORD +209 -0
  5. passagemath_polyhedra-10.6.37.dist-info/WHEEL +5 -0
  6. passagemath_polyhedra-10.6.37.dist-info/top_level.txt +3 -0
  7. passagemath_polyhedra.libs/libgcc_s-0cd532bd.so.1 +0 -0
  8. passagemath_polyhedra.libs/libgmp-0e7fc84e.so.10.5.0 +0 -0
  9. passagemath_polyhedra.libs/libgomp-8949ffbe.so.1.0.0 +0 -0
  10. passagemath_polyhedra.libs/libstdc++-5d72f927.so.6.0.33 +0 -0
  11. sage/all__sagemath_polyhedra.py +50 -0
  12. sage/game_theory/all.py +8 -0
  13. sage/game_theory/catalog.py +6 -0
  14. sage/game_theory/catalog_normal_form_games.py +923 -0
  15. sage/game_theory/cooperative_game.py +844 -0
  16. sage/game_theory/matching_game.py +1181 -0
  17. sage/game_theory/normal_form_game.py +2697 -0
  18. sage/game_theory/parser.py +275 -0
  19. sage/geometry/all__sagemath_polyhedra.py +22 -0
  20. sage/geometry/cone.py +6940 -0
  21. sage/geometry/cone_catalog.py +847 -0
  22. sage/geometry/cone_critical_angles.py +1027 -0
  23. sage/geometry/convex_set.py +1119 -0
  24. sage/geometry/fan.py +3743 -0
  25. sage/geometry/fan_isomorphism.py +389 -0
  26. sage/geometry/fan_morphism.py +1884 -0
  27. sage/geometry/hasse_diagram.py +202 -0
  28. sage/geometry/hyperplane_arrangement/affine_subspace.py +390 -0
  29. sage/geometry/hyperplane_arrangement/all.py +1 -0
  30. sage/geometry/hyperplane_arrangement/arrangement.py +3905 -0
  31. sage/geometry/hyperplane_arrangement/check_freeness.py +145 -0
  32. sage/geometry/hyperplane_arrangement/hyperplane.py +773 -0
  33. sage/geometry/hyperplane_arrangement/library.py +825 -0
  34. sage/geometry/hyperplane_arrangement/ordered_arrangement.py +642 -0
  35. sage/geometry/hyperplane_arrangement/plot.py +520 -0
  36. sage/geometry/integral_points.py +35 -0
  37. sage/geometry/integral_points_generic_dense.cpython-314-x86_64-linux-musl.so +0 -0
  38. sage/geometry/integral_points_generic_dense.pyx +7 -0
  39. sage/geometry/lattice_polytope.py +5894 -0
  40. sage/geometry/linear_expression.py +773 -0
  41. sage/geometry/newton_polygon.py +767 -0
  42. sage/geometry/point_collection.cpython-314-x86_64-linux-musl.so +0 -0
  43. sage/geometry/point_collection.pyx +1008 -0
  44. sage/geometry/polyhedral_complex.py +2616 -0
  45. sage/geometry/polyhedron/all.py +8 -0
  46. sage/geometry/polyhedron/backend_cdd.py +460 -0
  47. sage/geometry/polyhedron/backend_cdd_rdf.py +231 -0
  48. sage/geometry/polyhedron/backend_field.py +347 -0
  49. sage/geometry/polyhedron/backend_normaliz.py +2503 -0
  50. sage/geometry/polyhedron/backend_number_field.py +168 -0
  51. sage/geometry/polyhedron/backend_polymake.py +765 -0
  52. sage/geometry/polyhedron/backend_ppl.py +582 -0
  53. sage/geometry/polyhedron/base.py +1206 -0
  54. sage/geometry/polyhedron/base0.py +1444 -0
  55. sage/geometry/polyhedron/base1.py +886 -0
  56. sage/geometry/polyhedron/base2.py +812 -0
  57. sage/geometry/polyhedron/base3.py +1845 -0
  58. sage/geometry/polyhedron/base4.py +1262 -0
  59. sage/geometry/polyhedron/base5.py +2700 -0
  60. sage/geometry/polyhedron/base6.py +1741 -0
  61. sage/geometry/polyhedron/base7.py +997 -0
  62. sage/geometry/polyhedron/base_QQ.py +1258 -0
  63. sage/geometry/polyhedron/base_RDF.py +98 -0
  64. sage/geometry/polyhedron/base_ZZ.py +934 -0
  65. sage/geometry/polyhedron/base_mutable.py +215 -0
  66. sage/geometry/polyhedron/base_number_field.py +122 -0
  67. sage/geometry/polyhedron/cdd_file_format.py +155 -0
  68. sage/geometry/polyhedron/combinatorial_polyhedron/all.py +1 -0
  69. sage/geometry/polyhedron/combinatorial_polyhedron/base.cpython-314-x86_64-linux-musl.so +0 -0
  70. sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd +76 -0
  71. sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx +3859 -0
  72. sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.cpython-314-x86_64-linux-musl.so +0 -0
  73. sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pxd +39 -0
  74. sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx +1038 -0
  75. sage/geometry/polyhedron/combinatorial_polyhedron/conversions.cpython-314-x86_64-linux-musl.so +0 -0
  76. sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pxd +9 -0
  77. sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx +501 -0
  78. sage/geometry/polyhedron/combinatorial_polyhedron/face_data_structure.pxd +207 -0
  79. sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.cpython-314-x86_64-linux-musl.so +0 -0
  80. sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pxd +102 -0
  81. sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx +2274 -0
  82. sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.cpython-314-x86_64-linux-musl.so +0 -0
  83. sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pxd +370 -0
  84. sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pyx +84 -0
  85. sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.cpython-314-x86_64-linux-musl.so +0 -0
  86. sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pxd +31 -0
  87. sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx +587 -0
  88. sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.cpython-314-x86_64-linux-musl.so +0 -0
  89. sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pxd +52 -0
  90. sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx +560 -0
  91. sage/geometry/polyhedron/constructor.py +773 -0
  92. sage/geometry/polyhedron/double_description.py +753 -0
  93. sage/geometry/polyhedron/double_description_inhomogeneous.py +564 -0
  94. sage/geometry/polyhedron/face.py +1060 -0
  95. sage/geometry/polyhedron/generating_function.py +1810 -0
  96. sage/geometry/polyhedron/lattice_euclidean_group_element.py +178 -0
  97. sage/geometry/polyhedron/library.py +3502 -0
  98. sage/geometry/polyhedron/misc.py +121 -0
  99. sage/geometry/polyhedron/modules/all.py +1 -0
  100. sage/geometry/polyhedron/modules/formal_polyhedra_module.py +155 -0
  101. sage/geometry/polyhedron/palp_database.py +447 -0
  102. sage/geometry/polyhedron/parent.py +1279 -0
  103. sage/geometry/polyhedron/plot.py +1986 -0
  104. sage/geometry/polyhedron/ppl_lattice_polygon.py +556 -0
  105. sage/geometry/polyhedron/ppl_lattice_polytope.py +1257 -0
  106. sage/geometry/polyhedron/representation.py +1723 -0
  107. sage/geometry/pseudolines.py +515 -0
  108. sage/geometry/relative_interior.py +445 -0
  109. sage/geometry/toric_plotter.py +1103 -0
  110. sage/geometry/triangulation/all.py +2 -0
  111. sage/geometry/triangulation/base.cpython-314-x86_64-linux-musl.so +0 -0
  112. sage/geometry/triangulation/base.pyx +963 -0
  113. sage/geometry/triangulation/data.h +147 -0
  114. sage/geometry/triangulation/data.pxd +4 -0
  115. sage/geometry/triangulation/element.py +914 -0
  116. sage/geometry/triangulation/functions.h +10 -0
  117. sage/geometry/triangulation/functions.pxd +4 -0
  118. sage/geometry/triangulation/point_configuration.py +2256 -0
  119. sage/geometry/triangulation/triangulations.h +49 -0
  120. sage/geometry/triangulation/triangulations.pxd +7 -0
  121. sage/geometry/voronoi_diagram.py +319 -0
  122. sage/interfaces/all__sagemath_polyhedra.py +1 -0
  123. sage/interfaces/polymake.py +2028 -0
  124. sage/numerical/all.py +13 -0
  125. sage/numerical/all__sagemath_polyhedra.py +11 -0
  126. sage/numerical/backends/all.py +1 -0
  127. sage/numerical/backends/all__sagemath_polyhedra.py +1 -0
  128. sage/numerical/backends/cvxopt_backend.cpython-314-x86_64-linux-musl.so +0 -0
  129. sage/numerical/backends/cvxopt_backend.pyx +1006 -0
  130. sage/numerical/backends/cvxopt_backend_test.py +19 -0
  131. sage/numerical/backends/cvxopt_sdp_backend.cpython-314-x86_64-linux-musl.so +0 -0
  132. sage/numerical/backends/cvxopt_sdp_backend.pyx +382 -0
  133. sage/numerical/backends/cvxpy_backend.cpython-314-x86_64-linux-musl.so +0 -0
  134. sage/numerical/backends/cvxpy_backend.pxd +41 -0
  135. sage/numerical/backends/cvxpy_backend.pyx +934 -0
  136. sage/numerical/backends/cvxpy_backend_test.py +13 -0
  137. sage/numerical/backends/generic_backend_test.py +24 -0
  138. sage/numerical/backends/interactivelp_backend.cpython-314-x86_64-linux-musl.so +0 -0
  139. sage/numerical/backends/interactivelp_backend.pxd +36 -0
  140. sage/numerical/backends/interactivelp_backend.pyx +1231 -0
  141. sage/numerical/backends/interactivelp_backend_test.py +12 -0
  142. sage/numerical/backends/logging_backend.py +391 -0
  143. sage/numerical/backends/matrix_sdp_backend.cpython-314-x86_64-linux-musl.so +0 -0
  144. sage/numerical/backends/matrix_sdp_backend.pxd +15 -0
  145. sage/numerical/backends/matrix_sdp_backend.pyx +478 -0
  146. sage/numerical/backends/ppl_backend.cpython-314-x86_64-linux-musl.so +0 -0
  147. sage/numerical/backends/ppl_backend.pyx +1126 -0
  148. sage/numerical/backends/ppl_backend_test.py +13 -0
  149. sage/numerical/backends/scip_backend.cpython-314-x86_64-linux-musl.so +0 -0
  150. sage/numerical/backends/scip_backend.pxd +22 -0
  151. sage/numerical/backends/scip_backend.pyx +1289 -0
  152. sage/numerical/backends/scip_backend_test.py +13 -0
  153. sage/numerical/interactive_simplex_method.py +5338 -0
  154. sage/numerical/knapsack.py +665 -0
  155. sage/numerical/linear_functions.cpython-314-x86_64-linux-musl.so +0 -0
  156. sage/numerical/linear_functions.pxd +31 -0
  157. sage/numerical/linear_functions.pyx +1648 -0
  158. sage/numerical/linear_tensor.py +470 -0
  159. sage/numerical/linear_tensor_constraints.py +448 -0
  160. sage/numerical/linear_tensor_element.cpython-314-x86_64-linux-musl.so +0 -0
  161. sage/numerical/linear_tensor_element.pxd +6 -0
  162. sage/numerical/linear_tensor_element.pyx +459 -0
  163. sage/numerical/mip.cpython-314-x86_64-linux-musl.so +0 -0
  164. sage/numerical/mip.pxd +40 -0
  165. sage/numerical/mip.pyx +3667 -0
  166. sage/numerical/sdp.cpython-314-x86_64-linux-musl.so +0 -0
  167. sage/numerical/sdp.pxd +39 -0
  168. sage/numerical/sdp.pyx +1433 -0
  169. sage/rings/all__sagemath_polyhedra.py +3 -0
  170. sage/rings/polynomial/all__sagemath_polyhedra.py +10 -0
  171. sage/rings/polynomial/omega.py +982 -0
  172. sage/schemes/all__sagemath_polyhedra.py +2 -0
  173. sage/schemes/toric/all.py +10 -0
  174. sage/schemes/toric/chow_group.py +1248 -0
  175. sage/schemes/toric/divisor.py +2082 -0
  176. sage/schemes/toric/divisor_class.cpython-314-x86_64-linux-musl.so +0 -0
  177. sage/schemes/toric/divisor_class.pyx +322 -0
  178. sage/schemes/toric/fano_variety.py +1606 -0
  179. sage/schemes/toric/homset.py +650 -0
  180. sage/schemes/toric/ideal.py +451 -0
  181. sage/schemes/toric/library.py +1322 -0
  182. sage/schemes/toric/morphism.py +1958 -0
  183. sage/schemes/toric/points.py +1032 -0
  184. sage/schemes/toric/sheaf/all.py +1 -0
  185. sage/schemes/toric/sheaf/constructor.py +302 -0
  186. sage/schemes/toric/sheaf/klyachko.py +921 -0
  187. sage/schemes/toric/toric_subscheme.py +905 -0
  188. sage/schemes/toric/variety.py +3460 -0
  189. sage/schemes/toric/weierstrass.py +1078 -0
  190. sage/schemes/toric/weierstrass_covering.py +457 -0
  191. sage/schemes/toric/weierstrass_higher.py +288 -0
  192. sage_wheels/share/reflexive_polytopes/Full2d/zzdb.info +10 -0
  193. sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v03 +0 -0
  194. sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v04 +0 -0
  195. sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v05 +1 -0
  196. sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v06 +1 -0
  197. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.info +22 -0
  198. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v04 +0 -0
  199. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v05 +0 -0
  200. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v06 +0 -0
  201. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v07 +0 -0
  202. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v08 +0 -0
  203. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v09 +0 -0
  204. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v10 +0 -0
  205. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v11 +1 -0
  206. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v12 +1 -0
  207. sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v13 +1 -0
  208. sage_wheels/share/reflexive_polytopes/reflexive_polytopes_2d +80 -0
  209. sage_wheels/share/reflexive_polytopes/reflexive_polytopes_3d +37977 -0
@@ -0,0 +1,767 @@
1
+ # sage_setup: distribution = sagemath-polyhedra
2
+ """
3
+ Newton Polygons
4
+
5
+ This module implements finite Newton polygons and
6
+ infinite Newton polygons having a finite number of
7
+ slopes (and hence a last infinite slope).
8
+ """
9
+
10
+ #############################################################################
11
+ # Copyright (C) 2013 Xavier Caruso <xavier.caruso@normalesup.org>
12
+ #
13
+ # Distributed under the terms of the GNU General Public License (GPL)
14
+ #
15
+ # https://www.gnu.org/licenses/
16
+ #############################################################################
17
+
18
+ import sage.geometry.abc
19
+
20
+ from sage.structure.unique_representation import UniqueRepresentation
21
+ from sage.structure.parent import Parent
22
+ from sage.structure.element import Element
23
+ from sage.structure.richcmp import op_EQ, op_NE, op_LE, op_GE, op_LT
24
+ from sage.misc.cachefunc import cached_method
25
+
26
+ from sage.rings.infinity import Infinity
27
+ from sage.geometry.polyhedron.constructor import Polyhedron
28
+
29
+
30
+ class NewtonPolygon_element(Element):
31
+ """
32
+ Class for infinite Newton polygons with last slope.
33
+ """
34
+ def __init__(self, polyhedron, parent):
35
+ """
36
+ Initialize a Newton polygon.
37
+
38
+ INPUT:
39
+
40
+ - ``polyhedron`` -- a polyhedron defining the Newton polygon
41
+
42
+ TESTS::
43
+
44
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
45
+ sage: NewtonPolygon([ (0,0), (1,1), (3,5) ])
46
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5)
47
+
48
+ sage: NewtonPolygon([ (0,0), (1,1), (2,8), (3,5) ], last_slope=3)
49
+ Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5)
50
+ ending by an infinite line of slope 3
51
+
52
+ ::
53
+
54
+ sage: TestSuite(NewtonPolygon).run()
55
+ """
56
+ Element.__init__(self, parent)
57
+ self._polyhedron = polyhedron
58
+ self._vertices = None
59
+ if polyhedron.is_mutable():
60
+ polyhedron._add_dependent_object(self)
61
+
62
+ def _repr_(self) -> str:
63
+ """
64
+ Return a string representation of this Newton polygon.
65
+
66
+ EXAMPLES::
67
+
68
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
69
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (2,5) ]); NP
70
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 5)
71
+
72
+ sage: NP._repr_()
73
+ 'Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 5)'
74
+ """
75
+ vertices = self.vertices()
76
+ length = len(vertices)
77
+ if self.last_slope() is Infinity:
78
+ if length == 0:
79
+ return "Empty Newton polygon"
80
+ if length == 1:
81
+ return "Finite Newton polygon with 1 vertex: %s" % str(vertices[0])
82
+ return "Finite Newton polygon with %s vertices: %s" % (length, str(vertices)[1:-1])
83
+
84
+ if length == 1:
85
+ return "Newton Polygon consisting of a unique infinite line of slope %s starting at %s" % (self.last_slope(), str(vertices[0]))
86
+ else:
87
+ return "Infinite Newton polygon with %s vertices: %s ending by an infinite line of slope %s" % (length, str(vertices)[1:-1], self.last_slope())
88
+
89
+ def vertices(self, copy=True) -> list:
90
+ """
91
+ Return the list of vertices of this Newton polygon.
92
+
93
+ INPUT:
94
+
95
+ - ``copy`` -- boolean (default: ``True``)
96
+
97
+ OUTPUT: the list of vertices of this Newton polygon (or a copy of it
98
+ if ``copy`` is set to ``True``)
99
+
100
+ EXAMPLES::
101
+
102
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
103
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (2,5) ]); NP
104
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 5)
105
+
106
+ sage: v = NP.vertices(); v
107
+ [(0, 0), (1, 1), (2, 5)]
108
+
109
+ TESTS::
110
+
111
+ sage: del v[0]
112
+ sage: v
113
+ [(1, 1), (2, 5)]
114
+ sage: NP.vertices()
115
+ [(0, 0), (1, 1), (2, 5)]
116
+ """
117
+ if self._vertices is None:
118
+ self._vertices = [tuple(v) for v in self._polyhedron.vertices()]
119
+ self._vertices.sort()
120
+ if copy:
121
+ return list(self._vertices)
122
+ else:
123
+ return self._vertices
124
+
125
+ @cached_method
126
+ def last_slope(self):
127
+ """
128
+ Return the last (infinite) slope of this Newton polygon
129
+ if it is infinite and ``+Infinity`` otherwise.
130
+
131
+ EXAMPLES::
132
+
133
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
134
+ sage: NP1 = NewtonPolygon([ (0,0), (1,1), (2,8), (3,5) ], last_slope=3)
135
+ sage: NP1.last_slope()
136
+ 3
137
+
138
+ sage: NP2 = NewtonPolygon([ (0,0), (1,1), (2,5) ])
139
+ sage: NP2.last_slope()
140
+ +Infinity
141
+
142
+ We check that the last slope of a sum (resp. a product) is the
143
+ minimum of the last slopes of the summands (resp. the factors)::
144
+
145
+ sage: (NP1 + NP2).last_slope()
146
+ 3
147
+ sage: (NP1 * NP2).last_slope()
148
+ 3
149
+ """
150
+ rays = self._polyhedron.rays()
151
+ for r in rays:
152
+ if r[0] > 0:
153
+ return r[1]/r[0]
154
+ return Infinity
155
+
156
+ def slopes(self, repetition=True) -> list:
157
+ """
158
+ Return the slopes of this Newton polygon.
159
+
160
+ INPUT:
161
+
162
+ - ``repetition`` -- boolean (default: ``True``)
163
+
164
+ OUTPUT:
165
+
166
+ The consecutive slopes (not including the last slope
167
+ if the polygon is infinity) of this Newton polygon.
168
+
169
+ If ``repetition`` is ``True``, each slope is repeated a number of
170
+ times equal to its length. Otherwise, it appears only one time.
171
+
172
+ EXAMPLES::
173
+
174
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
175
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (3,6) ]); NP
176
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 6)
177
+
178
+ sage: NP.slopes()
179
+ [1, 5/2, 5/2]
180
+
181
+ sage: NP.slopes(repetition=False)
182
+ [1, 5/2]
183
+ """
184
+ slopes = []
185
+ vertices = self.vertices(copy=False)
186
+ for i in range(1, len(vertices)):
187
+ dx = vertices[i][0] - vertices[i-1][0]
188
+ dy = vertices[i][1] - vertices[i-1][1]
189
+ slope = dy/dx
190
+ if repetition:
191
+ slopes.extend(dx * [slope])
192
+ else:
193
+ slopes.append(slope)
194
+ return slopes
195
+
196
+ def _add_(self, other):
197
+ """
198
+ Return the convex hull of ``self`` and ``other``.
199
+
200
+ INPUT:
201
+
202
+ - ``other`` -- a Newton polygon
203
+
204
+ OUTPUT:
205
+
206
+ the Newton polygon, which is the convex hull of this Newton polygon
207
+ and ``other``
208
+
209
+ EXAMPLES::
210
+
211
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
212
+ sage: NP1 = NewtonPolygon([ (0,0), (1,1), (2,6) ]); NP1
213
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 6)
214
+ sage: NP2 = NewtonPolygon([ (0,0), (1,3/2) ], last_slope=2); NP2
215
+ Infinite Newton polygon with 2 vertices: (0, 0), (1, 3/2)
216
+ ending by an infinite line of slope 2
217
+
218
+ sage: NP1 + NP2
219
+ Infinite Newton polygon with 2 vertices: (0, 0), (1, 1)
220
+ ending by an infinite line of slope 2
221
+ """
222
+ polyhedron = self._polyhedron.convex_hull(other._polyhedron)
223
+ return self.parent()(polyhedron)
224
+
225
+ def _mul_(self, other):
226
+ """
227
+ Return the Minkowski sum of ``self`` and ``other``.
228
+
229
+ INPUT:
230
+
231
+ - ``other`` -- a Newton polygon
232
+
233
+ OUTPUT:
234
+
235
+ the Newton polygon, which is the Minkowski sum of this Newton polygon
236
+ and ``other``
237
+
238
+ .. NOTE::
239
+
240
+ If ``self`` and ``other`` are respective Newton polygons
241
+ of some polynomials `f` and `g` the self*other is the
242
+ Newton polygon of the product `fg`
243
+
244
+ EXAMPLES::
245
+
246
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
247
+ sage: NP1 = NewtonPolygon([ (0,0), (1,1), (2,6) ]); NP1
248
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 6)
249
+ sage: NP2 = NewtonPolygon([ (0,0), (1,3/2) ], last_slope=2); NP2
250
+ Infinite Newton polygon with 2 vertices: (0, 0), (1, 3/2)
251
+ ending by an infinite line of slope 2
252
+
253
+ sage: NP = NP1 * NP2; NP
254
+ Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 5/2)
255
+ ending by an infinite line of slope 2
256
+
257
+ The slopes of ``NP`` is the union of those of ``NP1`` and
258
+ those of ``NP2`` which are less than the last slope::
259
+
260
+ sage: NP1.slopes()
261
+ [1, 5]
262
+ sage: NP2.slopes()
263
+ [3/2]
264
+ sage: NP.slopes()
265
+ [1, 3/2]
266
+ """
267
+ polyhedron = self._polyhedron.minkowski_sum(other._polyhedron)
268
+ return self.parent()(polyhedron)
269
+
270
+ def __pow__(self, exp, ignored=None):
271
+ """
272
+ Return ``self`` dilated by ``exp``.
273
+
274
+ INPUT:
275
+
276
+ - ``exp`` -- positive integer
277
+
278
+ OUTPUT: this Newton polygon scaled by a factor ``exp``
279
+
280
+ .. NOTE::
281
+
282
+ If ``self`` is the Newton polygon of a polynomial `f`, then
283
+ ``self^exp`` is the Newton polygon of `f^{exp}`.
284
+
285
+ EXAMPLES::
286
+
287
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
288
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (2,6) ]); NP
289
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 6)
290
+
291
+ sage: NP^10
292
+ Finite Newton polygon with 3 vertices: (0, 0), (10, 10), (20, 60)
293
+ """
294
+ polyhedron = self._polyhedron.dilation(exp)
295
+ return self.parent()(polyhedron)
296
+
297
+ def __lshift__(self, i):
298
+ """
299
+ Return ``self`` shifted by `(0,i)`.
300
+
301
+ INPUT:
302
+
303
+ - ``i`` -- a rational number
304
+
305
+ OUTPUT: this Newton polygon shifted by the vector `(0,i)`
306
+
307
+ EXAMPLES::
308
+
309
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
310
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (2,6) ]); NP
311
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 6)
312
+
313
+ sage: NP << 2
314
+ Finite Newton polygon with 3 vertices: (0, 2), (1, 3), (2, 8)
315
+ """
316
+ polyhedron = self._polyhedron.translation((0, i))
317
+ return self.parent()(polyhedron)
318
+
319
+ def __rshift__(self, i):
320
+ """
321
+ Return ``self`` shifted by `(0,-i)`.
322
+
323
+ INPUT:
324
+
325
+ - ``i`` -- a rational number
326
+
327
+ OUTPUT: this Newton polygon shifted by the vector `(0,-i)`
328
+
329
+ EXAMPLES::
330
+
331
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
332
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (2,6) ]); NP
333
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 6)
334
+
335
+ sage: NP >> 2
336
+ Finite Newton polygon with 3 vertices: (0, -2), (1, -1), (2, 4)
337
+ """
338
+ polyhedron = self._polyhedron.translation((0, -i))
339
+ return self.parent()(polyhedron)
340
+
341
+ def __call__(self, x):
342
+ """
343
+ Return `self(x)`.
344
+
345
+ INPUT:
346
+
347
+ - ``x`` -- a real number
348
+
349
+ OUTPUT: the value of this Newton polygon at abscissa `x`
350
+
351
+ EXAMPLES::
352
+
353
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
354
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (3,6) ]); NP
355
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 6)
356
+
357
+ sage: [ NP(i) for i in range(4) ]
358
+ [0, 1, 7/2, 6]
359
+ """
360
+ # complexity: O(log(n))
361
+ vertices = self.vertices()
362
+ lastslope = self.last_slope()
363
+ if len(vertices) == 0 or x < vertices[0][0]:
364
+ return Infinity
365
+ if x == vertices[0][0]:
366
+ return vertices[0][1]
367
+ if x == vertices[-1][0]:
368
+ return vertices[-1][1]
369
+ if x > vertices[-1][0]:
370
+ return vertices[-1][1] + lastslope * (x - vertices[-1][0])
371
+ a = 0
372
+ b = len(vertices)
373
+ while b - a > 1:
374
+ c = (a + b) // 2
375
+ if vertices[c][0] < x:
376
+ a = c
377
+ else:
378
+ b = c
379
+ xg, yg = vertices[a]
380
+ xd, yd = vertices[b]
381
+ return ((x-xg)*yd + (xd-x)*yg) / (xd-xg)
382
+
383
+ def _richcmp_(self, other, op) -> bool:
384
+ r"""
385
+ Comparisons of two Newton polygons.
386
+
387
+ TESTS::
388
+
389
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
390
+
391
+ sage: NP1 = NewtonPolygon([ (0,0), (1,1), (3,6) ])
392
+ sage: NP2 = NewtonPolygon([ (0,0), (1,1), (2,6), (3,6) ])
393
+ sage: NP1 == NP2
394
+ True
395
+ sage: NP1 != NP2
396
+ False
397
+
398
+ sage: NP1 >= NP1 and NP2 >= NP2
399
+ True
400
+ sage: NP1 > NP1 or NP2 > NP2
401
+ False
402
+
403
+ sage: NP1 = NewtonPolygon([ (0,0), (1,1), (2,6) ])
404
+ sage: NP2 = NewtonPolygon([ (0,0), (1,3/2) ], last_slope=2)
405
+ sage: NP3 = NP1 + NP2
406
+
407
+ sage: NP1 <= NP2
408
+ False
409
+ sage: NP3 <= NP1
410
+ True
411
+ sage: NP3 <= NP2
412
+ True
413
+
414
+ sage: NP1 < NP1
415
+ False
416
+ sage: NP1 < NP2
417
+ False
418
+
419
+ sage: NP1 >= NP2
420
+ False
421
+
422
+ sage: NP1 >= NP3
423
+ True
424
+
425
+ sage: NP1 > NP1
426
+ False
427
+ sage: NP1 > NP2
428
+ False
429
+
430
+ sage: NP1 >= NP3 and NP2 >= NP3 and NP3 <= NP1 and NP3 <= NP2
431
+ True
432
+ sage: NP1 > NP3 and NP2 > NP3
433
+ True
434
+ sage: NP3 < NP2 and NP3 < NP1
435
+ True
436
+ """
437
+ if self._polyhedron == other._polyhedron:
438
+ return op == op_EQ or op == op_LE or op == op_GE
439
+ elif op == op_NE:
440
+ return True
441
+ elif op == op_EQ:
442
+ return False
443
+
444
+ if op == op_LT or op == op_LE:
445
+ if self.last_slope() > other.last_slope():
446
+ return False
447
+ return all(v in self._polyhedron for v in other.vertices())
448
+
449
+ else:
450
+ if self.last_slope() < other.last_slope():
451
+ return False
452
+ return all(v in other._polyhedron for v in self.vertices())
453
+
454
+ def plot(self, **kwargs):
455
+ """
456
+ Plot this Newton polygon.
457
+
458
+ .. NOTE::
459
+
460
+ All usual rendering options (color, thickness, etc.) are available.
461
+
462
+ EXAMPLES::
463
+
464
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
465
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (2,6) ])
466
+ sage: polygon = NP.plot() # needs sage.plot
467
+ """
468
+ vertices = self.vertices()
469
+ if len(vertices) == 0:
470
+ from sage.plot.graphics import Graphics
471
+ return Graphics()
472
+
473
+ from sage.plot.line import line
474
+ xstart, ystart = vertices[0]
475
+ xend, yend = vertices[-1]
476
+ if self.last_slope() is Infinity:
477
+ return line([(xstart, ystart+1), (xstart, ystart+0.5)],
478
+ linestyle='--', **kwargs) \
479
+ + line([(xstart, ystart+0.5)] + vertices
480
+ + [(xend, yend+0.5)], **kwargs) \
481
+ + line([(xend, yend+0.5), (xend, yend+1)],
482
+ linestyle='--', **kwargs)
483
+ else:
484
+ return line([(xstart, ystart+1), (xstart, ystart+0.5)],
485
+ linestyle='--', **kwargs) \
486
+ + line([(xstart, ystart+0.5)] + vertices
487
+ + [(xend+0.5, yend + 0.5*self.last_slope())], **kwargs) \
488
+ + line([(xend+0.5, yend + 0.5*self.last_slope()), (xend+1, yend+self.last_slope())],
489
+ linestyle='--', **kwargs)
490
+
491
+ def reverse(self, degree=None):
492
+ r"""
493
+ Return the symmetric of ``self``.
494
+
495
+ INPUT:
496
+
497
+ - ``degree`` -- integer (default: the top right abscissa of
498
+ this Newton polygon)
499
+
500
+ OUTPUT:
501
+
502
+ The image this Newton polygon under the symmetry
503
+ '(x,y) \mapsto (degree-x, y)`.
504
+
505
+ EXAMPLES::
506
+
507
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
508
+ sage: NP = NewtonPolygon([ (0,0), (1,1), (2,5) ])
509
+ sage: NP2 = NP.reverse(); NP2
510
+ Finite Newton polygon with 3 vertices: (0, 5), (1, 1), (2, 0)
511
+
512
+ We check that the slopes of the symmetric Newton polygon are
513
+ the opposites of the slopes of the original Newton polygon::
514
+
515
+ sage: NP.slopes()
516
+ [1, 4]
517
+ sage: NP2.slopes()
518
+ [-4, -1]
519
+ """
520
+ if self.last_slope() is not Infinity:
521
+ raise ValueError("Can only reverse *finite* Newton polygons")
522
+ if degree is None:
523
+ degree = self.vertices()[-1][0]
524
+ vertices = [(degree - x, y) for x, y in self.vertices()]
525
+ vertices.reverse()
526
+ parent = self.parent()
527
+ polyhedron = Polyhedron(base_ring=parent.base_ring(),
528
+ vertices=vertices, rays=[(0, 1)])
529
+ return parent(polyhedron)
530
+
531
+
532
+ class ParentNewtonPolygon(Parent, UniqueRepresentation):
533
+ r"""
534
+ Construct a Newton polygon.
535
+
536
+ INPUT:
537
+
538
+ - ``arg`` -- list/tuple/iterable of vertices or of
539
+ slopes. Currently, slopes must be rational numbers
540
+
541
+ - ``sort_slopes`` -- boolean (default: ``True``); whether slopes must be
542
+ first sorted
543
+
544
+ - ``last_slope`` -- rational or infinity (default:
545
+ ``Infinity``); the last slope of the Newton polygon
546
+
547
+ OUTPUT: the corresponding Newton polygon
548
+
549
+ .. NOTE::
550
+
551
+ By convention, a Newton polygon always contains the point
552
+ at infinity `(0, \infty)`. These polygons are attached to
553
+ polynomials or series over discrete valuation rings (e.g. padics).
554
+
555
+ EXAMPLES:
556
+
557
+ We specify here a Newton polygon by its vertices::
558
+
559
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
560
+ sage: NewtonPolygon([ (0,0), (1,1), (3,5) ])
561
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5)
562
+
563
+ We note that the convex hull of the vertices is automatically
564
+ computed::
565
+
566
+ sage: NewtonPolygon([ (0,0), (1,1), (2,8), (3,5) ])
567
+ Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5)
568
+
569
+ Note that the value ``+Infinity`` is allowed as the second coordinate
570
+ of a vertex::
571
+
572
+ sage: NewtonPolygon([ (0,0), (1,Infinity), (2,8), (3,5) ])
573
+ Finite Newton polygon with 2 vertices: (0, 0), (3, 5)
574
+
575
+ If last_slope is set, the returned Newton polygon is infinite
576
+ and ends with an infinite line having the specified slope::
577
+
578
+ sage: NewtonPolygon([ (0,0), (1,1), (2,8), (3,5) ], last_slope=3)
579
+ Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5)
580
+ ending by an infinite line of slope 3
581
+
582
+ Specifying a last slope may discard some vertices::
583
+
584
+ sage: NewtonPolygon([ (0,0), (1,1), (2,8), (3,5) ], last_slope=3/2)
585
+ Infinite Newton polygon with 2 vertices: (0, 0), (1, 1)
586
+ ending by an infinite line of slope 3/2
587
+
588
+ Next, we define a Newton polygon by its slopes::
589
+
590
+ sage: NP = NewtonPolygon([0, 1/2, 1/2, 2/3, 2/3, 2/3, 1, 1])
591
+ sage: NP
592
+ Finite Newton polygon with 5 vertices: (0, 0), (1, 0), (3, 1), (6, 3), (8, 5)
593
+ sage: NP.slopes()
594
+ [0, 1/2, 1/2, 2/3, 2/3, 2/3, 1, 1]
595
+
596
+ By default, slopes are automatically sorted::
597
+
598
+ sage: NP2 = NewtonPolygon([0, 1, 1/2, 2/3, 1/2, 2/3, 1, 2/3])
599
+ sage: NP2
600
+ Finite Newton polygon with 5 vertices: (0, 0), (1, 0), (3, 1), (6, 3), (8, 5)
601
+ sage: NP == NP2
602
+ True
603
+
604
+ except if the contrary is explicitly mentioned::
605
+
606
+ sage: NewtonPolygon([0, 1, 1/2, 2/3, 1/2, 2/3, 1, 2/3], sort_slopes=False)
607
+ Finite Newton polygon with 4 vertices: (0, 0), (1, 0), (6, 10/3), (8, 5)
608
+
609
+ Slopes greater that or equal last_slope (if specified) are discarded::
610
+
611
+ sage: NP = NewtonPolygon([0, 1/2, 1/2, 2/3, 2/3, 2/3, 1, 1], last_slope=2/3)
612
+ sage: NP
613
+ Infinite Newton polygon with 3 vertices: (0, 0), (1, 0), (3, 1)
614
+ ending by an infinite line of slope 2/3
615
+ sage: NP.slopes()
616
+ [0, 1/2, 1/2]
617
+
618
+ Be careful, do not confuse Newton polygons provided by this class
619
+ with Newton polytopes. Compare::
620
+
621
+ sage: NP = NewtonPolygon([ (0,0), (1,45), (3,6) ]); NP
622
+ Finite Newton polygon with 2 vertices: (0, 0), (3, 6)
623
+
624
+ sage: x, y = polygen(QQ,'x, y')
625
+ sage: p = 1 + x*y**45 + x**3*y**6
626
+ sage: p.newton_polytope()
627
+ A 2-dimensional polyhedron in ZZ^2 defined as the convex hull
628
+ of 3 vertices
629
+ sage: p.newton_polytope().vertices()
630
+ (A vertex at (0, 0), A vertex at (1, 45), A vertex at (3, 6))
631
+ """
632
+
633
+ Element = NewtonPolygon_element
634
+
635
+ def __init__(self) -> None:
636
+ """
637
+ Parent class for all Newton polygons.
638
+
639
+ EXAMPLES::
640
+
641
+ sage: from sage.geometry.newton_polygon import ParentNewtonPolygon
642
+ sage: ParentNewtonPolygon()
643
+ Parent for Newton polygons
644
+
645
+ TESTS:
646
+
647
+ This class is a singleton::
648
+
649
+ sage: ParentNewtonPolygon() is ParentNewtonPolygon()
650
+ True
651
+
652
+ ::
653
+
654
+ sage: TestSuite(ParentNewtonPolygon()).run()
655
+ """
656
+ from sage.categories.semirings import Semirings
657
+ from sage.rings.rational_field import QQ
658
+ Parent.__init__(self, category=Semirings(), base=QQ)
659
+
660
+ def _repr_(self) -> str:
661
+ """
662
+ Return the string representation of this parent,
663
+ which is ``Parent for Newton polygons``.
664
+
665
+ TESTS::
666
+
667
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
668
+ sage: NewtonPolygon
669
+ Parent for Newton polygons
670
+
671
+ sage: NewtonPolygon._repr_()
672
+ 'Parent for Newton polygons'
673
+ """
674
+ return "Parent for Newton polygons"
675
+
676
+ def _an_element_(self):
677
+ """
678
+ Return a Newton polygon (which is the empty one).
679
+
680
+ TESTS::
681
+
682
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
683
+ sage: NewtonPolygon._an_element_()
684
+ Empty Newton polygon
685
+ """
686
+ return self(Polyhedron(base_ring=self.base_ring(), ambient_dim=2))
687
+
688
+ def _element_constructor_(self, arg, sort_slopes=True,
689
+ last_slope=Infinity):
690
+ r"""
691
+ INPUT:
692
+
693
+ - ``arg`` -- an argument describing the Newton polygon
694
+
695
+ - ``sort_slopes`` -- boolean (default: ``True``); whether
696
+ slopes must be first sorted
697
+
698
+ - ``last_slope`` -- rational or infinity (default:
699
+ ``Infinity``). The last slope of the Newton polygon
700
+
701
+ The first argument ``arg`` can be either:
702
+
703
+ - a polyhedron in `\QQ^2`
704
+
705
+ - the element ``0`` (corresponding to the empty Newton polygon)
706
+
707
+ - the element ``1`` (corresponding to the Newton polygon of the
708
+ constant polynomial equal to 1)
709
+
710
+ - a list/tuple/iterable of vertices
711
+
712
+ - a list/tuple/iterable of slopes
713
+
714
+ OUTPUT: the corresponding Newton polygon
715
+
716
+ For more informations, see :class:`ParentNewtonPolygon`.
717
+
718
+ TESTS:
719
+
720
+ sage: from sage.geometry.newton_polygon import NewtonPolygon
721
+ sage: NewtonPolygon(0)
722
+ Empty Newton polygon
723
+ sage: NewtonPolygon(1)
724
+ Finite Newton polygon with 1 vertex: (0, 0)
725
+ """
726
+ if isinstance(arg, sage.geometry.abc.Polyhedron):
727
+ return self.element_class(arg, parent=self)
728
+ if arg == 0:
729
+ polyhedron = Polyhedron(base_ring=self.base_ring(), ambient_dim=2)
730
+ return self.element_class(polyhedron, parent=self)
731
+ if arg == 1:
732
+ polyhedron = Polyhedron(base_ring=self.base_ring(),
733
+ vertices=[(0, 0)], rays=[(0, 1)])
734
+ return self.element_class(polyhedron, parent=self)
735
+ if not isinstance(arg, list):
736
+ try:
737
+ arg = list(arg)
738
+ except TypeError:
739
+ raise TypeError("argument must be a list of coordinates "
740
+ "or a list of (rational) slopes")
741
+ if arg and arg[0] in self.base_ring():
742
+ if sort_slopes:
743
+ arg.sort()
744
+ x = y = 0
745
+ vertices = [(x, y)]
746
+ for slope in arg:
747
+ if slope not in self.base_ring():
748
+ raise TypeError("argument must be a list of coordinates "
749
+ "or a list of (rational) slopes")
750
+ x += 1
751
+ y += slope
752
+ vertices.append((x, y))
753
+ else:
754
+ vertices = [(x, y) for (x, y) in arg if y is not Infinity]
755
+
756
+ if len(vertices) == 0:
757
+ polyhedron = Polyhedron(base_ring=self.base_ring(), ambient_dim=2)
758
+ else:
759
+ rays = [(0, 1)]
760
+ if last_slope is not Infinity:
761
+ rays.append((1, last_slope))
762
+ polyhedron = Polyhedron(base_ring=self.base_ring(),
763
+ vertices=vertices, rays=rays)
764
+ return self.element_class(polyhedron, parent=self)
765
+
766
+
767
+ NewtonPolygon = ParentNewtonPolygon()