@@ -625,11 +625,22 @@ def truncate(self, d):
625
625
sage: M = z + z^2 + z^3 + z^4
626
626
sage: M.truncate(4)
627
627
z + z^2 + z^3
628
+
629
+ TESTS:
630
+
631
+ Check that :issue:`36154` is fixed::
632
+
633
+ sage: L.<z> = LazyPowerSeriesRing(QQ)
634
+ sage: f = L([0,1,2])
635
+ sage: f.truncate(1)
636
+ 0
628
637
"""
629
638
P = self .parent ()
630
639
coeff_stream = self ._coeff_stream
631
640
v = coeff_stream ._approximate_order
632
641
initial_coefficients = [coeff_stream [i ] for i in range (v , d )]
642
+ if not any (initial_coefficients ):
643
+ return P .zero ()
633
644
return P .element_class (P , Stream_exact (initial_coefficients , order = v ))
634
645
635
646
def shift (self , n ):
@@ -1838,6 +1849,14 @@ def _acted_upon_(self, scalar, self_on_left):
1838
1849
sage: 1 * M is M
1839
1850
True
1840
1851
1852
+ TESTS:
1853
+
1854
+ Check that :issue:`36154` is fixed::
1855
+
1856
+ sage: L.<z> = LazyPowerSeriesRing(Zmod(4))
1857
+ sage: f = L(constant=2)
1858
+ sage: 2*f
1859
+ 0
1841
1860
"""
1842
1861
# With the current design, the coercion model does not have
1843
1862
# enough information to detect a priori that this method only
@@ -1872,6 +1891,8 @@ def _acted_upon_(self, scalar, self_on_left):
1872
1891
else :
1873
1892
c = scalar * coeff_stream ._constant
1874
1893
initial_coefficients = [scalar * val for val in init_coeffs ]
1894
+ if not any (initial_coefficients ) and not c :
1895
+ return P .zero ()
1875
1896
return P .element_class (P , Stream_exact (initial_coefficients ,
1876
1897
order = v ,
1877
1898
constant = c ,
@@ -2816,6 +2837,14 @@ def _mul_(self, other):
2816
2837
2817
2838
sage: (1+z) * L([1,0,1], constant=1)
2818
2839
1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6)
2840
+
2841
+ Check that :issue:`36154` is fixed::
2842
+
2843
+ sage: L.<z> = LazyLaurentSeriesRing(Zmod(4))
2844
+ sage: f = L(constant=2, valuation=0)
2845
+ sage: g = L([2])
2846
+ sage: f * g
2847
+ 0
2819
2848
"""
2820
2849
P = self .parent ()
2821
2850
left = self ._coeff_stream
@@ -2874,6 +2903,8 @@ def _mul_(self, other):
2874
2903
c += left ._constant * ir [- 1 ]
2875
2904
else :
2876
2905
c = left ._constant # this is zero
2906
+ if not any (initial_coefficients ) and not c :
2907
+ return P .zero ()
2877
2908
coeff_stream = Stream_exact (initial_coefficients ,
2878
2909
order = lv + rv ,
2879
2910
constant = c )
@@ -2939,6 +2970,14 @@ def __pow__(self, n):
2939
2970
sage: (1 + z)^(1 + z)
2940
2971
1 + z + z^2 + 1/2*z^3 + 1/3*z^4 + 1/12*z^5 + 3/40*z^6 + O(z^7)
2941
2972
2973
+ TESTS:
2974
+
2975
+ Check that :issue:`36154` is fixed::
2976
+
2977
+ sage: L.<z> = LazyLaurentSeriesRing(Zmod(4))
2978
+ sage: f = L([2])
2979
+ sage: f^2
2980
+ 0
2942
2981
"""
2943
2982
if n == 0 :
2944
2983
return self .parent ().one ()
@@ -2951,14 +2990,15 @@ def __pow__(self, n):
2951
2990
# return P(self.finite_part() ** ZZ(n))
2952
2991
P = self .parent ()
2953
2992
ret = cs ._polynomial_part (P ._internal_poly_ring ) ** ZZ (n )
2993
+ if not ret :
2994
+ return P .zero ()
2954
2995
val = ret .valuation ()
2955
2996
deg = ret .degree () + 1
2956
2997
initial_coefficients = [ret [i ] for i in range (val , deg )]
2957
2998
return P .element_class (P , Stream_exact (initial_coefficients ,
2958
2999
constant = cs ._constant ,
2959
3000
degree = deg ,
2960
3001
order = val ))
2961
-
2962
3002
return super ().__pow__ (n )
2963
3003
2964
3004
def __invert__ (self ):
@@ -3806,6 +3846,17 @@ def __call__(self, g, *, check=True):
3806
3846
sage: g = L.undefined(valuation=0)
3807
3847
sage: f(g) == f.polynomial()(g)
3808
3848
True
3849
+
3850
+ TESTS:
3851
+
3852
+ Check that :issue:`36154` is fixed::
3853
+
3854
+ sage: L.<z> = LazyLaurentSeriesRing(Zmod(4))
3855
+ sage: f = L([0,2])
3856
+ sage: g = L([2])
3857
+ sage: f(g)
3858
+ 0
3859
+
3809
3860
"""
3810
3861
# Find a good parent for the result
3811
3862
from sage .structure .element import get_coercion_model
@@ -3850,6 +3901,8 @@ def __call__(self, g, *, check=True):
3850
3901
except (ValueError , TypeError ): # the result is not a Laurent polynomial
3851
3902
ret = None
3852
3903
if ret is not None and ret .parent () is R :
3904
+ if not ret :
3905
+ return P .zero ()
3853
3906
val = ret .valuation ()
3854
3907
deg = ret .degree () + 1
3855
3908
initial_coefficients = [ret [i ] for i in range (val , deg )]
@@ -4164,6 +4217,12 @@ def derivative(self, *args):
4164
4217
sage: f.derivative(q)[3]
4165
4218
3*q^2 - 2
4166
4219
4220
+ Check that :issue:`36154` is fixed::
4221
+
4222
+ sage: L.<z> = LazyLaurentSeriesRing(Zmod(4))
4223
+ sage: f = L([0,0,2])
4224
+ sage: f.derivative()
4225
+ 0
4167
4226
"""
4168
4227
P = self .parent ()
4169
4228
R = P ._laurent_poly_ring
@@ -4191,6 +4250,8 @@ def derivative(self, *args):
4191
4250
coeffs = [prod (i - k for k in range (order )) * c
4192
4251
for i , c in enumerate (coeff_stream ._initial_coefficients ,
4193
4252
coeff_stream ._approximate_order )]
4253
+ if not any (coeffs ):
4254
+ return P .zero ()
4194
4255
coeff_stream = Stream_exact (coeffs ,
4195
4256
order = coeff_stream ._approximate_order - order ,
4196
4257
constant = coeff_stream ._constant )
@@ -4993,6 +5054,14 @@ def derivative(self, *args):
4993
5054
+ (6*q^5*x^6+(-30*q^4)*x^5*y+60*q^3*x^4*y^2+(-60*q^2)*x^3*y^3+30*q*x^2*y^4+(-6)*x*y^5)
4994
5055
+ O(x,y)^7
4995
5056
5057
+ TESTS:
5058
+
5059
+ Check that :issue:`36154` is fixed::
5060
+
5061
+ sage: L.<z> = LazyPowerSeriesRing(Zmod(4))
5062
+ sage: f = L([0,0,2])
5063
+ sage: f.derivative()
5064
+ 0
4996
5065
"""
4997
5066
P = self .parent ()
4998
5067
R = P ._laurent_poly_ring
@@ -5038,6 +5107,8 @@ def derivative(self, *args):
5038
5107
coeffs = [prod (i - k for k in range (order )) * c
5039
5108
for i , c in enumerate (coeff_stream ._initial_coefficients ,
5040
5109
coeff_stream ._approximate_order )]
5110
+ if not any (coeffs ):
5111
+ return P .zero ()
5041
5112
coeff_stream = Stream_exact (coeffs ,
5042
5113
order = coeff_stream ._approximate_order - order ,
5043
5114
constant = coeff_stream ._constant )
0 commit comments