Ask Your Question
1

Approximate real numbers by rationals

asked 2013-08-21 13:52:33 +0100

LMN gravatar image

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.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2013-08-23 22:02:07 +0100

vdelecroix gravatar image

You 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.

edit flag offensive delete link more
0

answered 2013-08-21 14:09:46 +0100

kcrisman gravatar image

See Trac 237 for the closest to this that has been proposed. I'm not sure if there would be anything for just rationals or not.

edit flag offensive delete link more

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: 2013-08-21 13:52:33 +0100

Seen: 1,621 times

Last updated: Aug 23 '13