@@ -233,9 +233,23 @@ cdef class nmod_poly(flint_poly):
233
233
nmod_poly_reverse(res.val, self .val, length)
234
234
return res
235
235
236
+ def leading_coefficient (self ):
237
+ """
238
+ Return the leading coefficient of this polynomial.
239
+
240
+ >>> f = nmod_poly([123, 129, 63, 14, 51, 76, 133], 163)
241
+ >>> f.leading_coefficient()
242
+ 133
243
+ """
244
+ d = self .degree()
245
+ if d < 0 :
246
+ return 0
247
+ return nmod_poly_get_coeff_ui(self .val, d)
248
+
236
249
def inverse_series_trunc (self , slong n ):
237
250
"""
238
- Returns the inverse of ``self`` modulo `x^n`.
251
+ Returns the inverse of ``self`` modulo `x^n`. Assumes the leading
252
+ coefficient of the polynomial is invertible.
239
253
240
254
>>> f = nmod_poly([123, 129, 63, 14, 51, 76, 133], 163)
241
255
>>> f.inverse_series_trunc(3)
@@ -245,6 +259,9 @@ cdef class nmod_poly(flint_poly):
245
259
>>> f.inverse_series_trunc(5)
246
260
45*x^4 + 23*x^3 + 159*x^2 + 151*x + 110
247
261
"""
262
+ if n <= 0 :
263
+ raise ValueError (" n must be positive" )
264
+
248
265
cdef nmod_poly res
249
266
res = nmod_poly.__new__ (nmod_poly)
250
267
nmod_poly_init_preinv(res.val, self .val.mod.n, self .val.mod.ninv)
0 commit comments