| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ae31437 commit 4495a4c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -233,9 +233,26 @@ 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 | + # XXX: This is a workaround for a Cython/PyPy bug: | ||
| 245 | + # https://github.com/flintlib/python-flint/issues/74 | ||
| 246 | + # https://github.com/cython/cython/issues/5776 | ||
| 247 | + d = self.degree() | ||
| 248 | + if d < 0: | ||
| 249 | + return 0 | ||
| 250 | + return nmod_poly_get_coeff_ui(self.val, d) | ||
| 251 | + | ||
| 236 | 252 | def inverse_series_trunc(self, slong n): | |
| 237 | 253 | """ | |
| 238 | - Returns the inverse of ``self`` modulo `x^n`. | ||
| 254 | + Returns the inverse of ``self`` modulo `x^n`. Assumes the leading | ||
| 255 | + coefficient of the polynomial is invertible. | ||
| 239 | 256 | ||
| 240 | 257 | >>> f = nmod_poly([123, 129, 63, 14, 51, 76, 133], 163) | |
| 241 | 258 | >>> f.inverse_series_trunc(3) | |
@@ -245,6 +262,9 @@ cdef class nmod_poly(flint_poly): | |||
| 245 | 262 | >>> f.inverse_series_trunc(5) | |
| 246 | 263 | 45*x^4 + 23*x^3 + 159*x^2 + 151*x + 110 | |
| 247 | 264 | """ | |
| 265 | + if n <= 0: | ||
| 266 | + raise ValueError("n must be positive") | ||
| 267 | + | ||
| 248 | 268 | cdef nmod_poly res | |
| 249 | 269 | res = nmod_poly.__new__(nmod_poly) | |
| 250 | 270 | nmod_poly_init_preinv(res.val, self.val.mod.n, self.val.mod.ninv) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments