ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 09 Oct 2017 07:34:08 -0500Can the base ring of a polyhedron be restricted?http://ask.sagemath.org/question/34507/can-the-base-ring-of-a-polyhedron-be-restricted/I have a polyhedron `P` with rational vertices
sage: A = matrix([[1,0,0],[1,0,2],[1,1,1],[1,3/2,0]])
sage: A
[ 1 0 0]
[ 1 0 2]
[ 1 1 1]
[ 1 3/2 0]
sage: P = Polyhedron(A)
sage: P
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
If we scale `P` by a factor of two, then we get a lattice polytope.
sage: (2*P).is_lattice_polytope()
True
However, the base ring of `P` is still `QQ`
sage: (2*P).parent()
Polyhedra in QQ^3
Since `2*P` is a lattice polytope it seems like it should be possible to restrict the base ring of `2*P` to `ZZ`. Is this possible?Wed, 17 Aug 2016 20:03:20 -0500http://ask.sagemath.org/question/34507/can-the-base-ring-of-a-polyhedron-be-restricted/Answer by jipilab for <p>I have a polyhedron <code>P</code> with rational vertices</p>
<pre><code>sage: A = matrix([[1,0,0],[1,0,2],[1,1,1],[1,3/2,0]])
sage: A
[ 1 0 0]
[ 1 0 2]
[ 1 1 1]
[ 1 3/2 0]
sage: P = Polyhedron(A)
sage: P
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
</code></pre>
<p>If we scale <code>P</code> by a factor of two, then we get a lattice polytope.</p>
<pre><code>sage: (2*P).is_lattice_polytope()
True
</code></pre>
<p>However, the base ring of <code>P</code> is still <code>QQ</code></p>
<pre><code>sage: (2*P).parent()
Polyhedra in QQ^3
</code></pre>
<p>Since <code>2*P</code> is a lattice polytope it seems like it should be possible to restrict the base ring of <code>2*P</code> to <code>ZZ</code>. Is this possible?</p>
http://ask.sagemath.org/question/34507/can-the-base-ring-of-a-polyhedron-be-restricted/?answer=39087#post-id-39087The current difference between the base ring `QQ` and `ZZ` for polyhedron objects in Sage is not quite big nor quite well defined...
A polytope (a compact polyhedron) may have all vertices with integer coordinates, so that it could be called a "Lattice polytope", but its `H`-representation may still contain rational numbers. Of course, it is possible to multiply all coefficients in the `H`-representation by a certain integer factor to get an integral `H`-representation, but this is not automatically done in Sage.
The tickets [Add .change_ring() method for polyhedra](https://trac.sagemath.org/ticket/22574) and [Add .change_backend() method for polyhedra](https://trac.sagemath.org/ticket/22575) will then make it possible to apply the desired changes on the base ring and backend, if possible.Mon, 09 Oct 2017 07:34:08 -0500http://ask.sagemath.org/question/34507/can-the-base-ring-of-a-polyhedron-be-restricted/?answer=39087#post-id-39087Answer by tmonteil for <p>I have a polyhedron <code>P</code> with rational vertices</p>
<pre><code>sage: A = matrix([[1,0,0],[1,0,2],[1,1,1],[1,3/2,0]])
sage: A
[ 1 0 0]
[ 1 0 2]
[ 1 1 1]
[ 1 3/2 0]
sage: P = Polyhedron(A)
sage: P
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
</code></pre>
<p>If we scale <code>P</code> by a factor of two, then we get a lattice polytope.</p>
<pre><code>sage: (2*P).is_lattice_polytope()
True
</code></pre>
<p>However, the base ring of <code>P</code> is still <code>QQ</code></p>
<pre><code>sage: (2*P).parent()
Polyhedra in QQ^3
</code></pre>
<p>Since <code>2*P</code> is a lattice polytope it seems like it should be possible to restrict the base ring of <code>2*P</code> to <code>ZZ</code>. Is this possible?</p>
http://ask.sagemath.org/question/34507/can-the-base-ring-of-a-polyhedron-be-restricted/?answer=34514#post-id-34514I could not find any `change_ring` method or similar, but you can to the following by changing the ring of the vertices (note the `transpose` since the vertices are given as columns not rows):
sage: R = Polyhedron((2*P).vertices_matrix().transpose().change_ring(ZZ))
sage: R
A 2-dimensional polyhedron in ZZ^3 defined as the convex hull of 4 vertices
sage: 2*P
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
sage: R == 2*P
TrueThu, 18 Aug 2016 07:09:07 -0500http://ask.sagemath.org/question/34507/can-the-base-ring-of-a-polyhedron-be-restricted/?answer=34514#post-id-34514Comment by done_with_fish for <p>I could not find any <code>change_ring</code> method or similar, but you can to the following by changing the ring of the vertices (note the <code>transpose</code> since the vertices are given as columns not rows):</p>
<pre><code>sage: R = Polyhedron((2*P).vertices_matrix().transpose().change_ring(ZZ))
sage: R
A 2-dimensional polyhedron in ZZ^3 defined as the convex hull of 4 vertices
sage: 2*P
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
sage: R == 2*P
True
</code></pre>
http://ask.sagemath.org/question/34507/can-the-base-ring-of-a-polyhedron-be-restricted/?comment=34523#post-id-34523Thanks for the tip. It seems like sage should automatically change the ring to ZZ whenever P is a lattice polytope.Thu, 18 Aug 2016 14:31:30 -0500http://ask.sagemath.org/question/34507/can-the-base-ring-of-a-polyhedron-be-restricted/?comment=34523#post-id-34523