ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 02 May 2018 08:24:44 -0500Can sage compute the h* vector of a polytope?https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/We can define polytopes in sage with the command
sage: p = Polytope(A)
Here p is the convex hull of the integer matrix A.
I'm curious if we can compute the h* vector of p. Is this possible?
Roughly, the h* vector of a convex lattice polytope is constructed as follows.
The [Ehrhart series](https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series) can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.
I'm aware that sage can compute the ehrhart polynomial of a polytope with `sage: p.ehrhart_polynomial()` but I cant find anything about the h* vector in the documentation.
I know the command in polymake is `$p -> H_STAR_VECTOR`, but I'm not sure if this vector can be constructed in sage.
Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?Tue, 09 Feb 2016 00:46:30 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/Comment by kcrisman for <p>We can define polytopes in sage with the command</p>
<pre><code>sage: p = Polytope(A)
</code></pre>
<p>Here p is the convex hull of the integer matrix A.</p>
<p>I'm curious if we can compute the h* vector of p. Is this possible? </p>
<p>Roughly, the h* vector of a convex lattice polytope is constructed as follows.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series">Ehrhart series</a> can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.</p>
<p>I'm aware that sage can compute the ehrhart polynomial of a polytope with <code>sage: p.ehrhart_polynomial()</code> but I cant find anything about the h* vector in the documentation.</p>
<p>I know the command in polymake is <code>$p -> H_STAR_VECTOR</code>, but I'm not sure if this vector can be constructed in sage.</p>
<p>Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32529#post-id-32529Currently I think it's not always possible to interact with polymake. You have to install it yourself, I guess - the interface itself probably still works, but we only let a package go when we can build it on all "supported platforms". You're welcome to take a whirl and see if you can connect your polymake to Sage!Thu, 11 Feb 2016 09:36:00 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32529#post-id-32529Comment by done_with_fish for <p>We can define polytopes in sage with the command</p>
<pre><code>sage: p = Polytope(A)
</code></pre>
<p>Here p is the convex hull of the integer matrix A.</p>
<p>I'm curious if we can compute the h* vector of p. Is this possible? </p>
<p>Roughly, the h* vector of a convex lattice polytope is constructed as follows.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series">Ehrhart series</a> can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.</p>
<p>I'm aware that sage can compute the ehrhart polynomial of a polytope with <code>sage: p.ehrhart_polynomial()</code> but I cant find anything about the h* vector in the documentation.</p>
<p>I know the command in polymake is <code>$p -> H_STAR_VECTOR</code>, but I'm not sure if this vector can be constructed in sage.</p>
<p>Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32522#post-id-32522@kcrisman If I'm reading that link correctly, it sounds like sage once had this capability but no longer does?Wed, 10 Feb 2016 12:14:30 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32522#post-id-32522Comment by kcrisman for <p>We can define polytopes in sage with the command</p>
<pre><code>sage: p = Polytope(A)
</code></pre>
<p>Here p is the convex hull of the integer matrix A.</p>
<p>I'm curious if we can compute the h* vector of p. Is this possible? </p>
<p>Roughly, the h* vector of a convex lattice polytope is constructed as follows.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series">Ehrhart series</a> can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.</p>
<p>I'm aware that sage can compute the ehrhart polynomial of a polytope with <code>sage: p.ehrhart_polynomial()</code> but I cant find anything about the h* vector in the documentation.</p>
<p>I know the command in polymake is <code>$p -> H_STAR_VECTOR</code>, but I'm not sure if this vector can be constructed in sage.</p>
<p>Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32514#post-id-32514http://trac.sagemath.org/ticket/14116 is probably relevant here...Tue, 09 Feb 2016 16:05:25 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32514#post-id-32514Comment by done_with_fish for <p>We can define polytopes in sage with the command</p>
<pre><code>sage: p = Polytope(A)
</code></pre>
<p>Here p is the convex hull of the integer matrix A.</p>
<p>I'm curious if we can compute the h* vector of p. Is this possible? </p>
<p>Roughly, the h* vector of a convex lattice polytope is constructed as follows.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series">Ehrhart series</a> can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.</p>
<p>I'm aware that sage can compute the ehrhart polynomial of a polytope with <code>sage: p.ehrhart_polynomial()</code> but I cant find anything about the h* vector in the documentation.</p>
<p>I know the command in polymake is <code>$p -> H_STAR_VECTOR</code>, but I'm not sure if this vector can be constructed in sage.</p>
<p>Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32512#post-id-32512@tmonteil I've included a brief description as well as a link to the wikipedia article where the h* vector is defined. Thanks for looking at this!Tue, 09 Feb 2016 12:28:24 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32512#post-id-32512Comment by kcrisman for <p>We can define polytopes in sage with the command</p>
<pre><code>sage: p = Polytope(A)
</code></pre>
<p>Here p is the convex hull of the integer matrix A.</p>
<p>I'm curious if we can compute the h* vector of p. Is this possible? </p>
<p>Roughly, the h* vector of a convex lattice polytope is constructed as follows.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series">Ehrhart series</a> can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.</p>
<p>I'm aware that sage can compute the ehrhart polynomial of a polytope with <code>sage: p.ehrhart_polynomial()</code> but I cant find anything about the h* vector in the documentation.</p>
<p>I know the command in polymake is <code>$p -> H_STAR_VECTOR</code>, but I'm not sure if this vector can be constructed in sage.</p>
<p>Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32510#post-id-32510@done_with_fish: Does [the ref for h-rep and v-rep](http://doc.sagemath.org/html/en/reference/geometry/sage/geometry/polyhedron/representation.html) of polytopes help?Tue, 09 Feb 2016 11:06:34 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32510#post-id-32510Comment by tmonteil for <p>We can define polytopes in sage with the command</p>
<pre><code>sage: p = Polytope(A)
</code></pre>
<p>Here p is the convex hull of the integer matrix A.</p>
<p>I'm curious if we can compute the h* vector of p. Is this possible? </p>
<p>Roughly, the h* vector of a convex lattice polytope is constructed as follows.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series">Ehrhart series</a> can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.</p>
<p>I'm aware that sage can compute the ehrhart polynomial of a polytope with <code>sage: p.ehrhart_polynomial()</code> but I cant find anything about the h* vector in the documentation.</p>
<p>I know the command in polymake is <code>$p -> H_STAR_VECTOR</code>, but I'm not sure if this vector can be constructed in sage.</p>
<p>Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32508#post-id-32508If you could please give us a pointer to the definition of the h* vector of a polytope ?Tue, 09 Feb 2016 08:53:44 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32508#post-id-32508Answer by jipilab for <p>We can define polytopes in sage with the command</p>
<pre><code>sage: p = Polytope(A)
</code></pre>
<p>Here p is the convex hull of the integer matrix A.</p>
<p>I'm curious if we can compute the h* vector of p. Is this possible? </p>
<p>Roughly, the h* vector of a convex lattice polytope is constructed as follows.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series">Ehrhart series</a> can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.</p>
<p>I'm aware that sage can compute the ehrhart polynomial of a polytope with <code>sage: p.ehrhart_polynomial()</code> but I cant find anything about the h* vector in the documentation.</p>
<p>I know the command in polymake is <code>$p -> H_STAR_VECTOR</code>, but I'm not sure if this vector can be constructed in sage.</p>
<p>Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?answer=42241#post-id-42241You can use the `normaliz` backend (requires Normaliz 3.5.4) and its python interface `pynormaliz` (requires PyNormaliz 1.16).
You can install them by typing:
sage -i normaliz
sage -i pynormaliz
Then, in a terminal with Sage 8.9 or more recent, you can get the h^*-vector by typing:
sage: C = polytopes.hypercube(3, backend="normaliz")
sage: C.ehrhart_series().numerator().coefficients()
[1, 23, 23, 1]
This hypercube is the ±1 cube, so its volume is `8*factorial(3)=48`, which is `1+23+23+1`.
Eventually, once [this ticket](https://trac.sagemath.org/ticket/28413) is merged, it will be possible to call it directly on the polytope like so:
sage: C.h_star_vector()
[1, 23, 23, 1]Wed, 02 May 2018 08:24:44 -0500https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?answer=42241#post-id-42241Answer by kdilks for <p>We can define polytopes in sage with the command</p>
<pre><code>sage: p = Polytope(A)
</code></pre>
<p>Here p is the convex hull of the integer matrix A.</p>
<p>I'm curious if we can compute the h* vector of p. Is this possible? </p>
<p>Roughly, the h* vector of a convex lattice polytope is constructed as follows.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Ehrhart_polynomial#Ehrhart_Series">Ehrhart series</a> can be expressed as a rational function whose numerator is a polynomial. The h* vector of a polytope is the vector of coefficients of this polynomial.</p>
<p>I'm aware that sage can compute the ehrhart polynomial of a polytope with <code>sage: p.ehrhart_polynomial()</code> but I cant find anything about the h* vector in the documentation.</p>
<p>I know the command in polymake is <code>$p -> H_STAR_VECTOR</code>, but I'm not sure if this vector can be constructed in sage.</p>
<p>Perhaps a more general question would be: can I pass a polytope defined in sage to polymake and can sage read the results of the polymake operation?</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?answer=32578#post-id-32578 Sage doesn't have a direct 'print out the h* vector' command. It's not too difficult to manipulate the Ehrhart polynomial to get it, though I'm not sure my way could be cleanly implemented into Sage proper.
Let's say `P` is your polytope, of dimension `n=P.dimension()`, with Ehrhart polynomial `p=P.ehrhart_polynomial()` . Also, let `t=p.parent().gen()` . We need a polynomial ring to work over, and this let's us work over the same polynomial ring as p. Now, compute the first n+2 terms of the Ehrhart series (or more, if you want to be safe)
X=0
for i in range(0,n+10):
X+=p(i)*t^i
print(X)
Now, look at `X*(1-t)^(n+1)` . If X were the entire infinite Ehrhart series, we would get exactly the h* vector. But since we took sufficiently many terms of the Ehrhart series, we'll get lower order terms corresponding to the h* vector, and higher order error terms that can be discarded.
Wed, 17 Feb 2016 04:04:44 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?answer=32578#post-id-32578Comment by kcrisman for <p>Sage doesn't have a direct 'print out the h* vector' command. It's not too difficult to manipulate the Ehrhart polynomial to get it, though I'm not sure my way could be cleanly implemented into Sage proper. </p>
<p>Let's say <code>P</code> is your polytope, of dimension <code>n=P.dimension()</code>, with Ehrhart polynomial <code>p=P.ehrhart_polynomial()</code> . Also, let <code>t=p.parent().gen()</code> . We need a polynomial ring to work over, and this let's us work over the same polynomial ring as p. Now, compute the first n+2 terms of the Ehrhart series (or more, if you want to be safe)</p>
<pre><code>X=0
for i in range(0,n+10):
X+=p(i)*t^i
print(X)
</code></pre>
<p>Now, look at <code>X*(1-t)^(n+1)</code> . If X were the entire infinite Ehrhart series, we would get exactly the h* vector. But since we took sufficiently many terms of the Ehrhart series, we'll get lower order terms corresponding to the h* vector, and higher order error terms that can be discarded.</p>
https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32591#post-id-32591Can you add a specific example of this for a slightly nontrivial polytope?Wed, 17 Feb 2016 12:13:38 -0600https://ask.sagemath.org/question/32505/can-sage-compute-the-h-vector-of-a-polytope/?comment=32591#post-id-32591