1
- # -*- coding: utf-8 -*-
2
1
r"""
3
2
Integer-valued polynomial rings
4
3
12
11
# Distributed under the terms of the GNU General Public License (GPL)
13
12
# https://www.gnu.org/licenses/
14
13
# ***************************************************************************
15
- from sage .arith .misc import ( binomial , factorial )
14
+ from sage .arith .misc import binomial , factorial
16
15
from sage .categories .algebras import Algebras
17
- from sage .categories .rings import Rings
18
16
from sage .categories .realizations import Category_realization_of_parent
17
+ from sage .categories .rings import Rings
19
18
from sage .combinat .free_module import CombinatorialFreeModule
20
19
from sage .matrix .constructor import matrix
20
+ from sage .misc .bindable_class import BindableClass
21
21
from sage .misc .cachefunc import cached_method
22
22
from sage .modules .free_module_element import vector
23
23
from sage .rings .integer_ring import ZZ
24
24
from sage .rings .polynomial .polynomial_ring import polygen
25
25
from sage .rings .polynomial .polynomial_ring_constructor import PolynomialRing
26
26
from sage .rings .rational_field import QQ
27
- from sage .sets .non_negative_integers import NonNegativeIntegers
28
27
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
31
29
from sage .structure .parent import Parent
30
+ from sage .structure .unique_representation import UniqueRepresentation
32
31
33
32
34
33
class IntegerValuedPolynomialRing (UniqueRepresentation , Parent ):
@@ -812,7 +811,7 @@ def h_vector(self):
812
811
813
812
If ``self`` is an Ehrhart polynomial, this is the `h`-vector.
814
813
815
- .. SEEALSO:: :meth:`h_polynomial`
814
+ .. SEEALSO:: :meth:`h_polynomial`, :meth:`fraction`
816
815
817
816
EXAMPLES::
818
817
@@ -832,18 +831,48 @@ def h_polynomial(self):
832
831
"""
833
832
Return the `h`-vector as a polynomial.
834
833
835
- .. SEEALSO:: :meth:`h_vector`
834
+ .. SEEALSO:: :meth:`h_vector`, :meth:`fraction`
836
835
837
836
EXAMPLES::
838
837
839
838
sage: x = polygen(QQ,'x')
840
839
sage: A = IntegerValuedPolynomialRing(ZZ).S()
841
840
sage: ex = A.from_polynomial((1+x)**3)
842
841
sage: ex.h_polynomial()
843
- z^3 + 4*z^2 + z
842
+ z^2 + 4*z + 1
844
843
"""
845
844
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
847
876
848
877
S = Shifted
849
878
0 commit comments