First time here? Check out the FAQ!

Ask Your Question
1

discriminant of multivariate polynomial

asked 5 years ago

physicist gravatar image

updated 5 years ago

If I do

R.<x,z,I>=QQ[]
f_str = 'x**3 + x*z +1'
f = eval(f_str) 
f.discriminant(x)

this works out correctly, giving

-4*z^3 - 27

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

R.<x,z,I>=QQ[]
f_str = '1.0*x**3 + x*z +1'
f = eval(f_str) 
f.discriminant(x)

I get the following error:

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

Can someone explain how to make it work?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

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.

Preview: (hide)
link

Comments

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 ( 5 years ago )

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 ( 5 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 5 years ago

Seen: 1,171 times

Last updated: Mar 23 '20