back to table · edit · history · where entries came from · files · download
2940 bytes, as of the version from 2026-09-15 08:19 (current). Recorded here, not run.
"""Ehrhart polynomials of Birkhoff polytopes -- numberdb.org/T232
For n = 3, ..., 6 this stores the Ehrhart polynomial H_n(t) of the
Birkhoff polytope B_n.
Run it with SageMath:
$ sage -pip install numberdb # once
$ sage -python generate.py # check the table against this code
$ sage -python generate.py --publish # fill the draft, with NUMBERDB_API_KEY set
The h-star coefficients used here are transcribed from OEIS A259473. The
Ehrhart polynomials are computed from those rows by the exact binomial
transform
H_n(t) = sum_i h_i^* binomial(t + d - i, d), d = (n - 1)^2.
The rings are named rather than taken from `sage.all`, so this runs on a
modular passagemath as well as on a full SageMath.
"""
import os
import sys
from math import factorial
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
UP_TO_N = 6
H_STAR_COEFFICIENTS = {
3: [1, 1, 1],
4: [1, 14, 87, 148, 87, 14, 1],
5: [
1, 103, 4306, 63110, 388615, 1115068, 1575669, 1115068, 388615,
63110, 4306, 103, 1,
],
6: [
1, 694, 184015, 15902580, 567296265, 9816969306, 91422589980,
490333468494, 1583419977390, 3166404385990, 3982599815746,
3166404385990, 1583419977390, 490333468494, 91422589980,
9816969306, 567296265, 15902580, 184015, 694, 1,
],
}
_T = PolynomialRing(QQ, "t")
_t = _T.gen()
def _key_from_stdin():
if os.environ.get("NUMBERDB_KEY_FROM_STDIN") != "1":
return
token = sys.stdin.read().strip()
if "=" in token and token.split("=", 1)[0].isupper():
token = token.split("=", 1)[1].strip().strip("'\"")
if token:
os.environ["NUMBERDB_API_KEY"] = token
def dimension(n):
return (n - 1) ** 2
def binomial_polynomial(shift, degree):
value = _T.one()
for j in range(degree):
value *= _t + QQ(shift - j)
return value / QQ(factorial(degree))
def ehrhart_polynomial(n):
d = dimension(n)
return sum(
QQ(c) * binomial_polynomial(d - i, d)
for i, c in enumerate(H_STAR_COEFFICIENTS[n])
)
class BirkhoffPolytopeEhrhartPolynomials(numberdb.Generator):
table = os.environ.get("NUMBERDB_TABLE", "T232")
parameters = ("n",)
type = "Q[]"
rigour = "exact"
def enumerate(self, up_to_n=UP_TO_N):
for n in range(3, up_to_n + 1):
yield {"n": str(n)}
def value(self, params, digits):
return ehrhart_polynomial(int(params["n"]))
if __name__ == "__main__":
_key_from_stdin()
generator = BirkhoffPolytopeEhrhartPolynomials()
if os.environ.get("NUMBERDB_PUBLISH") == "1" or "--publish" in sys.argv:
print(generator.publish(message="Birkhoff polytope Ehrhart polynomials"))
else:
report = generator.verify(sample=None)
print(report)
sys.exit(0 if report.ok else 1)