多面体提示和技巧¶
操作快捷方式¶
您可以使用自然符号获得不同的运算:
sage: Cube = polytopes.cube()
sage: Octahedron = 3/2*Cube.polar() # Dilation
sage: Cube + Octahedron # Minkowski sum
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 24 vertices
sage: Cube & Octahedron # Intersection
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 24 vertices
sage: Cube * Octahedron # Cartesian product
A 6-dimensional polyhedron in QQ^6 defined as the convex hull of 48 vertices
sage: Cube - Polyhedron(vertices=[[-1,0,0],[1,0,0]]) # Minkowski difference
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
SAGE输入功能¶
如果您正在使用一个难以构建的多面体,并且您想要重新获得正确的Sage输入代码来重现此对象,那么您可以!
sage: Cube = polytopes.cube()
sage: TCube = Cube.truncation().dilation(1/2)
sage: sage_input(TCube)
Polyhedron(backend='ppl', base_ring=QQ, vertices=[(1/6, -1/2, -1/2),
(1/2, -1/6, -1/2), (1/2, 1/6, -1/2), (1/2, 1/2, -1/6), (1/2, 1/2, 1/6),
(1/2, 1/6, 1/2), (1/6, 1/2, 1/2), (1/2, -1/6, 1/2), (1/6, 1/2, -1/2),
(1/6, -1/2, 1/2), (1/2, -1/2, 1/6), (1/2, -1/2, -1/6), (-1/2, 1/6, -1/2),
(-1/2, -1/2, 1/6), (-1/2, 1/6, 1/2), (-1/2, 1/2, 1/6), (-1/6, 1/2, 1/2),
(-1/2, 1/2, -1/6), (-1/6, 1/2, -1/2), (-1/2, -1/6, 1/2), (-1/6, -1/2, 1/2),
(-1/2, -1/2, -1/6), (-1/6, -1/2, -1/2), (-1/2, -1/6, -1/2)])
Hrepresentation_str
¶
如果您想要将 H -表现得很好,甚至得到 Latex 演示,这是有方法的!
sage: Nice_repr = TCube.Hrepresentation_str()
sage: print(Nice_repr)
-6*x0 - 6*x1 - 6*x2 >= -7
-6*x0 - 6*x1 + 6*x2 >= -7
-6*x0 + 6*x1 - 6*x2 >= -7
-6*x0 + 6*x1 + 6*x2 >= -7
-2*x0 >= -1
-2*x1 >= -1
-2*x2 >= -1
6*x0 + 6*x1 + 6*x2 >= -7
2*x2 >= -1
2*x1 >= -1
2*x0 >= -1
6*x0 - 6*x1 - 6*x2 >= -7
6*x0 - 6*x1 + 6*x2 >= -7
6*x0 + 6*x1 - 6*x2 >= -7
sage: print(TCube.Hrepresentation_str(latex=True))
\begin{array}{rcl}
-6 x_{0} - 6 x_{1} - 6 x_{2} & \geq & -7 \\
-6 x_{0} - 6 x_{1} + 6 x_{2} & \geq & -7 \\
-6 x_{0} + 6 x_{1} - 6 x_{2} & \geq & -7 \\
-6 x_{0} + 6 x_{1} + 6 x_{2} & \geq & -7 \\
-2 x_{0} & \geq & -1 \\
-2 x_{1} & \geq & -1 \\
-2 x_{2} & \geq & -1 \\
6 x_{0} + 6 x_{1} + 6 x_{2} & \geq & -7 \\
2 x_{2} & \geq & -1 \\
2 x_{1} & \geq & -1 \\
2 x_{0} & \geq & -1 \\
6 x_{0} - 6 x_{1} - 6 x_{2} & \geq & -7 \\
6 x_{0} - 6 x_{1} + 6 x_{2} & \geq & -7 \\
6 x_{0} + 6 x_{1} - 6 x_{2} & \geq & -7
\end{array}
sage: Latex_repr = LatexExpr(TCube.Hrepresentation_str(latex=True))
sage: view(Latex_repr) # not tested
这个 style 参数允许更改打印 H -关系:
sage: P = polytopes.permutahedron(3)
sage: print(P.Hrepresentation_str(style='<='))
-x0 - x1 - x2 == -6
-x0 - x1 <= -3
x0 + x1 <= 5
-x1 <= -1
x0 <= 3
-x0 <= -1
x1 <= 3
sage: print(P.Hrepresentation_str(style='positive'))
x0 + x1 + x2 == 6
x0 + x1 >= 3
5 >= x0 + x1
x1 >= 1
3 >= x0
x0 >= 1
3 >= x1