@@ -24,6 +24,20 @@ cdef fmpz_series_coerce_operands(x, y):
2424 return NotImplemented , NotImplemented
2525
2626cdef class fmpz_series(flint_series):
27+ """
28+ Power series with integer coefficients.
29+
30+ >>> fmpz_series([1,2,3])
31+ 1 + 2*x + 3*x^2 + O(x^10)
32+ >>> fmpz_series([1,2,3], prec=2)
33+ 1 + 2*x + O(x^2)
34+ >>> fmpz_series([1,2,3], prec=2) + fmpz_series([1,2,3,4,5])
35+ 2 + 4*x + O(x^2)
36+ >>> a = fmpz_series([1,2,3])
37+ >>> (a+1)*(a-1) - a**2 + 1
38+ 0 + O(x^10)
39+
40+ """
2741
2842 cdef fmpz_poly_t val
2943 cdef long prec
@@ -151,6 +165,17 @@ cdef class fmpz_series(flint_series):
151165 return s * t
152166
153167 cpdef valuation(self ):
168+ """
169+ Returns the valuation of this power series.
170+ If there are no known nonzero coefficients, returns -1.
171+
172+ >>> fmpz_series([1,2,3]).valuation()
173+ 0
174+ >>> fmpz_series([0,0,0,1,2,3]).valuation()
175+ 3
176+ >>> fmpz_series([]).valuation()
177+ -1
178+ """
154179 cdef long i
155180 if fmpz_poly_is_zero(self .val):
156181 return - 1
@@ -159,7 +184,26 @@ cdef class fmpz_series(flint_series):
159184 i += 1
160185 return i
161186
162- def __div__ (s , t ):
187+ def _div_ (s , t ):
188+ """
189+ Power series division.
190+
191+ >>> fmpz_series([1]) / fmpz_series([1,-1,-1])
192+ 1 + x + 2*x^2 + 3*x^3 + 5*x^4 + 8*x^5 + 13*x^6 + 21*x^7 + 34*x^8 + 55*x^9 + O(x^10)
193+ >>> fmpz_series([0,1,2]) / fmpz_series([0,1,2])
194+ 1 + O(x^9)
195+ >>> fmpz_series([1,2]) / fmpz_series([0,1,2])
196+ Traceback (most recent call last):
197+ ...
198+ ValueError: quotient would not be a power series
199+ >>> fmpz_series([1,2]) / fmpz_series([2,3])
200+ Traceback (most recent call last):
201+ ...
202+ ValueError: leading term in denominator is not a unit
203+ >>> fmpz_series([]) / fmpz_series([1,2,3], prec=5)
204+ 0 + O(x^5)
205+
206+ """
163207 cdef long cap, sval, tval
164208 cdef fmpz_poly_t stmp, ttmp
165209 if type (s) is type (t):
@@ -173,7 +217,7 @@ cdef class fmpz_series(flint_series):
173217 u = fmpz_series.__new__ (fmpz_series)
174218
175219 if fmpz_poly_is_zero((< fmpz_series> s).val):
176- u.cap = cap
220+ ( < fmpz_series > u).prec = cap
177221 return u
178222
179223 sval = (< fmpz_series> s).valuation()
@@ -205,10 +249,19 @@ cdef class fmpz_series(flint_series):
205249 return s
206250 return s / t
207251
252+ def __div__ (s , t ):
253+ return fmpz_series._div_(s, t)
254+
208255 def __truediv__ (s , t ):
209- return fmpz_series.__div__ (s, t)
256+ return fmpz_series._div_ (s, t)
210257
211258 def __pow__ (fmpz_series s , ulong exp , mod ):
259+ """
260+ Power series exponentiation.
261+
262+ >>> fmpz_series([3,4,5], prec=4) ** 5
263+ 243 + 1620*x + 6345*x^2 + 16560*x^3 + O(x^4)
264+ """
212265 cdef long cap
213266 if mod is not None :
214267 raise NotImplementedError (" fmpz_series modular exponentiation" )
@@ -220,6 +273,17 @@ cdef class fmpz_series(flint_series):
220273 return u
221274
222275 def __call__ (s , t ):
276+ """
277+ Power series composition.
278+
279+ >>> fmpz_series([1,2,3])(fmpz_series([0,1,2]))
280+ 1 + 2*x + 7*x^2 + 12*x^3 + 12*x^4 + O(x^10)
281+ >>> fmpz_series([1,2,3])(fmpz_series([1,1,2]))
282+ Traceback (most recent call last):
283+ ...
284+ ValueError: power series composition with nonzero constant term
285+
286+ """
223287 cdef long cap
224288 if typecheck(t, fmpz_series):
225289 u = fmpz_series.__new__ (fmpz_series)
@@ -234,6 +298,19 @@ cdef class fmpz_series(flint_series):
234298 raise TypeError (" cannot call fmpz_series with input of type %s " , type (t))
235299
236300 def reversion (s ):
301+ """
302+ Power series reversion.
303+
304+ >>> fmpz_series([0,1,-2,-3]).reversion()
305+ x + 2*x^2 + 11*x^3 + 70*x^4 + 503*x^5 + 3864*x^6 + 31092*x^7 + 258654*x^8 + 2206655*x^9 + O(x^10)
306+ >>> fmpz_series([0,1,-2,-3]).reversion()(fmpz_series([0,1,-2,-3]))
307+ x + O(x^10)
308+ >>> fmpz_series([1,2,3]).reversion()
309+ Traceback (most recent call last):
310+ ...
311+ ValueError: power series reversion must have valuation 1
312+
313+ """
237314 cdef long cap
238315 cap = getcap()
239316 cap = min (cap, (< fmpz_series> s).prec)
0 commit comments