On Fri, Mar 22, 2024 at 01:22:23PM +0100, Ralf Hemmecke wrote: > Suppose by some computation I get an expression like > > z := (10*sqrt(163)+11*%i)/13/sqrt(105) > > I would like to transform it into an element of AlgebraicNumber. > > Unfortunately, up to now I was unable to find a function that helps to to > the retraction. > > Does someone know a way for cases where I know that the input actually can > happily live in AN?
You asked almost the same thing on 6 Jul 2023. My anwer looked like this: Well, the trouble is %i, if you use sqrt(-1), then you will get Expression(Integer) and things will be easy. But one can do (1) -> eI := Expression(Integer) (1) Expression(Integer) Type: Type (2) -> eCI := Expression(Complex(Integer)) (2) Expression(Complex(Integer)) Type: Type (3) -> iTM := ITRIGMNP(Integer, eI, eCI) (3) InnerTrigonometricManipulations Integer , Expression(Integer) , Expression(Complex(Integer)) Type: Type (4) -> z := (10*sqrt(163)+11*%i)/13/sqrt(105) +---+ 10 \|163 + 11 %i (4) ----------------- +---+ 13 \|105 Type: Expression(Complex(Integer)) (5) -> FG2F(z)$iTM +---+ +---+ 10 \|163 + 11 \|- 1 (5) --------------------- +---+ 13 \|105 Type: Expression(Integer) (6) -> %::AlgebraicNumber +---+ +---+ +---+ +---+ 10 \|105 \|163 + 11 \|- 1 \|105 (6) --------------------------------- 1365 Type: AlgebraicNumber > 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. 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... -- Waldek Hebisch -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/Zf2uaTGPA7_5kBs6%40fricas.org.