ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 19 Mar 2019 16:06:15 +0100Converting real numbers to rational formathttps://ask.sagemath.org/question/45837/converting-real-numbers-to-rational-format/ 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. noelTue, 19 Mar 2019 16:06:15 +0100https://ask.sagemath.org/question/45837/Determine rationality of an expression?https://ask.sagemath.org/question/11067/determine-rationality-of-an-expression/I am trying to determine whether an expression is rational or not - and if it rational, to get the numerator and denominator.
To give you some context, I first use "solve" to get a `[ x == ..., y == ... ]` solution, and then I compute `log(solution[x])/log(solution[y])`. In some cases, this expression is a rational. I would like to be able to determine when it is a rational.
Of course it is rational in some very predictable cases - i.e., when the two logarithms are commensurate, and there are ways of checking this on the value of `solution[x]` and `solution[y]` themselves. But I am hoping that sage can do this for me.
I tried to do `Rational((log(...)/log(...)).n())` or `(log(...)/log(...)).n() in QQ`, but of course that does not work, as `.n()` converts the expression to some arbitrary precision float. Doing `(log(...)/log(...)) in QQ` always returns False even, for instance, for the case `(log(100)/log(10)) = 2`.
How can I do this?JeremieThu, 20 Feb 2014 22:49:58 +0100https://ask.sagemath.org/question/11067/How to represent the answer of linear programming in Rational modehttps://ask.sagemath.org/question/9378/how-to-represent-the-answer-of-linear-programming-in-rational-mode/ Hi everyone:
I use COIN in sage to solve a linear programming. And I need the answer to be in fraction, but the default is not factional. That's to say I need the answer
\frac{1}{3}
not
`0.3333....` ,
so, how can I get the answer I need ?jialrsTue, 02 Oct 2012 01:00:17 +0200https://ask.sagemath.org/question/9378/