Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
0

Converting real numbers to rational format

asked 6 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 6 years ago

rburing gravatar image

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

Preview: (hide)
link

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 ( 6 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: 6 years ago

Seen: 691 times

Last updated: Mar 19 '19