Ask Your Question

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:

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

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

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

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)

Note that

sage: a.nearby_rational(max_denominator=1000)

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

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]

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

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

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

And you can check:

sage: bool(3623680665059/2*sqrt(2/19) == 3623680665059/sqrt(38))
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


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

Seen: 149 times

Last updated: Aug 29 '21