First, you should understand that, since the values
a = 4.4747038862752024491936821935697961325
and the value
sage: b = 179398994850*sqrt(38).n()
sage: b
1.10588967597190e12
are only approximations of rational (resp. algebraic of degree 2) numbers. SInce they are plenty interesting rational numbers close to a
, and plenty algebraic numbers of degree 2 close to b
, what you are asking for is guessing, hence there will be some tuning to find the values you are looking for.
Fortunately, Sage provide tools to guess rational and algebraic numbers from their approximations.
1) Let us start with rational numbers. Since a
is a floating-point number (with 127 bits of precision), it can be seen as a rational number:
sage: a.parent()
Real Field with 127 bits of precision
sage: a.exact_rational()
47583213427876491813140527010326406415/10633823966279326983230456482242756608
While exact, this complicated rational is not what you were looking for. To find rational approximations of a
with smaller denominators, you can use the nearby_rational
method with a bounded numerator:
sage: a.nearby_rational(max_denominator=1000000)
3344161/747348
Note that
sage: a.nearby_rational(max_denominator=1000)
4157/929
is also valid, and the difference is mostly a matter of choice.
2) Let us now look at the algebraic number. If we start with the poor (53 bits of precision) floating-point approximation provided by the n
method:
sage: b = 179398994850*sqrt(38).n()
sage: b
1.10588967597190e12
We can ask Sage (via Pari) to guess some degree-2 integer polynomial with a root close to it:
sage: b.algebraic_dependency(2)
x^2 - 1105889675973*x + 1217328727802
Then, we can look at its roots, viewed as algebraic numbers:
sage: b.algebraic_dependency(2).roots(QQbar)
[(1.100768688099167?, 1), (1.105889675971900?e12, 1)]
Then, we can extract the large one:
sage: b.algebraic_dependency(2).roots(QQbar)[1][0]
1.105889675971900?e12
Then, we can ask for a symbolic expression involving roots:
sage: c = b.algebraic_dependency(2).roots(QQbar)[1][0]
sage: c.radical_expression()
1/2*sqrt(1222991975418797618585521) + 1105889675973/2
This is not what you expected. So, let us start with a better approximation, say with 1000 bits of precision:
sage: b = RealField(1000)(179398994850*sqrt(38))
sage: b
1.10588967597189929090820554425201919527368795421846950803639444912291826569689289728414766246782498538537131425403806720215830815019234020631697431575191020911782669720145901546499900188296595971738373962158743936852282082156205797291962646088366408981989820309700523881619507404041629259803795581637e12
Now, with the same procedure as above summarized in a single command, we have:
sage: b.algebraic_dependency(2).roots(QQbar)[1][0].radical_expression()
179398994850*sqrt(38)
The last form works the same way:
sage: d = RealField(1000)(3623680665059/sqrt(38))
sage: d.algebraic_dependency(2).roots(QQbar)[1][0].radical_expression()
3623680665059/2*sqrt(2/19)
And you can check:
sage: bool(3623680665059/2*sqrt(2/19) == 3623680665059/sqrt(38))
True