Skip to content

Commit

Permalink
sagemathgh-39349: fix bug for zero-dimension Ehrhart polynomial
Browse files Browse the repository at this point in the history
make sure that the Ehrhart poly of a zero dimensional lattice polytope
is 1.

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

URL: sagemath#39349
Reported by: Frédéric Chapoton
Reviewer(s): Dima Pasechnik
  • Loading branch information
Release Manager committed Jan 20, 2025
2 parents c73d6b8 + ebc4a02 commit 32ac474
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=f9c1bea6113a6a09430ee1f1aca16c75ed427d48
sha256=c1e0826fb54dd60e78f19e6fcad0b0ef90b33e1771fbbc2165a54c9297a89557
sha1=3cab7a94c31a21291853260a833e886cc958d794
sha256=18b43c409535004df6117293e42809481c997fc84adc3da12a8541d166192673
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5eb37241946a9ef9130ce36eff7e4f135d980eaf
b8c2e4eee46c020cecb4655bf1aceb51cadecf13
26 changes: 19 additions & 7 deletions src/sage/geometry/polyhedron/base_QQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ def integral_points_count(self, verbose=False, use_Hrepresentation=False,

@cached_method(do_pickle=True)
def ehrhart_polynomial(self, engine=None, variable='t', verbose=False,
dual=None, irrational_primal=None, irrational_all_primal=None,
maxdet=None, no_decomposition=None, compute_vertex_cones=None,
smith_form=None, dualization=None, triangulation=None,
triangulation_max_height=None, **kwds):
dual=None, irrational_primal=None,
irrational_all_primal=None, maxdet=None,
no_decomposition=None, compute_vertex_cones=None,
smith_form=None, dualization=None,
triangulation=None,
triangulation_max_height=None, **kwds):
r"""
Return the Ehrhart polynomial of this polyhedron.
Expand Down Expand Up @@ -348,23 +350,33 @@ def ehrhart_polynomial(self, engine=None, variable='t', verbose=False,
sage: Q = loads(dumps(P))
sage: Q.ehrhart_polynomial.is_in_cache()
True
sage: L = Polyhedron(vertices=[[QQ(0)]])
sage: L.ehrhart_polynomial()
1
"""
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.rational_field import QQ
R = PolynomialRing(QQ, variable)

# check if ``self`` is compact and has vertices in ZZ
if self.is_empty():
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.rational_field import QQ
R = PolynomialRing(QQ, variable)
return R.zero()

if not self.is_compact():
raise ValueError("Ehrhart polynomial only defined for compact polyhedra")

if any(not v.is_integral() for v in self.vertex_generator()):
raise TypeError("the polytope has nonintegral vertices, use ehrhart_quasipolynomial with backend 'normaliz'")

if self.dimension() == 0:
return R.one()

# Passes to specific latte or normaliz subfunction depending on engine
if engine is None:
# set default engine to latte
engine = 'latte'

if engine == 'latte':
poly = self._ehrhart_polynomial_latte(verbose, dual,
irrational_primal, irrational_all_primal, maxdet,
Expand Down
22 changes: 14 additions & 8 deletions src/sage/geometry/polyhedron/base_ZZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,13 @@ def _ehrhart_polynomial_normaliz(self, variable='t'):
raise TypeError("The polyhedron's backend should be 'normaliz'")

@cached_method(do_pickle=True)
def ehrhart_polynomial(self, engine=None, variable='t', verbose=False, dual=None,
irrational_primal=None, irrational_all_primal=None, maxdet=None,
no_decomposition=None, compute_vertex_cones=None, smith_form=None,
dualization=None, triangulation=None, triangulation_max_height=None,
**kwds):
def ehrhart_polynomial(self, engine=None, variable='t', verbose=False,
dual=None, irrational_primal=None,
irrational_all_primal=None, maxdet=None,
no_decomposition=None, compute_vertex_cones=None,
smith_form=None, dualization=None,
triangulation=None, triangulation_max_height=None,
**kwds):
r"""
Return the Ehrhart polynomial of this polyhedron.
Expand Down Expand Up @@ -458,12 +460,16 @@ def ehrhart_polynomial(self, engine=None, variable='t', verbose=False, dual=None
sage: Q.ehrhart_polynomial.is_in_cache() # optional - latte_int
True
"""
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.rational_field import QQ
R = PolynomialRing(QQ, variable)

if self.is_empty():
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.rational_field import QQ
R = PolynomialRing(QQ, variable)
return R.zero()

if self.dimension() == 0:
return R.one()

if not self.is_compact():
raise ValueError("Ehrhart polynomial only defined for compact polyhedra")

Expand Down

0 comments on commit 32ac474

Please sign in to comment.