On Wednesday, March 26, 2014 10:34:35 AM UTC+1, John Cremona wrote:
>
> Looking at the code used, it uses the resultant formula which in turn
> evaluates a determinant. I agree with you that for small degrees it
> would be better (almost certainly in a lot of cases) be better to
> substitute into the generic formula.
>
Here is some code which does that:
def generic_discriminant(p):
"""
Compute discriminant of univariate polynomial.
The discriminant is computed in two steps. First all non-zero
coefficients of the polynomial are replaced with variables, and
the discriminant is computed using these variables. Then the
original coefficients are substituted into the result of this
computation. This should be faster in many cases, particularly
with big coefficients like complicated polynomials. In those
cases, the matrix computation on simple generators is a lot
faster, and the final substitution is cheaper than carrying all
that information along at all times.
"""
pr = p.parent()
if not pr.ngens() == 1:
raise ValueError("Must be univariate")
ex = p.exponents()
pr1 = PolynomialRing(ZZ, "x", len(ex))
pr2.<y> = pr1[]
py = sum(v*y^e for v, e in zip(pr1.gens(), ex))
d = py.discriminant()
return d(p.coefficients())
Should I file a trac ticket for this? If so, should I try to determine the
cases when to use it, or should I simply get the function in there and ask
someone else to take care of the required connections to existing code?
What is the correct ring to choose here? I thought about using
pr.base_ring() instead of ZZ, but that would mean that in the case of
stacked polynomial rings, I'd be doing the computation in a more difficult
setup than needed. It seems that sage will automatically coerce things
correctly: if the input is a polynomial over a polynomial ring over QQ or
GF(p), then so is the output. But I'm not sure whether that will always be
the case, or whether there might be cases where conversion from ZZ to
something else fails to do the right thing.
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.