Skip to content

Commit 30fd3f4

Browse files
committed
new method "fraction" in integer-valued polynomials
1 parent b002b63 commit 30fd3f4

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

src/sage/rings/polynomial/integer_valued_polynomials.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
r"""
32
Integer-valued polynomial rings
43
@@ -12,23 +11,23 @@
1211
# Distributed under the terms of the GNU General Public License (GPL)
1312
# https://www.gnu.org/licenses/
1413
# ***************************************************************************
15-
from sage.arith.misc import (binomial, factorial)
14+
from sage.arith.misc import binomial, factorial
1615
from sage.categories.algebras import Algebras
17-
from sage.categories.rings import Rings
1816
from sage.categories.realizations import Category_realization_of_parent
17+
from sage.categories.rings import Rings
1918
from sage.combinat.free_module import CombinatorialFreeModule
2019
from sage.matrix.constructor import matrix
20+
from sage.misc.bindable_class import BindableClass
2121
from sage.misc.cachefunc import cached_method
2222
from sage.modules.free_module_element import vector
2323
from sage.rings.integer_ring import ZZ
2424
from sage.rings.polynomial.polynomial_ring import polygen
2525
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
2626
from sage.rings.rational_field import QQ
27-
from sage.sets.non_negative_integers import NonNegativeIntegers
2827
from sage.sets.family import Family
29-
from sage.misc.bindable_class import BindableClass
30-
from sage.structure.unique_representation import UniqueRepresentation
28+
from sage.sets.non_negative_integers import NonNegativeIntegers
3129
from sage.structure.parent import Parent
30+
from sage.structure.unique_representation import UniqueRepresentation
3231

3332

3433
class IntegerValuedPolynomialRing(UniqueRepresentation, Parent):
@@ -812,7 +811,7 @@ def h_vector(self):
812811
813812
If ``self`` is an Ehrhart polynomial, this is the `h`-vector.
814813
815-
.. SEEALSO:: :meth:`h_polynomial`
814+
.. SEEALSO:: :meth:`h_polynomial`, :meth:`fraction`
816815
817816
EXAMPLES::
818817
@@ -832,18 +831,48 @@ def h_polynomial(self):
832831
"""
833832
Return the `h`-vector as a polynomial.
834833
835-
.. SEEALSO:: :meth:`h_vector`
834+
.. SEEALSO:: :meth:`h_vector`, :meth:`fraction`
836835
837836
EXAMPLES::
838837
839838
sage: x = polygen(QQ,'x')
840839
sage: A = IntegerValuedPolynomialRing(ZZ).S()
841840
sage: ex = A.from_polynomial((1+x)**3)
842841
sage: ex.h_polynomial()
843-
z^3 + 4*z^2 + z
842+
z^2 + 4*z + 1
844843
"""
845844
anneau = PolynomialRing(self.parent().base_ring(), 'z')
846-
return anneau(list(self.h_vector()))
845+
return anneau(list(reversed(self.h_vector())))
846+
847+
def fraction(self):
848+
"""
849+
Return the generating series of values as a fraction.
850+
851+
In the case of Ehrhart polynomials, this is known as
852+
the Ehrhart series.
853+
854+
.. SEEALSO:: :meth:`h_vector`, :meth:`h_polynomial`
855+
856+
EXAMPLES::
857+
858+
sage: A = IntegerValuedPolynomialRing(ZZ).S()
859+
sage: ex = A.monomial(4)
860+
sage: f = ex.fraction();f
861+
-1/(t^5 - 5*t^4 + 10*t^3 - 10*t^2 + 5*t - 1)
862+
863+
sage: F = QQ[['t']]
864+
sage: F(f).O(6)
865+
1 + 5*t + 15*t^2 + 35*t^3 + 70*t^4 + 126*t^5 + O(t^6)
866+
867+
sage: poly = ex.polynomial()
868+
sage: [poly(i) for i in range(6)]
869+
[1, 5, 15, 35, 70, 126]
870+
"""
871+
v = self.h_vector()
872+
d = len(v)
873+
t = polygen(self.parent().base_ring(), 't')
874+
numer = sum(v[i] * t**(d - 1 - i) for i in range(d))
875+
return numer / (1 - t)**d
847876

848877
S = Shifted
849878

0 commit comments

Comments
 (0)