Ask Your Question
1

discriminant of multivariate polynomial

asked 2020-03-21 03:50:29 -0500

physicist gravatar image

updated 2020-03-23 07:06:05 -0500

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-03-21 04:46:08 -0500

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

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 ( 2020-03-23 07:05:06 -0500 )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 07:50:32 -0500 )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

Stats

Asked: 2020-03-21 03:50:29 -0500

Seen: 55 times

Last updated: Mar 23