多面体技巧

操作快捷方式

您可以使用自然符号获得不同的操作:

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
      x1 + x2 <=  5
           x2 <=  3
           x1 <=  3
          -x1 <= -1
     -x1 - x2 <= -3
          -x2 <= -1
sage: print(P.Hrepresentation_str(style='positive'))
x0 + x1 + x2 == 6
           5 >= x1 + x2
           3 >= x2
           3 >= x1
          x1 >= 1
     x1 + x2 >= 3
          x2 >= 1