Ask Your Question

Converting real numbers to rational format

asked 2019-03-19 10:06:15 -0500

noel gravatar image

I have a number of polynomials that are up to 200 terms long which I am copying and pasting into sage. They all have real-valued coefficients. When I try a and compute a Groebner basis I get the error:

AttributeError: 'sage.rings.real_mpfr.RealNumber' object has no attribute 'divides'

Is there a way to automatically approximate these coefficients as exact rationals? I could do it view convoluted string parsing in python but would prefer if there is a built in method in python. As a toy example, the following does not work (note the .1 in the first term)

R = PolynomialRing(QQ,'q0,q1,q2,q3,q4')
I = Ideal(
B = I.groebner_basis(); B

While if I represent the value as a fraction everything works fine.

R = PolynomialRing(QQ,'q0,q1,q2,q3,q4')
I = Ideal(
B = I.groebner_basis(); B

My actual use case has many terms, all of which have many more decimal places that this example so manually adjusting things would take a substantial amount of time.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-03-19 16:47:52 -0500

rburing gravatar image

Write R.ideal( instead of Ideal( which tries to guess the ring that you want (and gets it wrong here).

edit flag offensive delete link more


Thanks! I ended up just parsing the string in python and converting each number to a fraction there. It wasn't pretty but is solved the issue.

noel gravatar imagenoel ( 2019-03-21 07:13:02 -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


Asked: 2019-03-19 10:06:15 -0500

Seen: 123 times

Last updated: Mar 19 '19