Ask Your Question

Approximate real numbers by rationals

asked 2013-08-21 06:52:33 -0500

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

answered 2013-08-23 15:02:07 -0500

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

answered 2013-08-21 07:09:46 -0500

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


Asked: 2013-08-21 06:52:33 -0500

Seen: 283 times

Last updated: Aug 23 '13