Ask Your Question
0

Convert symbolic expressions like sqrt(2) or exp(1) to rational numbers [closed]

asked 2014-07-25 12:35:04 -0500

jjack gravatar image

updated 2014-07-26 01:48:34 -0500

I have coefficents of a rational polynomial f(x) in terms of symbolic expressions like sqrt(2) and exp(1).

How can I convert these coefficients to rational number approximations of them, so that I can work in a structure like a polynomial ring?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by jjack
close date 2014-07-26 12:57:17.227063

1 answer

Sort by » oldest newest most voted
0

answered 2014-07-25 13:22:06 -0500

FrédéricC gravatar image

updated 2014-07-25 13:22:44 -0500

Maybe something like that:

sage: R.<x> = SR['X']
sage: ex = sqrt(2) + exp(1)*x
sage: realring = RR['x']
sage: ratring = QQ['x']
sage: ratring(realring(ex))
268876667/98914198*x + 131836323/93222358
edit flag offensive delete link more

Comments

That sounds good. Is there an advantage in the additional step to working over a field of real numbers? What if I wanted to invert a power series with those coefficients, are rational coeffients better than real numbers?

jjack gravatar imagejjack ( 2014-07-25 14:37:55 -0500 )edit

Well, you can use either reals or rationals, they will play exactly the same role in any computation with polynomials. If you want rationals, you first need to convert to reals, so that one can then approximate them to rationals. By the way, could you please upvote and accept my answer if it suits you ?

FrédéricC gravatar imageFrédéricC ( 2014-07-25 14:44:53 -0500 )edit

I'll maybe post a separate question for the precision issue. Thank you for your answer.

jjack gravatar imagejjack ( 2014-07-26 01:41:39 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-25 12:35:04 -0500

Seen: 101 times

Last updated: Jul 26 '14