Ask Your Question
1

How to radicalize `fraction * I` or `number * N^(± 1/2)`

asked 2021-08-28 11:48:14 +0200

Jakob777 gravatar image

updated 2021-08-29 12:17:23 +0200

slelievre gravatar image

There seem to be 2 cases which would help me to complete some Sage code.

  1. Complex fractions fraction * I like $$ 4.4747038862752024491936821935697961325*I $$ so that one obtains the fraction $$\frac{3344161}{747348} I$$

  2. Numbers of the form number * N^(±1/2) like $$\frac{3623680665059}{\sqrt{38}}, 179398994850 \sqrt{38}$$ where one does not know $N = 38$ in advance.

Using the function .canonicalize_radical(), I get the error:

PARI/GP ERROR:
***   at top-level: sage[1296]=canonicalize_radical(sage[1264])
***                            ^--------------------------------
***   not a function in function call

I hope there is a solution in Sage.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-08-28 22:42:43 +0200

tmonteil gravatar image

updated 2021-08-28 22:48:48 +0200

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
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

1 follower

Stats

Asked: 2021-08-28 11:48:14 +0200

Seen: 78 times

Last updated: Aug 29 '21