@@ -498,16 +498,13 @@ def inverse_of_unit(self):
498498 sage: R.<x> = InfinitePolynomialRing(Zmod(128))
499499 sage: (1+4*x[0]).inverse_of_unit()
500500 64*x_0^3 + 16*x_0^2 - 4*x_0 + 1
501- sage: p =71+28*x[0]+96*x[1]
501+
502+ sage: p = 71+28*x[0]+96*x[1]
502503 sage: p * p.inverse_of_unit()
503504 1
504505
505- Sadly, :trac:`22514` afflicts this calculation; the following should not be an error::
506-
507506 sage: R(5).inverse_of_unit()
508- Traceback (most recent call last):
509- ...
510- AttributeError: <class 'sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse'> has no attribute constant_coefficient
507+ 77
511508
512509 ALGORITHM:
513510
@@ -516,7 +513,6 @@ def inverse_of_unit(self):
516513 """
517514 return inverse_of_unit_polynomial (self )
518515
519-
520516 @cached_method
521517 def variables (self ):
522518 """
@@ -918,6 +914,32 @@ def lt(self):
918914 return InfinitePolynomial (self .parent (), self ._p .leading_coefficient ()* self ._p .parent ().gen ()** max (self ._p .exponents ()))
919915 return self # if it is scalar
920916
917+ def constant_coefficient (self ):
918+ r"""
919+ The constant coefficient of this polynomial
920+
921+ EXAMPLES::
922+
923+ sage: R.<a> = InfinitePolynomialRing(QQ)
924+ sage: (a[0] + a[1] + 2*a[2] + 3).constant_coefficient()
925+ 3
926+ sage: R.one().constant_coefficient()
927+ 1
928+ sage: (a[0] + 1 - a[0]).constant_coefficient()
929+ 1
930+
931+ sage: R.<a,b> = InfinitePolynomialRing(QQ)
932+ sage: p = (a[0] * b[1] + 1) * (a[2] - b[3] - 2) + 4
933+ sage: p.constant_coefficient()
934+ 2
935+ sage: R.one().constant_coefficient()
936+ 1
937+ """
938+ if self ._p .parent () is self .base_ring ():
939+ return self ._p
940+ else :
941+ return self ._p .constant_coefficient ()
942+
921943 def tail (self ):
922944 """
923945 The tail of ``self`` (this is ``self`` minus its leading term).
0 commit comments