Skip to content

Commit 4854839

Browse files
author
Release Manager
committed
gh-36940: new method "fraction" in integer-valued polynomials This is adding a new useful method to this class. Also fixing the h-polynomial method by adding a reversal there. ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [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 accordingly. URL: #36940 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Travis Scrimshaw
2 parents 8e8c4e4 + f588340 commit 4854839

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

src/sage/rings/polynomial/integer_valued_polynomials.py

Lines changed: 51 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,60 @@ 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 = LazyPowerSeriesRing(QQ, 't')
864+
sage: F(f)
865+
1 + 5*t + 15*t^2 + 35*t^3 + 70*t^4 + 126*t^5 + 210*t^6 + O(t^7)
866+
867+
sage: poly = ex.polynomial()
868+
sage: [poly(i) for i in range(6)]
869+
[1, 5, 15, 35, 70, 126]
870+
871+
sage: y = polygen(QQ, 'y')
872+
sage: penta = A.from_polynomial(7/2*y^2 + 7/2*y + 1)
873+
sage: penta.fraction()
874+
(-t^2 - 5*t - 1)/(t^3 - 3*t^2 + 3*t - 1)
875+
876+
TESTS::
877+
878+
sage: A.zero().fraction()
879+
0
880+
sage: A.zero().fraction().parent()
881+
Fraction Field of Univariate Polynomial Ring in t over Integer Ring
882+
"""
883+
v = self.h_vector()
884+
d = len(v)
885+
t = polygen(self.parent().base_ring(), 't')
886+
numer = sum(v[i] * t**(d - 1 - i) for i in range(d))
887+
return numer / (1 - t)**d
847888

848889
S = Shifted
849890

0 commit comments

Comments
 (0)