On 3/22/24 17:14, Waldek Hebisch wrote:
> You asked almost the same thing on 6 Jul 2023.
Do you see a problem?
I have at least 2.
(1) your solution was too complicated, i.e. hard to remember by heart,
(2) it involves InnerTrigonometricManipulations.
I consider an "Inner..." package as something hidden for a user.
(3) if a user does not know how to achieve
Expression(Complex(Integer))->AlgebraicNumber,
then what function name he would search for? "FG2F"?
I much more like Qian's suggestion to add this special case to
"retractIfCan".
>> PS: That is one of the situations where things that look simple are
>> hard for users to actually perform.
>
> Well, internally Expression(Complex(Integer)) and Expression(Integer)
> are represented in quite different way, so there is notrivial
> calculation to convert between the two forms.
Why shouldn't FriCAS help the user by basically exporting the
functionality of "FG2F" via "retractIfCan"?
Would you accept such a patch?
> And at least one reason for types is that we want to do calculations
> in a single type, without "useless" convertions. So, start from
> 'sqrt(-1)' and you will consistently get Expression(Integer) or
> AlgebraicNumber. OTOH if you want Expression(Complex(Integer)) then
> stay there...
Good suggestion. ;-)
You know that I like FriCAS, because it has types. However, I hate it to
waste time if I first have to dig deep into the internals until I can do
seemingly simple transformations.
My actual problem was to denest that expresssion.
%%% (1) -> z :=
sqrt(184726398605281*sqrt(-163)+14962838287027761)/(17502080*sqrt(20010))
+--------------------------------------------+
+-----+ | +-----+
\|20010 \|184726398605281 \|- 163 + 14962838287027761
(1) -------------------------------------------------------
350216620800
Type: AlgebraicNumber
%%% (2) -> rsimp(z)$RootSimplification
(2) "failed"
Type: Union("failed",...)
So I wrote a function that simply solves "x^2-radicand=0". I would have
to do it over complex numbers otherwise it wouldn't factorize. So I
ended in Expression Complex Integer.
While writing this mail, I have found out, that meanwhile
rsimp$RootSimplification can do the trick via ...(see below).
BTW, I am not sure whether I can trust the result, because there is
sqrt(-163) so it's over complex numbers and the docstring of rsimp
http://fricas.github.io/api/RootSimplification.html doesn't say anything
about how to interpret the result. Is there a particular preference over
the two possible solutions?
I still think that "retractIfCan" in Expression(Complex Integer) should
be able to yield an AlgebraicNumber if possible.
Ralf
%%% (57) -> z :=
sqrt(184726398605281*sqrt(-163)+14962838287027761)/(17502080*sqrt(20010))::Expression(Integer)
+--------------------------------------------+
| +-----+
\|184726398605281 \|- 163 + 14962838287027761
(57) -----------------------------------------------
+-----+
17502080 \|20010
Type: Expression(Integer)
%%% (58) -> rsimp(numer z)$RootSimplification
+---------------+
+-----+ |184726398605281
(58) (\|- 163 + 163) |---------------
\| 326
Type: Union(Expression(Integer),...)
%%% (59) -> rootSplit rsimp(numer z)$RootSimplification
+-----+
13591409 \|- 163 + 2215399667
(59) ------------------------------
+---+
\|326
Type: Expression(Integer)
%%% (60) -> rootSplit rsimp(numer z)$RootSimplification / denom z
+-----+
13591409 \|- 163 + 2215399667
(60) ------------------------------
+---+ +-----+
17502080 \|326 \|20010
Type: Expression(Integer)
%%% (61) -> % :: AlgebraicNumber
+-----+ +---+ +-----+
(13591409 \|- 163 + 2215399667)\|326 \|20010
(61) ----------------------------------------------
114170618380800