Ask Your Question
0

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

asked 10 years ago

jjack gravatar image

updated 10 years ago

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?

Preview: (hide)

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

1 Answer

Sort by » oldest newest most voted
0

answered 10 years ago

FrédéricC gravatar image

updated 10 years ago

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
Preview: (hide)
link

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 ( 10 years ago )

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 ( 10 years ago )

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

jjack gravatar imagejjack ( 10 years ago )

Question Tools

1 follower

Stats

Asked: 10 years ago

Seen: 477 times

Last updated: Jul 26 '14