# HG changeset patch
# User Johan Bosman <johan.g.bosman@gmail.com>
# Date 1315641690 -7200
# Node ID 88d153d67ef8f5368cf66879022c91b8fa1503e3
# Parent 914339e71ae5a8eb0bdafb3fb383b8417f94898d
Trac 11782: use Sylvester matrices where faster methods fail
diff --git a/sage/rings/polynomial/polynomial_element.pyx b/sage/rings/polynomial/polynomial_element.pyx
|
a
|
b
|
|
| 4210 | 4210 | sage: f = x^2 + a |
| 4211 | 4211 | sage: f.discriminant() |
| 4212 | 4212 | 1 |
| | 4213 | |
| | 4214 | The following examples show that #11782 has been fixed:: |
| | 4215 | |
| | 4216 | sage: ZZ.quo(81)[x](3*x^2 + 3*x + 3).discriminant() |
| | 4217 | 54 |
| | 4218 | sage: ZZ.quo(9)[x](2*x^3 + x^2 + x).discriminant() |
| | 4219 | 2 |
| 4213 | 4220 | """ |
| 4214 | 4221 | if self.is_zero(): |
| 4215 | 4222 | return self.parent().zero_element() |
| … |
… |
|
| 4221 | 4228 | u = -1 # (-1)**(n*(n-1)/2) |
| 4222 | 4229 | if r == 0 or r == 1: |
| 4223 | 4230 | u = 1 |
| 4224 | | an = self[n]**(n - k - 2) |
| 4225 | | return self.base_ring()(u * self.resultant(d) * an) |
| 4226 | | |
| | 4231 | try: |
| | 4232 | an = self[n]**(n - k - 2) |
| | 4233 | return self.base_ring()(u * self.resultant(d) * an) |
| | 4234 | except ZeroDivisionError: |
| | 4235 | # Rather than dividing the resultant by the leading coefficient, |
| | 4236 | # we alter the Sylvester matrix (see #11782). |
| | 4237 | mat = self.sylvester_matrix(d) |
| | 4238 | mat[0, 0] = self.base_ring()(1) |
| | 4239 | mat[n - 1, 0] = self.base_ring()(n) |
| | 4240 | return u * mat.determinant() |
| | 4241 | |
| 4227 | 4242 | def reverse(self, degree=None): |
| 4228 | 4243 | """ |
| 4229 | 4244 | Return polynomial but with the coefficients reversed. |
diff --git a/sage/rings/polynomial/polynomial_zmod_flint.pyx b/sage/rings/polynomial/polynomial_zmod_flint.pyx
|
a
|
b
|
|
| 267 | 267 | sage: r.parent() is GF(19) |
| 268 | 268 | True |
| 269 | 269 | """ |
| 270 | | res = zmod_poly_resultant(&(<Polynomial_template>self).x, &(<Polynomial_template>other).x) |
| 271 | | return self.parent().base_ring()(res) |
| | 270 | if self.base_ring().is_field(): |
| | 271 | res = zmod_poly_resultant(&(<Polynomial_template>self).x, |
| | 272 | &(<Polynomial_template>other).x) |
| | 273 | return self.parent().base_ring()(res) |
| | 274 | else: |
| | 275 | return self.sylvester_matrix(other).determinant() |
| 272 | 276 | |
| 273 | 277 | def small_roots(self, *args, **kwds): |
| 274 | 278 | r""" |