@@ -110,9 +110,8 @@ def Polyhedra(base_ring, ambient_dim, backend=None):
110
110
raise ValueError ("the 'field' backend for polyhedron can not be used with non-exact fields" )
111
111
return Polyhedra_field (base_ring .fraction_field (), ambient_dim )
112
112
else :
113
- raise ValueError ('No such backend (=' + str (backend )+
114
- ') implemented for given basering (=' + str (base_ring )+ ').' )
115
-
113
+ raise ValueError ('No such backend (=' + str (backend ) +
114
+ ') implemented for given basering (=' + str (base_ring )+ ').' )
116
115
117
116
118
117
class Polyhedra_base (UniqueRepresentation , Parent ):
@@ -222,14 +221,14 @@ def an_element(self):
222
221
A 4-dimensional polyhedron in QQ^4 defined as the convex hull of 5 vertices
223
222
"""
224
223
zero = self .base_ring ().zero ()
225
- one = self .base_ring ().one ()
224
+ one = self .base_ring ().one ()
226
225
p = [zero ] * self .ambient_dim ()
227
226
points = [p ]
228
- for i in range (0 ,self .ambient_dim ()):
227
+ for i in range (0 , self .ambient_dim ()):
229
228
p = [zero ] * self .ambient_dim ()
230
229
p [i ] = one
231
230
points .append (p )
232
- return self .element_class (self , [points ,[],[]], None )
231
+ return self .element_class (self , [points , [], []], None )
233
232
234
233
@cached_method
235
234
def some_elements (self ):
@@ -251,16 +250,16 @@ def some_elements(self):
251
250
if self .ambient_dim () == 0 :
252
251
return [
253
252
self .element_class (self , None , None ),
254
- self .element_class (self , None , [[],[]]) ]
253
+ self .element_class (self , None , [[], []])]
255
254
points = []
256
255
R = self .base_ring ()
257
- for i in range (0 ,self .ambient_dim ()+ 5 ):
258
- points .append ([R (i * j ^ 2 ) for j in range (0 ,self .ambient_dim ())])
256
+ for i in range (0 , self .ambient_dim () + 5 ):
257
+ points .append ([R (i * j ^ 2 ) for j in range (0 , self .ambient_dim ())])
259
258
return [
260
259
self .element_class (self , [points [0 :self .ambient_dim ()+ 1 ], [], []], None ),
261
260
self .element_class (self , [points [0 :1 ], points [1 :self .ambient_dim ()+ 1 ], []], None ),
262
261
self .element_class (self , [points [0 :3 ], points [4 :5 ], []], None ),
263
- self .element_class (self , None , None ) ]
262
+ self .element_class (self , None , None )]
264
263
265
264
@cached_method
266
265
def zero (self ):
@@ -432,7 +431,7 @@ def _element_constructor_(self, *args, **kwds):
432
431
433
432
sage: from sage.geometry.polyhedron.parent import Polyhedra
434
433
sage: P = Polyhedra(QQ, 3)
435
- sage: P._element_constructor_([[(0,0, 0),(1,0, 0),(0,1, 0),(0,0,1)], [], []], None)
434
+ sage: P._element_constructor_([[(0, 0, 0), (1, 0, 0), (0, 1, 0), (0,0,1)], [], []], None)
436
435
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
437
436
sage: P([[(0,0,0),(1,0,0),(0,1,0),(0,0,1)], [], []], None)
438
437
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
@@ -448,47 +447,49 @@ def _element_constructor_(self, *args, **kwds):
448
447
sage: P = b.interactive_lp_problem()
449
448
sage: p = P.plot()
450
449
451
- sage: Q= Polyhedron(ieqs=[[-499999,1000000],[1499999,-1000000]])
452
- sage: P= Polyhedron(ieqs=[[0,1.0],[1.0,-1.0]], base_ring=RDF)
450
+ sage: Q = Polyhedron(ieqs=[[-499999, 1000000], [1499999, -1000000]])
451
+ sage: P = Polyhedron(ieqs=[[0, 1.0], [1.0, -1.0]], base_ring=RDF)
453
452
sage: Q.intersection(P)
454
453
A 1-dimensional polyhedron in RDF^1 defined as the convex hull of 2 vertices
455
454
sage: P.intersection(Q)
456
455
A 1-dimensional polyhedron in RDF^1 defined as the convex hull of 2 vertices
457
456
"""
458
457
nargs = len (args )
459
458
convert = kwds .pop ('convert' , True )
459
+
460
460
def convert_base_ring (lstlst ):
461
- return [ [self .base_ring ()(x ) for x in lst ] for lst in lstlst ]
461
+ return [[self .base_ring ()(x ) for x in lst ] for lst in lstlst ]
462
+
462
463
# renormalize before converting when going from QQ to RDF, see trac 21270
463
464
def convert_base_ring_Hrep (lstlst ):
464
465
newlstlst = []
465
466
for lst in lstlst :
466
467
if all (c in QQ for c in lst ):
467
- m = max (abs (w ) for w in lst )
468
+ m = max (abs (w ) for w in lst )
468
469
if m == 0 :
469
470
newlstlst .append (lst )
470
471
else :
471
472
newlstlst .append ([q / m for q in lst ])
472
473
else :
473
474
newlstlst .append (lst )
474
475
return convert_base_ring (newlstlst )
475
- if nargs == 2 :
476
+ if nargs == 2 :
476
477
Vrep , Hrep = args
477
478
if convert and Hrep :
478
- if self .base_ring == RDF :
479
+ if self .base_ring == RDF :
479
480
Hrep = [convert_base_ring_Hrep (_ ) for _ in Hrep ]
480
481
else :
481
482
Hrep = [convert_base_ring (_ ) for _ in Hrep ]
482
483
if convert and Vrep :
483
484
Vrep = [convert_base_ring (_ ) for _ in Vrep ]
484
485
return self .element_class (self , Vrep , Hrep , ** kwds )
485
- if nargs == 1 and is_Polyhedron (args [0 ]):
486
+ if nargs == 1 and is_Polyhedron (args [0 ]):
486
487
polyhedron = args [0 ]
487
- Hrep = [ polyhedron .inequality_generator (), polyhedron .equation_generator () ]
488
- if self .base_ring ()== RDF :
488
+ Hrep = [polyhedron .inequality_generator (), polyhedron .equation_generator ()]
489
+ if self .base_ring () == RDF :
489
490
Hrep = [convert_base_ring_Hrep (_ ) for _ in Hrep ]
490
491
return self .element_class (self , None , Hrep , ** kwds )
491
- if nargs == 1 and args [0 ]== 0 :
492
+ if nargs == 1 and args [0 ] == 0 :
492
493
return self .zero ()
493
494
raise ValueError ('Cannot convert to polyhedron object.' )
494
495
@@ -874,4 +875,3 @@ class Polyhedra_RDF_cdd(Polyhedra_base):
874
875
875
876
class Polyhedra_field (Polyhedra_base ):
876
877
Element = Polyhedron_field
877
-
0 commit comments