# Ticket #11782: 11782_use_sylvester.patch

File 11782_use_sylvester.patch, 2.5 KB (added by johanbosman, 21 months ago)
• ## sage/rings/polynomial/polynomial_element.pyx

```# 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 sage: f = x^2 + a sage: f.discriminant() 1 The following examples show that #11782 has been fixed:: sage: ZZ.quo(81)[x](3*x^2 + 3*x + 3).discriminant() 54 sage: ZZ.quo(9)[x](2*x^3 + x^2 + x).discriminant() 2 """ if self.is_zero(): return self.parent().zero_element() u = -1 # (-1)**(n*(n-1)/2) if r == 0 or r == 1: u = 1 an = self[n]**(n - k - 2) return self.base_ring()(u * self.resultant(d) * an) try: an = self[n]**(n - k - 2) return self.base_ring()(u * self.resultant(d) * an) except ZeroDivisionError: # Rather than dividing the resultant by the leading coefficient, # we alter the Sylvester matrix (see #11782). mat = self.sylvester_matrix(d) mat[0, 0] = self.base_ring()(1) mat[n - 1, 0] = self.base_ring()(n) return u * mat.determinant() def reverse(self, degree=None): """ Return polynomial but with the coefficients reversed.
• ## sage/rings/polynomial/polynomial_zmod_flint.pyx

`diff --git a/sage/rings/polynomial/polynomial_zmod_flint.pyx b/sage/rings/polynomial/polynomial_zmod_flint.pyx`
 a sage: r.parent() is GF(19) True """ res = zmod_poly_resultant(&(self).x, &(other).x) return self.parent().base_ring()(res) if self.base_ring().is_field(): res = zmod_poly_resultant(&(self).x, &(other).x) return self.parent().base_ring()(res) else: return self.sylvester_matrix(other).determinant() def small_roots(self, *args, **kwds): r"""