@@ -38,14 +38,15 @@ def __init__(self, polyhedron, parent):
38
38
39
39
- ``polyhedron`` -- a polyhedron defining the Newton polygon
40
40
41
- TESTS:
41
+ TESTS::
42
42
43
43
sage: from sage.geometry.newton_polygon import NewtonPolygon
44
44
sage: NewtonPolygon([ (0,0), (1,1), (3,5) ])
45
45
Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5)
46
46
47
47
sage: NewtonPolygon([ (0,0), (1,1), (2,8), (3,5) ], last_slope=3)
48
- Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5) ending by an infinite line of slope 3
48
+ Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5)
49
+ ending by an infinite line of slope 3
49
50
50
51
::
51
52
@@ -57,7 +58,7 @@ def __init__(self, polyhedron, parent):
57
58
if polyhedron .is_mutable ():
58
59
polyhedron ._add_dependent_object (self )
59
60
60
- def _repr_ (self ):
61
+ def _repr_ (self ) -> str :
61
62
"""
62
63
Return a string representation of this Newton polygon.
63
64
@@ -75,17 +76,16 @@ def _repr_(self):
75
76
if self .last_slope () is Infinity :
76
77
if length == 0 :
77
78
return "Empty Newton polygon"
78
- elif length == 1 :
79
+ if length == 1 :
79
80
return "Finite Newton polygon with 1 vertex: %s" % str (vertices [0 ])
80
- else :
81
- return "Finite Newton polygon with %s vertices: %s" % (length , str (vertices )[1 :- 1 ])
81
+ return "Finite Newton polygon with %s vertices: %s" % (length , str (vertices )[1 :- 1 ])
82
+
83
+ if length == 1 :
84
+ return "Newton Polygon consisting of a unique infinite line of slope %s starting at %s" % (self .last_slope (), str (vertices [0 ]))
82
85
else :
83
- if length == 1 :
84
- return "Newton Polygon consisting of a unique infinite line of slope %s starting at %s" % (self .last_slope (), str (vertices [0 ]))
85
- else :
86
- return "Infinite Newton polygon with %s vertices: %s ending by an infinite line of slope %s" % (length , str (vertices )[1 :- 1 ], self .last_slope ())
86
+ return "Infinite Newton polygon with %s vertices: %s ending by an infinite line of slope %s" % (length , str (vertices )[1 :- 1 ], self .last_slope ())
87
87
88
- def vertices (self , copy = True ):
88
+ def vertices (self , copy = True ) -> list :
89
89
"""
90
90
Return the list of vertices of this Newton polygon.
91
91
@@ -94,7 +94,7 @@ def vertices(self, copy=True):
94
94
- ``copy`` -- boolean (default: ``True``)
95
95
96
96
OUTPUT: the list of vertices of this Newton polygon (or a copy of it
97
- if ``copy`` is set to True)
97
+ if ``copy`` is set to `` True`` )
98
98
99
99
EXAMPLES::
100
100
@@ -105,7 +105,7 @@ def vertices(self, copy=True):
105
105
sage: v = NP.vertices(); v
106
106
[(0, 0), (1, 1), (2, 5)]
107
107
108
- TESTS:
108
+ TESTS::
109
109
110
110
sage: del v[0]
111
111
sage: v
@@ -114,7 +114,7 @@ def vertices(self, copy=True):
114
114
[(0, 0), (1, 1), (2, 5)]
115
115
"""
116
116
if self ._vertices is None :
117
- self ._vertices = [ tuple (v ) for v in self ._polyhedron .vertices () ]
117
+ self ._vertices = [tuple (v ) for v in self ._polyhedron .vertices ()]
118
118
self ._vertices .sort ()
119
119
if copy :
120
120
return list (self ._vertices )
@@ -152,7 +152,7 @@ def last_slope(self):
152
152
return r [1 ]/ r [0 ]
153
153
return Infinity
154
154
155
- def slopes (self , repetition = True ):
155
+ def slopes (self , repetition = True ) -> list :
156
156
"""
157
157
Return the slopes of this Newton polygon.
158
158
@@ -165,7 +165,7 @@ def slopes(self, repetition=True):
165
165
The consecutive slopes (not including the last slope
166
166
if the polygon is infinity) of this Newton polygon.
167
167
168
- If ``repetition`` is True, each slope is repeated a number of
168
+ If ``repetition`` is `` True`` , each slope is repeated a number of
169
169
times equal to its length. Otherwise, it appears only one time.
170
170
171
171
EXAMPLES::
@@ -180,9 +180,9 @@ def slopes(self, repetition=True):
180
180
sage: NP.slopes(repetition=False)
181
181
[1, 5/2]
182
182
"""
183
- slopes = [ ]
183
+ slopes = []
184
184
vertices = self .vertices (copy = False )
185
- for i in range (1 ,len (vertices )):
185
+ for i in range (1 , len (vertices )):
186
186
dx = vertices [i ][0 ] - vertices [i - 1 ][0 ]
187
187
dy = vertices [i ][1 ] - vertices [i - 1 ][1 ]
188
188
slope = dy / dx
@@ -200,18 +200,23 @@ def _add_(self, other):
200
200
201
201
- ``other`` -- a Newton polygon
202
202
203
- OUTPUT: the Newton polygon, which is the convex hull of this Newton polygon and ``other``
203
+ OUTPUT:
204
+
205
+ the Newton polygon, which is the convex hull of this Newton polygon
206
+ and ``other``
204
207
205
208
EXAMPLES::
206
209
207
210
sage: from sage.geometry.newton_polygon import NewtonPolygon
208
211
sage: NP1 = NewtonPolygon([ (0,0), (1,1), (2,6) ]); NP1
209
212
Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 6)
210
213
sage: NP2 = NewtonPolygon([ (0,0), (1,3/2) ], last_slope=2); NP2
211
- Infinite Newton polygon with 2 vertices: (0, 0), (1, 3/2) ending by an infinite line of slope 2
214
+ Infinite Newton polygon with 2 vertices: (0, 0), (1, 3/2)
215
+ ending by an infinite line of slope 2
212
216
213
217
sage: NP1 + NP2
214
- Infinite Newton polygon with 2 vertices: (0, 0), (1, 1) ending by an infinite line of slope 2
218
+ Infinite Newton polygon with 2 vertices: (0, 0), (1, 1)
219
+ ending by an infinite line of slope 2
215
220
"""
216
221
polyhedron = self ._polyhedron .convex_hull (other ._polyhedron )
217
222
return self .parent ()(polyhedron )
@@ -224,26 +229,32 @@ def _mul_(self, other):
224
229
225
230
- ``other`` -- a Newton polygon
226
231
227
- OUTPUT: the Newton polygon, which is the Minkowski sum of this Newton polygon and ``other``
232
+ OUTPUT:
233
+
234
+ the Newton polygon, which is the Minkowski sum of this Newton polygon
235
+ and ``other``
228
236
229
237
.. NOTE::
230
238
231
- If ``self`` and ``other`` are respective Newton polygons of some polynomials
232
- `f` and `g` the self*other is the Newton polygon of the product `fg`
239
+ If ``self`` and ``other`` are respective Newton polygons
240
+ of some polynomials `f` and `g` the self*other is the
241
+ Newton polygon of the product `fg`
233
242
234
243
EXAMPLES::
235
244
236
245
sage: from sage.geometry.newton_polygon import NewtonPolygon
237
246
sage: NP1 = NewtonPolygon([ (0,0), (1,1), (2,6) ]); NP1
238
247
Finite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 6)
239
248
sage: NP2 = NewtonPolygon([ (0,0), (1,3/2) ], last_slope=2); NP2
240
- Infinite Newton polygon with 2 vertices: (0, 0), (1, 3/2) ending by an infinite line of slope 2
249
+ Infinite Newton polygon with 2 vertices: (0, 0), (1, 3/2)
250
+ ending by an infinite line of slope 2
241
251
242
252
sage: NP = NP1 * NP2; NP
243
- Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 5/2) ending by an infinite line of slope 2
253
+ Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (2, 5/2)
254
+ ending by an infinite line of slope 2
244
255
245
- The slopes of ``NP`` is the union of those of ``NP1`` and those of ``NP2``
246
- which are less than the last slope::
256
+ The slopes of ``NP`` is the union of those of ``NP1`` and
257
+ those of ``NP2`` which are less than the last slope::
247
258
248
259
sage: NP1.slopes()
249
260
[1, 5]
@@ -301,7 +312,7 @@ def __lshift__(self, i):
301
312
sage: NP << 2
302
313
Finite Newton polygon with 3 vertices: (0, 2), (1, 3), (2, 8)
303
314
"""
304
- polyhedron = self ._polyhedron .translation ((0 ,i ))
315
+ polyhedron = self ._polyhedron .translation ((0 , i ))
305
316
return self .parent ()(polyhedron )
306
317
307
318
def __rshift__ (self , i ):
@@ -323,7 +334,7 @@ def __rshift__(self, i):
323
334
sage: NP >> 2
324
335
Finite Newton polygon with 3 vertices: (0, -2), (1, -1), (2, 4)
325
336
"""
326
- polyhedron = self ._polyhedron .translation ((0 ,- i ))
337
+ polyhedron = self ._polyhedron .translation ((0 , - i ))
327
338
return self .parent ()(polyhedron )
328
339
329
340
def __call__ (self , x ):
@@ -368,7 +379,7 @@ def __call__(self, x):
368
379
xd , yd = vertices [b ]
369
380
return ((x - xg )* yd + (xd - x )* yg ) / (xd - xg )
370
381
371
- def _richcmp_ (self , other , op ):
382
+ def _richcmp_ (self , other , op ) -> bool :
372
383
r"""
373
384
Comparisons of two Newton polygons.
374
385
@@ -457,18 +468,24 @@ def plot(self, **kwargs):
457
468
if len (vertices ) == 0 :
458
469
from sage .plot .graphics import Graphics
459
470
return Graphics ()
471
+
472
+ from sage .plot .line import line
473
+ xstart , ystart = vertices [0 ]
474
+ xend , yend = vertices [- 1 ]
475
+ if self .last_slope () is Infinity :
476
+ return line ([(xstart , ystart + 1 ), (xstart , ystart + 0.5 )],
477
+ linestyle = '--' , ** kwargs ) \
478
+ + line ([(xstart , ystart + 0.5 )] + vertices
479
+ + [(xend , yend + 0.5 )], ** kwargs ) \
480
+ + line ([(xend , yend + 0.5 ), (xend , yend + 1 )],
481
+ linestyle = '--' , ** kwargs )
460
482
else :
461
- from sage .plot .line import line
462
- (xstart ,ystart ) = vertices [0 ]
463
- (xend ,yend ) = vertices [- 1 ]
464
- if self .last_slope () is Infinity :
465
- return line ([(xstart , ystart + 1 ), (xstart ,ystart + 0.5 )], linestyle = '--' , ** kwargs ) \
466
- + line ([(xstart , ystart + 0.5 )] + vertices + [(xend , yend + 0.5 )], ** kwargs ) \
467
- + line ([(xend , yend + 0.5 ), (xend , yend + 1 )], linestyle = '--' , ** kwargs )
468
- else :
469
- return line ([(xstart , ystart + 1 ), (xstart ,ystart + 0.5 )], linestyle = '--' , ** kwargs ) \
470
- + line ([(xstart , ystart + 0.5 )] + vertices + [(xend + 0.5 , yend + 0.5 * self .last_slope ())], ** kwargs ) \
471
- + line ([(xend + 0.5 , yend + 0.5 * self .last_slope ()), (xend + 1 , yend + self .last_slope ())], linestyle = '--' , ** kwargs )
483
+ return line ([(xstart , ystart + 1 ), (xstart , ystart + 0.5 )],
484
+ linestyle = '--' , ** kwargs ) \
485
+ + line ([(xstart , ystart + 0.5 )] + vertices
486
+ + [(xend + 0.5 , yend + 0.5 * self .last_slope ())], ** kwargs ) \
487
+ + line ([(xend + 0.5 , yend + 0.5 * self .last_slope ()), (xend + 1 , yend + self .last_slope ())],
488
+ linestyle = '--' , ** kwargs )
472
489
473
490
def reverse (self , degree = None ):
474
491
r"""
@@ -503,10 +520,11 @@ def reverse(self, degree=None):
503
520
raise ValueError ("Can only reverse *finite* Newton polygons" )
504
521
if degree is None :
505
522
degree = self .vertices ()[- 1 ][0 ]
506
- vertices = [ (degree - x , y ) for ( x , y ) in self .vertices () ]
523
+ vertices = [(degree - x , y ) for x , y in self .vertices ()]
507
524
vertices .reverse ()
508
525
parent = self .parent ()
509
- polyhedron = Polyhedron (base_ring = parent .base_ring (), vertices = vertices , rays = [(0 ,1 )])
526
+ polyhedron = Polyhedron (base_ring = parent .base_ring (),
527
+ vertices = vertices , rays = [(0 , 1 )])
510
528
return parent (polyhedron )
511
529
512
530
@@ -557,12 +575,14 @@ class ParentNewtonPolygon(Parent, UniqueRepresentation):
557
575
and ends with an infinite line having the specified slope::
558
576
559
577
sage: NewtonPolygon([ (0,0), (1,1), (2,8), (3,5) ], last_slope=3)
560
- Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5) ending by an infinite line of slope 3
578
+ Infinite Newton polygon with 3 vertices: (0, 0), (1, 1), (3, 5)
579
+ ending by an infinite line of slope 3
561
580
562
581
Specifying a last slope may discard some vertices::
563
582
564
583
sage: NewtonPolygon([ (0,0), (1,1), (2,8), (3,5) ], last_slope=3/2)
565
- Infinite Newton polygon with 2 vertices: (0, 0), (1, 1) ending by an infinite line of slope 3/2
584
+ Infinite Newton polygon with 2 vertices: (0, 0), (1, 1)
585
+ ending by an infinite line of slope 3/2
566
586
567
587
Next, we define a Newton polygon by its slopes::
568
588
@@ -589,7 +609,8 @@ class ParentNewtonPolygon(Parent, UniqueRepresentation):
589
609
590
610
sage: NP = NewtonPolygon([0, 1/2, 1/2, 2/3, 2/3, 2/3, 1, 1], last_slope=2/3)
591
611
sage: NP
592
- Infinite Newton polygon with 3 vertices: (0, 0), (1, 0), (3, 1) ending by an infinite line of slope 2/3
612
+ Infinite Newton polygon with 3 vertices: (0, 0), (1, 0), (3, 1)
613
+ ending by an infinite line of slope 2/3
593
614
sage: NP.slopes()
594
615
[0, 1/2, 1/2]
595
616
@@ -602,14 +623,15 @@ class ParentNewtonPolygon(Parent, UniqueRepresentation):
602
623
sage: x, y = polygen(QQ,'x, y')
603
624
sage: p = 1 + x*y**45 + x**3*y**6
604
625
sage: p.newton_polytope()
605
- A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices
626
+ A 2-dimensional polyhedron in ZZ^2 defined as the convex hull
627
+ of 3 vertices
606
628
sage: p.newton_polytope().vertices()
607
629
(A vertex at (0, 0), A vertex at (1, 45), A vertex at (3, 6))
608
630
"""
609
631
610
632
Element = NewtonPolygon_element
611
633
612
- def __init__ (self ):
634
+ def __init__ (self ) -> None :
613
635
"""
614
636
Parent class for all Newton polygons.
615
637
@@ -634,12 +656,12 @@ def __init__(self):
634
656
from sage .rings .rational_field import QQ
635
657
Parent .__init__ (self , category = Semirings (), base = QQ )
636
658
637
- def _repr_ (self ):
659
+ def _repr_ (self ) -> str :
638
660
"""
639
661
Return the string representation of this parent,
640
662
which is ``Parent for Newton polygons``.
641
663
642
- TESTS:
664
+ TESTS::
643
665
644
666
sage: from sage.geometry.newton_polygon import NewtonPolygon
645
667
sage: NewtonPolygon
@@ -654,15 +676,16 @@ def _an_element_(self):
654
676
"""
655
677
Return a Newton polygon (which is the empty one).
656
678
657
- TESTS:
679
+ TESTS::
658
680
659
681
sage: from sage.geometry.newton_polygon import NewtonPolygon
660
682
sage: NewtonPolygon._an_element_()
661
683
Empty Newton polygon
662
684
"""
663
685
return self (Polyhedron (base_ring = self .base_ring (), ambient_dim = 2 ))
664
686
665
- def _element_constructor_ (self , arg , sort_slopes = True , last_slope = Infinity ):
687
+ def _element_constructor_ (self , arg , sort_slopes = True ,
688
+ last_slope = Infinity ):
666
689
r"""
667
690
INPUT:
668
691
@@ -712,15 +735,17 @@ def _element_constructor_(self, arg, sort_slopes=True, last_slope=Infinity):
712
735
try :
713
736
arg = list (arg )
714
737
except TypeError :
715
- raise TypeError ("argument must be a list of coordinates or a list of (rational) slopes" )
738
+ raise TypeError ("argument must be a list of coordinates "
739
+ "or a list of (rational) slopes" )
716
740
if arg and arg [0 ] in self .base_ring ():
717
741
if sort_slopes :
718
742
arg .sort ()
719
743
x = y = 0
720
744
vertices = [(x , y )]
721
745
for slope in arg :
722
746
if slope not in self .base_ring ():
723
- raise TypeError ("argument must be a list of coordinates or a list of (rational) slopes" )
747
+ raise TypeError ("argument must be a list of coordinates "
748
+ "or a list of (rational) slopes" )
724
749
x += 1
725
750
y += slope
726
751
vertices .append ((x , y ))
@@ -733,7 +758,8 @@ def _element_constructor_(self, arg, sort_slopes=True, last_slope=Infinity):
733
758
rays = [(0 , 1 )]
734
759
if last_slope is not Infinity :
735
760
rays .append ((1 , last_slope ))
736
- polyhedron = Polyhedron (base_ring = self .base_ring (), vertices = vertices , rays = rays )
761
+ polyhedron = Polyhedron (base_ring = self .base_ring (),
762
+ vertices = vertices , rays = rays )
737
763
return self .element_class (polyhedron , parent = self )
738
764
739
765
0 commit comments