@@ -10,7 +10,8 @@ from flint.types.fmpz cimport any_as_fmpz
1010
1111from flint.flintlib.functions.fmpz cimport fmpz_is_zero
1212from flint.flintlib.functions.fmpz cimport fmpz_set
13- from flint.flintlib.functions.fmpq cimport fmpq_is_zero
13+ from flint.flintlib.functions.fmpz_poly cimport fmpz_poly_discriminant
14+ from flint.flintlib.functions.fmpq cimport fmpq_is_zero, fmpq_set_fmpz_frac
1415from flint.flintlib.functions.fmpq_poly cimport *
1516from flint.flintlib.functions.arith cimport arith_bernoulli_polynomial
1617from flint.flintlib.functions.arith cimport arith_euler_polynomial
@@ -518,6 +519,34 @@ cdef class fmpq_poly(flint_poly):
518519 fmpq_poly_gcd(res.val, self .val, (< fmpq_poly> other).val)
519520 return res
520521
522+ def discriminant (self ):
523+ """
524+ Return the discriminant of ``self``.
525+
526+ >>> f = fmpq_poly([1, 2, 3, 4, 5, 6])
527+ >>> f.discriminant()
528+ 1037232
529+ >>> f = fmpq_poly([1, 3, 5, 7, 9, 11, 13])
530+ >>> f.discriminant()
531+ -2238305839
532+ >>> f = fmpq_poly([1, 3, 5, 7, 9, 11, 13], 10)
533+ >>> f.discriminant()
534+ -2238305839/10000000000
535+
536+ """
537+ # There is no FLINT function for the discriminant of a fmpq_poly,
538+ # we use the fact that disc(f/q) = disc(f)/q^(2d-2)
539+ cdef fmpq res = fmpq.__new__ (fmpq)
540+ cdef fmpz rnum = fmpz.__new__ (fmpz)
541+ cdef fmpz rden = self .denom()** (2 * self .degree() - 2 )
542+
543+ cdef fmpz_poly x = fmpz_poly.__new__ (fmpz_poly)
544+ fmpq_poly_get_numerator(x.val, self .val)
545+ fmpz_poly_discriminant(rnum.val, x.val)
546+ fmpq_set_fmpz_frac(res.val, rnum.val, rden.val)
547+
548+ return res
549+
521550 def resultant (self , other ):
522551 """
523552 Returns the resultant of *self* and *other*.
0 commit comments