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.Fri, 23 Aug 2013 22:02:07 +0200Approximate real numbers by rationalshttps://ask.sagemath.org/question/10461/approximate-real-numbers-by-rationals/Does sage have routines to approximate real numbers by fractions:
For example, suppose 13.000000000000000000001 is an approximation of a complicated expression involving $pi, e$ and other transcendental constants. Then it "is probably" a rational number. Can sage tell me what rational number it "probably" is.Wed, 21 Aug 2013 13:52:33 +0200https://ask.sagemath.org/question/10461/approximate-real-numbers-by-rationals/Answer by vdelecroix for <p>Does sage have routines to approximate real numbers by fractions:</p>
<p>For example, suppose 13.000000000000000000001 is an approximation of a complicated expression involving $pi, e$ and other transcendental constants. Then it "is probably" a rational number. Can sage tell me what rational number it "probably" is.</p>
https://ask.sagemath.org/question/10461/approximate-real-numbers-by-rationals/?answer=15371#post-id-15371You can use the method nearby_rational which works for real numbers. If you do have a symbolic expression, you first have to take a numerical approximation as in
sage: pi.n().nearby_rational()
The term pi may be replaced by any symbolic expression.Fri, 23 Aug 2013 22:02:07 +0200https://ask.sagemath.org/question/10461/approximate-real-numbers-by-rationals/?answer=15371#post-id-15371Answer by kcrisman for <p>Does sage have routines to approximate real numbers by fractions:</p>
<p>For example, suppose 13.000000000000000000001 is an approximation of a complicated expression involving $pi, e$ and other transcendental constants. Then it "is probably" a rational number. Can sage tell me what rational number it "probably" is.</p>
https://ask.sagemath.org/question/10461/approximate-real-numbers-by-rationals/?answer=15355#post-id-15355See [Trac 237](http://trac.sagemath.org/ticket/237) for the closest to this that has been proposed. I'm not sure if there would be anything for just rationals or not.Wed, 21 Aug 2013 14:09:46 +0200https://ask.sagemath.org/question/10461/approximate-real-numbers-by-rationals/?answer=15355#post-id-15355