Ask Your Question
0

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

asked 2014-07-25 19:35:04 +0200

jjack gravatar image

updated 2014-07-26 08:48:34 +0200

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 19:57:17.227063

1 Answer

Sort by » oldest newest most voted
0

answered 2014-07-25 20:22:06 +0200

FrédéricC gravatar image

updated 2014-07-25 20:22:44 +0200

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 21:37:55 +0200 )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 21:44:53 +0200 )edit

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

jjack gravatar imagejjack ( 2014-07-26 08:41:39 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-25 19:35:04 +0200

Seen: 350 times

Last updated: Jul 26 '14