Ask Your Question
0

Converting real numbers to rational format

asked 2019-03-19 16:06:15 +0100

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(
      1522732369974.1*q0^3-8*q1^3+3924472*q0^2*q1-142784271977*q0^2*q2, 
      1423*q3^2*q4-1396461224121*q3^2+57684122*q0*q1*q2+q0*q1*q3+294*q3*q4^2
     )
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(
      15227323699741/10*q0^3-8*q1^3+3924472*q0^2*q1-142784271977*q0^2*q2, 
      1423*q3^2*q4-1396461224121*q3^2+57684122*q0*q1*q2+q0*q1*q3+294*q3*q4^2
     )
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
0

answered 2019-03-19 22:47:52 +0100

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

Comments

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 13:13:02 +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

Stats

Asked: 2019-03-19 16:06:15 +0100

Seen: 638 times

Last updated: Mar 19 '19