Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/geometry/polyhedron/parent.py
8817 views
1
r"""
2
Parents for Polyhedra
3
"""
4
5
#*****************************************************************************
6
# Copyright (C) 2011 Volker Braun <[email protected]>
7
#
8
# Distributed under the terms of the GNU General Public License (GPL)
9
# http://www.gnu.org/licenses/
10
#******************************************************************************
11
12
from sage.structure.parent import Parent
13
from sage.structure.element import get_coercion_model
14
from sage.structure.unique_representation import UniqueRepresentation
15
from sage.modules.free_module import is_FreeModule
16
from sage.misc.cachefunc import cached_method
17
from sage.rings.commutative_ring import is_CommutativeRing
18
from sage.rings.all import ZZ, QQ, RDF
19
from sage.categories.fields import Fields
20
_Fields = Fields()
21
22
from sage.geometry.polyhedron.base import Polyhedron_base, is_Polyhedron
23
from representation import Inequality, Equation, Vertex, Ray, Line
24
25
26
def Polyhedra(base_ring, ambient_dim, backend=None):
27
"""
28
Construct a suitable parent class for polyhedra
29
30
INPUT:
31
32
- ``base_ring`` -- A ring. Currently there are backends for `\ZZ`,
33
`\QQ`, and `\RDF`.
34
35
- ``ambient_dim`` -- integer. The ambient space dimension.
36
37
- ``backend`` -- string. The name of the backend for computations. Currently there are two backends implemented:
38
39
* ``backend=ppl`` uses the Parma Polyhedra Library
40
41
* ``backend=cdd`` uses CDD
42
43
OUTPUT:
44
45
A parent class for polyhedra over the given base ring if the
46
backend supports it. If not, the parent base ring can be larger
47
(for example, `\QQ` instead of `\ZZ`). If there is no
48
implementation at all, a ``ValueError`` is raised.
49
50
EXAMPLES::
51
52
sage: from sage.geometry.polyhedron.parent import Polyhedra
53
sage: Polyhedra(ZZ, 3)
54
Polyhedra in ZZ^3
55
sage: type(_)
56
<class 'sage.geometry.polyhedron.parent.Polyhedra_ZZ_ppl_with_category'>
57
sage: Polyhedra(QQ, 3, backend='cdd')
58
Polyhedra in QQ^3
59
sage: type(_)
60
<class 'sage.geometry.polyhedron.parent.Polyhedra_QQ_cdd_with_category'>
61
62
CDD does not support integer polytopes directly::
63
64
sage: Polyhedra(ZZ, 3, backend='cdd')
65
Polyhedra in QQ^3
66
"""
67
if backend is None:
68
if base_ring is ZZ:
69
return Polyhedra_ZZ_ppl(base_ring, ambient_dim)
70
elif base_ring is QQ:
71
return Polyhedra_QQ_ppl(base_ring, ambient_dim)
72
elif base_ring is RDF:
73
return Polyhedra_RDF_cdd(base_ring, ambient_dim)
74
else:
75
raise ValueError('Polyhedral objects can only be constructed over ZZ, QQ, and RDF')
76
elif backend=='ppl' and base_ring is QQ:
77
return Polyhedra_QQ_ppl(base_ring, ambient_dim)
78
elif backend=='ppl' and base_ring is ZZ:
79
return Polyhedra_ZZ_ppl(base_ring, ambient_dim)
80
elif backend=='cdd' and base_ring in (ZZ, QQ):
81
return Polyhedra_QQ_cdd(QQ, ambient_dim)
82
elif backend=='cdd' and base_ring is RDF:
83
return Polyhedra_RDF_cdd(RDF, ambient_dim)
84
else:
85
raise ValueError('No such backend (='+str(backend)+
86
') implemented for given basering (='+str(base_ring)+').')
87
88
89
90
class Polyhedra_base(UniqueRepresentation, Parent):
91
r"""
92
Polyhedra in a fixed ambient space.
93
94
INPUT:
95
96
- ``base_ring`` -- either ``ZZ``, ``QQ``, or ``RDF``. The base
97
ring of the ambient module/vector space.
98
99
- ``ambient_dim`` -- integer. The ambient space dimension.
100
101
EXAMPLES::
102
103
sage: from sage.geometry.polyhedron.parent import Polyhedra
104
sage: Polyhedra(ZZ, 3)
105
Polyhedra in ZZ^3
106
"""
107
def __init__(self, base_ring, ambient_dim):
108
"""
109
The Python constructor.
110
111
EXAMPLES::
112
113
sage: from sage.geometry.polyhedron.parent import Polyhedra
114
sage: Polyhedra(QQ, 3)
115
Polyhedra in QQ^3
116
117
TESTS::
118
119
sage: from sage.geometry.polyhedron.parent import Polyhedra
120
sage: P = Polyhedra(QQ, 3)
121
sage: TestSuite(P).run(skip='_test_pickling')
122
"""
123
self._ambient_dim = ambient_dim
124
from sage.categories.polyhedra import PolyhedralSets
125
Parent.__init__(self, base=base_ring, category=PolyhedralSets(base_ring))
126
self._Inequality_pool = []
127
self._Equation_pool = []
128
self._Vertex_pool = []
129
self._Ray_pool = []
130
self._Line_pool = []
131
132
def recycle(self, polyhedron):
133
"""
134
Recycle the H/V-representation objects of a polyhedron.
135
136
This speeds up creation of new polyhedra by reusing
137
objects. After recycling a polyhedron object, it is not in a
138
consistent state any more and neither the polyhedron nor its
139
H/V-representation objects may be used any more.
140
141
INPUT:
142
143
- ``polyhedron`` -- a polyhedron whose parent is ``self``.
144
145
146
EXAMPLES::
147
148
sage: p = Polyhedron([(0,0),(1,0),(0,1)])
149
sage: p.parent().recycle(p)
150
151
TESTS::
152
153
sage: p = Polyhedron([(0,0),(1,0),(0,1)])
154
sage: n = len(p.parent()._Vertex_pool)
155
sage: p.delete()
156
sage: len(p.parent()._Vertex_pool) - n
157
3
158
"""
159
if self is not polyhedron.parent():
160
raise TypeError('The polyhedron has the wrong parent class.')
161
self._Inequality_pool.extend(polyhedron.inequalities())
162
self._Equation_pool.extend(polyhedron.equations())
163
self._Vertex_pool.extend(polyhedron.vertices())
164
self._Ray_pool.extend(polyhedron.rays())
165
self._Line_pool.extend(polyhedron.lines())
166
for Hrep in polyhedron.Hrep_generator():
167
Hrep._polyhedron = None
168
for Vrep in polyhedron.Vrep_generator():
169
Vrep._polyhedron = None
170
polyhedron._Hrepresentation = None
171
polyhedron._Vrepresentation = None
172
173
def ambient_dim(self):
174
r"""
175
Return the dimension of the ambient space.
176
177
EXAMPLES::
178
179
sage: from sage.geometry.polyhedron.parent import Polyhedra
180
sage: Polyhedra(QQ, 3).ambient_dim()
181
3
182
"""
183
return self._ambient_dim
184
185
@cached_method
186
def an_element(self):
187
r"""
188
Returns a Polyhedron.
189
190
EXAMPLES::
191
192
sage: from sage.geometry.polyhedron.parent import Polyhedra
193
sage: Polyhedra(QQ, 4).an_element()
194
A 4-dimensional polyhedron in QQ^4 defined as the convex hull of 5 vertices
195
"""
196
p = [0] * self.ambient_dim()
197
points = [p]
198
for i in range(0,self.ambient_dim()):
199
p = [0] * self.ambient_dim()
200
p[i] = 1
201
points.append(p)
202
return self.element_class(self, [points,[],[]], None)
203
204
@cached_method
205
def some_elements(self):
206
r"""
207
Returns a list of some elements of the semigroup.
208
209
EXAMPLES::
210
211
sage: from sage.geometry.polyhedron.parent import Polyhedra
212
sage: Polyhedra(QQ, 4).some_elements()
213
[A 3-dimensional polyhedron in QQ^4 defined as the convex hull of 4 vertices,
214
A 4-dimensional polyhedron in QQ^4 defined as the convex hull of 1 vertex and 4 rays,
215
A 2-dimensional polyhedron in QQ^4 defined as the convex hull of 2 vertices and 1 ray,
216
The empty polyhedron in QQ^4]
217
sage: Polyhedra(ZZ,0).some_elements()
218
[The empty polyhedron in ZZ^0,
219
A 0-dimensional polyhedron in ZZ^0 defined as the convex hull of 1 vertex]
220
"""
221
if self.ambient_dim() == 0:
222
return [
223
self.element_class(self, None, None),
224
self.element_class(self, None, [[],[]]) ]
225
points = []
226
for i in range(0,self.ambient_dim()+5):
227
points.append([i*j^2 for j in range(0,self.ambient_dim())])
228
return [
229
self.element_class(self, [points[0:self.ambient_dim()+1], [], []], None),
230
self.element_class(self, [points[0:1], points[1:self.ambient_dim()+1], []], None),
231
self.element_class(self, [points[0:3], points[4:5], []], None),
232
self.element_class(self, None, None) ]
233
234
@cached_method
235
def zero_element(self):
236
r"""
237
Return the polyhedron consisting of the origin, which is the
238
neutral element for Minkowski addition.
239
240
EXAMPLES::
241
242
sage: from sage.geometry.polyhedron.parent import Polyhedra
243
sage: p = Polyhedra(QQ, 4).zero_element(); p
244
A 0-dimensional polyhedron in QQ^4 defined as the convex hull of 1 vertex
245
sage: p+p == p
246
True
247
"""
248
Vrep = [[[self.base_ring().zero()]*self.ambient_dim()], [], []]
249
return self.element_class(self, Vrep, None)
250
251
def empty(self):
252
"""
253
Return the empty polyhedron.
254
255
EXAMPLES::
256
257
sage: from sage.geometry.polyhedron.parent import Polyhedra
258
sage: P = Polyhedra(QQ, 4)
259
sage: P.empty()
260
The empty polyhedron in QQ^4
261
sage: P.empty().is_empty()
262
True
263
"""
264
return self(None, None)
265
266
def universe(self):
267
"""
268
Return the entire ambient space as polyhedron.
269
270
EXAMPLES::
271
272
sage: from sage.geometry.polyhedron.parent import Polyhedra
273
sage: P = Polyhedra(QQ, 4)
274
sage: P.universe()
275
A 4-dimensional polyhedron in QQ^4 defined as the convex hull of 1 vertex and 4 lines
276
sage: P.universe().is_universe()
277
True
278
"""
279
return self(None, [[[1]+[0]*self.ambient_dim()], []], convert=True)
280
281
@cached_method
282
def Vrepresentation_space(self):
283
r"""
284
Return the ambient vector space.
285
286
This is the vector space or module containing the
287
Vrepresentation vectors.
288
289
OUTPUT:
290
291
A free module over the base ring of dimension :meth:`ambient_dim`.
292
293
EXAMPLES::
294
295
sage: from sage.geometry.polyhedron.parent import Polyhedra
296
sage: Polyhedra(QQ, 4).Vrepresentation_space()
297
Vector space of dimension 4 over Rational Field
298
sage: Polyhedra(QQ, 4).ambient_space()
299
Vector space of dimension 4 over Rational Field
300
"""
301
if self.base_ring() in _Fields:
302
from sage.modules.free_module import VectorSpace
303
return VectorSpace(self.base_ring(), self.ambient_dim())
304
else:
305
from sage.modules.free_module import FreeModule
306
return FreeModule(self.base_ring(), self.ambient_dim())
307
308
ambient_space = Vrepresentation_space
309
310
@cached_method
311
def Hrepresentation_space(self):
312
r"""
313
Return the linear space containing the H-representation vectors.
314
315
OUTPUT:
316
317
A free module over the base ring of dimension :meth:`ambient_dim` + 1.
318
319
EXAMPLES::
320
321
sage: from sage.geometry.polyhedron.parent import Polyhedra
322
sage: Polyhedra(ZZ, 2).Hrepresentation_space()
323
Ambient free module of rank 3 over the principal ideal domain Integer Ring
324
"""
325
if self.base_ring() in _Fields:
326
from sage.modules.free_module import VectorSpace
327
return VectorSpace(self.base_ring(), self.ambient_dim()+1)
328
else:
329
from sage.modules.free_module import FreeModule
330
return FreeModule(self.base_ring(), self.ambient_dim()+1)
331
332
def _repr_ambient_module(self):
333
"""
334
Return an abbreviated string representation of the ambient
335
space.
336
337
OUTPUT:
338
339
String.
340
341
EXAMPLES::
342
343
sage: from sage.geometry.polyhedron.parent import Polyhedra
344
sage: Polyhedra(QQ, 3)._repr_ambient_module()
345
'QQ^3'
346
"""
347
if self.base_ring() is ZZ:
348
s = 'ZZ'
349
elif self.base_ring() is QQ:
350
s = 'QQ'
351
elif self.base_ring() is RDF:
352
s = 'RDF'
353
else:
354
assert False
355
s += '^' + repr(self.ambient_dim())
356
return s
357
358
def _repr_(self):
359
"""
360
Return a string representation.
361
362
OUTPUT:
363
364
String.
365
366
EXAMPLES::
367
368
sage: from sage.geometry.polyhedron.parent import Polyhedra
369
sage: Polyhedra(QQ, 3)
370
Polyhedra in QQ^3
371
sage: Polyhedra(QQ, 3)._repr_()
372
'Polyhedra in QQ^3'
373
"""
374
return 'Polyhedra in '+self._repr_ambient_module()
375
376
def _element_constructor_(self, *args, **kwds):
377
"""
378
The element (polyhedron) constructor.
379
380
INPUT:
381
382
- ``Vrep`` -- a list `[vertices, rays, lines]`` or ``None``.
383
384
- ``Hrep`` -- a list `[ieqs, eqns]`` or ``None``.
385
386
- ``convert`` -- boolean keyword argument (default:
387
``True``). Whether to convert the cooordinates into the base
388
ring.
389
390
- ``**kwds`` -- optional remaining keywords that are passed to the
391
polyhedron constructor.
392
393
EXAMPLES::
394
395
sage: from sage.geometry.polyhedron.parent import Polyhedra
396
sage: P = Polyhedra(QQ, 3)
397
sage: P._element_constructor_([[(0,0,0),(1,0,0),(0,1,0),(0,0,1)], [], []], None)
398
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
399
sage: P([[(0,0,0),(1,0,0),(0,1,0),(0,0,1)], [], []], None)
400
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
401
sage: P(0)
402
A 0-dimensional polyhedron in QQ^3 defined as the convex hull of 1 vertex
403
"""
404
nargs = len(args)
405
convert = kwds.pop('convert', True)
406
if nargs==2:
407
Vrep, Hrep = args
408
def convert_base_ring(lstlst):
409
return [ [self.base_ring()(x) for x in lst] for lst in lstlst]
410
if convert and Hrep:
411
Hrep = map(convert_base_ring, Hrep)
412
if convert and Vrep:
413
Vrep = map(convert_base_ring, Vrep)
414
return self.element_class(self, Vrep, Hrep, **kwds)
415
if nargs==1 and is_Polyhedron(args[0]):
416
polyhedron = args[0]
417
Hrep = [ polyhedron.inequality_generator(), polyhedron.equation_generator() ]
418
return self.element_class(self, None, Hrep, **kwds)
419
if nargs==1 and args[0]==0:
420
return self.zero_element()
421
raise ValueError('Cannot convert to polyhedron object.')
422
423
def base_extend(self, base_ring, backend=None):
424
"""
425
Return the base extended parent.
426
427
INPUT:
428
429
- ``base_ring``, ``backend`` -- see
430
:func:`~sage.geometry.polyhedron.constructor.Polyhedron`.
431
432
EXAMPLES::
433
434
sage: from sage.geometry.polyhedron.parent import Polyhedra
435
sage: Polyhedra(ZZ,3).base_extend(QQ)
436
Polyhedra in QQ^3
437
sage: Polyhedra(ZZ,3).an_element().base_extend(QQ)
438
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
439
"""
440
if self.base_ring().has_coerce_map_from(base_ring):
441
return self
442
elif base_ring.has_coerce_map_from(self.base_ring()):
443
return Polyhedra(base_ring, self.ambient_dim())
444
445
def _coerce_base_ring(self, other):
446
"""
447
Return the common base rincg for both ``self`` and ``other``.
448
449
This method is not part of the coercion framework, but only a
450
convenience function for :class:`Polyhedra_base`.
451
452
INPUT:
453
454
- ``other`` -- must be either:
455
456
* another ``Polyhedron`` object
457
458
* `\ZZ`, `\QQ`, `RDF`, or a ring that can be coerced into them.
459
460
* a constant that can be coerced to `\ZZ`, `\QQ`, or `RDF`.
461
462
OUTPUT:
463
464
Either `\ZZ`, `\QQ`, or `RDF`. Raises ``TypeError`` if
465
``other`` is not a suitable input.
466
467
.. NOTE::
468
469
"Real" numbers in sage are not necessarily elements of
470
`RDF`. For example, the literal `1.0` is not.
471
472
EXAMPLES::
473
474
sage: triangle_QQ = Polyhedron(vertices = [[1,0],[0,1],[1,1]], base_ring=QQ).parent()
475
sage: triangle_RDF = Polyhedron(vertices = [[1,0],[0,1],[1,1]], base_ring=RDF).parent()
476
sage: triangle_QQ._coerce_base_ring(QQ)
477
Rational Field
478
sage: triangle_QQ._coerce_base_ring(triangle_RDF)
479
Real Double Field
480
sage: triangle_RDF._coerce_base_ring(triangle_QQ)
481
Real Double Field
482
sage: triangle_QQ._coerce_base_ring(RDF)
483
Real Double Field
484
sage: triangle_QQ._coerce_base_ring(ZZ)
485
Rational Field
486
sage: triangle_QQ._coerce_base_ring(1/2)
487
Rational Field
488
sage: triangle_QQ._coerce_base_ring(0.5)
489
Real Double Field
490
"""
491
try:
492
other_ring = other.base_ring()
493
except AttributeError:
494
try:
495
# other is a constant?
496
other_ring = other.parent()
497
except AttributeError:
498
other_ring = None
499
for ring in (ZZ, QQ, RDF):
500
try:
501
ring.coerce(other)
502
other_ring = ring
503
break
504
except TypeError:
505
pass
506
if other_ring is None:
507
raise TypeError('Could not coerce '+str(other)+' into ZZ, QQ, or RDF.')
508
509
if not other_ring.is_exact():
510
other_ring = RDF # the only supported floating-point numbers for now
511
512
cm_map, cm_ring = get_coercion_model().analyse(self.base_ring(), other_ring)
513
if cm_ring is None:
514
raise TypeError('Could not coerce type '+str(other)+' into ZZ, QQ, or RDF.')
515
return cm_ring
516
517
def _coerce_map_from_(self, X):
518
r"""
519
Return whether there is a coercion from ``X``
520
521
INPUT:
522
523
- ``X`` -- anything.
524
525
OUTPUT:
526
527
Boolean.
528
529
EXAMPLE::
530
531
sage: from sage.geometry.polyhedron.parent import Polyhedra
532
sage: Polyhedra(QQ,3).has_coerce_map_from( Polyhedra(ZZ,3) ) # indirect doctest
533
True
534
sage: Polyhedra(ZZ,3).has_coerce_map_from( Polyhedra(QQ,3) )
535
False
536
"""
537
if not isinstance(X, Polyhedra_base):
538
return False
539
if self.ambient_dim() != X.ambient_dim():
540
return False
541
return self.base_ring().has_coerce_map_from(X.base_ring())
542
543
def _get_action_(self, other, op, self_is_left):
544
"""
545
Register actions with the coercion model.
546
547
The monoid actions are Minkowski sum and cartesian product. In
548
addition, we want multiplication by a scalar to be dilation
549
and addition by a vector to be translation. This is
550
implemented as an action in the coercion model.
551
552
INPUT:
553
554
- ``other`` -- a scalar or a vector.
555
556
- ``op`` -- the operator.
557
558
- ``self_is_left`` -- boolean. Whether ``self`` is on the left
559
of the operator.
560
561
OUTPUT:
562
563
An action that is used by the coercion model.
564
565
EXAMPLES::
566
567
sage: from sage.geometry.polyhedron.parent import Polyhedra
568
sage: Polyhedra(ZZ,2).get_action(ZZ) # indirect doctest
569
Right action by Integer Ring on Polyhedra in ZZ^2
570
sage: Polyhedra(ZZ,2).get_action(QQ)
571
Right action by Rational Field on Polyhedra in QQ^2
572
with precomposition on left by Conversion map:
573
From: Polyhedra in ZZ^2
574
To: Polyhedra in QQ^2
575
with precomposition on right by Identity endomorphism of Rational Field
576
sage: Polyhedra(QQ,2).get_action(ZZ)
577
Right action by Integer Ring on Polyhedra in QQ^2
578
sage: Polyhedra(QQ,2).get_action(QQ)
579
Right action by Rational Field on Polyhedra in QQ^2
580
581
sage: Polyhedra(ZZ,2).an_element() * 2
582
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices
583
sage: Polyhedra(ZZ,2).an_element() * (2/3)
584
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices
585
sage: Polyhedra(QQ,2).an_element() * 2
586
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices
587
sage: Polyhedra(QQ,2).an_element() * (2/3)
588
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices
589
590
sage: 2 * Polyhedra(ZZ,2).an_element()
591
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices
592
sage: (2/3) * Polyhedra(ZZ,2).an_element()
593
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices
594
sage: 2 * Polyhedra(QQ,2).an_element()
595
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices
596
sage: (2/3) * Polyhedra(QQ,2).an_element()
597
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices
598
599
sage: from sage.geometry.polyhedron.parent import Polyhedra
600
sage: Polyhedra(ZZ,2).get_action( ZZ^2, op=operator.add)
601
Right action by Ambient free module of rank 2 over the principal ideal
602
domain Integer Ring on Polyhedra in ZZ^2
603
with precomposition on left by Identity endomorphism of Polyhedra in ZZ^2
604
with precomposition on right by Free module morphism defined by the matrix
605
[1 0]
606
[0 1]
607
Domain: Ambient free module of rank 2 over the principal ideal domain ...
608
Codomain: Ambient free module of rank 2 over the principal ideal domain ...
609
"""
610
import operator
611
from sage.structure.coerce_actions import ActedUponAction
612
from sage.categories.action import PrecomposedAction
613
614
if op is operator.add and is_FreeModule(other):
615
base_ring = self._coerce_base_ring(other)
616
extended_self = self.base_extend(base_ring)
617
extended_other = other.base_extend(base_ring)
618
action = ActedUponAction(extended_other, extended_self, not self_is_left)
619
if self_is_left:
620
action = PrecomposedAction(action,
621
extended_self.coerce_map_from(self),
622
extended_other.coerce_map_from(other))
623
else:
624
action = PrecomposedAction(action,
625
extended_other.coerce_map_from(other),
626
extended_self.coerce_map_from(self))
627
return action
628
629
if op is operator.mul and is_CommutativeRing(other):
630
ring = self._coerce_base_ring(other)
631
if ring is self.base_ring():
632
return ActedUponAction(other, self, not self_is_left)
633
extended = self.base_extend(ring)
634
action = ActedUponAction(ring, extended, not self_is_left)
635
if self_is_left:
636
action = PrecomposedAction(action,
637
extended.coerce_map_from(self),
638
ring.coerce_map_from(other))
639
else:
640
action = PrecomposedAction(action,
641
ring.coerce_map_from(other),
642
extended.coerce_map_from(self))
643
return action
644
645
def _make_Inequality(self, polyhedron, data):
646
"""
647
Create a new inequality object.
648
649
INPUT:
650
651
- ``polyhedron`` -- the new polyhedron.
652
653
- ``data`` -- the H-representation data.
654
655
OUTPUT:
656
657
A new :class:`~sage.geometry.polyhedron.representation.Inequality` object.
658
659
EXAMPLES::
660
661
sage: p = Polyhedron([(1,2,3),(2/3,3/4,4/5)]) # indirect doctest
662
sage: p.inequality_generator().next()
663
An inequality (0, 0, -1) x + 3 >= 0
664
"""
665
try:
666
obj = self._Inequality_pool.pop()
667
except IndexError:
668
obj = Inequality(self)
669
obj._set_data(polyhedron, data)
670
return obj
671
672
def _make_Equation(self, polyhedron, data):
673
"""
674
Create a new equation object.
675
676
INPUT:
677
678
- ``polyhedron`` -- the new polyhedron.
679
680
- ``data`` -- the H-representation data.
681
682
OUTPUT:
683
684
A new :class:`~sage.geometry.polyhedron.representation.Equation` object.
685
686
EXAMPLES::
687
688
sage: p = Polyhedron([(1,2,3),(2/3,3/4,4/5)]) # indirect doctest
689
sage: p.equation_generator().next()
690
An equation (0, 44, -25) x - 13 == 0
691
"""
692
try:
693
obj = self._Equation_pool.pop()
694
except IndexError:
695
obj = Equation(self)
696
obj._set_data(polyhedron, data)
697
return obj
698
699
def _make_Vertex(self, polyhedron, data):
700
"""
701
Create a new vertex object.
702
703
INPUT:
704
705
- ``polyhedron`` -- the new polyhedron.
706
707
- ``data`` -- the V-representation data.
708
709
OUTPUT:
710
711
A new :class:`~sage.geometry.polyhedron.representation.Vertex` object.
712
713
EXAMPLES::
714
715
sage: p = Polyhedron([(1,2,3),(2/3,3/4,4/5)], rays=[(5/6,6/7,7/8)]) # indirect doctest
716
sage: p.vertex_generator().next()
717
A vertex at (1, 2, 3)
718
"""
719
try:
720
obj = self._Vertex_pool.pop()
721
except IndexError:
722
obj = Vertex(self)
723
obj._set_data(polyhedron, data)
724
return obj
725
726
def _make_Ray(self, polyhedron, data):
727
"""
728
Create a new ray object.
729
730
INPUT:
731
732
- ``polyhedron`` -- the new polyhedron.
733
734
- ``data`` -- the V-representation data.
735
736
OUTPUT:
737
738
A new :class:`~sage.geometry.polyhedron.representation.Ray` object.
739
740
EXAMPLES::
741
742
sage: p = Polyhedron([(1,2,3),(2/3,3/4,4/5)], rays=[(5/6,6/7,7/8)]) # indirect doctest
743
sage: p.ray_generator().next()
744
A ray in the direction (140, 144, 147)
745
"""
746
try:
747
obj = self._Ray_pool.pop()
748
except IndexError:
749
obj = Ray(self)
750
obj._set_data(polyhedron, data)
751
return obj
752
753
def _make_Line(self, polyhedron, data):
754
"""
755
Create a new line object.
756
757
INPUT:
758
759
- ``polyhedron`` -- the new polyhedron.
760
761
- ``data`` -- the V-representation data.
762
763
OUTPUT:
764
765
A new :class:`~sage.geometry.polyhedron.representation.Line` object.
766
767
EXAMPLES::
768
769
sage: p = Polyhedron([(1,2,3),(2/3,3/4,4/5)], lines=[(5/6,6/7,7/8)]) # indirect doctest
770
sage: p.line_generator().next()
771
A line in the direction (140, 144, 147)
772
"""
773
try:
774
obj = self._Line_pool.pop()
775
except IndexError:
776
obj = Line(self)
777
obj._set_data(polyhedron, data)
778
return obj
779
780
781
782
from sage.geometry.polyhedron.backend_cdd import Polyhedron_QQ_cdd, Polyhedron_RDF_cdd
783
from sage.geometry.polyhedron.backend_ppl import Polyhedron_ZZ_ppl, Polyhedron_QQ_ppl
784
785
class Polyhedra_ZZ_ppl(Polyhedra_base):
786
Element = Polyhedron_ZZ_ppl
787
788
class Polyhedra_QQ_ppl(Polyhedra_base):
789
Element = Polyhedron_QQ_ppl
790
791
class Polyhedra_QQ_cdd(Polyhedra_base):
792
Element = Polyhedron_QQ_cdd
793
794
class Polyhedra_RDF_cdd(Polyhedra_base):
795
Element = Polyhedron_RDF_cdd
796
797
798