Ask Your Question

discriminant of multivariate polynomial

asked 2020-03-21 09:50:29 +0100

physicist gravatar image

updated 2020-03-23 13:06:05 +0100

If I do

f_str = 'x**3 + x*z +1'
f = eval(f_str) 

this works out correctly, giving

-4*z^3 - 27

But if I instead replace the coefficient of any monomial with a rational, such as

f_str = '1.0*x**3 + x*z +1'
f = eval(f_str) 

I get the following error:

AttributeError: 'MPolynomial_polydict' object has no attribute 'discriminant'

Can someone explain how to make it work?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-03-21 10:46:08 +0100

rburing gravatar image

Multiplying a string by 1.0 shouldn't work. What version of SageMath are you using? Try 9.0.

You probably want to do something like this:

sage: R.<x,z,I>=QQ[]
sage: f_str = '1.0*(x**3 + x*z +1)'
sage: f = R(sage_eval(f_str,locals={'x':x, 'z':z, 'I':I}))
sage: f.discriminant(x)
-4*z^3 - 27

If you do only sage_eval without converting into R, you will get a polynomial over RR (Real Field with 53 bits of precision), because that's what the parent of 1.0 is in SageMath.

Instead of specifying the dictionary of local variables you can also lazily write locals(), but that is less clean.

edit flag offensive delete link more


Thanks so much! Of course, I didn't attempt to multiply the whle string by 1.0, that was a typo in my question, which I'll correct now. Just wondering, what's wrong with the field RR for this purpose? Is it that the variables x,z,I are not included automatically?

physicist gravatar imagephysicist ( 2020-03-23 13:05:06 +0100 )edit

Trying to compute the discriminant over RR using SageMath 9.0 gives me a different error than the one you posted; I reported it as a bug; it is now trac ticket #29396.

rburing gravatar imagerburing ( 2020-03-23 13:50:32 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-03-21 09:50:29 +0100

Seen: 635 times

Last updated: Mar 23 '20